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