diff --git a/src/opsinputs/opsinputs_cxwriter_mod.F90 b/src/opsinputs/opsinputs_cxwriter_mod.F90 index c7c7eeea..b8bf3c32 100644 --- a/src/opsinputs/opsinputs_cxwriter_mod.F90 +++ b/src/opsinputs/opsinputs_cxwriter_mod.F90 @@ -226,7 +226,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("verbose") GeneralMode = VerboseMode case default - write (ErrorMessage, '("GeneralMode code not recognised: ",A)') StringValue + write (ErrorMessage, '("GeneralMode not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -286,7 +286,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("wave") self % FH_VertCoord = FH_VertCoord_Wave case default - write (ErrorMessage, '("FH_VertCoord code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_VertCoord not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -311,7 +311,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("lamwrapeq") self % FH_HorizGrid = FH_HorizGrid_LamWrapEq case default - write (ErrorMessage, '("FH_HorizGrid code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_HorizGrid not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -326,7 +326,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("endgame") self % FH_GridStagger = FH_GridStagger_EndGame case default - write (ErrorMessage, '("FH_GridStagger code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_GridStagger not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -343,7 +343,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("wave") self % FH_ObsFileType = FH_ObsFileType_Wave case default - write (ErrorMessage, '("FH_ObsFileType code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_ObsFileType not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -357,7 +357,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("atmos") self % FH_SubModel = FH_SubModel_Atmos case default - write (ErrorMessage, '("FH_SubModel code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_SubModel not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -439,7 +439,7 @@ function opsinputs_cxwriter_create(self, f_conf, geovars) case ("sst") ModelType = ModelType_SST case default - write (ErrorMessage, '("model_type code not recognised: ",A)') StringValue + write (ErrorMessage, '("model_type not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_cxwriter_create = .false. return @@ -610,6 +610,8 @@ subroutine opsinputs_cxwriter_addrequiredgeovars(self, geovars) GeoVarName = opsinputs_cxfields_unknown select case (CxField) + case (IMDI) + cycle ! Surface variables @@ -911,6 +913,8 @@ subroutine opsinputs_cxwriter_populatecx(self, ReportFlags, Cx) do iCxField = 1, size(CxFields) CxField = CxFields(iCxField) select case (CxField) + case (IMDI) + cycle ! Surface variables diff --git a/src/opsinputs/opsinputs_varobswriter_mod.F90 b/src/opsinputs/opsinputs_varobswriter_mod.F90 index d493f792..184716ac 100644 --- a/src/opsinputs/opsinputs_varobswriter_mod.F90 +++ b/src/opsinputs/opsinputs_varobswriter_mod.F90 @@ -270,7 +270,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe case ("verbose") GeneralMode = VerboseMode case default - write (ErrorMessage, '("GeneralMode code not recognised: ",A)') StringValue + write (ErrorMessage, '("GeneralMode not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -355,7 +355,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe case ("wave") self % FH_VertCoord = FH_VertCoord_Wave case default - write (ErrorMessage, '("FH_VertCoord code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_VertCoord not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -380,7 +380,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe case ("lamwrapeq") self % FH_HorizGrid = FH_HorizGrid_LamWrapEq case default - write (ErrorMessage, '("FH_HorizGrid code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_HorizGrid not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -395,7 +395,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe case ("endgame") self % FH_GridStagger = FH_GridStagger_EndGame case default - write (ErrorMessage, '("FH_GridStagger code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_GridStagger not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -413,7 +413,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe case ("wave") self % FH_SubModel = FH_SubModel_Wave case default - write (ErrorMessage, '("FH_SubModel code not recognised: ",A)') StringValue + write (ErrorMessage, '("FH_SubModel not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -437,7 +437,7 @@ function opsinputs_varobswriter_create(self, f_conf, comm_is_valid, comm, channe write (ErrorMessage, '("IC_GroundGPSOperator set to IC_GroundGPSOperatorGeneric: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) case default - write (ErrorMessage, '("IC_GroundGPSOperator code not recognised: ",A)') StringValue + write (ErrorMessage, '("IC_GroundGPSOperator not recognized: ",A)') StringValue call gen_warn(RoutineName, ErrorMessage) opsinputs_varobswriter_create = .false. return @@ -608,8 +608,6 @@ subroutine opsinputs_varobswriter_addrequiredgeovars(self, geovars) ! Local declarations: integer(integer64) :: VarFields(ActualMaxVarfield) integer :: i -character(len=80) :: ErrorMessage -character(len=*), parameter :: RoutineName = "opsinputs_varobswriter_addrequiredgeovars" ! Body: VarBC = self % OutputVarBCPredictors @@ -617,14 +615,14 @@ subroutine opsinputs_varobswriter_addrequiredgeovars(self, geovars) do i = 1, size(VarFields) select case (VarFields(i)) + case (IMDI) + cycle case (VarField_modelsurface) ! TODO(someone): "land_type_index" may not be the right geoval to use. If it isn't, change it ! here and in opsinputs_varobswriter_populateobservations. call geovars % push_back("land_type_index") case default - write (ErrorMessage, '("Varfield not recognized: ",I0)') VarFields(i) - call gen_warn(RoutineName, ErrorMessage) - continue + cycle end select end do @@ -1221,7 +1219,7 @@ subroutine opsinputs_varobswriter_populateobservations( & ! TODO(someone): handle this varfield ! call Ops_Alloc(Ob % Header % HeightCOG, "HeightCOG", Ob % Header % NumObsLocal, Ob % HeightCOG) case default - write (ErrorMessage, "(A,I0)") "VarField code not recognised ", VarFields(iVarField) + write (ErrorMessage, "(A,I0)") "Varfield not recognized: ", VarFields(iVarField) call gen_warn(RoutineName, ErrorMessage) cycle end select diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 065fcc66..5fae0086 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,7 +25,7 @@ include( opsinputs_functions ) function( ADD_WRITER_TEST ) set( options DONT_SET_OPS_OUTPUT_DIR_ENV_VAR ) set( single_value_args NAME YAML NAMELIST MPI ) - set( multi_value_args DATA LABELS ) + set( multi_value_args DATA LABELS EXPECTED_WARNINGS ) cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${_FIRST_ARG} ${ARGN} ) if(_PAR_UNPARSED_ARGUMENTS) @@ -48,14 +48,28 @@ function( ADD_WRITER_TEST ) if(NOT _PAR_MPI) set(_PAR_MPI 1) endif() + set( test_command ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}_test_inputs_filters.x ) + set( test_args "testinput/${_PAR_YAML}" ) + if(_PAR_EXPECTED_WARNINGS) + set( test_command ${CMAKE_COMMAND} ) + set( test_args + "-DWRITER_EXECUTABLE=${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}_test_inputs_filters.x" + "-DWRITER_INPUT=testinput/${_PAR_YAML}" + "-DEXPECTED_WARNINGS=${_PAR_EXPECTED_WARNINGS}" + -P ${CMAKE_CURRENT_SOURCE_DIR}/check_writer_warnings.cmake ) + endif() ecbuild_add_test( TARGET ${PROJECT_NAME}_${_PAR_NAME} LABELS ${_PAR_LABELS} - COMMAND ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME}_test_inputs_filters.x - ARGS "testinput/${_PAR_YAML}" + COMMAND ${test_command} + ARGS ${test_args} ENVIRONMENT "${environment}" MPI ${_PAR_MPI} DEPENDS ${PROJECT_NAME}_test_inputs_filters.x ) set_tests_properties( ${PROJECT_NAME}_${_PAR_NAME} PROPERTIES FIXTURES_REQUIRED CleanOutputDir ) + if(NOT _PAR_EXPECTED_WARNINGS) + set_tests_properties( ${PROJECT_NAME}_${_PAR_NAME} PROPERTIES + FAIL_REGULAR_EXPRESSION "Varfield not recognized;Stash code not recognized" ) + endif() endfunction() set( OPSINPUTS_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/testoutput ) @@ -453,6 +467,12 @@ ADD_WRITER_TEST(NAME varobswriter_globalnamelist_aircraft YAML varobswriter_globalnamelist_aircraft.yaml NAMELIST ../../etc/global/varobs/Aircraft.nl DATA varobs_globalnamelist_aircraft.nc4) +ADD_WRITER_TEST(NAME varobswriter_unknown_varfield + LABELS varobswriter + YAML varobswriter_unknown_varfield.yaml + NAMELIST VarObsWriterNamelists_unknown/Surface.nl + DATA 003_VarField_rh_Surface.nc4 + EXPECTED_WARNINGS "opsinputs_varobswriter_populateobservations.*Varfield not recognized: 13") ADD_WRITER_TEST(NAME varobswriter_globalnamelist_sternamwr LABELS varobswriter globalnamelist YAML varobswriter_globalnamelist_sternamwr.yaml @@ -878,6 +898,14 @@ ADD_WRITER_TEST(NAME cxwriter_globalnamelist_aircraft YAML cxwriter_globalnamelist_aircraft.yaml NAMELIST ../../etc/global/cx/Aircraft.nl DATA cx_globalnamelist_aircraft.nc4 dummy.nc4) +ADD_WRITER_TEST(NAME cxwriter_unknown_stash + LABELS cxwriter + YAML cxwriter_unknown_stash.yaml + NAMELIST CxWriterNamelists_unknown/Aircraft.nl + DATA cx_globalnamelist_aircraft.nc4 dummy.nc4 + EXPECTED_WARNINGS + "opsinputs_cxwriter_addrequiredgeovars.*Stash code not recognized: 99999" + "opsinputs_cxwriter_populatecx.*Stash code not recognized: 99999") ADD_WRITER_TEST(NAME cxwriter_globalnamelist_surface LABELS cxwriter globalnamelist YAML cxwriter_globalnamelist_surface.yaml diff --git a/test/check_writer_warnings.cmake b/test/check_writer_warnings.cmake new file mode 100644 index 00000000..eae685b3 --- /dev/null +++ b/test/check_writer_warnings.cmake @@ -0,0 +1,18 @@ +execute_process( + COMMAND "${WRITER_EXECUTABLE}" "${WRITER_INPUT}" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_VARIABLE errors) +message("${output}${errors}") +if(NOT "${result}" STREQUAL "0") + message(FATAL_ERROR "Writer test failed: ${result}") +endif() +set( log "${output}${errors}" ) +if(log MATCHES "Varfield not recognized: -32768|Stash code not recognized: -32768") + message(FATAL_ERROR "Writer reported missing-data padding as an unknown field") +endif() +foreach(warning IN LISTS EXPECTED_WARNINGS) + if(NOT log MATCHES "${warning}") + message(FATAL_ERROR "Missing expected writer warning: ${warning}") + endif() +endforeach() diff --git a/test/testinput/CxWriterNamelists_unknown/Aircraft.nl b/test/testinput/CxWriterNamelists_unknown/Aircraft.nl new file mode 100644 index 00000000..124a96ef --- /dev/null +++ b/test/testinput/CxWriterNamelists_unknown/Aircraft.nl @@ -0,0 +1,3 @@ +&CXControlNL +CxFields=33,99999 +/ diff --git a/test/testinput/VarObsWriterNamelists_unknown/Surface.nl b/test/testinput/VarObsWriterNamelists_unknown/Surface.nl new file mode 100644 index 00000000..bd58081f --- /dev/null +++ b/test/testinput/VarObsWriterNamelists_unknown/Surface.nl @@ -0,0 +1,3 @@ +&VarobsControlNL +Varfields=3,13 +/ diff --git a/test/testinput/cxwriter_unknown_stash.yaml b/test/testinput/cxwriter_unknown_stash.yaml new file mode 100644 index 00000000..5e20392d --- /dev/null +++ b/test/testinput/cxwriter_unknown_stash.yaml @@ -0,0 +1,29 @@ +time window: + begin: 2018-01-01T00:00:00Z + end: 2018-01-01T01:00:00Z + +observations: + - obs space: + name: Aircraft + obsdatain: + engine: + type: H5File + obsfile: Data/dummy.nc4 + simulated variables: [dummy] + geovals: + filename: Data/cx_globalnamelist_aircraft.nc4 + obs filters: + - filter: Cx Writer + namelist_directory: testinput/CxWriterNamelists_unknown + general_mode: debug + - filter: Cx Checker + expected_surface_variables: ["1"] + expected_upper_air_variables: [] + expected_main_table_columns: + - - ["17.10"] + - ["**********"] + - ["17.30"] + - ["17.40"] + HofX: ObsValue + benchmarkFlag: 1000 + flaggedBenchmark: 0 diff --git a/test/testinput/varobswriter_unknown_varfield.yaml b/test/testinput/varobswriter_unknown_varfield.yaml new file mode 100644 index 00000000..837155f3 --- /dev/null +++ b/test/testinput/varobswriter_unknown_varfield.yaml @@ -0,0 +1,23 @@ +time window: + begin: 2018-01-01T00:00:00Z + end: 2018-01-01T02:00:00Z + +observations: + - obs space: + name: Surface + obsdatain: + engine: + type: H5File + obsfile: Data/003_VarField_rh_Surface.nc4 + simulated variables: [relativeHumidityAt2M] + obs filters: + - filter: VarObs Writer + namelist_directory: testinput/VarObsWriterNamelists_unknown + general_mode: debug + - filter: VarObs Checker + expected_main_table_columns: + field: [3, 3, 3, 3] + ob value: ["1.10000", "-1073741824.00000", "1.30000", "1.40000"] + HofX: ObsValue + benchmarkFlag: 1000 + flaggedBenchmark: 0