ocssw  1.0
/disk01/web/ocssw/build/src/l1bgen_modisa/Granule.h (r8218/r6020)
Go to the documentation of this file.
00001 #ifndef GRANULE_H
00002 #define GRANULE_H
00003 
00004 #include    "PGS_SMF.h"    /* define PGSt_SMF_status */  
00005 #include    "hdf.h"        /* contain prototype for hdf functions */
00006 #include    "mfhdf.h"      /* contain prototype for hdf functions */
00007 #include    "HdfEosDef.h"  /* contain prototype for eos hdf functions */
00008 
00009 /*
00010 !C-INC***********************************************************************
00011 !Description:  Public header file containing macros, structure definitions 
00012                and external function declarations.
00013 
00014 !Revision History:
00015    $Log: Granule.h,v $
00016    Revision 1.24  2011-04-07 14:40:12-04  xgeng
00017    1. RSB &TEB uncertainty algorithm update; 2. The quadratic RSB RVS changed to 4th order.
00018 
00019    Revision 1.23  2010-11-15 11:25:16-05  xgeng
00020    Defined a new fill value UNABLE_CALIBRATE_SI (65524); Added a new boolean member Electronic_Anomaly to structure QA_Common_t.
00021 
00022    Revision 1.22  2009/08/31 17:40:18  xgeng
00023    Change LOG to Log
00024 
00025    Revision 02.38, Janurary 7, 2008  Razor Issue #216
00026    Added a new constant "DEAD_SUBFRAME_SI" for dead subframe
00027    Added a new constant "NUM_HIGH_RESOLUTION DETECTORS"
00028    Added a new constant "NUM_HIGH_RESOLUTION SUBFRAMES"
00029    Added a new variable "dead_subframe_pixels" in L1B_granule_t
00030    Added a new variable "num_dead_subframe_EV_data" in QA_Common_t
00031    Xu Geng, SAIC GSO (xu.geng@saic.com)
00032 
00033    Revision 1.16  2006/10/27 15:02:54  ltan
00034    Added parameter PGE02_Version. Changed for ANSI-C compliance. Correction for the generation of code change log.
00035 
00036    Revision 02.37, October 31, 2003  Razor Issue #195
00037    Added ProcessingCenter to runtime parameters
00038    Liqin Tan, SAIC GSO (ltan@saicmodis.com)
00039 
00040    Revision 02.36 September 15, 2003  Razor Issue #181
00041    Added ProcessingEnvironment to runtime parameters
00042    Liqin Tan, SAIC GSO (ltan@saicmodis.com)
00043 
00044    Revision 02.35  March 26, 2003  Razor Issue #191
00045    Changed name of dn_28 to dn_X for use with any emissive band.
00046    Added band number to L1B_Scan structure type.
00047    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00048 
00049    Revision 02.32 June 28, 2002    Razor Issue #161
00050    Moved NUM_*_SUBSAMP definitions from Preprocess.h; added NUM_REFL_INDICES
00051    Gwyn Fireman, SAIC-GSO <Gwyn.Fireman@gsfc.nasa.gov>
00052 
00053    Revision 02.31   April 16, 2002  Razor Issue #166
00054    Added leading_granule_scan_gap and trailing_granule_scan_gap to 
00055       QA_Common_t
00056    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00057 
00058    Revision 02.29 March 19, 2002  Razor Issue #182
00059    Applicable to MODIS/TERRA (PFM) processing only.
00060    Added b26_fr_b5_scaled_corr to RSB_Cal_Coeff_t.
00061    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00062 
00063    Revision 02.28 March 10, 2002  Razor Issue #174
00064    Added RVS tables to RSB_Cal_Coeff_t.  Defined TEB_Cal_Coeff_t to hold
00065       RVS tables.   
00066    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00067 
00068    Revision 02.27 February 7, 2002  Razor Issue #180
00069    Added flag TEB_B1_NOT_CALCULATED and counter for it in QA_Common.
00070    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00071 
00072    Revision 02.26 December 14, 2001
00073    Changed MAX_*_TRACK_DIM parameters so that they are automatically determined
00074    by MAX_NUM_SCANS.  
00075    Alice Isaacman, SAIC GSO (Alice.R.Isaacman.1@gsfc.nasa.gov)
00076 
00077    Revision 02.25 November 12, 2001       (Razor Issue #169)
00078    Added boolean skip_night_hi_res to prototype for Close_L1B_Granule.
00079    Added Write_Night_Mode_HiRes_Data to Run_Time_Parameters_t
00080    Alice Isaacman (Alice.R.Isaacman.1@gsfc.nasa.gov), SAIC GSO
00081 
00082    Revision 02.24  November 6, 2001
00083    Added MCST_LUT_Version to Run_Time_Parameters_t (Razor issue #167)
00084    Alice Isaacman (Alice.R.Isaacman.1@gsfc.nasa.gov), SAIC GSO
00085 
00086    Revision 02.23  Sept. 28, 2001
00087    Eliminated use of defined PI value due to conflict with SDP Toolkit 5.2.7
00088    (PI was defined to be PGS_PI in any case) (Razor issue #168)
00089    Alice Isaacman (Alice.R.Isaacman.1@gsfc.nasa.gov), SAIC GSO
00090 
00091    Revision 02.22  Feb 22, 2001, Issue 155
00092    Added Run_Time_Parameters_t and Read_Run_Time_Parameters.
00093    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00094 
00095    Revision 02.21  Jan 29, 2001
00096    Corrected variable names and simplified L1A_Scan_t.
00097    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00098 
00099    Revision 02.21  Dec. 5, 2000
00100    Razor issue 147.
00101    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00102 
00103    Revision 02.20  Dec. 1, 2000
00104    Added dn_28 to L1B_Scan_t
00105    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00106 
00107    Revision 02.19  October 29, 2000
00108    Added new unusable data value for L > L_Max as per issue 139.
00109    Added code for granule average QA values as per issue 140.
00110    Added structure element to L1A_granule_t, Razor issue 142.
00111    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00112 
00113    Revision 02.18  September 21, 2000
00114    Added counting num_rsb_at_night_scans as per issue 137.
00115    Jim Rogers (rogers@mcst.gsfc.nasa.gov)
00116 
00117    ... (many changes not logged) ...
00118 
00119  Revision 02.17 Nov 05, 1999
00120  Change momos_t to RSB_Cal_Coeff_t and add new variables
00121  Zhenying Gu (zgu@mcst.gsfc.nasa.gov)
00122 
00123  Revision 02.16 Sep 30, 1999
00124  Made num_thermistor_outliers dimensioned [MAX_NUM_SCANS] in QA_Emiss_t
00125  Jim Rogers (rogers@msct.gsfc.nasa.gov)
00126 
00127  Revision 02.15 May 13, 1999
00128  Added band 26 section.
00129  Jim Rogers (rogers@msct.gsfc.nasa.gov)
00130 
00131  Revision 02.14 Feb 22, 1999
00132  Added macros INDEX_1000M_DAY and INDEX_1000M_NIGHT to allow clarity
00133  uf usage elsewhere in the code.
00134  Jim Rogers (rogers@msct.gsfc.nasa.gov)
00135 
00136  Revision 02.13 Feb 8, 1999
00137  Moved definition of L1B_Scan_Metadata_t to L1B_SetupP.h since that structure
00138  is local in scope to L1B_Setup.c
00139  Jim Rogers (rogers@msct.gsfc.nasa.gov)
00140 
00141  Revision 02.12 Feb 2, 1999
00142  Separated out parts belonging to L1B_Setup as part of the
00143  process of separating L1B_Setup out into its own module.
00144  Added L1B_BANDS_AT_RES as an external declaration.
00145  Jim Rogers (rogers@msct.gsfc.nasa.gov)
00146 
00147  Revision 02.11 July 1998
00148  Add Write_L1B_SI_UI() prototype
00149  Zhenying Gu (zgu@ltpmail.gsfc.nasa.gov)
00150   
00151  Revision 02.10 April 13, 1998.
00152  Removed the SUN_EARTH_DIST_ADJUST() and DAYS_IN_YEAR macros.
00153  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
00154 
00155  Revision 02.10 April 10, 1998.
00156  Changed the L1A_granule_t's EVStartTime_TAIsecond, MirrorSide, and
00157  ScanType from pointers to static arrays.
00158  Removed the L1B_granule_t's SunAdj, EVStartTime_TAIday, 
00159  and EVStartTime_TAIyear.
00160  Added momos_t variable to L1B_granule_t.
00161  Removed the following from L1B_ScaleOffset_t:
00162    rad_scale_RefSB
00163    rad_offset_RefSB
00164    refl_scale_RefSB
00165    refl_offset_RefSB
00166  (they're replaced by the momos_t)
00167  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
00168  
00169  Revision 02.10 April 1998
00170  Added L1B_Scan_metadat_t structure.
00171  Zhenying Gu (zgu@gscmail.gsfc.nasa.gov)
00172  
00173  Revision 02.10 April 1998.
00174  Added the momos_t structure.
00175  David Catozzi (cato@ltpmail.gsfc.nasa.gov)
00176 
00177  Revision 02.10 March 1998.
00178  Add ADC, PCX and INT correction switch 
00179  Add emiss_band_index_t data structure
00180  Shi-Yue Qiu (syqiu@ltpmail.gsfc.nasa.gov)
00181 
00182  Revision 02.00 March 1997.
00183  Summarizes Geom_Param_Lib.h, Granule.h, L1A_to_L1B.h, ......
00184  Zhidong Hao (hao@barebackride.gsfc.nasa.gov)
00185 
00186  Revision 01.01 1996/04/09
00187  Updated to match Version 1 Design Document.
00188  John Hannon(hannon@highwire.gsfc.nasa.gov)
00189  Neal Devine(devine@ltpmail.gsfc.nasa.gov)
00190  Joan Baden (baden@highwire.gsfc.nasa.gov)
00191 
00192  Revision 01.00 1993
00193  Initial development
00194  Geir E. Kvaran(geir@highwire.gsfc.nasa.gov)
00195 
00196  Revision 01.00 Nov. 1998
00197  This is part of original Granule.h, L1B.h
00198  Initial development
00199  Zhenying Gu(zgu@mcst.gsfc.nasa.gov)
00200 
00201 !Team-unique Header:
00202    This software is developed by the MODIS Characterization Support
00203    Team (MCST)for the National Aeronautics and Space Administration,
00204    Goddard Space Flight Center, under contract NAS5-32373.
00205 
00206 !References and Credits:
00207    HDF portions developed at the National Center for Supercomputing
00208    Applications at the University of Illinois at Urbana-Champaign.
00209 
00210 !Design Notes:
00211    
00212 1. L1A Granule.  The L1A granule contains 4 HDF SDSs, each corresponding
00213    to a group of MODIS bands:
00214 
00215    L1A SDS name               MODIS bands
00216    ------------    ---------------------------------------------------------
00217    "XX_250m"       1,2
00218    "XX_500m"       3,4,5,6,7
00219    "XX_1km_day"    8,9,10,11,12,13lo,13hi,14lo,14hi,15,16,17,18,19
00220    "XX_1km_night"  20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36
00221 
00222    where:
00223 
00224    XX = SD        (Solar Diffusor)
00225    XX = SRCA      (Spectro-Radiometric Calibration Assembly)
00226    XX = BB        (Black Body)
00227    XX = SV        (Space View)
00228    XX = EV        (Earth View)
00229 
00230    "lo" and "hi" refer to two different gain levels.  Thus, 13lo and 13hi
00231    are treated as different bands even though they have the same center
00232    wavelegnth.  Similarly for 14lo and 14hi.  Thus, MODIS has 36 different
00233    center wavelengths but 38 different "bands" of data.
00234 
00235    Within the code, we refer to the above L1A SDSs as 4 "resolutions", even
00236    though the last two groups have the same resolution (1km).  All SDSs are
00237    present in one L1A granule HDF file.  The logic implemented in
00238    "Open_L1A_EV_SDS" is that each of the above SDSs must be present in the
00239    L1A granule.  If any is missing, then the function returns a
00240    MODIS_F_READ_ERROR.  The logic implemented in "Read_L1A_EV_Scan" (which
00241    reads one scan) is that the "EV_1km_night" data are always read but the
00242    other three are read only if the scan type is "DAY".
00243 
00244    Each L1A input granule covers a time period of approximately 5 minutes.
00245    The actual number of scans will be either 203 or 204, depending on how a
00246    scan fits into the granule (there are always whole scans in the granule).
00247    Thus, the maximum number of scans that can occur in an L1A granule is 204.
00248 
00249 2. L1B Granules.  The L1B EV granules group the MODIS bands slightly
00250    differently than the above L1A SDSs.  Band 26 (in the L1A "night" group)
00251    is placed in the 1km reflective solar band (RefSB) group.
00252 
00253    L1B SDSs                   MODIS bands
00254    ------------       ------------------------------------------------------
00255    "EV_250_RefSB"     1,2
00256    "EV_500_RefSB"     3,4,5,6,7
00257    "EV_1KM_RefSB"     8,9,10,11,12,13lo,13hi,14lo,14hi,15,16,17,18,19,26
00258    "EV_1KM_Emissive"  20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36
00259 
00260    The L1B SDSs are placed in three L1B output HDF files which are based on
00261    resolution (see the file specifications).  This includes aggregation of
00262    the higher-resolution SDSs to a lower resolution.
00263 
00264    In the code, when we fill the L1B SDSs from the L1A data, there is logic
00265    which specifically deals with MODIS band 26. 
00266 
00267 3. Detectors.  There are different numbers of detectors based on band
00268    resolution.  Also note that bands 13 and 14 also each have two sets
00269    of detectors.  In terms of the L1B SDSs:
00270 
00271    L1B SDSs           # of detectors      total in all bands of this res.
00272    ----------         --------------      ------------------------------
00273    "EV_250_RefSB"          40                        80
00274    "EV_500_RefSB"          20                       100
00275    "EV_1KM_RefSB"          10                       150
00276    "EV_1KM_Emissive"       10                       160
00277 
00278    Thus, the total number of detectors is 490.
00279 
00280 4. Coordinate system:
00281 
00282       |---------------- ALONG SCAN ---------------->
00283       |
00284       |      --------------------------------------
00285       |      --------------------------------------
00286       |      --------------------------------------
00287     ALONG    -------------- SCAN LINES ------------
00288     TRACK    --------------------------------------
00289       |      --------------------------------------
00290       |      --------------------------------------
00291       |      --------------------------------------
00292      \|/     --------------------------------------
00293 
00294    For one sweep of the MODIS scan mirror, the number of scan lines generated
00295    equals the number of detectors (which is dependent on band). The number of
00296    samples generated along a scan line is also dependent on band (the 250m
00297    bands being sampled at 0.25km IFOV, the 500m bands being sampled at 0.5km
00298    IFOV and the 1km bands being sampled at 1km IFOV).
00299 
00300    Thus, for a given sweep of the mirror, 250m resolution bands have 4 times
00301    the number of scan lines as 1km resolution bands since they have 4 times
00302    the number of detectors.  Similarly, for a given aperture width (such as
00303    the earth view), 250m resolution bands have 4 times the number of samples
00304    ("FRAMES") as 1km resolution bands.
00305 
00306    In the macros below, the following terminology is used:
00307      "TRACK_DIM"    refers to scan lines in the along-track direction
00308      "FRAME_DIM"    refers to samples in the along-scan direction.
00309      "1km_FRAMES"   refers to samples taken at the rate of 1km IFOV
00310      "500m_FRAMES"  refers to samples taken at the rate of 0.5km IFOV
00311      "250m_FRAMES"  refers to samples taken at the rate of 0.25km IFOV
00312 
00313 5. Aperture widths.  The following table relates the basic aperture widths 
00314    in terms of 1km frames:
00315 
00316       Aperture       acronym       # 1km_frames
00317      ----------      -------       ------------
00318      earth view        EV             1354
00319      space view        SV               50
00320      black body        BB               50
00321      SRCA              SRCA             10
00322      solar diffuser    SD               50      
00323 
00324 !END***********************************************************************
00325 */
00326 
00327 /***************************************************************************
00328 Band/Detector/Frame Geometry constants
00329 --------------------------------------
00330   MAX_NUM_SCANS             Maximum number of scans in one 5-minute granule.
00331   NUM_BANDS                 Number of bands (see note 1 above).
00332   NUM_DETECTORS             Total number of detectors for all bands.
00333   NUM_HIGH_RESOLUTION_DETECTORS   Total number of detectors in 250m and 500m bands.
00334   NUM_HIGH_RESOLUTION_SUBFRAMES   Total number of subframes in 250m and 500m bands.
00335   NUM_REFLECTIVE_DETECTORS  Total number of detectors for the L1B reflective
00336                             solar bands (RefSB).
00337   NUM_EMISSIVE_DETECTORS    Total number of detectors for the L1B emissive
00338                             bands (16 emissive bands, 10 detectors each).
00339   NUM_MIRROR_SIDES          Number of mirror sides (2).
00340   NUM_250M_BANDS            Number of 250m-resolution bands (2).
00341   NUM_500M_BANDS            Number of 500m-resolution bands (5).
00342   NUM_1000M_REFL_BANDS      Number of L1B reflective solar bands that have
00343                             1km resolution.
00344   NUM_REFLECTIVE_BANDS      Total number of L1B reflective solar bands.  This
00345                             is the sum of NUM_250M_BANDS, NUM_500M_BANDS and
00346                             NUM_1000M_REFL_BANDS.
00347   NUM_1000M_EMISS_BANDS     Number of L1B 1km-resolution emissive bands.
00348                             Since all emissive bands are 1km-resolution bands,
00349                             this macro means the same as the one below.
00350   NUM_EMISSIVE_BANDS        Number of L1B emissive bands.
00351   NUM_1000M_DAY_BANDS       Number of bands in the "EV_1km_day" L1A SDS.
00352   NUM_1000M_NIGHT_BANDS     Number of bands in the "EV_1km_night" L1A SDS.
00353   DETECTORS_PER_1KM_BAND    Number of detectors in any 1km-resolution band.
00354   DETECTORS_PER_500M_BAND   Number of detectors in any 500m-resolution band.
00355   DETECTORS_PER_250M_BAND   Number of detectors in any 250m-resolution band.
00356   NUM_1KM_SUBSAMP           Number of subsamples per frame in any 
00357                             1km-resolution band.
00358   NUM_500M_SUBSAMP          Number of subsamples per frame in any 
00359                             500m-resolution band.
00360   NUM_250M_SUBSAMP          Number of subsamples per frame in any 
00361                             250m-resolution band.
00362   NUM_REFL_INDICES          Total number of valid reflective 
00363                             band/detector/subframe/mirror side combinations.
00364   MODIS_BAND26_INDEX        For the set of 38 bands of this code (indexed 0
00365                             through 37), this is the index for MODIS band 26.
00366   MODIS_BAND26_INDEX_AT_RES For the set of 17 L1A 1km night bands (indexed
00367                             0 through 16), this is the index corresponding to
00368                             MODIS band 26.
00369   MODIS_BAND20_INDEX        For the set of 38 bands of this code (indexed 0
00370                             through 37), this is the index for MODIS band 20.
00371   MAX_250M_TRACK_DIM        Maximum number of scan lines spanning the along-
00372                             track dimension of the entire granule for any 250m
00373                             resolution band. This equals the maximum number of
00374                             scans times the number of detectors for 250m
00375                             resolution).
00376   MAX_500M_TRACK_DIM        Maximum number of scan lines for any 500m
00377                             resolution band. 
00378   MAX_1KM_TRACK_DIM         Maximum number of scan lines for any 1km
00379                             resolution band.
00380   MAX_SWIR_TRACK_DIM        Maximum number of scan lines for any SWIR band.
00381   MAX_250M_OBC_FRAME_DIM    Maximum number of 1km frames in any of the OBC
00382                             data sets (50) times the number of subsamples per
00383                             frame for a 250m-resolution band (4)
00384   MAX_500M_OBC_FRAME_DIM    Maximum number of 1km frames in any of the OBC
00385                             data sets (50) times the number of subsamples per
00386                             frame for a 500m-resolution band (2)
00387   MAX_1KM_OBC_FRAME_DIM     Maximum number of 1km frames in any of the OBC
00388                             data sets (50).
00389   SRCA_250M_FRAME_DIM       Number of 1km frames for the SRCA data sets (10)
00390                             times the number of subsamples per frame for a
00391                             250m-resolution band (4).
00392   SRCA_500M_FRAME_DIM       Number of 1km frames for the SRCA data sets (10)
00393                             times the number of subsamples per frame for a
00394                             500m-resolution band (2).
00395   SRCA_1KM_FRAME_DIM        Number of 1km frames for the SRCA data sets (10).
00396   TOTAL_1km_FRAMES          Total number of EV, SV, BB, SRCA and SD 1km frames.
00397   EV_1km_FRAMES             Number of earth view 1km frames.
00398   EV_250m_FRAMES            Number of earth view 250m frames
00399                             (EV_1km_FRAMES * 4).
00400   EV_500m_FRAMES            Number of earth view 500m frames
00401                             (EV_1km_FRAMES * 2).
00402   SD_1km_FRAMES             Number of solar diffusor 1km frames.
00403   SRCA_1km_FRAMES           Number of SRCA 1km frames.
00404   BB_1km_FRAMES             Number of black-body 1km frames.
00405   SV_1km_FRAMES             Number of space view 1km frames.
00406   NADIR_1km_FRAME_NUM       The 1km frame number nominally desginated as
00407                             the center frame number of the earth-view window.
00408   MAX_DETECTORS_PER_BAND    Maximum number of detectors in any band 
00409                             (occurs in the 250m bands).
00410   MAX_SAMPLES_PER_BAND      Maximum number of subsamples in a 1km frame for
00411                             any band (occurs in the 250m bands).
00412 ****************************************************************************/
00413 #define    NUM_SCANS_DIM_NAME       "nscans"
00414 
00415 /* Normally MAX_NUM_SCANS should be 204. However, the number of scans could
00416  * reach 208 due to a L1A abnormality. So, define it to be 208.
00417  */
00418 
00419 #define    MAX_NUM_SCANS           1000
00420 #define    NUM_BANDS                 38
00421 #define    NUM_DETECTORS            490
00422 #define    NUM_HIGH_RESOLUTION_DETECTORS            180
00423 #define    NUM_HIGH_RESOLUTION_SUBFRAMES            520
00424 #define    NUM_REFLECTIVE_DETECTORS 330
00425 #define    NUM_EMISSIVE_DETECTORS   160
00426 #define    NUM_MIRROR_SIDES           2
00427 #define    NUM_250M_BANDS             2
00428 #define    NUM_500M_BANDS             5
00429 #define    NUM_1000M_REFL_BANDS      15
00430 #define    NUM_REFLECTIVE_BANDS      22
00431 #define    NUM_1000M_EMISS_BANDS     16
00432 #define    NUM_EMISSIVE_BANDS        16
00433 #define    NUM_1000M_DAY_BANDS       14
00434 #define    NUM_1000M_NIGHT_BANDS     17
00435 #define    DETECTORS_PER_1KM_BAND    10
00436 #define    DETECTORS_PER_500M_BAND   20      
00437 #define    DETECTORS_PER_250M_BAND   40 
00438 #define    NUM_1KM_SUBSAMP            1
00439 #define    NUM_500M_SUBSAMP           2
00440 #define    NUM_250M_SUBSAMP           4
00441 #define    NUM_REFL_INDICES        1340
00442 #define    MODIS_BAND5_INDEX          4    
00443 #define    MODIS_BAND26_INDEX        27
00444 #define    MODIS_BAND26_INDEX_AT_RES  6
00445 #define    MODIS_BAND20_INDEX        21
00446 
00447 #define    L1B_1KM_EMISS_BAND28_INDEX  7    /* emissive band group */
00448 
00449 /* The four macros below are related to the macro MAX_NUM_SCANS. */
00450 
00451 #define    MAX_250M_TRACK_DIM      MAX_NUM_SCANS*DETECTORS_PER_250M_BAND  /* 8320 */  /* 208 * 40 */
00452 #define    MAX_500M_TRACK_DIM      MAX_NUM_SCANS*DETECTORS_PER_500M_BAND  /* 4160 */
00453 #define    MAX_1KM_TRACK_DIM       MAX_NUM_SCANS*DETECTORS_PER_1KM_BAND   /* 2080 */
00454 #define    MAX_SWIR_TRACK_DIM      MAX_NUM_SCANS*DETECTORS_PER_500M_BAND  /* 4160 */
00455 
00456 #define    MAX_250M_OBC_FRAME_DIM   200   /* 50 * 4 */
00457 #define    MAX_500M_OBC_FRAME_DIM   100   /* 50 * 2 */
00458 #define    MAX_1KM_OBC_FRAME_DIM     50 
00459 #define    SRCA_250M_FRAME_DIM       40    /* 10 * 4 */
00460 #define    SRCA_500M_FRAME_DIM       20
00461 #define    SRCA_1KM_FRAME_DIM        10
00462 #define    SD_1km_FRAMES             50
00463 #define    SRCA_1km_FRAMES           10
00464 #define    BB_1km_FRAMES             50
00465 #define    SV_1km_FRAMES             50
00466 #define    EV_1km_FRAMES           1354
00467 #define    EV_250m_FRAMES          5416
00468 #define    EV_500m_FRAMES          2708 
00469 #define    TOTAL_1km_FRAMES        1514
00470 #define    NADIR_1km_FRAME_NUM      677
00471 #define    MAX_DETECTORS_PER_BAND    40
00472 #define    MAX_SAMPLES_PER_BAND       4
00473 
00474 
00475 /* Three correction switch in Emissive Band */
00476 typedef enum { OFF, ON } switch_t ;
00477 
00478 #define  SCAN_TYPE_TEXT_SIZE       10
00479 #define  COMMON_TEXT_SIZE          10
00480 #define  MAX_ERROR_MESSAGE_LENGTH  1024 
00481 
00482 #define  NUM_BB_THERMISTORS        12
00483 #define  NUM_FOCAL_PLANES           4
00484 
00485 #define SCAN_QUALITY_ARRAY_NUM_ELEMENTS 4
00486 
00487 #define PGS_PI          3.14159265358979323846
00488 
00489 #define PGS_EXP     2.7182818284590452354
00490 
00491 #define SAME       0 /*Used with strcmp()*/
00492 
00493 /*
00494  * Macros for L1B sector DNs, to be used with the Check_Valid_Range
00495  * function.  Note that the HDF default is currently used in the
00496  * L1A code (does not comply with file specs, but we must allow it).
00497  *   L1A_DN_SDS_LB -- lower bound
00498  *   L1A_DN_SDS_UB -- upper bound
00499  *   L1A_DN_SDS_FV -- fill value
00500  * These are strings since that is the interface to Check_Valid_Range.
00501  */
00502 
00503 #define L1A_DN_SDS_LB        "-1"
00504 #define L1A_DN_SDS_UB        "4095"
00505 #define L1A_DN_SDS_FV        "-32767"  /* HDF default */
00506 
00507 #define HDF_DEFAULT_FILLVALUE    -32767
00508 #define SATURATED_DN      4095
00509 
00510 #define MISSING_L1B_DATA  65535 
00511 #define MISSING_L1B_UI      255
00512 #define MISSING_L1A_FLAG    -1 
00513 
00514 #define L1A_SCAN_DATA_MISSING_SI 65535
00515 #define L1A_DN_MISSING_SI        65534
00516 #define SATURATED_DETECTOR_SI    65533
00517 #define ZERO_POINT_DN_SI         65532
00518 #define DEAD_DETECTOR_SI         65531
00519 #define RSB_DN_STAR_BELOW_MIN_SI 65530    
00520 #define TEB_OR_RSB_GT_MAX_SI     65529
00521 #define AGGREGATION_FAIL_SI      65528
00522 #define SECTOR_ROTATION_SI       65527
00523 #define TEB_B1_NOT_CALCULATED    65526
00524 #define DEAD_SUBFRAME_SI         65525
00525 #define UNABLE_CALIBRATE_SI      65524
00526 #define UNRESCALED_HIGH_SI       65521
00527 #define RESCALED_L1B_SI          65520
00528 #define NAD_CLOSED_UPPER_SI      65500
00529 #define L1A_SCAN_DATA_MISSING_UI 255
00530 #define BAD_DATA_UI              15
00531 
00532 #define TOLERANCE      1.0E-20  /* defined zero */
00533 
00534 #define True                         1
00535 #define False                        0
00536 
00537 /* Focal Plane Indices */
00538 
00539 #define VIS  0
00540 #define NIR  1
00541 #define SWIR 2
00542 #define LWIR 3
00543 
00544 /* satellite ID */
00545 
00546 #define TERRA 0
00547 #define AQUA  1
00548 #define INVALID_SATELLITE_ID -1
00549 
00550 /* MOD_PR02 exit code */
00551 
00552 extern int32 MOD_PR02_Failure_Exit_Code;
00553 
00554 /*****************************************************************************
00555  The following defines macros for the number of L1A or L1B "resolutions" (or
00556  groupings of bands) and the indices representing the ordering of the
00557  resolutions in arrays.  Even though INDEX_1000M_DAY and INDEX_1000M_REFL are
00558  both the same value, they represent different band groupings because of
00559  MODIS band 26 (see earlier comments).  Currently, the code uses these macros
00560  somewhat inconsistently, so beware.  Similar comments apply to
00561  INDEX_1000M_NIGHT and INDEX_1000M_EMISS.
00562  *****************************************************************************/
00563 typedef  int8  boolean;
00564 
00565 typedef enum {
00566   INDEX_250M,
00567   INDEX_500M,
00568   INDEX_1000M_DAY,
00569   INDEX_1000M_NIGHT,
00570   NUM_L1A_RESOLUTIONS
00571 } resolution_index_t;
00572 #define INDEX_1000M_REFL  INDEX_1000M_DAY
00573 #define INDEX_1000M_EMISS INDEX_1000M_NIGHT
00574 
00575 /*****************************************************************************
00576  The following defines macros for the number of earth-view products generated
00577  and indices for each product.
00578  *****************************************************************************/
00579 
00580 typedef enum {
00581   INDEX_L1B_250m,
00582   INDEX_L1B_500m,
00583   INDEX_L1B_1km,
00584   NUM_L1B_EV_FILES
00585 } L1B_EV_FILE_index_t;
00586 
00587 /***************************************************************************
00588  L1B_BANDS_AT_RES         Number of bands in each L1B "resolution"
00589                           (group of bands -- see notes at top)
00590  L1A_BANDS_AT_RES         Number of bands in each L1A "resolution"
00591                           (group of bands -- see notes at top)
00592  DETECT_PER_BAND_AT_RES   Number of detectors in any band of the 4 different
00593                           "resolutions" (same for both L1A and L1B even though
00594                           the "groupings" are defined slightly differently).
00595  BAND_RATIO_AT_RES        This is the ratio of the #samples at a resolution to
00596                           the number of samples at a 1km resolution (also the
00597                           ratio of the number of detectors relative to the
00598                           number of detectors for a 1km resolution band).
00599                           Same for both L1A and L1B "resolutions".
00600  **************************************************************************/
00601 extern int32 SUBSAMPLES_AT_RES[NUM_L1A_RESOLUTIONS];
00602 
00603 extern int16 L1B_BANDS_AT_RES[NUM_L1A_RESOLUTIONS];
00604 
00605 extern int16 L1A_BANDS_AT_RES[NUM_L1A_RESOLUTIONS]; 
00606 
00607 extern int16 DETECT_PER_BAND_AT_RES [NUM_L1A_RESOLUTIONS]; 
00608 
00609 extern int16 BAND_RATIO_AT_RES[NUM_L1A_RESOLUTIONS];
00610 
00611 typedef enum {
00612   Orbital_Node,
00613   Number_Of_Scans,
00614   Number_Day_Scans,
00615   Number_Night_Scans,
00616   Total_Frames,
00617   Earth_Frames,
00618   SD_Frames,
00619   SRCA_Frames,
00620   BB_Frames,
00621   SV_Frames,
00622   Scan_Type,
00623   Incomplete_Scans,
00624   Missing_Packets,
00625   Packets_With_Bad_CRC,
00626   Discarded_Packets, 
00627   NUM_L1A_ATTRIBUTES
00628 } L1A_attr_index_t;
00629 
00630 typedef enum {
00631   SD_INDEX,
00632   SRCA_INDEX,
00633   BB_INDEX,
00634   SV_INDEX,
00635   EV_INDEX,
00636   NUM_TARGETS
00637 } target_index_t;
00638 
00639 typedef enum {
00640   BAND20, BAND21, BAND22, BAND23, BAND24, BAND25, BAND26, BAND27, BAND28,
00641   BAND29, BAND30, BAND31, BAND32, BAND33, BAND34, BAND35, BAND36, NUM_NIGHT_BANDS 
00642 } night_band_index_t;
00643 
00644 /******************************************************************************
00645  * Define macros for granule average quantities.
00646  *
00647  * NOTE 1: the code uses loops when assigning some of these quantities.
00648  * In particular, the number and order of BB, INS, CAV and RC temperatures
00649  * must match the arrays defined in Temperatures_t in PreprocessP.h
00650  * and the calculations in Read_Convert_Temperatures.
00651  * Consequently, these cannot be arbitrarily rearranged without inspecting
00652  * and possibly changing the code.
00653  *
00654  * NOTE 2: some elements of "granule_averages" (a structure member in
00655  * QA_Common_t) are unused.  This variable is currently
00656  * initialized in Calculate_Temp_QA, where all non-zero values
00657  * are assigned.  The initialization sets the unused elements to zero.
00658  * If other granule averages are added, then the location of the
00659  * initialization may need to be changed.
00660  */
00661 
00662 typedef enum {
00663   GRAN_AVG_TP_BB_TEMP01,        /* BB Thermistor 1 */
00664   GRAN_AVG_TP_BB_TEMP02,        /* BB Thermistor 2 */
00665   GRAN_AVG_TP_BB_TEMP03,        /* BB Thermistor 3 */
00666   GRAN_AVG_TP_BB_TEMP04,        /* BB Thermistor 4 */
00667   GRAN_AVG_TP_BB_TEMP05,        /* BB Thermistor 5 */
00668   GRAN_AVG_TP_BB_TEMP06,        /* BB Thermistor 6 */
00669   GRAN_AVG_TP_BB_TEMP07,        /* BB Thermistor 7 */
00670   GRAN_AVG_TP_BB_TEMP08,        /* BB Thermistor 8 */
00671   GRAN_AVG_TP_BB_TEMP09,        /* BB Thermistor 9 */
00672   GRAN_AVG_TP_BB_TEMP10,        /* BB Thermistor 10 */
00673   GRAN_AVG_TP_BB_TEMP11,        /* BB Thermistor 11 */
00674   GRAN_AVG_TP_BB_TEMP12,        /* BB Thermistor 12 */
00675   GRAN_AVG_TA_AO_VIS_FPAE,      /* (FPA1) VIS Focal Plane */
00676   GRAN_AVG_TA_AO_NIR_FPAE,      /* (FPA2) NIR Focal Plane */
00677   GRAN_AVG_TA_RC_SMIR_CFPAE,    /* (FPA3) SMIR Focal plane Temp */
00678   GRAN_AVG_TA_RC_LWIR_CFPAE,    /* (FPA4) LWIR Focal plane Temp */
00679   GRAN_AVG_TP_SA_RCT1_MIRE,     /* Scan Mirror Temp 1 */
00680   GRAN_AVG_TP_SA_RCT2_MIRE,     /* Scan Mirror Temp 2 */
00681   GRAN_AVG_TP_SA_A_MTR,         /* Scan motor temperature A */
00682   GRAN_AVG_TP_MF_CALBKHD_SR,    /* (CAV1) Cal bulkhead below SRCA mount */
00683   GRAN_AVG_TP_SR_SNOUT,         /* (CAV2) SRCA Bulkhead Temp */
00684   GRAN_AVG_TP_MF_Z_BKHD_BB,     /* (CAV3) Mid zenith bulkhead near BB */
00685   GRAN_AVG_TP_MF_CVR_OP_SR,     /* (CAV4) cover opposite SRCA */
00686   GRAN_AVG_TP_AO_SMIR_OBJ,      /* (INS1) SMIR Objective Lens Temp */
00687   GRAN_AVG_TP_AO_LWIR_OBJ,      /* (INS2) LWIR Objective Lens Temp */
00688   GRAN_AVG_TP_AO_SMIR_LENS,     /* (INS3) SMIR Eye Assy Temp */
00689   GRAN_AVG_TP_AO_LWIR_LENS,     /* (INS4) LWIR Eye Assy Temp */
00690   GRAN_AVG_TA_RC_CS,            /* (RC1) Cold stage Temp */
00691   GRAN_AVG_TA_RC_CS_OG,         /* (RC2) Cold stage outgas Temp */
00692   GRAN_AVG_TA_RC_IS,            /* (RC3) Intermediate Stage Temp */
00693   GRAN_AVG_TA_RC_IS_OG,         /* (RC4) Intermediate Stage outgas Temp */
00694   GRAN_AVG_TA_RC_OS_OG,         /* (RC5) Outerstage outgas Temp */
00695   GRAN_AVG_VR_RC_LW_FPA_HTR,    /* LWIR heater voltage */
00696   NUM_GRAN_AVERAGES
00697 } gran_average_def_t;
00698 
00699 /* Define the dimension of the attribute.  Unused elements are set to
00700  * zero within the attribute.
00701  */
00702 
00703 #define MAX_NUM_GRAN_AVERAGES   50
00704 
00705 /* Define the number of RC values in the above definition.  This value
00706  * is also used in Preprocess when calculating and temporarily storing
00707  * the temperatures.
00708  */
00709 
00710 #define NUM_T_RC_VALUES  5
00711 
00712 /* Define a bad value for voltages
00713  */
00714 
00715 #define VOLTAGE_BAD_VALUE  -1000.
00716 
00717 /***************************************************************************/
00718 
00719 /*--------------------------------------------------------------------------
00720   Data Structures
00721 --------------------------------------------------------------------------*/
00722 
00723   /* Upper bound on length of ProcessingEnvironment archive
00724    * metadata item
00725    */
00726 
00727 #define  MAX_PROCESSING_ENVIRONMENT_STRLEN 200
00728 
00729 #define MAX_RUNTIME_PARAM_SIZE 256
00730 
00731 typedef struct {
00732   char SatelliteInstrument[MAX_RUNTIME_PARAM_SIZE];
00733   char ReprocessingPlanned[MAX_RUNTIME_PARAM_SIZE];
00734   char ReprocessingActual[MAX_RUNTIME_PARAM_SIZE];
00735   char PGE02_Version[MAX_RUNTIME_PARAM_SIZE];
00736   char MCST_LUT_Version[MAX_RUNTIME_PARAM_SIZE];
00737   char Write_Night_Mode_HiRes_Data[MAX_RUNTIME_PARAM_SIZE];
00738   char ProcessingEnvironment[MAX_RUNTIME_PARAM_SIZE];
00739   char ProcessingCenter[MAX_RUNTIME_PARAM_SIZE];
00740   } Run_Time_Parameters_t;
00741 
00742 typedef  struct {
00743   int32     v_id;
00744   int32     sd_id;
00745   int32     satellite_id;
00746   int32     num_scans;
00747   int32     num_day_scans;
00748   int16     MirrorSide[MAX_NUM_SCANS]; 
00749   char      ScanType[MAX_NUM_SCANS][SCAN_TYPE_TEXT_SIZE];
00750   float64   EVStartTime_TAIsecond[MAX_NUM_SCANS];
00751   int32     scan_quality[MAX_NUM_SCANS][SCAN_QUALITY_ARRAY_NUM_ELEMENTS];
00752   float64   data_collection_time;
00753 
00754   /* For L1B metadata */
00755 
00756   int32     num_night_scans;
00757   int32     incomplete_scans;
00758   int32     max_ev_frames;
00759   int32     Extract_Pixel_Offset;
00760   int32     Extract_Pixel_Count;
00761   int32     Extract_Line_Offset;
00762   int32     Extract_Line_Count;
00763 
00764   /* For identifying completely missing scans */
00765 
00766   boolean   missing_scan[MAX_NUM_SCANS];
00767 
00768   } L1A_granule_t;
00769 
00770 typedef struct 
00771 {
00772   int32 sds_id[NUM_L1A_RESOLUTIONS];
00773 
00774   int16 EV_250m     [DETECTORS_PER_250M_BAND]
00775                     [NUM_250M_BANDS]
00776                     [EV_250m_FRAMES];
00777 
00778   int16 EV_500m     [DETECTORS_PER_500M_BAND]
00779                     [NUM_500M_BANDS]
00780                     [EV_500m_FRAMES];
00781 
00782   int16 EV_1km_day  [DETECTORS_PER_1KM_BAND]
00783                     [NUM_1000M_DAY_BANDS]
00784                     [EV_1km_FRAMES];
00785 
00786   int16 EV_1km_night[DETECTORS_PER_1KM_BAND]
00787                     [NUM_1000M_NIGHT_BANDS]
00788                     [EV_1km_FRAMES];
00789 } L1A_Scan_t;
00790 
00791 /* Level 1B scale_offset data */
00792 
00793 typedef struct {
00794   float32 dn_star_Max[NUM_REFLECTIVE_BANDS];
00795   float32 dn_star_Min[NUM_REFLECTIVE_BANDS]; 
00796 
00797   float32 rad_scale_RefSB[NUM_REFLECTIVE_BANDS]; 
00798   float32 rad_offset_RefSB[NUM_REFLECTIVE_BANDS]; 
00799   float32 refl_scale_RefSB[NUM_REFLECTIVE_BANDS];
00800   float32 refl_offset_RefSB[NUM_REFLECTIVE_BANDS];
00801 
00802   float32 counts_scale_RefSB[NUM_REFLECTIVE_BANDS];
00803   float32 counts_offset_RefSB[NUM_REFLECTIVE_BANDS];
00804 
00805   float32 rad_scale_Emiss[NUM_EMISSIVE_BANDS];
00806   float32 rad_offset_Emiss[NUM_EMISSIVE_BANDS];
00807 } L1B_ScaleOffset_t;
00808 
00809 
00810 typedef struct 
00811 {
00812   float32 m1_des_sq[NUM_REFLECTIVE_BANDS]
00813                    [MAX_DETECTORS_PER_BAND]
00814                    [MAX_SAMPLES_PER_BAND]
00815                    [NUM_MIRROR_SIDES];
00816 
00817   float32 m1_des_sq_max[NUM_REFLECTIVE_BANDS];
00818 
00819   float32 RVS_250m[NUM_250M_BANDS]
00820                   [DETECTORS_PER_250M_BAND]
00821                   [EV_250m_FRAMES]
00822                   [NUM_MIRROR_SIDES];
00823 
00824   float32 RVS_500m[NUM_500M_BANDS]
00825                   [DETECTORS_PER_500M_BAND]
00826                   [EV_500m_FRAMES]
00827                   [NUM_MIRROR_SIDES];
00828 
00829   float32 RVS_1km_RefSB[NUM_1000M_REFL_BANDS]
00830                        [DETECTORS_PER_1KM_BAND]
00831                        [EV_1km_FRAMES]
00832                        [NUM_MIRROR_SIDES];
00833 
00834   float32 u2[NUM_REFLECTIVE_DETECTORS]
00835             [EV_1km_FRAMES]
00836             [NUM_MIRROR_SIDES]; 
00837 
00838 } RSB_Cal_Coeff_t;
00839 
00840 typedef  struct {
00841   float32 RVS_1km_Emiss_EV[NUM_EMISSIVE_DETECTORS]
00842                           [EV_1km_FRAMES]
00843                           [NUM_MIRROR_SIDES];
00844   float32 RVS_1km_Emiss_SV[NUM_EMISSIVE_DETECTORS]
00845                           [NUM_MIRROR_SIDES];
00846   float32 RVS_1km_Emiss_BB[NUM_EMISSIVE_DETECTORS]
00847                           [NUM_MIRROR_SIDES];
00848   float32 sigma_RVS_Emiss_EV[NUM_EMISSIVE_DETECTORS]
00849                             [EV_1km_FRAMES]
00850                             [NUM_MIRROR_SIDES];
00851 } Emiss_Cal_Coeff_t;
00852 
00853 typedef  struct {
00854   int32     sw_f_id[NUM_L1B_EV_FILES];
00855   int32     v_id[NUM_L1B_EV_FILES];
00856   int32     sd_id[NUM_L1B_EV_FILES];
00857   int32     num_scans;
00858   int32     num_day_scans;
00859   
00860   RSB_Cal_Coeff_t   RSB_Cal_Coeff;
00861   Emiss_Cal_Coeff_t Emiss_Cal_Coeff;
00862   L1B_ScaleOffset_t SO;
00863 
00864   float32 b26_fr_b5_scaled_corr[DETECTORS_PER_1KM_BAND];
00865   
00866   /* For L1B metadata */
00867 
00868   float32 validEVPercent[NUM_BANDS];
00869   float32 satEVPercent[NUM_BANDS];
00870   float32 missEVPercent[NUM_BANDS];
00871   uint32  elecRedVec[2];
00872   int8    FPSetPointState[NUM_FOCAL_PLANES];
00873 
00874   uint32 total_pixels[NUM_BANDS];
00875   uint32 valid_pixels[NUM_BANDS];
00876   uint32 saturated_pixels[NUM_BANDS];
00877   uint32 missing_pixels[NUM_BANDS]; 
00878   uint32 interpolated_pixels[NUM_BANDS];
00879   uint32 dead_detector_pixels[NUM_BANDS];
00880   uint32 dead_subframe_pixels[NUM_BANDS];
00881   uint32 negative_value_below_noise_pixels[NUM_BANDS];
00882   int16  bad_data_flag[NUM_BANDS];
00883   float32 Earth_Sun_Dist;
00884 } L1B_granule_t;
00885 
00886 typedef struct 
00887 {
00888   uint16 EV_250m_RefSB  [NUM_250M_BANDS]
00889                         [DETECTORS_PER_250M_BAND]
00890                         [EV_250m_FRAMES];
00891 
00892   uint16 EV_500m_RefSB  [NUM_500M_BANDS]
00893                         [DETECTORS_PER_500M_BAND]
00894                         [EV_500m_FRAMES];
00895 
00896   uint16 EV_1km_RefSB   [NUM_1000M_REFL_BANDS]
00897                         [DETECTORS_PER_1KM_BAND]
00898                         [EV_1km_FRAMES];
00899 
00900   uint16 EV_1km_Emissive[NUM_1000M_EMISS_BANDS]
00901                         [DETECTORS_PER_1KM_BAND]
00902                         [EV_1km_FRAMES];
00903 } L1B_Scan_SI_t;
00904 
00905 typedef struct 
00906 {
00907   uint8 EV_250m_RefSB_UI  [NUM_250M_BANDS]
00908                           [DETECTORS_PER_250M_BAND]
00909                           [EV_250m_FRAMES];
00910 
00911   uint8 EV_500m_RefSB_UI  [NUM_500M_BANDS]
00912                           [DETECTORS_PER_500M_BAND]
00913                           [EV_500m_FRAMES];
00914 
00915   uint8 EV_1km_RefSB_UI   [NUM_1000M_REFL_BANDS]
00916                           [DETECTORS_PER_1KM_BAND]
00917                           [EV_1km_FRAMES];
00918 
00919   uint8 EV_1km_Emissive_UI[NUM_1000M_EMISS_BANDS]
00920                           [DETECTORS_PER_1KM_BAND]
00921                           [EV_1km_FRAMES];
00922 } L1B_Scan_UI_t;
00923 
00924 /************************* Begin Band 26 Section **************************/
00925 /*
00926  * If the macro WRITE_BAND_26_SDS is defined, then the MODIS band 26 SDSs will
00927  * be written to the EV 1km file.  Two SDSs are written: (1) scaled integer,
00928  * (2) uncertainty index.  These are written regardless of whether the scan
00929  * is day or night.
00930  */
00931 
00932 /*** UNCOMMENT THE FOLLOW STATEMENT TO ENABLE WRITING BAND 26 SDS ***/
00933 
00934 #define WRITE_BAND_26_SDS  
00935 
00936 #ifdef WRITE_BAND_26_SDS
00937 
00938 #define BAND_26_SI_SDS_NAME      "EV_Band26"
00939 #define BAND_26_UI_SDS_NAME      "EV_Band26_Uncert_Indexes"
00940 #define BAND_26_SI_SDS_LONG_NAME "Earth View Band 26 Scaled Integers"
00941 #define BAND_26_UI_SDS_LONG_NAME "Earth View Band 26 Uncertainty Indexes"
00942 
00943 typedef struct {
00944   int32 SI_sds_id;
00945   int32 UI_sds_id;
00946   uint16 SI[DETECTORS_PER_1KM_BAND][EV_1km_FRAMES];
00947   uint8  UI[DETECTORS_PER_1KM_BAND][EV_1km_FRAMES];
00948 } Band_26_t;
00949 
00950 #endif /* WRITE_BAND_26_SDS */
00951 /************************** End Band 26 Section ***************************/
00952 
00953 typedef struct {
00954 /*-------------------------
00955   SI == Scaled Integer
00956   UI == Uncert Index
00957   SU == Samples Used
00958 -------------------------*/
00959   int32    SI_sds_id[NUM_L1A_RESOLUTIONS];
00960   int32    EV_250m_Aggr500m_RefSB_sds_id;
00961   int32    EV_250m_Aggr1km_RefSB_sds_id;
00962   int32    EV_500m_Aggr1km_RefSB_sds_id;
00963   int32    UI_sds_id[NUM_L1A_RESOLUTIONS];
00964   int32    EV_250m_Aggr500m_RefSB_UI_sds_id;
00965   int32    EV_250m_Aggr1km_RefSB_UI_sds_id;
00966   int32    EV_500m_Aggr1km_RefSB_UI_sds_id;
00967   int32    EV_250m_Aggr500m_RefSB_SU_sds_id;
00968   int32    EV_250m_Aggr1km_RefSB_SU_sds_id;
00969   int32    EV_500m_Aggr1km_RefSB_SU_sds_id;
00970   L1B_Scan_SI_t   SI;
00971   /* uint16   ***SI[NUM_L1A_RESOLUTIONS];*/    /*[band][det][frame]*/
00972   uint16   EV_250m_Aggr500m_RefSB   [NUM_250M_BANDS]
00973                                     [DETECTORS_PER_500M_BAND]
00974                                     [EV_500m_FRAMES];
00975 
00976   uint16   EV_250m_Aggr1km_RefSB    [NUM_250M_BANDS]
00977                                     [DETECTORS_PER_1KM_BAND]
00978                                     [EV_1km_FRAMES];
00979 
00980   uint16   EV_500m_Aggr1km_RefSB    [NUM_500M_BANDS]
00981                                     [DETECTORS_PER_1KM_BAND]
00982                                     [EV_1km_FRAMES];
00983 
00984   L1B_Scan_UI_t   UI;
00985 
00986   /* uint8    ***UI[NUM_L1A_RESOLUTIONS];
00987  */   /*
00988                                     [band][det][frame]*/
00989   uint8    EV_250m_Aggr500m_RefSB_UI[NUM_250M_BANDS]
00990                                     [DETECTORS_PER_500M_BAND]
00991                                     [EV_500m_FRAMES];
00992          
00993   uint8    EV_250m_Aggr1km_RefSB_UI [NUM_250M_BANDS]
00994                                     [DETECTORS_PER_1KM_BAND]
00995                                     [EV_1km_FRAMES];
00996            
00997   uint8    EV_500m_Aggr1km_RefSB_UI [NUM_500M_BANDS]
00998                                     [DETECTORS_PER_1KM_BAND]
00999                                     [EV_1km_FRAMES];
01000              
01001   int8     EV_250m_Aggr500m_RefSB_SU[NUM_250M_BANDS]
01002                                     [DETECTORS_PER_500M_BAND]
01003                                     [EV_500m_FRAMES];
01004 
01005   int8     EV_250m_Aggr1km_RefSB_SU [NUM_250M_BANDS]
01006                                     [DETECTORS_PER_1KM_BAND]
01007                                     [EV_1km_FRAMES];
01008 
01009   int8     EV_500m_Aggr1km_RefSB_SU [NUM_500M_BANDS]
01010                                     [DETECTORS_PER_1KM_BAND]
01011                                     [EV_1km_FRAMES];
01012 
01013 /************************* Begin Band 26 Section **************************/
01014 #ifdef WRITE_BAND_26_SDS
01015 /*
01016  * This structure member holds arrays dimensioned appropriately for one
01017  * scan of the Band 26 SDSs.
01018  */
01019   Band_26_t Band26;
01020 #endif /* WRITE_BAND_26_SDS */
01021 /************************** End Band 26 Section ***************************/
01022 
01023   int16   band_X;
01024   float32 dn_X[DETECTORS_PER_1KM_BAND][EV_1km_FRAMES]; 
01025 } L1B_Scan_t;
01026 
01027 typedef struct 
01028 {
01029   uint8 noise_T_bb[12];
01030   uint8 noise_T_bb_avg;
01031   uint8 noise_T_lwir;
01032   uint8 noise_T_mwir;
01033   uint8 noise_T_mir1;
01034   uint8 noise_T_mir2;
01035   uint8 noise_T_mir_avg;
01036   uint8 noise_T_ins;
01037   uint8 noise_T_cav;
01038   uint8 NEdL[NUM_EMISSIVE_DETECTORS];        /*noise in system*/
01039   uint8 change_b1[NUM_EMISSIVE_DETECTORS];
01040   uint8 num_thermistor_outliers[MAX_NUM_SCANS];     /* range [0-12] */
01041   int8  change_dc_restore[MAX_NUM_SCANS]
01042                          [NUM_EMISSIVE_BANDS]
01043                          [DETECTORS_PER_1KM_BAND];
01044   int8  emiss_band_bad_data[NUM_EMISSIVE_BANDS];
01045   int8  moon_in_SV_KOB_TEB[MAX_NUM_SCANS]; 
01046 } QA_Emiss_t;
01047 
01048 typedef struct 
01049 {
01050   uint8 noise_T_vis;
01051   uint8 noise_T_nir;
01052   int8  change_dc_restore_250m[MAX_NUM_SCANS][NUM_250M_BANDS]
01053                               [DETECTORS_PER_250M_BAND];
01054   int8  change_dc_restore_500m[MAX_NUM_SCANS][NUM_500M_BANDS]
01055                               [DETECTORS_PER_500M_BAND];
01056   int8  change_dc_restore_1km[MAX_NUM_SCANS][NUM_1000M_REFL_BANDS]
01057                              [DETECTORS_PER_1KM_BAND];
01058   int8  refl_band_bad_data[NUM_REFLECTIVE_BANDS];
01059   int8  moon_in_SV_KOB_RSB[MAX_NUM_SCANS];
01060   int8  all_SV_DN_bad[MAX_NUM_SCANS];
01061   int8  all_BB_DN_bad[MAX_NUM_SCANS]; 
01062 } QA_Refl_t;
01063 
01064 typedef struct 
01065 {
01066   int8  all_l1b_error_flags_off;
01067   boolean missing_leading_granule;   /* True or False */
01068   boolean missing_trailing_granule;  /* True or False */
01069   boolean leading_granule_scan_gap;  /* True or False */
01070   boolean trailing_granule_scan_gap; /* True or False */
01071   boolean NAD_Door_Open[MAX_NUM_SCANS];
01072   boolean Sector_Rotation[MAX_NUM_SCANS];
01073   boolean Electronic_Anomaly[MAX_NUM_SCANS];
01074   int32 num_missing_scans;
01075   int32 num_rsb_at_night_scans;
01076   int32 num_missing_data_in_scans[NUM_DETECTORS];
01077   int32 num_dead_detector_EV_data[NUM_DETECTORS];
01078   int32 num_dead_subframe_EV_data[NUM_HIGH_RESOLUTION_DETECTORS];
01079   int32 num_sector_rotation_EV_data[NUM_DETECTORS];
01080   int32 num_saturated_EV_data[NUM_DETECTORS];
01081   int32 num_no_bg_DN_EV_data[NUM_DETECTORS];
01082   int32 num_moon_in_SVP_TEB_EV_data[NUM_DETECTORS];
01083   int32 num_bad_dn_star_star_RSB_EV_data[NUM_DETECTORS];
01084   int32 num_exceed_max_for_scaling[NUM_DETECTORS];
01085   int32 num_nadir_door_closed_EV_data[NUM_DETECTORS];
01086   int32 num_negative_b1[NUM_DETECTORS];
01087   uint32 bit_QA_flags_last_value;
01088   uint32 bit_QA_flags_change;
01089   float32 granule_averages[MAX_NUM_GRAN_AVERAGES];
01090 } QA_Common_t;
01091 
01092 typedef struct 
01093 {
01094   QA_Common_t  QA_common;
01095   QA_Emiss_t   QA_emiss;
01096   QA_Refl_t    QA_refl;
01097 } QA_Data_t;
01098 
01099 /* 16 Bit Constants for Re-Scaling of Radiance */
01100 #define DN15_SAT                32767
01101 #define DN_MIN                  0
01102 
01103 /************************ Error message utilities ************************/
01104 /*
01105  * The following are global values to use for the "other_msg" input to
01106  * L1BErrorMsg. These errors may occur many times.
01107  */
01108 
01109 extern char Invalid_MOD01_Msg[];  /* Invalid or out of bounds L1A data */
01110 
01111 /*
01112  * Function protos
01113  */
01114 int safe_strcat(
01115   char *buf,     /* A character buffer that we want to concatenate to */
01116   char *str,     /* The string to be concatenated */
01117   int  buflen    /* The known memory limitation of the character buffer */
01118 );
01119 
01120 void L1BErrorMsg(
01121        /* name of L1B function that error occurred in */    
01122   char          *L1B_location,    
01123     
01124        /* associated error code for this error */    
01125   PGSt_SMF_code code,             
01126     
01127        /* short (usually 1-line) description of error */    
01128   char          *input_message,   
01129     
01130        /* name of the associated function that failed */    
01131   char          *assoc_function,  
01132   
01133        /* associated LUN for the file being accessed */  
01134   int32         lun,            
01135   
01136        /* other message to add such as probable cause */  
01137   char          *other_msg,     
01138   
01139        /* flag to tell whether or not to call SMF_ERROR */  
01140   boolean       error_out       
01141   
01142 );
01143 
01144 void            SMF_ERROR  
01145                   (PGSt_SMF_code         code, 
01146                    char                  *messagestring);
01147 
01148 void            Bad_L1A_Error_Out
01149                   (char                  *name,
01150                    char                  *message);
01151 
01152 /********************** Other function Prototypes **************************/
01153 
01154 PGSt_SMF_status Read_Run_Time_Parameters 
01155                   (Run_Time_Parameters_t *runtime_params);
01156 
01157 PGSt_SMF_status Open_and_Read_L1A 
01158                   (Run_Time_Parameters_t *runtime_params,
01159                    L1A_granule_t         *L1A_Gran,
01160                    boolean               *skip_night_hi_res);
01161 
01162 
01163 PGSt_SMF_status Get_Satellite_ID 
01164                   (PGSt_PC_Logical lun, 
01165                    int32                 *satellite_ID);
01166 
01167 
01168 PGSt_SMF_status Read_L1A_EV_Scan 
01169                   (int16                 S,
01170                    L1A_granule_t         *L1A_Gran,
01171                    L1A_Scan_t            *L1A_Scan);
01172 
01173 
01174 PGSt_SMF_status Aggregate_L1B 
01175                   (L1B_Scan_t            *L1B_Scan);
01176 
01177 
01178 PGSt_SMF_status Fill_Dead_Detector_SI 
01179                   (boolean               isdaymode,
01180                    int8                  *dead_detector,
01181                    L1B_Scan_t            *L1B_Scan,
01182                    L1B_granule_t         *L1B_Gran,
01183                    QA_Common_t           *QA_Common);
01184 
01185 
01186 PGSt_SMF_status Write_L1B_EV_Scan 
01187                   (int16                 S,
01188                    L1B_granule_t         *L1B_Gran,
01189                    L1B_Scan_t            *L1B_Scan,
01190                    boolean               isdaymode);
01191 
01192 
01193 PGSt_SMF_status Close_L1A_Granule 
01194                   (L1A_granule_t         *L1A_Gran,
01195                    L1A_Scan_t            *L1A_Scan);
01196 
01197 
01198 PGSt_SMF_status Close_L1B_Granule 
01199                   (L1B_granule_t         *L1B_Gran,
01200                    L1B_Scan_t            *L1B_Scan,
01201                    boolean               skip_night_hi_res);
01202 
01203 
01204 #endif
01205