13 #define VERSION "0.998"
14 #define BOUNDS_ERROR 110
45 int main(
int argc,
char* argv[])
48 cout <<
"l1aextract_viirs " <<
VERSION <<
" ("
49 << __DATE__ <<
" " << __TIME__ <<
")" << endl;
53 "l1aextract_viirs infile spixl epixl sline eline outfile\n" << endl;
54 cout <<
" where:" << endl;
55 cout <<
" infile - input VIIRS L1A file\n" << endl;
56 cout <<
" spixl - start pixel (1-based)" << endl;
57 cout <<
" epixl - end pixel (1-based)" << endl;
58 cout <<
" sline - start line (M-band resolution, 1-based)" << endl;
59 cout <<
" eline - end line (M-band resolution, 1-based)" << endl;
60 cout <<
" outfile - output VIIRS L1A extract file" << endl;
63 cout <<
"To extract entire scan line set both spixl and epixl to 0"
71 int32_t spixl, epixl, npixl, sline, eline, sscan, escan,
nscan;
75 istringstream(
str) >> spixl;
76 if (spixl != 0) spixl--;
79 istringstream(
str) >> epixl;
80 if (epixl == 0) epixl = npixels;
84 istringstream(
str) >> sline;
86 sscan = floor(sline / 16);
89 istringstream(
str) >> eline;
91 escan = ceil(eline / 16);
93 if ((spixl > epixl) || (sscan > escan)) {
94 cout <<
"\nInvalid range requested:" << endl;
95 npixl = epixl - spixl + 1;
96 nscan = escan - sscan + 1;
97 printf(
"spixl: %4d epixl: %4d npixl: %4d\n", spixl+1, epixl+1, npixl);
98 printf(
"sscan: %4d escan: %4d nscan: %4d\n", sscan+1, escan+1,
nscan);
105 int ncid =
infile.getNcid();
106 nc_get_att(ncid, NC_GLOBAL,
"number_of_filled_scans", &nfilled);
110 nscan = escan - sscan + 1;
112 cout <<
"Adjusting start/end scans so that extract is at least 8 scans"
118 half_diff =
diff / 2;
120 half_diff = (
diff / 2) + 1;
122 if ((sscan - half_diff) < 0) {
123 escan = escan + 2 * half_diff - sscan;
125 }
else if ((escan + half_diff) > (nfilled - 1)) {
126 sscan = sscan - 2 * half_diff + ((nfilled - 1) - escan);
129 sscan = sscan - half_diff;
130 escan = escan + half_diff;
133 nscan = escan - sscan + 1;
137 spixl = (spixl / 16) * 16;
138 epixl = (epixl / 16) * 16 + 15;
139 npixl = epixl - spixl + 1;
142 if (spixl >= npixels) {
143 cout <<
"spixl " << spixl <<
" >= pixel count ("
144 << npixels <<
")" << endl;
147 if (epixl >= npixels) {
148 cout <<
"epixl " << epixl <<
" >= pixel count ("
149 << npixels <<
") ; adjusting." << endl;
152 if (sscan >= nfilled) {
153 cout <<
"sscan " << sscan <<
" >= scan count ("
154 << nfilled <<
")" << endl;
157 if (escan >= nfilled) {
158 cout <<
"escan " << escan <<
" >= scan count ("
159 << nfilled <<
") ; adjusting." << endl;
164 cout <<
"Adjusted extract range:" << endl;
165 printf(
"spixl: %4d epixl: %4d npixl: %4d\n", spixl+1, epixl+1, npixl);
166 printf(
"sscan: %4d escan: %4d nscan: %4d\n", sscan+1, escan+1,
nscan);
172 outfile.
createl1(argv[6], sscan, escan, spixl, epixl, (int32_t) 1);
174 infile.copyl1(argv[1], argv[6], &outfile, sscan, escan, spixl, epixl);