OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
L1B_Tables.c
Go to the documentation of this file.
1 #include "L1B_Tables.h"
2 #include "HDF_Lib.h"
3 #include "PGS_PC.h"
4 #include "PGS_Error_Codes.h"
5 #include "FNames.h"
6 #include "HDF_Lib.h" /* for error messages invalidinputfile
7  and corruptinputfile */
8 #include <math.h>
9 #include <stdlib.h>
10 
11 /***************************************************************************
12 Developer's note: (Jim Rogers)
13 
14 In the functions "Read_..._Tables", there is a return statement after each
15 L1BErrorMsg function call. These are actually not necessary if the last
16 argument to L1BErrorMsg is "True". These returns make it easier to test
17 error out conditions (with SMF_ERROR used in UNIT_TEST_MODE_ONLY -- it does
18 not actually exit).
19 ****************************************************************************/
20 
21 extern int16 RFLAG;
22 
23 static char *invalidlutfile =
24  "This is most likely due to an invalid LUT file.";
25 static PGSt_SMF_status Read_LUT_Tables
26  (L1A_granule_t *L1A_Gran,
27  int32 lun,
29 
30 PGSt_SMF_status Read_Lookup_Tables
31  (L1A_granule_t *L1A_Gran,
33  Run_Time_Parameters_t *runtime_params)
34 /*
35 !C***************************************************************
36 !Description: Read all L1B lookup tables.
37 
38 !Input Parameters:
39  L1A_granule_t *L1A_Gran contains satellite id and
40  EV start time
41  lookup_tables_t *tables
42  Run_Time_Parameters_t *runtime_params contains LUT version for check
43 
44 !Output Parameters:
45  lookup_tables_t *tables
46 
47 !Revision History:
48 
49  Revision 02.20, October 31, 2003 (Razor Issue #195)
50  Delete LUT ProcessingCenter from the QA LUT array.
51  Liqin Tan SAIC/GSO (ltan@saicmodis.com)
52 
53  Revision 02.19 , October 24, 2003 Razor Issue #196 (formerly Issue #184)
54  Added "ROLL_THRESHOLD_LUT_NAME", 'PITCH_THRESHOLD_LUT_NAME', and
55  "YAW_THRESHOLD_LUT_NAME" in the LUT_Definition_t array "qa_luts[]".
56  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
57 
58  Revision 02.18 April 16, 2003
59  Changed lower bound on m1_table LUT values to a small positive epsilon.
60  Since the m1 values are used as divisors to generate the R* LUT values
61  (see revision 02.16), they should never be allowed to be 0.
62  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
63 
64  Revision 02.17 March 26, 2003 Razor Issue #191
65  Added LUT for SWIR OOB correction sending band.
66  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
67 
68  Revision 02.16, Oct 3, 2002 Razor Issue #187
69  Removed R_star from code and LUTs. Added zero divide error checks for m1 and
70  E_sun_over_pi
71  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
72 
73  Revision 02.15, April 23, 2001 Razor Issue #167
74  Changed references to "PDF" to "PCF"
75  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
76 
77  Revision 02.14, March 25, 2001 Razor Issue #178
78  Removed ADC Correction LUTs
79  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
80 
81  Revision 02.13 November 6, 2001 Razor issue #167
82  Added check on MCST Version read from runtime parameters
83  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov), SAIC GSO
84 
85  Revision 02.12 March 5, 2001 Razor issue #156
86  Added new function TDLUT_ReadPiecewiseLinearFunction
87  and appropriate call.
88  Added check on reported vs. actual rank in TDLUT_ReadStepFunction
89  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
90 
91  Revision 02.11 November 17, 1999
92  Added checking that MCST versions are consistent.
93  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
94 
95  Revision 02.10 Apr 1998
96  Removed Malloc_Lookup_Tables().
97  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
98 
99  Revision 02.00 Jan 1998
100  Added the QA component of lookup tables.
101  Zhidong Hao (hao@gscmail.gsfc.nasa.gov)
102 
103  Revision 01.00 Dec 1996
104  Initial development.
105  Zhidong Hao (hao@acrobat.gsfc.nasa.gov)
106 
107 !Team-unique Header:
108 
109 !References and Credits:
110  This software is developed by the MODIS Characterization Support
111  Team (MCST)for the National Aeronautics and Space Administration,
112  Goddard Space Flight Center, under contract NAS5-32373.
113 
114  HDF portions developed at the National Center for Supercomputing
115  Applications at the University of Illinois at Urbana-Champaign.
116 
117 !Design Notes:
118 
119 !END********************************************************************
120 */
121 {
122  PGSt_SMF_status returnStatus = MODIS_S_OK;
123  char *location = "Read_Lookup_Tables";
124 
125  /*
126  * Read tables
127  */
128  returnStatus = Read_Refl_Tables (L1A_Gran, &tables->refl);
129  if (returnStatus != MODIS_S_OK)
130  L1BErrorMsg(location, returnStatus, NULL,
131  "Read_Refl_Tables", 0, NULL, True);
132 
133  returnStatus = Read_Emiss_Tables (L1A_Gran, &tables->emiss);
134  if (returnStatus != MODIS_S_OK)
135  L1BErrorMsg(location, returnStatus, NULL,
136  "Read_Emiss_Tables", 0, NULL, True);
137 
138  returnStatus = Read_QA_Tables (L1A_Gran, &tables->QA);
139  if (returnStatus != MODIS_S_OK)
140  L1BErrorMsg(location, returnStatus, NULL,
141  "Read_QA_Tables", 0, NULL, True);
142 
143 #ifndef NOCHECKLUT
144  /*
145  * The table value of PGE version has already been checked against the
146  * code macro PGE02_VERSION. Each LUT file also contains the MCST
147  * version. Check that these are all the same.
148  */
149 
150  if (strcmp(tables->refl.MCST_Version,
151  tables->QA.common_QA_tables.MCST_Version))
152  {
153  returnStatus = MODIS_F_OUT_OF_RANGE;
154  L1BErrorMsg(location, returnStatus,
155  "MCST version in reflective LUT file does "
156  "not match that in QA LUT file.",
157  NULL, 0,
158  "LUT files are invalid. All must have the "
159  "same MCST version.",
160  True);
161  return returnStatus;
162  }
163  if (strcmp(tables->emiss.MCST_Version,
164  tables->QA.common_QA_tables.MCST_Version))
165  {
166  returnStatus = MODIS_F_OUT_OF_RANGE;
167  L1BErrorMsg(location, returnStatus,
168  "MCST version in emissive LUT file does not "
169  "match that in QA LUT file.",
170  NULL, 0,
171  "LUT files are invalid. All must have the "
172  "same MCST version.",
173  True);
174  return returnStatus;
175  }
176 
177  /*
178  * The MCST versions of the LUTs are identical; now check the MCST version
179  * against the MCST version given in the PCF file.
180  */
181 
182  if (strcmp(runtime_params->MCST_LUT_Version,
183  tables->QA.common_QA_tables.MCST_Version))
184  {
185  returnStatus = MODIS_F_OUT_OF_RANGE;
186  L1BErrorMsg(location, returnStatus,
187  "MCST version in PCF file does not match that in LUT files.",
188  NULL, 0,
189  "LUT files must have the same MCST version as "
190  "specified in the PCF file.",
191  True);
192  return returnStatus;
193  }
194 #endif
195 
196  return(MODIS_S_OK);
197 }
198 
199 /********************* MACRO ASSIGN_DATA_PTR ********************************
200 This macro assigns the dataptr to the luts[i].data member.
201 This macro is used in Read_Refl_Tables, Read_Emiss_Tables and Read_QA_Tables.
202 There should be the following local variables in those functions:
203  i (loop counter)
204  lun (assigned to be the logical unit number)
205 Macro variables:
206  luts (array of luts, either refl_luts, emiss_luts or qa_luts)
207  lutname (name of particular LUT)
208  dataptr (structure member to be assigned.)
209 ****************************************************************************/
210 
211 #define ASSIGN_DATA_PTR(luts,lutname,dataptr) \
212  i = 0; \
213  while (luts[i].name) \
214  { \
215  if (!strcmp(lutname,luts[i].name)) \
216  break; \
217  i++; \
218  } \
219  if (!luts[i].name) \
220  { \
221  char errmsg[512]; \
222  sprintf(errmsg, "LUT name %s not found in LUTs array.", lutname); \
223  returnStatus = MODIS_F_NOK; \
224  L1BErrorMsg(location, returnStatus, errmsg, NULL, \
225  lun, "*** CODE BUG ***", True); \
226  return returnStatus; \
227  } \
228  luts[i].data = (VOIDP) dataptr;
229 
230 
231 PGSt_SMF_status Read_Refl_Tables (L1A_granule_t *L1A_Gran,
233 /*
234 !C***************************************************************
235 !Description: Read all reflective lookup tables.
236 
237 !Input Parameters:
238  L1A_granule_t *L1A_Gran contains satellite id and
239  EV start time
240  refl_tables_t *tables address of empty tables
241 
242 !Output Parameters:
243  refl_tables_t *tables address of filled tables
244 
245 !Revision History:
246  $Log: L1B_Tables.c,v $
247  Revision 1.41 2017-03-02 12:55:07-05 xgeng
248  Added uncertainty penalty to PV LWIR band
249 
250  Revision 1.38 2016-07-22 13:23:31-04 xgeng
251  Applied xtalk correction to Terra LWIR PV bands (27-30)
252 
253  Revision 1.37 2011-04-07 14:42:40-04 xgeng
254  1. RSB &TEB uncertainty algorithm update; 2. The quadratic RSB RVS changed to 4th order.
255 
256  Revision 1.35 2008-12-16 16:37:12-05 xgeng
257  Extended rvs ascii lut validation limitation
258 
259  Revision 1.33 2008/11/18 19:41:07 xgeng
260  merge branch for V6.0.0
261 
262  Revision 1.32.2.2 2008/06/05 14:07:43 xgeng
263  1.Added a new table piece "DET_QUAL_FLAG2_VALS_LUT_NAME" into the LUT_Definition_t array "qa_luts[]". 2.Added the calculation of Detector_Quality_Flag2. 3.Generated noisy and dead subframe list.
264 
265  Revision 1.32 2005/01/18 19:34:46 ltan
266  MOD_PR02_TERRA update to V5.0.4
267 
268 
269  Revision 02.42 October 15, 2004 Razor Issue #199
270  Added "swir_oob_sending_detector_table" to the Reflective LUTs.
271  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
272 
273  Revision 02.41 March 26, 2003 Razor Issue #191
274  Check range of sending band to use for SWIR OOB correction
275  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
276 
277  Revision 02.40 October 21, 2002
278  Remove incorrect "&" in data pointer assignment
279  of B26_B5_Frame_Offset.
280  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
281 
282  Revision 02.39 June 28, 2002 Razor Issue #161
283  Handle BDSM LUTs without fill values.
284  Gwyn Fireman, SAIC-GSO <Gwyn.Fireman@gsfc.nasa.gov>
285 
286  Revision 02.38 June 5, 2002 Razor Issue #183
287  Change type of dn_sat_ev to float64.
288  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
289 
290  Revision 02.37, March 25, 2001 Razor Issue #178
291  Removed ADC Correction LUTs
292  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
293 
294  Revision 02.36 March 15, 2002 Razor Issue #182
295  Applicable to MODIS/TERRA (PFM) processing only.
296  Added LUTs "B26_B5_Corr_Terra", "B26_B5_Corr_Switch_Terra",
297  "B26_B5_Frame_Offset_Terra"
298  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
299 
300  Revision 02.35, March 8, 2002 Razor Issue #174
301  Removed LUTs "RVS_250m", "RVS_500m", "RVS_1km_RefSB"
302  Added LUT "RVS_RefSB"
303  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
304 
305  Revision 02.34, March 26, 2001
306  Added new LUT dn_sat_ev and removed LUT DN_sat
307  Alice Isaacman, SAIC GSC (Alice.R.Isaacman.1@gsfc.nasa.gov)
308 
309  Revision 02.31, December 22, 1999
310  Redid the tables array to make it work for LUT generation also.
311  Added Read_LUT_Tables to avoid a lot of code duplication.
312  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
313 
314  Revision 02.30, November 17, 1999
315  Completely revised methodology of reading in tables. Using a loop to
316  allow for better error messages and for valid range checking (if enabled).
317  Checks for PGE version consistency also added.
318  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
319 
320  Revision 02.12 Sept. 03, 1999
321  Replaced all old SWIR correction tables with new ones due to the new
322  SWIR correction algorithm.
323  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
324  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
325 
326  Revision 02.11 August 1999
327  Added delta_DN_RSB
328  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
329  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
330 
331  Revision 02.10 Apr. 9, 1998
332  Changed Time_gain_factor to Time_gain_factor_rad
333  and added Time_gain_factor_refl.
334  Added L_SD table read.
335  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
336 
337  Revision 02.10 Apr. 8, 1998
338  Changed the read table calls to the new generalized interfaces.
339  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
340 
341  Revision 02.10 Apr. 2, 1998
342  V2.1 reflective tables added.
343  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
344 
345  Revision 01.00 Nov. 22, 1996
346  Initial development.
347  Zhidong Hao (hao@acrobat.gsfc.nasa.gov)
348 
349 !Team-unique Header:
350 
351 !References and Credits:
352  This software is developed by the MODIS Characterization Support
353  Team (MCST)for the National Aeronautics and Space Administration,
354  Goddard Space Flight Center, under contract NAS5-32373.
355 
356  HDF portions developed at the National Center for Supercomputing
357  Applications at the University of Illinois at Urbana-Champaign.
358 
359 !Design Notes:
360 
361 !END********************************************************************
362 */
363 {
364  PGSt_SMF_status returnStatus = MODIS_S_OK;
365  int16 band, det, sample, mirr_side;
366  int32 i, lun = REFLECTIVE_TABLES_FILE;
367  char *location = "Read_Refl_Tables";
368  SWIR_correction_tables_t *swir_tables = &tables->SWIR_correction_tables;
369 
370  /*
371  * Assign the array pointers to the data member in refl_luts.
372  */
373 
376  tables->PGE_Version);
377 
380  tables->MCST_Version);
381 
384  tables->Serial_Number);
385 
387  M0_LUT_NAME,
388  tables->m0);
389 
391  M1_LUT_NAME,
392  tables->m1);
393 
396  tables->dn_star_Max);
397 
400  tables->dn_star_Min);
401 
404  tables->K_inst);
405 
408  tables->K_FPA);
409 
412  &tables->T_inst_ref);
413 
416  tables->T_FPA_ref);
417 
420  tables->RVS_RefSB);
421 
422  /*
423  * obsolete due to RSB UI algorithm update, 2/19/2011, Xu Geng
424  */
425  /*
426  ASSIGN_DATA_PTR(refl_luts,
427  SIGMA_RVS_RSB_LUT_NAME,
428  tables->Sigma_RVS_RSB);
429 
430  ASSIGN_DATA_PTR(refl_luts,
431  SIGMA_M1_LUT_NAME,
432  tables->Sigma_m1);
433 
434  ASSIGN_DATA_PTR(refl_luts,
435  SIGMA_K_INST_LUT_NAME,
436  tables->Sigma_K_inst);
437 
438  ASSIGN_DATA_PTR(refl_luts,
439  SIGMA_T_INST_LUT_NAME,
440  &tables->Sigma_T_inst);
441 
442  ASSIGN_DATA_PTR(refl_luts,
443  SIGMA_PV_RESID_ELEC_LUT_NAME,
444  tables->Sigma_PV_Resid_Elec);
445 
446  ASSIGN_DATA_PTR(refl_luts,
447  SIGMA_R_STAR_LIN_RESID_UCOEFF_LUT_NAME,
448  tables->Sigma_R_Star_Lin_Resid_Ucoeff);
449 
450  ASSIGN_DATA_PTR(refl_luts,
451  RSB_NEDL_LUT_NAME,
452  tables->RSB_NEdL);
453 
454  ASSIGN_DATA_PTR(refl_luts,
455  SIGMA_RSB_ADC_LUT_NAME,
456  tables->Sigma_RSB_ADC);
457  */
458 
461  &tables->DN_obc_avg_first_frame_to_use);
462 
465  &tables->DN_obc_avg_number_of_frames_to_use);
466 
469  &swir_tables->SWIR_correction_switch);
470 
473  &swir_tables->SWIR_corr_sending_band);
474 
477  &swir_tables->SWIR_corr_sending_detector);
478 
481  swir_tables->X_OOB_0);
482 
485  swir_tables->X_OOB_1);
486 
489  swir_tables->X_OOB_2);
490 
493  tables->RSB_specified_uncertainty);
494 
497  tables->RSB_UI_scaling_factor);
498 
501  tables->E_sun_over_pi);
502 
505  &tables->RSB_SV_DN_moon_include_frames);
506 
509  tables->dn_sat_ev);
510 
513  tables->B26_B5_Corr);
514 
517  &tables->B26_B5_Corr_Switch);
518 
521  tables->B26_B5_Frame_Offset);
522 
524  U1_LUT_NAME,
525  tables->u1);
526 
528  U2_LUT_NAME,
529  tables->u2_samples);
530 
532  U3_LUT_NAME,
533  tables->u3);
534 
536  U4_LUT_NAME,
537  tables->u4_coeffs);
538 
541  tables->u2_frames);
542 
545  tables->swir_ui_factor);
546 
547  /*
548  * Read all tables.
549  */
550 
551  returnStatus = Read_LUT_Tables(L1A_Gran,
553  refl_luts);
554  if (returnStatus != MODIS_S_OK)
555  {
556  L1BErrorMsg(location, returnStatus, NULL,
557  "Read_LUT_Tables", REFLECTIVE_TABLES_FILE,
558  NULL, True);
559  return returnStatus;
560  }
561 
562 
563  /*
564  * Check some quantities that could cause code failures and normalize the
565  * Sigma RVS quantities by the RVS. If full checking has been enabled,
566  * some of these checks may be redundant. However, in operations, we do not
567  * expect to turn on the full checking (that is for LUT generation only).
568  */
569 
570  /* MODIS_BAND20_INDEX = 21 NUM_BANDS = 38 MODIS_BAND26_INDEX = 27 */
571 
572  if (swir_tables->SWIR_corr_sending_band < MODIS_BAND20_INDEX - 1 ||
573  swir_tables->SWIR_corr_sending_band > NUM_BANDS - 1 ||
574  swir_tables->SWIR_corr_sending_band == MODIS_BAND26_INDEX - 1)
575  {
576  returnStatus = MODIS_F_OUT_OF_RANGE;
577  L1BErrorMsg(location, returnStatus,
578  "Band to use for SWIR OOB Correction is out of range.",
579  NULL, REFLECTIVE_TABLES_FILE, invalidlutfile, True);
580  return returnStatus;
581  }
582 
583  if (tables->DN_obc_avg_first_frame_to_use < 0 ||
584  tables->DN_obc_avg_first_frame_to_use >= MAX_1KM_OBC_FRAME_DIM)
585  {
586  returnStatus = MODIS_F_OUT_OF_RANGE;
587  L1BErrorMsg(location, returnStatus,
588  "DN_OBC first frame to use is out of range.",
589  NULL, REFLECTIVE_TABLES_FILE, invalidlutfile, True);
590  return returnStatus;
591  }
592 
593  if (tables->DN_obc_avg_number_of_frames_to_use <= 0 ||
594  (tables->DN_obc_avg_first_frame_to_use +
595  tables->DN_obc_avg_number_of_frames_to_use) > MAX_1KM_OBC_FRAME_DIM)
596  {
597  returnStatus = MODIS_F_OUT_OF_RANGE;
598  L1BErrorMsg(location, returnStatus,
599  "DN_OBC number of frames to use is out of range "
600  "or is inconsistent\n"
601  "with the value of DN_OBC first frame to use.",
602  NULL, REFLECTIVE_TABLES_FILE, invalidlutfile, True);
603  return returnStatus;
604  }
605 
606  /* Ensure that m1 isn't zero (divide by m1 occurs in code) */
607  for ( band = 0; band < NUM_REFLECTIVE_BANDS; band++ )
608  for ( det = 0; det < MAX_DETECTORS_PER_BAND; det++ )
609  for ( sample = 0; sample < MAX_SAMPLES_PER_BAND; sample++ )
610  for ( mirr_side = 0; mirr_side < NUM_MIRROR_SIDES; mirr_side++ )
611  if ( fabs((double) tables->m1[band][det][sample][mirr_side])
612  < TOLERANCE )
613  {
614  returnStatus = MODIS_F_OUT_OF_RANGE;
615  L1BErrorMsg(location, returnStatus,
616  "Bad m1 LUT (Zero values detected).",
617  NULL, REFLECTIVE_TABLES_FILE, invalidlutfile, True);
618  return returnStatus;
619  }
620 
621  /* Ensure that E_sun_over_pi isn't zero (divide by E_sun_over_pi occurs in code) */
622  for ( det = 0; det < NUM_REFLECTIVE_DETECTORS; det++ )
623  if ( fabs((double) tables->E_sun_over_pi[det])
624  < TOLERANCE )
625  {
626  returnStatus = MODIS_F_OUT_OF_RANGE;
627  L1BErrorMsg(location, returnStatus,
628  "Bad E_sun_over_pi LUT (Zero values detected).",
629  NULL, REFLECTIVE_TABLES_FILE, invalidlutfile, True);
630  return returnStatus;
631  }
632 
633  /*
634  * Check if the LUT RSB_specified_uncertainty has zero or negative values.
635  * The values should be all positive.
636  */
637 
638  for (band = 0; band < NUM_REFLECTIVE_BANDS; band++)
639  if (tables->RSB_specified_uncertainty[band] <= TOLERANCE)
640  {
641  returnStatus = MODIS_F_OUT_OF_RANGE;
642  L1BErrorMsg(location, returnStatus,
643  "Bad RSB_specified_uncertainty LUT "
644  "(Zero or negative values detected).",
646  return returnStatus;
647  }
648 
649  /* If no 250m bands then use rescaling */
650  if ((RFLAG & 1) == 1) {
651  tables->dn_star_Max[0] = 32767;
652  tables->dn_star_Max[1] = 32767;
653  }
654 
655  /* If no 500m bands then use rescaling */
656  if ((RFLAG & 2) == 2) {
657  tables->dn_star_Max[2] = 32767;
658  tables->dn_star_Max[3] = 32767;
659  }
660 
661  return(MODIS_S_OK);
662 }
663 
664 PGSt_SMF_status Read_Emiss_Tables (L1A_granule_t *L1A_Gran,
666 /*
667 !C***************************************************************
668 !Description: Read in all Emissive lookup tables.
669 
670 !Input Parameters:
671  L1A_granule_t *L1A_Gran contains satellite id and
672  EV start time
673  emiss_tables_t *tables address of set of empty tables
674 
675 !Output Parameters:
676  emiss_tables_t *tables address of set of filled tables
677 
678 !Revision History:
679  Revision 02.36, October 15, 2004 Razor Issue #201
680  Added the new dimension of Mirror Side to the LUT definition of band_21_b1
681  for Emissive LUTs.
682  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
683 
684  Revision 02.35, March 8, 2002
685  Removed LUTs "RVS_1km_Emiss_SV", "RVS_1km_Emiss_BB", "RVS_1km_Emiss_EV"
686  Added LUTs "RVS_TEB", "RVS_BB_SV_Frame_No"
687  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
688 
689  Revision 02.31, December 22, 1999
690  Redid the tables array to make it work for LUT generation also.
691  Added Read_LUT_Tables to avoid a lot of code duplication.
692  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
693 
694  Revision 02.30, November 17, 1999
695  Completely revised methodology of reading in tables. Using a loop to
696  allow for better error messages and for valid range checking (if enabled).
697  Checks for PGE version consistency also added.
698  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
699 
700  Revision 02.18 August 1999
701  Removed LUT INT_correction_switch.
702  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
703 
704  Revision 02.17 August 1999
705  Added delta_DN_TEB
706  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
707  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
708 
709  Revision 02.16 August 12, 1999
710  Added L_Max, L_Min Luts
711  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
712 
713  Revision 02.15 April 12, 1999
714  Removed cubic term a3
715  Zhenying Gu(zgu@mcst.gsfc.nasa.gov)
716 
717  Revision 02.10 Mar. 1998
718  Replaced the V2.0 tables by V2.1 tables input
719  Shi-Yue Qiu (syqiu@ltpmail.gsfc.nasa.gov)
720 
721  Revision 01.00 Nov. 1996
722  Initial development.
723  Zhidong Hao (hao@acrobat.gsfc.nasa.gov)
724 
725 !Team-unique Header:
726 
727 !References and Credits:
728  This software is developed by the MODIS Characterization Support
729  Team (MCST)for the National Aeronautics and Space Administration,
730  Goddard Space Flight Center, under contract NAS5-32373.
731 
732  HDF portions developed at the National Center for Supercomputing
733  Applications at the University of Illinois at Urbana-Champaign.
734 
735 !Design Notes:
736 
737 !END********************************************************************
738 */
739 {
740  PGSt_SMF_status returnStatus = MODIS_S_OK;
741  int32 i, j, band, lun = EMISSIVE_TABLES_FILE;
742  char *location = "Read_Emiss_Tables";
743 
744  /*
745  * Assign the array pointers to the data member in emiss_luts.
746  */
747 
748 
751  tables->PGE_Version);
752 
755  tables->MCST_Version);
756 
759  tables->Serial_Number);
760 
763  tables->epsilon_bb);
764 
767  tables->epsilon_cav);
768 
771  tables->delta_T_bb_beta);
772 
775  tables->delta_T_bb_delta);
776 
779  tables->PC_XT);
780 
783  tables->RVS_TEB);
784 
787  tables->RVS_BB_SV_Frame_No);
788 
790  RSR_LUT_NAME,
791  tables->RSR);
792 
795  tables->wavelength);
796 
799  tables->NUM_RSR_vs_Lambda);
800 
803  tables->A0);
804 
807  tables->A2);
808 
809  /*
810  * obsolete due to TEB UI algorithm update, 3/22/2011, Xu Geng
811  */
812  /*
813  ASSIGN_DATA_PTR(emiss_luts,
814  UI_UCOEFF_LUT_NAME,
815  tables->Ucoeff);
816 
817  ASSIGN_DATA_PTR(emiss_luts,
818  SIGMA_TEB_PV_RESID_ELEC_LUT_NAME,
819  tables->Sigma_TEB_PV_resid_elec);
820 
821  ASSIGN_DATA_PTR(emiss_luts,
822  SIGMA_TEB_ADC_LUT_NAME,
823  tables->Sigma_TEB_ADC);
824 
825  ASSIGN_DATA_PTR(emiss_luts,
826  UCOEFF_CALIBR_RESID_LUT_NAME,
827  tables->Ucoeff_Calibr_resid);
828 
829  ASSIGN_DATA_PTR(emiss_luts,
830  BAND_21_UNCERT_LSAT_LUT_NAME,
831  &tables->Band_21_Uncert_Lsat);
832  */
833 
836  tables->T_ins_function_flag);
837 
840  &tables->T_ins_default);
841 
844  tables->T_ins_offset);
845 
848  tables->T_cav_function_flag);
849 
852  &tables->T_cav_default);
853 
856  tables->T_mir_function_flag);
857 
860  &tables->T_mir_default);
861 
864  tables->BB_Weight);
865 
868  &tables->BB_DN_first_frame_to_use);
869 
872  &tables->BB_DN_number_of_frames_to_use);
873 
876  &tables->SV_DN_first_frame_to_use);
877 
880  &tables->SV_DN_number_of_frames_to_use);
881 
884  &tables->SV_DN_moon_include_frames);
885 
888  &tables->PCX_correction_switch);
889 
892  &tables->num_overlap_scans_b1);
893 
896  tables->Band_21_b1);
897 
900  tables->L_Min);
901 
904  tables->L_Max);
905 
908  tables->TEB_specified_uncertainty);
909 
912  tables->TEB_UI_scaling_factor);
913 
916  tables->sigma_a0);
917 
920  tables->sigma_a2);
921 
924  tables->sigma_RVS_EV);
925 
928  tables->sigma_epsilon_BB);
929 
932  tables->sigma_epsilon_CAV);
933 
936  tables->sigma_L_lambda);
937 
940  tables->sigma_L_Tbb);
941 
944  tables->sigma_L_Tsm);
945 
948  tables->sigma_L_Tcav);
949 
952  tables->sigma_b1_B21);
953 
956  tables->xt_ui_factor);
957 
960  tables->PVLW_XT_coeff);
961 
962  /*
963  * Read all tables.
964  */
965 
966  returnStatus = Read_LUT_Tables(L1A_Gran,
968  emiss_luts);
969  if (returnStatus != MODIS_S_OK)
970  {
971  L1BErrorMsg(location, returnStatus, NULL,
972  "Read_LUT_Tables", EMISSIVE_TABLES_FILE, NULL, True);
973  return returnStatus;
974  }
975 
976 
977  /*
978  * Check some quantities that could cause code failures. If full
979  * checking has been enabled, some of these checks may be
980  * redundant. In operations, we do not expect to turn on the full
981  * checking (that is for LUT generation only).
982  *
983  */
984 
985  /*
986  * BAND30 is the index of band 31 if band 26 is not included.
987  */
988 
989  for (i = 0; i < 2; i++)
990  {
991  if (tables->RVS_BB_SV_Frame_No[i] < 0 ||
992  tables->RVS_BB_SV_Frame_No[i] >= EV_1km_FRAMES)
993  {
994  returnStatus = MODIS_F_OUT_OF_RANGE;
995  L1BErrorMsg(location, returnStatus,
996  "Value(s) of Frame to use for BB or SV RVS "
997  " correction is out of range.",
998  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
999  return returnStatus;
1000  }
1001  }
1002 
1003 
1004  /*
1005  * Check that each wavelength is positive (this could be done in a call to
1006  * Check_Valid_Range if the dead elements had a non-zero fill value).
1007  */
1008 
1009  for (i = 0; i < NUM_EMISSIVE_DETECTORS; i++)
1010  {
1011  for (j = 0; j < tables->NUM_RSR_vs_Lambda[i]; j++)
1012  {
1013  if (tables->wavelength[i][j] < TOLERANCE)
1014  {
1015  returnStatus = MODIS_F_OUT_OF_RANGE;
1016  L1BErrorMsg(location, returnStatus,
1017  "Value(s) of input RSR wavelength are zero.",
1018  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
1019  return returnStatus;
1020  }
1021  }
1022  }
1023 
1024  /*
1025  * Check the consistency of the BB and SV number of frames to use with the
1026  * first frame to use.
1027  */
1028 
1029  if (tables->BB_DN_first_frame_to_use < 0 ||
1030  tables->BB_DN_first_frame_to_use >= MAX_1KM_OBC_FRAME_DIM)
1031  {
1032  returnStatus = MODIS_F_OUT_OF_RANGE;
1033  L1BErrorMsg(location, returnStatus,
1034  "BB DN first frame to use is out of range.",
1035  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
1036  return returnStatus;
1037  }
1038 
1039  if (tables->BB_DN_number_of_frames_to_use <= 0 ||
1040  (tables->BB_DN_first_frame_to_use +
1041  tables->BB_DN_number_of_frames_to_use) > MAX_1KM_OBC_FRAME_DIM)
1042  {
1043  returnStatus = MODIS_F_OUT_OF_RANGE;
1044  L1BErrorMsg(location, returnStatus,
1045  "BB DN number of frames to use is out of "
1046  "range or is inconsistent\n"
1047  "with the value of DN_OBC first frame to use.",
1048  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
1049  return returnStatus;
1050  }
1051 
1052  if (tables->SV_DN_first_frame_to_use < 0 ||
1053  tables->SV_DN_first_frame_to_use >= MAX_1KM_OBC_FRAME_DIM)
1054  {
1055  returnStatus = MODIS_F_OUT_OF_RANGE;
1056  L1BErrorMsg(location, returnStatus,
1057  "SV DN first frame to use is out of range.",
1058  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
1059  return returnStatus;
1060  }
1061 
1062  if (tables->SV_DN_number_of_frames_to_use <= 0 ||
1063  (tables->SV_DN_first_frame_to_use +
1064  tables->SV_DN_number_of_frames_to_use) > MAX_1KM_OBC_FRAME_DIM)
1065  {
1066  returnStatus = MODIS_F_OUT_OF_RANGE;
1067  L1BErrorMsg(location, returnStatus,
1068  "SV DN number of frames to use is out of range or "
1069  "is inconsistent\n"
1070  "with the value of DN_OBC first frame to use.",
1071  NULL, EMISSIVE_TABLES_FILE, invalidlutfile, True);
1072  return returnStatus;
1073  }
1074 
1075  /*
1076  * Check if the LUT TEB_specified_uncertainty has zero or negative values.
1077  * The values should be all positive.
1078  */
1079 
1080  for (band = 0; band < NUM_EMISSIVE_BANDS; band++)
1081  if (tables->TEB_specified_uncertainty[band] <= TOLERANCE)
1082  {
1083  returnStatus = MODIS_F_OUT_OF_RANGE;
1084  L1BErrorMsg(location, returnStatus,
1085  "Bad TEB_specified_uncertainty LUT (Zero "
1086  "or negative values detected).",
1088  return returnStatus;
1089  }
1090 
1091  return(MODIS_S_OK);
1092 }
1093 
1094 
1095 PGSt_SMF_status Read_QA_Tables (L1A_granule_t *L1A_Gran,
1096  QA_tables_t *QA_tables)
1097 /*
1098 !C***************************************************************
1099 !Description: Read in all QA lookup tables in this module.
1100 
1101 !Input Parameters:
1102  L1A_granule_t *L1A_Gran contains satellite id and
1103  EV start time
1104 
1105 !Output Parameters:
1106  QA_tables_t *QA_tables Holds all QA tables.
1107 
1108 !Revision History:
1109  Revision 02.32, October 29, 2000
1110  Add LUT "Control Parameters", Razor issue 142.
1111  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
1112 
1113  Revision 02.31, December 22, 1999
1114  Redid the tables array to make it work for LUT generation also.
1115  Added Read_LUT_Tables to avoid a lot of code duplication.
1116  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
1117 
1118  Revision 02.30, November 17, 1999
1119  Completely revised methodology of reading in tables. Using a loop to
1120  allow for better error messages and for valid range checking (if enabled).
1121  Checks for PGE version consistency also added.
1122  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
1123 
1124  Revision 02.10 Mar 1998
1125  Included all QA tables
1126  Shi-Yue Qiu (syqiu@ltpmail.gsfc.nasa.gov)
1127 
1128  Revision 01.00 Jan 1998
1129  Initial development.
1130  Zhidong Hao (hao@gscmail.gsfc.nasa.gov)
1131 
1132 !Team-unique Header:
1133  This software is developed by the MODIS Characterization Support
1134  Team (MCST)for the National Aeronautics and Space Administration,
1135  Goddard Space Flight Center, under contract NAS5-32373.
1136 
1137 !References and Credits:
1138  HDF portions developed at the National Center for Supercomputing
1139  Applications at the University of Illinois at Urbana-Champaign.
1140 
1141 !Design Notes:
1142 
1143 !END********************************************************************
1144 */
1145 {
1146  PGSt_SMF_status returnStatus = MODIS_S_OK;
1147  int32 i, j, lun = QA_TABLES_FILE;
1148  int16 D_490, R, B, D, S_520, subsamp;
1149  int8 mask;
1150  char *location = "Read_QA_Tables";
1151 
1152  common_QA_tables_t *common_QA_LUT = &QA_tables->common_QA_tables;
1153  refl_QA_tables_t *refl_QA_LUT = &QA_tables->refl_QA_tables;
1154  emiss_QA_tables_t *emiss_QA_LUT = &QA_tables->emiss_QA_tables;
1155 
1156  /*
1157  * Assign the array pointers to the data member in qa_luts.
1158  */
1159 
1162  common_QA_LUT->PGE_Version);
1163 
1166  common_QA_LUT->MCST_Version);
1167 
1170  common_QA_LUT->Serial_Number);
1171 
1174  common_QA_LUT->AssociatedPlatformShortname);
1175 
1178  common_QA_LUT->AlgorithmPackageAcceptanceDate);
1179 
1182  common_QA_LUT->AlgorithmPackageMaturityCode);
1183 
1186  common_QA_LUT->Detector_Quality_Flag_Values);
1187 
1190  common_QA_LUT->Detector_Quality_Flag2_Values);
1191 
1194  common_QA_LUT->moon_offset_limits);
1195 
1198  common_QA_LUT->mission_phase);
1199 
1202  common_QA_LUT->control_options);
1203 
1206  &refl_QA_LUT->var_visual_FPA);
1207 
1210  &refl_QA_LUT->var_NIR_FPA);
1211 
1214  emiss_QA_LUT->var_T_bb);
1215 
1218  &emiss_QA_LUT->var_T_bb_avg);
1219 
1222  &emiss_QA_LUT->var_T_lwir);
1223 
1226  &emiss_QA_LUT->var_T_mwir);
1227 
1230  &emiss_QA_LUT->var_T_mir1);
1231 
1234  &emiss_QA_LUT->var_T_mir2);
1235 
1238  &emiss_QA_LUT->var_T_mir_avg);
1239 
1242  &emiss_QA_LUT->var_T_ins);
1243 
1246  &emiss_QA_LUT->var_T_cav);
1247 
1250  emiss_QA_LUT->NEdL);
1251 
1254  emiss_QA_LUT->a1);
1255 
1258  &common_QA_LUT->roll_threshold_angle);
1259 
1262  &common_QA_LUT->pitch_threshold_angle);
1263 
1266  &common_QA_LUT->yaw_threshold_angle);
1267 
1268  /*
1269  * Read all tables.
1270  */
1271 
1272  returnStatus = Read_LUT_Tables(L1A_Gran,
1273  QA_TABLES_FILE,
1274  qa_luts);
1275  if (returnStatus != MODIS_S_OK)
1276  {
1277  L1BErrorMsg(location, returnStatus, NULL,
1278  "Read_LUT_Tables", QA_TABLES_FILE, NULL, True);
1279  return returnStatus;
1280  }
1281 
1282 
1283 /*
1284  * Calculate Detector_Quality_Flag and Determine Dead Detector List
1285  * and Noisy Detector List. The LUT "Detector Quality Flag Values"
1286  * contains the array used to fill the L1B global attribute
1287  * "Detector Quality Flag". Each array element of this LUT (having
1288  * a value of 0 or 1) sets one bit of the corresponding L1B
1289  * attribute. The second dimension of this LUT cycles through the 8
1290  * bits of each word of the attribute, with array element [w][0]
1291  * corresponding to the least significant bit w and array element
1292  * [w][7] corresponding to the most significant bit. The global
1293  * attributes Dead Detector List and Noisy Detector List used to be
1294  * implemented from LUTs. These two attributes don't provide enough
1295  * information for detector behavior and are superseded by Detector
1296  * Quality Flag. For backward compatibility, they are retained. The
1297  * array element [w][0] of the LUT "Detector Quality Flag Values" is
1298  * noisy detector flag for detector w and [w][1] is the dead
1299  * detector flag for detector w.
1300  */
1301 
1302 
1303  for (i = 0; i < NUM_DETECTORS; i++)
1304  {
1305  mask = 1;
1306  common_QA_LUT->Detector_Quality_Flag[i] = 0;
1307  for (j = 0; j < NUM_BITS_IN_UINT8; j++)
1308  {
1309  if (common_QA_LUT->Detector_Quality_Flag_Values[i][j] == 1)
1310  common_QA_LUT->Detector_Quality_Flag[i] |= mask;
1311 
1312  mask = mask << 1;
1313  }
1314 
1315  common_QA_LUT->noisy_detector[i] =
1316  common_QA_LUT->Detector_Quality_Flag_Values[i][0];
1317  common_QA_LUT->dead_detector[i] =
1318  common_QA_LUT->Detector_Quality_Flag_Values[i][1];
1319  }
1320 
1321 /*
1322  * Calculate Detector_Quality_Flag2.
1323  * The LUT "Detector Quality Flag2 Values" contains the array
1324  * used to fill the L1B global attribute "Detector Quality Flag2".
1325  * Each array element of this LUT (having a value of 0 or 1)
1326  * sets one bit of the corresponding L1B attribute. The second
1327  * dimension of this LUT cycles through the 8 bits of each word
1328  * of the attribute, with array element [w][0] corresponding to
1329  * the least significant bit w and array element [w][7]
1330  * corresponding to the most significant bit.
1331  * The element [w][0] of the LUT "Detector Quality Flag2 Values"
1332  * is for subframe 1 and [w][3] is for subframe 4 for detector w.
1333  * bits 0 to 3 are used for noisy subframes, and bits 4 to 7 are
1334  * used for dead subframes. Only 250m and 500m bands are considered.
1335  */
1336 
1337  D_490 = 0;
1338  S_520 = 0;
1339  for (R = 0; R <= INDEX_500M; R++)
1340  {
1341  for (B = 0; B < L1A_BANDS_AT_RES[R]; B++)
1342  {
1343  for (D = 0; D < DETECT_PER_BAND_AT_RES[R]; D++, D_490++)
1344  {
1345  mask = 1;
1346  common_QA_LUT->Detector_Quality_Flag2[D_490] = 0;
1347  for (j = 0; j < NUM_BITS_IN_UINT8; j++)
1348  {
1349  if (common_QA_LUT->Detector_Quality_Flag2_Values[D_490][j] == 1)
1350  common_QA_LUT->Detector_Quality_Flag2[D_490] |= mask;
1351 
1352  mask = mask << 1;
1353  }
1354  /*generate noisy and dead subbframe list*/
1356  for (subsamp = 0; subsamp < i; subsamp++, S_520++)
1357  {
1358  common_QA_LUT->noisy_subframe[S_520] =
1359  common_QA_LUT->Detector_Quality_Flag2_Values[D_490][subsamp];
1360  common_QA_LUT->dead_subframe[S_520] =
1361  common_QA_LUT->Detector_Quality_Flag2_Values[D_490][subsamp+4];
1362  }
1363  }
1364  }
1365  }
1366 
1367  /*----------------------------------------------------------------------------
1368  Note: all the Emissive QA lookup table value should not be zero, because
1369  they will be divided by the calculated values in the production code.
1370  Physically, all these values should be positive.
1371  -----------------------------------------------------------------------------*/
1372  for (i = 0; i < 12; i++)
1373  if ( emiss_QA_LUT->var_T_bb[i] < TOLERANCE )
1374  {
1375  returnStatus = MODIS_F_OUT_OF_RANGE;
1376  L1BErrorMsg(location, returnStatus,
1377  "Table \"var_T_bb\" is zero or negative.",
1378  NULL, QA_TABLES_FILE, invalidlutfile, True);
1379  return returnStatus;
1380  }
1381 
1382  if ( emiss_QA_LUT->var_T_bb_avg < TOLERANCE )
1383  {
1384  returnStatus = MODIS_F_OUT_OF_RANGE;
1385  L1BErrorMsg(location, returnStatus,
1386  "Table \"var_T_bb_avg\" is zero or negative.",
1387  NULL, QA_TABLES_FILE, invalidlutfile, True);
1388  return returnStatus;
1389  }
1390  if ( emiss_QA_LUT->var_T_lwir < TOLERANCE )
1391  {
1392  returnStatus = MODIS_F_OUT_OF_RANGE;
1393  L1BErrorMsg(location, returnStatus,
1394  "Table \"var_T_lwir\" is zero or negative.",
1395  NULL, QA_TABLES_FILE, invalidlutfile, True);
1396  return returnStatus;
1397  }
1398 
1399  if ( emiss_QA_LUT->var_T_mwir < TOLERANCE )
1400  {
1401  returnStatus = MODIS_F_OUT_OF_RANGE;
1402  L1BErrorMsg(location, returnStatus,
1403  "Table \"var_T_mwir\" is zero or negative.",
1404  NULL, QA_TABLES_FILE, invalidlutfile, True);
1405  return returnStatus;
1406  }
1407 
1408  if ( emiss_QA_LUT->var_T_mir1 < TOLERANCE )
1409  {
1410  returnStatus = MODIS_F_OUT_OF_RANGE;
1411  L1BErrorMsg(location, returnStatus,
1412  "Table \"var_T_mir1\" is zero or negative.",
1413  NULL, QA_TABLES_FILE, invalidlutfile, True);
1414  return returnStatus;
1415  }
1416 
1417  if ( emiss_QA_LUT->var_T_mir2 < TOLERANCE )
1418  {
1419  returnStatus = MODIS_F_OUT_OF_RANGE;
1420  L1BErrorMsg(location, returnStatus,
1421  "Table \"var_T_mir2\" is zero or negative.",
1422  NULL, QA_TABLES_FILE, invalidlutfile, True);
1423  return returnStatus;
1424  }
1425 
1426  if ( emiss_QA_LUT->var_T_mir_avg < TOLERANCE )
1427  {
1428  returnStatus = MODIS_F_OUT_OF_RANGE;
1429  L1BErrorMsg(location, returnStatus,
1430  "Table \"var_T_mir_avg\" is zero or negative.",
1431  NULL, QA_TABLES_FILE, invalidlutfile, True);
1432  return returnStatus;
1433  }
1434 
1435  if ( emiss_QA_LUT->var_T_ins < TOLERANCE )
1436  {
1437  returnStatus = MODIS_F_OUT_OF_RANGE;
1438  L1BErrorMsg(location, returnStatus,
1439  "Table \"var_T_ins\" is zero or negative.",
1440  NULL, QA_TABLES_FILE, invalidlutfile, True);
1441  return returnStatus;
1442  }
1443 
1444  if ( emiss_QA_LUT->var_T_cav < TOLERANCE )
1445  {
1446  returnStatus = MODIS_F_OUT_OF_RANGE;
1447  L1BErrorMsg(location, returnStatus,
1448  "Table \"var_T_cav\" is zero or negative.",
1449  NULL, QA_TABLES_FILE, invalidlutfile, True);
1450  return returnStatus;
1451  }
1452 
1453  for (i = 0; i < NUM_EMISSIVE_DETECTORS; i++)
1454  if ( emiss_QA_LUT->NEdL[i] < TOLERANCE )
1455  {
1456  returnStatus = MODIS_F_OUT_OF_RANGE;
1457  L1BErrorMsg(location, returnStatus,
1458  "Table \"NEdL\" is zero or negative.",
1459  NULL, QA_TABLES_FILE, invalidlutfile, True);
1460  return returnStatus;
1461  }
1462 
1463  for (i = 0; i < NUM_EMISSIVE_DETECTORS; i++)
1464  if ( emiss_QA_LUT->a1[i] < TOLERANCE )
1465  {
1466  returnStatus = MODIS_F_OUT_OF_RANGE;
1467  L1BErrorMsg(location, returnStatus,
1468  "Table \"a1\" is zero or negative.",
1469  NULL, QA_TABLES_FILE, invalidlutfile, True);
1470  return returnStatus;
1471  }
1472 
1473  /*
1474  * Check the platform name. Currently, the allowed name for Terra is "AM-1"
1475  * and possibly "Terra", and the allowed name for Aqua could be "PM-1" or
1476  * "Aqua". These names should be consistent with the satellite id determined
1477  * from the metadata SHORTNAME in L1A granule.
1478  */
1479 
1480  if (!((strcmp(common_QA_LUT->AssociatedPlatformShortname, "AM-1") == 0 ||
1481  strcmp(common_QA_LUT->AssociatedPlatformShortname, "Terra") == 0) &&
1482  L1A_Gran->satellite_id == TERRA) &&
1483  !((strcmp(common_QA_LUT->AssociatedPlatformShortname, "PM-1") == 0 ||
1484  strcmp(common_QA_LUT->AssociatedPlatformShortname, "Aqua") == 0) &&
1485  L1A_Gran->satellite_id == AQUA))
1486  {
1487  returnStatus = MODIS_F_OUT_OF_RANGE;
1488  L1BErrorMsg(location, returnStatus,
1489  "*** WRONG LUTS ARE INSTALLED ***\n"
1490  "Satellite instrument in the LUTs is inconsistent "
1491  "with the value\n"
1492  "inside the middle L1A granule (lun 500001).",
1493  NULL, QA_TABLES_FILE,
1494  "This is probably due to improper installation of "
1495  "LUT files.", True);
1496  return returnStatus;
1497  }
1498 
1499  return(MODIS_S_OK);
1500 }
1501 
1502 static
1503 PGSt_SMF_status Read_LUT_Tables (L1A_granule_t *L1A_Gran,
1504  int32 lun,
1506 /*
1507 !C**************************************************************************
1508 !Description:
1509  Read all lookup tables. The "data" member of the luts structure will
1510  contain the data read in. This should be already allocated (or assigned
1511  to the appropriate buffer) prior to calling this function.
1512 
1513 !Input Parameters:
1514  L1A_granule_t *L1A_Gran contains satellite id and EV start time
1515  int32 lun The logical unit number for the file to be read
1516  LUT_Definition_t *luts Array of structures, one per LUT. All data are
1517  assigned and the "data" member of the luts
1518  structure will contain the data read in. This
1519  should be already allocated (or assigned to the
1520  appropriate buffer) prior to calling this function.
1521 
1522 !Output Parameters:
1523  LUT_Definition_t *luts "data" member filled with the data read from file.
1524 
1525 !Revision History:
1526  Revision 01.00, December 22, 1999
1527  Initial development
1528  Jim Rogers (rogers@mcst.gsfc.nasa.gov)
1529 
1530 !Team-unique Header:
1531  This software is developed by the MODIS Characterization Support
1532  Team (MCST)for the National Aeronautics and Space Administration,
1533  Goddard Space Flight Center, under contract NAS5-32373.
1534 
1535 !References and Credits:
1536  HDF portions developed at the National Center for Supercomputing
1537  Applications at the University of Illinois at Urbana-Champaign.
1538 
1539 !Design Notes:
1540 
1541 !END********************************************************************
1542 */
1543 {
1544  PGSt_SMF_status returnStatus = MODIS_S_OK;
1545  PGSt_integer version = 1;
1546  char file_name[PGSd_PC_FILE_PATH_MAX];
1547  int32 file_id = 0;
1548  int32 i;
1549  int32 nluts;
1550  char *location = "Read_LUT_Tables";
1551  int32 i_bdsm = -1; /* Index of LUT in refl_lut structure */
1552  int32 rank = 0; /* Intrinsic LUT rank */
1553  int32 *dims_ptr; /* Pointer to dimension arrays */
1554 
1555  /*
1556  * Initially, only check the bounds of the luts during LUT generation.
1557  * Later, when bounds are stabilized, perhaps implement checking
1558  * bounds operationally
1559  */
1560 
1561 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1562  int32 count, j;
1563 #endif
1564 
1565  /*
1566  * Obtain the file name from the PCF and open the file for
1567  * Science Data access.
1568  */
1569 
1570  returnStatus = PGS_PC_GetReference (lun, &version, file_name);
1571  if (returnStatus != PGS_S_SUCCESS)
1572  {
1573  returnStatus = MODIS_F_FILE_NOT_FOUND;
1574  L1BErrorMsg(location, returnStatus,
1575  "Could not retrieve file name from PCF.",
1576  "PGS_PC_GetReference", lun, NULL, True);
1577  return returnStatus;
1578  }
1579  file_id = SDstart(file_name, DFACC_RDONLY);
1580  if (file_id == FAIL)
1581  {
1582  returnStatus = MODIS_F_FILE_NOT_OPENED;
1583  L1BErrorMsg(location, returnStatus,
1584  "Could not open file for SD read access.",
1585  "SDstart", lun,
1586  "The file may be missing, corrupted or "
1587  "not an HDF-4 file.", True);
1588  return returnStatus;
1589  }
1590 
1591  /*
1592  * Determine the number of luts to read.
1593  */
1594 
1595  nluts = 0;
1596  while (luts[nluts].name) nluts++;
1597 
1598  /*
1599  * Read and check all LUTs.
1600  */
1601 
1602  for (i = 0; i < nluts; i++)
1603  {
1604  if (!luts[i].data)
1605  {
1606  char errmsg[PGS_SMF_MAX_MSGBUF_SIZE];
1607  returnStatus = MODIS_F_NOK;
1608  sprintf(errmsg, "\"data\" member not assigned for LUT %s",
1609  luts[i].name);
1610  L1BErrorMsg(location, returnStatus, errmsg,
1611  NULL, lun, "*** CODE BUG ***", True);
1612  return returnStatus;
1613  }
1614 
1615  if (luts[i].kind == GLOBAL_ATTRIBUTE_LUT)
1616  {
1617  returnStatus = read_attribute(file_id, luts[i].name,
1618  luts[i].type, luts[i].data);
1619  if (returnStatus != MODIS_S_OK)
1620  {
1621  L1BErrorMsg(location, returnStatus, NULL,
1622  "read_attribute", lun, NULL, True);
1623  return returnStatus;
1624  }
1625  }
1626  else
1627  {
1628 
1629  /*
1630  * If a Reflective BDSM LUT, set dimensions expected in HDF file
1631  */
1632 
1633  rank = luts[i].rank;
1634  dims_ptr = luts[i].dims;
1635 
1636  if ((i_bdsm = BDSM_index (luts[i].ascii_file)) >= 0)
1637  {
1638  rank = 1;
1639  dims_ptr[0] = NUM_REFL_INDICES;
1640  dims_ptr[1] = 0;
1641  dims_ptr[2] = 0;
1642  dims_ptr[3] = 0;
1643  }
1644 
1645  /*
1646  * Read the LUT
1647  */
1648  returnStatus = Read_L1B_SDS_LUT(file_id,
1649  luts[i].name,
1650  luts[i].type,
1651  rank,
1652  dims_ptr,
1653  L1A_Gran->data_collection_time,
1654  luts[i].data);
1655  if (returnStatus != MODIS_S_OK)
1656  {
1657  L1BErrorMsg(location, returnStatus, NULL,
1658  "Read_L1B_SDS_LUT", lun, NULL, True);
1659  return returnStatus;
1660  }
1661 
1662  /*
1663  * If a Reflective BDSM LUT, expand array into full BDSM
1664  */
1665 
1666  if (i_bdsm >= 0)
1667  {
1668  void *data_new = NULL;
1669  int32 n_bytes;
1670  returnStatus = Expand_BDSM_LUT(luts[i].data, &data_new,
1671  luts[i].type, 1, &n_bytes);
1672  if (returnStatus != MODIS_S_OK)
1673  {
1674  L1BErrorMsg(location, returnStatus, NULL,
1675  "Expand_BDSM_LUT", lun, NULL, False);
1676  return returnStatus;
1677  }
1678  memcpy(luts[i].data, data_new, n_bytes);
1679  free(data_new);
1680  }
1681  }
1682 
1683 #ifndef NOCHECKLUT
1684  /*
1685  * Check the PGE version against the code macro. If it does not
1686  * match, then don't bother reading any of the rest of the tables.
1687  */
1688 
1689  if (!strcmp(luts[i].name, PGE_VERSION_LUT_NAME))
1690  {
1691  if (strcmp(luts[i].data, PGE02_VERSION))
1692  {
1693  char msg[PGS_SMF_MAX_MSGBUF_SIZE];
1694  returnStatus = MODIS_F_OUT_OF_RANGE;
1695  sprintf(msg, "PGE version in the file (%s) does not "
1696  "match the code value of %s",
1697  (char *) luts[i].data, PGE02_VERSION);
1698  L1BErrorMsg(location, returnStatus, msg, NULL, lun,
1699  "The LUT file is incompatible with this "
1700  "version of the L1B code.",
1701  True);
1702  return returnStatus;
1703  }
1704  }
1705 #endif
1706 
1707 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1708  for (count = 1, j = 0; j < luts[i].rank; j++)
1709  count *= luts[i].dims[j];
1710  returnStatus = Check_Valid_Range(luts[i].name,
1711  luts[i].type,
1712  luts[i].a_lb,
1713  luts[i].a_ub,
1714  luts[i].a_fv,
1715  count,
1716  luts[i].data);
1717  if (returnStatus != MODIS_S_OK)
1718  {
1719  L1BErrorMsg(location, returnStatus, NULL,
1720  "Check_Valid_Range", lun, NULL, True);
1721  return returnStatus;
1722  }
1723 #endif
1724  }
1725 
1726  /*
1727  * Close the file.
1728  */
1729 
1730  if (SDend(file_id) == FAIL)
1731  {
1732  returnStatus = MODIS_F_HDF_ERROR;
1733  L1BErrorMsg(location, returnStatus,
1734  "Could not close access to the HDF file.",
1735  "SDend", lun, NULL, True);
1736  return returnStatus;
1737  }
1738 
1739  return(MODIS_S_OK);
1740 }
1741 
1742 /************************************************************************
1743 
1744 Global variables which define the LUTs:
1745 
1746 1. refl_luts (defines LUTs for Reflective_Lookup_Tables_file)
1747 2. emiss_luts (defines LUTs for Emissive_Lookup_Tables_file)
1748 3. qa_luts (defines LUTs for QA_Lookup_Tables_file)
1749 
1750 *************************************************************************/
1751 
1752 /*
1753  * Define the reflective LUT information as LUT_Definition_t array.
1754  * This array must be NULL-terminated.
1755  */
1756 
1758 {
1759  { REFL_SERIAL_NUMBER_LUT_NAME, "refl_lut_serial_number.asc",
1760  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
1761  {MAX_SERIAL_NUMBER_BUFFER, 0, 0, 0, 0},
1762  {"MAX_SERIAL_NUMBER_BUFFER", NULL, NULL, NULL, NULL},
1763  NULL, False, NULL, NULL, NULL },
1764 
1765  { PGE_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
1766  {MAX_PGE_VERSION_BUFFER, 0, 0, 0, 0},
1767  {"MAX_PGE_VERSION_BUFFER", NULL, NULL, NULL, NULL},
1768  NULL, False, NULL, NULL, NULL },
1769 
1770  { MCST_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
1771  {MAX_MCST_VERSION_BUFFER, 0, 0, 0, 0},
1772  {"MAX_MCST_VERSION_BUFFER", NULL, NULL, NULL, NULL},
1773  NULL, False, NULL, NULL, NULL },
1774 
1775  { K_INST_LUT_NAME, "k_inst_table.asc",
1776  SDS_LUT, DFNT_FLOAT32, 4,
1779  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1780  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1781  NULL, True, "-0.1", "0.1", "-999" },
1782 
1783  { K_FPA_LUT_NAME, "k_fpa_table.asc",
1784  SDS_LUT, DFNT_FLOAT32, 4,
1787  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1788  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1789  NULL, True, "-0.1", "0.1", "-999" },
1790 
1791  { M0_LUT_NAME, "m0_table.asc",
1792  SDS_LUT, DFNT_FLOAT32, 4,
1795  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1796  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1797  NULL, True, "0.0", "1.0", "-999" },
1798 
1799  { M1_LUT_NAME, "m1_table.asc",
1800  SDS_LUT, DFNT_FLOAT32, 4,
1803  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1804  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1805  NULL, True, "1.0E-20", "1.0", "-999" },
1806 
1807  { RVS_RSB_LUT_NAME, "rvs_rsb_table.asc",
1808  SDS_LUT, DFNT_FLOAT32, 4,
1810  NUM_RSB_RVS_COEFFS, 0},
1811  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1812  "NUM_MIRROR_SIDES", "NUM_RSB_RVS_COEFFS", NULL},
1813  NULL, True, "-4.0E-4", "2.4", "-999" },
1814 
1815  /*
1816  * obsolete due to RSB UI algorithm update, 2/19/2011, Xu Geng
1817  */
1818  /*
1819  { SIGMA_RSB_ADC_LUT_NAME, "sigma_rsb_adc_table.asc",
1820  SDS_LUT, DFNT_FLOAT32, 2,
1821  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND, 0, 0, 0},
1822  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND", NULL, NULL, NULL},
1823  NULL, True, NULL, NULL, "-999" },
1824 
1825  { SIGMA_RVS_RSB_LUT_NAME, "sigma_rvs_rsb_table.asc",
1826  SDS_LUT, DFNT_FLOAT32, 2,
1827  {NUM_REFLECTIVE_BANDS, NUM_MIRROR_SIDES, 0, 0, 0},
1828  {"NUM_REFLECTIVE_BANDS", "NUM_MIRROR_SIDES", NULL, NULL, NULL},
1829  NULL, False, "0", "0.03", NULL },
1830 
1831  { SIGMA_M1_LUT_NAME, "sigma_m1_table.asc",
1832  SDS_LUT, DFNT_FLOAT32, 4,
1833  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND,
1834  MAX_SAMPLES_PER_BAND, NUM_MIRROR_SIDES, 0},
1835  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1836  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1837  NULL, True, "0.0", "1.0", "-999" },
1838 
1839  { SIGMA_K_INST_LUT_NAME, "sigma_k_inst_table.asc",
1840  SDS_LUT, DFNT_FLOAT32, 4,
1841  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND,
1842  MAX_SAMPLES_PER_BAND, NUM_MIRROR_SIDES, 0},
1843  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1844  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1845  NULL, True, "0", "0.01", "-999" },
1846 
1847  { SIGMA_T_INST_LUT_NAME, "sigma_t_inst_table.asc",
1848  SDS_LUT, DFNT_FLOAT32, 1,
1849  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1850  NULL, False, NULL, NULL, NULL },
1851 
1852  { SIGMA_PV_RESID_ELEC_LUT_NAME, "sigma_pv_resid_elec_table.asc",
1853  SDS_LUT, DFNT_FLOAT32, 3,
1854  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND,
1855  MAX_SAMPLES_PER_BAND, 0, 0},
1856  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1857  "MAX_SAMPLES_PER_BAND",
1858  NULL, NULL},
1859  NULL, True, NULL, NULL, "-999" },
1860 
1861  { SIGMA_R_STAR_LIN_RESID_UCOEFF_LUT_NAME,
1862  "sigma_r_star_lin_resid_ucoeff_table.asc",
1863  SDS_LUT, DFNT_FLOAT32, 5,
1864  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND,
1865  MAX_SAMPLES_PER_BAND, NUM_MIRROR_SIDES, NUM_4TH_ORDER_COEFFS},
1866  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1867  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", "NUM_4TH_ORDER_COEFFS"},
1868  NULL, True, NULL, NULL, "-999" },
1869 
1870  { RSB_NEDL_LUT_NAME, "rsb_nedl_table.asc",
1871  SDS_LUT, DFNT_FLOAT32, 4,
1872  {NUM_REFLECTIVE_BANDS, MAX_DETECTORS_PER_BAND,
1873  MAX_SAMPLES_PER_BAND, NUM_MIRROR_SIDES, 0},
1874  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1875  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1876  NULL, True, "0", "1", "-999" },
1877  */
1878 
1879  { T_INST_REF_LUT_NAME, "t_inst_ref_table.asc",
1880  SDS_LUT, DFNT_FLOAT32, 1,
1881  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1882  NULL, False, "250", "300", NULL },
1883 
1884  { T_FPA_REF_LUT_NAME, "t_fpa_ref_table.asc",
1885  SDS_LUT, DFNT_FLOAT32, 1,
1886  {NUM_FOCAL_PLANES, 0, 0, 0, 0},
1887  {"NUM_FOCAL_PLANES", NULL, NULL, NULL, NULL},
1888  NULL, False, "80", "300", NULL },
1889 
1891  "swir_oob_correction_switch_table.asc",
1892  SDS_LUT, DFNT_INT16, 1,
1893  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1894  NULL, False, "0", "1", NULL },
1895 
1897  "swir_oob_sending_band_table.asc",
1898  SDS_LUT, DFNT_INT16, 1,
1899  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1900  NULL, False, "20", "36", NULL },
1901 
1903  "swir_oob_sending_detector_table.asc",
1904  SDS_LUT, DFNT_INT16, 1,
1905  {DETECTORS_PER_1KM_BAND, 0, 0, 0, 0},
1906  {"DETECTORS_PER_1KM_BAND", NULL, NULL, NULL, NULL},
1907  NULL, True, "0", "9", NULL },
1908 
1909  { X_OOB_0_LUT_NAME, "x_oob_0_table.asc",
1910  SDS_LUT, DFNT_FLOAT32, 4,
1913  {"NUM_SWIR_BANDS", "MAX_DETECTORS_PER_SWIR_BAND",
1914  "MAX_NUM_SWIR_SUBSAMPLES", "NUM_MIRROR_SIDES", NULL},
1915  NULL, True, "-100", "100", "-999" },
1916 
1917  { X_OOB_1_LUT_NAME, "x_oob_1_table.asc",
1918  SDS_LUT, DFNT_FLOAT32, 4,
1921  {"NUM_SWIR_BANDS", "MAX_DETECTORS_PER_SWIR_BAND",
1922  "MAX_NUM_SWIR_SUBSAMPLES", "NUM_MIRROR_SIDES", NULL},
1923  NULL, True, "-100", "100", "-999" },
1924 
1925  { X_OOB_2_LUT_NAME, "x_oob_2_table.asc",
1926  SDS_LUT, DFNT_FLOAT32, 4,
1929  {"NUM_SWIR_BANDS", "MAX_DETECTORS_PER_SWIR_BAND",
1930  "MAX_NUM_SWIR_SUBSAMPLES", "NUM_MIRROR_SIDES", NULL},
1931  NULL, True, "-100", "100", "-999" },
1932 
1934  "dn_obc_avg_first_frame_to_use_table.asc",
1935  SDS_LUT, DFNT_INT16, 1,
1936  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1937  NULL, False, "0", "49", NULL },
1938 
1940  "dn_obc_avg_number_of_frames_to_use_table.asc",
1941  SDS_LUT, DFNT_INT16, 1,
1942  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1943  NULL, False, "1", "50", NULL },
1944 
1945  { DN_STAR_MIN_LUT_NAME, "dn_star_min_table.asc",
1946  SDS_LUT, DFNT_FLOAT32, 1,
1947  {NUM_REFLECTIVE_BANDS, 0, 0, 0, 0},
1948  {"NUM_REFLECTIVE_BANDS", NULL, NULL, NULL, NULL},
1949  NULL, False, "-40", "0", NULL },
1950 
1951  { DN_STAR_MAX_LUT_NAME, "dn_star_max_table.asc",
1952  SDS_LUT, DFNT_FLOAT32, 1,
1953  {NUM_REFLECTIVE_BANDS, 0, 0, 0, 0},
1954  {"NUM_REFLECTIVE_BANDS", NULL, NULL, NULL, NULL},
1955  NULL, False, "4095", "4095", NULL },
1956 
1957 
1959  "rsb_specified_uncertainty_table.asc",
1960  SDS_LUT, DFNT_FLOAT32, 1,
1961  {NUM_REFLECTIVE_BANDS, 0, 0, 0, 0},
1962  {"NUM_REFLECTIVE_BANDS", NULL, NULL, NULL, NULL},
1963  NULL, False, NULL, NULL, NULL },
1964 
1966  "rsb_ui_scaling_factor_table.asc",
1967  SDS_LUT, DFNT_FLOAT32, 1,
1968  {NUM_REFLECTIVE_BANDS, 0, 0, 0, 0},
1969  {"NUM_REFLECTIVE_BANDS", NULL, NULL, NULL, NULL},
1970  NULL, False, NULL, NULL, NULL },
1971 
1972  { E_SUN_OVER_PI_LUT_NAME, "e_sun_over_pi_table.asc",
1973  SDS_LUT, DFNT_FLOAT32, 1,
1974  {NUM_REFLECTIVE_DETECTORS, 0, 0, 0, 0},
1975  {"NUM_REFLECTIVE_DETECTORS", NULL, NULL, NULL, NULL},
1976  NULL, True, NULL, NULL, NULL },
1977 
1979  "rsb_sv_dn_moon_include_frames_table.asc",
1980  SDS_LUT, DFNT_INT16, 1,
1981  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
1982  NULL, False, "0", "50", NULL },
1983 
1984  { DN_SAT_EV_LUT_NAME, "dn_sat_ev_table.asc",
1985  SDS_LUT, DFNT_FLOAT64, 4,
1988  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
1989  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", NULL},
1990  NULL, True, "0", "4095", "-999" },
1991 
1992  { B26_B5_CORR_LUT_NAME, "b26_b5_corr_table.asc",
1993  SDS_LUT, DFNT_FLOAT32, 1,
1994  {DETECTORS_PER_1KM_BAND, 0, 0, 0, 0},
1995  {"DETECTORS_PER_1KM_BAND", NULL, NULL, NULL, NULL},
1996  NULL, True, "0.", "1.", "-999" },
1997 
1998  { B26_B5_CORR_SWITCH_LUT_NAME, "b26_b5_corr_switch_table.asc",
1999  SDS_LUT, DFNT_INT16, 1,
2000  {1, 0, 0, 0, 0},
2001  {"1", NULL, NULL, NULL, NULL},
2002  NULL, FALSE, "0", "1", NULL },
2003 
2004  { B26_B5_FRAME_OFFSET_LUT_NAME, "b26_b5_frame_offset_table.asc",
2005  SDS_LUT, DFNT_INT16, 1,
2006  {DETECTORS_PER_1KM_BAND, 0, 0, 0, 0},
2007  {"DETECTORS_PER_1KM_BAND", NULL, NULL, NULL, NULL},
2008  NULL, True, "-10", "10", "-999" },
2009 
2010  { U1_LUT_NAME, "u1_table.asc",
2011  SDS_LUT, DFNT_FLOAT32, 1,
2013  0, 0, 0},
2014  {"NUM_REFLECTIVE_DETECTORS", NULL,
2015  NULL, NULL, NULL},
2016  NULL, True, "0", "0.15", NULL },
2017 
2018  { U2_LUT_NAME, "u2_table.asc",
2019  SDS_LUT, DFNT_FLOAT32, 3,
2022  {"NUM_REFLECTIVE_DETECTORS",
2023  "NUM_MIRROR_SIDES", "NUM_U2_FRAME", NULL, NULL},
2024  NULL, True, "0", NULL, NULL },
2025 
2026  { U3_LUT_NAME, "u3_table.asc",
2027  SDS_LUT, DFNT_FLOAT32, 2,
2029  NUM_MIRROR_SIDES, 0, 0, 0},
2030  {"NUM_REFLECTIVE_DETECTORS",
2031  "NUM_MIRROR_SIDES", NULL, NULL, NULL},
2032  NULL, True, "0", "0.15", NULL },
2033 
2034  { U4_LUT_NAME, "u4_table.asc",
2035  SDS_LUT, DFNT_FLOAT32, 5,
2038  {"NUM_REFLECTIVE_BANDS", "MAX_DETECTORS_PER_BAND",
2039  "MAX_SAMPLES_PER_BAND", "NUM_MIRROR_SIDES", "NUM_2ND_ORDER_COEFFS"},
2040  NULL, True, NULL, NULL, "-999.000" },
2041 
2042  { U2_FRAMES_LUT_NAME, "u2_frames_table.asc",
2043  SDS_LUT, DFNT_INT16, 1,
2044  {NUM_U2_FRAME, 0, 0, 0, 0},
2045  {"NUM_U2_FRAME", NULL, NULL, NULL, NULL},
2046  NULL, False, "0", "1353", NULL },
2047 
2048  { SWIR_UI_FACTOR_LUT_NAME, "swir_ui_factor_table.asc",
2049  SDS_LUT, DFNT_FLOAT, 1,
2050  {NUM_SWIR_BANDS, 0, 0, 0, 0},
2051  {"NUM_SWIR_BANDS", NULL, NULL, NULL, NULL},
2052  NULL, False, "0", "1", NULL },
2053 
2054 
2055  { NULL } /* Must be NULL-terminated */
2056 };
2057 
2058 /*
2059  * Define the emissive LUT information as LUT_Definition_t array.
2060  * This array must be NULL-terminated.
2061  */
2062 
2064 {
2065  { EMISS_SERIAL_NUMBER_LUT_NAME, "emiss_lut_serial_number.asc",
2066  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2067  {MAX_SERIAL_NUMBER_BUFFER, 0, 0, 0, 0},
2068  {"MAX_SERIAL_NUMBER_BUFFER", NULL, NULL, NULL, NULL},
2069  NULL, False, NULL, NULL, NULL },
2070 
2071  { PGE_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2072  {MAX_PGE_VERSION_BUFFER, 0, 0, 0, 0},
2073  {"MAX_PGE_VERSION_BUFFER", NULL, NULL, NULL, NULL},
2074  NULL, False, NULL, NULL, NULL },
2075 
2076  { MCST_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2077  {MAX_MCST_VERSION_BUFFER, 0, 0, 0, 0},
2078  {"MAX_MCST_VERSION_BUFFER", NULL, NULL, NULL, NULL},
2079  NULL, False, NULL, NULL, NULL },
2080 
2081  { EPSILON_BB_LUT_NAME, "epsilon_bb_table.asc",
2082  SDS_LUT, DFNT_FLOAT32, 1,
2083  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2084  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2085  NULL, True, "0.9", "1.1", NULL },
2086 
2087  { EPSILON_CAV_LUT_NAME, "epsilon_cav_table.asc",
2088  SDS_LUT, DFNT_FLOAT32, 1,
2089  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2090  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2091  NULL, True, "0.5", "1.0", NULL },
2092 
2093  { DELTA_T_BB_BETA_LUT_NAME, "delta_t_bb_beta_table.asc",
2094  SDS_LUT, DFNT_FLOAT32, 1,
2095  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2096  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2097  NULL, True, "-0.5", "0.5", NULL },
2098 
2099  { DELTA_T_BB_DELTA_LUT_NAME, "delta_t_bb_delta_table.asc",
2100  SDS_LUT, DFNT_FLOAT32, 1,
2101  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2102  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2103  NULL, True, "-0.5", "0.5", NULL },
2104 
2105  { PCX_TALK_LUT_NAME, "pc_xt_table.asc",
2106  SDS_LUT, DFNT_FLOAT32, 3,
2108  NUM_PC_XT_PARAMETERS, 0, 0},
2109  {"NUM_PC_XT_BANDS", "DETECTORS_PER_1KM_BAND",
2110  "NUM_PC_XT_PARAMETERS", NULL, NULL},
2111  NULL, True, "-15", "15", NULL },
2112 
2113  { RSR_LUT_NAME, "rsr_table.asc",
2114  SDS_LUT, DFNT_FLOAT32, 2,
2116  {"NUM_EMISSIVE_DETECTORS", "MAX_NUM_RSR_vs_LAMBDA",
2117  NULL, NULL, NULL},
2118  NULL, True, "0.01", "1.0", "0.0" },
2119 
2120  { WAVELENGTH_LUT_NAME, "wavelength_table.asc",
2121  SDS_LUT, DFNT_FLOAT32, 2,
2123  {"NUM_EMISSIVE_DETECTORS", "MAX_NUM_RSR_vs_LAMBDA",
2124  NULL, NULL, NULL},
2125  NULL, True, "3.0", "15.0", "-999." },
2126 
2127  { NUM_WL_INCREMENT_LUT_NAME, "nwl_table.asc",
2128  SDS_LUT, DFNT_INT16, 1,
2129  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2130  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2131  NULL, True, "24", "50", NULL },
2132 
2133  { CALIB_A0_LUT_NAME, "a0_table.asc",
2134  SDS_LUT, DFNT_FLOAT32, 3,
2136  NUM_EMISSIVE_DETECTORS, 0, 0},
2137  {"NUM_a0_vs_T_inst_COEFF", "NUM_MIRROR_SIDES",
2138  "NUM_EMISSIVE_DETECTORS", NULL, NULL},
2139  NULL, True, "-100.", "300.", NULL },
2140 
2141  { CALIB_A2_LUT_NAME, "a2_table.asc",
2142  SDS_LUT, DFNT_FLOAT32, 3,
2144  NUM_EMISSIVE_DETECTORS, 0, 0},
2145  {"NUM_a2_vs_T_inst_COEFF", "NUM_MIRROR_SIDES",
2146  "NUM_EMISSIVE_DETECTORS", NULL, NULL},
2147  NULL, True, "-1.", "1.", NULL },
2148 
2149  /*
2150  * obsolete due to TEB UI algorithm update, 3/22/2011, Xu Geng
2151  */
2152  /*
2153  { UI_UCOEFF_LUT_NAME, "ucoeff_table.asc",
2154  SDS_LUT, DFNT_FLOAT32, 4,
2155  {NUM_EMISSIVE_DETECTORS, NUM_UI_PARAMETERS,
2156  NUM_UI_POLYNOMIAL_COEFF, NUM_FI_POLYNOMIAL_COEFF, 0},
2157  {"NUM_EMISSIVE_DETECTORS", "NUM_UI_PARAMETERS",
2158  "NUM_UI_POLYNOMIAL_COEFF", "NUM_FI_POLYNOMIAL_COEFF", NULL},
2159  NULL, True, NULL, NULL, "-999." },
2160 
2161  { SIGMA_TEB_PV_RESID_ELEC_LUT_NAME,
2162  "sigma_teb_pv_resid_elec_table.asc",
2163  SDS_LUT, DFNT_FLOAT32, 1,
2164  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2165  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2166  NULL, True, NULL, NULL, "-999." },
2167 
2168  { SIGMA_TEB_ADC_LUT_NAME, "sigma_teb_adc_table.asc",
2169  SDS_LUT, DFNT_FLOAT32, 1,
2170  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2171  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2172  NULL, True, NULL, NULL, "-999." },
2173 
2174  { UCOEFF_CALIBR_RESID_LUT_NAME,
2175  "ucoeff_calibr_resid_table.asc",
2176  SDS_LUT, DFNT_FLOAT32, 2,
2177  {NUM_EMISSIVE_DETECTORS, NUM_4TH_ORDER_COEFFS, 0, 0, 0},
2178  {"NUM_EMISSIVE_DETECTORS", "NUM_4TH_ORDER_COEFFS",
2179  NULL, NULL, NULL},
2180  NULL, True, NULL, NULL, "-999." },
2181 
2182  { BAND_21_UNCERT_LSAT_LUT_NAME,
2183  "band_21_uncert_lsat_table.asc",
2184  SDS_LUT, DFNT_FLOAT32, 1,
2185  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2186  NULL, False, "0.0", "0.2", NULL },
2187  */
2188 
2190  "bb_dn_first_frame_to_use_table.asc",
2191  SDS_LUT, DFNT_INT16, 1,
2192  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2193  NULL, False, "0", "49", NULL },
2194 
2196  "bb_dn_number_of_frames_to_use_table.asc",
2197  SDS_LUT, DFNT_INT16, 1,
2198  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2199  NULL, False, "1", "50", NULL },
2200 
2202  "sv_dn_first_frame_to_use_table.asc",
2203  SDS_LUT, DFNT_INT16, 1,
2204  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2205  NULL, False, "0", "49", NULL },
2206 
2208  "sv_dn_number_of_frames_to_use_table.asc",
2209  SDS_LUT, DFNT_INT16, 1,
2210  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2211  NULL, False, "1", "50", NULL },
2212 
2214  "sv_dn_moon_include_frames_table.asc",
2215  SDS_LUT, DFNT_INT16, 1,
2216  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2217  NULL, False, "0", "50", NULL },
2218 
2219  { OVERLAP_SCANS_B1_LUT_NAME, "num_overlap_scans_b1_table.asc",
2220  SDS_LUT, DFNT_INT16, 1,
2221  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2222  NULL, False, "0", "100", NULL },
2223 
2225  "pcx_correction_switch_table.asc",
2226  SDS_LUT, DFNT_INT8, 1,
2227  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2228  NULL, False, "0", "1", NULL },
2229 
2231  "t_ins_function_flag_table.asc",
2232  SDS_LUT, DFNT_INT32, 1,
2233  {NUM_T_INS_THERMISTORS, 0, 0, 0, 0},
2234  {"NUM_T_INS_THERMISTORS", NULL, NULL, NULL, NULL},
2235  NULL, False, "0", "1", NULL },
2236 
2237  { T_INS_DEFAULT_LUT_NAME, "t_ins_default_table.asc",
2238  SDS_LUT, DFNT_FLOAT32, 1,
2239  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2240  NULL, False, "200.", "300.", NULL },
2241 
2242  { T_INS_OFFSET_LUT_NAME, "t_ins_offset_table.asc",
2243  SDS_LUT, DFNT_FLOAT32, 1,
2244  {NUM_T_INS_THERMISTORS, 0, 0, 0, 0},
2245  {"NUM_T_INS_THERMISTORS", NULL, NULL, NULL, NULL},
2246  NULL, False, "-15.", "15.", NULL },
2247 
2249  "t_cav_function_flag_table.asc",
2250  SDS_LUT, DFNT_INT32, 1,
2251  {NUM_T_CAV_THERMISTORS, 0, 0, 0, 0},
2252  {"NUM_T_CAV_THERMISTORS", NULL, NULL, NULL, NULL},
2253  NULL, False, "0", "1", NULL },
2254 
2256  "t_mir_function_flag_table.asc",
2257  SDS_LUT, DFNT_INT32, 1,
2258  {NUM_T_MIR_THERMISTORS, 0, 0, 0, 0},
2259  {"NUM_T_MIR_THERMISTORS", NULL, NULL, NULL, NULL},
2260  NULL, False, "0", "1", NULL },
2261 
2263  "t_cav_default_table.asc",
2264  SDS_LUT, DFNT_FLOAT32, 1,
2265  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2266  NULL, False, "230", "300", NULL },
2267 
2268  { T_MIR_DEFAULT_LUT_NAME, "t_mir_default_table.asc",
2269  SDS_LUT, DFNT_FLOAT32, 1,
2270  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2271  NULL, False, "230", "300", NULL },
2272 
2273  { BB_WEIGHT_LUT_NAME, "bb_weight_table.asc",
2274  SDS_LUT, DFNT_FLOAT32, 1,
2275  {NUM_BB_THERMISTORS, 0, 0, 0, 0},
2276  {"NUM_BB_THERMISTORS", NULL, NULL, NULL, NULL},
2277  NULL, False, "0", "1", NULL },
2278 
2279  { RVS_TEB_LUT_NAME, "rvs_teb_table.asc",
2280  SDS_LUT, DFNT_FLOAT32, 4,
2283  {"NUM_EMISSIVE_BANDS", "DETECTORS_PER_1KM_BAND",
2284  "NUM_MIRROR_SIDES", "NUM_2ND_ORDER_COEFFS", NULL},
2285  NULL, True, "-2.0E-4", "1.2", "-999" },
2286 
2287  { RVS_BB_SV_FRAME_NO_LUT_NAME, "rvs_bb_sv_frame_no_table.asc",
2288  SDS_LUT, DFNT_INT16, 1,
2289  {2, 0, 0, 0, 0},
2290  {"2", NULL, NULL, NULL, NULL},
2291  NULL, False, "0", "1353", NULL },
2292 
2293  { BAND_21_B1_LUT_NAME, "band_21_b1_table.asc",
2294  SDS_LUT, DFNT_FLOAT32, 2,
2296  {"DETECTORS_PER_1KM_BAND", "NUM_MIRROR_SIDES", NULL, NULL, NULL},
2297  NULL, True, "0.005", "0.1", NULL },
2298 
2299  { L_MAX_LUT_NAME, "l_max_table.asc",
2300  SDS_LUT, DFNT_FLOAT32, 1,
2301  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2302  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2303  NULL, False, "0", "100", NULL },
2304 
2305  { L_MIN_LUT_NAME, "l_min_table.asc",
2306  SDS_LUT, DFNT_FLOAT32, 1,
2307  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2308  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2309  NULL, False, "-10.", "0", NULL },
2310 
2312  "teb_specified_uncertainty_table.asc",
2313  SDS_LUT, DFNT_FLOAT32, 1,
2314  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2315  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2316  NULL, False, NULL, NULL, NULL },
2317 
2319  "teb_ui_scaling_factor_table.asc",
2320  SDS_LUT, DFNT_FLOAT32, 1,
2321  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2322  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2323  NULL, False, NULL, NULL, NULL },
2324 
2325  { SIGMA_A0_LUT_NAME,
2326  "sigma_a0_table.asc",
2327  SDS_LUT, DFNT_FLOAT32, 3,
2329  NUM_EMISSIVE_DETECTORS, 0, 0},
2330  {"NUM_a0_vs_T_inst_COEFF", "NUM_MIRROR_SIDES",
2331  "NUM_EMISSIVE_DETECTORS", NULL, NULL},
2332  NULL, True, NULL, NULL, NULL },
2333 
2334  { SIGMA_A2_LUT_NAME,
2335  "sigma_a2_table.asc",
2336  SDS_LUT, DFNT_FLOAT32, 3,
2338  NUM_EMISSIVE_DETECTORS, 0, 0},
2339  {"NUM_a2_vs_T_inst_COEFF", "NUM_MIRROR_SIDES",
2340  "NUM_EMISSIVE_DETECTORS", NULL, NULL},
2341  NULL, True, NULL, NULL, NULL },
2342 
2344  "sigma_RVS_ev_table.asc",
2345  SDS_LUT, DFNT_FLOAT32, 4,
2348  {"NUM_EMISSIVE_BANDS", "DETECTORS_PER_1KM_BAND",
2349  "NUM_MIRROR_SIDES", "NUM_2ND_ORDER_COEFFS", NULL},
2350  NULL, True, NULL, NULL, NULL },
2351 
2353  "sigma_epsilon_bb_table.asc",
2354  SDS_LUT, DFNT_FLOAT32, 1,
2355  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2356  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2357  NULL, False, NULL, NULL, NULL },
2358 
2360  "sigma_epsilon_cav_table.asc",
2361  SDS_LUT, DFNT_FLOAT32, 1,
2362  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2363  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2364  NULL, False, NULL, NULL, NULL },
2365 
2367  "sigma_L_lambda_table.asc",
2368  SDS_LUT, DFNT_FLOAT32, 2,
2370  {"NUM_EMISSIVE_BANDS", "NUM_1ST_ORDER_COEFFS", NULL, NULL, NULL},
2371  NULL, False, NULL, NULL, NULL },
2372 
2374  "sigma_L_Tbb_table.asc",
2375  SDS_LUT, DFNT_FLOAT32, 1,
2376  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2377  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2378  NULL, False, NULL, NULL, NULL },
2379 
2381  "sigma_L_Tsm_table.asc",
2382  SDS_LUT, DFNT_FLOAT32, 1,
2383  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2384  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2385  NULL, False, NULL, NULL, NULL },
2386 
2388  "sigma_L_Tcav_table.asc",
2389  SDS_LUT, DFNT_FLOAT32, 1,
2390  {NUM_EMISSIVE_BANDS, 0, 0, 0, 0},
2391  {"NUM_EMISSIVE_BANDS", NULL, NULL, NULL, NULL},
2392  NULL, False, NULL, NULL, NULL },
2393 
2395  "sigma_b1_B21_table.asc",
2396  SDS_LUT, DFNT_FLOAT32, 2,
2398  {"DETECTORS_PER_1KM_BAND", "NUM_MIRROR_SIDES", NULL, NULL, NULL},
2399  NULL, True, NULL, NULL, NULL },
2400 
2402  "xt_ui_factor_table.asc",
2403  SDS_LUT, DFNT_FLOAT32, 2,
2405  {"NUM_EMISSIVE_BANDS", "DETECTORS_PER_1KM_BAND", NULL, NULL, NULL},
2406  NULL, False, NULL, NULL, NULL },
2407 
2409  "pvlw_xt_coeff_table.asc",
2410  SDS_LUT, DFNT_FLOAT64, 5,
2412  {"NUM_PVLW_XT_RECEIVING_BANDS", "DETECTORS_PER_1KM_BAND", "NUM_PVLW_XT_SENDING_BANDS", "DETECTORS_PER_1KM_BAND", "NUM_PVLW_XT_COEFF"},
2413  NULL, False, NULL, NULL, NULL },
2414 
2415  { NULL } /* Must be NULL-terminated */
2416 };
2417 
2418 /*
2419  * Define the quality assurance LUT information as LUT_Definition_t array.
2420  * This array must be NULL-terminated.
2421  */
2422 
2424 
2425  { QA_SERIAL_NUMBER_LUT_NAME, "qa_lut_serial_number.asc",
2426  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2427  {MAX_SERIAL_NUMBER_BUFFER, 0, 0, 0, 0},
2428  {"MAX_SERIAL_NUMBER_BUFFER", NULL, NULL, NULL, NULL},
2429  NULL, False, NULL, NULL, NULL },
2430 
2431  { PGE_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2432  {MAX_PGE_VERSION_BUFFER, 0, 0, 0, 0},
2433  {"MAX_PGE_VERSION_BUFFER", NULL, NULL, NULL, NULL},
2434  NULL, False, NULL, NULL, NULL },
2435 
2436  { MCST_VERSION_LUT_NAME, NULL, GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2437  {MAX_MCST_VERSION_BUFFER, 0, 0, 0, 0},
2438  {"MAX_MCST_VERSION_BUFFER", NULL, NULL, NULL, NULL},
2439  NULL, False, NULL, NULL, NULL },
2440 
2442  "associatedplatformshortname_table.asc",
2443  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2445  {"MAX_ASSOCIATEDPLATFORMSHORTNAME_BUFFER", NULL, NULL, NULL, NULL},
2446  NULL, False, NULL, NULL, NULL },
2447 
2449  "algorithmpackageacceptancedate_table.asc",
2450  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2452  {"MAX_ALGORITHMPACKAGEACCEPTANCEDATE_BUFFER", NULL, NULL, NULL, NULL},
2453  NULL, False, NULL, NULL, NULL },
2454 
2456  "algorithmpackagematuritycode_table.asc",
2457  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2459  {"MAX_ALGORITHMPACKAGEMATURITYCODE_BUFFER", NULL, NULL, NULL, NULL},
2460  NULL, False, NULL, NULL, NULL },
2461 
2463  "detector_quality_flag_values_table.asc",
2464  SDS_LUT, DFNT_UINT8, 2,
2465  {NUM_DETECTORS, NUM_BITS_IN_UINT8, 0, 0, 0},
2466  {"NUM_DETECTORS", "NUM_BITS_IN_UINT8", NULL, NULL, NULL},
2467  NULL, True, "0", "1", NULL },
2468 
2470  "detector_quality_flag2_values_table.asc",
2471  SDS_LUT, DFNT_UINT8, 2,
2473  {"NUM_HIGH_RESOLUTION_DETECTORS", "NUM_BITS_IN_UINT8", NULL, NULL, NULL},
2474  NULL, True, "0", "1", NULL },
2475 
2476  { MISSION_PHASE_LUT_NAME, "mission_phase_table.asc",
2477  GLOBAL_ATTRIBUTE_LUT, DFNT_CHAR8, 1,
2478  {MAX_MISSION_PHASE_BUFFER, 0, 0, 0, 0},
2479  {"MAX_MISSION_PHASE_BUFFER", NULL, NULL, NULL, NULL},
2480  NULL, False, NULL, NULL, NULL },
2481 
2482  { CONTROL_OPTIONS_LUT_NAME, "control_options_table.asc",
2483  SDS_LUT, DFNT_UINT8, 1,
2484  {NUM_CONTROL_OPTIONS, 0, 0, 0, 0},
2485  {"NUM_CONTROL_OPTIONS", NULL, NULL, NULL, NULL},
2486  NULL, False, "0", "1", NULL },
2487 
2489  "visual_fpa_base_variance_table.asc",
2490  SDS_LUT, DFNT_FLOAT32, 1,
2491  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2492  NULL, False, NULL, NULL, NULL },
2493 
2495  "nir_fpa_base_variance_table.asc",
2496  SDS_LUT, DFNT_FLOAT32, 1,
2497  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2498  NULL, False, NULL, NULL, NULL },
2499 
2500  { BB_TEMP_VARIANCE_LUT_NAME, "t_bb_variance_table.asc",
2501  SDS_LUT, DFNT_FLOAT32, 1,
2502  {NUM_BB_THERMISTORS, 0, 0, 0, 0},
2503  {"NUM_BB_THERMISTORS", NULL, NULL, NULL, NULL},
2504  NULL, False, "0.001", "0.1", NULL },
2505 
2507  "bb_average_temperature_variance_table.asc",
2508  SDS_LUT, DFNT_FLOAT32, 1,
2509  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2510  NULL, False, "0.0001", "0.1", NULL },
2511 
2513  "lwir_fpa_temperature_variance_table.asc",
2514  SDS_LUT, DFNT_FLOAT32, 1,
2515  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2516  NULL, False, "0.000001", "0.1", NULL },
2517 
2519  "mwir_fpa_temperature_variance_table.asc",
2520  SDS_LUT, DFNT_FLOAT32, 1,
2521  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2522  NULL, False, "0.001", "0.1", NULL },
2523 
2525  "mirrorside_1_temperature_variance_table.asc",
2526  SDS_LUT, DFNT_FLOAT32, 1,
2527  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2528  NULL, False, "0.0001", "0.1", NULL },
2529 
2531  "mirrorside_2_temperature_variance_table.asc",
2532  SDS_LUT, DFNT_FLOAT32, 1,
2533  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2534  NULL, False, "0.0001", "0.1", NULL },
2535 
2537  "mirror_average_temperature_variance_table.asc",
2538  SDS_LUT, DFNT_FLOAT32, 1,
2539  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2540  NULL, False, "0.001", "0.1", NULL },
2541 
2543  "instrument_temperature_variance_table.asc",
2544  SDS_LUT, DFNT_FLOAT32, 1,
2545  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2546  NULL, False, "0.001", "0.1", NULL },
2547 
2549  "cavity_temperature_variance_table.asc",
2550  SDS_LUT, DFNT_FLOAT32, 1,
2551  {1, 0, 0, 0, 0}, {"1", NULL, NULL, NULL, NULL},
2552  NULL, False, "0.01", "0.1", NULL },
2553 
2554  { EMISS_NEdL_LUT_NAME, "nedl_table.asc",
2555  SDS_LUT, DFNT_FLOAT32, 1,
2556  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2557  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2558  NULL, True, "0.0002", "0.1", NULL },
2559 
2560  { CALIB_A1_LUT_NAME, "a1_table.asc",
2561  SDS_LUT, DFNT_FLOAT32, 1,
2562  {NUM_EMISSIVE_DETECTORS, 0, 0, 0, 0},
2563  {"NUM_EMISSIVE_DETECTORS", NULL, NULL, NULL, NULL},
2564  NULL, True, "0.0002", "0.1", NULL },
2565 
2566  { MOON_OFFSET_LIMITS_LUT_NAME, "moon_offset_limits_table.asc",
2567  SDS_LUT, DFNT_FLOAT32, 2,
2568  {NUM_BANDS, NUM_MOON_OFFSET_LIMITS, 0, 0, 0},
2569  {"NUM_BANDS", "NUM_MOON_OFFSET_LIMITS", NULL, NULL, NULL},
2570  NULL, False, "-200", "200", NULL },
2571 
2572  { ROLL_THRESHOLD_LUT_NAME, "roll_threshold_angle_table.asc",
2573  SDS_LUT, DFNT_FLOAT32, 1,
2574  {1, 0, 0, 0, 0},
2575  {"1", NULL, NULL, NULL, NULL},
2576  NULL, False, "0.0", "360.0", NULL },
2577 
2578  { PITCH_THRESHOLD_LUT_NAME, "pitch_threshold_angle_table.asc",
2579  SDS_LUT, DFNT_FLOAT32, 1,
2580  {1, 0, 0, 0, 0},
2581  {"1", NULL, NULL, NULL, NULL},
2582  NULL, False, "0.0", "360.0", NULL },
2583 
2584  { YAW_THRESHOLD_LUT_NAME, "yaw_threshold_angle_table.asc",
2585  SDS_LUT, DFNT_FLOAT32, 1,
2586  {1, 0, 0, 0, 0},
2587  {"1", NULL, NULL, NULL, NULL},
2588  NULL, False, "0.0", "360.0", NULL },
2589 
2590  { NULL } /* Must be NULL-terminated */
2591 };
2592 
2593 
2594 PGSt_SMF_status Read_L1B_SDS_LUT(int32 sd_id,
2595  char *name,
2596  int32 data_type,
2597  int32 rank,
2598  int32 *dims,
2599  float64 data_collection_TAI_time,
2600  void *data)
2601 /*
2602 !C**************************************************************************
2603 !Description: This function reads one level 1B LUT implemented as SDS.
2604 
2605 !Input Parameters:
2606  int32 sd_id HDF file ID of the LUT file being read.
2607  char *name Name of the LUT as implemented in the HDF file
2608  int32 data_type HDF data type of the data being read. This also
2609  matches the data type of the memory addressed by
2610  the "data" pointer.
2611  int32 rank Array rank of the data. This matches the intrinsic
2612  array rank of the data in the HDF file.
2613  int32 *dims Array containing the size of each dimension of the
2614  intrinsic array.
2615  float64 data_collection_TAI_time The data collection time in TAI
2616  seconds (seconds since 1/1/1993)
2617 
2618 !Output Parameters:
2619  void *data Address of memory being filled by this function.
2620  The data type and number of elements of this array
2621  should be consistent with the inputs.
2622 
2623 !Revision History:
2624  Revision 01.00 June 23, 2000
2625  Initial development.
2626  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
2627 
2628 !Team-unique Header:
2629  This software is developed by the MODIS Science Data Support
2630  Team for the National Aeronautics and Space Administration,
2631  Goddard Space Flight Center, under contract NAS5-32373.
2632 
2633 !References and Credits
2634  HDF portions developed at the National Center for Supercomputing
2635  Applications at the University of Illinois at Urbana-Champaign.
2636 
2637 !Design Notes:
2638 !END********************************************************************
2639 */
2640 {
2641  PGSt_SMF_status returnStatus = MODIS_S_OK;
2642  int32 algorithm;
2643  int32 start[MAX_VAR_DIMS];
2644  int32 i;
2645  char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2646  char *location = "Read_L1B_SDS_LUT";
2647 
2648  /* Check input parameters for gross validility */
2649 
2650  if (sd_id == FAIL || !name || rank <= 0 || rank > MAX_VAR_DIMS ||
2651  !dims || !data || data_collection_TAI_time <= 0)
2652  {
2653  returnStatus = MODIS_F_INVALID_ARGUMENT;
2654  L1BErrorMsg(location, returnStatus,
2655  "One or more input parameters are invalid.\n",
2656  NULL, 0, "Code bug.", False);
2657  return returnStatus;
2658  }
2659 
2660  /* Determine the time dependent algorithm for this LUT */
2661 
2662  algorithm = TDLUT_GetAlgorithm(sd_id, name);
2663 
2664  if (algorithm == TDLUT_CONSTANT)
2665  { /* constant LUT */
2666  for (i = 0; i < MAX_VAR_DIMS; i++)
2667  start[i] = 0;
2668 
2669  returnStatus = read_sds_rankn(sd_id, name, data_type, rank,
2670  start, dims, data);
2671  if (returnStatus != MODIS_S_OK)
2672  {
2673  L1BErrorMsg(location, returnStatus, NULL,
2674  "read_sds_rankn", 0, NULL, False);
2675  }
2676  }
2677  else if (algorithm == TDLUT_STEPFUNCTION)
2678  { /* step function LUT */
2679  returnStatus = TDLUT_ReadStepFunction(sd_id, name, data_type,
2680  rank, dims,
2681  data_collection_TAI_time,
2682  data);
2683  if (returnStatus != MODIS_S_OK)
2684  {
2685  L1BErrorMsg(location, returnStatus, NULL,
2686  "TDLUT_ReadStepFunction", 0, NULL, False);
2687  }
2688  }
2689  else if (algorithm == TDLUT_PIECEWISE_LINEAR)
2690  { /* piecewise linear function LUT */
2691  returnStatus = TDLUT_ReadPiecewiseLinearFunction(sd_id, name, data_type,
2692  rank, dims,
2693  data_collection_TAI_time,
2694  data);
2695  if (returnStatus != MODIS_S_OK)
2696  {
2697  L1BErrorMsg(location, returnStatus, NULL,
2698  "TDLUT_ReadPiecewiseLinearFunction", 0, NULL, False);
2699  }
2700  }
2701 
2702  else
2703  { /* algorithm flag is invalid */
2704  returnStatus = MODIS_F_NOK;
2705  sprintf(errmsgbuf,
2706  "The algorithm flag is invalid for LUT \"%s\".",
2707  name);
2708  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
2709  }
2710 
2711  return returnStatus;
2712 }
2713 
2714 int32 TDLUT_GetAlgorithm(int32 sd_id,
2715  char *name)
2716 /*
2717 !C**************************************************************************
2718 !Description: Given a HDF file ID and a LUT name (LUT is assumed to be an SDS),
2719  return the time-dependence algorithm flag associated with the LUT.
2720 
2721 !Input Parameters:
2722  int32 sd_id HDF file ID of the LUT file being read.
2723  char *name Name of the LUT as implemented in the HDF file
2724 
2725 !Output Parameters:
2726  (none)
2727 
2728 !Revision History:
2729  Revision 01.00 June 22, 2000
2730  Initial development.
2731  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
2732 
2733 !Team-unique Header:
2734  This software is developed by the MODIS Science Data Support
2735  Team for the National Aeronautics and Space Administration,
2736  Goddard Space Flight Center, under contract NAS5-32373.
2737 
2738 !References and Credits
2739  HDF portions developed at the National Center for Supercomputing
2740  Applications at the University of Illinois at Urbana-Champaign.
2741 
2742 !Design Notes:
2743  1. The algorithm is implemented as an SDS attribute, of int32 type
2744  (scalar). The name of the attribute is given by the macro
2745  TDLUT_ALGORITHM_ATTR_NAME. If this attribute is missing, then
2746  it is assumed that the algorithm is TDLUT_CONSTANT.
2747 
2748  2. Initialize the SDS identifier to FAIL.
2749 !END********************************************************************
2750 */
2751 {
2752  int32 algorithm_flag;
2753  int32 sds_id = FAIL; /* SDS identifier */
2754  int32 sds_index; /* SDS index */
2755  int32 attr_index; /* index of an attribute of the SDS */
2756  int32 nattrs; /* number of attributes of the SDS */
2757  int32 count; /* number of values of an attribute */
2758  int32 rank; /* rank of the SDS */
2759  int32 dims[MAX_VAR_DIMS]; /* dimensionality of the SDS */
2760  int32 data_type; /* data type of an attributes or the SDS */
2761  char buffer[MAX_NC_NAME]; /* buffer to store a name */
2762  char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2763  intn hdf_return;
2764  char *location = "TDLUT_GetAlgorithm";
2765 
2766  /* Check the gross validility of the input parameters */
2767 
2768  if (sd_id == FAIL || !name)
2769  {
2771  "Input parameter sd_id is -1 or name is NULL\n",
2772  NULL, 0, "Code bug.", False);
2773  return TDLUT_INVALID;
2774  }
2775 
2776  /* Find the index of the SDS from its name */
2777 
2778  sds_index = SDnametoindex(sd_id, name);
2779  if (sds_index == FAIL)
2780  {
2781  sprintf(errmsgbuf,
2782  "Could not find SDS \"%s\" in the file.", name);
2783  L1BErrorMsg(location, MODIS_F_READ_ERROR, errmsgbuf,
2784  "SDnametoindex", 0, invalidinputfile, False);
2785  return TDLUT_INVALID;
2786  }
2787 
2788  /* Get the identifier of the SDS */
2789 
2790  sds_id = SDselect (sd_id, sds_index);
2791  if (sds_id == FAIL)
2792  {
2793  sprintf(errmsgbuf,
2794  "Could not open access to SDS \"%s\".", name);
2795  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf, "SDselect", 0,
2797  return TDLUT_INVALID;
2798  }
2799 
2800  /* Get the information of the SDS, especially the attribute information */
2801 
2802  hdf_return = SDgetinfo(sds_id,
2803  buffer,
2804  &rank,
2805  dims,
2806  &data_type,
2807  &nattrs);
2808  if (hdf_return == FAIL)
2809  {
2810  algorithm_flag = TDLUT_INVALID;
2811  sprintf(errmsgbuf,
2812  "Could not get information about SDS \"%s\".", name);
2813  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf, "SDgetinfo", 0,
2815  goto TDLUT_GetAlgorithm_exit;
2816  }
2817 
2818  algorithm_flag = TDLUT_CONSTANT;
2819 
2820  /* If there is no attribute for the SDS, assume the algorithm is
2821  * TDLUT_CONSTANT.
2822  */
2823 
2824  if (nattrs == 0)
2825  goto TDLUT_GetAlgorithm_exit;
2826 
2827  /* Loop through the attributes to find the attribute
2828  * TDLUT_ALGORITHM_ATTR_NAME. If it is missing, the algorithm is
2829  * assumed to be TDLUT_CONSTANT. If an error occurs, return
2830  * TDLUT_INVALID.
2831  */
2832 
2833  for (attr_index = 0; attr_index < nattrs; attr_index++)
2834  {
2835  hdf_return = SDattrinfo(sds_id,
2836  attr_index,
2837  buffer,
2838  &data_type,
2839  &count);
2840  if (hdf_return == FAIL)
2841  {
2842  algorithm_flag = TDLUT_INVALID;
2843  sprintf(errmsgbuf,
2844  "Could not get information of an attribute of SDS \"%s\""
2845  "with a valid index.", name);
2846  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf, "SDattrinfo", 0,
2848  goto TDLUT_GetAlgorithm_exit;
2849  }
2850  if (strcmp(buffer, TDLUT_ALGORITHM_ATTR_NAME) == 0)
2851  {
2852  if (data_type != DFNT_INT32 || count != 1)
2853  {
2854  algorithm_flag = TDLUT_INVALID;
2855  sprintf(errmsgbuf,
2856  "The data type or the count is not correct for the"
2857  "attribute \"%s\" of SDS \"%s\".", TDLUT_ALGORITHM_ATTR_NAME,
2858  name);
2859  L1BErrorMsg(location, MODIS_F_NOK, errmsgbuf, NULL, 0,
2861  goto TDLUT_GetAlgorithm_exit;
2862  }
2863  else
2864  {
2865  hdf_return = SDreadattr(sds_id, attr_index, &algorithm_flag);
2866  if (hdf_return == FAIL)
2867  {
2868  algorithm_flag = TDLUT_INVALID;
2869  sprintf(errmsgbuf,
2870  "Failed to read attribute \"%s\" of SDS \"%s\".",
2872  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf,
2873  "SDreadattr", 0, corruptinputfile, False);
2874  goto TDLUT_GetAlgorithm_exit;
2875  }
2876  }
2877  break; /* out of the "for" loop */
2878  }
2879  }
2880 
2881 TDLUT_GetAlgorithm_exit:
2882 
2883  if (sds_id != FAIL) SDendaccess(sds_id);
2884 
2885  return algorithm_flag;
2886 }
2887 
2888 PGSt_SMF_status TDLUT_ReadStepFunction (int32 sd_id,
2889  char *name,
2890  int32 data_type,
2891  int32 rank,
2892  int32 *dims,
2893  float64 data_collection_TAI_time,
2894  void *data)
2895 /*
2896 !C**************************************************************************
2897 !Description: This function reads one level 1B LUT which has a step-function
2898  time dependence.
2899 
2900 !Input Parameters:
2901  int32 sd_id HDF file ID of the LUT file being read.
2902  char *name Name of the LUT as implemented in the HDF file
2903  int32 data_type HDF data type of the data being read. This also
2904  matches the data type of the memory addressed by
2905  the "data" pointer.
2906  int32 rank Array rank of the data. This matches the intrinsic
2907  array rank of the data in the HDF file.
2908  int32 *dims Array containing the size of each dimension of the
2909  intrinsic array.
2910  float64 data_collection_TAI_time The data collection time in TAI
2911  seconds (seconds since 1/1/1993)
2912 
2913 !Output Parameters:
2914  void *data Address of memory being filled by this function.
2915  The data type and number of elements of this array
2916  should be consistent with the inputs.
2917 
2918 !Revision History:
2919  Revision 01.01 October 16, 2004 Razor Issue #200
2920  Casted Int32 variables in sprintf calls to "long" with the
2921  format specifier "%ld" for better code portability.
2922  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
2923 
2924  Revision 01.00 June 23, 2000
2925  Initial development.
2926  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
2927 
2928 !Team-unique Header:
2929  This software is developed by the MODIS Science Data Support
2930  Team for the National Aeronautics and Space Administration,
2931  Goddard Space Flight Center, under contract NAS5-32373.
2932 
2933 !References and Credits
2934  HDF portions developed at the National Center for Supercomputing
2935  Applications at the University of Illinois at Urbana-Champaign.
2936 
2937 !Design Notes:
2938  The actual LUT implemented in the HDF LUT file has an extra leading
2939  dimension from the intrinsic rank and dimensions indicated by the
2940  input variable. The extra leading dimension corresponds to TAI
2941  time of the steps.
2942 
2943  There must be an additional SDS attribute having the name given by the
2944  macro TDLUT_STEPFUNCTION_TIMES. This attribute must be of type
2945  float64. The number of elements of this attribute must match the
2946  size of the leading dimension of the LUT as implemented in the HDF file.
2947  The times in this attribute are assumed monotonically increasing.
2948 !END********************************************************************
2949 */
2950 {
2951 
2952 #define TDLUT_STEPFUNCTION_MAX_TIMES 500
2953  PGSt_SMF_status returnStatus = MODIS_S_OK;
2954  int32 sds_id = FAIL; /* SDS identifier */
2955  int32 sds_index; /* SDS index */
2956  int32 attr_index; /* index of an attribute of the SDS */
2957  int32 nattrs; /* number of attributes of the SDS */
2958  int32 count; /* number of values of an attribute */
2959  int32 f_rank; /* rank of the SDS */
2960  int32 full_dims[MAX_VAR_DIMS]; /* leading dimension + intrinsic dims */
2961  int32 f_data_type; /* data type of an attributes or the SDS */
2962  char buffer[MAX_NC_NAME]; /* buffer to store a name */
2963  char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2964  intn hdf_return;
2965  int32 start[MAX_VAR_DIMS];
2966  int32 edge [MAX_VAR_DIMS];
2967  float64 times[TDLUT_STEPFUNCTION_MAX_TIMES];
2968  int32 i;
2969  char *location = "TDLUT_ReadStepFunction";
2970 
2971  /* Check input parameters for gross validity */
2972 
2973  if (sd_id == FAIL || !name || rank <= 0 || rank >= MAX_VAR_DIMS ||
2974  !dims || !data || data_collection_TAI_time <= 0)
2975  {
2976  returnStatus = MODIS_F_INVALID_ARGUMENT;
2977  L1BErrorMsg(location, returnStatus,
2978  "One or more input parameters are invalid.\n",
2979  NULL, 0, "Code bug.", False);
2980  return returnStatus;
2981  }
2982 
2983  /* Find the index of the SDS from its name */
2984 
2985  sds_index = SDnametoindex(sd_id, name);
2986  if (sds_index == FAIL)
2987  {
2988  returnStatus = MODIS_F_READ_ERROR;
2989  sprintf(errmsgbuf,
2990  "Could not find SDS \"%s\" in the file.", name);
2991  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDnametoindex", 0,
2993  goto TDLUT_ReadStepFunction_exit;
2994  }
2995 
2996  /* Open SDS access to the data set */
2997 
2998  sds_id = SDselect (sd_id, sds_index);
2999  if (sds_id == FAIL)
3000  {
3001  returnStatus = MODIS_F_HDF_ERROR;
3002  sprintf(errmsgbuf,
3003  "Could not open access to SDS \"%s\".", name);
3004  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDselect", 0,
3006  goto TDLUT_ReadStepFunction_exit;
3007  }
3008 
3009  /* Get information about the SDS */
3010 
3011  hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3012  &f_data_type, &nattrs);
3013  if (hdf_return == FAIL)
3014  {
3015  returnStatus = MODIS_F_HDF_ERROR;
3016  sprintf(errmsgbuf,
3017  "Could not get information about SDS \"%s\".", name);
3018  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDgetinfo", 0,
3020  goto TDLUT_ReadStepFunction_exit;
3021  }
3022  if (data_type != f_data_type)
3023  {
3024  returnStatus = MODIS_F_READ_ERROR;
3025  sprintf(errmsgbuf,
3026  "SDS \"%s\" has data type mismatch.\n"
3027  "File data type = %ld, expected type = %ld\n",
3028  name, (long)f_data_type, (long)data_type);
3029  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3031  goto TDLUT_ReadStepFunction_exit;
3032  }
3033 
3034  /* Check that the HDF rank is one more than the actual rank. */
3035  if ((rank + 1) != f_rank)
3036  {
3037  returnStatus = MODIS_F_READ_ERROR;
3038  sprintf(errmsgbuf,
3039  "SDS \"%s\" has a rank mismatch.\n"
3040  "HDF File rank = %ld, expected rank = %ld\n",
3041  name, (long)f_rank, (long)(rank + 1));
3042  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3044  goto TDLUT_ReadStepFunction_exit;
3045  }
3046 
3047  /* For step function time-dependent LUT, number of attributes
3048  * should not be zero. The attributes include at least "algorithm"
3049  * and "times".
3050  */
3051 
3052  if (nattrs == 0)
3053  {
3054  returnStatus = MODIS_F_NOK;
3055  sprintf(errmsgbuf,
3056  "The number of attributes for the step function LUT"
3057  " \"%s\" is 0.", name);
3058  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3060  goto TDLUT_ReadStepFunction_exit;
3061  }
3062 
3063  /* Find the attribute TDLUT_STEPFUNCTION_TIMES */
3064 
3065  attr_index = SDfindattr(sds_id, TDLUT_STEPFUNCTION_TIMES);
3066  if (attr_index == FAIL)
3067  {
3068  returnStatus = MODIS_F_NOK;
3069  sprintf(errmsgbuf,
3070  "Step function lut \"%s\" does not have attribute \"%s\".",
3072  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDfindattr", 0,
3074  goto TDLUT_ReadStepFunction_exit;
3075  }
3076 
3077  /* Get the attribute info */
3078 
3079  hdf_return = SDattrinfo(sds_id, attr_index, buffer, &f_data_type, &count);
3080  if (hdf_return == FAIL)
3081  {
3082  returnStatus = MODIS_F_HDF_ERROR;
3083  sprintf(errmsgbuf,
3084  "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3086  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDattrinfo", 0,
3088  goto TDLUT_ReadStepFunction_exit;
3089  }
3090 
3091  /*
3092  * Check the data type and count of the attribute
3093  * TDLUT_STEPFUNCTION_TIMES. The data type should be float64
3094  * (DFNT_FLOAT64) and the count should not exceed
3095  * TDLUT_STEPFUNCTION_MAX_TIMES.
3096  */
3097 
3098 
3099  if (f_data_type != DFNT_FLOAT64 ||
3101  {
3102  returnStatus = MODIS_F_NOK;
3103  sprintf(errmsgbuf,
3104  "Either the data type is not float64 or the number of\n"
3105  "values are too large (>500) for the "
3106  "attribute\n \"%s\" of SDS \"%s\".",
3108  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
3109  goto TDLUT_ReadStepFunction_exit;
3110  }
3111 
3112  /* Read the attribute TDLUT_STEPFUNCTION_TIMES */
3113 
3114  hdf_return = SDreadattr(sds_id, attr_index, times);
3115  if (hdf_return == FAIL)
3116  {
3117  returnStatus = MODIS_F_HDF_ERROR;
3118  sprintf(errmsgbuf,
3119  "Failed to read attribute \"%s\" of SDS \"%s\".",
3121  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf, "SDreadattr", 0,
3123  goto TDLUT_ReadStepFunction_exit;
3124  }
3125 
3126  /* Determine the index of the leading dimension to read the data by
3127  * comparing the data collection time with the times as read from the
3128  * attribute.
3129  */
3130 
3131  if (data_collection_TAI_time < times[0])
3132  start[0] = 0;
3133  else if (data_collection_TAI_time >= times[count - 1])
3134  start[0] = count - 1;
3135  else
3136  {
3137  for (i = 0; i < count - 1; i++)
3138  {
3139  if (data_collection_TAI_time >= times[i] &&
3140  data_collection_TAI_time < times[i + 1])
3141  {
3142  start[0] = i;
3143  break;
3144  }
3145  }
3146  }
3147 
3148  edge[0] = 1;
3149 
3150  /* Set values for other elements of "start" and "edge" arrays */
3151 
3152  for (i = 1; i < MAX_VAR_DIMS; i++)
3153  {
3154  start[i] = 0;
3155  if (i <= rank)
3156  edge[i] = dims[i - 1];
3157  else
3158  edge[i] = 0;
3159  }
3160 
3161  /* Read the data from the LUT */
3162 
3163  hdf_return = SDreaddata(sds_id, start, NULL, edge, data);
3164  if (hdf_return == FAIL)
3165  {
3166  returnStatus = MODIS_F_HDF_ERROR;
3167  sprintf(errmsgbuf,
3168  "Could not read data from SDS \"%s\".", name);
3169  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDreaddata", 0,
3171  goto TDLUT_ReadStepFunction_exit;
3172  }
3173 
3174 TDLUT_ReadStepFunction_exit:
3175 
3176  if (sds_id != FAIL) SDendaccess(sds_id);
3177 
3178  return returnStatus;
3179 }
3180 
3181 /*=============================================== */
3182 
3183 
3184 PGSt_SMF_status TDLUT_ReadPiecewiseLinearFunction
3185  (int32 sd_id,
3186  char *name,
3187  int32 data_type,
3188  int32 rank,
3189  int32 *dims,
3190  float64 data_collection_TAI_time,
3191  void *data)
3192 /*
3193 !C**************************************************************************
3194 !Description: This function reads one level 1B LUT which is piecewise
3195  linear time dependent.
3196 
3197 !Input Parameters:
3198  int32 sd_id HDF file ID of the LUT file being read.
3199  char *name Name of the LUT as implemented in the HDF file
3200  int32 data_type HDF data type of the data being read. This also
3201  matches the data type of the memory addressed by
3202  the "data" pointer.
3203  int32 rank Array rank of the data. This matches the intrinsic
3204  array rank of the data in the HDF file.
3205  int32 *dims Array containing the size of each dimension of the
3206  intrinsic array.
3207  float64 data_collection_TAI_time The data collection time in TAI
3208  seconds (seconds since 1/1/1993)
3209 
3210 !Output Parameters:
3211  void *data Address of memory being filled by this function.
3212  The data type and number of elements of this array
3213  should be consistent with the inputs.
3214 
3215 !Revision History:
3216  Revision 01.01 October 16, 2004 Razor Issue #200
3217  Casted Int32 variables in sprintf calls to "long" with the
3218  format specifier "%ld" for better code portability.
3219  Liqin Tan, SAIC GSO (ltan@saicmodis.com)
3220 
3221  Revision 01.00 March 04, 2001
3222  Initial development.
3223  Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
3224 
3225 !Team-unique Header:
3226  This software is developed by the MODIS Science Data Support
3227  Team for the National Aeronautics and Space Administration,
3228  Goddard Space Flight Center, under contract NAS5-32373.
3229 
3230 !References and Credits
3231  HDF portions developed at the National Center for Supercomputing
3232  Applications at the University of Illinois at Urbana-Champaign.
3233 
3234 !Design Notes:
3235  The actual LUT implemented in the HDF LUT file has an extra leading
3236  dimension from the intrinsic rank and dimensions indicated by the
3237  input variable. The extra leading dimension corresponds to the TAI
3238  times of the LUT tables which can be interpolated.
3239 
3240  The LUT which is being interpolated must have data type float32.
3241 
3242  There must be an additional SDS attribute having the name given by the
3243  macro TDLUT_PIECEWISE_LINEAR_TIMES. This attribute must be of type
3244  float64. The number of elements of this attribute must match the
3245  size of the leading dimension of the LUT as implemented in the HDF file.
3246 !END*********************************************************************/
3247 
3248 {
3249 
3250 /********************* TDLUT_PIECEWISE_LINEAR_MAX_TIMES ******************/
3251 /* Maximum number of separate time dependent lookup tables allowed in a */
3252 /* file. */
3253 #define TDLUT_PIECEWISE_LINEAR_MAX_TIMES 1000
3254 
3255  PGSt_SMF_status returnStatus = MODIS_S_OK;
3256  int32 sds_id = FAIL; /* SDS identifier */
3257  int32 sds_index; /* SDS index */
3258  int32 attr_index; /* index of an attribute of the SDS */
3259  int32 nattrs; /* number of attributes of the SDS */
3260  int32 num_lut_copies; /* number of LUT copies in the file */
3261  int32 f_rank; /* rank of the SDS */
3262  int32 full_dims[MAX_VAR_DIMS]; /* leading dimension + intrinsic dims */
3263  int32 f_data_type; /* data type of an attribute or SDS */
3264  char buffer[MAX_NC_NAME]; /* buffer to store a name */
3265  char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
3266  intn hdf_return;
3267  int32 start[MAX_VAR_DIMS];
3268  int32 next_start[MAX_VAR_DIMS];
3269  int32 edge [MAX_VAR_DIMS];
3270  float64 times[TDLUT_PIECEWISE_LINEAR_MAX_TIMES];
3271  float64 data_coll_time; /* Scaled data collection time */
3272  float64 lut_data_time; /* Scaled data time of first LUT */
3273  float64 next_lut_data_time; /* Scaled data time of second LUT */
3274  float64 slope_denom; /* Denominator of Linear Slope */
3275  float64 xproportion; /* Linear Proportion (x - x1)/(x2 - x1)*/
3276  int32 num_lut_elements; /* Total number of elements in one LUT */
3277  char *location = "TDLUT_ReadPiecewiseLinearFunction";
3278  void *data2 = NULL; /* Pointer to data in second LUT */
3279  int32 pw_size = sizeof(float32); /* Allowed size of PW Linear LUT data */
3280  int32 i;
3281 
3282  /* Check input parameters for gross validity */
3283 
3284  if (sd_id == FAIL || !name || rank <= 0 || rank >= MAX_VAR_DIMS ||
3285  !dims || !data || data_collection_TAI_time <= 0)
3286  {
3287  returnStatus = MODIS_F_INVALID_ARGUMENT;
3288  L1BErrorMsg(location, returnStatus,
3289  "One or more input parameters are invalid.\n",
3290  NULL, 0, "Code bug.", False);
3291  return returnStatus;
3292  }
3293 
3294  /* Determine the input data type of the LUT. It must be float32. */
3295  if (data_type != DFNT_FLOAT32)
3296  {
3297  returnStatus = MODIS_F_NOK;
3298  sprintf(errmsgbuf,
3299  "\"%s\" must have data type float32 to be Piecewise Linear.", name) ;
3300  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
3301  return returnStatus;
3302  }
3303 
3304  /* Find the index of the SDS from its name */
3305 
3306  sds_index = SDnametoindex(sd_id, name);
3307  if (sds_index == FAIL)
3308  {
3309  returnStatus = MODIS_F_READ_ERROR;
3310  sprintf(errmsgbuf,
3311  "Could not find SDS \"%s\" in the file.", name);
3312  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDnametoindex", 0,
3314  return returnStatus;
3315  }
3316 
3317  /* Open SDS access to the data set */
3318 
3319  sds_id = SDselect (sd_id, sds_index);
3320  if (sds_id == FAIL)
3321  {
3322  returnStatus = MODIS_F_HDF_ERROR;
3323  sprintf(errmsgbuf,
3324  "Could not open access to SDS \"%s\".", name);
3325  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDselect", 0,
3327  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3328  }
3329 
3330  /* Get information about the SDS */
3331 
3332  hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3333  &f_data_type, &nattrs);
3334  if (hdf_return == FAIL)
3335  {
3336  returnStatus = MODIS_F_HDF_ERROR;
3337  sprintf(errmsgbuf,
3338  "Could not get information about SDS \"%s\".", name);
3339  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDgetinfo", 0,
3341  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3342  }
3343 
3344 
3345  /* Check that the HDF data type is the same as that expected. */
3346  if (data_type != f_data_type)
3347  {
3348  returnStatus = MODIS_F_READ_ERROR;
3349  sprintf(errmsgbuf,
3350  "SDS \"%s\" has data type mismatch.\n"
3351  "HDF File data type = %ld, expected type = %ld\n",
3352  name, (long)f_data_type, (long)data_type);
3353  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3355  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3356  }
3357 
3358  /* Check that the HDF rank is one more than the actual rank. */
3359  if ((rank + 1) != f_rank)
3360  {
3361  returnStatus = MODIS_F_READ_ERROR;
3362  sprintf(errmsgbuf,
3363  "SDS \"%s\" has a rank mismatch.\n"
3364  "HDF File rank = %ld, expected rank = %ld\n",
3365  name, (long)f_rank, (long)(rank + 1));
3366  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3368  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3369  }
3370 
3371  /* For piecewise linear time-dependent LUTs, the number of attributes */
3372  /* should be two or more. (The attributes must include at least */
3373  /* "algorithm" and "times".) */
3374 
3375 
3376  if (nattrs < 2)
3377  {
3378  returnStatus = MODIS_F_NOK;
3379  sprintf(errmsgbuf,
3380  "There must be at least 2 attributes for a Piecewise Linear LUT but"
3381  " \"%s\" has %ld.", name, (long)nattrs);
3382  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0,
3384  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3385  }
3386 
3387  /* Find the attribute TDLUT_PIECEWISE_LINEAR_TIMES */
3388 
3389  attr_index = SDfindattr(sds_id, TDLUT_PIECEWISE_LINEAR_TIMES);
3390  if (attr_index == FAIL)
3391  {
3392  returnStatus = MODIS_F_NOK;
3393  sprintf(errmsgbuf,
3394  "Piecewise linear function LUT \"%s\" does not have attribute \"%s\".",
3396  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDfindattr", 0,
3398  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3399  }
3400 
3401  /* Get the attribute info */
3402 
3403  hdf_return = SDattrinfo(sds_id,
3404  attr_index,
3405  buffer,
3406  &f_data_type,
3407  &num_lut_copies);
3408  if (hdf_return == FAIL)
3409  {
3410  returnStatus = MODIS_F_HDF_ERROR;
3411  sprintf(errmsgbuf,
3412  "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3414  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDattrinfo", 0,
3416  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3417  }
3418 
3419  /* Check the data type and count of the attribute */
3420  /* TDLUT_PIECEWISE_LINEAR_TIMES. The data type should be float64 */
3421  /* (DFNT_FLOAT64) and the count should not exceed */
3422  /* TDLUT_PIECEWISE_LINEAR_MAX_TIMES. */
3423 
3424  if (f_data_type != DFNT_FLOAT64 ||
3425  num_lut_copies > TDLUT_PIECEWISE_LINEAR_MAX_TIMES)
3426  {
3427  returnStatus = MODIS_F_NOK;
3428  sprintf(errmsgbuf,
3429  "Either the data type is not float64 or the number of\n"
3430  "values are too large (>500) for the "
3431  "attribute\n \"%s\" of SDS \"%s\".",
3433  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
3434  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3435  }
3436 
3437  /* Read the attribute TDLUT_PIECEWISE_LINEAR_TIMES */
3438 
3439  hdf_return = SDreadattr(sds_id, attr_index, times);
3440  if (hdf_return == FAIL)
3441  {
3442  returnStatus = MODIS_F_HDF_ERROR;
3443  sprintf(errmsgbuf,
3444  "Failed to read attribute \"%s\" of SDS \"%s\".",
3446  L1BErrorMsg(location, MODIS_F_HDF_ERROR, errmsgbuf, "SDreadattr", 0,
3448  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3449  }
3450 
3451  /* Determine the index of the leading dimension to read the data by */
3452  /* comparing the data collection time with the times as read from the */
3453  /* attribute. */
3454 
3455 
3456  /* First special case: even though the LUT is designated piecewise */
3457  /* linear, there is actually only one table in it. */
3458  if (num_lut_copies == 1)
3459  {
3460  start[0] = 0;
3461  }
3462 
3463  /* Second special case: granule time before time of first LUT */
3464  else if (data_collection_TAI_time < times[0])
3465  {
3466  start[0] = 0;
3467  next_start[0] = 1;
3468  }
3469  /* Third special case: granule time after time of last LUT */
3470  else if (data_collection_TAI_time >= times[num_lut_copies-1])
3471  {
3472  start[0] = num_lut_copies - 2;
3473  next_start[0] = num_lut_copies - 1;
3474  }
3475  /* All other cases */
3476  else
3477  {
3478  for (i = 0; i < num_lut_copies - 1; i++)
3479  {
3480  if (data_collection_TAI_time >= times[i] &&
3481  data_collection_TAI_time < times[i+1])
3482  {
3483  start[0] = i;
3484  next_start[0] = i+1;
3485  break;
3486  }
3487  }
3488  }
3489 
3490  edge[0] = 1;
3491 
3492  /* Set values for other elements of "start" and "edge" arrays */
3493 
3494  for (i = 1; i <= rank; i++)
3495  {
3496  start[i] = 0;
3497  next_start[i] = 0;
3498  edge[i] = dims[i - 1];
3499  }
3500 
3501  /* Read the data from the LUT */
3502 
3503  hdf_return = SDreaddata(sds_id, start, NULL, edge, data);
3504  if (hdf_return == FAIL)
3505  {
3506  returnStatus = MODIS_F_HDF_ERROR;
3507  sprintf(errmsgbuf,
3508  "Could not read first set of data from"
3509  " SDS \"%s\".", name);
3510  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDreaddata", 0,
3512  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3513  }
3514 
3515  /* Exit if there is only one record; no interpolation can be done. */
3516 
3517  if (num_lut_copies == 1) return returnStatus;
3518 
3519  /* Get the times and their difference, which must be positive. */
3520  /* Scale the TAI times. */
3521  data_coll_time = data_collection_TAI_time;
3522  lut_data_time = times[start[0]];
3523  next_lut_data_time = times[next_start[0]];
3524  slope_denom = (next_lut_data_time - lut_data_time);
3525 
3526  /* If the denominator of the slope is 0 then there is a problem. */
3527  /* Likewise, a negative slope indicates the times are not in */
3528  /* increasing order. */
3529 
3530  if (slope_denom <= 0)
3531  {
3532  returnStatus = MODIS_F_NOK;
3533  sprintf(errmsgbuf,
3534  "LUT associated with \"%s\" has times out of order.",
3535  name);
3536  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
3537  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3538  }
3539 
3540  /* Linear Proportion (x - x1)/(x2 - x1) */
3541  xproportion = (data_coll_time - lut_data_time)/slope_denom;
3542 
3543  /* Get total number of LUT elements */
3544  for (num_lut_elements = 1, i = 0; i < rank; i++)
3545  num_lut_elements *= dims[i];
3546 
3547  /* Read the data from the next higher LUT */
3548 
3549  data2 = malloc((unsigned) num_lut_elements*pw_size);
3550  if (!(data2))
3551  {
3552  returnStatus = MODIS_F_OUT_OF_MEMORY;
3553  sprintf(errmsgbuf,
3554  "Could not allocate memory for second LUT associated "
3555  "with \"%s\".", name);
3556  L1BErrorMsg(location, returnStatus, errmsgbuf, NULL, 0, NULL, False);
3557  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3558  }
3559 
3560  hdf_return = SDreaddata(sds_id, next_start, NULL, edge, data2);
3561  if (hdf_return == FAIL)
3562  {
3563  returnStatus = MODIS_F_HDF_ERROR;
3564  sprintf(errmsgbuf,
3565  "Could not read second set of data from"
3566  " SDS \"%s\"." , name);
3567  L1BErrorMsg(location, returnStatus, errmsgbuf, "SDreaddata", 0,
3569  goto TDLUT_ReadPiecewiseLinearFunction_exit;
3570  }
3571 
3572  /* Do the interpolation. */
3573 
3574  /* Begin Interpolation Block */
3575  {
3576  float32 first_val, second_val, interp_val;
3577  float32 *first_data = (float32 *) data;
3578  float32 *next_data = (float32 *) data2;
3579 
3580  for (i = 0; i < num_lut_elements; i++)
3581  {
3582  first_val = *first_data;
3583  second_val = *next_data;
3584  interp_val = first_val + xproportion*(second_val - first_val);
3585  *first_data = interp_val;
3586  first_data++;
3587  next_data++;
3588  }
3589 
3590  }
3591  /* End Interpolation Block */
3592 
3593 
3594 TDLUT_ReadPiecewiseLinearFunction_exit:
3595 
3596  /* Free up the memory used by data2 */
3597  if (data2 != NULL)
3598  free(data2);
3599 
3600  if (sds_id != FAIL) SDendaccess(sds_id);
3601 
3602  return returnStatus;
3603 }
3604 
3605 PGSt_SMF_status Expand_BDSM_LUT (
3606  void *data, /* generic pointer to the unexpanded LUT array */
3607  void **data_new, /* generic pointer to the array to fill and return */
3608  int32 data_type, /* HDF data type of the data in the file */
3609  int32 lead_dim, /* NUM_TIMES in time-dependent LUTs */
3610  int32 *n_bytes /* size of filled array in bytes */
3611  )
3612 /*
3613 !C****************************************************************************
3614 !Description:
3615  Given a LUT array containing values only for valid BDSM combinations,
3616  expand the array with fill values occupying invalid BDSM combinations.
3617 
3618 !Input Parameters:
3619  void *data Generic pointer to the unexpanded LUT array
3620  int32 data_type HDF data type of the data in the file
3621  int32 lead_dim NUM_TIMES in time-dependent LUTs
3622 
3623 !Output Parameters:
3624  void **data_new Generic pointer to the array to fill and return
3625 
3626 !Revision History:
3627 
3628  Revision 01.02 August 9, 2002
3629  Removed illegal printf statement.
3630  Gwyn Fireman, SAIC-GSO <Gwyn.Fireman@gsfc.nasa.gov>
3631 
3632  Revision 01.01 June 28, 2002 Razor Issue #161
3633  Handle expansion in memory, not files. Moved to L1B_Tables.c.
3634  Gwyn Fireman, SAIC-GSO <Gwyn.Fireman@gsfc.nasa.gov>
3635 
3636  Revision 01.00 December 31, 2001
3637  Initial development
3638  Gwyn Fireman, SAIC-GSO <fireman@mcst.gsfc.nasa.gov>
3639 
3640 !Team-unique Header:
3641  This software is developed by the MODIS Characterization Support
3642  Team (MCST)for the National Aeronautics and Space Administration,
3643  Goddard Space Flight Center, under contract NAS5-32373.
3644 
3645 !References and Credits:
3646  HDF portions developed at the National Center for Supercomputing
3647  Applications at the University of Illinois at Urbana-Champaign.
3648 
3649 !Design Notes:
3650 
3651 !END********************************************************************
3652 */
3653 {
3654  PGSt_SMF_status returnStatus = MODIS_S_OK;
3655  typedef enum {
3656  INT8, UINT8, INT16,
3657  UINT16, INT32, UINT32,
3658  FLOAT32, FLOAT64,
3659  NUM_DATA_TYPES
3660  } alltypes_t;
3661  int32 all_data_types[NUM_DATA_TYPES] = {
3662  DFNT_INT8, DFNT_UINT8, DFNT_INT16,
3663  DFNT_UINT16, DFNT_INT32, DFNT_UINT32,
3664  DFNT_FLOAT32, DFNT_FLOAT64
3665  };
3666  int32 data_var_size[NUM_DATA_TYPES] = {
3667  sizeof(int8), sizeof(uint8), sizeof(int16),
3668  sizeof(uint16), sizeof(int32), sizeof(uint32),
3669  sizeof(float32), sizeof(float64)
3670  };
3671 
3672  void * datap;
3673  float64 fill_64 = -999.0;
3674  int32 rank = 4;
3675  int32 dims[] = {0, /* override 2-d array dimensions */
3680  int32 i, i_type, arrsize;
3681  int32 i_T, i_B, i_D, i_S, i_M; /* loop indices for
3682  time, band, det, sf, ms */
3683  char *location = "Expand_BDSM_LUT";
3684 
3685 
3686 /************************ MACRO FOR INSERTING LUT VALUES *******************/
3687 #define INSERT_LUT_VALUES \
3688  /* for every LUT time, */ \
3689  i = 0; \
3690  for (i_T = 0; i_T < dims[0]; i_T++) \
3691  { \
3692  /* \
3693  * For every 250m Band, \
3694  * For every 250-m Detector, SubFrame and Mirror Side, \
3695  * Write value to new array. \
3696  */ \
3697  for (i_B = 0; i_B < NUM_250M_BANDS; i_B++) \
3698  for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3699  for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3700  for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3701  {data_temp[i] = *data_orig++; \
3702  i++;} \
3703  \
3704  /* \
3705  * For every 500m Band, \
3706  * For every 250-m Detector, SubFrame and Mirror Side, \
3707  * If Detector and SubFrame are meaningful for 500-m bands,\
3708  * Write value to new array. \
3709  */ \
3710  for (i_B = 0; i_B < NUM_500M_BANDS; i_B++) \
3711  for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3712  for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3713  for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3714  {if ((i_D < DETECTORS_PER_500M_BAND) && \
3715  (i_S < NUM_500M_SUBSAMP)) \
3716  data_temp[i] = *data_orig++; \
3717  i++;} \
3718  \
3719  /* \
3720  * For every 1km Reflective Solar Band, \
3721  * For every 250-m Detector, SubFrame and Mirror Side, \
3722  * If Detector and SubFrame are meaningful for 1km bands, \
3723  * Write value to new array. \
3724  */ \
3725  for (i_B = 0; i_B < NUM_1000M_REFL_BANDS; i_B++) \
3726  for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3727  for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3728  for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3729  {if ((i_D < DETECTORS_PER_1KM_BAND) && \
3730  (i_S < NUM_1KM_SUBSAMP)) \
3731  data_temp[i] = *data_orig++; \
3732  i++;} \
3733  \
3734  } /* i_T */
3735 
3736 /************************ END MACRO ************************/
3737 
3738 
3739  /* Calculate total number of values in new LUT array */
3740 
3741  dims[0] = lead_dim;
3742  for (arrsize = 1, i = 0; i < rank+1; i++)
3743  arrsize *= dims[i];
3744 
3745  /* Determine index of the data type. */
3746 
3747  for (i_type = 0; i_type < NUM_DATA_TYPES; i_type++) {
3748  if (all_data_types[i_type] == data_type) break;
3749  }
3750  if (i_type == NUM_DATA_TYPES)
3751  {
3752  returnStatus = MODIS_F_INVALID_ARGUMENT;
3753  L1BErrorMsg(location, returnStatus, "Invalid data type",
3754  "Expand_BDSM_LUT", 0, NULL, False);
3755  return returnStatus;
3756  }
3757  *n_bytes = arrsize * data_var_size[i_type];
3758 
3759  /* Allocate memory for new array */
3760 
3761  datap = malloc((unsigned) (*n_bytes));
3762  if (!(datap))
3763  {
3764  returnStatus = MODIS_F_OUT_OF_MEMORY;
3765  L1BErrorMsg(location, returnStatus, "Could not allocate memory",
3766  "Expand_BDSM_LUT", 0, NULL, False);
3767  return returnStatus;
3768  }
3769 
3770  /* Cast array to proper type, initialize to fill value and expand */
3771 
3772  if (data_type == DFNT_INT8)
3773  {
3774  int8 *data_orig = (int8 *)data;
3775  int8 *data_temp = (int8 *)datap;
3776  int8 fill_value = (int8)fill_64;
3777  for (i = 0; i < arrsize; i++)
3778  data_temp[i] = fill_value;
3780  *data_new = (void *) data_temp;
3781  }
3782  else if (data_type == DFNT_INT16)
3783  {
3784  int16 *data_orig = (int16 *)data;
3785  int16 *data_temp = (int16 *)datap;
3786  int16 fill_value = (int16)fill_64;
3787  for (i = 0; i < arrsize; i++)
3788  data_temp[i] = fill_value;
3790  *data_new = (void *) data_temp;
3791  }
3792  else if (data_type == DFNT_INT32)
3793  {
3794  int32 *data_orig = (int32 *)data;
3795  int32 *data_temp = (int32 *)datap;
3796  int32 fill_value = (int32)fill_64;
3797  for (i = 0; i < arrsize; i++)
3798  data_temp[i] = fill_value;
3800  *data_new = (void *) data_temp;
3801  }
3802  else if (data_type == DFNT_FLOAT32)
3803  {
3804  float32 *data_orig = (float32 *)data;
3805  float32 *data_temp = (float32 *)datap;
3806  float32 fill_value = (float32)fill_64;
3807  for (i = 0; i < arrsize; i++)
3808  data_temp[i] = fill_value;
3810  *data_new = (void *) data_temp;
3811  }
3812  else if (data_type == DFNT_FLOAT64)
3813  {
3814  float64 *data_orig = (float64 *)data;
3815  float64 *data_temp = (float64 *)datap;
3816  float64 fill_value = fill_64;
3817  for (i = 0; i < arrsize; i++)
3818  data_temp[i] = fill_value;
3820  *data_new = (void *) data_temp;
3821  }
3822  else returnStatus = MODIS_F_INVALID_ARGUMENT;
3823 
3824  return returnStatus;
3825 
3826 } /* end of Expand_BDSM_LUT */
3827 
3828 int32 BDSM_index (char *ascii_file)
3829 /*
3830 !C****************************************************************************
3831 !Description:
3832  Function returns index of LUT in refl_lut structure,
3833  or -1 if LUT is not a Reflective BDSM LUT.
3834 
3835 !Input Parameters:
3836  char *ascii_file name of the ASCII file holding the LUT
3837 
3838 !Output Parameters:
3839  (none)
3840 
3841 !Revision History:
3842 
3843  Revision 01.01 June 28, 2002 Razor Issue #161
3844  Moved to L1B_Tables.c.
3845  Gwyn Fireman, SAIC-GSO <Gwyn.Fireman@gsfc.nasa.gov>
3846 
3847  Revision 01.00 December 31, 2001
3848  Initial development
3849  Gwyn Fireman, SAIC-GSO <fireman@mcst.gsfc.nasa.gov>
3850 
3851 !Team-unique Header:
3852  This software is developed by the MODIS Characterization Support
3853  Team (MCST)for the National Aeronautics and Space Administration,
3854  Goddard Space Flight Center, under contract NAS5-32373.
3855 
3856 !References and Credits:
3857  HDF portions developed at the National Center for Supercomputing
3858  Applications at the University of Illinois at Urbana-Champaign.
3859 
3860 !Design Notes:
3861 
3862 !END********************************************************************
3863 */
3864 {
3865  int32 returnStatus = -1; /* return status */
3866  int32 i_lut; /* index of LUT in refl_lut structure */
3867  int32 nluts; /* number of LUTs in refl_lut structure */
3868  char **dimnames; /* name of each LUT dimension */
3869 
3870  /*
3871  * If LUT ascii name is null, then exit
3872  */
3873  if (!ascii_file)
3874  return returnStatus;
3875 
3876  /*
3877  * If LUT is not in refl_luts list, then exit
3878  */
3879  nluts = 0; /* find # of LUTs in structure */
3880  while (refl_luts[nluts].name) nluts++;
3881 
3882  for (i_lut = 0; i_lut < nluts; i_lut++)
3883  {
3884  if (refl_luts[i_lut].ascii_file) /* don't test against nulls */
3885  if (!strcmp (ascii_file, refl_luts[i_lut].ascii_file))
3886  break; /* found LUT name */
3887  }
3888 
3889  if (i_lut == nluts)
3890  return returnStatus;
3891 
3892  /*
3893  * If LUT is not of rank 4, then exit
3894  */
3895  if (refl_luts[i_lut].rank != 4)
3896  return returnStatus;
3897 
3898  /*
3899  * If LUT does not have BDSM dimensions, then exit
3900  */
3901  dimnames = refl_luts[i_lut].dimnames;
3902  if (strcmp (dimnames[0], "NUM_REFLECTIVE_BANDS") ||
3903  strcmp (dimnames[1], "MAX_DETECTORS_PER_BAND") ||
3904  strcmp (dimnames[2], "MAX_SAMPLES_PER_BAND") ||
3905  strcmp (dimnames[3], "NUM_MIRROR_SIDES"))
3906  return returnStatus;
3907 
3908  /*
3909  * LUT passes all tests;
3910  * return index of LUT in refl_lut structure
3911  */
3912  return returnStatus = i_lut;
3913 
3914 } /* end of BDSM_LUT_index */
#define QA_SERIAL_NUMBER_LUT_NAME
Definition: L1B_Tables.h:582
LUT_Definition_t emiss_luts[]
Definition: L1B_Tables.c:2084
#define SIGMA_RVS_EV_LUT_NAME
Definition: L1B_Tables.h:568
#define MIR_SIDE_2_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:598
#define MODIS_S_OK
int16 RFLAG
Definition: Granule.c:75
#define MODIS_F_FILE_NOT_FOUND
integer, parameter int16
Definition: cubeio.f90:3
char AlgorithmPackageMaturityCode[MAX_ALGORITHMPACKAGEMATURITYCODE_BUFFER]
Definition: L1B_Tables.h:888
#define QA_TABLES_FILE
Definition: FNames.h:76
#define BAND_21_B1_LUT_NAME
Definition: L1B_Tables.h:555
char MCST_LUT_Version[MAX_RUNTIME_PARAM_SIZE]
Definition: Granule.h:739
#define TEB_UI_SCALING_FACTOR_LUT_NAME
Definition: L1B_Tables.h:559
double FLOAT64
Definition: elements.h:8
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of tables
Definition: HISTORY.txt:695
#define TDLUT_INVALID
Definition: L1B_Tables.h:289
#define SV_DN_MOON_INCLUDE_FRAMES_LUT_NAME
Definition: L1B_Tables.h:552
#define U3_LUT_NAME
Definition: L1B_Tables.h:510
#define T_MIR_FUNCTION_FLAG_LUT_NAME
Definition: L1B_Tables.h:545
#define MAX_SAMPLES_PER_BAND
Definition: Granule.h:475
#define T_CAV_FUNCTION_FLAG_LUT_NAME
Definition: L1B_Tables.h:543
int j
Definition: decode_rs.h:73
#define B26_B5_CORR_SWITCH_LUT_NAME
Definition: L1B_Tables.h:503
#define BB_AVG_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:594
float32 X_OOB_0[NUM_SWIR_BANDS][MAX_DETECTORS_PER_SWIR_BAND][MAX_NUM_SWIR_SUBSAMPLES][NUM_MIRROR_SIDES]
Definition: L1B_Tables.h:624
PGSt_SMF_status Read_QA_Tables(L1A_granule_t *L1A_Gran, QA_tables_t *QA_tables)
Definition: L1B_Tables.c:1116
#define DN_STAR_MAX_LUT_NAME
Definition: L1B_Tables.h:473
float32 var_T_mir1
Definition: L1B_Tables.h:928
#define MIR_AVG_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:599
#define CALIB_A0_LUT_NAME
Definition: L1B_Tables.h:530
#define SIGMA_L_TSM_LUT_NAME
Definition: L1B_Tables.h:573
#define MAX_NUM_SWIR_SUBSAMPLES
Definition: L1B_Tables.h:387
float32 moon_offset_limits[NUM_BANDS][NUM_MOON_OFFSET_LIMITS]
Definition: L1B_Tables.h:900
#define NUM_T_INS_THERMISTORS
Definition: L1B_Tables.h:415
#define CAVITY_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:601
char * invalidinputfile
Definition: HDF_Lib.c:18
int32 TDLUT_GetAlgorithm(int32 sd_id, char *name)
Definition: L1B_Tables.c:2766
#define OVERLAP_SCANS_B1_LUT_NAME
Definition: L1B_Tables.h:554
#define NUM_2ND_ORDER_COEFFS
Definition: L1B_Tables.h:363
#define INT32
Definition: l1_imgscale.c:3
float32 a1[NUM_EMISSIVE_DETECTORS]
Definition: L1B_Tables.h:934
#define SIGMA_L_LAMBDA_LUT_NAME
Definition: L1B_Tables.h:571
#define MAX_NUM_RSR_vs_LAMBDA
Definition: L1B_Tables.h:405
emiss_QA_tables_t emiss_QA_tables
Definition: L1B_Tables.h:945
#define MAX_ALGORITHMPACKAGEMATURITYCODE_BUFFER
Definition: L1B_Tables.h:356
#define SIGMA_EPSILON_CAV_LUT_NAME
Definition: L1B_Tables.h:570
#define TDLUT_PIECEWISE_LINEAR_MAX_TIMES
#define FAIL
Definition: ObpgReadGrid.h:18
#define U2_FRAMES_LUT_NAME
Definition: L1B_Tables.h:512
#define T_INS_FUNCTION_FLAG_LUT_NAME
Definition: L1B_Tables.h:540
#define FALSE
Definition: rice.h:164
#define MODIS_F_OUT_OF_MEMORY
@ INDEX_500M
Definition: Granule.h:570
#define MAX_NC_NAME
Definition: Granule.h:9
#define NULL
Definition: decode_rs.h:63
#define TERRA
Definition: Granule.h:549
refl_QA_tables_t refl_QA_tables
Definition: L1B_Tables.h:944
#define EPSILON_CAV_LUT_NAME
Definition: L1B_Tables.h:521
#define MODIS_BAND26_INDEX
Definition: Granule.h:446
#define T_MIR_DEFAULT_LUT_NAME
Definition: L1B_Tables.h:546
#define NUM_PC_XT_BANDS
Definition: L1B_Tables.h:403
#define SIGMA_B1_BAND21_LUT_NAME
Definition: L1B_Tables.h:575
#define DN_STAR_MIN_LUT_NAME
Definition: L1B_Tables.h:474
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
PGSt_SMF_status Read_L1B_SDS_LUT(int32 sd_id, char *name, int32 data_type, int32 rank, int32 *dims, float64 data_collection_TAI_time, void *data)
Definition: L1B_Tables.c:2646
#define B26_B5_CORR_LUT_NAME
Definition: L1B_Tables.h:502
PGSt_SMF_status Expand_BDSM_LUT(void *data, void **data_new, int32 data_type, int32 lead_dim, int32 *n_bytes)
Definition: L1B_Tables.c:3656
#define ROLL_THRESHOLD_LUT_NAME
Definition: L1B_Tables.h:604
PGSt_SMF_status Read_Emiss_Tables(L1A_granule_t *L1A_Gran, emiss_tables_t *tables)
Definition: L1B_Tables.c:668
#define BB_DN_1ST_FRAME_LUT_NAME
Definition: L1B_Tables.h:548
#define L_MIN_LUT_NAME
Definition: L1B_Tables.h:556
#define MODIS_F_OUT_OF_RANGE
#define TDLUT_PIECEWISE_LINEAR_TIMES
Definition: L1B_Tables.h:295
#define TDLUT_STEPFUNCTION
Definition: L1B_Tables.h:291
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
#define PACKAGE_ACCEPT_DATE_LUT_NAME
Definition: L1B_Tables.h:584
#define RVS_BB_SV_FRAME_NO_LUT_NAME
Definition: L1B_Tables.h:526
#define SDS_LUT
Definition: L1B_Tables.h:456
float64 data_collection_time
Definition: Granule.h:755
const int NUM_MIRROR_SIDES
#define NUM_PVLW_XT_COEFF
Definition: L1B_Tables.h:401
#define RSB_UI_SCALING_FACTOR_LUT_NAME
Definition: L1B_Tables.h:498
#define NUM_EMISSIVE_DETECTORS
Definition: Granule.h:428
#define T_CAV_DEFAULT_LUT_NAME
Definition: L1B_Tables.h:544
#define CALIB_A1_LUT_NAME
Definition: L1B_Tables.h:603
float32 var_T_lwir
Definition: L1B_Tables.h:926
#define MAX_MISSION_PHASE_BUFFER
Definition: L1B_Tables.h:357
#define EMISS_SERIAL_NUMBER_LUT_NAME
Definition: L1B_Tables.h:519
#define DETECTORS_PER_1KM_BAND
Definition: Granule.h:438
float32 var_T_mir_avg
Definition: L1B_Tables.h:930
#define EPSILON_BB_LUT_NAME
Definition: L1B_Tables.h:520
#define MODIS_BAND20_INDEX
Definition: Granule.h:448
#define TDLUT_STEPFUNCTION_MAX_TIMES
#define T_INS_OFFSET_LUT_NAME
Definition: L1B_Tables.h:542
PGSt_SMF_status TDLUT_ReadPiecewiseLinearFunction(int32 sd_id, char *name, int32 data_type, int32 rank, int32 *dims, float64 data_collection_TAI_time, void *data)
Definition: L1B_Tables.c:3236
#define NUM_PVLW_XT_BANDS
Definition: L1B_Tables.h:400
#define CONTROL_OPTIONS_LUT_NAME
Definition: L1B_Tables.h:590
#define BB_DN_NUM_FRAMES_LUT_NAME
Definition: L1B_Tables.h:549
#define M0_LUT_NAME
Definition: L1B_Tables.h:471
#define U4_LUT_NAME
Definition: L1B_Tables.h:511
#define PCX_TALK_LUT_NAME
Definition: L1B_Tables.h:524
#define NUM_BITS_IN_UINT8
Definition: L1B_Tables.h:360
#define BASE_VARI_VISUAL_FPA_LUT_NAME
Definition: L1B_Tables.h:591
#define DELTA_T_BB_DELTA_LUT_NAME
Definition: L1B_Tables.h:523
#define SWIR_CORRECTION_SWITCH_LUT_NAME
Definition: L1B_Tables.h:493
#define TDLUT_STEPFUNCTION_TIMES
Definition: L1B_Tables.h:294
const int NUM_BANDS
const int NUM_DETECTORS
#define RVS_TEB_LUT_NAME
Definition: L1B_Tables.h:525
#define INST_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:600
#define EMISS_NEdL_LUT_NAME
Definition: L1B_Tables.h:602
short int INT16
Definition: elements.h:5
#define NUM_a2_vs_T_inst_COEFF
Definition: L1B_Tables.h:407
#define GLOBAL_ATTRIBUTE_LUT
Definition: L1B_Tables.h:455
#define EMISSIVE_TABLES_FILE
Definition: FNames.h:75
#define MAX_SERIAL_NUMBER_BUFFER
Definition: L1B_Tables.h:351
#define CALIB_A2_LUT_NAME
Definition: L1B_Tables.h:531
#define MISSION_PHASE_LUT_NAME
Definition: L1B_Tables.h:589
#define WAVELENGTH_LUT_NAME
Definition: L1B_Tables.h:528
#define L_MAX_LUT_NAME
Definition: L1B_Tables.h:557
#define MAX_DETECTORS_PER_SWIR_BAND
Definition: L1B_Tables.h:388
int16 L1A_BANDS_AT_RES[NUM_L1A_RESOLUTIONS]
Definition: Granule.c:63
float32 X_OOB_2[NUM_SWIR_BANDS][MAX_DETECTORS_PER_SWIR_BAND][MAX_NUM_SWIR_SUBSAMPLES][NUM_MIRROR_SIDES]
Definition: L1B_Tables.h:634
#define SIGMA_A2_LUT_NAME
Definition: L1B_Tables.h:567
#define AQUA
Definition: Granule.h:550
char MCST_Version[MAX_MCST_VERSION_BUFFER]
Definition: L1B_Tables.h:882
float32 var_NIR_FPA
Definition: L1B_Tables.h:915
@ NUM_CONTROL_OPTIONS
Definition: L1B_Tables.h:875
#define MODIS_F_READ_ERROR
uint8 Detector_Quality_Flag[NUM_DETECTORS]
Definition: L1B_Tables.h:895
#define SIGMA_L_TBB_LUT_NAME
Definition: L1B_Tables.h:572
#define X_OOB_0_LUT_NAME
Definition: L1B_Tables.h:494
#define TDLUT_PIECEWISE_LINEAR
Definition: L1B_Tables.h:292
#define EV_1km_FRAMES
Definition: Granule.h:469
#define X_OOB_1_LUT_NAME
Definition: L1B_Tables.h:495
float32 yaw_threshold_angle
Definition: L1B_Tables.h:905
#define PITCH_THRESHOLD_LUT_NAME
Definition: L1B_Tables.h:605
const int NUM_REFLECTIVE_BANDS
#define K_INST_LUT_NAME
Definition: L1B_Tables.h:475
PGSt_SMF_status Check_Valid_Range(char *data_name, int32 data_type, char *a_lb, char *a_ub, char *a_fillvalue, int32 count, void *buffer)
Definition: HDF_Lib.c:1782
#define PGE02_VERSION
Definition: L1B_Tables.h:340
#define NUM_SWIR_BANDS
Definition: L1B_Tables.h:386
#define NUM_1ST_ORDER_COEFFS
Definition: L1B_Tables.h:362
int8 noisy_detector[NUM_DETECTORS]
Definition: L1B_Tables.h:890
#define ASSIGN_DATA_PTR(luts, lutname, dataptr)
Definition: L1B_Tables.c:211
#define DELTA_T_BB_BETA_LUT_NAME
Definition: L1B_Tables.h:522
int8 noisy_subframe[NUM_HIGH_RESOLUTION_SUBFRAMES]
Definition: L1B_Tables.h:892
#define T_INST_REF_LUT_NAME
Definition: L1B_Tables.h:477
#define SWIR_CORR_SENDING_BAND_LUT_NAME
Definition: L1B_Tables.h:505
float32 var_T_mwir
Definition: L1B_Tables.h:927
#define TDLUT_ALGORITHM_ATTR_NAME
Definition: L1B_Tables.h:293
#define DET_QUAL_FLAG2_VALS_LUT_NAME
Definition: L1B_Tables.h:587
#define REFL_SERIAL_NUMBER_LUT_NAME
Definition: L1B_Tables.h:470
#define E_SUN_OVER_PI_LUT_NAME
Definition: L1B_Tables.h:499
#define RVS_RSB_LUT_NAME
Definition: L1B_Tables.h:479
#define INSERT_LUT_VALUES
#define T_FPA_REF_LUT_NAME
Definition: L1B_Tables.h:478
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file for both the L1A and Geolocation enabling retrieval of South Polar DEM data Resolved Bug by changing to opent the geolocation file only after a successful read of the L1A and also by checking for fatal errors from not restoring C5 and to report how many of those high resolution values were water in the new WaterPresent SDS Added valid_range attribute to Land SeaMask Changed to bilinearly interpolate the geoid_height to remove artifacts at one degree lines Made corrections to const qualification of pointers allowed by new version of M API library Removed casts that are no longer for same not the geoid Corrected off by one error in calculation of high resolution offsets Corrected parsing of maneuver list configuration parameter Corrected to set Height SDS to fill values when geolocation when for elevation and land water mask
Definition: HISTORY.txt:114
char PGE_Version[MAX_PGE_VERSION_BUFFER]
Definition: L1B_Tables.h:881
#define NUM_U2_FRAME
Definition: L1B_Tables.h:427
float32 var_T_mir2
Definition: L1B_Tables.h:929
#define MCST_VERSION_LUT_NAME
Definition: L1B_Tables.h:464
#define XT_UI_FACTOR_LUT_NAME
Definition: L1B_Tables.h:568
#define NUM_HIGH_RESOLUTION_DETECTORS
Definition: Granule.h:425
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
uint8 Detector_Quality_Flag2_Values[NUM_HIGH_RESOLUTION_DETECTORS][NUM_BITS_IN_UINT8]
Definition: L1B_Tables.h:897
#define DN_OBC_NUM_FRAMES_LUT_NAME
Definition: L1B_Tables.h:492
PGSt_SMF_status read_attribute(int32 s_id, char *attr_name, int32 TypeID, void *buffer)
Definition: HDF_Lib.c:33
float32 var_T_bb[NUM_BB_THERMISTORS]
Definition: L1B_Tables.h:924
#define MODIS_F_NOK
#define SV_DN_NUM_FRAMES_LUT_NAME
Definition: L1B_Tables.h:551
#define M1_LUT_NAME
Definition: L1B_Tables.h:472
char * dimnames[5]
Definition: L1B_Tables.h:317
char mission_phase[MAX_MISSION_PHASE_BUFFER]
Definition: L1B_Tables.h:901
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
#define RSB_SPECIFIED_UNCERTAINTY_LUT_NAME
Definition: L1B_Tables.h:497
#define BB_TEMP_VARIANCE_LUT_NAME
Definition: L1B_Tables.h:593
int8 dead_detector[NUM_DETECTORS]
Definition: L1B_Tables.h:889
#define T_INS_DEFAULT_LUT_NAME
Definition: L1B_Tables.h:541
#define DN_SAT_EV_LUT_NAME
Definition: L1B_Tables.h:501
#define PLATFORM_SHORT_NAME_LUT_NAME
Definition: L1B_Tables.h:583
#define True
Definition: Granule.h:537
#define K_FPA_LUT_NAME
Definition: L1B_Tables.h:476
#define TOLERANCE
Definition: Granule.h:535
#define SIGMA_A0_LUT_NAME
Definition: L1B_Tables.h:566
LUT_Definition_t qa_luts[]
Definition: L1B_Tables.c:2475
#define X_OOB_2_LUT_NAME
Definition: L1B_Tables.h:496
#define BASE_VARI_NIR_FPA_LUT_NAME
Definition: L1B_Tables.h:592
#define SWIR_CORR_SENDING_DETECTOR_LUT_NAME
Definition: L1B_Tables.h:506
#define MOON_OFFSET_LIMITS_LUT_NAME
Definition: L1B_Tables.h:588
#define TDLUT_CONSTANT
Definition: L1B_Tables.h:290
float32 roll_threshold_angle
Definition: L1B_Tables.h:903
#define B26_B5_FRAME_OFFSET_LUT_NAME
Definition: L1B_Tables.h:504
float32 pitch_threshold_angle
Definition: L1B_Tables.h:904
char AlgorithmPackageAcceptanceDate[MAX_ALGORITHMPACKAGEACCEPTANCEDATE_BUFFER]
Definition: L1B_Tables.h:886
#define NUM_WL_INCREMENT_LUT_NAME
Definition: L1B_Tables.h:529
char AssociatedPlatformShortname[MAX_ASSOCIATEDPLATFORMSHORTNAME_BUFFER]
Definition: L1B_Tables.h:884
#define FLOAT32
Definition: l1_imgscale.c:4
#define RSR_LUT_NAME
Definition: L1B_Tables.h:527
#define NUM_REFL_INDICES
Definition: Granule.h:444
char * corruptinputfile
Definition: HDF_Lib.c:20
int16 SWIR_corr_sending_detector[DETECTORS_PER_1KM_BAND]
Definition: L1B_Tables.h:620
int8 dead_subframe[NUM_HIGH_RESOLUTION_SUBFRAMES]
Definition: L1B_Tables.h:891
#define REFLECTIVE_TABLES_FILE
Definition: FNames.h:74
#define DET_QUAL_FLAG_VALS_LUT_NAME
Definition: L1B_Tables.h:586
float32 NEdL[NUM_EMISSIVE_DETECTORS]
Definition: L1B_Tables.h:933
PGSt_SMF_status Read_Refl_Tables(L1A_granule_t *L1A_Gran, refl_tables_t *tables)
Definition: L1B_Tables.c:231
#define fabs(a)
Definition: misc.h:93
LUT_Definition_t refl_luts[]
Definition: L1B_Tables.c:1779
float32 var_visual_FPA
Definition: L1B_Tables.h:914
Extra metadata that will be written to the HDF4 file l2prod rank
#define SIGMA_EPSILON_BB_LUT_NAME
Definition: L1B_Tables.h:569
#define NUM_a0_vs_T_inst_COEFF
Definition: L1B_Tables.h:406
const int NUM_T_MIR_THERMISTORS
char Serial_Number[MAX_SERIAL_NUMBER_BUFFER]
Definition: L1B_Tables.h:880
#define MAX_MCST_VERSION_BUFFER
Definition: L1B_Tables.h:353
uint8 Detector_Quality_Flag2[NUM_HIGH_RESOLUTION_DETECTORS]
Definition: L1B_Tables.h:898
#define NUM_REFLECTIVE_DETECTORS
Definition: Granule.h:427
#define MAX_1KM_OBC_FRAME_DIM
Definition: Granule.h:461
#define LWIR_FPA_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:595
#define U1_LUT_NAME
Definition: L1B_Tables.h:508
float32 X_OOB_1[NUM_SWIR_BANDS][MAX_DETECTORS_PER_SWIR_BAND][MAX_NUM_SWIR_SUBSAMPLES][NUM_MIRROR_SIDES]
Definition: L1B_Tables.h:629
float32 var_T_bb_avg
Definition: L1B_Tables.h:925
#define NUM_T_CAV_THERMISTORS
Definition: L1B_Tables.h:421
#define PVLW_XT_COEFF_LUT_NAME
Definition: L1B_Tables.h:569
#define U2_LUT_NAME
Definition: L1B_Tables.h:509
const int NUM_FOCAL_PLANES
int32 satellite_id
Definition: Granule.h:748
#define MODIS_F_HDF_ERROR
#define PACKAGE_MATURITY_CODE_LUT_NAME
Definition: L1B_Tables.h:585
PGSt_SMF_status TDLUT_ReadStepFunction(int32 sd_id, char *name, int32 data_type, int32 rank, int32 *dims, float64 data_collection_TAI_time, void *data)
Definition: L1B_Tables.c:2940
string msg
Definition: mapgen.py:227
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
#define NUM_RSB_RVS_COEFFS
Definition: L1B_Tables.h:428
#define NUM_PC_XT_PARAMETERS
Definition: L1B_Tables.h:404
#define MAX_DETECTORS_PER_BAND
Definition: Granule.h:474
int16 DETECT_PER_BAND_AT_RES[NUM_L1A_RESOLUTIONS]
Definition: Granule.c:68
#define R
Definition: make_L3_v1.1.c:96
#define MAX_ASSOCIATEDPLATFORMSHORTNAME_BUFFER
Definition: L1B_Tables.h:354
void L1BErrorMsg(char *L1B_location, PGSt_SMF_code code, char *input_message, char *assoc_function, int32 lun, char *other_msg, boolean error_out)
Definition: Granule.c:918
#define MWIR_FPA_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:596
#define MODIS_F_FILE_NOT_OPENED
const int NUM_MOON_OFFSET_LIMITS
int32 BDSM_index(char *ascii_file)
Definition: L1B_Tables.c:3865
#define YAW_THRESHOLD_LUT_NAME
Definition: L1B_Tables.h:606
const int NUM_EMISSIVE_BANDS
#define MAX_ALGORITHMPACKAGEACCEPTANCEDATE_BUFFER
Definition: L1B_Tables.h:355
int i
Definition: decode_rs.h:71
PGSt_SMF_status Read_Lookup_Tables(L1A_granule_t *L1A_Gran, lookup_tables_t *tables, Run_Time_Parameters_t *runtime_params)
Definition: L1B_Tables.c:31
#define MODIS_F_INVALID_ARGUMENT
const int NUM_BB_THERMISTORS
#define PGE_VERSION_LUT_NAME
Definition: L1B_Tables.h:463
uint8 control_options[NUM_CONTROL_OPTIONS]
Definition: L1B_Tables.h:902
#define DN_OBC_1ST_FRAME_LUT_NAME
Definition: L1B_Tables.h:491
#define MAX_PGE_VERSION_BUFFER
Definition: L1B_Tables.h:352
algorithm
Definition: DDProcess.h:25
#define PCX_CORRECTION_SWITCH_LUT_NAME
Definition: L1B_Tables.h:553
#define MAX_VAR_DIMS
Definition: Granule.h:10
PGSt_SMF_status read_sds_rankn(int32 sd_id, char *sds_name, int32 data_type, int32 rank, int32 *start, int32 *edge, void *data)
Definition: HDF_Lib.c:1478
#define SIGMA_L_TCAV_LUT_NAME
Definition: L1B_Tables.h:574
#define RSB_SV_DN_MOON_INCLUDE_FRAMES_LUT_NAME
Definition: L1B_Tables.h:500
common_QA_tables_t common_QA_tables
Definition: L1B_Tables.h:943
version
Definition: setup.py:15
#define TEB_SPECIFIED_UNCERTAINTY_LUT_NAME
Definition: L1B_Tables.h:558
#define BB_WEIGHT_LUT_NAME
Definition: L1B_Tables.h:547
#define False
Definition: Granule.h:538
uint8 Detector_Quality_Flag_Values[NUM_DETECTORS][NUM_BITS_IN_UINT8]
Definition: L1B_Tables.h:894
#define MIR_SIDE_1_TEMP_VAR_LUT_NAME
Definition: L1B_Tables.h:597
#define SV_DN_1ST_FRAME_LUT_NAME
Definition: L1B_Tables.h:550
#define SWIR_UI_FACTOR_LUT_NAME
Definition: L1B_Tables.h:513
int count
Definition: decode_rs.h:79