bes  Updated for version 3.20.10
GeoFile.h
Go to the documentation of this file.
1 
5 
7 
8 #ifndef GEO_FILE_H_
9 #define GEO_FILE_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include <STARE.h>
15 
16 #include "BESInternalError.h"
17 
18 #define SSC_LAT_NAME "Latitude"
19 #define SSC_LON_NAME "Longitude"
20 #define SSC_I_NAME "i"
21 #define SSC_J_NAME "j"
22 #define SSC_INDEX_NAME "STARE_index"
23 #define SSC_COVER_NAME "STARE_cover"
24 #define SSC_LONG_NAME "long_name"
25 #define SSC_INDEX_LONG_NAME "SpatioTemporal Adaptive Resolution Encoding (STARE) index"
26 #define SSC_COVER_LONG_NAME "SpatioTemporal Adaptive Resolution Encoding (STARE) cover"
27 #define SSC_LAT_LONG_NAME "latitude"
28 #define SSC_LON_LONG_NAME "longitude"
29 #define SSC_UNITS "units"
30 #define SSC_LAT_UNITS "degrees_north"
31 #define SSC_LON_UNITS "degrees_east"
32 #define SSC_INDEX_VAR_ATT_NAME "variables"
33 #define SSC_NUM_GRING 4
34 #define SSC_MOD05 "mod05"
35 #define SSC_TITLE_NAME "title"
36 #define SSC_TITLE "SpatioTemporal Adaptive Resolution Encoding (STARE) sidecar file"
37 #define SSC_MAX_NAME 256
38 
39 #define SSC_NDIM1 1
40 #define SSC_NDIM2 2
41 #define NDIM2 2
42 
43 #define SSC_NOT_SIDECAR (-1001)
44 #define MAX_NUM_INDEX 10
49 class GeoFile
50 {
51 private:
52  int d_ncid;
53  int d_num_index;
54  std::string d_data_file_name;
55 
56  std::vector<std::string> d_stare_index_name;
57  std::vector<std::string> stare_cover_name;
58  std::vector<std::string> d_variables;
59  std::vector<size_t> d_size_i, d_size_j;
60  std::vector<int> d_stare_varid;
61 
62  // int *geo_num_i1; /**< Number of I. */
63  // int *geo_num_j1; /**< Number of J. */
64  // double **geo_lat1; /**< Array of latitude values. */
65  // double **geo_lon1; /**< Array of longitude values. */
66  // unsigned long long **geo_index1; /**< Array of STARE index. */
67 
68  // TODO These may be used by the STAREmaster library or createSidecarFile.
69  // jhrg 6/17/21
70 // int num_cover;
71 // unsigned long long **geo_cover1;
72 // int *geo_num_cover_values1;
73 // STARE_SpatialIntervals cover;
74 //
75 // int cover_level;
76 // int perimeter_stride;
77 
78 protected:
79  std::string sanitize_pathname(string path) const;
80 
82  std::string sidecar_filename(const std::string &file_name) const;
83 
84  int read_sidecar_file(const std::string &file_name);
85 
86 public:
87  GeoFile() : d_ncid(-1), d_num_index(0) {};
88 
93  explicit GeoFile(const std::string &data_file_name) : d_ncid(-1), d_num_index(0), d_data_file_name(data_file_name) {
94  // load much of the info and set d_ncid
95  int ret = read_sidecar_file(sidecar_filename(data_file_name));
96  if (ret != NC_NOERR)
97  throw BESInternalError("Could not open file " + sanitize_pathname(data_file_name)
98  + " - " + nc_strerror(ret), __FILE__, __LINE__);
99  };
100 
101  virtual ~GeoFile() { close_sidecar_file(); };
102 
103  // The data types for STARESTARE_ArrayIndexSpatialValue
104  // STARE_SpatialIntervals (which is std::vector<STARE_ArrayIndexSpatialValue>
105  void get_stare_indices(const std::string &var_name, std::vector<STARE_ArrayIndexSpatialValue> &values);
106 
107  size_t get_variable_rows(std::string variable_name) const;
108  size_t get_variable_cols(std::string variable_name) const;
109 
110  void close_sidecar_file();
111 };
112 
113 #endif /* GEO_FILE_H_ */
exception thrown if internal error encountered
int read_sidecar_file(const std::string &file_name)
Read a sidecar file.
Definition: GeoFile.cc:56
std::string sidecar_filename(const std::string &file_name) const
Definition: GeoFile.cc:30
std::string sanitize_pathname(string path) const
Strip away path info. Use in error messages.
Definition: GeoFile.cc:22
void close_sidecar_file()
Definition: GeoFile.cc:191
void get_stare_indices(const std::string &var_name, std::vector< STARE_ArrayIndexSpatialValue > &values)
Definition: GeoFile.cc:137
GeoFile(const std::string &data_file_name)
Open and read the sidecar file for a given data file.
Definition: GeoFile.h:93