From a9d30fc7c242a30f40411d42564a55ee6b3ea4ea Mon Sep 17 00:00:00 2001 From: arezoorn Date: Tue, 8 May 2018 06:46:45 -0600 Subject: [PATCH] added the model configuration as global attribute to the output file --- trunk/NDHMS/Routing/module_NWM_io.F | 84 ++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/trunk/NDHMS/Routing/module_NWM_io.F b/trunk/NDHMS/Routing/module_NWM_io.F index 00ddb9850..5f7bdd023 100644 --- a/trunk/NDHMS/Routing/module_NWM_io.F +++ b/trunk/NDHMS/Routing/module_NWM_io.F @@ -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 !============================================================================== @@ -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 @@ -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 @@ -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. @@ -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. @@ -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 @@ -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 @@ -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") @@ -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 @@ -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") @@ -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") @@ -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. @@ -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. @@ -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)) @@ -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 @@ -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) @@ -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") @@ -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 @@ -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 @@ -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") @@ -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 @@ -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 @@ -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.') @@ -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. @@ -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 @@ -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 @@ -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))