Go to the documentation of this file.
14 #define BOUNDS_ERROR 110
23 int main(
int argc,
char** argv) {
33 sscan = atoi(argv[2]) - 1;
34 escan = atoi(argv[3]) - 1;
35 outFilename = argv[4];
36 }
else if (argc == 7) {
38 spixl = atoi(argv[2]) - 1;
39 epixl = atoi(argv[3]) - 1;
40 sscan = atoi(argv[4]) - 1;
41 escan = atoi(argv[5]) - 1;
42 outFilename = argv[6];
44 printf(
"\nusage: l1bextract_meris infile [spixl epixl] sscan escan outfile\n");
46 printf(
" infile - input envsat file\n");
47 printf(
" spixl - start pixel (1-based)\n");
48 printf(
" epixl - end pixel (1-based)\n");
49 printf(
" sscan - start scan line (1-based)\n");
50 printf(
" escan - end scan line (1-based)\n");
51 printf(
" outfile - output file name\n");
55 if ((spixl > epixl) || (sscan > escan)) {
56 printf(
"Invalid range requested:\n");
57 int npixl = epixl - spixl + 1;
58 int nscan = escan - sscan + 1;
59 printf(
"spixl: %5d epixl: %5d npixl: %5d\n", spixl+1, epixl+1, npixl);
60 printf(
"sscan: %5d escan: %5d nscan: %5d\n", sscan+1, escan+1,
nscan);
66 printf(
"Error: Could not open file %s\n", inFilename.c_str());
70 printf(
"Error: Could not read header for file %s\n", inFilename.c_str());
76 printf(
"Error: Could not get MPH from file\n");
81 printf(
"Error: Could not get SPH from file\n");
86 printf(
"Original File-------------------------------\n");
95 printf(
"Error: Could not get MPH from file2\n");
100 printf(
"Error: Could not get SPH from file2\n");
110 if (sscan >= origNumScans) {
111 printf(
"sscan %d >= scan count (%d)\n",
112 sscan, origNumScans);
116 escan = origNumScans - 1;
117 if (escan >= origNumScans) {
118 printf(
"escan %d >= scan count (%d); adjusting.\n",
119 escan, origNumScans);
120 escan = origNumScans - 1;
124 int sscanTiepoint = sscan / linesPerTiepoint;
125 int escanTiepoint = escan / linesPerTiepoint;
126 if (escan % linesPerTiepoint > 0)
130 sscan = sscanTiepoint * linesPerTiepoint;
133 int sscanQuality = sscanTiepoint / 8;
134 int escanQuality = escanTiepoint / 8;
135 if (escanTiepoint % 8 > 0)
139 int numScans = escan - sscan + 1;
140 int numScansTiepoint = escanTiepoint - sscanTiepoint + 1;
141 int numScansQuality = escanQuality - sscanQuality + 1;
146 if (spixl >= origNumPixels) {
147 printf(
"spixl %d >= pixel count (%d)\n",
148 spixl, origNumPixels);
153 if (epixl >= origNumPixels) {
154 printf(
"epixl %d >= pixel count (%d); adjusting.\n",
155 epixl, origNumPixels);
163 int tmp_spixl = spixl;
167 spixl = origNumPixels - epixl - 1;
172 epixl = origNumPixels - tmp_spixl - 1;
188 int64_t dsSize = numScansQuality * dsd2->
getDSRSize();
196 int64_t dsSize = numScansTiepoint * dsd2->
getDSRSize();
200 }
else if (dsd2->
getType() ==
'M') {
204 int64_t dsSize = numScans * dsd2->
getDSRSize();
208 }
else if (dsd2->
getType() ==
'R') {
231 printf(
"Error: Could not find Tiepoint DSD\n");
239 if (envsatFile->
seekData(dsd, sscanTiepoint)) {
240 printf(
"Error: Could seek to DSR#%d of Tiepoint DSD\n", sscanTiepoint);
243 if (envsatFile->
readData(tiepointDSR1)) {
244 printf(
"Error: Could read data for DSR#%d of Tiepoint DSD\n", sscanTiepoint);
249 printf(
"sscan tiepoint# = %d\n", sscanTiepoint);
250 tiepointDSR1->
print();
254 int startTiepoint, midTiepoint, endTiepoint;
259 startTiepoint = spixl / samplesPerTiepoint;
264 endTiepoint = epixl / samplesPerTiepoint;
266 midTiepoint = (endTiepoint - startTiepoint) / 2 + startTiepoint;
278 int tiepointIndex1, tiepointIndex2;
279 int tiepointScan1, tiepointScan2;
280 tiepointIndex1 = escan / linesPerTiepoint;
281 if (tiepointIndex1 >= (dsd->
getNumDSRs() - 1)) {
284 tiepointIndex2 = tiepointIndex1 + 1;
285 tiepointScan1 = tiepointIndex1 * linesPerTiepoint;
286 tiepointScan2 = tiepointIndex2 * linesPerTiepoint;
288 if (envsatFile->
seekData(dsd, tiepointIndex1)) {
289 printf(
"Error: Could not seek file position for DSR#%d of DSD \"%s\"\n", tiepointIndex1, dsd->
getName().c_str());
292 if (envsatFile->
readData(tiepointDSR1)) {
293 printf(
"Error: Could not read data for DSR#%d of DSD \"%s\"\n", tiepointIndex1, dsd->
getName().c_str());
296 if (envsatFile->
readData(tiepointDSR2)) {
297 printf(
"Error: Could not read data for DSR#%d of DSD \"%s\"\n", tiepointIndex1 + 1, dsd->
getName().c_str());
302 printf(
"tiepointScan1 = %d\n", tiepointScan1);
303 printf(
"tiepointScan2 = %d\n", tiepointScan2);
304 tiepointDSR1->
print();
307 double x1, x2, y1, y2;
317 y1 = tiepointDSR1->
getLat(startTiepoint);
318 y2 = tiepointDSR2->
getLat(startTiepoint);
321 y1 = tiepointDSR1->
getLon(startTiepoint);
322 y2 = tiepointDSR2->
getLon(startTiepoint);
325 y1 = tiepointDSR1->
getLat(midTiepoint);
326 y2 = tiepointDSR2->
getLat(midTiepoint);
329 y1 = tiepointDSR1->
getLon(midTiepoint);
330 y2 = tiepointDSR2->
getLon(midTiepoint);
333 y1 = tiepointDSR1->
getLat(endTiepoint);
334 y2 = tiepointDSR2->
getLat(endTiepoint);
337 y1 = tiepointDSR1->
getLon(endTiepoint);
338 y2 = tiepointDSR2->
getLon(endTiepoint);
344 if (spixl == -1 && epixl == -1)
352 printf(
"\n\nModify File-------------------------------\n");
358 printf(
"Error: Could not open file \"%s\"\n", envsatFile2->
getFileName().c_str());
362 printf(
"Error: Could not write header for file \"%s\"\n", envsatFile2->
getFileName().c_str());
375 printf(
"copying DSD %s\n", dsd->
getName().c_str());
381 bool extractPixel =
false;
387 start = sscanQuality;
392 start = sscanTiepoint;
394 }
else if (dsd->
getType() ==
'M') {
396 if (dsd->
getName().substr(0, 12).compare(
"Radiance MDS") == 0)
398 else if (dsd->
getName().substr(0, 9).compare(
"Flags MDS") == 0) {
414 printf(
"Error: Could not seek file position for DSR#%d of DSD \"%s\"\n",
start, dsd->
getName().c_str());
417 for (
int row =
start; row <= end; row++) {
419 printf(
"Error: Could not read data for DSR#%d of DSD \"%s\"\n", row, dsd->
getName().c_str());
431 printf(
"Error: Could not write data for DSR#%d of DSD \"%s\"\n", row, dsd->
getName().c_str());
virtual int writeData(EnvsatDSR *dsr)
virtual void setDSSize(int64_t size)
virtual const std::string & getQualityName()=0
virtual void setFileName(const std::string &name)
virtual int64_t getDSSize()
virtual int getNumPixels()
virtual EnvsatDSD * findDSD(const std::string &name)
virtual int seekData(EnvsatDSD *dsd, int scanLine=0)
virtual void setFirstLastLat(double lat)=0
virtual void setLastLineTime(double unixTime)=0
virtual EnvsatMPH * getMPH()
virtual double getLon(int pixel)
virtual void setFirstFirstLat(double lat)=0
virtual void setLastLastLat(double lat)=0
virtual int getNumScans()
virtual void setLastFirstLon(double lon)=0
virtual void setFirstFirstLon(double lon)=0
virtual double getLat(int pixel)
virtual int64_t getDSRSize()
virtual int readData(EnvsatDSR *dsr)
virtual int getNumPixels()
virtual void setDSOffset(int64_t offset)
virtual void setFirstLastLon(double lon)=0
virtual double getStartTime()
virtual void setEndPixel(int pix)
virtual void setLastMidLat(double lat)=0
virtual void setFirstLineTime(double unixTime)=0
virtual std::string & getName()
virtual void setNumDSRs(int size)
virtual int getLinesPerTiepoint()=0
virtual int64_t getDSOffset()
virtual void setTotalSize(int64_t size)
virtual EnvsatSPH * getSPH()
virtual const std::string & getTiepointName()=0
virtual void setStartPixel(int pix)
virtual void setFirstMidLon(double lon)=0
virtual void modifyProductName()
virtual int writeHeader()
virtual void setObpgExtract(bool val)
virtual void setLastMidLon(double lon)=0
virtual void printRecursive()
double envsatInterp(double x1, double x2, double y1, double y2, double xin)
virtual int getSamplesPerTiepoint()=0
virtual void setSensingStop(double unixTime)
virtual int openFile(bool write=false)
virtual void setLastFirstLat(double lat)=0
virtual void setLastLastLon(double lon)=0
virtual void setFirstMidLat(double lat)=0
virtual const std::string & getFileName()
virtual void setRange(int offset, int count, int val)
virtual EnvsatDSD * getDSD(int index)
virtual void setSensingStart(double unixTime)
virtual int getNumPixels()