character*11 name1(5873) character*10 name2(12) character*60 name3 dimension krain(31),index(500), 1 iy1(5873),mo1(5873),iy2(5873),mo2(5873) data name2/'stnx1.txt ','stnx2.txt ','stnx3.txt ','stnx4.txt ', 1 'stnx5.txt ','stnx6.txt ','stnx7.txt ','stnx8.txt ', 1 'stnx9.txt ','stnx10.txt','stnx11.txt','stnx12.txt'/ open(7,file='stnames.txt',status='old') nstat=0 do 20 j=1,12 open(8,file=name2(j),status='old') nx=0 kk=1 30 read(8,1001,end=40)istn nx=nx+1 if(istn.eq.999999)then index(kk)=nx-1 kk=kk+1 nx=0 endif goto30 40 close(unit=8) open(8,file=name2(j),status='old') do 50 k1=1,kk-1 nstat=nstat+1 read(7,'(a)')name1(nstat) open(9,file=name1(nstat),status='new') do 60 k2=1,index(k1) read(8,1001)nst1,iy,mo,(krain(i),i=1,31) if(k2.eq.1)then iy1(nstat)=iy mo1(nstat)=mo endif if(k2.gt.1)then if(iy.eq.iyold.and.mo.eq.mold+1)goto41 if(iy.eq.iyold+1.and.mo.eq.1.and.mold.eq.12)goto41 501 mold=mold+1 if(mold.eq.13)then iyold=iyold+1 mold=1 endif if(mold.eq.mo.and.iyold.eq.iy)goto41 do 502 k=1,31 if(mcalc(iyold,mold,k).eq.0)goto502 write(9,1002)iyold,mold,k,-1 502 continue goto501 endif 41 iyold=iy mold=mo do 70 k=1,31 if(mcalc(iy,mo,k).eq.0)goto70 write(9,1002)iy,mo,k,krain(k) 70 continue 60 continue iy2(nstat)=iy mo2(nstat)=mo close(unit=9) read(8,1001)istn 50 continue if(j.eq.12)goto88 nstat=nstat+1 read(7,'(a)')name1(nstat) open(9,file=name1(nstat),status='new') k2=1 85 read(8,1001,end=80)nst1,iy,mo,(krain(i),i=1,31) if(k2.eq.1)then iy1(nstat)=iy mo1(nstat)=mo endif if(k2.gt.1)then if(iy.eq.iyold.and.mo.eq.mold+1)goto86 if(iy.eq.iyold+1.and.mo.eq.1.and.mold.eq.12)goto86 601 mold=mold+1 if(mold.eq.13)then iyold=iyold+1 mold=1 endif if(mold.eq.mo.and.iyold.eq.iy)goto86 do 602 k=1,31 if(mcalc(iyold,mold,k).eq.0)goto602 write(9,1002)iyold,mold,k,-1 602 continue goto601 endif 86 iyold=iy mold=mo k2=2 do 90 k=1,31 if(mcalc(iy,mo,k).eq.0)goto90 write(9,1002)iy,mo,k,krain(k) 90 continue goto85 80 close(unit=9) iy2(nstat)=iy mo2(nstat)=mo 88 continue close(unit=8) 20 continue close(unit=7) c open(7,file='stnames.txt',status='old') c open(10,file='5873inv.txt',status='old') c do 700 i=1,5873 c read(10,1003)name3 c write(7,1004)name1(i),iy1(i),mo1(i),iy2(i),mo2(i),name3 c 700 continue 1001 format(i6,i4,i2,1x,31i4) 1002 format(i5,i3,i3,i5) 1003 format(6x,a60) 1004 format(a11,i5,i3,i5,i3,a60) end c function mcalc(iy,mo,k) c determine whether day k of month mo of year iy exists c return 1 if it does, 0 otherwise mcalc=1 if(mo.eq.4.and.k.eq.31)mcalc=0 if(mo.eq.6.and.k.eq.31)mcalc=0 if(mo.eq.9.and.k.eq.31)mcalc=0 if(mo.eq.11.and.k.eq.31)mcalc=0 if(mo.eq.2.and.k.eq.30)mcalc=0 if(mo.eq.2.and.k.eq.31)mcalc=0 if(mo.eq.2.and.k.eq.29.and.iy.eq.1900)mcalc=0 if(mo.eq.2.and.k.eq.29.and.4*(iy/4).ne.iy)mcalc=0 return end