#! /bin/sh # # Last change: Mihai Dima 2001 # if [ $# -lt 7 ] then echo " " echo " ***** GAD2EXT ***** " echo " " echo " The program transforms a GRADS file in an EXTRA file" echo " " echo " Syntax:" echo " " echo " gad2ext " echo " " echo " " exit 0 else echo " " echo " ***** GAD2EXT ***** " echo " " echo "Input file (GRADS)="$7 echo "Output file (EXTRA)="$8 cp $7 fort.1 fi cat > gad2ext.f << EOF PROGRAM GAD2EXTX implicit none integer mxdim, nx,ny,dt,date,var,level,len, $ day,month,year,i,irec,ireal,j,rec parameter(mxdim=22000) real data(mxdim),udefi REAL odata(mxdim),udefo C data nx,ny,date,dt/ 148,74,1,100/ C data udefi,udefo,level/ 0.9.e+10,0.9e+10,9999/ ireal=4 c --> Read command inputs: read(5,*,end=10) nx,ny,udefi,udefo,date,dt 10 continue print *,'nx=',nx,' ny=',ny print *,' udefi=',udefi,' udefo=',udefo print *,'date=',date,' dt=',dt C stop 'OK!' len=nx*ny c --> open files OPEN(1,form='unformatted',access='direct',recl=ireal*len) c OPEN(1,form='unformatted',access='direct',recl=1) OPEN(2,form='unformatted') level=9999 var=nx*1000+1 irec=1 print*,'Using: date=',date,' var=',var,' level = ',level, $ ' len=',len,' delta t = ',dt print*, 'Input undef = ',udefi,', Extra file undef = ',udefo c rewind 1 c -------Start while-not-end-of-file unit 9: 20 continue read(1,err=99,rec=irec) (data(i),i=1,len) c print*,'OK!' c --> Correct udef: do i=1,len if(abs(data(i)-udefi).lt.0.00001*abs(udefi)) then odata(i)=udefo else odata(i)=data(i) endif enddo c --> Write Extra data record write(2) date,var,level,len write(2) ((odata(i+j*nx),i=1,nx),j=ny-1,0,-1) irec=irec+1 c --> Compute new date date=date+dt month=mod(date,10000)/100 year=date/10000 day=mod(date,100) if(day.gt.30) month=month+1 if(month.gt.12) year=year+1 month=mod(month-1,12)+1 day=mod(day-1,30)+1 date=year*10000+month*100+day goto 20 99 continue print*,irec-1,' records written.' c ------End while loop print*, '----- normal end of gad2extx -----' stop end EOF f77 gad2ext.f -o gad2ext.x gad2ext.x $7 << M $1 $2 $3 $4 $5 $6 M cp fort.2 $7.ext rm fort.1 fort.2 rm gad2ext.x gad2ext.f exit