[cdftools] 169/228: AL : add cdfcmp and cdfchgrid + related modifications in Makefile
Alastair McKinstry
mckinstry at moszumanska.debian.org
Fri Jun 12 08:21:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
mckinstry pushed a commit to branch master
in repository cdftools.
commit a036eaaed6fd7125238f2aeca16a8bb4961acbda
Author: lecointre <lecointre at 1055176f-818a-41d9-83e1-73fbe5b947c5>
Date: Tue Sep 18 15:05:40 2012 +0000
AL : add cdfcmp and cdfchgrid + related modifications in Makefile
git-svn-id: http://servforge.legi.grenoble-inp.fr/svn/CDFTOOLS/trunk@617 1055176f-818a-41d9-83e1-73fbe5b947c5
---
Makefile | 8 ++-
cdfchgrid.f90 | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cdfcmp.f90 | 138 +++++++++++++++++++++++++++++++++++++
3 files changed, 358 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index ec7a156..0cf8e25 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ EXEC = cdfmoy cdfmoyt cdfstd cdfmoy_weighted cdfmoy_freq cdfvT \
cdfcsp cdfcoloc cdfmltmask cdfstatcoord cdfpolymask cdfsmooth cdfmkmask cdfdifmask\
cdfkempemekeepe cdfbci cdfbti cdfnrjcomp cdfcofdis cdfsections cdfnorth_unfold cdfovide cdfmppini\
cdfpsi_level cdfhdy cdfhdy3d cdffracinv cdfmaskdmp cdfnan cdfscale cdfnamelist \
- cdfisopsi cdf2matlab cdffixtime cdfgeostrophy
+ cdfisopsi cdf2matlab cdffixtime cdfgeostrophy cdfchgrid cdfcmp
.PHONY: all help clean cleanexe install man installman
@@ -406,6 +406,12 @@ cdffixtime: cdfio.o cdffixtime.f90
cdfnamelist: modcdfnames.o cdfnamelist.f90
$(F90) cdfnamelist.f90 -o $(BINDIR)/cdfnamelist modcdfnames.o $(FFLAGS) $(FDATE_FLAG)
+cdfchgrid: cdfio.o cdfchgrid.f90
+ $(F90) cdfchgrid.f90 -o $(BINDIR)/cdfchgrid cdfio.o modcdfnames.o $(FFLAGS)
+
+cdfcmp: cdfio.o cdfcmp.f90
+ $(F90) cdfcmp.f90 -o $(BINDIR)/cdfcmp cdfio.o modcdfnames.o $(FFLAGS)
+
# OLD bimg/dimg stuff: use by the trpsig monitoring....
cdfsections: eos.o cdfsections.f90
$(F90) cdfsections.f90 -o $(BINDIR)/cdfsections eos.o modcdfnames.o $(FFLAGS)
diff --git a/cdfchgrid.f90 b/cdfchgrid.f90
new file mode 100644
index 0000000..d7851c0
--- /dev/null
+++ b/cdfchgrid.f90
@@ -0,0 +1,213 @@
+PROGRAM cdfchgrid
+ !!======================================================================
+ !! *** PROGRAM cdfchgrid ***
+ !!======================================================================
+ !! ** Purpose : Transform an 1442x1021 ORCA025 grid variable into an
+ !! 4322x3059 ORCA12 grid variable.
+ !! No interpolation, only copying one grid cell into 9 grid cells.
+ !!
+ !! ** Method : Store the result on a 'cdfchgrid.nc' file similar to the input file
+ !! (except x and y dimension)
+ !!
+ !! ** Restriction : Caution for mask coherence !
+ !! This tool is only adapted for drowned field
+ !!
+ !! History : 3.0 ! 08/2012 A. Lecointre : Original code with Full Doctor form + Lic.
+ !!----------------------------------------------------------------------
+ !!----------------------------------------------------------------------
+ !! routines : description
+ !! chgrid : Convert 1442x1021 ORCA025 2D var into 4322x3059 ORCA12 var
+ !!----------------------------------------------------------------------
+ USE cdfio
+ USE modcdfnames
+ !!----------------------------------------------------------------------
+ !! CDFTOOLS_3.0 , MEOM 2011
+ !! $Id: cdfchgrid.f90 XXX YYYY-MM-DD MM:MM:SSZ molines $
+ !! Copyright (c) 2010, J.-M. Molines
+ !! Software governed by the CeCILL licence (Licence/CDFTOOLSCeCILL.txt)
+ !!----------------------------------------------------------------------
+ IMPLICIT NONE
+
+ INTEGER(KIND=4) :: jk, jt ! dummy loop index
+ INTEGER(KIND=4) :: jvar,jjvar ! dummy loop index
+ INTEGER(KIND=4) :: ierr ! working integer
+ INTEGER(KIND=4) :: narg, iargc, ijarg ! argument on line
+ INTEGER(KIND=4) :: npiglo, npjglo ! size of the input domain
+ INTEGER(KIND=4), PARAMETER :: npigloout=4322, npjgloout=3059 ! size of the output domain
+ INTEGER(KIND=4) :: npk, npt ! size of the domain
+ INTEGER(KIND=4) :: nvars ! number of variables in the input file
+ INTEGER(KIND=4) :: ncout ! ncid of output ncdf file
+ INTEGER(KIND=4), DIMENSION(1) :: ipk ! output variable : number of levels
+ INTEGER(KIND=4), DIMENSION(1) :: id_varout ! ncdf varid's
+
+ REAL(KIND=4), DIMENSION(:,:), ALLOCATABLE :: v2d ! array to read a layer of data
+ REAL(KIND=4), DIMENSION(:,:), ALLOCATABLE :: u2d ! array onto ORCA12-grid
+ REAL(KIND=4), DIMENSION(:), ALLOCATABLE :: tim ! time counter of the file
+ REAL(KIND=4), DIMENSION(:), ALLOCATABLE :: dep ! depth of the file
+
+ CHARACTER(LEN=256) :: cf_out='cdfchgrid.nc' ! output file name
+ CHARACTER(LEN=256) :: cf_in ! input file name
+ CHARACTER(LEN=256) :: cv_in ! variable name
+ CHARACTER(LEN=256) :: cldum ! working string
+ CHARACTER(LEN=256) :: cv_dep ! true name of dep dimension
+ CHARACTER(LEN=256), DIMENSION(:), ALLOCATABLE :: cv_names ! array of var name
+
+ TYPE (variable), DIMENSION(:), ALLOCATABLE :: stypvar ! structure for variable attribute
+ !!--------------------------------------------------------------------------------------------------------------
+ CALL ReadCdfNames()
+
+ narg = iargc()
+ IF ( narg == 0 ) THEN
+ PRINT *,' usage : cdfchgrid -f IN-file -var IN-var'
+ PRINT *,' '
+ PRINT *,' PURPOSE :'
+ PRINT *,' Convert ORCA025-grid variable into ORCA12-grid variable'
+ PRINT *,' No interpolation, only copying one grid cell into nine grid cells'
+ PRINT *,' '
+ PRINT *,' RESTRICTION :'
+ PRINT *,' Caution for mask coherence !'
+ PRINT *,' This tool is only adapted for drowned field'
+ PRINT *,' '
+ PRINT *,' ARGUMENTS :'
+ PRINT *,' -f IN-var : input ORCA025-grid file'
+ PRINT *,' -var IN-var : input ORCA025-grid variable to be converted'
+ PRINT *,' '
+ PRINT *,' REQUIRED FILES :'
+ PRINT *,' none '
+ PRINT *,' '
+ PRINT *,' OUTPUT : '
+ PRINT *,' netcdf file : ', TRIM(cf_out)
+ PRINT *,' variable : same name as in input file'
+ STOP
+ ENDIF
+ !!
+ ijarg = 1
+ ! Read command line
+ DO WHILE (ijarg <= narg)
+ CALL getarg(ijarg,cldum) ; ijarg = ijarg + 1
+ SELECT CASE ( cldum )
+ CASE ( '-f' )
+ CALL getarg(ijarg, cf_in) ; ijarg = ijarg + 1
+ CASE ( '-var' )
+ CALL getarg(ijarg,cv_in) ; ijarg = ijarg + 1
+ CASE DEFAULT
+ PRINT *, TRIM(cldum),' : unknown option '
+ STOP
+ END SELECT
+ END DO
+
+ IF ( chkfile(cf_in) ) STOP ! missing files
+
+ ! get domain dimension from input file
+ npiglo = getdim (cf_in, cn_x)
+ npjglo = getdim (cf_in, cn_y)
+ npk = getdim (cf_in, cn_z, cdtrue=cv_dep, kstatus=ierr) ! defautl cn_z is depth
+ npt = getdim (cf_in, cn_t)
+
+ IF ( npk == 0 ) npk = 1 ! assume a 2D variable
+ IF ( npt == 0 ) npt = 1 ! assume a 1 time frame file
+
+ PRINT *, 'npiglo = ', npiglo
+ PRINT *, 'npjglo = ', npjglo
+ PRINT *, 'npk = ', npk
+ PRINT *, 'npt = ', npt
+
+ ALLOCATE ( v2d(npiglo,npjglo) )
+ ALLOCATE ( u2d(npigloout,npjgloout) )
+ ALLOCATE ( tim(npt) )
+ ALLOCATE ( dep(npk) )
+
+ ! look for the number of variables in the input file
+ nvars = getnvar(cf_in)
+ ALLOCATE (cv_names(nvars) ,stypvar(nvars))
+ cv_names(:)=getvarname(cf_in,nvars,stypvar)
+
+ ! find the number of variable we are interested in
+ jvar=0
+ DO WHILE (jvar <= nvars)
+ jvar=jvar+1
+ IF ( cv_names(jvar) == cv_in ) jjvar=jvar
+ END DO
+ ipk(1)=npk
+ ncout = create (cf_out, cf_in , npigloout, npjgloout, npk )
+ ierr = createvar (ncout , stypvar(jjvar), 1 , ipk , id_varout )
+
+ ! get time and write time and get deptht and write deptht
+ tim=getvar1d(cf_in,cn_t,npt) ; ierr=putvar1d(ncout,tim,npt,'T')
+ dep=getvar1d(cf_in,cv_dep,npk) ; ierr=putvar1d(ncout,dep,npk,'D')
+
+ PRINT *,' Working with ', TRIM(cv_in), npk
+ DO jt = 1, npt
+ DO jk = 1, npk
+ v2d(:,:) = getvar(cf_in, cv_in, jk, npiglo, npjglo, ktime=jt)
+ PRINT *,'level ',jk, 'time ',jt
+ CALL chgrid(v2d,u2d,'025to12')
+ ierr = putvar ( ncout , id_varout(1), REAL(u2d), jk, npigloout, npjgloout, ktime=jt)
+ ENDDO
+ ENDDO
+
+ ierr = closeout(ncout)
+
+CONTAINS
+
+ SUBROUTINE chgrid (invar,outvar,cc)
+
+ REAL(KIND=4), DIMENSION(npiglo,npjglo), INTENT(in) :: invar
+ REAL(KIND=4), DIMENSION(npigloout,npjgloout), INTENT(out) :: outvar
+ CHARACTER(LEN=*), INTENT(in) :: cc
+ INTEGER(KIND=4) :: iin,jin,iout,jout ! dummy loop index
+
+ SELECT CASE (cc)
+ CASE ('025to12')
+ DO iin = 2, 1441
+ iout=3*iin-4
+ jin=1 ! Fill only NORTH and EAST and WEST
+ jout=3*jin-2
+ outvar(iout ,jout ) = invar(iin,jin)
+ outvar(iout ,jout+1) = invar(iin,jin)
+ outvar(iout-1,jout ) = invar(iin,jin)
+ outvar(iout+1,jout ) = invar(iin,jin)
+ outvar(iout+1,jout+1) = invar(iin,jin)
+ outvar(iout-1,jout+1) = invar(iin,jin)
+ DO jin = 2, 1020 ! Fill all: NORTH and SOUTH and EAST and WEST
+ jout=3*jin-2
+ outvar(iout ,jout ) = invar(iin,jin)
+ outvar(iout+1,jout ) = invar(iin,jin)
+ outvar(iout-1,jout ) = invar(iin,jin)
+ outvar(iout ,jout-1) = invar(iin,jin)
+ outvar(iout ,jout+1) = invar(iin,jin)
+ outvar(iout+1,jout+1) = invar(iin,jin)
+ outvar(iout+1,jout-1) = invar(iin,jin)
+ outvar(iout-1,jout+1) = invar(iin,jin)
+ outvar(iout-1,jout-1) = invar(iin,jin)
+ ENDDO
+ ENDDO
+ iin=1442
+ iout=3*iin-4
+ jin=1 ! Fill only NORTH and WEST
+ jout=3*jin-2
+ outvar(iout ,jout ) = invar(iin,jin)
+ outvar(iout ,jout+1) = invar(iin,jin)
+ outvar(iout-1,jout ) = invar(iin,jin)
+ outvar(iout-1,jout+1) = invar(iin,jin)
+ DO jin = 2, 1020 ! Fill only NORTH and SOUTH and WEST
+ jout=3*jin-2
+ outvar(iout ,jout ) = invar(iin,jin)
+ outvar(iout ,jout-1) = invar(iin,jin)
+ outvar(iout ,jout+1) = invar(iin,jin)
+ outvar(iout-1,jout ) = invar(iin,jin)
+ outvar(iout-1,jout-1) = invar(iin,jin)
+ outvar(iout-1,jout+1) = invar(iin,jin)
+ ENDDO
+ CASE ('05to025')
+ ! to do ...
+ CASE ('05to12')
+ ! to do ...
+ CASE DEFAULT
+ PRINT *, TRIM(cc),' is not recognized !'
+ PRINT *, 'No conversion will be performed'
+ END SELECT
+
+ END SUBROUTINE chgrid
+
+END PROGRAM cdfchgrid
diff --git a/cdfcmp.f90 b/cdfcmp.f90
new file mode 100644
index 0000000..05d7d7d
--- /dev/null
+++ b/cdfcmp.f90
@@ -0,0 +1,138 @@
+PROGRAM cdfcmp
+ !!======================================================================
+ !! *** PROGRAM cdfcmp ***
+ !!======================================================================
+ !! ** Purpose : Find the differences between one same variable in two different files
+ !! Indicate where are located these differences
+ !! Indicate the relative difference
+ !!
+ !! ** Method : Compare var1 and var2
+ !! If it differs, print in standard output where are located diff
+ !! Spatial sub-area restriction can be defined
+ !!
+ !! History : 3.0 ! 08/2012 A. Lecointre : Original code + Full Doctor form + Lic.
+ !!----------------------------------------------------------------------
+ USE cdfio
+ USE modcdfnames
+ !!----------------------------------------------------------------------
+ !! CDFTOOLS_3.0 , MEOM 2011
+ !! $Id: cdfcmp.f90 XXX YYYY-MM-DD HH:MM:SSZ molines $
+ !! Copyright (c) 2010, J.-M. Molines
+ !! Software governed by the CeCILL licence (Licence/CDFTOOLSCeCILL.txt)
+ !!----------------------------------------------------------------------
+ IMPLICIT NONE
+
+ INTEGER(KIND=4) :: jk,jj,ji, jvar, jjvar ! dummy loop index
+ INTEGER(KIND=4) :: ierr ! working integer
+ INTEGER(KIND=4) :: narg, iargc, ijarg ! argument on line
+ INTEGER(KIND=4) :: npiglo, npjglo ! size fo the domain
+ INTEGER(KIND=4) :: iimin=1, iimax=0 ! i-limit of the domain
+ INTEGER(KIND=4) :: ijmin=1, ijmax=0 ! j-limit of the domain
+ INTEGER(KIND=4) :: ikmin=1, ikmax=0 ! k-limit of the domain
+ INTEGER(KIND=4) :: nvars ! Number of variables in a file
+ INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE :: ipk ! arrays of var id's
+ REAL(KIND=4), DIMENSION(:,:), ALLOCATABLE :: var1, var2 ! variables to compare
+ REAL(KIND=4) :: dvar ! relative difference
+ CHARACTER(LEN=256) :: cf1_in,cf2_in ! input file name
+ CHARACTER(LEN=256) :: cv_in ! variable name
+ CHARACTER(LEN=256) :: cldum ! working string
+ CHARACTER(LEN=256), DIMENSION(:), ALLOCATABLE :: cv_names ! array of var name
+ TYPE (variable), DIMENSION(:), ALLOCATABLE :: stypvar ! Type variable is defined in cdfio.
+
+ !!--------------------------------------------------------------------------------------------------------------
+ CALL ReadCdfNames()
+
+ narg = iargc()
+ IF ( narg == 0 ) THEN
+ PRINT *,' usage : cmp_var -f1 IN-file1 -f2 IN-file2 -var IN-var ...'
+ PRINT *,' ... [-lev kmin kmax ] [-zoom imin imax jmin jmax] ...'
+ PRINT *,' '
+ PRINT *,' PURPOSE :'
+ PRINT *,' Find where IN-var is different between IN-file1 and IN-file2 '
+ PRINT *,' Options allow to restrict the finding to a sub area in space'
+ PRINT *,' '
+ PRINT *,' ARGUMENTS :'
+ PRINT *,' -f1 IN-file1 : input file1'
+ PRINT *,' -f2 IN-file2 : input file2'
+ PRINT *,' -var IN-var : input variable'
+ PRINT *,' '
+ PRINT *,' OPTIONS :'
+ PRINT *,' [-lev kmin kmax ] : restrict to level between kmin and kmax. '
+ PRINT *,' [-zoom imin imax jmin jmax] : restrict to sub area specified'
+ PRINT *,' by the given limits. '
+ PRINT *,' '
+ PRINT *,' REQUIRED FILES :'
+ PRINT *,' none '
+ PRINT *,' '
+ PRINT *,' OUTPUT : '
+ PRINT *,' output is done on standard output.'
+ STOP
+ ENDIF
+ !!
+ ijarg = 1
+ ! Read command line
+ DO WHILE (ijarg <= narg)
+ CALL getarg(ijarg,cldum) ; ijarg = ijarg + 1
+ SELECT CASE ( cldum )
+ CASE ( '-f1' )
+ CALL getarg(ijarg, cf1_in) ; ijarg = ijarg + 1
+ CASE ( '-f2' )
+ CALL getarg(ijarg, cf2_in) ; ijarg = ijarg + 1
+ CASE ( '-var' )
+ CALL getarg(ijarg,cv_in) ; ijarg = ijarg + 1
+ CASE ( '-lev' )
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) ikmin
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) ikmax
+ CASE ( '-zoom' )
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) iimin
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) iimax
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) ijmin
+ CALL getarg(ijarg, cldum) ; ijarg = ijarg + 1 ; READ(cldum,*) ijmax
+ CASE DEFAULT
+ PRINT *, TRIM(cldum),' : unknown option '
+ STOP
+ END SELECT
+ END DO
+
+ IF ( chkfile(cf1_in) .OR. chkfile(cf2_in) ) STOP ! missing file
+ IF ( chkvar(cf1_in, cv_in) .OR. chkvar(cf2_in, cv_in) ) STOP ! missing var
+
+ npiglo = getdim (cf1_in, cn_x)
+ npjglo = getdim (cf1_in, cn_y)
+ IF ( iimax == 0 ) iimax = npiglo
+ IF ( ijmax == 0 ) ijmax = npjglo
+
+ ! get the number of vertical levels of cv_in variable
+ nvars = getnvar(cf1_in)
+ ALLOCATE (ipk(nvars),cv_names(nvars),stypvar(nvars))
+ cv_names(:)=getvarname(cf1_in,nvars,stypvar)
+ ipk(:) = getipk (cf1_in,nvars)
+ DO jvar=1,nvars
+ IF ( cv_names(jvar) == cv_in ) jjvar=jvar
+ ENDDO
+ IF ( ikmax == 0 ) ikmax = ipk(jjvar)
+
+ ! Allocate memory.
+ ALLOCATE(var1(npiglo, npjglo))
+ ALLOCATE(var2(npiglo, npjglo))
+
+ PRINT *,' Working with ', TRIM(cv_in),' defined on ', ipk(jjvar),' level(s)'
+ DO jk = ikmin, ikmax
+ PRINT *,'# -------------------------------------------'
+ PRINT '(A19,I3)','# Checking level: ',jk
+ PRINT *,'# i j k var1 var2 %reldiff'
+ var1(:,:)=9999.0
+ var2(:,:)=9999.0
+ var1(:,:) = getvar(cf1_in, cv_in, jk, npiglo, npjglo)
+ var2(:,:) = getvar(cf2_in, cv_in, jk, npiglo, npjglo)
+ DO jj=ijmin, ijmax
+ DO ji=iimin, iimax
+ IF ( var1(ji,jj) /= var2(ji,jj) ) THEN
+ dvar = 100.0*(var1(ji,jj)-var2(ji,jj))/var1(ji,jj)
+ PRINT '(I4,2X,I4,2X,I3,2X,F8.3,2X,F8.3,2X,F8.3)',ji,jj,jk,var1(ji,jj),var2(ji,jj),dvar
+ ENDIF
+ ENDDO
+ ENDDO
+ ENDDO
+
+END PROGRAM cdfcmp
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cdftools.git
More information about the debian-science-commits
mailing list