NASA Logo
Ocean Color Science Software

ocssw V2022
l1c_str.cpp
Go to the documentation of this file.
1 
2 // l1c_str.cpp
3 //
4 //
5 // Created by Martin Montes on 8/15/2022
6 #include "l1c_str.h"
7 #include <iostream>
8 #include <string>
9 #include "l1c_filehandle.h"
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <math.h>
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include <netcdf.h>
16 #include <nc4utils.h>
17 #include "libnav.h"
18 #include <timeutils.h>
19 #include <genutils.h>
20 #include <allocate4d.h>
21 #include <allocate3d.h>
22 #include <allocate2d.h>
23 #include <l1.h>
24 #include <netcdf>
25 
26 #include "l1c_latlongrid.h"
27 
28 // static float *Fobar; // reflectance to radiance conversion factors
29 // static int extract_pixel_start = 0;
30 
31 static short *tmpShort;
32 static int normalizedLt = 0;
33 static int use_rhot = 1;
34 // whole file stuff
35 /*
36 // ONLY FOR OCIS!!
37 static size_t expected_num_blue_bands = 120; // 60;before
38 static size_t expected_num_red_bands = 120; // 60;
39 static size_t expected_num_SWIR_bands = 9;
40 static size_t tot_num_bands = 239; // 249-10
41 */
42 
43 //OCI
44 static size_t expected_num_blue_bands = 121;
45 static size_t expected_num_red_bands = 165;
46 static size_t expected_num_SWIR_bands = 9;
47 static size_t tot_num_bands = 295;
48 
49 
50 // static size_t nviews;
51 // static size_t nbands;
52 static size_t num_scans, num_pixels;
53 static size_t num_blue_bands, num_red_bands, num_SWIR_bands, nband_view, npol_band_view;
54 
55 static int ncid_L1B;
56 
57 // scan line attributes
58 static double *scan_time; // seconds of day
59 static int32_t scan_time_year, scan_time_month, scan_time_day;
60 // static int32_t scan_time_hour,scan_time_min;
61 // static double scan_time_secs;
62 
63 // static uint_8 *scan_quality;
64 
65 // geolocation data
66 static int geolocationGrp, lambdaGrp, blueGrp;
67 static int lonId, latId, senzId, senaId, solzId, solaId, bwId, rwId, swId, iwId, pwId, IntId, IpolId, vpId;
68 static float latFillValue =BAD_FLT;
69 static float lonFillValue = BAD_FLT;
70 static short senzFillValue = BAD_FLT;
71 static float senzScale = 0.01;
72 static float senzOffset = 0.0;
73 static short senaFillValue = BAD_FLT;
74 static float senaScale = 0.01;
75 static float senaOffset = 0.0;
76 static short solzFillValue = BAD_FLT;
77 static float solzScale = 0.01;
78 static float solzOffset = 0.0;
79 static short solaFillValue = BAD_FLT;
80 static float solaScale = 0.01;
81 static float solaOffset = 0.0;
82 
83 static float I_FillValue = BAD_FLT;
84 static float Ipol_FillValue = BAD_FLT;
85 
86 // Observation data
87 static int observationGrp;
88 static int Lt_blueId, Lt_redId, Lt_SWIRId;
89 // static float **Lt_blue; //[num_blue_bands][num_pixels], This scan
90 // static float **Lt_red; //[num_red_bands][num_pixels], This scan
91 // static float **Lt_SWIR; //[num_SWIR_bands][num_pixels], This scan
92 
93 // static float ****Lt_all;
94 
95 static float Lt_blueFillValue = BAD_FLT;
96 static float Lt_redFillValue = BAD_FLT;
97 static float Lt_SWIRFillValue = BAD_FLT;
98 
99 // Navigation data
100 // static int navGrp;
101 // static int ovId,opId,attID;
102 // static float *orbv;//for each scan we have xpixels dim
103 // static float *orbp;
104 // static float *attang;
105 // static double *timeArr;
106 
107 static int status, dimid;
108 
109 using namespace std;
110 
111 namespace l1c {
112 
113 l1c_str::l1c_str()
114  : att_ang{-999.0, -999.0, -999.0}, orb_pos{-999.0, -999.0, -999.0}, orb_vel{-999.0, -999.0, -999.0} {
115  // global attributes
116  npix = -1;
117  iscan = 0;
118  nscan = -1;
119  nbands = -1;
120  // scan line attributes--
121  ev_mid_time = nullptr;
122  scan_quality_flag = nullptr;
123  spix = -1;
124  epix = -1;
125  dpix = -1;
126 
127  // structure--pointers to data arrays
128  Lt = nullptr; // dim depends between sensors--OCI is bands x pixels --
129  Lt_blue = nullptr; //[num_views][num_pol][num_blue_bands][num_pixels]
130  Lt_red = nullptr;
131  Lt_SWIR = nullptr;
132  Lt_tot = nullptr;
133  Fobar = nullptr;
134 
135  blue_lambdas = nullptr;
136  red_lambdas = nullptr;
137  SWIR_lambdas = nullptr;
138 
139  I = nullptr;
140  I_polsample = nullptr;
141  I_lambdas = nullptr;
142  pol_lambdas = nullptr;
143  viewport = nullptr;
144 
145  // sensor/sun geometry
146  senz = nullptr;
147  sena = nullptr;
148  solz = nullptr;
149  sola = nullptr;
150  delphi = nullptr;
151  scattang = nullptr;
152 
153  // geolocation--
154  timepix = nullptr;
155  senazpix = nullptr;
156  latpix = nullptr;
157  lonpix = nullptr;
158  latpix2 = nullptr;
159  lonpix2 = nullptr;
160  latpix3 = nullptr;
161  lonpix3 = nullptr;
162 
163  senazpix_3d = nullptr;
164  latpix_3d = nullptr;
165  lonpix_3d = nullptr;
166  latpix2_3d = nullptr; // lat2/lon are the sline +1
167  lonpix2_3d = nullptr;
168 
169  latnad = nullptr;
170  lonnad = nullptr;
171  lonershift = nullptr;
172  terr_height = nullptr;
173  cloud_height = nullptr;
174 
175  l1cfile = nullptr;
176  l1file = nullptr;
177  // ancill info?
178 }
179 
181 }
182 
183 int32_t l1c_str::openl1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file) {
185  const char *ptstr;
186  // Open the netcdf4 input file
187  str = l1cfile->l1b_name;
188  ptstr = str.c_str();
189  printf("Opening MISR L1B file\n");
190  cout << ptstr << endl;
191 
192  if (openl1(l1file) != 0) {
193  printf("-E- %s: Error opening for reading.\n", l1file->name);
194  exit(FATAL_ERROR);
195  }
196 
197  return 0;
198 }
199 
202  const char *ptstr;
203  // Open the netcdf4 input file
204  str = l1cfile->l1b_name;
205  ptstr = str.c_str();
206  printf("Opening SPEXone L1B file\n");
207  cout << str << endl;
208 
209  status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
210  if (status != NC_NOERR) {
211  fprintf(stderr, "-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
212  return (1);
213  }
214 
215  if (l1cfile->format == FT_SPEXONE) {
216  // number of views
217  status = nc_inq_dimid(ncid_L1B, "number_of_views", &dimid);
218  if (status != NC_NOERR) {
219  fprintf(stderr, "-E- Error reading number_of_views.\n");
220  exit(EXIT_FAILURE);
221  }
222  nc_inq_dimlen(ncid_L1B, dimid, &nviews);
223  l1cstr->nviews = nviews;
224 
225  // number of scans
226  status = nc_inq_dimid(ncid_L1B, "bins_along_track", &dimid);
227  if (status != NC_NOERR) {
228  fprintf(stderr, "-E- Error reading number_of_scans.\n");
229  exit(EXIT_FAILURE);
230  }
231  nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
232  l1cstr->nscan = num_scans;
233 
234  // num_pixels
235  status = nc_inq_dimid(ncid_L1B, "spatial_samples_per_image", &dimid);
236  if (status != NC_NOERR) {
237  fprintf(stderr, "-E- Error reading num_pixels.\n");
238  exit(EXIT_FAILURE);
239  }
240  nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
241  l1cstr->npix = num_pixels;
242 
243  // number of bands
244  status = nc_inq_dimid(ncid_L1B, "intensity_bands_per_view", &dimid);
245  if (status != NC_NOERR) {
246  fprintf(stderr, "-E- Error reading intensity_bands_per_view.\n");
247  exit(EXIT_FAILURE);
248  }
249  nc_inq_dimlen(ncid_L1B, dimid, &nband_view);
250 
251  status = nc_inq_dimid(ncid_L1B, "polarization_bands_per_view", &dimid);
252  if (status != NC_NOERR) {
253  fprintf(stderr, "-E- Error reading polarization_bands_per_view.\n");
254  exit(EXIT_FAILURE);
255  }
256  nc_inq_dimlen(ncid_L1B, dimid, &npol_band_view);
257  }
258 
259  printf("L1B Npix :%d Nlines:%d\n", (int)num_pixels, (int)num_scans);
260 
261  // allocate all of the data
262  l1cstr->senazpix = (float *)calloc(num_pixels, sizeof(float));
263  l1cstr->latpix = (float *)calloc(num_pixels, sizeof(float));
264  l1cstr->lonpix = (float *)calloc(num_pixels, sizeof(float));
265  l1cstr->latpix2 = (float *)calloc(num_pixels, sizeof(float));
266  l1cstr->lonpix2 = (float *)calloc(num_pixels, sizeof(float));
267 
268  l1cstr->I = allocate2d_float(num_pixels, nband_view);
269  l1cstr->I_polsample = allocate2d_float(num_pixels, npol_band_view);
270  l1cstr->I_lambdas = allocate2d_float(nviews, nband_view);
271  l1cstr->pol_lambdas = allocate2d_float(nviews, npol_band_view);
272  l1cstr->viewport = (uint8_t *)calloc(num_pixels, sizeof(uint8_t));
273 
274  // get start time
275  size_t att_len;
276  status = nc_inq_attlen(ncid_L1B, NC_GLOBAL, "time_coverage_start", &att_len);
277  check_err(status, __LINE__, __FILE__);
278  // allocate required space before retrieving values
279  char *time_str = (char *)malloc(att_len + 1); // + 1 for trailing null
280  // get attribute values
281  status = nc_get_att_text(ncid_L1B, NC_GLOBAL, "time_coverage_start", time_str);
282  check_err(status, __LINE__, __FILE__);
283  time_str[att_len] = '\0';
284 
285  double start_time = isodate2unix(time_str);
286  int16_t syear, smon, sday;
287  double secs;
288  unix2ymds(start_time, &syear, &smon, &sday, &secs);
289  scan_time_year = syear;
290  scan_time_month = smon;
291  scan_time_day = sday;
292 
293  // read the orbit#
294  int orbit_number;
295  status = nc_get_att_int(ncid_L1B, NC_GLOBAL, "orbit_number", &orbit_number);
296  check_err(status, __LINE__, __FILE__);
297 
298  // lambdas for each spectral range
299  status = nc_inq_grp_ncid(ncid_L1B, "SENSOR_VIEW_BANDS", &lambdaGrp);
300  check_err(status, __LINE__, __FILE__);
301  status = nc_inq_varid(lambdaGrp, "intensity_wavelengths", &iwId);
302  check_err(status, __LINE__, __FILE__);
303  status = nc_inq_varid(lambdaGrp, "polarization_wavelengths", &pwId);
304  check_err(status, __LINE__, __FILE__);
305  status = nc_inq_varid(lambdaGrp, "viewport_index", &vpId);
306  check_err(status, __LINE__, __FILE__);
307 
308  status = nc_get_var_float(lambdaGrp, iwId, l1cstr->I_lambdas[0]);
309  check_err(status, __LINE__, __FILE__);
310  status = nc_get_var_float(lambdaGrp, pwId, l1cstr->pol_lambdas[0]);
311  check_err(status, __LINE__, __FILE__);
312  status = nc_get_var_ubyte(lambdaGrp, vpId, l1cstr->viewport);
313  check_err(status, __LINE__, __FILE__);
314 
315  // Setup geofile pointers
316  status = nc_inq_grp_ncid(ncid_L1B, "GEOLOCATION_DATA", &geolocationGrp);
317  check_err(status, __LINE__, __FILE__);
318  status = nc_inq_varid(geolocationGrp, "longitude", &lonId);
319  check_err(status, __LINE__, __FILE__);
320 
321  status = nc_inq_var_fill(geolocationGrp, lonId, NULL, &lonFillValue);
322  check_err(status, __LINE__, __FILE__);
323  status = nc_inq_varid(geolocationGrp, "latitude", &latId);
324  check_err(status, __LINE__, __FILE__);
325  status = nc_inq_var_fill(geolocationGrp, latId, NULL, &latFillValue);
326  check_err(status, __LINE__, __FILE__);
327 
328  status = nc_inq_varid(geolocationGrp, "sensor_zenith", &senzId);
329  check_err(status, __LINE__, __FILE__);
330  status = nc_inq_var_fill(geolocationGrp, senzId, NULL, &senzFillValue);
331  check_err(status, __LINE__, __FILE__);
332  // status = nc_get_att_float(geolocationGrp, senzId, "scale_factor", &senzScale);
333  // check_err(status, __LINE__, __FILE__);
334  // status = nc_get_att_float(geolocationGrp, senzId, "add_offset", &senzOffset);
335  // check_err(status, __LINE__, __FILE__);
336 
337  status = nc_inq_varid(geolocationGrp, "sensor_azimuth", &senaId);
338  check_err(status, __LINE__, __FILE__);
339  status = nc_inq_var_fill(geolocationGrp, senaId, NULL, &senaFillValue);
340  check_err(status, __LINE__, __FILE__);
341  // status = nc_get_att_float(geolocationGrp, senaId, "scale_factor", &senaScale);
342  // check_err(status, __LINE__, __FILE__);
343  // status = nc_get_att_float(geolocationGrp, senaId, "add_offset", &senaOffset);
344  // check_err(status, __LINE__, __FILE__);
345 
346  status = nc_inq_varid(geolocationGrp, "solar_zenith", &solzId);
347  check_err(status, __LINE__, __FILE__);
348  status = nc_inq_var_fill(geolocationGrp, solzId, NULL, &solzFillValue);
349  check_err(status, __LINE__, __FILE__);
350  status = nc_get_att_float(geolocationGrp, solzId, "scale_factor", &solzScale);
351  // check_err(status, __LINE__, __FILE__);
352  // status = nc_get_att_float(geolocationGrp, solzId, "add_offset", &solzOffset);
353  // check_err(status, __LINE__, __FILE__);
354 
355  status = nc_inq_varid(geolocationGrp, "solar_azimuth", &solaId);
356  check_err(status, __LINE__, __FILE__);
357  status = nc_inq_var_fill(geolocationGrp, solaId, NULL, &solaFillValue);
358  check_err(status, __LINE__, __FILE__);
359  status = nc_get_att_float(geolocationGrp, solaId, "scale_factor", &solaScale);
360  // check_err(status, __LINE__, __FILE__);
361  // status = nc_get_att_float(geolocationGrp, solaId, "add_offset", &solaOffset);
362  // check_err(status, __LINE__, __FILE__);
363 
364  // get IDs for the observations
365  status = nc_inq_grp_ncid(ncid_L1B, "OBSERVATION_DATA", &observationGrp);
366  check_err(status, __LINE__, __FILE__);
367 
368  // Get varids for each of the Lt_*
369  status = nc_inq_varid(observationGrp, "I", &IntId);
370  check_err(status, __LINE__, __FILE__);
371  status = nc_inq_var_fill(observationGrp, IntId, NULL, &I_FillValue);
372  check_err(status, __LINE__, __FILE__);
373 
374  status = nc_inq_varid(observationGrp, "I_polsample", &IpolId);
375  check_err(status, __LINE__, __FILE__);
376  status = nc_inq_var_fill(observationGrp, IpolId, NULL, &Ipol_FillValue);
377  check_err(status, __LINE__, __FILE__);
378 
379  // l1cfile assig
380  l1cfile->sd_id = ncid_L1B;
381  l1cfile->nband_view = nband_view;
382  l1cfile->npol_band_view = npol_band_view;
384 
385  cout << "nband_view =" << nband_view << endl;
386  cout << "npol_band_view = " << npol_band_view << endl;
387 
388  l1cfile->npix = num_pixels;
389  l1cfile->nadpix = (num_pixels - 1) / 2; // nadir pixel index
390  l1cfile->nscan = num_scans;
391  l1cfile->terrain_corrected = 1; // presumed.
392  l1cfile->orbit_number = orbit_number;
393 
394  cout << "n_views..." << l1cfile->n_views << "intensity bands.per view..." << nband_view
395  << "polarization bands.per view." << npol_band_view << endl;
396 
397  return 0;
398 }
399 
400 int32_t l1c_str::openl1b_oci_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile) {
402  const char *ptstr;
403 
404  // Open the netcdf4 input file
405  str = l1cfile->l1b_name;
406  ptstr = str.c_str();
407  printf("Opening OCI L1B file\n");
408  cout << str << endl;
409 
410  status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
411  if (status != NC_NOERR) {
412  fprintf(stderr, "-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
413  return (1);
414  }
415 
416  // num_scans
417  if (l1cfile->format == FT_OCIL1B) {
418  status = nc_inq_dimid(ncid_L1B, "number_of_scans", &dimid);
419  if (status != NC_NOERR) {
420  fprintf(stderr, "-E- Error reading number_of_scans.\n");
421  exit(EXIT_FAILURE);
422  }
423  cout << "reading OCI" << endl;
424  nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
425  l1cstr->nscan = num_scans;
426 
427  // num_pixels
428  status = nc_inq_dimid(ncid_L1B, "ccd_pixels", &dimid);
429  if (status != NC_NOERR) {
430  fprintf(stderr, "-E- Error reading num_pixels.\n");
431  exit(EXIT_FAILURE);
432  }
433  nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
434  l1cstr->npix = num_pixels;
435 
436  // num_blue_bands
437  status = nc_inq_dimid(ncid_L1B, "blue_bands", &dimid);
438  if (status != NC_NOERR) {
439  fprintf(stderr, "-E- Error reading num_blue_bands.\n");
440  exit(EXIT_FAILURE);
441  }
442  nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
443  if (num_blue_bands < expected_num_blue_bands) {
444  fprintf(stderr, "-E- blue bands in file are less than expected!, expecting %d, found %d.\n",
445  (int)expected_num_blue_bands, (int)num_blue_bands);
446 // exit(EXIT_FAILURE);
447  }
448 
449  // num_red_bands
450  status = nc_inq_dimid(ncid_L1B, "red_bands", &dimid);
451  if (status != NC_NOERR) {
452  fprintf(stderr, "-E- Error reading num_red_bands.\n");
453  exit(EXIT_FAILURE);
454  }
455  nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
456  if (num_red_bands < expected_num_red_bands) {
457  fprintf(stderr, "-E- red bands in file are less than expected!, expecting %d, found %d.\n",
458  (int)expected_num_red_bands, (int)num_red_bands);
459 // exit(EXIT_FAILURE);
460  }
461 
462  // num_SWIR_bands
463  status = nc_inq_dimid(ncid_L1B, "SWIR_bands", &dimid);
464  if (status != NC_NOERR) {
465  fprintf(stderr, "-E- Error reading num_SWIR_bands.\n");
466  exit(EXIT_FAILURE);
467  }
468  nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
469  if (num_SWIR_bands < expected_num_SWIR_bands) {
470  fprintf(stderr, "-E- SWIR bands in file are less than expected!, expecting %d, found %d.\n",
471  (int)expected_num_SWIR_bands, (int)num_SWIR_bands);
472 // exit(EXIT_FAILURE);
473  }
474  }
475 
476  printf("L1B Npix :%d Nlines:%d\n", (int)num_pixels, (int)num_scans);
477 
478  // allocate all of the data
479  // line by line!!!
480  tmpShort = (short *)calloc(num_pixels, sizeof(short));
481  l1cstr->timepix = (double *)calloc(num_scans, sizeof(double));
482  l1cstr->tilt = (float *)calloc(num_scans, sizeof(float));
483  l1cstr->latpix = (float *)calloc(num_pixels, sizeof(float));
484  l1cstr->lonpix = (float *)calloc(num_pixels, sizeof(float));
485  l1cstr->latpix2 = (float *)calloc(num_pixels, sizeof(float));
486  l1cstr->lonpix2 = (float *)calloc(num_pixels, sizeof(float));
487  l1cstr->latpix3 = (float *)calloc(num_pixels, sizeof(float));
488  l1cstr->lonpix3 = (float *)calloc(num_pixels, sizeof(float));
489 
490  l1cstr->Lt_blue = allocate2d_float(num_blue_bands, num_pixels);
491  l1cstr->Lt_red = allocate2d_float(num_red_bands, num_pixels);
492  l1cstr->Lt_SWIR = allocate2d_float(num_SWIR_bands, num_pixels);
493  l1cstr->Lt_tot = (float *)calloc(num_pixels * tot_num_bands, sizeof(float));
494 
495  l1cstr->Fobar = (float *)calloc(tot_num_bands, sizeof(float));
496  l1cstr->solz = (float *)calloc(num_pixels, sizeof(float));
497  l1cstr->senz = (float *)calloc(num_pixels, sizeof(float));
498 
499  l1cstr->blue_lambdas = (float *)calloc(num_blue_bands, sizeof(float));
500  l1cstr->red_lambdas = (float *)calloc(num_red_bands, sizeof(float));
501  l1cstr->SWIR_lambdas = (float *)calloc(num_SWIR_bands, sizeof(float));
502 
503  scan_time = (double *)malloc(num_scans * sizeof(double));
504 
505  // Get group id from L1B file for GROUP scan_line_attributes.
506  int groupid;
507  int varid;
508 
509  if ((nc_inq_grp_ncid(ncid_L1B, "navigation_data", &groupid)) == NC_NOERR) {
510  } else {
511  fprintf(stderr, "-E- Error finding navigation_data.\n");
512  exit(EXIT_FAILURE);
513  }
514  status = nc_inq_varid(groupid, "tilt", &varid);
515  float tiltFillValue = BAD_FLT;
516  if (status == NC_NOERR) {
517  status = nc_inq_var_fill(groupid, varid, NULL, &tiltFillValue);
518  check_err(status, __LINE__, __FILE__);
519  status = nc_get_var_float(groupid, varid, l1cstr->tilt);
520  check_err(status, __LINE__, __FILE__);
521  }
522 
523  if ((nc_inq_grp_ncid(ncid_L1B, "scan_line_attributes", &groupid)) == NC_NOERR) {
524  } else {
525  fprintf(stderr, "-E- Error finding scan_line_attributes.\n");
526  exit(EXIT_FAILURE);
527  }
528 
529  double scan_timeFillValue = BAD_FLT;
530  status = nc_inq_varid(groupid, "time", &varid);
531  if (status == NC_NOERR) {
532  status = nc_inq_var_fill(groupid, varid, NULL, &scan_timeFillValue);
533  check_err(status, __LINE__, __FILE__);
534  status = nc_get_var_double(groupid, varid, l1cstr->timepix);
535  check_err(status, __LINE__, __FILE__);
536  /* status = nc_get_att_int(groupid, varid, "year", &scan_time_year);
537  check_err(status, __LINE__, __FILE__);
538  status = nc_get_att_int(groupid, varid, "month", &scan_time_month);
539  check_err(status, __LINE__, __FILE__);
540  status = nc_get_att_int(groupid, varid, "day", &scan_time_day);
541  check_err(status, __LINE__, __FILE__);
542  */
543  } else {
544  status = nc_inq_varid(groupid, "ev_mid_time", &varid);
545  check_err(status, __LINE__, __FILE__);
546  status = nc_inq_var_fill(groupid, varid, NULL, &scan_timeFillValue);
547  check_err(status, __LINE__, __FILE__);
548  status = nc_get_var_double(groupid, varid, scan_time);
549  check_err(status, __LINE__, __FILE__);
550 
551  // get start time
552  size_t att_len;
553  status = nc_inq_attlen(ncid_L1B, NC_GLOBAL, "time_coverage_start", &att_len);
554  check_err(status, __LINE__, __FILE__);
555 
556  // allocate required space before retrieving values
557  char *time_str = (char *)malloc(att_len + 1); // + 1 for trailing null
558 
559  // get attribute values
560  status = nc_get_att_text(ncid_L1B, NC_GLOBAL, "time_coverage_start", time_str);
561  check_err(status, __LINE__, __FILE__);
562  time_str[att_len] = '\0';
563 
564  double start_time = isodate2unix(time_str);
565  int16_t syear, smon, sday;
566  double secs;
567  unix2ymds(start_time, &syear, &smon, &sday, &secs);
568  scan_time_year = syear;
569  scan_time_month = smon;
570  scan_time_day = sday;
571  }
572 
573  for (size_t i = 0; i < num_scans; i++) {
574  if (scan_time[i] == scan_timeFillValue)
575  scan_time[i] = BAD_FLT;
576  }
577 
578  // read the orbit#
579  /* int orbit_number;
580  status = nc_get_att_int(ncid_L1B, NC_GLOBAL, "orbit_number", &orbit_number);
581  check_err(status, __LINE__, __FILE__);
582  */
583  // lambdas for each spectral range
584  status = nc_inq_grp_ncid(ncid_L1B, "sensor_band_parameters", &lambdaGrp);
585  check_err(status, __LINE__, __FILE__);
586  status = nc_inq_varid(lambdaGrp, "blue_wavelength", &bwId);
587  check_err(status, __LINE__, __FILE__);
588  status = nc_inq_varid(lambdaGrp, "red_wavelength", &rwId);
589  check_err(status, __LINE__, __FILE__);
590  status = nc_inq_varid(lambdaGrp, "SWIR_wavelength", &swId);
591  check_err(status, __LINE__, __FILE__);
592  status = nc_get_var_float(lambdaGrp, bwId, l1cstr->blue_lambdas);
593  check_err(status, __LINE__, __FILE__);
594  status = nc_get_var_float(lambdaGrp, rwId, l1cstr->red_lambdas);
595  check_err(status, __LINE__, __FILE__);
596  status = nc_get_var_float(lambdaGrp, swId, l1cstr->SWIR_lambdas);
597  check_err(status, __LINE__, __FILE__);
598 
599  // Setup geofile pointers
600  status = nc_inq_grp_ncid(ncid_L1B, "geolocation_data", &geolocationGrp);
601  check_err(status, __LINE__, __FILE__);
602  status = nc_inq_varid(geolocationGrp, "longitude", &lonId);
603  check_err(status, __LINE__, __FILE__);
604 
605  status = nc_inq_var_fill(geolocationGrp, lonId, NULL, &lonFillValue);
606  check_err(status, __LINE__, __FILE__);
607  status = nc_inq_varid(geolocationGrp, "latitude", &latId);
608  check_err(status, __LINE__, __FILE__);
609  status = nc_inq_var_fill(geolocationGrp, latId, NULL, &latFillValue);
610  check_err(status, __LINE__, __FILE__);
611 
612  status = nc_inq_varid(geolocationGrp, "sensor_zenith", &senzId);
613  check_err(status, __LINE__, __FILE__);
614  status = nc_inq_var_fill(geolocationGrp, senzId, NULL, &senzFillValue);
615  check_err(status, __LINE__, __FILE__);
616  /* status = nc_get_att_float(geolocationGrp, senzId, "scale_factor", &senzScale);
617  check_err(status, __LINE__, __FILE__);
618  status = nc_get_att_float(geolocationGrp, senzId, "add_offset", &senzOffset);
619  check_err(status, __LINE__, __FILE__);
620  */
621  status = nc_inq_varid(geolocationGrp, "sensor_azimuth", &senaId);
622  check_err(status, __LINE__, __FILE__);
623  status = nc_inq_var_fill(geolocationGrp, senaId, NULL, &senaFillValue);
624  check_err(status, __LINE__, __FILE__);
625  /* status = nc_get_att_float(geolocationGrp, senaId, "scale_factor", &senaScale);
626  check_err(status, __LINE__, __FILE__);
627  status = nc_get_att_float(geolocationGrp, senaId, "add_offset", &senaOffset);
628  check_err(status, __LINE__, __FILE__);
629  */
630  status = nc_inq_varid(geolocationGrp, "solar_zenith", &solzId);
631  check_err(status, __LINE__, __FILE__);
632  status = nc_inq_var_fill(geolocationGrp, solzId, NULL, &solzFillValue);
633  check_err(status, __LINE__, __FILE__);
634  /* status = nc_get_att_float(geolocationGrp, solzId, "scale_factor", &solzScale);
635  check_err(status, __LINE__, __FILE__);
636  status = nc_get_att_float(geolocationGrp, solzId, "add_offset", &solzOffset);
637  check_err(status, __LINE__, __FILE__);
638  */
639  status = nc_inq_varid(geolocationGrp, "solar_azimuth", &solaId);
640  check_err(status, __LINE__, __FILE__);
641  status = nc_inq_var_fill(geolocationGrp, solaId, NULL, &solaFillValue);
642  check_err(status, __LINE__, __FILE__);
643  /* status = nc_get_att_float(geolocationGrp, solaId, "scale_factor", &solaScale);
644  check_err(status, __LINE__, __FILE__);
645  status = nc_get_att_float(geolocationGrp, solaId, "add_offset", &solaOffset);
646  check_err(status, __LINE__, __FILE__);
647  */
648 
649  // get IDs for the observations
650  status = nc_inq_grp_ncid(ncid_L1B, "observation_data", &observationGrp);
651  check_err(status, __LINE__, __FILE__);
652 
653  status = nc_inq_varid(observationGrp, "Lt_blue", &Lt_blueId);
654 
655  use_rhot = 0;
656  // Get varids for each of the Lt_*
657  if (status == NC_NOERR) {
658  status = nc_inq_var_fill(observationGrp, Lt_blueId, NULL, &Lt_blueFillValue);
659  check_err(status, __LINE__, __FILE__);
660 
661  status = nc_inq_varid(observationGrp, "Lt_red", &Lt_redId);
662  check_err(status, __LINE__, __FILE__);
663  status = nc_inq_var_fill(observationGrp, Lt_redId, NULL, &Lt_redFillValue);
664  check_err(status, __LINE__, __FILE__);
665 
666  status = nc_inq_varid(observationGrp, "Lt_SWIR", &Lt_SWIRId);
667  check_err(status, __LINE__, __FILE__);
668  status = nc_inq_var_fill(observationGrp, Lt_SWIRId, NULL, &Lt_SWIRFillValue);
669  check_err(status, __LINE__, __FILE__);
670  } else {
671  status = nc_inq_varid(observationGrp, "rhot_blue", &Lt_blueId);
672  check_err(status, __LINE__, __FILE__);
673  status = nc_inq_var_fill(observationGrp, Lt_blueId, NULL, &Lt_blueFillValue);
674  check_err(status, __LINE__, __FILE__);
675  status = nc_inq_varid(observationGrp, "rhot_red", &Lt_redId);
676  check_err(status, __LINE__, __FILE__);
677  status = nc_inq_var_fill(observationGrp, Lt_redId, NULL, &Lt_redFillValue);
678  check_err(status, __LINE__, __FILE__);
679 
680  status = nc_inq_varid(observationGrp, "rhot_SWIR", &Lt_SWIRId);
681  check_err(status, __LINE__, __FILE__);
682  status = nc_inq_var_fill(observationGrp, Lt_SWIRId, NULL, &Lt_SWIRFillValue);
683  check_err(status, __LINE__, __FILE__);
684  use_rhot = 1;
685  }
686 
687  l1cstr->nbands = tot_num_bands;
688  // l1cfile assig
689  l1cfile->sd_id = ncid_L1B;
690  l1cfile->nband_blue = num_blue_bands;
691  l1cfile->nband_red = num_red_bands;
692  l1cfile->nband_swir = num_SWIR_bands;
693  l1cfile->nbands = num_blue_bands + num_red_bands + num_SWIR_bands;
694  nviews = 2;
696 
697  cout << "file->nbands_b =" << l1cfile->nband_blue << endl;
698  cout << "file->nbands_r = " << l1cfile->nband_red << endl;
699  cout << "file->nbands_swir = " << l1cfile->nband_swir << endl;
700  /*
701  if(l1cfile->format==FT_OCIL1B){
702  expected_num_blue_bands=120;//actually 121,165,9
703  expected_num_red_bands=168;
704  expected_num_SWIR_bands=9;
705  tot_num_bands=expected_num_blue_bands+expected_num_red_bands+expected_num_SWIR_bands;
706  }
707  */
708  // cout<<"expected blue.."<<expected_num_blue_bands<<"expected
709  // red.."<<expected_num_red_bands<<"expected SWIR.."<<expected_num_SWIR_bands<<"tot
710  // bands.."<<tot_num_bands<<endl;
711 
712  l1cfile->npix = num_pixels;
713  l1cfile->nadpix = (num_pixels - 1) / 2; // nadir pixel index
714  l1cfile->nscan = num_scans;
715  l1cfile->ndets = 1;
716  l1cfile->terrain_corrected = 1; // presumed.
717  // l1cfile->orbit_number = orbit_number;
718 
719  return 0;
720 }
721 
724  const char *ptstr;
725 
726  // Open the netcdf4 input file
727  str = l1cfile->l1b_name;
728  ptstr = str.c_str();
729  printf("Opening OCIS L1B file\n");
730  cout << str << endl;
731 
732  status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
733  if (status != NC_NOERR) {
734  fprintf(stderr, "-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
735  return (1);
736  }
737 
738  // num_scans
739  if (l1cfile->format == FT_OCIS) {
740  status = nc_inq_dimid(ncid_L1B, "number_of_scans", &dimid);
741  if (status != NC_NOERR) {
742  fprintf(stderr, "-E- Error reading number_of_scans.\n");
743  exit(EXIT_FAILURE);
744  }
745  cout << "reading OCIS" << endl;
746  nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
747  l1cstr->nscan = num_scans;
748 
749  // num_pixels
750  status = nc_inq_dimid(ncid_L1B, "ccd_pixels", &dimid);
751  if (status != NC_NOERR) {
752  fprintf(stderr, "-E- Error reading num_pixels.\n");
753  exit(EXIT_FAILURE);
754  }
755  nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
756  l1cstr->npix = num_pixels;
757 
758  // num_blue_bands
759  status = nc_inq_dimid(ncid_L1B, "blue_bands", &dimid);
760  if (status != NC_NOERR) {
761  fprintf(stderr, "-E- Error reading num_blue_bands.\n");
762  exit(EXIT_FAILURE);
763  }
764  nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
765  if (num_blue_bands < expected_num_blue_bands) {
766  fprintf(stderr, "-E- blue bands in file is less than expected!, expecting %d, found %d.\n",
767  (int)expected_num_blue_bands, (int)num_blue_bands);
768  // exit(EXIT_FAILURE);
769  }
770 
771  // num_red_bands
772  status = nc_inq_dimid(ncid_L1B, "red_bands", &dimid);
773  if (status != NC_NOERR) {
774  fprintf(stderr, "-E- Error reading num_red_bands.\n");
775  exit(EXIT_FAILURE);
776  }
777  nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
778  if (num_red_bands < expected_num_red_bands) {
779  fprintf(stderr, "-E- red bands in file is less than expected!, expecting %d, found %d.\n",
780  (int)expected_num_red_bands, (int)num_red_bands);
781  // exit(EXIT_FAILURE);
782  }
783 
784  // num_SWIR_bands
785  status = nc_inq_dimid(ncid_L1B, "SWIR_bands", &dimid);
786  if (status != NC_NOERR) {
787  fprintf(stderr, "-E- Error reading num_SWIR_bands.\n");
788  exit(EXIT_FAILURE);
789  }
790  nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
791  if (num_SWIR_bands < expected_num_SWIR_bands) {
792  fprintf(stderr, "-E- SWIR bands in file is less than expected!, expecting %d, found %d.\n",
793  (int)expected_num_SWIR_bands, (int)num_SWIR_bands);
794 // exit(EXIT_FAILURE);
795  }
796  }
797 
798  printf("L1B Npix :%d Nlines:%d\n", (int)num_pixels, (int)num_scans);
799 
800  // allocate all of the data
801  // line by line!!!
802  tmpShort = (short *)calloc(num_pixels, sizeof(short));
803  l1cstr->timepix = (double *)calloc(num_scans, sizeof(double));
804  l1cstr->tilt = (float *)calloc(num_scans, sizeof(float));
805  l1cstr->latpix = (float *)calloc(num_pixels, sizeof(float));
806  l1cstr->lonpix = (float *)calloc(num_pixels, sizeof(float));
807  l1cstr->latpix2 = (float *)calloc(num_pixels, sizeof(float));
808  l1cstr->lonpix2 = (float *)calloc(num_pixels, sizeof(float));
809  l1cstr->latpix3 = (float *)calloc(num_pixels, sizeof(float));
810  l1cstr->lonpix3 = (float *)calloc(num_pixels, sizeof(float));
811 
812  l1cstr->Lt_blue = allocate2d_float(num_blue_bands, num_pixels);
813  l1cstr->Lt_red = allocate2d_float(num_red_bands, num_pixels);
814  l1cstr->Lt_SWIR = allocate2d_float(num_SWIR_bands, num_pixels);
815  l1cstr->Lt_tot = (float *)calloc(num_pixels * tot_num_bands, sizeof(float));
816 
817  l1cstr->Fobar = (float *)calloc(tot_num_bands, sizeof(float));
818  l1cstr->solz = (float *)calloc(num_pixels, sizeof(float));
819  l1cstr->senz = (float *)calloc(num_pixels, sizeof(float));
820 
821  l1cstr->blue_lambdas = (float *)calloc(num_blue_bands, sizeof(float));
822  l1cstr->red_lambdas = (float *)calloc(num_red_bands, sizeof(float));
823  l1cstr->SWIR_lambdas = (float *)calloc(num_SWIR_bands, sizeof(float));
824 
825  scan_time = (double *)malloc(num_scans * sizeof(double));
826 
827  // Get group id from L1B file for GROUP scan_line_attributes.
828  int groupid;
829  int varid;
830 
831  if ((nc_inq_grp_ncid(ncid_L1B, "navigation_data", &groupid)) == NC_NOERR) {
832  } else {
833  fprintf(stderr, "-E- Error finding navigation_data.\n");
834  exit(EXIT_FAILURE);
835  }
836  status = nc_inq_varid(groupid, "tilt_angle", &varid);
837  float tiltFillValue = BAD_FLT;
838  if (status == NC_NOERR) {
839  status = nc_inq_var_fill(groupid, varid, NULL, &tiltFillValue);
840  check_err(status, __LINE__, __FILE__);
841  status = nc_get_var_float(groupid, varid, l1cstr->tilt);
842  check_err(status, __LINE__, __FILE__);
843  }
844 
845  if ((nc_inq_grp_ncid(ncid_L1B, "scan_line_attributes", &groupid)) == NC_NOERR) {
846  } else {
847  fprintf(stderr, "-E- Error finding scan_line_attributes.\n");
848  exit(EXIT_FAILURE);
849  }
850 
851  double scan_timeFillValue = BAD_FLT;
852  status = nc_inq_varid(groupid, "time", &varid);
853  if (status == NC_NOERR) {
854  status = nc_inq_var_fill(groupid, varid, NULL, &scan_timeFillValue);
855  check_err(status, __LINE__, __FILE__);
856  status = nc_get_var_double(groupid, varid, l1cstr->timepix);
857  check_err(status, __LINE__, __FILE__);
858  status = nc_get_att_int(groupid, varid, "year", &scan_time_year);
859  check_err(status, __LINE__, __FILE__);
860  status = nc_get_att_int(groupid, varid, "month", &scan_time_month);
861  check_err(status, __LINE__, __FILE__);
862  status = nc_get_att_int(groupid, varid, "day", &scan_time_day);
863  check_err(status, __LINE__, __FILE__);
864 
865  } else {
866  status = nc_inq_varid(groupid, "ev_mid_time", &varid);
867  check_err(status, __LINE__, __FILE__);
868  status = nc_inq_var_fill(groupid, varid, NULL, &scan_timeFillValue);
869  check_err(status, __LINE__, __FILE__);
870  status = nc_get_var_double(groupid, varid, scan_time);
871  check_err(status, __LINE__, __FILE__);
872 
873  // get start time
874  size_t att_len;
875  status = nc_inq_attlen(ncid_L1B, NC_GLOBAL, "time_coverage_start", &att_len);
876  check_err(status, __LINE__, __FILE__);
877 
878  // allocate required space before retrieving values
879  char *time_str = (char *)malloc(att_len + 1); // + 1 for trailing null
880 
881  // get attribute values
882  status = nc_get_att_text(ncid_L1B, NC_GLOBAL, "time_coverage_start", time_str);
883  check_err(status, __LINE__, __FILE__);
884  time_str[att_len] = '\0';
885 
886  double start_time = isodate2unix(time_str);
887  int16_t syear, smon, sday;
888  double secs;
889  unix2ymds(start_time, &syear, &smon, &sday, &secs);
890  scan_time_year = syear;
891  scan_time_month = smon;
892  scan_time_day = sday;
893  }
894 
895  for (size_t i = 0; i < num_scans; i++) {
896  if (scan_time[i] == scan_timeFillValue)
897  scan_time[i] = BAD_FLT;
898  }
899 
900  // read the orbit#
901  int orbit_number;
902  status = nc_get_att_int(ncid_L1B, NC_GLOBAL, "orbit_number", &orbit_number);
903  check_err(status, __LINE__, __FILE__);
904 
905  // lambdas for each spectral range
906  status = nc_inq_grp_ncid(ncid_L1B, "sensor_band_parameters", &lambdaGrp);
907  check_err(status, __LINE__, __FILE__);
908  status = nc_inq_varid(lambdaGrp, "blue_wavelength", &bwId);
909  check_err(status, __LINE__, __FILE__);
910  status = nc_inq_varid(lambdaGrp, "red_wavelength", &rwId);
911  check_err(status, __LINE__, __FILE__);
912  status = nc_inq_varid(lambdaGrp, "SWIR_wavelength", &swId);
913  check_err(status, __LINE__, __FILE__);
914  status = nc_get_var_float(lambdaGrp, bwId, l1cstr->blue_lambdas);
915  check_err(status, __LINE__, __FILE__);
916  status = nc_get_var_float(lambdaGrp, rwId, l1cstr->red_lambdas);
917  check_err(status, __LINE__, __FILE__);
918  status = nc_get_var_float(lambdaGrp, swId, l1cstr->SWIR_lambdas);
919  check_err(status, __LINE__, __FILE__);
920 
921  // Setup geofile pointers
922  status = nc_inq_grp_ncid(ncid_L1B, "geolocation_data", &geolocationGrp);
923  check_err(status, __LINE__, __FILE__);
924  status = nc_inq_varid(geolocationGrp, "longitude", &lonId);
925  check_err(status, __LINE__, __FILE__);
926 
927  status = nc_inq_var_fill(geolocationGrp, lonId, NULL, &lonFillValue);
928  check_err(status, __LINE__, __FILE__);
929  status = nc_inq_varid(geolocationGrp, "latitude", &latId);
930  check_err(status, __LINE__, __FILE__);
931  status = nc_inq_var_fill(geolocationGrp, latId, NULL, &latFillValue);
932  check_err(status, __LINE__, __FILE__);
933 
934  status = nc_inq_varid(geolocationGrp, "sensor_zenith", &senzId);
935  check_err(status, __LINE__, __FILE__);
936  status = nc_inq_var_fill(geolocationGrp, senzId, NULL, &senzFillValue);
937  check_err(status, __LINE__, __FILE__);
938  status = nc_get_att_float(geolocationGrp, senzId, "scale_factor", &senzScale);
939  check_err(status, __LINE__, __FILE__);
940  status = nc_get_att_float(geolocationGrp, senzId, "add_offset", &senzOffset);
941  check_err(status, __LINE__, __FILE__);
942 
943  status = nc_inq_varid(geolocationGrp, "sensor_azimuth", &senaId);
944  check_err(status, __LINE__, __FILE__);
945  status = nc_inq_var_fill(geolocationGrp, senaId, NULL, &senaFillValue);
946  check_err(status, __LINE__, __FILE__);
947  status = nc_get_att_float(geolocationGrp, senaId, "scale_factor", &senaScale);
948  check_err(status, __LINE__, __FILE__);
949  status = nc_get_att_float(geolocationGrp, senaId, "add_offset", &senaOffset);
950  check_err(status, __LINE__, __FILE__);
951 
952  status = nc_inq_varid(geolocationGrp, "solar_zenith", &solzId);
953  check_err(status, __LINE__, __FILE__);
954  status = nc_inq_var_fill(geolocationGrp, solzId, NULL, &solzFillValue);
955  check_err(status, __LINE__, __FILE__);
956  status = nc_get_att_float(geolocationGrp, solzId, "scale_factor", &solzScale);
957  check_err(status, __LINE__, __FILE__);
958  status = nc_get_att_float(geolocationGrp, solzId, "add_offset", &solzOffset);
959  check_err(status, __LINE__, __FILE__);
960 
961  status = nc_inq_varid(geolocationGrp, "solar_azimuth", &solaId);
962  check_err(status, __LINE__, __FILE__);
963  status = nc_inq_var_fill(geolocationGrp, solaId, NULL, &solaFillValue);
964  check_err(status, __LINE__, __FILE__);
965  status = nc_get_att_float(geolocationGrp, solaId, "scale_factor", &solaScale);
966  check_err(status, __LINE__, __FILE__);
967  status = nc_get_att_float(geolocationGrp, solaId, "add_offset", &solaOffset);
968  check_err(status, __LINE__, __FILE__);
969 
970  // get IDs for the observations
971  status = nc_inq_grp_ncid(ncid_L1B, "observation_data", &observationGrp);
972  check_err(status, __LINE__, __FILE__);
973 
974  status = nc_inq_varid(observationGrp, "Lt_blue", &Lt_blueId);
975 
976  use_rhot = 0;
977  // Get varids for each of the Lt_*
978  if (status == NC_NOERR) {
979  status = nc_inq_var_fill(observationGrp, Lt_blueId, NULL, &Lt_blueFillValue);
980  check_err(status, __LINE__, __FILE__);
981 
982  status = nc_inq_varid(observationGrp, "Lt_red", &Lt_redId);
983  check_err(status, __LINE__, __FILE__);
984  status = nc_inq_var_fill(observationGrp, Lt_redId, NULL, &Lt_redFillValue);
985  check_err(status, __LINE__, __FILE__);
986 
987  status = nc_inq_varid(observationGrp, "Lt_SWIR", &Lt_SWIRId);
988  check_err(status, __LINE__, __FILE__);
989  status = nc_inq_var_fill(observationGrp, Lt_SWIRId, NULL, &Lt_SWIRFillValue);
990  check_err(status, __LINE__, __FILE__);
991  } else {
992  status = nc_inq_varid(observationGrp, "rhot_blue", &Lt_blueId);
993  check_err(status, __LINE__, __FILE__);
994  status = nc_inq_var_fill(observationGrp, Lt_blueId, NULL, &Lt_blueFillValue);
995  check_err(status, __LINE__, __FILE__);
996  status = nc_inq_varid(observationGrp, "rhot_red", &Lt_redId);
997  check_err(status, __LINE__, __FILE__);
998  status = nc_inq_var_fill(observationGrp, Lt_redId, NULL, &Lt_redFillValue);
999  check_err(status, __LINE__, __FILE__);
1000 
1001  status = nc_inq_varid(observationGrp, "rhot_SWIR", &Lt_SWIRId);
1002  check_err(status, __LINE__, __FILE__);
1003  status = nc_inq_var_fill(observationGrp, Lt_SWIRId, NULL, &Lt_SWIRFillValue);
1004  check_err(status, __LINE__, __FILE__);
1005  use_rhot = 1;
1006  }
1007 
1008  l1cstr->nbands = tot_num_bands;
1009  // l1cfile assig
1010  l1cfile->sd_id = ncid_L1B;
1011  l1cfile->nband_blue = num_blue_bands;
1012  l1cfile->nband_red = num_red_bands;
1013  l1cfile->nband_swir = num_SWIR_bands;
1014  l1cfile->nbands = num_blue_bands + num_red_bands + num_SWIR_bands;
1015  nviews = 2;
1016  l1cfile->n_views = nviews;
1017 
1018  cout << "file->nbands_b =" << l1cfile->nband_blue << endl;
1019  cout << "file->nbands_r = " << l1cfile->nband_red << endl;
1020  cout << "file->nbands_swir = " << l1cfile->nband_swir << endl;
1021  /*
1022  if(l1cfile->format==FT_OCIL1B){
1023  expected_num_blue_bands=120;//actually 121,165,9
1024  expected_num_red_bands=168;
1025  expected_num_SWIR_bands=9;
1026  tot_num_bands=expected_num_blue_bands+expected_num_red_bands+expected_num_SWIR_bands;
1027  }
1028  */
1029  // cout<<"expected blue.."<<expected_num_blue_bands<<"expected red.."<<expected_num_red_bands<<"expected
1030  // SWIR.."<<expected_num_SWIR_bands<<"tot bands.."<<tot_num_bands<<endl;
1031 
1032  l1cfile->npix = num_pixels;
1033  l1cfile->nadpix = (num_pixels - 1) / 2; // nadir pixel index
1034  l1cfile->nscan = num_scans;
1035  l1cfile->ndets = 1;
1036  l1cfile->terrain_corrected = 1; // presumed.
1037  // l1cfile->orbit_number = orbit_number;
1038 
1039  return 0;
1040 }
1041 
1043  std::string str;
1044  const char *ptstr;
1045 
1046  // Open the netcdf4 input file
1047  str = l1cfile->l1b_name;
1048  ptstr = str.c_str();
1049  printf("Opening HARP2 L1B file\n");
1050  cout << str << endl;
1051 
1052  status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
1053  if (status != NC_NOERR) {
1054  fprintf(stderr, "-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
1055  return (1);
1056  }
1057 
1058  if (l1cfile->format == FT_HARP2) {
1059  // open blue group--
1060  status = nc_inq_grp_ncid(ncid_L1B, "blue", &blueGrp);
1061  if (status != NC_NOERR) {
1062  fprintf(stderr, "-E- Error reading group blue.\n");
1063  exit(EXIT_FAILURE);
1064  }
1065 
1066  // number of views
1067  status = nc_inq_dimid(blueGrp, "Views", &dimid);
1068  if (status != NC_NOERR) {
1069  fprintf(stderr, "-E- Error reading number_of_views.\n");
1070  exit(EXIT_FAILURE);
1071  }
1072  nc_inq_dimlen(ncid_L1B, dimid, &nviews);
1073  l1cstr->nviews = nviews;
1074 
1075  // number of scans
1076  status = nc_inq_dimid(ncid_L1B, "Swath_Lines", &dimid);
1077  if (status != NC_NOERR) {
1078  fprintf(stderr, "-E- Error reading number_of_lines.\n");
1079  exit(EXIT_FAILURE);
1080  }
1081  nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
1082  l1cstr->nscan = num_scans;
1083 
1084  // num_pixels
1085  status = nc_inq_dimid(ncid_L1B, "Swath_Pixels", &dimid);
1086  if (status != NC_NOERR) {
1087  fprintf(stderr, "-E- Error reading num_pixels.\n");
1088  exit(EXIT_FAILURE);
1089  }
1090  nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
1091  l1cstr->npix = num_pixels;
1092 
1093  /* //number of bands
1094  status = nc_inq_dimid(ncid_L1B, "intensity_bands_per_view", &dimid);
1095  if (status != NC_NOERR) {
1096  fprintf(stderr, "-E- Error reading intensity_bands_per_view.\n");
1097  exit(EXIT_FAILURE);
1098  }
1099  nc_inq_dimlen(ncid_L1B, dimid, &nband_view);
1100 
1101 
1102  status = nc_inq_dimid(ncid_L1B, "polarization_bands_per_view", &dimid);
1103  if (status != NC_NOERR) {
1104  fprintf(stderr, "-E- Error reading polarization_bands_per_view.\n");
1105  exit(EXIT_FAILURE);
1106  }
1107  nc_inq_dimlen(ncid_L1B, dimid, &npol_band_view);
1108  */
1109 
1110  // blue group
1111  nband_view = 4;
1112  npol_band_view = 4;
1113  }
1114 
1115  printf("L1B Npix :%d Nlines:%d\n", (int)num_pixels, (int)num_scans);
1116 
1117  // allocate all of the data
1118  l1cstr->senazpix_3d = allocate2d_float(nviews, num_pixels);
1119  l1cstr->latpix_3d = allocate2d_float(nviews, num_pixels);
1120  l1cstr->lonpix_3d = allocate2d_float(nviews, num_pixels);
1121  l1cstr->latpix2_3d = allocate2d_float(nviews, num_pixels);
1122  l1cstr->lonpix2_3d = allocate2d_float(nviews, num_pixels);
1123 
1124  l1cstr->I = allocate2d_float(nviews, num_pixels);
1125  l1cstr->I_polsample = allocate2d_float(nviews, num_pixels);
1126 
1127  l1cstr->I_lambdas = allocate2d_float(nviews, nband_view);
1128  l1cstr->pol_lambdas = allocate2d_float(nviews, npol_band_view);
1129 
1130  // only blue group
1131  for (size_t i = 0; i < nviews; i++) {
1132  l1cstr->I_lambdas[i][0] = 441.9;
1133  l1cstr->I_lambdas[i][1] = 549.8;
1134  l1cstr->I_lambdas[i][2] = 669.4;
1135  l1cstr->I_lambdas[i][3] = 867.8;
1136 
1137  l1cstr->pol_lambdas[i][0] = 441.9;
1138  l1cstr->pol_lambdas[i][1] = 549.8;
1139  l1cstr->pol_lambdas[i][2] = 669.4;
1140  l1cstr->pol_lambdas[i][3] = 867.8;
1141  }
1142 
1143  // Get group id from L1B file for GROUP scan_line_attributes.
1144 
1145  // get start time
1146  size_t att_len;
1147  status = nc_inq_attlen(ncid_L1B, NC_GLOBAL, "time_coverage_start", &att_len);
1148  check_err(status, __LINE__, __FILE__);
1149 
1150  // allocate required space before retrieving values
1151  char *time_str = (char *)malloc(att_len + 1); // + 1 for trailing null
1152 
1153  // get attribute values
1154  status = nc_get_att_text(ncid_L1B, NC_GLOBAL, "time_coverage_start", time_str);
1155  check_err(status, __LINE__, __FILE__);
1156  time_str[att_len] = '\0';
1157 
1158  double start_time = isodate2unix(time_str);
1159  int16_t syear, smon, sday;
1160  double secs;
1161  unix2ymds(start_time, &syear, &smon, &sday, &secs);
1162  scan_time_year = syear;
1163  scan_time_month = smon;
1164  scan_time_day = sday;
1165 
1166  /*
1167  for(size_t i=0; i<num_scans; i++) {
1168  if(scan_time[i] == scan_timeFillValue)
1169  scan_time[i] = BAD_FLT;
1170  }
1171  */
1172 
1173  // read the orbit#
1174  int orbit_number;
1175  status = nc_get_att_int(ncid_L1B, NC_GLOBAL, "orbit_number", &orbit_number);
1176  check_err(status, __LINE__, __FILE__);
1177 
1178  // lambdas for each spectral range
1179  /*
1180  status = nc_inq_grp_ncid(ncid_L1B, "SENSOR_VIEW_BANDS", &lambdaGrp);
1181  check_err(status, __LINE__, __FILE__);
1182  status = nc_inq_varid(lambdaGrp, "intensity_wavelengths", &iwId);
1183  check_err(status, __LINE__, __FILE__);
1184  status = nc_inq_varid(lambdaGrp, "polarization_wavelengths", &pwId);
1185  check_err(status, __LINE__, __FILE__);
1186 
1187 
1188 
1189 
1190  status = nc_get_var_float(lambdaGrp, iwId,l1cstr->I_lambdas[0]);
1191  check_err(status, __LINE__, __FILE__);
1192  status = nc_get_var_float(lambdaGrp, pwId,l1cstr->pol_lambdas[0]);
1193  check_err(status, __LINE__, __FILE__);
1194  */
1195 
1196  // Setup geofile pointers
1197  status = nc_inq_varid(blueGrp, "Longitude", &lonId);
1198  check_err(status, __LINE__, __FILE__);
1199 
1200  status = nc_inq_var_fill(blueGrp, lonId, NULL, &lonFillValue);
1201  check_err(status, __LINE__, __FILE__);
1202  status = nc_inq_varid(blueGrp, "Latitude", &latId);
1203  check_err(status, __LINE__, __FILE__);
1204  status = nc_inq_var_fill(blueGrp, latId, NULL, &latFillValue);
1205  check_err(status, __LINE__, __FILE__);
1206 
1207  status = nc_inq_varid(blueGrp, "View_Zenith", &senzId);
1208  check_err(status, __LINE__, __FILE__);
1209  status = nc_inq_var_fill(blueGrp, senzId, NULL, &senzFillValue);
1210  check_err(status, __LINE__, __FILE__);
1211  // status = nc_get_att_float(geolocationGrp, senzId, "scale_factor", &senzScale);
1212  // check_err(status, __LINE__, __FILE__);
1213  // status = nc_get_att_float(geolocationGrp, senzId, "add_offset", &senzOffset);
1214  // check_err(status, __LINE__, __FILE__);
1215 
1216  status = nc_inq_varid(blueGrp, "View_Azimuth", &senaId);
1217  check_err(status, __LINE__, __FILE__);
1218  status = nc_inq_var_fill(blueGrp, senaId, NULL, &senaFillValue);
1219  check_err(status, __LINE__, __FILE__);
1220  // status = nc_get_att_float(geolocationGrp, senaId, "scale_factor", &senaScale);
1221  // check_err(status, __LINE__, __FILE__);
1222  // status = nc_get_att_float(geolocationGrp, senaId, "add_offset", &senaOffset);
1223  // check_err(status, __LINE__, __FILE__);
1224 
1225  status = nc_inq_varid(blueGrp, "Solar_Zenith", &solzId);
1226  check_err(status, __LINE__, __FILE__);
1227  status = nc_inq_var_fill(blueGrp, solzId, NULL, &solzFillValue);
1228  check_err(status, __LINE__, __FILE__);
1229  status = nc_get_att_float(blueGrp, solzId, "scale_factor", &solzScale);
1230  // check_err(status, __LINE__, __FILE__);
1231  // status = nc_get_att_float(geolocationGrp, solzId, "add_offset", &solzOffset);
1232  // check_err(status, __LINE__, __FILE__);
1233 
1234  status = nc_inq_varid(blueGrp, "Solar_Azimuth", &solaId);
1235  check_err(status, __LINE__, __FILE__);
1236  status = nc_inq_var_fill(blueGrp, solaId, NULL, &solaFillValue);
1237  check_err(status, __LINE__, __FILE__);
1238  status = nc_get_att_float(blueGrp, solaId, "scale_factor", &solaScale);
1239  // check_err(status, __LINE__, __FILE__);
1240  // status = nc_get_att_float(geolocationGrp, solaId, "add_offset", &solaOffset);
1241  // check_err(status, __LINE__, __FILE__);
1242 
1243  // get IDs for the observations
1244  // Get varids for each of the Lt_*
1245  status = nc_inq_varid(blueGrp, "I", &IntId);
1246  check_err(status, __LINE__, __FILE__);
1247  status = nc_inq_var_fill(blueGrp, IntId, NULL, &I_FillValue);
1248  check_err(status, __LINE__, __FILE__);
1249  /*
1250  status = nc_inq_varid(blueGrp, "I_polsample", &IpolId);
1251  check_err(status, __LINE__, __FILE__);
1252  status = nc_inq_var_fill(blueGrp, IpolId, NULL, &Ipol_FillValue);
1253  check_err(status, __LINE__, __FILE__);
1254  */
1255 
1256  // l1cfile assig
1257  l1cfile->sd_id = ncid_L1B;
1258  l1cfile->nband_view = nband_view;
1259  l1cfile->npol_band_view = npol_band_view;
1260  l1cfile->n_views = nviews;
1261 
1262  cout << "nband_view =" << nband_view << endl;
1263  cout << "npol_band_view = " << npol_band_view << endl;
1264 
1265  l1cfile->npix = num_pixels;
1266  l1cfile->nadpix = (num_pixels - 1) / 2; // nadir pixel index
1267  l1cfile->nscan = num_scans;
1268  l1cfile->terrain_corrected = 1; // presumed.
1269  l1cfile->orbit_number = orbit_number;
1270 
1271  cout << "n_views..." << l1cfile->n_views << "intensity bands.per view..." << nband_view
1272  << "polarization bands.per view." << npol_band_view << endl;
1273 
1274  return 0;
1275 }
1276 
1277 //--------------------------------------------------------------------------------------
1278 int32_t l1c_str::readl1b_spex_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t sline) {
1279  size_t oneline;
1280  size_t start[] = {0, 0}, start2[] = {0, 0}, start3[] = {0, 0, 0};
1281  size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1282  string str;
1283 
1284  str = l1cfile->l1b_name;
1285 
1286  printf("Reading SPEXone L1B file\n");
1287  cout << str << endl;
1288 
1289  // assigning mem for Lt of different bands **********************
1290 
1291  // GEOLOCATION
1292  l1cstr->iscan = sline;
1293 
1294  start[0] = sline;
1295  start[1] = 0;
1296  count[0] = 1;
1297  count[1] = num_pixels; // 1 line at a time
1298 
1299  status = nc_get_vara_float(
1300  geolocationGrp, senaId, start, count,
1301  l1cstr->senazpix); // sensor azimuth -1800 to 1800 degrees, so must be divdied by 100
1302  status = nc_get_vara_float(geolocationGrp, latId, start, count, l1cstr->latpix);
1303  check_err(status, __LINE__, __FILE__);
1304  status = nc_get_vara_float(geolocationGrp, lonId, start, count, l1cstr->lonpix);
1305  check_err(status, __LINE__, __FILE__);
1306 
1307  oneline = sline;
1308 
1309  if (oneline < num_scans - 1)
1310  start2[0] = sline + 1;
1311  else
1312  start2[0] = sline;
1313 
1314  start2[1] = 0;
1315 
1316  status = nc_get_vara_float(geolocationGrp, latId, start2, count, l1cstr->latpix2);
1317  check_err(status, __LINE__, __FILE__);
1318  status = nc_get_vara_float(geolocationGrp, lonId, start2, count, l1cstr->lonpix2);
1319  check_err(status, __LINE__, __FILE__);
1320 
1321  // RADIANCES
1322  start3[0] = sline;
1323  start3[1] = 0;
1324  start3[2] = 0;
1325  count2[0] = 1;
1326  count2[1] = num_pixels; // 1 line at a time
1327  count2[2] = nband_view;
1328 
1329  status = nc_get_vara_float(observationGrp, IntId, start3, count2,
1330  l1cstr->I[0]); // these are 2-D arrays------------ #bands x #pixels
1331  check_err(status, __LINE__, __FILE__);
1332 
1333  count2[2] = npol_band_view;
1334  status = nc_get_vara_float(observationGrp, IpolId, start3, count2, l1cstr->I_polsample[0]);
1335  check_err(status, __LINE__, __FILE__);
1336 
1337  return 0;
1338 }
1339 
1340 int32_t l1c_str::writel1c_ocis(l1c_str *l1cstr, bin_str *binl1c, netCDF::NcFile *nc_output, float **Ltfrac,
1341  float **areafrac, short **obs_view, int band_ix, int view_ix) {
1342  string str;
1343  short minval, maxval;
1344  float minval2, maxval2;
1345 
1346  netCDF::NcDim yd = nc_output->getDim("bins_along_track");
1347  int ybins = yd.getSize();
1348  netCDF::NcDim xd = nc_output->getDim("bins_across_track");
1349  int xbins = xd.getSize();
1350 
1351  cout << "saving full L1C granule -- aw binning.."
1352  << "ybins.." << ybins << "xbins.." << xbins << "band #: " << band_ix + 1
1353  << "view #: " << view_ix + 1 << endl;
1354 
1355  std::vector<size_t> start3;
1356  start3.push_back(0);
1357  start3.push_back(0);
1358  start3.push_back(view_ix);
1359 
1360  std::vector<size_t> count3;
1361  count3.push_back(ybins);
1362  count3.push_back(xbins);
1363  count3.push_back(1);
1364 
1365  short **obs_clean = allocate2d_short(ybins, xbins);
1366 
1367  netCDF::NcGroup od_grp = nc_output->getGroup("observation_data");
1368  netCDF::NcVar v1 = od_grp.getVar("obs_per_view");
1369  netCDF::NcVarAtt a1 = v1.getAtt("valid_min"); // root group
1370  a1.getValues(&minval);
1371  a1 = v1.getAtt("valid_max"); // root group
1372  a1.getValues(&maxval);
1373 
1374  for (int i = 0; i < ybins; i++) {
1375  for (int j = 0; j < xbins; j++) {
1376  if (obs_view[i][j] > maxval || obs_view[i][j] < minval) {
1377  obs_view[i][j] = binl1c->fillval1; // fillvalue
1378  }
1379  obs_clean[i][j] = obs_view[i][j];
1380  }
1381  }
1382  v1.putVar(start3, count3, &obs_clean[0][0]);
1383  free (obs_clean);
1384 
1385  v1 = od_grp.getVar("I");
1386  a1 = v1.getAtt("valid_min"); // root group
1387  a1.getValues(&minval2);
1388  a1 = v1.getAtt("valid_max"); // root group
1389  a1.getValues(&maxval2);
1390 
1391  std::vector<size_t> start4;
1392  start4.push_back(0);
1393  start4.push_back(0);
1394  start4.push_back(view_ix);
1395  start4.push_back(band_ix);
1396 
1397  std::vector<size_t> count4;
1398  count4.push_back(ybins);
1399  count4.push_back(xbins);
1400  count4.push_back(1);
1401  count4.push_back(1);
1402 
1403  float **Lt = allocate2d_float(ybins, xbins);
1404 
1405  for (int i = 0; i < ybins; i++) {
1406  for (int j = 0; j < xbins; j++) {
1407  if (areafrac[i][j] > 0) {
1408  Lt[i][j] = Ltfrac[i][j] / sqrt(areafrac[i][j]);
1409 
1410  // check min/max values
1411  if (Lt[i][j] < minval2 || Lt[i][j] > maxval2)
1412  Lt[i][j] = binl1c->fillval2;
1413  } else {
1414  Lt[i][j] = binl1c->fillval2; // fillvalue
1415  }
1416  }
1417  }
1418 
1419  v1.putVar(start4, count4, &Lt[0][0]);
1420 
1421  free (Lt);
1422 
1423  return 0;
1424 }
1425 
1426 int32_t l1c_str::readl1b_ocis_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t sline) {
1427  size_t oneline;
1428  size_t start[] = {0, 0}, start2[] = {0, 0}, start4[] = {0, 0, 0};
1429  size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1430  string str;
1431 
1432  str = l1cfile->l1b_name;
1433 
1434  printf("Reading OCIS L1B file\n");
1435  cout << str << endl;
1436 
1437  // assigning mem for Lt of different bands **********************
1438 
1439  // GEOLOCATION
1440  l1cstr->iscan = sline;
1441 
1442  start[0] = sline;
1443  start[1] = 0;
1444  count[0] = 1;
1445  count[1] = num_pixels; // 1 line at a time
1446 
1447  status = nc_get_vara_float(geolocationGrp, solzId, start, count, l1cstr->solz);
1448  status = nc_get_vara_float(geolocationGrp, senzId, start, count, l1cstr->senz);
1449  status = nc_get_vara_float(geolocationGrp, latId, start, count, l1cstr->latpix);
1450  check_err(status, __LINE__, __FILE__);
1451  status = nc_get_vara_float(geolocationGrp, lonId, start, count, l1cstr->lonpix);
1452  check_err(status, __LINE__, __FILE__);
1453 
1454  oneline = sline;
1455 
1456  if (oneline < num_scans - 1)
1457  start2[0] = sline + 1;
1458  else
1459  start2[0] = sline;
1460 
1461  start2[1] = 0;
1462 
1463  status = nc_get_vara_float(geolocationGrp, latId, start2, count, l1cstr->latpix2);
1464  check_err(status, __LINE__, __FILE__);
1465  status = nc_get_vara_float(geolocationGrp, lonId, start2, count, l1cstr->lonpix2);
1466  check_err(status, __LINE__, __FILE__);
1467 
1468  // RADIANCES---Don'way for indexing
1469  start4[0] = 0;
1470  start4[1] = sline;
1471  start4[2] = 0;
1472  count2[0] = num_blue_bands;
1473  count2[1] = 1; // 1 line at a time
1474  count2[2] = num_pixels;
1475 
1476  status = nc_get_vara_float(observationGrp, Lt_blueId, start4, count2,
1477  l1cstr->Lt_blue[0]); // these are 2-D arrays------------ #bands x #pixels
1478  check_err(status, __LINE__, __FILE__);
1479 
1480  count2[0] = num_red_bands;
1481  status = nc_get_vara_float(observationGrp, Lt_redId, start4, count2, l1cstr->Lt_red[0]);
1482  check_err(status, __LINE__, __FILE__);
1483 
1484  count2[0] = num_SWIR_bands;
1485  status = nc_get_vara_float(observationGrp, Lt_SWIRId, start4, count2, l1cstr->Lt_SWIR[0]);
1486  check_err(status, __LINE__, __FILE__);
1487 
1488  double scantime = ymds2unix((int16_t)scan_time_year, (int16_t)scan_time_month, (int16_t)scan_time_day,
1489  scan_time[sline]);
1490  int16_t syear, sday;
1491  double secs;
1492  unix2yds(scantime, &syear, &sday, &secs);
1493 
1494  int32_t yr = syear;
1495  int32_t dy = sday;
1496  int32_t msec = (int32_t)(secs * 1000.0);
1497  double esdist = esdist_(&yr, &dy, &msec);
1498 
1499  float fsol = pow(1.0 / esdist, 2);
1500 
1501  for (size_t ip = 0; ip < num_pixels; ip++) {
1502  size_t band;
1503  int ib = 0;
1504  int ipb = ip * tot_num_bands;
1505 
1506  // load up the blue bands skip the last two
1507  if(num_blue_bands<expected_num_blue_bands){
1508  expected_num_blue_bands=num_blue_bands;
1509  }
1510  else{
1511  expected_num_blue_bands=expected_num_blue_bands-2;
1512  }
1513 
1514  for (band = 0; band < expected_num_blue_bands; band++) {
1515  if (Lt_blue[band][ip] == Lt_blueFillValue) {
1516  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1517  } else {
1518  l1cstr->Lt_tot[ipb] = Lt_blue[band][ip];
1519  if (normalizedLt) {
1520  l1cstr->Lt_tot[ipb] *= 100;
1521  } else if (use_rhot) {
1522  // l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip]/RADEG) /
1523  // M_PI;
1524 
1525  } else {
1526  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1527  }
1528  }
1529  ib++;
1530  ipb++;
1531  }
1532 
1533  // load up the red bands skipping the first two and the last 4
1534  if(num_red_bands<expected_num_red_bands){
1535  expected_num_red_bands=num_red_bands;
1536  }
1537  else{
1538  expected_num_red_bands=expected_num_red_bands-4;
1539  }
1540 
1541  for (band = 2; band < expected_num_red_bands; band++) {
1542  if (Lt_red[band][ip] == Lt_redFillValue) {
1543  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1544  } else {
1545  l1cstr->Lt_tot[ipb] = Lt_red[band][ip];
1546  if (normalizedLt) {
1547  l1cstr->Lt_tot[ipb] *= 100;
1548  } else if (use_rhot) {
1549  l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip] / RADEG) / M_PI;
1550  } else {
1551  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1552  }
1553  }
1554  ib++;
1555  ipb++;
1556  }
1557 
1558  // load up the SWIR bands, skip band 3 and 6, hi/low gain wavelengths
1559  if(num_SWIR_bands<expected_num_SWIR_bands){
1560  expected_num_SWIR_bands=num_SWIR_bands;
1561  }
1562 
1563  for (band = 0; band < expected_num_SWIR_bands; band++) {
1564  if (band == 3 || band == 6)
1565  continue;
1566  if (Lt_SWIR[band][ip] == Lt_SWIRFillValue) {
1567  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1568  } else {
1569  l1cstr->Lt_tot[ipb] = Lt_SWIR[band][ip];
1570  if (normalizedLt) {
1571  l1cstr->Lt_tot[ipb] *= 100;
1572  } else if (use_rhot) {
1573  l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip] / RADEG) / M_PI;
1574  } else {
1575  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1576  }
1577  }
1578  ib++;
1579  ipb++;
1580  }
1581  }
1582 
1583  return 0;
1584 }
1585 
1586 int32_t l1c_str::readl1b_ocis_3lines(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t sline) {
1587  size_t oneline;
1588  size_t start[] = {0, 0}, start2[] = {0, 0}, start3[] = {0, 0}, start4[] = {0, 0, 0};
1589  size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1590  string str;
1591 
1592  str = l1cfile->l1b_name;
1593 
1594  printf("Reading OCIS L1B file\n");
1595 
1596 
1597  // assigning mem for Lt of different bands **********************
1598 
1599  // GEOLOCATION
1600  l1cstr->iscan = sline;
1601 
1602  start[0] = sline;
1603  start[1] = 0;
1604  count[0] = 1;
1605  count[1] = num_pixels; // 1 line at a time
1606 
1607  status = nc_get_vara_float(geolocationGrp, solzId, start, count, l1cstr->solz);
1608  status = nc_get_vara_float(geolocationGrp, senzId, start, count, l1cstr->senz);
1609  status = nc_get_vara_float(geolocationGrp, latId, start, count, l1cstr->latpix);
1610  check_err(status, __LINE__, __FILE__);
1611  status = nc_get_vara_float(geolocationGrp, lonId, start, count, l1cstr->lonpix);
1612  check_err(status, __LINE__, __FILE__);
1613 
1614  oneline = sline;
1615 
1616  if (oneline < num_scans - 1)
1617  start2[0] = sline + 1;
1618  else
1619  start2[0] = sline;
1620 
1621  start2[1] = 0;
1622 
1623  status = nc_get_vara_float(geolocationGrp, latId, start2, count, l1cstr->latpix2);
1624  check_err(status, __LINE__, __FILE__);
1625  status = nc_get_vara_float(geolocationGrp, lonId, start2, count, l1cstr->lonpix2);
1626  check_err(status, __LINE__, __FILE__);
1627 
1628  if (oneline < num_scans - 2)
1629  start3[0] = sline + 2;
1630  else
1631  start3[0] = sline;
1632 
1633  start3[1] = 0;
1634 
1635  status = nc_get_vara_float(geolocationGrp, latId, start3, count, l1cstr->latpix3);
1636  check_err(status, __LINE__, __FILE__);
1637  status = nc_get_vara_float(geolocationGrp, lonId, start3, count, l1cstr->lonpix3);
1638  check_err(status, __LINE__, __FILE__);
1639 
1640  // RADIANCES---Don'way for indexing
1641  start4[0] = 0;
1642  start4[1] = sline;
1643  start4[2] = 0;
1644  count2[0] = num_blue_bands;
1645  count2[1] = 1; // 1 line at a time
1646  count2[2] = num_pixels;
1647 
1648  status = nc_get_vara_float(observationGrp, Lt_blueId, start4, count2,
1649  l1cstr->Lt_blue[0]); // these are 2-D arrays------------ #bands x #pixels
1650  check_err(status, __LINE__, __FILE__);
1651 
1652  count2[0] = num_red_bands;
1653  status = nc_get_vara_float(observationGrp, Lt_redId, start4, count2, l1cstr->Lt_red[0]);
1654  check_err(status, __LINE__, __FILE__);
1655 
1656  count2[0] = num_SWIR_bands;
1657  status = nc_get_vara_float(observationGrp, Lt_SWIRId, start4, count2, l1cstr->Lt_SWIR[0]);
1658  check_err(status, __LINE__, __FILE__);
1659 
1660  double scantime = ymds2unix((int16_t)scan_time_year, (int16_t)scan_time_month, (int16_t)scan_time_day,
1661  scan_time[sline]);
1662  int16_t syear, sday;
1663  double secs;
1664  unix2yds(scantime, &syear, &sday, &secs);
1665 
1666  int32_t yr = syear;
1667  int32_t dy = sday;
1668  int32_t msec = (int32_t)(secs * 1000.0);
1669  double esdist = esdist_(&yr, &dy, &msec);
1670 
1671  float fsol = pow(1.0 / esdist, 2);
1672 
1673  for (size_t ip = 0; ip < num_pixels; ip++) {
1674  size_t band;
1675  int ib = 0;
1676  int ipb = ip * tot_num_bands;
1677 
1678  // load up the blue bands skip the last two
1679  if(num_blue_bands<expected_num_blue_bands){
1680  expected_num_blue_bands=num_blue_bands;
1681  }
1682  else{
1683  expected_num_blue_bands=expected_num_blue_bands-2;
1684  }
1685 
1686  for (band = 0; band < expected_num_blue_bands; band++) {
1687  if (Lt_blue[band][ip] == Lt_blueFillValue) {
1688  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1689  } else {
1690  l1cstr->Lt_tot[ipb] = Lt_blue[band][ip];
1691  if (normalizedLt) {
1692  l1cstr->Lt_tot[ipb] *= 100;
1693  } else if (use_rhot) {
1694  l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip] / RADEG) / M_PI;
1695 
1696  } else {
1697  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1698  }
1699  }
1700  ib++;
1701  ipb++;
1702  }
1703 
1704  // load up the red bands skipping the first two and the last 4
1705  if(num_red_bands<expected_num_red_bands){
1706  expected_num_red_bands=num_red_bands;
1707  }
1708  else{
1709  expected_num_red_bands=expected_num_red_bands-4;
1710  }
1711 
1712  for (band = 2; band < expected_num_red_bands; band++) {
1713  if (Lt_red[band][ip] == Lt_redFillValue) {
1714  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1715  } else {
1716  l1cstr->Lt_tot[ipb] = Lt_red[band][ip];
1717  if (normalizedLt) {
1718  l1cstr->Lt_tot[ipb] *= 100;
1719  } else if (use_rhot) {
1720  l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip] / RADEG) / M_PI;
1721  } else {
1722  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1723  }
1724  }
1725  ib++;
1726  ipb++;
1727  }
1728 
1729  // load up the SWIR bands, skip band 3 and 6, hi/low gain wavelengths
1730 
1731  if(num_SWIR_bands<expected_num_SWIR_bands){
1732  expected_num_SWIR_bands=num_SWIR_bands;
1733  }
1734  for (band = 0; band < expected_num_SWIR_bands; band++) {
1735  if (band == 3 || band == 6)
1736  continue;
1737  if (Lt_SWIR[band][ip] == Lt_SWIRFillValue) {
1738  l1cstr->Lt_tot[ipb] = 0.001; // should be BAD_FLT, but that makes atmocor fail
1739  } else {
1740  l1cstr->Lt_tot[ipb] = Lt_SWIR[band][ip];
1741  if (normalizedLt) {
1742  l1cstr->Lt_tot[ipb] *= 100;
1743  } else if (use_rhot) {
1744  l1cstr->Lt_tot[ipb] *= l1cstr->Fobar[ib] * fsol * cos(l1cstr->solz[ip] / RADEG) / M_PI;
1745  } else {
1746  l1cstr->Lt_tot[ipb] /= 10.; // the input is in W/m2 ...
1747  }
1748  }
1749  ib++;
1750  ipb++;
1751  }
1752  }
1753 
1754  return 0;
1755 }
1756 
1757 int32_t l1c_str::readl1b_harp2_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t sline) {
1758  size_t oneline;
1759  size_t start3[] = {0, 0, 0};
1760  size_t count2[] = {1, 1, 1};
1761  string str;
1762 
1763  str = l1cfile->l1b_name;
1764 
1765  printf("Reading HARP2 L1B file\n");
1766  cout << str << endl;
1767 
1768  // assigning mem for Lt of different bands **********************
1769 
1770  // GEOLOCATION
1771  l1cstr->iscan = sline;
1772 
1773  // RADIANCES
1774  start3[0] = 0;
1775  start3[1] = sline;
1776  start3[2] = 0;
1777  count2[0] = nviews;
1778  count2[1] = 1; // 1 line at a time
1779  count2[2] = num_pixels;
1780 
1781  status = nc_get_vara_float(blueGrp, senaId, start3, count2,
1782  l1cstr->senazpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1783  check_err(status, __LINE__, __FILE__);
1784  status = nc_get_vara_float(blueGrp, latId, start3, count2,
1785  l1cstr->latpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1786  check_err(status, __LINE__, __FILE__);
1787  status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1788  l1cstr->lonpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1789  check_err(status, __LINE__, __FILE__);
1790 
1791  oneline = sline;
1792 
1793  if (oneline < num_scans - 1)
1794  start3[1] = sline + 1;
1795  else
1796  start3[1] = sline;
1797 
1798  status = nc_get_vara_float(blueGrp, latId, start3, count2,
1799  l1cstr->latpix2_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1800  check_err(status, __LINE__, __FILE__);
1801  status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1802  l1cstr->lonpix2_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1803  check_err(status, __LINE__, __FILE__);
1804 
1805  status = nc_get_vara_float(blueGrp, IntId, start3, count2,
1806  l1cstr->I[0]); // these are 2-D arrays------------ #bands x #pixels
1807  check_err(status, __LINE__, __FILE__);
1808 
1809  return 0;
1810 }
1811 
1812 int32_t l1c_str::readl1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file,
1813  int32_t sline) {
1814  size_t oneline;
1815  size_t start3[] = {0, 0, 0};
1816  size_t count2[] = {1, 1, 1};
1817  string str;
1818 
1819  str = l1cfile->l1b_name;
1820 
1821  printf("Reading HARP2 L1B file\n");
1822  cout << str << endl;
1823 
1824  // assigning mem for Lt of different bands **********************
1825 
1826  // GEOLOCATION
1827  l1cstr->iscan = sline;
1828 
1829  // RADIANCES
1830  start3[0] = 0;
1831  start3[1] = sline;
1832  start3[2] = 0;
1833  count2[0] = nviews;
1834  count2[1] = 1; // 1 line at a time
1835  count2[2] = num_pixels;
1836 
1837  status = nc_get_vara_float(blueGrp, senaId, start3, count2,
1838  l1cstr->senazpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1839  check_err(status, __LINE__, __FILE__);
1840  status = nc_get_vara_float(blueGrp, latId, start3, count2,
1841  l1cstr->latpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1842  check_err(status, __LINE__, __FILE__);
1843  status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1844  l1cstr->lonpix_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1845  check_err(status, __LINE__, __FILE__);
1846 
1847  oneline = sline;
1848 
1849  if (oneline < num_scans - 1)
1850  start3[1] = sline + 1;
1851  else
1852  start3[1] = sline;
1853 
1854  status = nc_get_vara_float(blueGrp, latId, start3, count2,
1855  l1cstr->latpix2_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1856  check_err(status, __LINE__, __FILE__);
1857  status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1858  l1cstr->lonpix2_3d[0]); // these are 2-D arrays------------ #bands x #pixels
1859  check_err(status, __LINE__, __FILE__);
1860 
1861  status = nc_get_vara_float(blueGrp, IntId, start3, count2,
1862  l1cstr->I[0]); // these are 2-D arrays------------ #bands x #pixels
1863  check_err(status, __LINE__, __FILE__);
1864 
1865  return 0;
1866 }
1867 
1868 //--------------------------------------------------------------------------
1869 //__________________________________________________________________________
1870 
1872  string str;
1873 
1874  str = l1cfile->l1b_name;
1875  printf("Closing spexone l1b file\n");
1876  cout << str << endl;
1877  status = nc_close(l1cfile->sd_id);
1878  check_err(status, __LINE__, __FILE__);
1879 
1880  if (l1cstr->viewport != nullptr)
1881  free (l1cstr->viewport);
1882  if (l1cstr->senazpix != nullptr)
1883  free (l1cstr->senazpix);
1884  if (l1cstr->latpix != nullptr)
1885  free (l1cstr->latpix);
1886  if (l1cstr->lonpix != nullptr)
1887  free (l1cstr->lonpix);
1888  if (l1cstr->latpix2 != nullptr)
1889  free (l1cstr->latpix2);
1890  if (l1cstr->lonpix2 != nullptr)
1891  free (l1cstr->lonpix2);
1892  if (l1cstr->latpix3 != nullptr)
1893  free (l1cstr->latpix3);
1894  if (l1cstr->lonpix3 != nullptr)
1895  free (l1cstr->lonpix3);
1896 
1897  if (I_lambdas)
1898  free(I_lambdas);
1899  if (pol_lambdas)
1900  free(pol_lambdas);
1901 
1902  if (l1cstr->I)
1903  free2d_float(l1cstr->I);
1904  if (l1cstr->I_polsample)
1905  free2d_float(l1cstr->I_polsample);
1906 
1907  l1cstr->latpix = nullptr;
1908  l1cstr->latpix2 = nullptr;
1909  l1cstr->latpix3 = nullptr;
1910  l1cstr->lonpix = nullptr;
1911  l1cstr->lonpix2 = nullptr;
1912  l1cstr->lonpix3 = nullptr;
1913 
1914  l1cstr->I = nullptr;
1915  l1cstr->I_polsample = nullptr;
1916 
1917  return 0;
1918 }
1919 
1921  string str;
1922 
1923  str = l1cfile->l1b_name;
1924  printf("Closing ocis l1b file\n");
1925  cout << str << endl;
1926  status = nc_close(l1cfile->sd_id);
1927  check_err(status, __LINE__, __FILE__);
1928 
1929  // Free memory
1930  // From openl1b_ocis
1931  if (l1cstr->latpix != nullptr)
1932  free (l1cstr->latpix);
1933  if (l1cstr->lonpix != nullptr)
1934  free (l1cstr->lonpix);
1935  if (l1cstr->latpix2 != nullptr)
1936  free (l1cstr->latpix2);
1937  if (l1cstr->lonpix2 != nullptr)
1938  free (l1cstr->lonpix2);
1939  if (l1cstr->latpix3 != nullptr)
1940  free (l1cstr->latpix3);
1941  if (l1cstr->lonpix3 != nullptr)
1942  free (l1cstr->lonpix3);
1943  if (l1cstr->timepix != nullptr)
1944  free (l1cstr->timepix);
1945  if (l1cstr->tilt != nullptr)
1946  free (l1cstr->tilt);
1947 
1948  if (tmpShort)
1949  free(tmpShort);
1950  if (scan_time)
1951  free(scan_time);
1952  if (blue_lambdas)
1953  free(blue_lambdas);
1954  if (red_lambdas)
1955  free(red_lambdas);
1956  if (SWIR_lambdas)
1957  free(SWIR_lambdas);
1958 
1959  if (l1cstr->Lt_blue)
1960  free2d_float(l1cstr->Lt_blue);
1961  if (l1cstr->Lt_red)
1962  free2d_float(l1cstr->Lt_red);
1963  if (l1cstr->Lt_SWIR)
1964  free2d_float(l1cstr->Lt_SWIR);
1965 
1966  if (l1cstr->Lt_tot != nullptr)
1967  free (l1cstr->Lt_tot);
1968  if (l1cstr->Fobar != nullptr)
1969  free (l1cstr->Fobar);
1970  if (l1cstr->solz != nullptr)
1971  free (l1cstr->solz);
1972  if (l1cstr->senz != nullptr)
1973  free (l1cstr->senz);
1974 
1975  l1cstr->latpix = nullptr;
1976  l1cstr->latpix2 = nullptr;
1977  l1cstr->latpix3 = nullptr;
1978  l1cstr->lonpix = nullptr;
1979  l1cstr->lonpix2 = nullptr;
1980  l1cstr->lonpix3 = nullptr;
1981  l1cstr->timepix = nullptr;
1982  l1cstr->tilt = nullptr;
1983 
1984  l1cstr->Lt_blue = nullptr;
1985  l1cstr->Lt_red = nullptr;
1986  l1cstr->Lt_SWIR = nullptr;
1987  l1cstr->Lt_tot = nullptr;
1988  l1cstr->Fobar = nullptr;
1989 
1990  return 0;
1991 }
1992 
1994  string str;
1995 
1996  str = l1cfile->l1b_name;
1997  printf("Closing ocis l1b file\n");
1998  cout << str << endl;
1999  status = nc_close(l1cfile->sd_id);
2000  check_err(status, __LINE__, __FILE__);
2001 
2002  // Free memory
2003  // From openl1b_ocis
2004  if (l1cstr->latpix != nullptr)
2005  free (l1cstr->latpix);
2006  if (l1cstr->lonpix != nullptr)
2007  free (l1cstr->lonpix);
2008  if (l1cstr->latpix2 != nullptr)
2009  free (l1cstr->latpix2);
2010  if (l1cstr->lonpix2 != nullptr)
2011  free (l1cstr->lonpix2);
2012  if (l1cstr->latpix3 != nullptr)
2013  free (l1cstr->latpix3);
2014  if (l1cstr->lonpix3 != nullptr)
2015  free (l1cstr->lonpix3);
2016  if (l1cstr->timepix != nullptr)
2017  free (l1cstr->timepix);
2018 
2019  if (tmpShort)
2020  free(tmpShort);
2021  if (scan_time)
2022  free(scan_time);
2023  if (blue_lambdas)
2024  free(blue_lambdas);
2025  if (red_lambdas)
2026  free(red_lambdas);
2027  if (SWIR_lambdas)
2028  free(SWIR_lambdas);
2029 
2030  if (l1cstr->Lt_blue)
2031  free2d_float(l1cstr->Lt_blue);
2032  if (l1cstr->Lt_red)
2033  free2d_float(l1cstr->Lt_red);
2034  if (l1cstr->Lt_SWIR)
2035  free2d_float(l1cstr->Lt_SWIR);
2036 
2037  if (l1cstr->Lt_tot != nullptr)
2038  free (l1cstr->Lt_tot);
2039  if (l1cstr->Fobar != nullptr)
2040  free (l1cstr->Fobar);
2041  if (l1cstr->solz != nullptr)
2042  free (l1cstr->solz);
2043  if (l1cstr->senz != nullptr)
2044  free (l1cstr->senz);
2045 
2046  l1cstr->latpix = nullptr;
2047  l1cstr->latpix2 = nullptr;
2048  l1cstr->lonpix = nullptr;
2049  l1cstr->lonpix2 = nullptr;
2050 
2051  l1cstr->Lt_blue = nullptr;
2052  l1cstr->Lt_red = nullptr;
2053  l1cstr->Lt_SWIR = nullptr;
2054  l1cstr->Lt_tot = nullptr;
2055  l1cstr->Fobar = nullptr;
2056 
2057  return 0;
2058 }
2059 
2061  string str;
2062 
2063  str = l1cfile->l1b_name;
2064  printf("Closing harp2 l1b file\n");
2065  cout << str << endl;
2066  status = nc_close(l1cfile->sd_id);
2067  check_err(status, __LINE__, __FILE__);
2068 
2069  if (l1cstr->senazpix_3d)
2070  free2d_float(l1cstr->senazpix_3d);
2071  if (l1cstr->latpix_3d)
2072  free2d_float(l1cstr->latpix_3d);
2073  if (l1cstr->lonpix_3d)
2074  free2d_float(l1cstr->lonpix_3d);
2075  if (l1cstr->latpix2_3d)
2076  free2d_float(l1cstr->latpix2_3d);
2077  if (l1cstr->lonpix2_3d)
2078  free2d_float(l1cstr->lonpix2_3d);
2079 
2080  if (I_lambdas)
2081  free(I_lambdas);
2082  if (pol_lambdas)
2083  free(pol_lambdas);
2084 
2085  if (l1cstr->I)
2086  free2d_float(l1cstr->I);
2087  if (l1cstr->I_polsample)
2088  free2d_float(l1cstr->I_polsample);
2089 
2090  l1cstr->latpix = nullptr;
2091  l1cstr->latpix2 = nullptr;
2092  l1cstr->lonpix = nullptr;
2093  l1cstr->lonpix2 = nullptr;
2094 
2095  l1cstr->I = nullptr;
2096  l1cstr->I_polsample = nullptr;
2097 
2098  return 0;
2099 }
2100 
2101 int32_t l1c_str::closel1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file) {
2102  string str;
2103 
2104  str = l1cfile->l1b_name;
2105  printf("Closing harp2 l1b file\n");
2106  cout << str << endl;
2107  status = nc_close(l1cfile->sd_id);
2108  check_err(status, __LINE__, __FILE__);
2109 
2110  if (l1cstr->senazpix_3d)
2111  free2d_float(l1cstr->senazpix_3d);
2112  if (l1cstr->latpix_3d)
2113  free2d_float(l1cstr->latpix_3d);
2114  if (l1cstr->lonpix_3d)
2115  free2d_float(l1cstr->lonpix_3d);
2116  if (l1cstr->latpix2_3d)
2117  free2d_float(l1cstr->latpix2_3d);
2118  if (l1cstr->lonpix2_3d)
2119  free2d_float(l1cstr->lonpix2_3d);
2120 
2121  if (I_lambdas)
2122  free(I_lambdas);
2123  if (pol_lambdas)
2124  free(pol_lambdas);
2125 
2126  if (l1cstr->I)
2127  free2d_float(l1cstr->I);
2128  if (l1cstr->I_polsample)
2129  free2d_float(l1cstr->I_polsample);
2130 
2131  l1cstr->latpix = nullptr;
2132  l1cstr->latpix2 = nullptr;
2133  l1cstr->lonpix = nullptr;
2134  l1cstr->lonpix2 = nullptr;
2135 
2136  l1cstr->I = nullptr;
2137  l1cstr->I_polsample = nullptr;
2138 
2139  return 0;
2140 }
2141 
2142 } // namespace l1c
virtual int32_t closel1b_harp2_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:2060
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
float ** Lt_blue
Definition: l1c_str.h:68
Utility functions for allocating and freeing three-dimensional arrays of various types.
virtual int32_t openl1b_spex_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:200
int j
Definition: decode_rs.h:73
int status
Definition: l1_czcs_hdf.c:32
void check_err(const int stat, const int line, const char *file)
Definition: nc4utils.c:35
l1c_filehandle * l1cfile
Definition: l1c_str.h:119
virtual int32_t openl1b_ocis_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:722
float ** Lt_SWIR
Definition: l1c_str.h:70
float ** I_polsample
Definition: l1c_str.h:77
std::string l1b_name
virtual int32_t closel1b_oci_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:1920
#define NULL
Definition: decode_rs.h:63
float * lonpix2
Definition: l1c_str.h:102
double * timepix
Definition: l1c_str.h:96
float ** I_lambdas
Definition: l1c_str.h:78
float ** senazpix_3d
Definition: l1c_str.h:107
float ** I
Definition: l1c_str.h:76
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second band
float * red_lambdas
Definition: l1c_str.h:72
void unix2ymds(double usec, int16_t *year, int16_t *mon, int16_t *day, double *secs)
Definition: unix2ymds.c:8
float * latpix
Definition: l1c_str.h:99
virtual int32_t openl1b_oci_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:400
float * senazpix
Definition: l1c_str.h:98
int32 * msec
Definition: l1_czcs_hdf.c:31
double esdist_(int32_t *year, int32_t *day, int32_t *msec)
int syear
Definition: l1_czcs_hdf.c:15
filehandle * l1file
Definition: l1c_str.h:120
int32 nscan
Definition: l1_czcs_hdf.c:19
float * latpix2
Definition: l1c_str.h:101
float * lonpix3
Definition: l1c_str.h:104
@ string
float * lonpix
Definition: l1c_str.h:100
#define M_PI
Definition: dtranbrdf.cpp:19
float * latpix3
Definition: l1c_str.h:103
int sday
Definition: l1_czcs_hdf.c:15
int time_str(short, short, int, char *)
Definition: time_str.c:3
virtual int32_t readl1b_spex_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t recnum)
Definition: l1c_str.cpp:1278
float ** Lt
Definition: l1c_str.h:67
float ** lonpix2_3d
Definition: l1c_str.h:111
size_t iscan
Definition: l1c_str.h:53
Utility functions for allocating and freeing four-dimensional arrays of various types.
#define I
size_t nbands
Definition: l1c_str.h:56
short fillval1
void free2d_float(float **p)
Free a two-dimensional array created by allocate2d_float.
Definition: allocate2d.c:140
@ FT_OCIS
Definition: filetype.h:44
virtual ~l1c_str()
Definition: l1c_str.cpp:180
virtual int32_t closel1b_spex_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:1871
#define FATAL_ERROR
Definition: swl0_parms.h:5
float * senz
Definition: l1c_str.h:83
float * blue_lambdas
Definition: l1c_str.h:71
float fillval2
void unix2yds(double usec, short *year, short *day, double *secs)
size_t nscan
Definition: l1c_str.h:54
float * SWIR_lambdas
Definition: l1c_str.h:73
Definition: l1c.cpp:71
virtual int32_t closel1b_ocis_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:1993
#define RADEG
Definition: czcs_ctl_pt.c:5
float * Fobar
Definition: l1c_str.h:65
Utility functions for allocating and freeing two-dimensional arrays of various types.
@ FT_SPEXONE
Definition: filetype.h:61
virtual int32_t readl1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file, int32_t recnum)
Definition: l1c_str.cpp:1812
virtual int32_t readl1b_harp2_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t recnum)
Definition: l1c_str.cpp:1757
virtual int32_t writel1c_ocis(l1c_str *l1cstr, bin_str *binl1c, netCDF::NcFile *nc_output, float **Ltfrac, float **areafrac, short **obs_view, int band_ix, int view_ix)
Definition: l1c_str.cpp:1340
virtual int32_t openl1b_harp2_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile)
Definition: l1c_str.cpp:1042
float ** latpix2_3d
Definition: l1c_str.h:110
@ FT_HARP2
Definition: filetype.h:62
#define BAD_FLT
Definition: jplaeriallib.h:19
int32 dpix
Definition: l1_czcs_hdf.c:22
int32_t nbands
int32 spix
Definition: l1_czcs_hdf.c:21
int32_t iscan
virtual int32_t readl1b_ocis_3lines(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t recnum)
Definition: l1c_str.cpp:1586
uint8_t * viewport
Definition: l1c_str.h:80
float * tilt
Definition: l1c_str.h:97
int32 epix
Definition: l1_czcs_hdf.c:23
real *8 function esdist(iyr, iday, msec)
Definition: esdist.f:3
short ** allocate2d_short(size_t h, size_t w)
Allocate a two-dimensional array of type short of a given size.
Definition: allocate2d.c:79
float ** allocate2d_float(size_t h, size_t w)
Allocate a two-dimensional array of type float of a given size.
Definition: allocate2d.c:123
double ymds2unix(short year, short month, short day, double secs)
virtual int32_t readl1b_ocis_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, int32_t recnum)
Definition: l1c_str.cpp:1426
float32 * att_ang
Definition: l1_czcs_hdf.c:34
virtual int32_t closel1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file)
Definition: l1c_str.cpp:2101
@ FT_OCIL1B
Definition: filetype.h:43
int i
Definition: decode_rs.h:71
int openl1(filehandle *l1file)
Definition: l1_io.c:230
float ** latpix_3d
Definition: l1c_str.h:108
size_t npix
Definition: l1c_str.h:52
Definition: aerosol.c:136
float ** lonpix_3d
Definition: l1c_str.h:109
int npix
Definition: get_cmp.c:28
size_t nviews
Definition: l1c_str.h:55
float * solz
Definition: l1c_str.h:85
float ** pol_lambdas
Definition: l1c_str.h:79
float * Lt_tot
Definition: l1c_str.h:66
#define str(s)
virtual int32_t openl1b_misr_l1c(l1c_str *l1cstr, l1c_filehandle *l1cfile, filehandle *l1file)
Definition: l1c_str.cpp:183
double isodate2unix(const char *isodate)
Definition: unix2isodate.c:61
float ** Lt_red
Definition: l1c_str.h:69
int count
Definition: decode_rs.h:79