I was able to print out daily values and aggregate the final annual result but I am lost and dont know where to start on how to sum the daily values to monthly and print it out. I need your help badely.
Here is part of the code
import os.path
# Open files to read
ifh = open("D:/ArcView/pcp_avg.txt", "r")
ifh2 = open("D:/ArcView/parameters_31Oct.txt", "r")
# Open files to write output
ofh1 = open("D:/ArcView/rye1.txt", "w")
ofh2 = open("D:/ArcView/rye2.txt", "w")
# Read the files
rainF = ifh.readline()
cropP = ifh2.readline()
# print heading on the annual output
print >>ofh2, 'X_CORD', 'Y_CORD', 'ID', 'ETct', 'ETat'
while rainF and cropP:
rfields = rainF.split()
cfields = cropP.split()
X_Grid = cfields[0] # X-grid (latitude) in degree
Y_Grid = cfields[1] # Y-grid (longitude)
ID = int(float(cfields[2]))
# parameters initialization
KS = 1
Dri = TAWC*Zrmin_rf*Pstd
Total = 0
ETat = 0
ETct = 0
print >>ofh1, X_Grid, Y_Grid, ID,
print >>ofh2, X_Grid, Y_Grid, ID,
#for loop over the grawing period - from planting to harvest
for J in range (1, 365, 1):
# Daily calculation of different parameters
PR = float(rfields[J])
ETo = float(efields[J])
ETc = ETo * KC
# do some more here ........
# calculation of soil water balance
if Dri > RAW:
KS = max(0,((St)/((1-Pi)*TAW)))
else:
KS = 1
# and some more ......
ETa = ETc * KS
# aggregation over the growing period
ETct += ETc
ETat += ETa
# print daily values
print >>ofh1, '%7.2f' %ETc,
# how to print monthly values ??????
# print annual values
print >> ofh2, '%.2f %.2f'%(ETct, ETat),
print >>ofh1
print >>ofh2
# running over the files
rainF = ifh.readline()
cropP = ifh2.readline()
# closing the files
ofh1.close()
ofh2.close()
ifh.close()
ifh2.close()