program res2nc ! read an ascii *.res file and converts to a netcdf *.nc file. ! to invoke on the cray c-90, must first load netcdf module: ! module load netcdf implicit none include 'netcdf.inc' include 'itg.par' include 'itg.cmn' include 'itg_ri.cmn' ! someday will replace the above with an f90 module to enable dynamic ! array allocation. character filename*80 character yorn*1 integer net,ncnt,iou,status real tim,dt1 integer iargc,icount external iargc, getarg real second,cpu_time0, cpu_time1 ! Variables which used to be in post.cmn: real dt(mz) ! different time step for different ky's, for icrit>0. real time(mz) ! corresponding final time for different ky's. c determine the name of the input file: icount=iargc() if(icount .ge. 1) then call getarg(1,runname) else write(6,*) 'Usage: res2nc RUN' write(6,*) ' will convert ascii RUN.res into netCDF RUN.nc' endif lrunname=index(runname,' ')-1 filename=runname(1:lrunname)//'.res' iou=30 open(unit=iou,file=filename,status='old',form='formatted') ! read first few lines of data to determine array sizes read(iou,1)ld,ldb,kd,nmin,nmax,nd,lin,kdpass read(iou,1)nstp,ne,nfreq,ntotal,md,nspecies,ikx,iperiod 1 format(1x,3i10) close(unit=iou) write(*,*) "Min values for itg.par: (will be inaccurate for some files)" write(*,*) "lz = ",ld write(*,*) "mz = ", md write(*,*) "nz = ", nd write(*,*) "nez = ",ne write(*,*) "nspecz =",nspecies write(*,*) " " net=0 ncnt=0 open(unit=iou,file=filename,status='old',form='formatted') cpu_time0=second() call wread(iou,net,ncnt,tim,dt1,time,dt) cpu_time1=second() close(unit=iou) write(*,*) cpu_time1-cpu_time0,' seconds to read ', filename net=0 ncnt=0 filename=runname(1:lrunname)//'.nc' 10 STATUS = NF_CREATE(filename, 0, iou) ! overwrites old IF (STATUS .NE. NF_NOERR) then PRINT *, NF_STRERROR(STATUS) print *, ' ' print *, 'retry? (y/n)' read *, yorn if (yorn.eq.'n') then stop else goto 10 endif endif cpu_time0=second() call wpunchnc(iou,net,ncnt,tim,dt1,time,dt) cpu_time1=second() STATUS = NF_CLOSE(iou) IF (STATUS .NE. NF_NOERR) PRINT *, NF_STRERROR(STATUS) write(*,*) cpu_time1-cpu_time0,' seconds to write ', filename stop end