From 9541e84eac487d31fd9d70975a4c680175edf80a Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 27 Jun 2022 13:23:27 -0600 Subject: [PATCH] #1815 Support @ for pinterp --- .../vx_data2d_nc_pinterp/data2d_nc_pinterp.cc | 15 +++- .../vx_data2d_nc_pinterp/pinterp_file.cc | 60 ++++++++++----- .../vx_data2d_nc_pinterp/pinterp_file.h | 1 + .../var_info_nc_pinterp.cc | 74 ++++++++++++++----- .../var_info_nc_pinterp.h | 21 +++++- 5 files changed, 129 insertions(+), 42 deletions(-) diff --git a/src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc b/src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc index 327cab74a3..47354d9c0e 100644 --- a/src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc +++ b/src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc @@ -133,9 +133,20 @@ bool MetNcPinterpDataFile::data_plane(VarInfo &vinfo, DataPlane &plane) { plane.clear(); // Read the data + PinterpNc->get_nc_var_info(vinfo_nc->req_name().c_str(), info); + LongArray dimension = vinfo_nc->dimension(); + int dim_count = dimension.n_elements(); + for (int k=0; kVar, + GET_NC_NAME(get_nc_dim(info->var, k)), + vinfo_nc->dim_value(k), PinterpNc->Nvars, + (k == info->t_slot)); + } + } + status = PinterpNc->data(vinfo_nc->req_name().c_str(), - vinfo_nc->dimension(), - plane, pressure, info); + dimension, plane, pressure, info); // Check that the times match those requested if(status) { diff --git a/src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc b/src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc index d31e692e1a..3a6d3d566c 100644 --- a/src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc +++ b/src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc @@ -52,7 +52,7 @@ static const char pressure_var_wrf_interp_name [] = "LEV"; static const char pa_units_str [] = "Pa"; static const char hpa_units_str [] = "hPa"; -static const string init_time_att_name = "START_DATE"; +static const string start_time_att_name = "START_DATE"; static const int max_pinterp_args = 30; @@ -73,7 +73,6 @@ static bool is_bad_data_pinterp(double); static bool is_accumulation(const char *); - //////////////////////////////////////////////////////////////////////// @@ -281,7 +280,7 @@ else { } ConcatString att_value; -get_global_att(Nc, init_time_att_name, att_value); +get_global_att(Nc, start_time_att_name, att_value); InitTime = parse_init_time(att_value.c_str()); @@ -796,13 +795,15 @@ return ( true ); bool PinterpFile::data(const char * var_name, const LongArray & a, DataPlane & plane, - double & pressure, NcVarInfo *&info) const + double & pressure, NcVarInfo *&info) const { -{ + int j, time_index; + bool found = false; -int j, time_index; -bool found = false; + if (NULL != info) found = true; + else found = get_nc_var_info(var_name, info); +/* for (j=0; jvar, a, plane, pressure); // // store the times // -time_index = a[Var[j].t_slot]; + time_index = a[info->t_slot]; -plane.set_init ( InitTime ); -plane.set_valid ( valid_time(time_index) ); -plane.set_lead ( lead_time(time_index) ); + plane.set_init ( InitTime ); + plane.set_valid ( valid_time(time_index) ); + plane.set_lead ( lead_time(time_index) ); // // since Pinterp files only contain WRF-ARW output, it is always a // a runtime accumulation // -if ( is_accumulation(var_name) ) { + if ( is_accumulation(var_name) ) { - plane.set_accum ( lead_time(time_index) ); + plane.set_accum ( lead_time(time_index) ); -} else { + } else { - plane.set_accum ( 0 ); + plane.set_accum ( 0 ); -} + } // // done // -return ( found ); + return ( found ); } +//////////////////////////////////////////////////////////////////////// + +bool PinterpFile::get_nc_var_info(const char *var_name, NcVarInfo *&info) const { + bool found = false; + + if (NULL == info) { + for (int j=0; j " + mlog << Error << "\n" << method_name << "only one dimension can have a range for NetCDF variable \"" << MagicStr << "\".\n\n"; exit(1); } // Store the dimension of the range and limits else { - Dimension.add(range_flag); + add_dimension(range_flag); Level.set_lower(atoi(ptr2)); Level.set_upper(atoi(++ptr3)); @@ -202,7 +218,29 @@ void VarInfoNcPinterp::set_magic(const ConcatString &nstr, const ConcatString &l } // Single level else { - Dimension.add(atoi(ptr2)); + int level = 0; + double level_value = bad_data_double; + if (is_number(ptr2)) { + if (as_offset) level = atoi(ptr2); + else { + level = vx_data2d_dim_by_value; + level_value = atof(ptr2); + } + } + else if (is_datestring(ptr2)) { + unixtime unix_time = timestring_to_unix(ptr2); + level = vx_data2d_dim_by_value; + level_value = unix_time; + as_offset = false; + } + else { + mlog << Error << "\n" << method_name + << "trouble parsing NetCDF dimension value \"" + << ptr2 << "\"!\n\n"; + exit(1); + } + if (as_offset) add_dimension(level, as_offset); + else add_dimension(level, as_offset, level_value); } } diff --git a/src/libcode/vx_data2d_nc_pinterp/var_info_nc_pinterp.h b/src/libcode/vx_data2d_nc_pinterp/var_info_nc_pinterp.h index e169437291..bff8f90389 100644 --- a/src/libcode/vx_data2d_nc_pinterp/var_info_nc_pinterp.h +++ b/src/libcode/vx_data2d_nc_pinterp/var_info_nc_pinterp.h @@ -23,6 +23,10 @@ /////////////////////////////////////////////////////////////////////////////// +typedef CRC_Array BoolArray; + +/////////////////////////////////////////////////////////////////////////////// + // // List of Pinterp precipitation variable names // Taken from the WRF version 3.2 Registry.EM file @@ -184,9 +188,12 @@ class VarInfoNcPinterp : public VarInfo // LongArray Dimension; // Dimension values for extracting 2D field + BoolArray Is_offset; // boolean for Dimension value (true: offset, false: value to be an offset (false for value) + NumArray Dim_value; // Dimension values as float for extracting 2D field void init_from_scratch(); void assign(const VarInfoNcPinterp &); + void clear_dimension(); public: VarInfoNcPinterp(); @@ -202,8 +209,12 @@ class VarInfoNcPinterp : public VarInfo // GrdFileType file_type() const; - const LongArray & dimension() const; - int dimension(int i) const; + const LongArray & dimension() const; + int dimension(int i) const; + const NumArray & dim_value() const; + double dim_value(int i) const; + const BoolArray & is_offset() const; + bool is_offset(int i) const; int n_dimension() const; // @@ -213,7 +224,7 @@ class VarInfoNcPinterp : public VarInfo void set_magic(const ConcatString &, const ConcatString &); void set_dict(Dictionary &); - void add_dimension(int dim); + void add_dimension(int dim, bool as_index=true, double dim_value=bad_data_double); void set_dimension(int i_dim, int dim); // @@ -235,6 +246,10 @@ inline GrdFileType VarInfoNcPinterp::file_type() const { return(FileT inline const LongArray & VarInfoNcPinterp::dimension() const { return(Dimension); } inline int VarInfoNcPinterp::dimension(int i) const { return(Dimension[i]); } inline int VarInfoNcPinterp::n_dimension() const { return(Dimension.n_elements()); } +inline const NumArray & VarInfoNcPinterp::dim_value() const { return(Dim_value); } +inline double VarInfoNcPinterp::dim_value(int i) const { return(Dim_value[i]); } +inline const BoolArray & VarInfoNcPinterp::is_offset() const { return(Is_offset); } +inline bool VarInfoNcPinterp::is_offset(int i) const { return(Is_offset[i]); } ///////////////////////////////////////////////////////////////////////////////