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