Commit 1e64ebda authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

NetCDF: add deflate and precision option for output NetCDF files

parent 95f03e49
! Emacs: -*- mode: f90 -*-
!1) First give the timestep for writing gridded model outputs
! It should be integer and has to be perfectly divisible
! It should be integer and has to be perfectly divisible
! by the number of total modeling time steps
!2) Define main outputs of the model as namelist
! the particular output flag is specified as .TRUE. / .FALSE
......@@ -9,6 +9,10 @@
! SYNTAX = ".TRUE." or ".FALSE."
&NLoutputResults
!
! NetCDF output settings
output_deflate_level = 6
output_double_precision = .true.
!
! switch to control write out frequency of the gridded model outputs below
! >0: after each <timeStep_model_outputs> time steps
! 0: only at end of run
......@@ -30,14 +34,14 @@ outputFlxState(2)=.TRUE.
! soil water content in the single layers (L1_soilMoist) -- case 3
outputFlxState(3)=.TRUE.
!
! volumetric soil moisture in the single
! volumetric soil moisture in the single
! layers (L1_soilMoist / L1_soilMoistSat )
! [mm/mm] -- case 4
!
!
outputFlxState(4)=.TRUE.
!
! mean volumetric soil moisture averaged
! over all soil layers (L1_soilMoist / L1_soilMoistSat )
! mean volumetric soil moisture averaged
! over all soil layers (L1_soilMoist / L1_soilMoistSat )
! [mm/mm] -- case 5
outputFlxState(5)=.TRUE.
!
......@@ -59,10 +63,10 @@ outputFlxState(18)=.FALSE.
!----------------
!
! potential evapotranspiration PET [mm/T] -- case 9
outputFlxState(9)=.TRUE.
outputFlxState(9)=.TRUE.
!
! actual evapotranspiration aET [mm/T] -- case 10
outputFlxState(10)=.TRUE.
outputFlxState(10)=.TRUE.
!
! total discharge generated per cell (L1_total_runoff) [mm/T] -- case 11
outputFlxState(11)=.TRUE.
......@@ -86,7 +90,7 @@ outputFlxState(16)=.TRUE.
outputFlxState(17)=.FALSE.
!
! actual evapotranspiration from the soil layers [mm/T] -- case 19
outputFlxState(19)=.TRUE.
outputFlxState(19)=.TRUE.
!
! effective precipitation (L1_preEffect) [mm/T] -- case 20
outputFlxState(20)=.TRUE.
......
......@@ -9,6 +9,10 @@
! SYNTAX = ".TRUE." or ".FALSE."
&NLoutputResults
!
! NetCDF output settings
output_deflate_level_mrm = 6
output_double_precision_mrm = .true.
!
! switch to control write out frequency of the gridded model outputs below
! >0: after each <timeStep_model_outputs> time steps
! 0: only at end of run
......
......@@ -52,6 +52,8 @@ MODULE mo_global_variables
! -------------------------------------------------------------------
! DEFINE OUTPUTS
! -------------------------------------------------------------------
integer(i4) :: output_deflate_level
logical :: output_double_precision
integer(i4) :: timeStep_model_outputs ! timestep for writing model outputs
logical, dimension(nOutFlxState) :: outputFlxState ! Define model outputs see "mhm_outputs.nml"
! dim1 = number of output variables to be written
......
......@@ -101,7 +101,8 @@ CONTAINS
fnight_pet, fnight_prec, fnight_temp, fnight_ssrd, fnight_strd, &
inputFormat_meteo_forcings, nSoilHorizons_sm_input, outputFlxState, &
read_meteo_weights, timeStep_model_outputs, &
timestep_model_inputs
timestep_model_inputs, &
output_deflate_level, output_double_precision
use mo_message, only : message
use mo_mpr_constants, only : maxNoSoilHorizons
use mo_mpr_global_variables, only : nSoilHorizons_mHM
......@@ -187,7 +188,11 @@ CONTAINS
namelist /nightDayRatio/ read_meteo_weights, &
fnight_prec, fnight_pet, fnight_temp, fnight_ssrd, fnight_strd
! name list regarding output
namelist /NLoutputResults/timeStep_model_outputs, outputFlxState
namelist /NLoutputResults/ &
output_deflate_level, &
output_double_precision, &
timeStep_model_outputs, &
outputFlxState
!===============================================================
! Read namelist main directories
......@@ -353,6 +358,8 @@ CONTAINS
! Read output specifications for mHM
!===============================================================
call open_nml(file_defOutput, udefOutput, quiet = .true.)
output_deflate_level = 6
output_double_precision = .true.
outputFlxState = .FALSE.
call position_nml('NLoutputResults', udefOutput)
read(udefOutput, nml = NLoutputResults)
......@@ -360,6 +367,12 @@ CONTAINS
call message('')
call message('Following output will be written:')
call message(' NetCDF deflate level: ', adjustl(trim(num2str(output_deflate_level))))
if ( output_double_precision ) then
call message(' NetCDF output precision: double')
else
call message(' NetCDF output precision: single')
end if
call message(' STATES:')
if (outputFlxState(1)) then
call message(' interceptional storage (L1_inter) [mm]')
......
......@@ -20,6 +20,7 @@ module mo_write_fluxes_states
Conventions, contact, mHM_details, history
use mo_common_constants, only : nodata_dp
use mo_netcdf, only : NcDataset, NcDimension, NcVariable
use mo_global_variables, only : output_deflate_level, output_double_precision
implicit none
......@@ -123,7 +124,7 @@ contains
allocate(out%data(ncells))
out%nc = nc%setVariable(name, dtype, dims, deflate_level = 1, shuffle = .true.)
out%nc = nc%setVariable(name, dtype, dims, deflate_level = output_deflate_level, shuffle = .true.)
out%data = 0
out%mask => mask
if (present(avg)) out%avg = avg
......@@ -269,7 +270,11 @@ contains
type(OutputVariable), dimension(size(outputFlxState) * nSoilHorizons_mHM) :: tmpvars
dtype = "f64"
if ( output_double_precision ) then
dtype = "f64"
else
dtype = "f32"
end if
unit = fluxesUnit(iDomain)
if (iFlag_cordinate_sys == 0) then
......@@ -916,7 +921,13 @@ contains
real(dp), allocatable, dimension(:, :) :: lat2d, lon2d ! temporary storage of mHM's 2D latlon array.
! Used as 2d lat lon arrays if coordinate system is X & Y
character(3) :: dtype
if ( output_double_precision ) then
dtype = "f64"
else
dtype = "f32"
end if
fname = trim(dirOut(iDomain)) // 'mHM_Fluxes_States.nc'
call geoCoordinates(level1(iDomain), lat2d, lon2d)
......@@ -936,23 +947,23 @@ contains
nc%setDimension("time", 0) &
/)
! northing
var = nc%setVariable("northing", "f64", (/ dimids1(2) /))
var = nc%setVariable("northing", dtype, (/ dimids1(2) /))
call var%setData(northing)
call var%setAttribute("units", "m or degrees_north")
call var%setAttribute("long_name", "y-coordinate in the given coordinate system")
! easting
var = nc%setVariable("easting", "f64", (/ dimids1(1) /))
var = nc%setVariable("easting", dtype, (/ dimids1(1) /))
call var%setData(easting)
call var%setAttribute("units", "m or degrees_north")
call var%setAttribute("long_name", "x-coordinate in the given coordinate system")
! lon
var = nc%setVariable("lon", "f64", dimids1(1 : 2))
var = nc%setVariable("lon", dtype, dimids1(1 : 2))
call var%setData(lon2d)
call var%setAttribute("units", "degrees_east")
call var%setAttribute("long_name", "longitude")
call var%setAttribute("missing_value", nodata_dp)
! lat
var = nc%setVariable("lat", "f64", dimids1(1 : 2))
var = nc%setVariable("lat", dtype, dimids1(1 : 2))
call var%setData(lat2d)
call var%setAttribute("units", "degrees_north")
call var%setAttribute("long_name", "latitude")
......@@ -970,13 +981,13 @@ contains
nc%setDimension("time", 0) &
/)
! lon
var = nc%setVariable("lon", "f64", (/ dimids1(1) /)) ! sufficient to store lon as vector
var = nc%setVariable("lon", dtype, (/ dimids1(1) /)) ! sufficient to store lon as vector
call var%setData(lon1d)
call var%setAttribute("units", "degrees_east")
call var%setAttribute("long_name", "longitude")
call var%setAttribute("missing_value", nodata_dp)
! lat
var = nc%setVariable("lat", "f64", (/ dimids1(2) /)) ! sufficient to store lat as vector
var = nc%setVariable("lat", dtype, (/ dimids1(2) /)) ! sufficient to store lat as vector
call var%setData(lat1d)
call var%setAttribute("units", "degrees_north")
call var%setAttribute("long_name", "latitude")
......
......@@ -33,8 +33,9 @@ module mo_mrm_global_variables
! DEFINE OUTPUTS
! -------------------------------------------------------------------
!
integer(i4) :: output_deflate_level_mrm
logical :: output_double_precision_mrm
integer(i4) :: timeStep_model_outputs_mrm ! timestep for writing model outputs
logical, dimension(nOutFlxState) :: outputFlxState_mrm ! Define model outputs see "mhm_outputs.nml"
! dim1 = number of output variables to be written
......
......@@ -65,7 +65,8 @@ contains
dirGauges, dirTotalRunoff, filenameTotalRunoff, dirBankfullRunoff, gauge, is_start, &
nGaugesTotal, nGaugesLocal, nInflowGaugesTotal, outputFlxState_mrm, &
timeStep_model_outputs_mrm, &
varnameTotalRunoff, gw_coupling
varnameTotalRunoff, gw_coupling, &
output_deflate_level_mrm, output_double_precision_mrm
use mo_nml, only : close_nml, open_nml, position_nml
use mo_string_utils, only : num2str
......@@ -122,7 +123,11 @@ contains
namelist /inflow_gauges/ nInflowGaugesTotal, NoInflowGauges_domain, InflowGauge_id, &
InflowGauge_filename, InflowGauge_Headwater
! name list regarding output
namelist /NLoutputResults/timeStep_model_outputs_mrm, outputFlxState_mrm
namelist /NLoutputResults/ &
output_deflate_level_mrm, &
output_double_precision_mrm, &
timeStep_model_outputs_mrm, &
outputFlxState_mrm
!===============================================================
! INITIALIZATION
......@@ -354,6 +359,8 @@ contains
!===============================================================
! Read Output specifications for mRM
!===============================================================
output_deflate_level_mrm = 6
output_double_precision_mrm = .true.
outputFlxState_mrm = .FALSE.
timeStep_model_outputs_mrm = -2
inquire(file = file_defOutput, exist = file_exists)
......@@ -372,7 +379,12 @@ contains
if (any(outputFlxState_mrm)) then
call message('')
call message(' Following output will be written:')
call message(' NetCDF deflate level: ', adjustl(trim(num2str(output_deflate_level_mrm))))
if ( output_double_precision_mrm ) then
call message(' NetCDF output precision: double')
else
call message(' NetCDF output precision: single')
end if
call message(' FLUXES:')
if (outputFlxState_mrm(1)) then
call message(' routed streamflow (L11_qMod) [m3 s-1]')
......
......@@ -20,6 +20,7 @@ module mo_mrm_write_fluxes_states
Conventions, contact, mHM_details, history
use mo_common_constants, only : nodata_dp
use mo_netcdf, only : NcDataset, NcDimension, NcVariable
use mo_mrm_global_variables, only : output_deflate_level_mrm, output_double_precision_mrm
implicit none
......@@ -120,7 +121,7 @@ contains
allocate(out%data(ncells))
out%nc = nc%setVariable(name, dtype, dims, deflate_level = 1, shuffle = .true.)
out%nc = nc%setVariable(name, dtype, dims, deflate_level = output_deflate_level_mrm, shuffle = .true.)
out%data = 0
out%mask => mask
if (present(avg)) out%avg = avg
......@@ -262,7 +263,11 @@ contains
type(OutputVariable), dimension(size(outputFlxState_mrm)) :: tmpvars
dtype = "f64"
if ( output_double_precision_mrm ) then
dtype = "f64"
else
dtype = "f32"
end if
if (iFlag_cordinate_sys == 0) then
dims1 = (/"easting ", "northing", "time "/) ! X & Y coordinate system
......@@ -518,7 +523,13 @@ contains
real(dp), allocatable, dimension(:, :) :: lat2d, lon2d ! temporary storage of mHM's 2D latlon array.
! Used as 2d lat lon arrays if coordinate system is X & Y
character(3) :: dtype
if ( output_double_precision_mrm ) then
dtype = "f64"
else
dtype = "f32"
end if
fname = trim(dirOut(iDomain)) // trim(file_mrm_output)
call geoCoordinates(level11(iDomain), lat2d, lon2d)
......@@ -538,23 +549,23 @@ contains
nc%setDimension("time", 0) &
/)
! northing
var = nc%setVariable("northing", "f64", (/ dimids1(2) /))
var = nc%setVariable("northing", dtype, (/ dimids1(2) /))
call var%setData(northing)
call var%setAttribute("units", "m")
call var%setAttribute("long_name", "y-coordinate in the given coordinate system")
! easting
var = nc%setVariable("easting", "f64", (/ dimids1(1) /))
var = nc%setVariable("easting", dtype, (/ dimids1(1) /))
call var%setData(easting)
call var%setAttribute("units", "m")
call var%setAttribute("long_name", "x-coordinate in the given coordinate system")
! lon
var = nc%setVariable("lon", "f64", dimids1(1 : 2))
var = nc%setVariable("lon", dtype, dimids1(1 : 2))
call var%setData(lon2d)
call var%setAttribute("units", "degrees_east")
call var%setAttribute("long_name", "longitude")
call var%setAttribute("missing_value", nodata_dp)
! lat
var = nc%setVariable("lat", "f64", dimids1(1 : 2))
var = nc%setVariable("lat", dtype, dimids1(1 : 2))
call var%setData(lat2d)
call var%setAttribute("units", "degrees_north")
call var%setAttribute("long_name", "latitude")
......@@ -572,13 +583,13 @@ contains
nc%setDimension("time", 0) &
/)
! lon
var = nc%setVariable("lon", "f64", (/ dimids1(1) /)) ! sufficient to store lon as vector
var = nc%setVariable("lon", dtype, (/ dimids1(1) /)) ! sufficient to store lon as vector
call var%setData(lon1d)
call var%setAttribute("units", "degrees_east")
call var%setAttribute("long_name", "longitude")
call var%setAttribute("missing_value", nodata_dp)
! lat
var = nc%setVariable("lat", "f64", (/ dimids1(2) /)) ! sufficient to store lat as vector
var = nc%setVariable("lat", dtype, (/ dimids1(2) /)) ! sufficient to store lat as vector
call var%setData(lat1d)
call var%setAttribute("units", "degrees_north")
call var%setAttribute("long_name", "latitude")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment