Blame | Last modification | View Log | Download | RSS feed
PROGRAM Cutnetcdfc -----------------------------------------------------------------------c Cut and split an input netcdfc Michael Sprenger / Summer 2006c -----------------------------------------------------------------------implicit nonec -----------------------------------------------------------------------c Declaration of variablesc -----------------------------------------------------------------------c Maximum domain sizeinteger nxmax,nymax,nzmax,ntmaxparameter (nxmax=400,nymax=400,nzmax=400,ntmax=5)c Variables for input and output netcdf fileinteger cdfidreal phymin(4),phymax(4),stag(4), misdatinteger ndim, vardim(4), error, nlevinteger cstidreal dx, dyreal aklev(nzmax),bklev(nzmax),aklay(nzmax),bklay(nzmax)real pollon, pollatinteger stdate(5)integer ncdfidinteger datar(14)character*80 cfnreal varold(nxmax*nymax*nzmax)real time(ntmax)c Parameterscharacter*80 oldfile(400),newfile(400)character*80 oldname(400),newname(400)integer novarsc Auxiliary variablesinteger i,j,k,l,t,ntimesinteger imin, imax, jmin, jmax, tmin, tmaxinteger nx,ny,nzinteger crename(400),crefile(400)integer isnewcharacter*80 varnamec -----------------------------------------------------------------------c Preparationsc -----------------------------------------------------------------------print*,'*********************************************************'print*,'* cutnetcdf *'print*,'*********************************************************'c Read entries from argument fileopen(10,file='fort.10')novars=1100 read(10,*,end=110) oldname(novars),newname(novars),> oldfile(novars),newfile(novars)novars=novars+1goto 100110 close(10)novars=novars-1c Init the flags for creating files and variablesdo i=1,novarscrename(i)=0crefile(i)=0enddoc -----------------------------------------------------------------------c Loop through data pointsc -----------------------------------------------------------------------do t=1,novarsc Write infowrite(*,'(a10,a5,3x,a5,3x,a15,3x,a15)')> ' Split ',trim(oldname(t)),> trim(newname(t)),> trim(oldfile(t)),> trim(newfile(t))c Open input file and read some parametersqcall cdfopn(oldfile(t),cdfid,error)if (error.ne.0) goto 997call getcfn(cdfid,cfn,error)if (error.ne.0) goto 997call cdfopn(cfn,cstid,error)if (error.ne.0) goto 997call gettimes(cdfid, time, ntimes, error)if (error.ne.0) goto 997call getgrid(cstid, dx, dy, error)if (error.ne.0) goto 997call getlevs(cstid, nlev, aklev, bklev, aklay, bklay, error)if (error.ne.0) goto 997call getpole(cstid,pollon,pollat,error)if (error.ne.0) goto 997call getstart(cstid,stdate,error)if (error.ne.0) goto 997c Set new grid parameters and read data of subdomaincall getdef(cdfid,oldname(t),ndim,misdat,> vardim,phymin,phymax,stag,error)if (error.ne.0) goto 997nx=vardim(1)ny=vardim(2)nz=vardim(3)c Load datavarname=oldname(t)call getdat(cdfid,varname,time(1),0,varold,error)if (error.ne.0) goto 997c Create file if necessary (otherwise open it for writing)isnew=1do k=1,novarsif ((crefile(k).eq.1).and.> (newfile(t).eq.newfile(k))) thenisnew=0endifenddoif (isnew.eq.1) thencfn=trim(newfile(t))//'_cst'datar(1) = vardim(1)datar(2) = vardim(2)datar(3) = 1000.*phymax(2)datar(4) = 1000.*phymin(1)datar(5) = 1000.*phymin(2)datar(6) = 1000.*phymax(1)datar(7) = 1000.*dxdatar(8) = 1000.*dydatar(9) = nlevdatar(10) = 1datar(11) = 0datar(12) = 0datar(13) = 1000.*pollondatar(14) = 1000.*pollatcall wricst(cfn,datar,> aklev,bklev,aklay,bklay,stdate)call crecdf(trim(newfile(t)),ncdfid, phymin, phymax,> ndim,cfn,error)if (error.ne.0) goto 998elsecall cdfwopn(trim(newfile(t)),ncdfid,error)if (error.ne.0) goto 998endifdo k=1,novarsif (newfile(k).eq.newfile(t)) thencrefile(k)=1endifenddoc Create variable if necessaryisnew=1do k=1,novarsif ((newfile(t).eq.newfile(k)).and.> (newname(t).eq.newname(k)).and.> (crename(t).eq.1)) thenisnew=0endifenddoif (isnew.eq.1) thencall putdef(ncdfid, newname(t), ndim, misdat, vardim,> phymin, phymax, stag, error)if (error.ne.0) goto 998endifdo k=1,novarsif ((newname(k).eq.newname(t)).and.> (crefile(k).eq.1)) thencrename(k)=1endifenddoc Write datacall putdat(ncdfid,newname(t),time(1),0,varold,error)if (error.ne.0) goto 998c Close filescall clscdf(cdfid, error)if (error.ne.0) goto 997call clscdf(ncdfid, error)if (error.ne.0) goto 998call clscdf(cstid, error)if (error.ne.0) goto 997enddoc -----------------------------------------------------------------------c Exception handlingc -----------------------------------------------------------------------stop997 print*,'Problems with input file... Stop'stop998 print*,'Problems with output file... Stop'stopend