Thank you very much Tachywaxon for clarifying the till-now-somewhat-obscure food-production-growth mechanism

Till now I always played by instinct and rules of thumb about it, but after knowing which comes first and which second, and most important that there is an "invisible" granary bar, which is filled parallel with the granary up to half the food bar capacity, now all makes sense to me. I tried to build granaries on the half food bar marks, but only because I have read somewhere this is the best point, now I know why
To add a further point: middle food bar
isn't the sole optimal point to finish a granary. In fact, with a good food source, there are many. And the trick is simply based on the fact the code proceeds in step and granary/food bars are one before growth (btw, growth is simply a substraction of present food bar, then an added population from the code point of view).
The trick is to get the most "surplus" (I use the word surplus, but that concept is wrong) to get the growth.
For instance,
if you reach 13/22 with a food rate of +4

(granary chopped last turn when food bar was 9/22), experience will say you will miss 1

because you need 9

to complete the food bar (and granary bar at the same time). Next turn, it's gonna be 9/24. But in reality, after two turns, you get (13+4+4)/22=21/22. Let see how the code handles the next income of food:
Steps
1. (21+4)/22=25/22 (Food bar)
2. Granary was 8/11 but now is (8+4)/11=12/11 ==>max 11/11
3. food bar is eaten ==> (25-22)/22==>3/24==>14/24 thanks to granary.
4. Add a population
In the end, the very turn of growth, there is a margin to catch up missed half food bar granary.
And thus there is not a single point of optimal granary. It's situational.