NASA Logo
Ocean Color Science Software

ocssw V2022
l1_seawifs.c
Go to the documentation of this file.
1 #include <hdf4utils.h>
2 #include "l1a.h"
3 #include "navigation.h"
4 #include "l1a_proto.h"
5 #include "eng_qual.h"
6 #include "l1.h"
7 #include "l1_seawifs.h"
8 #include "cal_l1a.h"
9 #include "call1a_proto.h"
10 #include "getcal_proto.h"
11 #include "st_proto.h"
12 
13 #include <hdf.h>
14 #include <mfhdf.h>
15 
16 #define LAC_PIXEL_NUM 1285
17 #define GAC_PIXEL_NUM 248
18 #define NREC_IN_BUF 10
19 #define STBUFSIZ 5
20 #define NOTDONE 0
21 #define FIRST_KNEE 1
22 #define MASK_HIGHLT1 16
23 #define GENBUFSIZ NREC_IN_BUF*sizeof(float)*40 /* size of inst_ana */
24 
25 static int16_t syear, sday; /* data start date */
26 static int32_t smsec; /* data start time */
27 static int16_t eyear, eday; /* data end date */
28 static int32_t emsec; /* data end time */
29 static int32_t nscan; /* number of scans */
30 static int32_t npix; /* number pixels per scan */
31 static int32_t spix; /* start pixel number (from 0) */
32 static int32_t dpix; /* LAC pixel increment */
33 static float dark_mean[8]; /* Mean of dark restore counts */
34 static float dark_std[8]; /* Std dev of dark restore counts */
35 
36 static char cal_path_tab[128];
37 static char dtype[8];
38 
41 static short l2_flags_buffer[LAC_PIXEL_NUM];
42 
43 static int32_t nsta;
44 static int32_t ninc;
45 
46 static int16_t *l1a_data = NULL; /* raw radiances band-int-by-pix */
47 static int16_t *l1a_back = NULL; /* raw radiances band-int-by-pix */
48 static float *l1b_buffer = NULL; /* l1b radiances band-int-by-pix */
49 static int32_t *msec;
50 static int16_t *side;
51 static int16_t *dark_rest;
52 static float *tilt;
53 
54 static float ylat[LAC_PIXEL_NUM];
55 static float xlon[LAC_PIXEL_NUM];
56 static float solz[LAC_PIXEL_NUM];
57 static float sola[LAC_PIXEL_NUM];
58 static float senz[LAC_PIXEL_NUM];
59 static float sena[LAC_PIXEL_NUM];
60 
61 static int16_t stray_light = -1; /* num pixels to apply sl correct. */
62 static float Ltyp_frac = 0.25; /* fraction of B8 for sl threshold */
63 
64 typedef struct {
65  int16_t gain[8];
66  int16_t tdi[8];
67  int16_t scan_temp[8];
68  float inst_temp[40];
69  float orb_vec[3];
70  float sun_ref[3];
71  float sen_mat[3 * 3];
72  float scan_ell[6];
73 } inputBuffer;
74 
75 
76 static int32_t do_st = 1;
77 
78 int32_t get_l1a_rec(int32_t sd_id, int32_t recno, cal_mod_struc *cal_mod,
79  int16_t *l1a_dum, float **l1b_data, int16_t **l2_flags) {
80  /* */
81  /* local vars */
82  /* */
83  int32_t ipix; /* pixel number */
84  int32_t idet; /* detector number */
85  int32_t irec;
86  int32_t start[3] = {0, 0, 0};
87  int32_t edges[3];
88 
89  int16_t band_buf[LAC_PIXEL_NUM * 8];
90  int32_t scan_no;
91  int16_t gain8;
92  int32_t AS_pixels;
93  float Styp_frac = 0.9;
94  int32_t sl_scan;
95  int16_t *l1a_ptr;
96  int16_t *gain_ptr;
97 
98  static inputBuffer rdBuf[NREC_IN_BUF];
99  static inputBuffer bkBuf[STBUFSIZ - 2];
100  byte genBuf[GENBUFSIZ];
101 
102  static int32_t crec = -1;
103  static int16_t recursive_flag = 0;
104  static int16_t n_read = 0;
105  static int32_t max_rec_in_rdbuf;
106  static int32_t offset;
107  static int32_t i, j;
108  static int32_t stray_light_scan_no;
109 
110  static float *st_l1b_data;
111  static int16_t *st_l2_flags;
112 
113  static int32_t initial = 1;
114  static byte first = 1;
115 
116 
117  static int16_t hi_Lt[LAC_PIXEL_NUM]; /* whether radiance > knee */
118  int pixvalue; /* l1a pixel value */
119  int pixdark; /* dark_restore value for each pixel */
120  float kneevalue; /* radiance at first knee */
121 
122  /* */
123  /* Read L1A data scan by scan, build L1B record, and write. */
124 
125  /* If reading out-of-sequence, force restart from beginning to get stlight */
126  /* baf, 05-oct-2001. */
127  if (first || recno < crec) {
128  max_rec_in_rdbuf = recno - 1;
129  stray_light_scan_no = recno;
130  }
131 
132  crec = recno;
133 
134  if (crec > nscan) return 0;
135 
136 
137  if (crec > max_rec_in_rdbuf) {
138 
139  memcpy(&bkBuf, &rdBuf[NREC_IN_BUF - STBUFSIZ + 2],
140  sizeof (inputBuffer) * (STBUFSIZ - 2));
141  memcpy(l1a_back, &l1a_data[(NREC_IN_BUF - STBUFSIZ + 2) * npix * 8],
142  npix * 8 * (STBUFSIZ - 2) * sizeof (int16_t));
143 
144  n_read = (nscan - max_rec_in_rdbuf >= NREC_IN_BUF) ?
145  NREC_IN_BUF : nscan - max_rec_in_rdbuf;
146 
147 
148  edges[0] = 1;
149  start[1] = 0;
150  edges[1] = npix;
151  edges[2] = 8;
152  for (irec = 0; irec < n_read; irec++) {
153  start[0] = recno - 1 + irec;
154  SDreaddata(SDselect(sd_id, SDnametoindex(sd_id, "l1a_data")),
155  start, NULL, edges, (VOIDP) band_buf);
156  for (ipix = 0; ipix < npix; ipix++)
157  for (idet = 0; idet < 8; idet++)
158  l1a_data[irec * (8 * npix) + idet * npix + ipix] =
159  band_buf[ipix * 8 + idet];
160  }
161 
162 
163  rdSDS(sd_id, "gain", recno - 1, 0, n_read, 8, (VOIDP) genBuf);
164  for (i = 0; i < n_read; i++)
165  memcpy(&rdBuf[i].gain, &genBuf[i * 8 * 2], 8 * 2);
166 
167  rdSDS(sd_id, "tdi", recno - 1, 0, n_read, 8, (VOIDP) genBuf);
168  for (i = 0; i < n_read; i++)
169  memcpy(&rdBuf[i].tdi, &genBuf[i * 8 * 2], 8 * 2);
170 
171  rdSDS(sd_id, "scan_temp", recno - 1, 0, n_read, 8, (VOIDP) genBuf);
172  for (i = 0; i < n_read; i++)
173  memcpy(&rdBuf[i].scan_temp, &genBuf[i * 8 * 2], 8 * 2);
174 
175  rdSDS(sd_id, "inst_ana", recno - 1, 0, n_read, 40, (VOIDP) genBuf);
176  for (i = 0; i < n_read; i++)
177  memcpy(&rdBuf[i].inst_temp, &genBuf[i * 40 * 4], 40 * 4);
178 
179  rdSDS(sd_id, "orb_vec", recno - 1, 0, n_read, 3, (VOIDP) genBuf);
180  for (i = 0; i < n_read; i++)
181  memcpy(&rdBuf[i].orb_vec, &genBuf[i * 3 * 4], 3 * 4);
182 
183  rdSDS(sd_id, "sun_ref", recno - 1, 0, n_read, 3, (VOIDP) genBuf);
184  for (i = 0; i < n_read; i++)
185  memcpy(&rdBuf[i].sun_ref, &genBuf[i * 3 * 4], 3 * 4);
186 
187  rdSDS(sd_id, "scan_ell", recno - 1, 0, n_read, 6, (VOIDP) genBuf);
188  for (i = 0; i < n_read; i++)
189  memcpy(&rdBuf[i].scan_ell, &genBuf[i * 6 * 4], 6 * 4);
190 
191 
192  start[0] = recno - 1;
193  edges[0] = n_read;
194  start[1] = 0;
195  edges[1] = 3;
196  edges[2] = 3;
197  SDreaddata(SDselect(sd_id, SDnametoindex(sd_id, "sen_mat")),
198  start, NULL, edges, (VOIDP) genBuf);
199  for (i = 0; i < n_read; i++)
200  memcpy(&rdBuf[i].sen_mat, &genBuf[i * 9 * 4], 9 * 4);
201 
202 
203  offset = max_rec_in_rdbuf + 1;
204  max_rec_in_rdbuf += n_read;
205  }
206 
207  if ((crec - offset) >= 0) {
208  j = crec - offset;
209  gain8 = rdBuf[j].gain[7];
210  gain_ptr = rdBuf[j].gain;
211  l1a_ptr = &l1a_data[j * 8 * npix];
212 
213  l1b_rad(syear, sday, smsec, msec[recno - 1],
214  dtype, nsta, ninc, npix,
215  dark_mean, rdBuf[j].gain, rdBuf[j].tdi,
216  rdBuf[j].scan_temp, rdBuf[j].inst_temp, side[recno - 1],
217  &l1a_data[j * 8 * npix], l1b_buffer, cal_mod);
218  /*
219  calibrate_l1a(cal_path_tab,syear,sday,smsec,eday,msec[recno-1],
220  dtype, nsta, ninc, npix,
221  dark_mean, rdBuf[j].gain, rdBuf[j].tdi,
222  rdBuf[j].scan_temp, rdBuf[j].inst_temp, side[recno-1],
223  &l1a_data[j*8*npix], l1b_buffer, cal_mod);
224  */
225 
226  if (!recursive_flag) {
227  geonav_(rdBuf[j].orb_vec, rdBuf[j].sen_mat, rdBuf[j].scan_ell,
228  rdBuf[j].sun_ref, &nsta, &ninc, &npix,
229  ylat, xlon, solz, sola, senz, sena);
230 
231  }
232  } else {
233  j = (STBUFSIZ - 2) + (crec - offset);
234  gain8 = bkBuf[j].gain[7];
235  gain_ptr = bkBuf[j].gain;
236  l1a_ptr = &l1a_back[j * 8 * npix];
237 
238  if (!recursive_flag) {
239  geonav_(bkBuf[j].orb_vec, bkBuf[j].sen_mat, bkBuf[j].scan_ell,
240  bkBuf[j].sun_ref, &nsta, &ninc, &npix,
241  ylat, xlon, solz, sola, senz, sena);
242 
243  }
244  }
245 
246  if (first) {
247  memcpy(pcal_counts, cal_counts, sizeof (cal_counts));
248  memcpy(pcal_rads, cal_rads, sizeof (cal_rads));
249  first = 0;
250  }
251 
252  if (!recursive_flag) {
253  for (ipix = 0; ipix < npix; ipix++) {
254  hi_Lt[ipix] = FALSE;
255  /* HILT check limited to bands 7 & 8, BAF, 23 Jan 2002 */
256  /* Use dark_mean rather than dark_rest, BAF, 7 July 2003 */
257  for (idet = 6; (idet < 8)&&(hi_Lt[ipix] == FALSE); idet++) {
258  pixvalue = l1a_ptr[ipix + npix * idet];
259  /*
260  pixdark = dark_rest[8*(recno-1)+idet];
261  */
262  pixdark = dark_mean[idet];
263  kneevalue = pcal_counts[idet][gain_ptr[idet]][FIRST_KNEE];
264  hi_Lt[ipix] = ((pixvalue - pixdark) >= kneevalue);
265  }
266  }
267  }
268 
269 
270  scan_no = crec;
271  AS_pixels = stray_light;
272 
273  if (do_st == 0) {
274 
275  for (ipix = 0; ipix < npix; ipix++)
276  l2_flags_buffer[ipix] = 0;
277 
278  } else if (!recursive_flag) {
279 
280  do {
281  if (stray_light_scan_no != scan_no) {
282 
283  recursive_flag = 1;
284 
285  get_l1a_rec(sd_id, stray_light_scan_no, cal_mod,
286  l1a_dum, &st_l1b_data, &st_l2_flags);
287  }
288  } while (stray_light_corr(&initial, Ltyp_frac, Styp_frac,
289  nscan, npix, stray_light_scan_no++, dtype,
290  gain8, &pcal_rads[0][0][0], l1b_buffer, &sl_scan,
291  l2_flags_buffer, &AS_pixels) == NOTDONE);
292  recursive_flag = 0;
293  crec = scan_no;
294 
295  }
296 
297 
298 
299  for (ipix = 0; ipix < npix; ipix++) {
300  if (hi_Lt[ipix])
301  l2_flags_buffer[ipix] |= MASK_HIGHLT1;
302  }
303 
304  *l1b_data = l1b_buffer;
305  *l2_flags = l2_flags_buffer;
306 
307  return (0);
308 }
309 
310 int openl1_seawifs(filehandle *file) {
311 
312  /* */
313  /* input files */
314  /* */
315  char *cal_path = l1_input->calfile;
316 
317  /* */
318  /* get_l1a_open interface */
319  /* */
320  int32_t fileID;
321  int32_t status;
322  char buf[32];
323 
324 
325  /* */
326  /* set static global evaluation switch */
327  /* */
328  // evalmask = input->evalmask;
329 
330  /* open the file and get the file ID */
331  fileID = SDstart(file->name, DFACC_RDONLY);
332 
333  if (fileID < 0) {
334  fprintf(stderr,
335  "-E %s Line %d: Error opening %s for reading.\n",
336  __FILE__, __LINE__, file->name);
337  return (1);
338  }
339 
340  status = getHDFattr(fileID, "Start Year", "", (VOIDP) & syear);
341  status = getHDFattr(fileID, "Start Day", "", (VOIDP) & sday);
342  status = getHDFattr(fileID, "Start Millisec", "", (VOIDP) & smsec);
343  status = getHDFattr(fileID, "End Year", "", (VOIDP) & eyear);
344  status = getHDFattr(fileID, "End Day", "", (VOIDP) & eday);
345  status = getHDFattr(fileID, "End Millisec", "", (VOIDP) & emsec);
346  status = getHDFattr(fileID, "Number of Scan Lines", "", (VOIDP) & nscan);
347  status = getHDFattr(fileID, "Data Type", "", (VOIDP) & dtype);
348 
349  status = getHDFattr(fileID, "Pixels per Scan Line", "", (VOIDP) & npix);
350  status = getHDFattr(fileID, "LAC Pixel Start Number", "", (VOIDP) & nsta);
351  status = getHDFattr(fileID, "LAC Pixel Subsampling", "", (VOIDP) & ninc);
352 
353  status = getHDFattr(fileID, "Orbit Node Longitude", "", (VOIDP) & file->orbit_node_lon);
354  status = getHDFattr(fileID, "Orbit Number", "", (VOIDP) & file->orbit_number);
355  status = getHDFattr(fileID, "Node Crossing Time", "", (VOIDP) & buf);
356  file->node_crossing_time = zulu2unix(buf);
357 
358 
359  Ltyp_frac = l1_input->sl_frac;
360  stray_light = l1_input->sl_pixl;
361 
362 
363  if (stray_light == 0)
364  do_st = 0;
365  else {
366  do_st = 1;
367  if (stray_light < 0) {
368  if (strcmp(dtype, "GAC") == 0)
369  stray_light = 4;
370  else
371  stray_light = 3;
372  }
373  }
374 
375 
376  /* get the current calibration model solution */
377  if (cal_path == NULL) {
378  fprintf(stderr,
379  "-E %s Line %d: No calibration file specified.\n",
380  __FILE__, __LINE__);
381  exit(1);
382  }
383 
384  read_caltable(cal_path);
385 
386  /*
387  status = get_cal(cal_path, syear, sday, eday, smsec, npix, nsta, ninc,
388  dtype, tdi, &entry_year, &entry_day, &ref_year,
389  &ref_day, &ref_minute, fp_temps, scan_mod, t_const,
390  t_linear_1, t_exponential_1, t_linear_2, t_exponential_2,
391  cal_offs, inst_tcorr, inst_tref, fp_tcorr, fp_tref,
392  ms1_const, ms1_linear_1, ms1_exponential_1, ms1_linear_2,
393  ms1_exponential_2, ms2_const, ms2_linear_1,
394  ms2_exponential_1, ms2_linear_2, ms2_exponential_2,
395  counts, rads);
396  */
397 
398  if (status < 0) {
399  fprintf(stderr,
400  "-E- %s line %d: Error applying calibration table \"%s\".\n",
401  __FILE__, __LINE__, cal_path);
402  exit(status);
403  }
404 
405 
406  /* call cdata.f to initialize global FORTRAN common block data */
407  cdata_();
408 
409 
410  file->npix = npix;
411  file->nscan = nscan;
412  file->sensorID = SEAWIFS;
413  file->sd_id = fileID;
414  if (strcmp(dtype, "GAC") == 0)
415  strcpy(file->spatialResolution, "4.5 km");
416  else
417  strcpy(file->spatialResolution, "1.1 km");
418 
419  strcpy(cal_path_tab, cal_path);
420 
421  l1a_data = (int16_t *) calloc(npix * 8 * NREC_IN_BUF, sizeof (int16_t));
422  l1a_back = (int16_t *) calloc(npix * 8 * (STBUFSIZ - 2), sizeof (int16_t));
423  l1b_buffer = (float *) calloc(npix * 8, sizeof (float));
424 
425  msec = (int32_t *) calloc(nscan, sizeof (int32_t));
426  status = rdSDS(file->sd_id, "msec", 0, 0, 0, 0, (VOIDP) msec);
427  side = (int16_t *) calloc(nscan, sizeof (int16_t));
428  status = rdSDS(file->sd_id, "side", 0, 0, 0, 0, (VOIDP) side);
429 
430  dark_rest = (int16_t *) calloc(nscan * 8, sizeof (int16_t));
431  status = rdSDS(file->sd_id, "dark_rest", 0, 0, 0, 0, (VOIDP) dark_rest);
433  free(dark_rest);
434 
435  tilt = (float *) calloc(nscan, sizeof (float));
436  status = rdSDS(file->sd_id, "tilt", 0, 0, 0, 0, (VOIDP) tilt);
437 
438  spix = nsta - 1;
439  dpix = ninc;
440 
441  return (status);
442 }
443 
444 int readl1_seawifs(filehandle *file, int32_t recnum, l1str *l1rec) {
445 
446  /* */
447  /* get_l1a_rec interface */
448  /* */
449  static cal_mod_struc cal_mod; /* cal modification structure */
450  static int16_t *l2_flags; /* radiance quality flags for L2 */
451  static float *l1b_data;
452 
453  int32_t i;
454  int32_t status = 0;
455 
456  int32_t nwave = l1rec->l1file->nbands;
457  int32_t *bindx = (int32_t*) l1rec->l1file->bindx;
458 
459  /* */
460  /* local vars */
461  /* */
462  int32_t ipix; /* pixel number */
463  int32_t iw, ib;
464 
465  int16_t *l1a_dum = NULL;
466 
467  static int32_t prev_recnum = -1;
468 
469  static int16_t first = 1;
470  static int32_t ntilts;
471  static int16_t tilt_flags[20];
472  static int16_t tilt_ranges[2 * 20];
473 
474  int32_t nflag[8];
475 
476 
477  /* If reading out-of-sequence, force restart from beginning to get stlight */
478  /* baf, 05-oct-2001. */
479  if (recnum < prev_recnum) {
480  printf("Reading out-of-sequence %d %d\n", recnum, prev_recnum);
481  prev_recnum = -1;
482  }
483 
484 
485  /* Get tilt info */
486  /* ------------- */
487  if (first) {
488  status = rdSDS(file->sd_id, "ntilts", 0, 0, 0, 0, (VOIDP) & ntilts);
489  status = rdSDS(file->sd_id, "tilt_flags", 0, 0, 0, 0, (VOIDP) tilt_flags);
490  status = rdSDS(file->sd_id, "tilt_ranges", 0, 0, 0, 0, (VOIDP) tilt_ranges);
491  first = 0;
492  }
493 
494 
495  /* Check for bad or changing tilt */
496  /* ------------------------------ */
497  for (i = 0; i < ntilts; i++) {
498  if (tilt_ranges[2 * i] <= recnum + 1 && tilt_ranges[2 * i + 1] >= recnum)
499  break;
500  // if (tilt_flags[i] == 0 || /* nadir */
501  // tilt_flags[i] == 1 || /* fwd */
502  // tilt_flags[i] == 2 ) /* aft */
503  // bad_tilt = 0; /* tilt result is ok */
504  // else if (tilt_flags[i] == 3) /* tilt is changing */
505  // bad_tilt = 1;
506  // else /* tilt is unknown */
507  // bad_tilt = 2;
508  }
509 
510 
511  /* Get nav flag */
512  /* ------------ */
513  status = rdSDS(file->sd_id, "nflag", recnum, 0, 1, 8, (VOIDP) & nflag);
514 
515 
516  /* Get l1a data */
517  /* ------------ */
518  for (i = prev_recnum + 1; i <= recnum; i++)
519  status = get_l1a_rec(file->sd_id, i + 1, &cal_mod, l1a_dum,
520  &l1b_data, &l2_flags);
521 
522  /* */
523  /* Copy scan geolocation and view geometry */
524  /* */
525  memcpy(l1rec->lat, ylat, npix * sizeof (float));
526  memcpy(l1rec->lon, xlon, npix * sizeof (float));
527  memcpy(l1rec->solz, solz, npix * sizeof (float));
528  memcpy(l1rec->sola, sola, npix * sizeof (float));
529  memcpy(l1rec->senz, senz, npix * sizeof (float));
530  memcpy(l1rec->sena, sena, npix * sizeof (float));
531 
532  /* */
533  /* Copy L1B radiances, pixel interlaced by band. Add per-band */
534  /* view angles. */
535  /* */
536  for (ipix = 0; ipix < file->npix; ipix++) {
537  if (l1rec->sena[ipix] > 180) {
538  l1rec->sena[ipix] -= 360.0;
539  }
540  if (l1rec->sola[ipix] > 180) {
541  l1rec->sola[ipix] -= 360.0;
542  }
543  l1rec->pixnum[ipix] = spix + ipix*dpix;
544  for (iw = 0; iw < nwave; iw++) {
545  ib = bindx[iw];
546  l1rec->Lt [ipix * nwave + ib] = l1b_data[iw * npix + ipix];
547  }
548  l1rec->stlight[ipix] = ((l2_flags[ipix] & STRAYLIGHT) > 0);
549  l1rec->hilt [ipix] = ((l2_flags[ipix] & HILT) > 0);
550  l1rec->navwarn[ipix] = (nflag[7] & 1) | (nflag[0] & 1);
551  }
552 
553 
554  /* */
555  /* Set scan time in L1B output record */
556  /* */
557  double secs = (double) (msec[recnum] / 1.e3);
558  int16_t year = syear;
559  int16_t day = sday;
560 
561  if (msec[recnum] < smsec) { /* adjust for day rollover */
562  day += 1;
563  if (day > (365 + (year % 4 == 0))) {
564  year += 1;
565  day = 1;
566  }
567  }
568  l1rec->scantime = yds2unix(year, day, secs);
569 
570  l1rec->tilt = tilt[recnum];
571  l1rec->mside = side[recnum];
572 
573  prev_recnum = recnum;
574 
575  return (status);
576 }
577 
578 int readl1_lonlat_seawifs(filehandle *file, int32_t recnum, l1str *l1rec) {
579  int32_t start[3];
580  int32_t edges[3];
581 
582  inputBuffer rdBuf;
583 
584  if (recnum > nscan) return 0;
585 
586  rdSDS(file->sd_id, "orb_vec", recnum, 0, 1, 3, (VOIDP) rdBuf.orb_vec);
587  rdSDS(file->sd_id, "sun_ref", recnum, 0, 1, 3, (VOIDP) rdBuf.sun_ref);
588  rdSDS(file->sd_id, "scan_ell", recnum, 0, 1, 6, (VOIDP) rdBuf.scan_ell);
589 
590  start[0] = recnum;
591  edges[0] = 1;
592  start[1] = 0;
593  edges[1] = 3;
594  start[2] = 0;
595  edges[2] = 3;
596  SDreaddata(SDselect(file->sd_id, SDnametoindex(file->sd_id, "sen_mat")),
597  start, NULL, edges, (VOIDP) rdBuf.sen_mat);
598 
599  // read in solar zenith
600  // Read in lon, lat and solz
601  geonav_(rdBuf.orb_vec, rdBuf.sen_mat, rdBuf.scan_ell,
602  rdBuf.sun_ref, &nsta, &ninc, &npix,
603  l1rec->lat, l1rec->lon, l1rec->solz, l1rec->sola, l1rec->senz, l1rec->sena);
604 
605  // Read in scan time
606  double secs = (double) (msec[recnum] / 1.e3);
607  int16_t year = syear;
608  int16_t day = sday;
609 
610  if (msec[recnum] < smsec) { /* adjust for day rollover */
611  day += 1;
612  if (day > (365 + (year % 4 == 0))) {
613  year += 1;
614  day = 1;
615  }
616  }
617  l1rec->scantime = yds2unix(year, day, secs);
618 
619  return (0);
620 }
621 
622 int closel1_seawifs(filehandle *file) {
623  free(l1a_data);
624  free(l1a_back);
625  free(l1b_buffer);
626  free(msec);
627  free(side);
628  free(tilt);
629 
630  SDend(file->sd_id);
631 
632  return (0);
633 }
634 
635 
636 
const int bindx[3]
Definition: DbLutNetcdf.cpp:28
int16 eday
Definition: l1_czcs_hdf.c:17
int32_t get_l1a_rec(int32_t sd_id, int32_t recno, cal_mod_struc *cal_mod, int16_t *l1a_dum, float **l1b_data, int16_t **l2_flags)
Definition: l1_seawifs.c:78
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
int rdSDS(int32_t fileID, const char sdsname[], int32_t start1, int32_t start2, int32_t edges1, int32_t edges2, void *array_data)
int32_t day
int status
Definition: l1_czcs_hdf.c:32
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
int16_t fileID
#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
#define STRAYLIGHT
Definition: l2_flags.h:19
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[])
int32_t do_st
Definition: l1a_seawifs.c:116
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
int32 smsec
Definition: l1_czcs_hdf.c:16
#define FIRST_KNEE
Definition: l1_seawifs.c:21
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
int readl1_seawifs(filehandle *file, int32_t recnum, l1str *l1rec)
Definition: l1_seawifs.c:444
int32 nsta
Definition: l1_czcs_hdf.c:27
float Ltyp_frac
Definition: l1a_seawifs.c:101
read recnum
double zulu2unix(char *zulu)
Definition: zulu2unix.c:3
#define BANDS_DIMS_1A
Definition: level_1a_index.h:8
int openl1_seawifs(filehandle *file)
Definition: l1_seawifs.c:310
int32 ninc
Definition: l1_czcs_hdf.c:28
void cdata_()
#define LAC_PIXEL_NUM
Definition: l1_seawifs.c:16
l1_input_t * l1_input
Definition: l1_options.c:9
int getHDFattr(int32_t fileID, const char attrname[], const char sdsname[], void *data)
float sun_ref[3]
Definition: l1_seawifs.c:70
int16_t tdi[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:37
#define NREC_IN_BUF
Definition: l1_seawifs.c:18
short gain8
Definition: l1a.c:194
int closel1_seawifs(filehandle *file)
Definition: l1_seawifs.c:622
integer, parameter double
float dark_std[8]
Definition: l1a_seawifs.c:35
#define NOTDONE
Definition: l1_seawifs.c:20
#define HILT
Definition: l2_flags.h:15
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
#define STBUFSIZ
Definition: l1_seawifs.c:19
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])
int readl1_lonlat_seawifs(filehandle *file, int32_t recnum, l1str *l1rec)
Definition: l1_seawifs.c:578
#define GENBUFSIZ
Definition: l1_seawifs.c:23
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
l2prod offset
#define KNEES_DIMS_1A
#define MASK_HIGHLT1
Definition: l1_seawifs.c:22
#define SEAWIFS
Definition: sensorDefs.h:12
int16_t * tilt
Definition: l2bin.cpp:80
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