ocssw  1.0
/disk01/web/ocssw/build/src/l1agen_modis/level1a.c (r8096/r7924)
Go to the documentation of this file.
00001 #include <math.h>
00002 #include "EN_eng_data.h"
00003 #include "FP_failed_pkt_queue.h"
00004 #include "hdfi.h"
00005 #include "L1A_prototype.h"
00006 #include "MS_misc.h" 
00007 #include "PC_pcf_info.h"
00008 #include "PGS_IO_L0.h"
00009 #include "PGS_MODIS_35005.h"
00010 #include "PGS_PC.h"
00011 #include "PGS_SMF.h"
00012 #include "PGS_TD.h"
00013 #include "PGS_TYPES.h"
00014 #include "PH_pkt_hdr.h"
00015 #include "VU_vdata_utility.h"
00016 #include "version.h"
00017 #include "smfio.h"
00018  
00019 /* 
00020  * Define Global Variables 
00021  */
00022 
00023 char            global_input_pointer[MAX_INPUTS][PGSd_PC_VALUE_LENGTH_MAX];   
00024                              /* Input file names: Eng Data List file name,
00025                                 prior L0 file name, current L0 file name  */
00026 int             global_VU_ID_TABLE_READY = FALSE;
00027 int32           global_H_ID;
00028                    /* This is shared between the functions in this file so the 
00029                       user of this package doesn't have to deal with it.  */
00030 PGSt_double     global_first_gran_start_time; /* first granule start time */
00031 PGSt_double     global_last_gran_stop_time;   /* last granule stop time   */
00032 PGSt_double     global_time_offset_array[5];  
00033                              /* The time offsets for each sector from 
00034                                 the beginning of the scan (ie. SD sector) */
00035 PGSt_PC_Logical global_L0_logical;                 /* L0 file unit number */
00036 VU_ID_TABLE     global_VU_VDATA_ID[VU_MAX_NUMBER_OF_VDATAS];
00037                             /* used to store the Vdata IDs so that functions 
00038                                         need only refer to Vdatas by name */
00039 
00040 int  main () 
00041 /******************************************************************************
00042 !C
00043 
00044 !Description:  This is the main function of the MODIS Level 1A processing
00045                system. 
00046 
00047 !Input Parameters:   None
00048 
00049 !Output Parameters:  None
00050 
00051 Return Values: 
00052                 MS_MT_EXIT_FATAL_FAILURE 
00053                 MS_MT_EXIT_SUCCESS      
00054 
00055 Externally Defined:  
00056                 EN_NUM_VDATAS                   (EN_eng_data.h)
00057                 EN_VDATA_TYPE_t                 (EN_eng_data.h)
00058                 FALSE                           (hdfi.h)
00059                 FP_QUEUE_t                      (FP_failed_pkt_queue.h)
00060                 int32                           (hdfi.h)
00061                 MODIS_E_INITIALIZATION_FAILED   (PGS_MODIS_35005.h)
00062         MODIS_E_L1A         (PGS_MODIS_35005.h)
00063                 MODIS_E_MALLOC_FAILED           (PGS_MODIS_35005.h)
00064                 MODIS_E_NO_SCANS_IN_PRODUCT     (PGS_MODIS_35005.h)
00065                 MODIS_F_PROCESSAGRANULE         (PGS_MODIS_35005.h)
00066                 MODIS_U_L1A_BEGIN               (PGS_MODIS_35005.h)
00067                 MODIS_U_L1A_END                 (PGS_MODIS_35005.h)
00068                 MS_MT_EXIT_FATAL_FAILURE        (MS_misc.h)
00069                 MS_MT_EXIT_SUCCESS              (MS_misc.h)
00070                 PCF_CONFIG_t                    (PC_pcf_info.h)
00071                 PD_PKT_BUF_MAX                  (PD_pkt_data.h)
00072                 PGSd_PC_VALUE_LENGTH_MAX        (PGS_PC.h)
00073                 PGS_SMF_MAX_MSGBUF_SIZE         (PGS_SMF.h)
00074                 PGS_SMF_MASK_LEV_F              (PGS_SMF.h)
00075                 PGS_TRUE                        (PGS_SMF.h)
00076                 PGSt_double                     (PGS_TYPES.h)
00077                 PGSt_IO_L0_VirtualDataSet       (PGS_IO_L0.h)
00078                 PGSt_PC_Logical                 (PGS_TYPES.h)
00079                 PGSt_SMF_status                 (PGS_SMF.h)
00080                 PH_PACKET_HEADER_t              (PH_pkt_hdr.h)
00081                 PROCESSVERSION                  (version.h)
00082                 VU_ID_TABLE                     (VU_vdata_utility.h)
00083                 VU_MAX_NUMBER_OF_VDATAS         (VU_vdata_utility.h)
00084 
00085 Called By:     ECS
00086 
00087 Routines Called:
00088                PGS_SMF_TestSuccessLevel
00089                initialize_level1a           
00090                process_a_granule
00091                make_queue
00092                free_queue            
00093                log_fmt_msg               
00094                close_processing_run         
00095 
00096 !Revision History:
00097                $Log: level1a.c,v $
00098                Revision 5.2  2006/01/04 17:12:19  kuyper
00099                Changed to avoid daylight savings time problems by using a method of
00100                  skipping leap seconds that works directly on the asciiUTC representation.
00101 
00102                Revision 5.1  2006/01/04 00:02:44  kuyper
00103                Change to use minutes rather than seconds for granule sizes, for better
00104                  handling of leap seconds, resolving MODur00122 and GSFcd02888.
00105 
00106                Revision 4.3  2003/11/12 21:06:50  kuyper
00107                Changed to use MAX_INPUTS macro.
00108 
00109                Revision 4.2  2003/04/24 18:25:02  vlin
00110                updated after code walkthrough
00111 
00112                Revision 4.1  2003/02/24 20:21:04  kuyper
00113                Removed inappropriate uses of NULL.
00114 
00115                Revision 4.0  2003/01/08 19:35:56  vlin
00116                updated according to level1a.pdl revision 4.2
00117                vlin@saicmodis.com
00118 
00119                Revision 2.2  2001/01/04
00120                John Seaton  (seaton@ltpmail.gsfc.nasa.gov)
00121                Added new mnemonic for L1A version, not PGE version.
00122 
00123                Revision 2.1  2000/07/17
00124                John Seaton  (seaton@ltpmail.gsfc.nasa.gov)
00125                Added changes for Aqua spacecraft
00126 
00127                Revision 2.0  1997/08/08  15:15 EDT
00128                Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
00129                Remodeled PDL per Version 2 development.
00130 
00131 !Team-unique Header:
00132 
00133           This software is developed by the MODIS Science Data Support Team 
00134           for the National Aeronautics and Space Administration, 
00135           Goddard Space Flight Center, under contract NAS5-32373.
00136 
00137 References and Credits:
00138 
00139 Design Notes: 
00140 
00141 !END
00142 ******************************************************************************/
00143 
00144 {
00145   PGSt_SMF_status  Status;       
00146   int              exitStatus = MS_MT_EXIT_SUCCESS;  
00147   char             routine[] = "level1a";
00148   PCF_CONFIG_t     pcf_config;
00149   PGSt_double      gran_start_time;      
00150   PGSt_double      gran_stop_time;      
00151   PGSt_IO_L0_VirtualDataSet   L0_file;     /* File containing L0 data        */
00152   PGSt_IO_L0_Packet  pkt[PD_PKT_BUF_MAX];  /* Packet of L0 data              */
00153   PH_PACKET_HEADER_t pkt_header;           /* Unpacked header of L0 packet   */
00154   EN_VDATA_TYPE_t  eng_data[EN_NUM_VDATAS];/* Engineering vdata structure    */
00155   FP_QUEUE_t         failed_pkts;          /* Discarded packets queue        */
00156 
00157   setlinebuf (stdout);
00158   printf("L1A version: %s  built on %s (%s)\n",
00159       PROCESSVERSION,__DATE__,__TIME__);
00160 
00161   log_fmt_msg(MODIS_U_L1A_BEGIN, routine, "L1A version %s built on %s, at %s",
00162       PROCESSVERSION, __DATE__, __TIME__);
00163   Status = initialize_level1a(&pcf_config, eng_data, pkt, 
00164                               &pkt_header, &L0_file);
00165 
00166   if (PGS_SMF_TestStatusLevel(Status) < PGS_SMF_MASK_LEV_F) {
00167      failed_pkts = make_queue();
00168      if (failed_pkts != NULL)
00169      {
00170         gran_start_time = pcf_config.first_gran_start_time;
00171 
00172         gran_stop_time = pcf_config.first_gran_start_time + 
00173                          pcf_config.gran_time_length*60.0;
00174 
00175     //  while (gran_start_time < pcf_config.last_gran_stop_time)
00176     while (fabs(gran_start_time - pcf_config.last_gran_stop_time) > 0.1)
00177     {
00178         char asciiUTC[TIMECODEASIZE];
00179 
00180       //      gran_stop_time = gran_start_time + pcf_config.gran_time_length*60.0
00181       // + 1.0; /* to cover leapseconds, if present. */
00182 
00183         if(PGS_SMF_TestErrorLevel(PGS_TD_TAItoUTC(gran_stop_time, asciiUTC))
00184         != PGS_FALSE)
00185         {
00186         log_fmt_msg(MODIS_E_L1A, routine, "PGS_TD_TAItoUTC(%.1f)",
00187             gran_start_time);
00188         exitStatus = MS_MT_EXIT_FATAL_FAILURE;
00189         }
00190         else
00191         {
00192            /* Cancel out the +1.0, if no leap second was present, by
00193         * setting the last seconds digit to 0.
00194         */
00195           // JMG: This assumes that before adding the leap second above,
00196           //      the stop_time had a 0 in the first digit to the left
00197           //      of the decimal point.  This assumption does not 
00198           //      always hold.
00199 
00200           //      I have modified the source code by commenting out
00201           //      the addition of the leapsec above and removing the
00202           //      call to UTCtoTAI just below.
00203           
00204            asciiUTC[sizeof "2001-01-01T00:00:"] = '0';
00205 
00206            /*
00207            if(PGS_SMF_TestErrorLevel(PGS_TD_UTCtoTAI(asciiUTC,
00208            &gran_stop_time)) != PGS_FALSE)
00209            */
00210            if(0)
00211            {
00212           log_fmt_msg(MODIS_E_L1A, routine, "PGS_TD_UTCtoTAI(\"%s\")",
00213               asciiUTC);
00214           exitStatus = MS_MT_EXIT_FATAL_FAILURE;
00215            }
00216            else if(PGS_SMF_TestStatusLevel(process_a_granule(L0_file,
00217            gran_start_time, gran_stop_time, &pcf_config, eng_data,
00218            &pkt_header, pkt, &failed_pkts)) != PGS_SMF_MASK_LEV_F)
00219            {
00222           gran_start_time = gran_stop_time;
00223           if (global_input_pointer[2][0] != '\0') {
00224              memset(global_input_pointer[1], '\0', 
00225                 sizeof(global_input_pointer[1]));
00226              strcpy(global_input_pointer[1], global_input_pointer[2]);
00227              memset(global_input_pointer[2], '\0', 
00228                 sizeof(global_input_pointer[2]));
00229           }
00230            }
00231            else {
00232           log_fmt_msg(MODIS_F_PROCESSAGRANULE, routine,
00233               "Fatal Error: Could not process a granule");
00234           gran_start_time = pcf_config.last_gran_stop_time;
00235           exitStatus = MS_MT_EXIT_FATAL_FAILURE;
00236            }
00237         }
00238     }  /*  end while  */
00239         free_queue (failed_pkts);
00240      }
00241      else {
00242         log_fmt_msg(MODIS_E_MALLOC_FAILED, routine,
00243                    "unable to allocate memory for the discarded packets queue");
00244         exitStatus = MS_MT_EXIT_FATAL_FAILURE;
00245      }
00246   }
00247   else {
00248      log_fmt_msg(MODIS_E_INITIALIZATION_FAILED, routine, 
00249                  "Routine initialize_level1a failed");
00250      exitStatus = MS_MT_EXIT_FATAL_FAILURE;
00251   }
00252 
00253   close_processing_run(L0_file);
00254   log_fmt_msg(MODIS_U_L1A_END, routine, "L1A return code = %d", exitStatus);
00255   return exitStatus;
00256 
00257 }