diff --git a/src/tools/other/mode_time_domain/mtd.cc b/src/tools/other/mode_time_domain/mtd.cc index 45dc13a254..acfe9c3b27 100644 --- a/src/tools/other/mode_time_domain/mtd.cc +++ b/src/tools/other/mode_time_domain/mtd.cc @@ -210,18 +210,16 @@ MM_Engine engine; // storage for valid times // -unixtime * valid_times_fcst = 0; -valid_times_fcst = new unixtime [fcst_filenames.n()]; -unixtime * valid_times_obs = 0; -valid_times_obs = new unixtime [obs_filenames.n()]; +vector valid_times_fcst; +vector valid_times_obs; // // read the data files // -mtd_read_data(config, *(config.fcst_info), fcst_filenames, fcst_raw, valid_times_fcst); +valid_times_fcst = mtd_read_data(config, *(config.fcst_info), fcst_filenames, fcst_raw); -mtd_read_data(config, *(config.obs_info), obs_filenames, obs_raw, valid_times_obs); +valid_times_obs = mtd_read_data(config, *(config.obs_info), obs_filenames, obs_raw); if ( fcst_raw.nt() != obs_raw.nt() ) { @@ -446,6 +444,13 @@ for (j=0; j<(fcst_obj.n_objects()); ++j) { mask_2d = fcst_obj.const_t_mask(t, j + 1); // 1-based + if (t < 0 || t >= (int)valid_times_fcst.size()) { + mlog << Error + << "\n " << program_name << ": index " << t << " out of forecast valid times range 0 to " << valid_times_fcst.size()-1 + << "\n\n"; + exit ( 1 ); + } + fcst_raw.get_data_plane(t, raw_2d); att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value); @@ -480,6 +485,13 @@ for (j=0; j<(obs_obj.n_objects()); ++j) { mask_2d = obs_obj.const_t_mask(t, j + 1); // 1-based + if (t < 0 || t >= (int)valid_times_obs.size()) { + mlog << Error + << "\n " << program_name << ": index " << t << " out of obs valid times range 0 to " << valid_times_obs.size()-1 + << "\n\n"; + exit ( 1 ); + } + obs_raw.get_data_plane(t, raw_2d); att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value); @@ -695,7 +707,14 @@ if ( have_pairs ) { // cout << "j = " << j << ", vol = " << mask_2d.object_volume(0) << '\n'; - fcst_raw.get_data_plane(t, raw_2d); + if (t < 0 || t >= (int)valid_times_fcst.size()) { + mlog << Error + << "\n " << program_name << ": index " << t << " out of forecast valid times range 0 to " << valid_times_fcst.size()-1 + << "\n\n"; + exit ( 1 ); + } + + fcst_raw.get_data_plane(t, raw_2d); att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value); @@ -736,7 +755,14 @@ if ( have_pairs ) { // mask_2d = mask.const_t_mask(t, j + 1); // 1-based mask_2d = mask.const_t_mask(t, 1); // 1-based - obs_raw.get_data_plane(t, raw_2d); + if (t < 0 || t >= (int)valid_times_obs.size()) { + mlog << Error + << "\n " << program_name << ": index " << t << " out of obs valid times range 0 to " << valid_times_obs.size()-1 + << "\n\n"; + exit ( 1 ); + } + + obs_raw.get_data_plane(t, raw_2d); att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value); @@ -882,9 +908,6 @@ mlog << Debug(2) do_mtd_nc_output(config.nc_info, engine, fcst_raw, obs_raw, fcst_obj, obs_obj, config, path.c_str()); -if ( valid_times_fcst ) { delete [] valid_times_fcst; valid_times_fcst = 0; } -if ( valid_times_obs ) { delete [] valid_times_obs; valid_times_obs = 0; } - // // done // @@ -1066,14 +1089,13 @@ ConcatString path; // storage for valid times // -unixtime * valid_times = 0; -valid_times = new unixtime [single_filenames.n()]; +vector valid_times; // // read the data files // -mtd_read_data(config, *(config.fcst_info), single_filenames, raw, valid_times); +valid_times = mtd_read_data(config, *(config.fcst_info), single_filenames, raw); // // copy forecast name/units/level to observation @@ -1177,7 +1199,15 @@ for (j=0; j<(obj.n_objects()); ++j) { mask_2d = obj.const_t_mask(t, j + 1); // 1-based + if (t < 0 || t >= (int)valid_times.size()) { + mlog << Error + << "\n " << program_name << ": index " << t << " out of valid times range 0 to " << valid_times.size()-1 + << "\n\n"; + exit ( 1 ); + } + raw.get_data_plane(t, raw_2d); + //raw_2d.set_valid(valid_times[t]); att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value); @@ -1243,8 +1273,6 @@ mlog << Debug(2) do_mtd_nc_output(config.nc_info, raw, obj, config, path.c_str()); -if ( valid_times ) { delete [] valid_times; valid_times = 0; } - // // done // diff --git a/src/tools/other/mode_time_domain/mtd_file_base.cc b/src/tools/other/mode_time_domain/mtd_file_base.cc index 4295a2ba85..f73e88f4ea 100644 --- a/src/tools/other/mode_time_domain/mtd_file_base.cc +++ b/src/tools/other/mode_time_domain/mtd_file_base.cc @@ -91,6 +91,8 @@ Nx = Ny = Nt = 0; StartValidTime = (unixtime) 0; +ActualValidTimes.clear(); + DeltaT = 0; Filename.clear(); @@ -292,7 +294,6 @@ return; } - //////////////////////////////////////////////////////////////////////// @@ -306,6 +307,19 @@ return; } +//////////////////////////////////////////////////////////////////////// + + +void MtdFileBase::init_actual_valid_times(const vector &validTimes) + +{ + +ActualValidTimes = validTimes; + +return; + +} + //////////////////////////////////////////////////////////////////////// @@ -349,6 +363,25 @@ return ( StartValidTime + t*DeltaT ); } +//////////////////////////////////////////////////////////////////////// + + +unixtime MtdFileBase::actual_valid_time(int t) const + +{ + + if ( (t < 0) || ( t >= (int)ActualValidTimes.size()) ) { + + mlog << Error << "\n\n MtdFileBase::valid_time(int t) -> range check error\n\n"; + + exit ( 1 ); + +} + + return ( ActualValidTimes[t] ); + +} + //////////////////////////////////////////////////////////////////////// diff --git a/src/tools/other/mode_time_domain/mtd_file_base.h b/src/tools/other/mode_time_domain/mtd_file_base.h index 205b5feb92..98d30f10a1 100644 --- a/src/tools/other/mode_time_domain/mtd_file_base.h +++ b/src/tools/other/mode_time_domain/mtd_file_base.h @@ -85,9 +85,11 @@ class MtdFileBase { int Nx, Ny, Nt; - unixtime StartValidTime; + unixtime StartValidTime; // useful for constant time increments - int DeltaT; // seconds + int DeltaT; // seconds, useful for constant time increments + + vector ActualValidTimes; // useful for uneven time increments IntArray Lead_Times; @@ -113,8 +115,11 @@ class MtdFileBase { void set_grid(const Grid &); void set_start_valid_time (unixtime); + void set_delta_t (int); // seconds + void init_actual_valid_times(const vector &validTimes); + void set_lead_time(int index, int value); void set_filetype(MtdFileType); @@ -143,6 +148,8 @@ class MtdFileBase { unixtime valid_time (int) const; + unixtime actual_valid_time (int) const; + int lead_time (int index) const; // diff --git a/src/tools/other/mode_time_domain/mtd_read_data.cc b/src/tools/other/mode_time_domain/mtd_read_data.cc index 9872ab23ef..1f327fc5cd 100644 --- a/src/tools/other/mode_time_domain/mtd_read_data.cc +++ b/src/tools/other/mode_time_domain/mtd_read_data.cc @@ -27,9 +27,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////// -void mtd_read_data(MtdConfigInfo & config, VarInfo & varinfo, - const StringArray & filenames, MtdFloatFile & raw, - unixtime valid_times[]) +vector mtd_read_data(MtdConfigInfo & config, VarInfo & varinfo, + const StringArray & filenames, MtdFloatFile & raw) { @@ -45,7 +44,7 @@ int j, k; Met2dDataFile * data_2d_file = 0; Met2dDataFileFactory factory; DataPlane plane; - +vector valid_times; // // read the files // @@ -73,7 +72,7 @@ for (j=0; j<(filenames.n()); ++j) { } - valid_times[j] = plane.valid(); + valid_times.push_back(plane.valid()); if ( j == 0 ) { @@ -95,48 +94,51 @@ for (j=0; j<(filenames.n()); ++j) { varinfo.set_valid(valid_times[0]); + // store the valid times vector into the raw data for later use in do_2d_txt_output() + + raw.init_actual_valid_times(valid_times); + // // check the time intervals for consistency // Store the time differences between succesive valid times in an array // See if differences are constant or not, and if not see if all diffs are months // -unixtime dt_start, dt, *dtArray; -int numDt = filenames.n() - 1; -dtArray = new unixtime [numDt]; +unixtime dt_start; +vector dtVector; dt_start = valid_times[1] - valid_times[0]; -dtArray[0] = dt_start; +dtVector.push_back(dt_start); -for (j=2; j<(filenames.n()); ++j) { - dtArray[j - 1] = dt = valid_times[j] - valid_times[j - 1]; +for (size_t k=2; k file time increments are months (not constant), use MODE of the increments, mode=" << dt_start << " seconds = " << dt_start/(24*3600) << " days\n\n"; + mlog << Debug(1) << "File time increments are months (not constant), use MODE of the increments, mode=" << dt_start + << " seconds = " << dt_start/(24*3600) << " days\n\n"; } else { // compute some measures that might be used to exit with an error, for now just show them to the user and go on double mean, var, svar; @@ -153,12 +156,11 @@ if (variableTimeIncs) { unixtime umean = (unixtime)mean; unixtime uvar = (unixtime)var; unixtime suvar = (unixtime)svar; - mlog << Warning << "\n\n mtd_read_data() -> file time increments are not constant, could be problematic\n"; - mlog << Warning << " mtd_read_data() -> use MODE of the increments, mode=" << dt_start << "\n"; - mlog << Warning << " mtd_read_data() -> time increment properties: mean=" << umean << " variance=" << uvar << " sqrt(var)=" << suvar << "\n\n"; + mlog << Warning << "\n\n mtd_read_data() -> File time increments are not constant, could be problematic\n"; + mlog << Warning << " mtd_read_data() -> Using MODE of the increments, mode=" << dt_start << "\n"; + mlog << Warning << " mtd_read_data() -> Time increment properties: mean=" << umean << " variance=" << uvar << " sqrt(var)=" << suvar << "\n\n"; } } -delete [] dtArray; // // load up the rest of the MtdFloatFile class members @@ -178,7 +180,7 @@ raw.calc_data_minmax(); // done // -return; +return valid_times; } diff --git a/src/tools/other/mode_time_domain/mtd_read_data.h b/src/tools/other/mode_time_domain/mtd_read_data.h index 69d82caa88..a9e08d13f9 100644 --- a/src/tools/other/mode_time_domain/mtd_read_data.h +++ b/src/tools/other/mode_time_domain/mtd_read_data.h @@ -26,10 +26,12 @@ //////////////////////////////////////////////////////////////////////// +// +// returns the actual valid times +// -extern void mtd_read_data(MtdConfigInfo &, VarInfo &, - const StringArray & filenames, MtdFloatFile &, - unixtime valid_times[]); +extern vector mtd_read_data(MtdConfigInfo &, VarInfo &, + const StringArray & filenames, MtdFloatFile &); //////////////////////////////////////////////////////////////////////// diff --git a/src/tools/other/mode_time_domain/mtd_txt_output.cc b/src/tools/other/mode_time_domain/mtd_txt_output.cc index 23967d2624..8da256f4bb 100644 --- a/src/tools/other/mode_time_domain/mtd_txt_output.cc +++ b/src/tools/other/mode_time_domain/mtd_txt_output.cc @@ -399,8 +399,8 @@ return; void do_2d_txt_output(const MtdFloatFile & fcst_raw, const MtdFloatFile & obs_raw, - const unixtime valid_times_fcst[], - const unixtime valid_times_obs[], + const vector &valid_times_fcst, + const vector &valid_times_obs, const SingleAtt2DArray & fcst_simple_att, const SingleAtt2DArray & obs_simple_att, const SingleAtt2DArray & fcst_cluster_att, @@ -496,11 +496,9 @@ for (j=0; j<(fcst_simple_att.n()); ++j) { table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_simple_att.lead_time(j))); - //table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_simple_att.valid_time(j))); - table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[j])); + table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_simple_att.valid_time(j))); - //table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t))); - table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[t])); + table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.actual_valid_time(t))); table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_raw.lead_time(t))); @@ -512,13 +510,11 @@ for (j=0; j<(obs_simple_att.n()); ++j) { t = obs_simple_att.time_index(j); - //table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t))); - table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[t])); + table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.actual_valid_time(t))); table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_raw.lead_time(t))); - //table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_simple_att.valid_time(j))); - table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[j])); + table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_simple_att.valid_time(j))); table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_simple_att.lead_time(j))); @@ -534,8 +530,7 @@ for (j=0; j<(fcst_cluster_att.n()); ++j) { table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_cluster_att.valid_time(j))); - //table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t))); - table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[t])); + table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.actual_valid_time(t))); table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_raw.lead_time(t))); @@ -547,8 +542,7 @@ for (j=0; j<(obs_cluster_att.n()); ++j) { t = obs_cluster_att.time_index(j); - //table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t))); - table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[t])); + table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.actual_valid_time(t))); table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_raw.lead_time(t))); diff --git a/src/tools/other/mode_time_domain/mtd_txt_output.h b/src/tools/other/mode_time_domain/mtd_txt_output.h index b172e8a44c..e519eebd7e 100644 --- a/src/tools/other/mode_time_domain/mtd_txt_output.h +++ b/src/tools/other/mode_time_domain/mtd_txt_output.h @@ -48,8 +48,8 @@ extern void do_3d_pair_txt_output(const PairAtt3DArray &, extern void do_2d_txt_output(const MtdFloatFile & fcst_raw, const MtdFloatFile & obs_raw, - const unixtime valid_times_fcst[], - const unixtime valid_times_obs[], + const vector &valid_times_fcst, + const vector &valid_times_obs, const SingleAtt2DArray & fcst_single_att, const SingleAtt2DArray & obs_single_att, const SingleAtt2DArray & fcst_cluster_att,