Skip to content

Commit

Permalink
added the model configuration as global attribute to the output file
Browse files Browse the repository at this point in the history
  • Loading branch information
arezoorn committed May 8, 2018
1 parent 812f0f1 commit a9d30fc
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion trunk/NDHMS/Routing/module_NWM_io.F
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module module_NWM_io
! Module-wide variables
integer, private :: ftnNoahMP ! Private NetCDF file handle since output routine
! called multiple times for one file.

contains

!==============================================================================
Expand All @@ -31,6 +30,35 @@ module module_NWM_io
!
! User controllable options: None.

function GetModelConfigType (io_config_outputs) result(modelConfigType)
integer io_config_outputs
character (len=64) :: modelConfigType
if (io_config_outputs .eq. 0) then
! All
modelConfigType = "default"
else if (io_config_outputs .eq. 1) then
! Analysis and Assimilation
modelConfigType = "analysis_and_assimilation"
else if (io_config_outputs .eq. 2) then
! Short Range
modelConfigType = "short_range"
else if (io_config_outputs .eq. 3) then
! Medium Range
modelConfigType = "medium_range"
else if (io_config_outputs .eq. 4) then
! Long Range
modelConfigType = "long_range"
else if (io_config_outputs .eq. 5) then
! Retrospective
modelConfigType = "retrospective"
else if (io_config_outputs .eq. 6) then
! Diagnostic
modelConfigType = "diagnostic"
else
! call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif
END

subroutine output_chrt_NWM(domainId)
use module_rt_data, only: rt_domain
use module_namelist, only: nlst_rt
Expand Down Expand Up @@ -105,6 +133,8 @@ subroutine output_chrt_NWM(domainId)
real, allocatable, dimension(:,:) :: varMetaReal
integer, allocatable, dimension(:,:) :: varMetaInt

character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

! Initialize the ascFlag to 1
ascFlag = 1

Expand Down Expand Up @@ -175,6 +205,9 @@ subroutine output_chrt_NWM(domainId)
call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif

! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)

! First step is to collect and assemble all data that will be written to the
! NetCDF file. If we are not using MPI, we bypass the collection step through
! MPI.
Expand Down Expand Up @@ -622,6 +655,8 @@ subroutine output_chrt_NWM(domainId)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')

! Create global attributes specific to running output through the
! channel-only configuration of the model.
Expand Down Expand Up @@ -1018,6 +1053,8 @@ subroutine output_NoahMP_NWM(outDir,iGrid,output_timestep,startdate,date,ixPar,j
real, allocatable, dimension(:,:) :: globalRealTmp
real*8, allocatable, dimension(:) :: yCoord,xCoord,yCoord2
real, allocatable, dimension(:,:,:) :: varRealTmp
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs
#ifdef MPP_LAND
mppFlag = 1
Expand Down Expand Up @@ -1145,6 +1182,9 @@ subroutine output_NoahMP_NWM(outDir,iGrid,output_timestep,startdate,date,ixPar,j
call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif
! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)
! Sync all processes up.
if(mppFlag .eq. 1) then
#ifdef MPP_LAND
Expand Down Expand Up @@ -1185,6 +1225,8 @@ subroutine output_NoahMP_NWM(outDir,iGrid,output_timestep,startdate,date,ixPar,j
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')
iret = nf90_put_att(ftnNoahMP,NF90_GLOBAL,"proj4",trim(fileMeta%proj4))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create proj4 attribute')
iret = nf90_put_att(ftnNoahMP,NF90_GLOBAL,"GDAL_DataType","Generic")
Expand Down Expand Up @@ -1626,6 +1668,7 @@ subroutine output_rt_NWM(domainId,iGrid)
real, allocatable, dimension(:,:,:) :: globalOutReal
real*8, allocatable, dimension(:) :: yCoord,xCoord,yCoord2
integer :: numLev ! This will be 4 for soil moisture, and 1 for all other variables.
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs
! Establish macro variables to hlep guide this subroutine.
#ifdef MPP_LAND
Expand Down Expand Up @@ -1686,6 +1729,9 @@ subroutine output_rt_NWM(domainId,iGrid)
call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif
! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)
! Calculate datetime information.
! First compose strings of EPOCH and simulation start date.
epochDate = trim("1970-01-01 00:00")
Expand Down Expand Up @@ -1741,6 +1787,8 @@ subroutine output_rt_NWM(domainId,iGrid)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"proj4",trim(fileMeta%proj4))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create proj4 attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"GDAL_DataType","Generic")
Expand Down Expand Up @@ -2169,6 +2217,8 @@ subroutine output_lakes_NWM(domainId,iGrid)
! scale_factor/add_offset
! have been applied.
integer, allocatable, dimension(:) :: chIndArray ! Array of index values for
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

!each channel point. feature_id will need to be sorted in ascending order once
!data is collected into the global array. From there, the index values are
!re-sorted, and used to re-sort output arrays.
Expand Down Expand Up @@ -2235,6 +2285,9 @@ subroutine output_lakes_NWM(domainId,iGrid)
call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif

! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)

! First step is to collect and assemble all data that will be written to the
! NetCDF file. If we are not using MPI, we bypass the collection step through
! MPI.
Expand Down Expand Up @@ -2427,6 +2480,8 @@ subroutine output_lakes_NWM(domainId,iGrid)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')

! Create dimensions
iret = nf90_def_dim(ftn,"feature_id",gSize,dimId(1))
Expand Down Expand Up @@ -2771,6 +2826,8 @@ subroutine output_chrtout_grd_NWM(domainId,iGrid)
! allocatable arrays to hold coordinate values
real*8, allocatable, dimension(:) :: yCoord,xCoord,yCoord2

character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

! Establish macro variables to hlep guide this subroutine.
#ifdef MPP_LAND
mppFlag = 1
Expand Down Expand Up @@ -2896,6 +2953,9 @@ subroutine output_chrtout_grd_NWM(domainId,iGrid)
nlst_rt(domainId)%olddate(12:13)//&
nlst_rt(domainId)%olddate(15:16), igrid
! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)
if(myId .eq. 0) then
! Create output NetCDF file for writing.
iret = nf90_create(trim(output_flnm),cmode=nf90_hdf5,ncid = ftn)
Expand All @@ -2912,6 +2972,8 @@ subroutine output_chrtout_grd_NWM(domainId,iGrid)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"proj4",trim(fileMeta%proj4))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create proj4 attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"GDAL_DataType","Generic")
Expand Down Expand Up @@ -3248,6 +3310,8 @@ subroutine output_lsmOut_NWM(domainId)
real, allocatable, dimension(:,:) :: localRealTmp, globalOutReal
!integer, allocatable, dimension(:,:) :: globalCompTmp, localCompTmp

character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

#ifdef MPP_LAND
mppFlag = 1
#else
Expand Down Expand Up @@ -3327,6 +3391,9 @@ subroutine output_lsmOut_NWM(domainId)
! diagnostic in nature.
fileMeta%outFlag(:) = [1,1,1,1,1,1,1,1,1,1,1,1,1,1]

! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)

! Sync all processes up.
if(mppFlag .eq. 1) then
#ifdef MPP_LAND
Expand Down Expand Up @@ -3357,6 +3424,8 @@ subroutine output_lsmOut_NWM(domainId)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"proj4",trim(fileMeta%proj4))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create proj4 attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"GDAL_DataType","Generic")
Expand Down Expand Up @@ -3710,6 +3779,7 @@ subroutine output_frxstPts(domainId)
integer, allocatable, dimension(:) :: frxstPtsLocal, g_STRMFRXSTPTSOut
real, allocatable, dimension(:) :: g_chlatOut, g_chlonOut, g_hlinkOut
integer, allocatable, dimension(:) :: g_linkid, g_linkidOut
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

#ifdef MPP_LAND
mppFlag = 1
Expand Down Expand Up @@ -4019,6 +4089,7 @@ subroutine output_chanObs_NWM(domainId)
! have been applied.
integer, allocatable, dimension(:) :: g_STRMFRXSTPTS, g_outInd
integer, allocatable, dimension(:) :: frxstPtsLocal, g_STRMFRXSTPTSOut
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs

! Establish macro variables to hlep guide this subroutine.
#ifdef WRF_HYDRO_NUDGING
Expand Down Expand Up @@ -4280,6 +4351,9 @@ subroutine output_chanObs_NWM(domainId)
! Mask out missing values
where ( varOutReal == fileMeta%modelNdv ) varOutReal = -9999.0

! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)

! Create NetCDF for output.
iret = nf90_create(trim(output_flnm),cmode=nf90_hdf5,ncid = ftn)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create CHANOBS NetCDF file.')
Expand Down Expand Up @@ -4307,6 +4381,8 @@ subroutine output_chanObs_NWM(domainId)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')

! Create global attributes specific to running output through the
! channel-only configuration of the model.
Expand Down Expand Up @@ -4696,6 +4772,7 @@ subroutine output_gw_NWM(domainId,iGrid)
integer, allocatable, dimension(:) :: varOutInt ! Array holding output variables after
! scale_factor/add_offset
! have been applied.
character (len=64) :: modelConfigType ! This is character verion (long name) for the io_config_outputs
! Establish macro variables to hlep guide this subroutine.
#ifdef MPP_LAND
Expand Down Expand Up @@ -4756,6 +4833,9 @@ subroutine output_gw_NWM(domainId,iGrid)
call nwmCheck(diagFlag,1,'ERROR: Invalid IOC flag provided by namelist file.')
endif
! call the GetModelConfigType function
modelConfigType = GetModelConfigType(nlst_rt(1)%io_config_outputs)
gnbasns = rt_domain(domainId)%gnumbasns
gSize = gnbasns
Expand Down Expand Up @@ -4898,6 +4978,8 @@ subroutine output_gw_NWM(domainId,iGrid)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_version attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_output_type",trim(fileMeta%modelOutputType))
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_output_type attribute')
iret = nf90_put_att(ftn,NF90_GLOBAL,"model_configuration",modelConfigType)
call nwmCheck(diagFlag,iret,'ERROR: Unable to create model_configuration attribute')
! Create dimensions
iret = nf90_def_dim(ftn,"feature_id",gSize,dimId(1))
Expand Down

0 comments on commit a9d30fc

Please sign in to comment.