NASA Logo
Ocean Color Science Software

ocssw V2022
scaledNcVar.hpp
Go to the documentation of this file.
1 
9 #ifndef SCALED_NCVAR_H
10 #define SCALED_NCVAR_H
11 
12 #define DEFAULT_SENSOR 30 // OCI
13 
14 #include <netcdf>
15 #include <productInfo.h>
16 #include <genutils.h>
17 
18 class ScaledNcVar : public netCDF::NcVar {
19  public:
20 
21  // Copy constructor
22  ScaledNcVar(const NcVar &copied);
23 
24  // destructor
25  ~ScaledNcVar();
26 
32  void getVar(float *dataValues);
33 
39  void getVar(double *dataValues);
40 
45  void getVar(std::vector<size_t> start, std::vector<size_t> count, float *dataValues);
46 
51  void getVar(std::vector<size_t> start, std::vector<size_t> count, double *dataValues);
52 
57  void putVar(const float *dataValues);
58 
63  void putVar(const double *dataValues);
64 
69  void putVar(std::vector<size_t> start, std::vector<size_t> count, const float *dataValues);
70 
75  void putVar(std::vector<size_t> start, std::vector<size_t> count, const double *dataValues);
76 
81  void getFillValue(double *fillValue);
82 
87  void getFillValue(float *fillValue);
88 
89  productInfo_t* getProductInfo() { return prodInfo; }
90 
96 
100  void setScaleFactors(double scale, double offset, double fillValue = BAD_FLT);
101 
106  void assignBadValue(double newValue);
107 
112  void assignFillValue(double newValue);
113 
114  void setProdInfo(productInfo_t* prodInfo) { this->prodInfo = prodInfo; }
115 
116  // netCDF data type for the variable in the file
117  netCDF::NcType::ncType thisVarType = getType().getTypeClass();
118 
119  private:
120  // Indicates whether the scale factors of this NcVar have already been obtained
121  bool scaleFactorsSet = false;
122  // A scalar value that will be added each value stored in this NcVar. 1 by default
123  double scaleFactor = 1.0;
124  // A scalar value that will be added each value stored in this NcVar. 0 by default
125  double addOffset = 0.0;
126  // fill value the netCDF file uses
127  double fillValue = BAD_FLT;
128  // sentinal value for bad data in teh internal memory (usually the fillValue)
129  double badValue = BAD_FLT;
130  // pointer to the product structure from the product.xml file
131  productInfo_t *prodInfo = nullptr;
132 
137  bool floatingPoint();
138 
146  void compress(const double *toCompress, std::vector<int32_t> &compressed, size_t count);
147 
155  void compress(const float *toCompress, std::vector<int32_t> &compressed, size_t count);
156 
164  void uncompress(double *toUncompress, size_t count);
165 
173  void uncompress(float *toUncompress, size_t count);
174 
180  template <typename T>
181  void fillToBad(T *data, size_t count);
182 
188  template <typename T, typename E>
189  void badToFill(const T *data, const size_t &count, std::vector<E> &compressed);
190 
194  void getScaleFactorsFromFile();
195 
200  double initFillValue();
201 
206  std::pair<double, double> range();
207 };
208 
217 ScaledNcVar newScaledNcVar(const netCDF::NcGroup &group, const std::string &name,
218  const std::vector<netCDF::NcDim> &dims, int sensorID = DEFAULT_SENSOR);
219 
220 #endif
netCDF::NcType::ncType thisVarType
productInfo_t * getProductInfo()
Definition: scaledNcVar.hpp:89
void getFillValue(double *fillValue)
Get the fill value of this NcVar.
ScaledNcVar(const NcVar &copied)
Definition: scaledNcVar.cpp:19
@ string
void getVar(float *dataValues)
Takes in a pointer whose memory will be modified. Assumes values found there are integers and perform...
void assignFillValue(double newValue)
Reassign the fill value.
Definition: scaledNcVar.cpp:51
ScaledNcVar newScaledNcVar(const netCDF::NcGroup &group, const std::string &name, const std::vector< netCDF::NcDim > &dims, int sensorID=DEFAULT_SENSOR)
Create a ScaledNcVar using the product.xml for definition.
#define DEFAULT_SENSOR
An extension of NetCDF::NcVar to perform scale and offset when getting a variable.
Definition: scaledNcVar.hpp:12
void setScaleFactors(double scale, double offset, double fillValue=BAD_FLT)
Populate scale factor and add offset manually. Throws an invalid_argument
void putVar(const float *dataValues)
put an entire variable
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
void assignBadValue(double newValue)
Reassign the value of badValue.
Definition: scaledNcVar.cpp:47
#define BAD_FLT
Definition: jplaeriallib.h:19
bool populateScaleFactors(int sensorID=DEFAULT_SENSOR)
Populate scale factor and add offset from product.xml. Assumes default sensor (30 == OCI)
void setProdInfo(productInfo_t *prodInfo)
l2prod offset
int32_t sensorID[MAXNFILES]
Definition: l2bin.cpp:91
int count
Definition: decode_rs.h:79