Skip to content

Commit

Permalink
Per #2609, adding hooks for the Met2dDataFile::data_planes() function…
Browse files Browse the repository at this point in the history
… to the class heirarchy.
  • Loading branch information
JohnHalleyGotway committed Aug 30, 2023
1 parent 4a91bda commit bfe80f1
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/libcode/vx_data2d/data_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class Met2dDataFile : public Met2dData {

virtual int index(VarInfo &) = 0;

// retrieve a vector of all requested data planes

virtual int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&) = 0;

// post-process data after reading it

bool process_data_plane(VarInfo *, DataPlane &);
Expand Down
15 changes: 15 additions & 0 deletions src/libcode/vx_data2d_grib/data2d_grib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,18 @@ int MetGrib1DataFile::index(VarInfo &vinfo){

return rec;
}

////////////////////////////////////////////////////////////////////////

int MetGrib1DataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetGrib1DataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}

////////////////////////////////////////////////////////////////////////
13 changes: 12 additions & 1 deletion src/libcode/vx_data2d_grib/data2d_grib.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ class MetGrib1DataFile : public Met2dDataFile {

int read_record( VarInfoGrib &); // returns match count (>=0), or -1 on error

// retrieve the first matching data plane

bool data_plane(VarInfo &, DataPlane &);

// retrieve all matching data planes

int data_plane_array(VarInfo &, DataPlaneArray &);


// retrieve the index of the first matching record

int index(VarInfo &);

// retrieve a vector of all requested data planes

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

};


Expand Down
13 changes: 13 additions & 0 deletions src/libcode/vx_data2d_grib2/data2d_grib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,19 @@ int MetGrib2DataFile::index( VarInfo &vinfo ){
return 1 > listMatchExact.size() ? -1 : listMatchExact[0]->Index;
}

////////////////////////////////////////////////////////////////////////

int MetGrib2DataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetGrib2DataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}

////////////////////////////////////////////////////////////////////////
//
// Begin utility functions.
Expand Down
5 changes: 5 additions & 0 deletions src/libcode/vx_data2d_grib2/data2d_grib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class MetGrib2DataFile : public Met2dDataFile {

int index(VarInfo &);

// retrieve a vector of all requested data planes

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

//
// do stuff
//
Expand Down
13 changes: 13 additions & 0 deletions src/libcode/vx_data2d_nc_met/data2d_nc_met.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,16 @@ int MetNcMetDataFile::index(VarInfo &vinfo) {
}

////////////////////////////////////////////////////////////////////////

int MetNcMetDataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetNcMetDataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}

////////////////////////////////////////////////////////////////////////
5 changes: 5 additions & 0 deletions src/libcode/vx_data2d_nc_met/data2d_nc_met.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class MetNcMetDataFile : public Met2dDataFile {

int index(VarInfo &);

// retrieve a vector of all requested data planes

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

//
// do stuff
//
Expand Down
15 changes: 15 additions & 0 deletions src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,18 @@ int MetNcPinterpDataFile::data_plane_array(VarInfo &vinfo,
int MetNcPinterpDataFile::index(VarInfo &vinfo){
return -1;
}

////////////////////////////////////////////////////////////////////////

int MetNcPinterpDataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetNcPinterpDataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}

////////////////////////////////////////////////////////////////////////
5 changes: 5 additions & 0 deletions src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class MetNcPinterpDataFile : public Met2dDataFile {

int index(VarInfo &);

// retrieve a vector of all requested data planes

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

//
// do stuff
//
Expand Down
13 changes: 13 additions & 0 deletions src/libcode/vx_data2d_nccf/data2d_nccf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ int MetNcCFDataFile::index(VarInfo &vinfo){

////////////////////////////////////////////////////////////////////////

int MetNcCFDataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetNcCFDataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}

////////////////////////////////////////////////////////////////////////

long MetNcCFDataFile::convert_time_to_offset(long time_value) {
bool found = false;
bool found_value = false;
Expand Down
4 changes: 4 additions & 0 deletions src/libcode/vx_data2d_nccf/data2d_nccf.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class MetNcCFDataFile : public Met2dDataFile {

int index(VarInfo &);

// retrieve a vector of all requested data planes

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

//
// do stuff
Expand Down
14 changes: 14 additions & 0 deletions src/libcode/vx_data2d_python/data2d_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,17 @@ return ( 0 );

////////////////////////////////////////////////////////////////////////


int MetPythonDataFile::data_planes(vector<VarInfo*> &vi_list,
vector<DataPlane> &dp_list) {

// TODO implement this

mlog << Error << "\nMetPythonDataFile::data_planes() -> "
<< "not yet implemented!\n\n";
exit(1);

}


////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions src/libcode/vx_data2d_python/data2d_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class MetPythonDataFile : public Met2dDataFile {

int index(VarInfo &);

int data_planes(std::vector<VarInfo*>&,
std::vector<DataPlane>&);

bool data_plane(DataPlane &);

};
Expand Down
87 changes: 87 additions & 0 deletions src/libcode/vx_series_data/series_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

////////////////////////////////////////////////////////////////////////

using namespace std;

#include <cstdio>
#include <fstream>
#include <iostream>
Expand All @@ -23,6 +25,9 @@
static bool read_single_entry(VarInfo*, const ConcatString&, const GrdFileType,
DataPlane&, Grid&);

static bool read_all_entries(vector<VarInfo*>&, const ConcatString&, const GrdFileType,
vector<DataPlane>&, Grid&);

////////////////////////////////////////////////////////////////////////

bool get_series_entry(int i_series, VarInfo* data_info,
Expand Down Expand Up @@ -103,3 +108,85 @@ bool read_single_entry(VarInfo* info, const ConcatString& filename,
}

////////////////////////////////////////////////////////////////////////

bool get_series_entries(int i_series, vector<VarInfo*> &vi_list,
const StringArray &search_files, const GrdFileType type,
vector<DataPlane> &dp_list, Grid &grid,
bool error_out, bool print_warning) {
int i;
bool found;

// Check for at least one field requested
if(vi_list.size() <= 0) return(false);

// Save the log print warning state
bool save_print_warning_state = mlog.print_warning();

// Suppress log warnings, if requested
if(!print_warning) mlog.set_print_warning(false);

mlog << Debug(3)
<< "Processing series entry " << i_series + 1 << ": "
<< vi_list[0]->magic_time_str() << "\n";

// Initialize
dp_list.clear();

// Search for data, beginning with the i_series index
for(i=0,found=false; i<search_files.n(); i++) {

int i_cur = (i_series + i) % search_files.n();

found = read_all_entries(vi_list, search_files[i_cur],
type, dp_list, grid);

// Break out of the loop if data was found
if(found) break;

} // end for i

// Error out if not found and specified
if(!found && error_out) {
mlog << Error << "\nget_series_entries() -> "
<< "Could not find data for " << vi_list[0]->magic_time_str()
<< " in file list:\n" << write_css(search_files) << "\n\n";
exit(1);
}

// Restore warnings to their original state
mlog.set_print_warning(save_print_warning_state);

return(found);
}

////////////////////////////////////////////////////////////////////////

bool read_all_entries(vector<VarInfo*> &vi_list, const ConcatString &filename,
const GrdFileType type, vector<DataPlane> &dp_list, Grid &grid) {

Met2dDataFileFactory mtddf_factory;
Met2dDataFile* mtddf = (Met2dDataFile*) 0;

// Check that file exists
if(!file_exists(filename.c_str())) {
mlog << Warning << "\nread_all_entries() -> "
<< "File does not exist: " << filename << "\n\n";
return(false);
}

// Open data file
mtddf = mtddf_factory.new_met_2d_data_file(filename.c_str(), type);

// Attempt to read gridded data
int n_valid = mtddf->data_planes(vi_list, dp_list);

// Store grid
if(n_valid > 0) grid = mtddf->grid();

// Cleanup
if(mtddf) { delete mtddf; mtddf = (Met2dDataFile *) 0; }

return(n_valid > 0);
}

////////////////////////////////////////////////////////////////////////
7 changes: 7 additions & 0 deletions src/libcode/vx_series_data/series_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

////////////////////////////////////////////////////////////////////////

#include <vector>

#include "vx_util.h"
#include "vx_log.h"
#include "vx_data2d.h"
Expand All @@ -26,6 +28,11 @@ bool get_series_entry(int, VarInfo*, const StringArray&,
bool error_out=true,
bool print_warning=true);

bool get_series_entries(int, std::vector<VarInfo*>&, const StringArray&,
const GrdFileType, std::vector<DataPlane>&, Grid&,
bool error_out=true,
bool print_warning=true);

////////////////////////////////////////////////////////////////////////

#endif // __SERIES_DATA_H__
Expand Down
Loading

0 comments on commit bfe80f1

Please sign in to comment.