I have too collect a daily rainfall data from a certain model output. The model ouput gives out each stations daily data separately which I have to collect together and further analyse.
[I have tried the following, it works but my data - thousands of pcp_#.txt which makes the process very cumbersam.
ifh1=open("pcp_1.txt")
ifh2=open("pcp_2.txt")
ifh3=open("pcp_3.txt")
ifh4=open("pcp_4.txt")
ifh5=open("pcp_5.txt")
ifh6=open("pcp_6.txt")
ifh7=open("pcp_7.txt")
ifh8=open("pcp_8.txt")
ifh9=open("pcp_9.txt")
ifh10=open("pcp_10.txt")
ofh = open("pcp_total5.txt", "w")
line1=ifh1.readline()
line2=ifh2.readline()
line3=ifh3.readline()
line4=ifh4.readline()
line5=ifh5.readline()
line6=ifh6.readline()
line7=ifh7.readline()
line8=ifh8.readline()
line9=ifh9.readline()
line10=ifh10.readline()
# run through line by line and extract the data from the different txt files
while line1 and line2 and line3 and line4 and line5 and line6 and line7 and line8 and line9 and line10:
fields1=line1.split()
fields2=line2.split()
fields3=line3.split()
fields4=line4.split()
fields5=line5.split()
fields6=line6.split()
fields7=line7.split()
fields8=line8.split()
fields9=line9.split()
fields10=line10.split()
ID = fields1[0]
ID1 = fields1[1]
ID2 = fields1[2]
r1=fields1[3]
r2=fields2[3]
r3=fields3[3]
r4=fields4[3]
r5=fields5[3]
r6=fields6[3]
r7=fields7[3]
r8=fields8[3]
r9=fields9[3]
r10=fields10[3]
#writing the heading on the file
print >> ofh, ID,ID1, ID2,
#writing the result on the file
print >>ofh, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10
# running over the files
line1=ifh1.readline()
line2=ifh2.readline()
line3=ifh3.readline()
line4=ifh4.readline()
line5=ifh5.readline()
line6=ifh6.readline()
line7=ifh7.readline()
line8=ifh8.readline()
line9=ifh9.readline()
line10=ifh10.readline()
# closing the files
ofh.close()
ifh1.close
ifh2.close
ifh3.close
ifh4.close
ifh5.close
ifh6.close
ifh7.close
ifh8.close
ifh9.close
ifh10.close
Someone may have a good suggestion how to make to read the file's automatically and put them toghert. Please I need your help!!
chebude