[cdftools] 135/228: JMM : add -dep option for cdfprofile, in order to provide a vertically interpolated value of a profile
Alastair McKinstry
mckinstry at moszumanska.debian.org
Fri Jun 12 08:21:40 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 b8b6430f136b2c839a6285278136d309fed2e0c5
Author: molines <molines at 1055176f-818a-41d9-83e1-73fbe5b947c5>
Date: Wed Apr 4 10:55:10 2012 +0000
JMM : add -dep option for cdfprofile, in order to provide a vertically interpolated value of a profile
git-svn-id: http://servforge.legi.grenoble-inp.fr/svn/CDFTOOLS/trunk@583 1055176f-818a-41d9-83e1-73fbe5b947c5
---
cdfprofile.f90 | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 86 insertions(+), 13 deletions(-)
diff --git a/cdfprofile.f90 b/cdfprofile.f90
index a6c95c7..60f9872 100644
--- a/cdfprofile.f90
+++ b/cdfprofile.f90
@@ -23,6 +23,7 @@ PROGRAM cdfprofile
INTEGER(KIND=4) :: jk, jt, jvar ! dummy loop index
INTEGER(KIND=4) :: narg, iargc ! argument numbers
+ INTEGER(KIND=4) :: ijarg ! argument counter
INTEGER(KIND=4) :: ilook, jlook ! look position
INTEGER(KIND=4) :: npiglo, npjglo ! size of the domain
INTEGER(KIND=4) :: npk, npt, nvars ! vetical, time size, number of variables
@@ -31,7 +32,9 @@ PROGRAM cdfprofile
INTEGER(KIND=4) :: ncout, ierr ! ncid and error flag for cdfio
INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE :: ipk, id_varout ! vertical size and id of output variables
+ REAL(KIND=4) :: rdep ! vertical interpolation stuff
REAL(KIND=4), DIMENSION(:), ALLOCATABLE :: gdept, rprofile ! depth and profile values
+ REAL(KIND=4), DIMENSION(:), ALLOCATABLE :: gdepout ! output depth array
REAL(KIND=4), DIMENSION(:), ALLOCATABLE :: tim ! time counter
REAL(KIND=4), DIMENSION(:,:), ALLOCATABLE :: v2d, rlon, rlat ! 2d data array, longitude, latitude
REAL(KIND=4), DIMENSION(1,1) :: rdumlon, rdumlat ! dummy array for output
@@ -45,12 +48,14 @@ PROGRAM cdfprofile
TYPE(variable), DIMENSION(:), ALLOCATABLE :: stypvar_input ! structure of input data
TYPE(variable), DIMENSION(:), ALLOCATABLE :: stypvar ! structure of output data
+
+ LOGICAL :: l_vert_interp=.false. ! flag for -dep option
!!----------------------------------------------------------------------
CALL ReadCdfNames()
narg= iargc()
IF ( narg /= 4 ) THEN
- PRINT *,' usage : cdfprofile I J IN-file IN-var '
+ PRINT *,' usage : cdfprofile I J IN-file IN-var [-dep depth ]'
PRINT *,' '
PRINT *,' PURPOSE :'
PRINT *,' Extract a vertical profile at location I J, for a variable'
@@ -61,6 +66,10 @@ PROGRAM cdfprofile
PRINT *,' IN-file : input file to work with.'
PRINT *,' IN-var : variable name whose profile is requested.'
PRINT *,' '
+ PRINT *,' OPTIONS :'
+ PRINT *,' -dep depth : specify a depth where vertical value will be'
+ PRINT *,' interpolated.'
+ PRINT *,' '
PRINT *,' REQUIRED FILES :'
PRINT *,' none '
PRINT *,' '
@@ -71,11 +80,23 @@ PROGRAM cdfprofile
STOP
ENDIF
- CALL getarg (1, cldum ) ; READ(cldum,*) ilook
- CALL getarg (2, cldum ) ; READ(cldum,*) jlook
- CALL getarg (3, cf_in)
- CALL getarg (4, cv_in)
-
+ ijarg = 1
+
+ DO WHILE ( ijarg < narg )
+ CALL getarg (ijarg, cldum ) ; ijarg = ijarg+1
+ SELECT CASE ( cldum )
+ CASE ( '-dep' )
+ CALL getarg (ijarg, cldum ) ; ijarg = ijarg+1
+ READ(cldum,*) rdep
+ l_vert_interp = .true.
+ CASE DEFAULT ! read 4 successives arguments
+ READ(cldum,*) ilook
+ CALL getarg (ijarg, cldum ) ; READ(cldum,*) jlook ; ijarg = ijarg+1
+ CALL getarg (ijarg, cf_in ) ; ijarg = ijarg+1
+ CALL getarg (ijarg, cv_in ) ; ijarg = ijarg+1
+ END SELECT
+ ENDDO
+
IF ( chkfile(cf_in) ) STOP ! missing file
npiglo = getdim (cf_in, cn_x)
@@ -96,7 +117,19 @@ PROGRAM cdfprofile
rdumlon(:,:) = rlon(ilook,jlook)
rdumlat(:,:) = rlat(ilook,jlook)
- ipk(:) = npk
+ gdept(:) = getvar1d(cf_in, cv_dep, npk, ierr)
+
+ IF ( l_vert_interp ) THEN
+ ipk(:) = 1
+ ikz = 1
+ ALLOCATE ( gdepout(ikz) )
+ gdepout(1) = rdep
+ ELSE
+ ipk(:) = npk
+ ikz = npk
+ ALLOCATE ( gdepout(ikz) )
+ gdepout(:) = gdept(:)
+ ENDIF
cv_names(:) = getvarname(cf_in, nvars, stypvar_input)
@@ -107,13 +140,11 @@ PROGRAM cdfprofile
ENDIF
ENDDO
- gdept(:) = getvar1d(cf_in, cv_dep, npk, ierr)
- ikz = npk
! create output fileset
- ncout = create (cf_out, 'none', ikx, iky, npk, cdep='depth')
+ ncout = create (cf_out, 'none', ikx, iky, ikz, cdep='depth')
ierr = createvar (ncout, stypvar, nboutput, ipk, id_varout )
- ierr = putheadervar(ncout, cf_in, ikx, iky, ikz, pnavlon=rdumlon, pnavlat=rdumlat, pdep=gdept)
+ ierr = putheadervar(ncout, cf_in, ikx, iky, ikz, pnavlon=rdumlon, pnavlat=rdumlat, pdep=gdepout)
tim = getvar1d(cf_in, cn_vtimec, npt )
ierr = putvar1d(ncout, tim, npt, 'T')
@@ -123,17 +154,59 @@ PROGRAM cdfprofile
v2d(:,:) = getvar(cf_in, cv_in, jk, npiglo, npjglo, ktime=jt)
rprofile(jk) = v2d(ilook,jlook)
! netcdf output
- rdummy(1,1) = rprofile(jk)
- ierr = putvar(ncout, id_varout(1), rdummy, jk, ikx, iky, ktime=jt)
+ IF ( .NOT. l_vert_interp ) THEN
+ rdummy(1,1) = rprofile(jk)
+ ierr = putvar(ncout, id_varout(1), rdummy, jk, ikx, iky, ktime=jt)
+ ENDIF
END DO
PRINT *, 'FILE : ', TRIM(cf_in), ' TIME = ', jt
PRINT *, ' ', TRIM(cv_dep),' ', TRIM(cv_in),'(',ilook,',',jlook,')'
+ IF ( l_vert_interp ) THEN
+ rdummy(1,1) = vinterp (rprofile, gdept , rdep, npk )
+ ierr = putvar(ncout, id_varout(1), rdummy, 1, ikx, iky, ktime=jt)
+ ENDIF
+
+ ! Ascii output
DO jk=1, npk
PRINT *, gdept(jk), rprofile(jk)
END DO
+
END DO
ierr = closeout(ncout)
+CONTAINS
+ REAL(KIND=4) FUNCTION vinterp ( profile, pdept, pdep, kpk)
+ !!---------------------------------------------------------------------
+ !! *** FUNCTION vinterp ***
+ !!
+ !! ** Purpose : return the interpolated value at specified depth from
+ !! an input profile.
+ !!
+ !! ** Method : Linear interpolation
+ !!
+ !!----------------------------------------------------------------------
+ REAL(KIND=4), DIMENSION(kpk), INTENT(in) :: profile ! vertical profile
+ REAL(KIND=4), DIMENSION(kpk), INTENT(in) :: pdept ! depth array
+ REAL(KIND=4), INTENT(in) :: pdep ! required depth
+ INTEGER(KIND=4), INTENT(in) :: kpk ! number of level in the profile
+ !
+ INTEGER(KIND=4) :: jk ! loop index
+ INTEGER(KIND=4) :: ik0, ik1 ! limit index
+ REAL(KIND=8) :: dalfa ! weight
+ !!----------------------------------------------------------------------
+ ! find interpolation limits for required depth
+ DO jk = 1, kpk
+ IF ( pdept(jk) > pdep ) THEN
+ ik0 = jk - 1
+ ik1 = ik0 + 1
+ EXIT
+ ENDIF
+ ENDDO
+ dalfa = ( pdep - pdept(ik0) ) / ( pdept(ik1) - pdept(ik0) )
+ vinterp = dalfa * profile (ik1) + ( 1.d0 - dalfa ) * profile (ik0 )
+
+ END FUNCTION vinterp
+
END PROGRAM cdfprofile
--
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