c This program reads multiple variables, c makes monthly climatologies from c 219-months of data, and writes it in one file. c mons=219: 219 months from 1983/7 to 2001/9 c ktime=9: 9 UTC time (00, 03, 06,...21 and all time mean) program output one variable c parameter (lons=144,lats=72,mons=219,ktime=9,maxvar=130,nvar=12) parameter (lons=144,lats=72,mons=219,nmon=12,mon0=7) parameter (ktime=9,maxvar=130,nvar=12) dimension dd(lons,lats,ktime) real dsum(lons,lats,nvar,nmon) integer nsum(lons,lats,nvar,nmon) integer i,j,ii,it,iv,im integer kvars(nvar) real missing logical yep character in_file*60 open(21,file='file_names_var130_sun.dat',form='formatted') c Above file contains the path of 219 data files. c Since san5 path for SGI and SUN workstations are different, c please use "file_names_var130_sun.dat" when you run this C program at sun and use "file_names_var130_sgi.dat' c at SGI open(8,file='test.dat', & form='unformatted',access='sequential') c *********************************** data kvars/1,2,3,4,5,6,8,20,23,26,32,33/ data missing/-999999/ c kvars is the numbers of the variables in the VARIABLE LIST c shown in README file. c Please reset the kvars for picking up the variables you want. c *********************************** dsum = 0.0 ! initialize nsum = 0 do 120 k=1,mons im=mod(k+mon0-1,nmon) if(im.eq.0) im=12 ! wrap 0 to 12 for December read(21,'(a60)') in_file c print *, in_file open(22,file=in_file, & form='unformatted',access='sequential') c iv=1 c *********************************** do 140 ii=1,maxvar do 160 it=1,ktime read(22) ((dd(i,j,it), i=1,lons),j=1,lats) 160 continue c continue if ii is on one of the variables requested in kvars, c noting the index, iv, among the requested data fields. yep=.false. iv=1 do while (.not. yep .and. iv .le. nvar+1) !nvar -> nvar+1 c if(iv>nvar) go to 120 ! so as not to read all the trailing junk in the file if(ii.eq.kvars(iv)) then yep=.true. else iv=iv+1 end if end do if(.not.yep) go to 140 print *, 'reading month ',k, ', variable number ', ii c *********************************** c do 172 it=1,ktime it=ktime ! only sum the total for all hours do 174 j=1,lats do 176 i=1,lons if(dd(i,j,it).lt.0.0) then dd(i,j,it)=missing ! All data are positive, the missing data is set to -999999 else dsum(i,j,iv,im)=dsum(i,j,iv,im)+dd(i,j,it) nsum(i,j,iv,im)=nsum(i,j,iv,im)+1 end if 176 continue 174 continue c 172 continue c it=ktime ! write only monthly mean for all times of day c write(8) ((dd(i,j,it), i=1,lons),j=1,lats) 140 continue c *********************************** end loop over variables ii 120 continue c *********************************** end loop over months c now divide the monthwise sums by the number of years c in the average and write it do im=1,nmon do iv=1,nvar do j=1,lats do i=1,lons if(nsum(i,j,iv,im).ne.0) then dsum(i,j,iv,im)=dsum(i,j,iv,im)/real(nsum(i,j,iv,im)) else dsum(i,j,iv,im)=missing end if end do end do write(8) ((dsum(i,j,iv,im), i=1,lons),j=1,lats) end do end do print *, 'read_12vars: normal completion' stop end