NASA Logo
Ocean Color Science Software

ocssw V2022
l1_seawifs_netcdf.cpp
Go to the documentation of this file.
1 #include <netcdf>
2 #include <iostream>
3 #include "l1_seawifs_netcdf.h"
4 #include "l1.h"
5 #include "l1a.h"
6 #include "eng_qual.h"
7 #include "cal_l1a.h"
8 #include "call1a_proto.h"
9 #include "getcal_proto.h"
10 #include "l1a_proto.h"
11 #include "navigation.h"
12 #include "st_proto.h"
13 
14 using namespace std;
15 using namespace netCDF;
16 using namespace netCDF::exceptions;
17 
18 
19 #define LAC_PIXEL_NUM 1285
20 #define GAC_PIXEL_NUM 248
21 #define NREC_IN_BUF 10
22 #define STBUFSIZ 5
23 #define NOTDONE 0
24 #define FIRST_KNEE 1
25 #define MASK_HIGHLT1 16
26 #define GENBUFSIZ NREC_IN_BUF*sizeof(float)*40 /* size of inst_ana */
27 
28 static int16_t syear, sday; /* data start date */
29 static int32_t smsec; /* data start time */
30 static int16_t eyear, eday; /* data end date */
31 static int32_t emsec; /* data end time */
32 static int32_t nscan; /* number of scans */
33 static int32_t npix; /* number pixels per scan */
34 static int32_t spix; /* start pixel number (from 0) */
35 static int32_t dpix; /* LAC pixel increment */
36 static float dark_mean[8]; /* Mean of dark restore counts */
37 static float dark_std[8]; /* Std dev of dark restore counts */
38 
39 static char cal_path_tab[128];
40 static char dtype[8];
41 
44 static short l2_flags_buffer[LAC_PIXEL_NUM];
45 
46 static int32_t nsta;
47 static int32_t ninc;
48 
49 static int16_t *l1a_data = NULL; /* raw radiances band-int-by-pix */
50 static int16_t *l1a_back = NULL; /* raw radiances band-int-by-pix */
51 static float *l1b_buffer = NULL; /* l1b radiances band-int-by-pix */
52 static int32_t *msec;
53 static int16_t *side;
54 static int16_t *dark_rest;
55 static float *tilt;
56 
57 static float ylat[LAC_PIXEL_NUM];
58 static float xlon[LAC_PIXEL_NUM];
59 static float solz[LAC_PIXEL_NUM];
60 static float sola[LAC_PIXEL_NUM];
61 static float senz[LAC_PIXEL_NUM];
62 static float sena[LAC_PIXEL_NUM];
63 
64 static int16_t stray_light = -1; /* num pixels to apply sl correct. */
65 static float Ltyp_frac = 0.25; /* fraction of B8 for sl threshold */
66 
67 typedef struct {
68  int16_t gain[8];
69  int16_t tdi[8];
70  int16_t scan_temp[8];
71  float inst_temp[40];
72  float orb_vec[3];
73  float sun_ref[3];
74  float sen_mat[3 * 3];
75  float scan_ell[6];
76 } inputBuffer;
77 
78 
79 static int32_t do_st = 1;
80 
81 
96  inputBuffer rdBuf[],
97  byte genBuf[],
98  NcFile &dataFile,
99  string variable,
100  size_t start0,
101  size_t start1,
102  size_t start2,
103  size_t count0,
104  size_t count1,
105  size_t count2,
106  int numBytes,
107  int n_read
108 ) {
109  vector<size_t> start = {start0, start1, start2};
110  vector<size_t> count = {count0, count1, count2};
111  dataFile.getVar(variable).getVar(start, count, (void*)genBuf);
112  for (int i = 0; i < n_read; i++)
113  if (variable == "gain")
114  memcpy(&rdBuf[i].gain, &genBuf[i * numBytes], numBytes);
115  else if (variable == "tdi")
116  memcpy(&rdBuf[i].tdi, &genBuf[i * numBytes], numBytes);
117  else if (variable == "scan_temp")
118  memcpy(&rdBuf[i].scan_temp, &genBuf[i * numBytes], numBytes);
119  else if (variable == "inst_ana")
120  memcpy(&rdBuf[i].inst_temp, &genBuf[i * numBytes], numBytes);
121  else if (variable == "orb_vec")
122  memcpy(&rdBuf[i].orb_vec, &genBuf[i * numBytes], numBytes);
123  else if (variable == "sun_ref")
124  memcpy(&rdBuf[i].sun_ref, &genBuf[i * numBytes], numBytes);
125  else if (variable == "scan_ell")
126  memcpy(&rdBuf[i].scan_ell, &genBuf[i * numBytes], numBytes);
127  else if (variable == "sen_mat")
128  memcpy(&rdBuf[i].sen_mat, &genBuf[i * numBytes], numBytes);
129 }
130 
131 extern "C" int32_t get_l1a_rec_netcdf(filehandle *file, int32_t recno, cal_mod_struc *cal_mod,
132  int16_t *l1a_dum, float **l1b_data, int16_t **l2_flags) {
133  /* */
134  /* local vars */
135  /* */
136  int32_t ipix; /* pixel number */
137  int32_t idet; /* detector number */
138  int32_t irec;
139  int16_t band_buf[LAC_PIXEL_NUM * 8];
140  int32_t scan_no;
141  int16_t gain8;
142  int32_t AS_pixels;
143  float Styp_frac = 0.9;
144  int32_t sl_scan;
145  int16_t *l1a_ptr;
146  int16_t *gain_ptr;
147 
148  static inputBuffer rdBuf[NREC_IN_BUF];
149  static inputBuffer bkBuf[STBUFSIZ - 2];
150  byte genBuf[GENBUFSIZ];
151 
152  static int32_t crec = -1;
153  static int16_t recursive_flag = 0;
154  static int16_t n_read = 0;
155  static int32_t max_rec_in_rdbuf;
156  static int32_t offset;
157  static int32_t j;
158  static int32_t stray_light_scan_no;
159 
160  static float *st_l1b_data;
161  static int16_t *st_l2_flags;
162 
163  static int32_t initial = 1;
164  static byte first = 1;
165 
166 
167  static int16_t hi_Lt[LAC_PIXEL_NUM]; /* whether radiance > knee */
168  int pixvalue; /* l1a pixel value */
169  int pixdark; /* dark_restore value for each pixel */
170  float kneevalue; /* radiance at first knee */
171 
172  // Used to read variable data from a netcdf file
173  vector<size_t> start = {0, 0, 0}; // Starting position index.
174  vector<size_t> count = {0, 0, 0}; // slice/poirtion of the data from start to read
175 
176 
177  /* */
178  /* Read L1A data scan by scan, build L1B record, and write. */
179 
180  /* If reading out-of-sequence, force restart from beginning to get stlight */
181  /* baf, 05-oct-2001. */
182  if (first || recno < crec) {
183  max_rec_in_rdbuf = recno - 1;
184  stray_light_scan_no = recno;
185  }
186 
187  crec = recno;
188 
189  if (crec > nscan) return 0;
190 
191  if (crec > max_rec_in_rdbuf) {
192 
193  memcpy(&bkBuf, &rdBuf[NREC_IN_BUF - STBUFSIZ + 2],
194  sizeof (inputBuffer) * (STBUFSIZ - 2));
195  memcpy(l1a_back, &l1a_data[(NREC_IN_BUF - STBUFSIZ + 2) * npix * 8],
196  npix * 8 * (STBUFSIZ - 2) * sizeof (int16_t));
197 
198  n_read = (nscan - max_rec_in_rdbuf >= NREC_IN_BUF) ?
199  NREC_IN_BUF : nscan - max_rec_in_rdbuf;
200 
201 
202  try {
203  NcFile dataFile(file->name, NcFile::read);
204 
205  // starting position of the array to read. 3rd index only used for 3D arrays
206  start[0] = 0;
207  start[1] = 0;
208  start[2] = 0;
209  // how large the data to read from start. 3rd index only used for 3D arrays
210  count[0] = 1;
211  count[1] = (size_t) npix;
212  count[2] = 8;
213 
214  for (irec = 0; irec < n_read; irec++) {
215  start[0]= (size_t) (recno - 1 + irec);
216  dataFile.getVar("l1a_data").getVar(start, count, (void*) band_buf);
217  for (ipix = 0; ipix < npix; ipix++) {
218  for (idet = 0; idet < 8; idet++) {
219  l1a_data[irec * (8 * npix) + idet * npix + ipix] =
220  band_buf[ipix * 8 + idet];
221  }
222  }
223  }
224 
225 
226  // Get variables and copy them to the reading buffer for calculation
227 
229  rdBuf, // reference the buffer and datafiles
230  genBuf,
231  dataFile,
232  "gain",
233  recno-1, 0, 0, // start
234  n_read, 8, 0, // count
235  8*2, // numBytes 8 columns, int_16 = 2 bytes
236  n_read
237  );
238 
240  rdBuf,
241  genBuf,
242  dataFile,
243  "tdi",
244  recno-1, 0, 0, // start
245  n_read, 8, 0, // count
246  8*2, // numBytes 8 columns, int_16 = 2 bytes
247  n_read
248  );
249 
251  rdBuf,
252  genBuf,
253  dataFile,
254  "scan_temp",
255  recno-1, 0, 0, // start
256  n_read, 8, 0, // count
257  8*2, // numBytes 8 columns, int_16 = 2 bytes
258  n_read
259  );
260 
262  rdBuf,
263  genBuf,
264  dataFile,
265  "inst_ana",
266  recno-1, 0, 0, // start
267  n_read, 8, 0, // count
268  40*4, // numBytes 40 columns, float = 4 bytes
269  n_read
270  );
271 
273  rdBuf,
274  genBuf,
275  dataFile,
276  "orb_vec",
277  recno-1, 0, 0, // start
278  n_read, 3, 0, // count
279  3*4, // numBytes 3 columns, float = 4 bytes
280  n_read
281  );
282 
284  rdBuf,
285  genBuf,
286  dataFile,
287  "sun_ref",
288  recno-1, 0, 0, // start
289  n_read, 3, 0, // count
290  3*4, // numBytes 3 columns, float = 4 bytes
291  n_read
292  );
293 
295  rdBuf,
296  genBuf,
297  dataFile,
298  "scan_ell",
299  recno-1, 0, 0, // start
300  n_read, 6, 0, // count
301  6*4, // numBytes 6 columns, float = 4 bytes
302  n_read
303  );
304 
306  rdBuf,
307  genBuf,
308  dataFile,
309  "sen_mat",
310  recno-1, 0, 0, // start
311  n_read, 3, 3, // count
312  9*4, // numBytes 9 columns, float = 4 bytes
313  n_read
314  );
315 
316  offset = max_rec_in_rdbuf + 1;
317  max_rec_in_rdbuf += n_read;
318 
319  }
320  catch (NcException& e) {
321  cout << "-E- Error getting L1A Data in Seawifs l2gen reader: " << e.what() << endl;
322  exit(1);
323  }
324  }
325 
326  if ((crec - offset) >= 0) {
327  j = crec - offset;
328  gain8 = rdBuf[j].gain[7];
329  gain_ptr = rdBuf[j].gain;
330  l1a_ptr = &l1a_data[j * 8 * npix];
331 
332  l1b_rad(syear, sday, smsec, msec[recno - 1],
333  dtype, nsta, ninc, npix,
334  dark_mean, rdBuf[j].gain, rdBuf[j].tdi,
335  rdBuf[j].scan_temp, rdBuf[j].inst_temp, side[recno - 1],
336  &l1a_data[j * 8 * npix], l1b_buffer, cal_mod);
337 
338  if (!recursive_flag) {
339  geonav_(rdBuf[j].orb_vec, rdBuf[j].sen_mat, rdBuf[j].scan_ell,
340  rdBuf[j].sun_ref, &nsta, &ninc, &npix,
341  ylat, xlon, solz, sola, senz, sena);
342 
343  }
344  } else {
345  j = (STBUFSIZ - 2) + (crec - offset);
346  gain8 = bkBuf[j].gain[7];
347  gain_ptr = bkBuf[j].gain;
348  l1a_ptr = &l1a_back[j * 8 * npix];
349 
350  if (!recursive_flag) {
351  geonav_(bkBuf[j].orb_vec, bkBuf[j].sen_mat, bkBuf[j].scan_ell,
352  bkBuf[j].sun_ref, &nsta, &ninc, &npix,
353  ylat, xlon, solz, sola, senz, sena);
354  }
355  }
356  if (first) {
357  memcpy(pcal_counts, cal_counts, sizeof (cal_counts));
358  memcpy(pcal_rads, cal_rads, sizeof (cal_rads));
359  first = 0;
360  }
361 
362  if (!recursive_flag) {
363  for (ipix = 0; ipix < npix; ipix++) {
364  hi_Lt[ipix] = FALSE;
365  /* HILT check limited to bands 7 & 8, BAF, 23 Jan 2002 */
366  /* Use dark_mean rather than dark_rest, BAF, 7 July 2003 */
367  for (idet = 6; (idet < 8)&&(hi_Lt[ipix] == FALSE); idet++) {
368  pixvalue = l1a_ptr[ipix + npix * idet];
369  /*
370  pixdark = dark_rest[8*(recno-1)+idet];
371  */
372  pixdark = dark_mean[idet];
373  kneevalue = pcal_counts[idet][gain_ptr[idet]][FIRST_KNEE];
374  hi_Lt[ipix] = ((pixvalue - pixdark) >= kneevalue);
375  }
376  }
377  }
378 
379 
380  scan_no = crec;
381  AS_pixels = stray_light;
382 
383  if (do_st == 0) {
384 
385  for (ipix = 0; ipix < npix; ipix++)
386  l2_flags_buffer[ipix] = 0;
387 
388  } else if (!recursive_flag) {
389 
390  do {
391  if (stray_light_scan_no != scan_no) {
392 
393  recursive_flag = 1;
394 
395  get_l1a_rec_netcdf(file, stray_light_scan_no, cal_mod,
396  l1a_dum, &st_l1b_data, &st_l2_flags);
397  }
398  } while (stray_light_corr(&initial, Ltyp_frac, Styp_frac,
399  nscan, npix, stray_light_scan_no++, dtype,
400  gain8, &pcal_rads[0][0][0], l1b_buffer, &sl_scan,
401  l2_flags_buffer, &AS_pixels) == NOTDONE);
402  recursive_flag = 0;
403  crec = scan_no;
404 
405  }
406 
407  for (ipix = 0; ipix < npix; ipix++) {
408  if (hi_Lt[ipix])
409  l2_flags_buffer[ipix] |= MASK_HIGHLT1;
410  }
411 
412  *l1b_data = l1b_buffer;
413  *l2_flags = l2_flags_buffer;
414 
415  return (0);
416 }
417 
418 extern "C" int openl1_seawifs_netcdf(filehandle *file) {
419 
420  /* */
421  /* input files */
422  /* */
423  char *cal_path = l1_input->calfile;
424 
425  /* */
426  /* get_l1a_open interface */
427  /* */
428  char buf[32];
429 
430  // Reading some Global Attributes and Dimentions
431  try {
432  NcFile dataFile(file->name, NcFile::read);
433 
434  /*
435  NetCDF contains only the isodate for the start and end time.
436  The temp variable will store the isodate and then call the conversion function
437  that will convert and set the start/end year, day and msec
438  */
439  char tempTimeCoverage[27];
440 
441  // Start Time
442  dataFile.getAtt("time_coverage_start").getValues((void*) &tempTimeCoverage);
443 
444  // temp to hold the value and then reassign it to the 16 bit int
445  int32_t tempDay, tempYear;
446  isodate2ydmsec(tempTimeCoverage, &tempYear, &tempDay, &smsec);
447  sday = tempDay;
448  syear = tempYear;
449 
450  // End Time
451  dataFile.getAtt("time_coverage_end").getValues((void*) &tempTimeCoverage);
452  isodate2ydmsec(tempTimeCoverage, &tempYear, &tempDay, &emsec);
453  eday = tempDay;
454  eyear = tempYear;
455 
456 
457  npix = dataFile.getDim("pixels").getSize();
458  nscan = dataFile.getDim("scans").getSize();
459 
460  dataFile.getAtt("data_type").getValues((void*) &dtype);
461  dataFile.getAtt("LAC_pixel_start_number").getValues((void*) &nsta);
462  dataFile.getAtt("LAC_pixel_subsampling").getValues((void*) &ninc);
463  dataFile.getAtt("orbit_node_longitude").getValues((void*) &file->orbit_node_lon);
464  dataFile.getAtt("orbit_number").getValues((void*) &file->orbit_number);
465  dataFile.getAtt("node_crossing_time").getValues((void*) &buf);
466  file->node_crossing_time = isodate2unix(buf);
467 
468 
469  // Allocate space for data and read them in
470  msec = (int32_t *) calloc(nscan, sizeof (int32_t));
471  side = (int16_t *) calloc(nscan, sizeof (int16_t));
472  dark_rest = (int16_t *) calloc(nscan * 8, sizeof (int16_t));
473  tilt = (float *) calloc(nscan, sizeof (float));
474 
475  dataFile.getVar("scan_time").getVar(msec);
476  dataFile.getVar("side").getVar(side);
477  dataFile.getVar("dark_rest").getVar(dark_rest);
478  dataFile.getVar("tilt").getVar(tilt);
479  }
480  catch (NcException& e) {
481  cout << "-E- Error in reading in openl1a_seawifs_netcdf. NetCDF: " << e.what() << endl;
482  exit(1);
483  }
484 
485  Ltyp_frac = l1_input->sl_frac;
486  stray_light = l1_input->sl_pixl;
487 
488 
489  if (stray_light == 0)
490  do_st = 0;
491  else {
492  do_st = 1;
493  if (stray_light < 0) {
494  if (strcmp(dtype, "GAC") == 0)
495  stray_light = 4;
496  else
497  stray_light = 3;
498  }
499  }
500  /* get the current calibration model solution */
501  if (cal_path == NULL) {
502  fprintf(stderr,
503  "-E %s Line %d: No calibration file specified.\n",
504  __FILE__, __LINE__);
505  exit(1);
506  }
507  read_caltable(cal_path);
508  cdata_();
509 
510  file->npix = npix;
511  file->nscan = nscan;
512  file->sensorID = SEAWIFS;
513 
514  if (strcmp(dtype, "GAC") == 0)
515  strcpy(file->spatialResolution, "4.5 km");
516  else
517  strcpy(file->spatialResolution, "1.1 km");
518 
519  strcpy(cal_path_tab, cal_path);
520 
521  l1a_data = (int16_t *) calloc(npix * 8 * NREC_IN_BUF, sizeof (int16_t));
522  l1a_back = (int16_t *) calloc(npix * 8 * (STBUFSIZ - 2), sizeof (int16_t));
523  l1b_buffer = (float *) calloc(npix * 8, sizeof (float));
524 
526  free(dark_rest);
527  spix = nsta - 1;
528  dpix = ninc;
529 
530  return (0);
531 }
532 
533 extern "C" int readl1_seawifs_netcdf(filehandle *file, int32_t recnum, l1str *l1rec) {
534 
535  /* */
536  /* get_l1a_rec interface */
537  /* */
538  static cal_mod_struc cal_mod; /* cal modification structure */
539  static int16_t *l2_flags; /* radiance quality flags for L2 */
540  static float *l1b_data;
541 
542  int32_t i;
543 
544  int32_t nwave = l1rec->l1file->nbands;
545  int32_t *bindx = (int32_t*) l1rec->l1file->bindx;
546 
547  /* */
548  /* local vars */
549  /* */
550  int32_t ipix; /* pixel number */
551  int32_t iw, ib;
552 
553  int16_t *l1a_dum = NULL;
554 
555  static int32_t prev_recnum = -1;
556 
557  static int16_t first = 1;
558  static int32_t ntilts;
559  static int16_t tilt_flags[20];
560  static int16_t tilt_ranges[2 * 20];
561 
562  int32_t nflag[8];
563 
564 
565  /* If reading out-of-sequence, force restart from beginning to get stlight */
566  /* baf, 05-oct-2001. */
567  if (recnum < prev_recnum) {
568  printf("Reading out-of-sequence %d %d\n", recnum, prev_recnum);
569  prev_recnum = -1;
570  }
571 
572 
573  /* Get tilt info */
574  /* ------------- */
575  try {
576  NcFile dataFile(file->name, NcFile::read);
577 
578  if (first) {
579  ntilts = dataFile.getDim("tilts").getSize();
580  dataFile.getVar("tilt_flags").getVar(tilt_flags);
581  dataFile.getVar("tilt_ranges").getVar(tilt_ranges);
582  first = 0;
583  }
584 
585  /* Check for bad or changing tilt */
586  /* ------------------------------ */
587  for (i = 0; i < ntilts; i++) {
588  if (tilt_ranges[2 * i] <= recnum + 1 && tilt_ranges[2 * i + 1] >= recnum)
589  break;
590  }
591 
592  // read navigation flags for each scan
593  vector<size_t> start = {(size_t) recnum, 0};
594  vector<size_t> count = {1, 8};
595  dataFile.getVar("nflag").getVar(start, count, (void*)&nflag);
596  }
597  catch (NcException& e) {
598  cout << "-E- Error in reading in readl1a_seawifs_netcdf. NetCDF: " << e.what() << endl;
599  exit(1);
600  }
601 
602 
603  // /* Get l1a data */
604  // /* ------------ */
605  for (i = prev_recnum + 1; i <= recnum; i++)
606  get_l1a_rec_netcdf(file, i + 1, &cal_mod, l1a_dum,
607  &l1b_data, &l2_flags);
608 
609  // /* */
610  // /* Copy scan geolocation and view geometry */
611  // /* */
612  memcpy(l1rec->lat, ylat, npix * sizeof (float));
613  memcpy(l1rec->lon, xlon, npix * sizeof (float));
614  memcpy(l1rec->solz, solz, npix * sizeof (float));
615  memcpy(l1rec->sola, sola, npix * sizeof (float));
616  memcpy(l1rec->senz, senz, npix * sizeof (float));
617  memcpy(l1rec->sena, sena, npix * sizeof (float));
618 
619  // /* */
620  // /* Copy L1B radiances, pixel interlaced by band. Add per-band */
621  // /* view angles. */
622  // /* */
623  for (ipix = 0; ipix < file->npix; ipix++) {
624  if (l1rec->sena[ipix] > 180) {
625  l1rec->sena[ipix] -= 360.0;
626  }
627  if (l1rec->sola[ipix] > 180) {
628  l1rec->sola[ipix] -= 360.0;
629  }
630  l1rec->pixnum[ipix] = spix + ipix*dpix;
631  for (iw = 0; iw < nwave; iw++) {
632  ib = bindx[iw];
633  l1rec->Lt [ipix * nwave + ib] = l1b_data[iw * npix + ipix];
634  }
635  l1rec->stlight[ipix] = ((l2_flags[ipix] & STRAYLIGHT) > 0);
636  l1rec->hilt [ipix] = ((l2_flags[ipix] & HILT) > 0);
637  l1rec->navwarn[ipix] = (nflag[7] & 1) | (nflag[0] & 1);
638  }
639 
640 
641  // /* */
642  // /* Set scan time in L1B output record */
643  // /* */
644  double secs = (double) (msec[recnum] / 1.e3);
645  int16_t year = syear;
646  int16_t day = sday;
647 
648  if (msec[recnum] < smsec) { /* adjust for day rollover */
649  day += 1;
650  if (day > (365 + (year % 4 == 0))) {
651  year += 1;
652  day = 1;
653  }
654  }
655  l1rec->scantime = yds2unix(year, day, secs);
656 
657  l1rec->tilt = tilt[recnum];
658  l1rec->mside = side[recnum];
659  prev_recnum = recnum;
660 
661  return (0); // no issues
662 }
663 
664 extern "C" int readl1_lonlat_seawifs_netcdf(filehandle *file, int32_t recnum, l1str *l1rec) {
665  inputBuffer rdBuf;
666 
667  if (recnum > nscan) return 0;
668 
669  try {
670 
671  NcFile dataFile(file->name, NcFile::read);
672 
673  vector<size_t> start = {(size_t) recnum, 0};
674  vector<size_t> count = {0, 0};
675 
676 
677  count[0] = 1;
678  count[1] = 3;
679  dataFile.getVar("orb_vec").getVar(start, count, (void*)rdBuf.orb_vec);
680  dataFile.getVar("sun_ref").getVar(start, count, (void*)rdBuf.sun_ref);
681 
682  count[1] = 6;
683  dataFile.getVar("scan_ell").getVar(start, count, (void*)rdBuf.scan_ell);
684 
685  start = {(size_t)recnum, 0, 0};
686  count = {1, 3, 3};
687  dataFile.getVar("sen_mat").getVar(start, count, (void*)rdBuf.sen_mat);
688 
689  }
690  catch (NcException& e) {
691  cout << "-E- Error in reading seawifs lon and lat data netcdf." << endl;
692  exit(1);
693  }
694 
695  // Lon and lat
696  geonav_(rdBuf.orb_vec, rdBuf.sen_mat, rdBuf.scan_ell,
697  rdBuf.sun_ref, &nsta, &ninc, &npix,
698  l1rec->lat, l1rec->lon, l1rec->solz, l1rec->sola, l1rec->senz, l1rec->sena);
699 
700  // Time
701  double secs = (double) (msec[recnum] / 1.e3);
702  int16_t year = syear;
703  int16_t day = sday;
704 
705  if (msec[recnum] < smsec) { /* adjust for day rollover */
706  day += 1;
707  if (day > (365 + (year % 4 == 0))) {
708  year += 1;
709  day = 1;
710  }
711  }
712  l1rec->scantime = yds2unix(year, day, secs);
713 
714  return (0);
715 }
716 
717 extern "C" int closel1_seawifs_netcdf(filehandle *file) {
718  free(l1a_data);
719  free(l1a_back);
720  free(l1b_buffer);
721  free(msec);
722  free(side);
723  free(tilt);
724 
725  return (0);
726 }
int closel1_seawifs_netcdf(filehandle *file)
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
int16 eday
Definition: l1_czcs_hdf.c:17
int readl1_lonlat_seawifs_netcdf(filehandle *file, int32_t recnum, l1str *l1rec)
float cal_rads[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: calibrate_l1a.c:75
int j
Definition: decode_rs.h:73
float dark_mean[8]
Definition: l1a_seawifs.c:34
int32_t day
double yds2unix(int16_t year, int16_t day, double secs)
Definition: yds2unix.c:7
int16 * gain
Definition: l1_czcs_hdf.c:33
int16_t * l1a_back
Definition: l1a_seawifs.c:85
#define GAINS_DIMS_1A
char cal_path_tab[128]
Definition: l1a_seawifs.c:70
#define FALSE
Definition: rice.h:164
void read_caltable(char *cal_path)
Definition: get_cal_swf.c:152
#define NULL
Definition: decode_rs.h:63
read l1rec
int geonav_(FLOAT32 pos[3], FLOAT32 rm[3][3], FLOAT32 coef[6], FLOAT32 sunref[3], INT32 *spix, INT32 *ipix, INT32 *npix, FLOAT32 lat[], FLOAT32 lon[], FLOAT32 solz[], FLOAT32 sola[], FLOAT32 senz[], FLOAT32 sena[])
void getVariableAndCopyToRdBuffer(inputBuffer rdBuf[], byte genBuf[], NcFile &dataFile, string variable, size_t start0, size_t start1, size_t start2, size_t count0, size_t count1, size_t count2, int numBytes, int n_read)
int32_t do_st
Definition: l1a_seawifs.c:116
#define FIRST_KNEE
int16_t * l1a_data
Definition: l1a_seawifs.c:84
float pcal_rads[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: l1a_seawifs.c:78
int16_t * dark_rest
Definition: l1a_seawifs.c:89
float scan_ell[6]
Definition: l1_seawifs.c:72
float ylat[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:92
float pcal_counts[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: l1a_seawifs.c:77
int32 * msec
Definition: l1_czcs_hdf.c:31
int16 eyear
Definition: l1_czcs_hdf.c:17
int syear
Definition: l1_czcs_hdf.c:15
short l2_flags_buffer[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:79
int32 nscan
Definition: l1_czcs_hdf.c:19
@ STRAYLIGHT
int32 smsec
Definition: l1_czcs_hdf.c:16
int16_t stray_light
Definition: l1a_seawifs.c:100
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
character(len=1000) if
Definition: names.f90:13
int sday
Definition: l1_czcs_hdf.c:15
int32 nsta
Definition: l1_czcs_hdf.c:27
float Ltyp_frac
Definition: l1a_seawifs.c:101
#define NREC_IN_BUF
read recnum
int openl1_seawifs_netcdf(filehandle *file)
#define NOTDONE
#define BANDS_DIMS_1A
Definition: level_1a_index.h:8
#define LAC_PIXEL_NUM
int32 ninc
Definition: l1_czcs_hdf.c:28
void cdata_()
l1_input_t * l1_input
Definition: l1_options.c:9
float sun_ref[3]
Definition: l1_seawifs.c:70
int16_t tdi[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:37
#define STBUFSIZ
int readl1_seawifs_netcdf(filehandle *file, int32_t recnum, l1str *l1rec)
short gain8
Definition: l1a.c:194
integer, parameter double
float dark_std[8]
Definition: l1a_seawifs.c:35
void isodate2ydmsec(char *date, int32_t *year, int32_t *day, int32_t *msec)
Definition: date2ydmsec.c:20
float xlon[LAC_PIXEL_NUM]
Definition: l1a_seawifs.c:93
int32 emsec
Definition: l1_czcs_hdf.c:18
float * l1b_buffer
Definition: l1a_seawifs.c:86
int16_t gain[8]
Definition: l1_seawifs.c:65
int32_t l1b_rad(int syear, int sday, int32_t smsec, int32_t msec, char *dtype, int32_t nsta, int32_t ninc, int32_t npix, float *dark_mean, short *gain, short *tdi, short *scan_temp, float *inst_temp, int mside, short *l1a_data, float *l1b_data, cal_mod_struc *cal_mod)
Definition: get_cal_swf.c:700
int dark_rest_stat(int16 *data, int nrec, float *dark_mean, float *dark_std)
Definition: l1a.c:258
int32 dpix
Definition: l1_czcs_hdf.c:22
dtype
Definition: DDataset.hpp:31
int16_t * side
Definition: l1a_seawifs.c:88
int32 spix
Definition: l1_czcs_hdf.c:21
float orb_vec[3]
Definition: l1_seawifs.c:69
int scan_ell(float p[3], double sm[3][3], double coef[10])
#define MASK_HIGHLT1
int32_t stray_light_corr(int32_t *initial, float Ltyp_frac, float Styp_frac, int32_t nscans, int32_t nsamples, int32_t scan_no, char *dtype, int16_t gn, float *rads, float *l1b_data, int32_t *sl_scan, int16_t *l2_flags, int32_t *AS_pixels)
Definition: st_lt.c:65
int32_t get_l1a_rec_netcdf(filehandle *file, int32_t recno, cal_mod_struc *cal_mod, int16_t *l1a_dum, float **l1b_data, int16_t **l2_flags)
l2prod offset
#define KNEES_DIMS_1A
#define SEAWIFS
Definition: sensorDefs.h:12
int16_t * tilt
Definition: l2bin.cpp:80
#define GENBUFSIZ
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
float cal_counts[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: calibrate_l1a.c:74
int npix
Definition: get_cmp.c:28
float sen_mat[3 *3]
Definition: l1_seawifs.c:71
double isodate2unix(const char *isodate)
Definition: unix2isodate.c:61
int count
Definition: decode_rs.h:79