OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
EnvsatMPH.cpp
Go to the documentation of this file.
1 /*
2  * File: EnvsatMPH.cpp
3  * Author: dshea
4  *
5  * Created on November 28, 2012, 1:11 PM
6  */
7 
8 #include "EnvsatMPH.h"
9 
10 #include "EnvsatUtil.h"
11 #include "EnvsatFile.h"
12 
13 #include <string.h>
14 #include <unistd.h>
15 #include <stdio.h>
16 
17 using namespace std;
18 
19 const string EnvsatMPH::TYPE_MERIS_RR_L1 = "MER_RR__1P";
20 const string EnvsatMPH::TYPE_MERIS_FR_L1 = "MER_FR__1P";
21 const string EnvsatMPH::TYPE_MERIS_FRS_L1 = "MER_FRS_1P";
22 const string EnvsatMPH::OBPG_EXTRACT_STRING = "OBPG_EXTRACT=1";
23 const string EnvsatMPH::START_PIXEL_LABEL_STRING = "START_PIXEL=";
24 const string EnvsatMPH::PIXEL_UNITS_STRING = "<pixels>";
25 const string EnvsatMPH::END_PIXEL_LABEL_STRING = "END_PIXEL=";
26 
27 //EnvsatMPH::EnvsatMPH() {
28 // init(NULL);
29 //}
30 
32  init(file);
33 }
34 
36  init(orig.envsatFile);
37  memcpy(this->buffer, orig.buffer, MPH_LENGTH);
38 }
39 
41  delete buffer;
42 }
43 
44 void EnvsatMPH::init(EnvsatFile* file) {
45  buffer = new char[MPH_LENGTH];
46  envsatFile = file;
47 }
48 
49 // note that the EnvsatFile is not copied
50 
52  memcpy(buffer, src.buffer, MPH_LENGTH);
53  return *this;
54 }
55 
56 int EnvsatMPH::readHeader(int fin) {
57  int result;
58  int num = 0;
59 
60  while (num < (int) MPH_LENGTH) {
61  result = read(fin, buffer + num, MPH_LENGTH - num);
62  if (result == -1)
63  return -1;
64  else
65  num += result;
66  }
67  return 0;
68 }
69 
70 int EnvsatMPH::writeHeader(int fout) {
71  int result;
72  int num = 0;
73 
74  while (num < (int) MPH_LENGTH) {
75  result = write(fout, buffer + num, MPH_LENGTH - num);
76  if (result == -1)
77  return -1;
78  else
79  num += result;
80  }
81  return 0;
82 }
83 
85  if (getProductType() == TYPE_MERIS_RR_L1
86  || getProductType() == TYPE_MERIS_FR_L1
87  || getProductType() == TYPE_MERIS_FRS_L1) {
88  return new MerisSPH(envsatFile, getSPHSize(), getNumDSDs(),
89  getDSDSize());
90  }
91  return NULL;
92 }
93 
95  static string name;
96  getString(buffer, name, PRODUCTNAME_OFFSET, PRODUCTNAME_LENGTH);
97  return name;
98 }
99 
100 void EnvsatMPH::setProductName(const string &name) {
101  setString(name, buffer, PRODUCTNAME_OFFSET, PRODUCTNAME_LENGTH);
102 }
103 
105  static string name;
106  getString(buffer, name, PRODUCTNAME_OFFSET, PRODUCT_TYPE_LENGTH);
107  return name;
108 }
109 
111  string str;
112  getString(buffer, str, OBPG_EXTRACT_OFFSET, OBPG_EXTRACT_LENGTH);
113  if (str.compare(OBPG_EXTRACT_STRING) == 0)
114  return true;
115  else
116  return false;
117 }
118 
120  if (val)
121  setString(OBPG_EXTRACT_STRING, buffer, OBPG_EXTRACT_OFFSET, OBPG_EXTRACT_LENGTH);
122  else
123  setString(" ", buffer, OBPG_EXTRACT_OFFSET, OBPG_EXTRACT_LENGTH);
124 }
125 
132  string str;
133  int labelSize = START_PIXEL_LABEL_STRING.size();
134  getString(buffer, str, START_PIXEL_LABEL_OFFSET, labelSize);
135  if (str.compare(START_PIXEL_LABEL_STRING) == 0)
136  return getInt(buffer, START_PIXEL_LABEL_OFFSET + labelSize, START_PIXEL_LENGTH);
137  else
138  return -1;
139 }
140 
146  int labelSize = START_PIXEL_LABEL_STRING.size();
147  int unitsSize = PIXEL_UNITS_STRING.size();
148  if (pix < 1) {
149  setString(" ", buffer, START_PIXEL_LABEL_OFFSET, labelSize + START_PIXEL_LENGTH + unitsSize);
150  return;
151  }
152  setString(START_PIXEL_LABEL_STRING, buffer, START_PIXEL_LABEL_OFFSET, labelSize);
153  setInt(pix, buffer, START_PIXEL_LABEL_OFFSET + labelSize, START_PIXEL_LENGTH);
154  setString(PIXEL_UNITS_STRING, buffer, START_PIXEL_LABEL_OFFSET + labelSize + START_PIXEL_LENGTH, unitsSize);
155 }
156 
163  int labelSize = END_PIXEL_LABEL_STRING.size();
164  string str;
165  getString(buffer, str, END_PIXEL_LABEL_OFFSET, labelSize);
166  if (str.compare(END_PIXEL_LABEL_STRING) == 0) {
167  return getInt(buffer, END_PIXEL_LABEL_OFFSET + labelSize, END_PIXEL_LENGTH);
168  } else
169  return -1;
170 }
171 
176 void EnvsatMPH::setEndPixel(int pix) {
177  int labelSize = END_PIXEL_LABEL_STRING.size();
178  int unitsSize = PIXEL_UNITS_STRING.size();
179  if (pix < 1) {
180  setString(" ", buffer, END_PIXEL_LABEL_OFFSET, labelSize + END_PIXEL_LENGTH + unitsSize);
181  return;
182  }
183  setString(END_PIXEL_LABEL_STRING, buffer, END_PIXEL_LABEL_OFFSET, labelSize);
184  setInt(pix, buffer, END_PIXEL_LABEL_OFFSET + labelSize, END_PIXEL_LENGTH);
185  setString(PIXEL_UNITS_STRING, buffer, END_PIXEL_LABEL_OFFSET + labelSize + END_PIXEL_LENGTH, unitsSize);
186 }
187 
189  string startTime;
190  getString(buffer, startTime, SENSING_START_OFFSET, UTC_DATE_LENGTH);
191  return merisTime2unix(startTime);
192 }
193 
194 void EnvsatMPH::setSensingStart(double unixTime) {
195  setString(unix2merisTime(unixTime), buffer, SENSING_START_OFFSET,
196  UTC_DATE_LENGTH);
197 }
198 
200  string stopTime;
201  getString(buffer, stopTime, SENSING_STOP_OFFSET, UTC_DATE_LENGTH);
202  return merisTime2unix(stopTime);
203 }
204 
205 void EnvsatMPH::setSensingStop(double unixTime) {
206  setString(unix2merisTime(unixTime), buffer, SENSING_STOP_OFFSET,
207  UTC_DATE_LENGTH);
208 }
209 
211  return getInt64(buffer, TOT_SIZE_OFFSET, TOT_SIZE_LENGTH);
212 }
213 
215  setInt64(size, buffer, TOT_SIZE_OFFSET, TOT_SIZE_LENGTH);
216 }
217 
219  return getInt(buffer, SPH_SIZE_OFFSET, SPH_SIZE_LENGTH);
220 }
221 
223  setInt(size, buffer, SPH_SIZE_OFFSET, SPH_SIZE_LENGTH);
224 }
225 
227  return getInt(buffer, NUM_DSD_OFFSET, NUM_DSD_LENGTH);
228 }
229 
230 void EnvsatMPH::setNumDSDs(int num) {
231  setInt(num, buffer, NUM_DSD_OFFSET, NUM_DSD_LENGTH);
232 }
233 
235  return getInt(buffer, DSD_SIZE_OFFSET, DSD_SIZE_LENGTH);
236 }
237 
239  setInt(size, buffer, DSD_SIZE_OFFSET, DSD_SIZE_LENGTH);
240 }
241 
243  return getInt(buffer, NUM_DS_OFFSET, NUM_DS_LENGTH);
244 }
245 
246 void EnvsatMPH::setNumDSs(int num) {
247  setInt(num, buffer, NUM_DS_OFFSET, NUM_DS_LENGTH);
248 }
249 
251  printf("EnvsatMPH-----\n");
252  printf("MPHSize = %d\n", getMPHSize());
253  printf("productName = %s\n", getProductName().c_str());
254  printf("productType = %s\n", getProductType().c_str());
255  if (getObpgExtract())
256  printf("OBPG Extract= 1\n");
257  int i;
258  i = getStartPixel();
259  if (i != -1)
260  printf("startPixel = %d\n", i);
261  i = getEndPixel();
262  if (i != -1)
263  printf("endPixel = %d\n", i);
264  printf("startTime = %s\n", unix2merisTime(getSensingStart()).c_str());
265  printf("stopTime = %s\n", unix2merisTime(getSensingStop()).c_str());
266  printf("totalSize = %ld\n", (long) getTotalSize());
267  printf("SPHSize = %d\n", getSPHSize());
268  printf("numDSDs = %d\n", getNumDSDs());
269  printf("DSDSize = %d\n", getDSDSize());
270  printf("numDSs = %d\n", getNumDSs());
271 }
272 
274  print();
275 }
276 
virtual double getSensingStart()
Definition: EnvsatMPH.cpp:188
virtual int getDSDSize()
Definition: EnvsatMPH.cpp:234
virtual int64_t getTotalSize()
Definition: EnvsatMPH.cpp:210
virtual void setNumDSs(int num)
Definition: EnvsatMPH.cpp:246
virtual EnvsatMPH & operator=(const EnvsatMPH &src)
Definition: EnvsatMPH.cpp:51
#define NULL
Definition: decode_rs.h:63
int64_t getInt64(const char *buffer, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:66
virtual std::string & getProductType()
Definition: EnvsatMPH.cpp:104
int getInt(const char *buffer, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:50
virtual EnvsatSPH * createSPH()
Definition: EnvsatMPH.cpp:84
virtual void setNumDSDs(int num)
Definition: EnvsatMPH.cpp:230
virtual double getSensingStop()
Definition: EnvsatMPH.cpp:199
virtual bool getObpgExtract()
Definition: EnvsatMPH.cpp:110
virtual int getNumDSs()
Definition: EnvsatMPH.cpp:242
virtual void setDSDSize(int size)
Definition: EnvsatMPH.cpp:238
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
virtual ~EnvsatMPH()
Definition: EnvsatMPH.cpp:40
int init(int32_t ipr, int32_t jpr, char *efile, char *pfile)
Definition: proj_report.c:51
virtual int getStartPixel()
Definition: EnvsatMPH.cpp:131
virtual void setEndPixel(int pix)
Definition: EnvsatMPH.cpp:176
void setInt64(int64_t val, char *buffer, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:75
virtual std::string & getProductName()
Definition: EnvsatMPH.cpp:94
static const std::string TYPE_MERIS_FR_L1
Definition: EnvsatMPH.h:22
virtual void print()
Definition: EnvsatMPH.cpp:250
virtual void setTotalSize(int64_t size)
Definition: EnvsatMPH.cpp:214
double merisTime2unix(const string &timeStr)
Definition: EnvsatUtil.cpp:144
void setString(const string &str, char *buffer, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:33
static const std::string TYPE_MERIS_RR_L1
Definition: EnvsatMPH.h:21
virtual void setStartPixel(int pix)
Definition: EnvsatMPH.cpp:145
virtual void printRecursive()
Definition: EnvsatMPH.cpp:273
void getString(const char *buffer, string &str, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:45
void getProductName(char *name, l2prodstr *product)
virtual void setProductName(const std::string &name)
Definition: EnvsatMPH.cpp:100
const char * str
Definition: l1c_msi.cpp:35
virtual void setObpgExtract(bool val)
Definition: EnvsatMPH.cpp:119
virtual int readHeader(int fin)
Definition: EnvsatMPH.cpp:56
virtual void setSensingStop(double unixTime)
Definition: EnvsatMPH.cpp:205
virtual int writeHeader(int fout)
Definition: EnvsatMPH.cpp:70
virtual int getEndPixel()
Definition: EnvsatMPH.cpp:162
const string & unix2merisTime(double unixTime)
Definition: EnvsatUtil.cpp:160
virtual int getNumDSDs()
Definition: EnvsatMPH.cpp:226
virtual void setSPHSize(int size)
Definition: EnvsatMPH.cpp:222
virtual int getSPHSize()
Definition: EnvsatMPH.cpp:218
EnvsatMPH(const EnvsatMPH &orig)
Definition: EnvsatMPH.cpp:35
void setInt(int val, char *buffer, unsigned int offset, int size)
Definition: EnvsatUtil.cpp:59
int i
Definition: decode_rs.h:71
msiBandIdx val
Definition: l1c_msi.cpp:34
static const std::string TYPE_MERIS_FRS_L1
Definition: EnvsatMPH.h:23
virtual void setSensingStart(double unixTime)
Definition: EnvsatMPH.cpp:194