[Dart-dev] [5601] DART/branches/development/observations: apparently there are versions of the wind profiler files which use
nancy at ucar.edu
nancy at ucar.edu
Thu Mar 15 14:19:27 MDT 2012
Revision: 5601
Author: nancy
Date: 2012-03-15 14:19:27 -0600 (Thu, 15 Mar 2012)
Log Message:
-----------
apparently there are versions of the wind profiler files which use
different names for the lat/lon/elev arrays in the netcdf files.
also the time of the obs. make a routine which tries both known
names and is extensible in case they change the names yet again.
as far as i can see there is no way to figure out which ones are
being used other than trying to see if an array with that name
exists. added a new routine in the utilities mod that tries each
name in a list one by one and returns the index of the first one
found. minor commit to the dewpoint obs error module - one of
the error messages was going to report the wrong subroutine name.
no code changes; error msg contents only.
Modified Paths:
--------------
DART/branches/development/observations/MADIS/convert_madis_profiler.f90
DART/branches/development/observations/obs_error/dewpoint_obs_err_mod.f90
DART/branches/development/observations/utilities/obs_utilities_mod.f90
-------------- next part --------------
Modified: DART/branches/development/observations/MADIS/convert_madis_profiler.f90
===================================================================
--- DART/branches/development/observations/MADIS/convert_madis_profiler.f90 2012-03-15 19:44:45 UTC (rev 5600)
+++ DART/branches/development/observations/MADIS/convert_madis_profiler.f90 2012-03-15 20:19:27 UTC (rev 5601)
@@ -45,7 +45,7 @@
use obs_kind_mod, only : PROFILER_U_WIND_COMPONENT, PROFILER_V_WIND_COMPONENT
use obs_utilities_mod, only : getvar_real, get_or_fill_QC, add_obs_to_seq, &
create_3d_obs, getvar_int, getdimlen, getvar_real_2d, &
- getvar_int_2d
+ getvar_int_2d, query_varname
use netcdf
@@ -60,7 +60,7 @@
num_qc = 1 ! number of QC entries
-integer :: ncid, nsta, nlev, n, i, oday, osec, nused, j, k
+integer :: ncid, nsta, nlev, n, i, oday, osec, nused, j, k, index
logical :: file_exist, first_obs
real(r8) :: uwnd_miss, vwnd_miss
@@ -75,6 +75,7 @@
type(obs_type) :: obs, prev_obs
type(time_type) :: comp_day0, time_obs, prev_time
+character(len=NF90_MAX_NAME) :: namelist(5)
!------------
! start of executable code
@@ -106,13 +107,35 @@
allocate(levs(nlev,nsta))
! read in the data arrays
-call getvar_real(ncid, "staLat", lat ) ! station latitude
-call getvar_real(ncid, "staLon", lon ) ! station longitude
-call getvar_real(ncid, "staElev", elev ) ! station elevation
+
+! we have profiler data files which have different names for the
+! lat/lon/elev/obs arrays in the netcdf file. there doesn't seem
+! to be a global attr to say which one is in use, so for now try
+! both options.
+
+namelist(1) = 'staLat'
+namelist(2) = 'latitude'
+call query_varname(ncid, 2, namelist, index, force=.true.)
+call getvar_real(ncid, namelist(index), lat ) ! station latitude
+
+namelist(1) = 'staLon'
+namelist(2) = 'longitude'
+call query_varname(ncid, 2, namelist, index, force=.true.)
+call getvar_real(ncid, namelist(index), lon ) ! station longitude
+
+namelist(1) = 'staElev'
+namelist(2) = 'elevation'
+call query_varname(ncid, 2, namelist, index, force=.true.)
+call getvar_real(ncid, namelist(index), elev ) ! station elevation
+
+namelist(1) = 'timeObs'
+namelist(2) = 'observationTime'
+call query_varname(ncid, 2, namelist, index, force=.true.)
+call getvar_real(ncid, namelist(index), tobs ) ! observation time
+
call getvar_real_2d(ncid, "levels", levs ) ! height above station in meters
call getvar_real_2d(ncid, "uComponent", uwnd, uwnd_miss) ! e-w component
call getvar_real_2d(ncid, "vComponent", vwnd, uwnd_miss) ! n-s component
-call getvar_real(ncid, "timeObs", tobs ) ! observation time
! if user says to use them, read in QCs if present
if (use_input_qc) then
Modified: DART/branches/development/observations/obs_error/dewpoint_obs_err_mod.f90
===================================================================
--- DART/branches/development/observations/obs_error/dewpoint_obs_err_mod.f90 2012-03-15 19:44:45 UTC (rev 5600)
+++ DART/branches/development/observations/obs_error/dewpoint_obs_err_mod.f90 2012-03-15 20:19:27 UTC (rev 5601)
@@ -105,7 +105,7 @@
if ( ( dewpt > tmpk ) ) then
- print*,'dewpt_error_from_rh_and_temp: bad dewpt ',dewpt, tmpk
+ print*,'rh_error_from_dewpt_and_temp: bad dewpt ',dewpt, tmpk
stop
end if
Modified: DART/branches/development/observations/utilities/obs_utilities_mod.f90
===================================================================
--- DART/branches/development/observations/utilities/obs_utilities_mod.f90 2012-03-15 19:44:45 UTC (rev 5600)
+++ DART/branches/development/observations/utilities/obs_utilities_mod.f90 2012-03-15 20:19:27 UTC (rev 5601)
@@ -12,7 +12,7 @@
use types_mod, only : r8, MISSING_R8, MISSING_I
-use utilities_mod, only : nc_check
+use utilities_mod, only : nc_check, E_MSG, E_ERR, error_handler
use obs_def_mod, only : obs_def_type, set_obs_def_time, set_obs_def_kind, &
set_obs_def_error_variance, set_obs_def_location, &
get_obs_def_time, get_obs_def_location, &
@@ -44,12 +44,18 @@
getvar_int_1d_1val, &
getvar_real_2d_slice, &
get_or_fill_QC_2d_slice, &
+ query_varname, &
set_missing_name
! module global storage
character(len=NF90_MAX_NAME) :: missing_name = ''
+! version controlled file description for error handling, do not edit
+character(len=128), parameter :: &
+ source = "$URL$", &
+ revision = "$Revision$", &
+ revdate = "$Date$"
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -236,14 +242,11 @@
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
-! set_missing_name - subroutine that inquires, gets the variable, and fills
-! in the missing value attribute if that arg is present.
-! gets the entire array, no start or count specified.
+! set_missing_name - subroutine that sets the name of the attribute
+! that describes missing values. in some cases it is _FillValue
+! but in others it is something nonstandard like 'missing_value'.
!
-! ncid - open netcdf file handle
-! varname - string name of netcdf variable
-! darray - output array. real(r8)
-! dmiss - value that signals a missing value real(r8), optional
+! name - string name of attribute that holds the missing value
!
! created 11 Mar 2010, nancy collins, ncar/image
!
@@ -851,5 +854,58 @@
end subroutine get_or_fill_QC_2d_slice
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! query_varname - given a list of variable names, check the netcdf file
+! for their existence. if none of the given names are in the
+! file, return -1 for index. otherwise return the index of
+! the first name found. an optional arg can be used to force
+! it to fail if a match is not found.
+!
+! ncid - open netcdf file handle
+! nname - number of names in the namelist array
+! namelist - string array of netcdf variable names to test
+! index - index of first name which matched an array. -1 if none.
+! force - if true, one of the names must match or it is a fatal error.
+!
+! created Mar 15, 2012 nancy collins, ncar/image
+!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+subroutine query_varname(ncid, nnames, namelist, index, force)
+ integer, intent(in) :: ncid, nnames
+ character(len = *), intent(in) :: namelist(:)
+ integer, intent(out) :: index
+ logical, optional, intent(in) :: force
+integer :: varid, nfrc, i
+character(128) :: msgstring
+
+! test to see if variable is present. if yes, read it in.
+! otherwise, set to fill value, or 0 if none given.
+
+index = -1
+do i=1, nnames
+ nfrc = nf90_inq_varid(ncid, namelist(i), varid)
+ if (nfrc == NF90_NOERR) then
+ index = i
+ return
+ endif
+enddo
+
+if (present(force)) then
+ if (index == -1 .and. force) then
+ msgstring = 'trying to find one of the following arrays in the input netcdf file'
+ call error_handler(E_MSG, 'query_varname', msgstring)
+ do i=1, nnames
+ call error_handler(E_MSG, 'query_varname', namelist(i))
+ enddo
+ call error_handler(E_ERR, 'query_varname', 'fatal error, none are present', &
+ source, revision, revdate)
+
+ endif
+endif
+
+end subroutine query_varname
+
+
end module obs_utilities_mod
More information about the Dart-dev
mailing list