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 use itg_data use io implicit none include 'netcdf.inc' ! 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 :: nsteps, nfile integer iargc,icount external iargc, getarg real second,cpu_time0, cpu_time1 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_data.f90: (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 nsteps=nstp/nfreq nfile = 1 open(unit=iou,file=filename,status='old',form='formatted') cpu_time0=second() call wread(iou,net,ncnt,tim,dt1,nsteps, nfile) 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) 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