ocssw  1.0
/disk01/web/ocssw/build/src/l1agen_modis/unpack_secondary_header.c (r8099/r3)
Go to the documentation of this file.
00001 #include "PGS_MODIS_35005.h"
00002 #include "PGS_SMF.h"
00003 #include "PGS_TD.h"
00004 #include "PGS_IO.h"
00005 #include "PGS_IO_L0.h"
00006 #include "PGS_TYPES.h"
00007 #include "PH_pkt_hdr.h"
00008 #include "PD_pkt_data.h"
00009 #include "L1A_prototype.h"
00010 
00011 PGSt_SMF_status   unpack_secondary_header (PGSt_IO_L0_Packet   *pkt,
00012                                            PH_PACKET_HEADER_t  *packet_header)
00013 
00014 /*
00015 !C**********************************************************************
00016 
00017 !Description:  This function extracts the secondary header information 
00018                contained in the MODIS packet and places each item into the 
00019                appropriate variable in the PH_PACKET_HEADER_t structure.
00020 
00021 !Input Parameters:
00022                PGSt_IO_L0_Packet   *pkt            ** The MODIS packet         **
00023 
00024 !Output Parameters:
00025                PH_PACKET_HEADER_t  *packet_header  ** Pointer to structure that 
00026                                                    contains unpacked contents 
00027                                                    of the primary header,
00028                                                    secondary header, and MODIS 
00029                                                    header                      **
00030 
00031 Return Values: 
00032                MODIS_S_SUCCESS                    (PGS_MODIS_35005.h)
00033                MODIS_E_FAILED_TIMECODE_CONV       (PGS_MODIS_35005.h)
00034                MODIS_E_INV_QL_FLAG                (PGS_MODIS_35005.h)
00035                MODIS_E_INV_PKT_TYPE               (PGS_MODIS_35005.h)
00036 
00037 Externally Defined:
00038                PGSt_IO_L0_Packet                  (PGS_IO.h)
00039                PGSt_SMF_status                    (PGS_SMF.h)
00040                PH_PACKET_HEADER_t                 (PH_pkt_hdr.h)
00041                PH_SEC_TIME_TAG_NUM_BYTES          (PH_pkt_hdr.h)
00042                PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET (PH_pkt_hdr.h)
00043                PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET  (PH_pkt_hdr.h)
00044                PH_SEC_QUICK_LOOK_FLAG_NUM_BITS    (PH_pkt_hdr.h)
00045                PH_SEC_QUICK_LOOK_FLAG_SET         (PH_pkt_hdr.h)
00046                PH_SEC_PKT_TYPE_BYTE_OFFSET        (PH_pkt_hdr.h)
00047                PH_SEC_PKT_TYPE_BIT_OFFSET         (PH_pkt_hdr.h)
00048                PH_SEC_PKT_TYPE_NUM_BITS           (PH_pkt_hdr.h)
00049                PH_SEC_PKT_TYPE_ENG2_GROUP         (PH_pkt_hdr.h)
00050                PH_SEC_SCAN_CNT_BYTE_OFFSET        (PH_pkt_hdr.h)
00051                PH_SEC_SCAN_CNT_BIT_OFFSET         (PH_pkt_hdr.h)
00052                PH_SEC_SCAN_CNT_NUM_BITS           (PH_pkt_hdr.h)
00053                PH_SEC_MIRROR_SIDE_BYTE_OFFSET     (PH_pkt_hdr.h)
00054                PH_SEC_MIRROR_SIDE_BIT_OFFSET      (PH_pkt_hdr.h)
00055                PH_SEC_MIRROR_SIDE_NUM_BITS        (PH_pkt_hdr.h)
00056                PH_SEC_PKT_TYPE_SPARE              (PH_pkt_hdr.h)
00057 
00058 Called By:
00059                unpack_packet_header
00060 
00061 Routines Called:
00062                extr_bits                       
00063                log_fmt_msg
00064                PGS_TD_EOSAMtoTAI
00065                PGS_SMF_TestStatusLevel 
00066 
00067 !Revision History:
00068                Revision 2.2  2000/07/14
00069                John Seaton  (seaton@ltpmail.gsfc.nasa.gov)
00070                Implemented Aqua changes.
00071 
00072                Revision 2.1  1999/08/20  10:25
00073                John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
00074                Updated the verification of the packet type in the
00075                secondary header to check for all spare values.
00076 
00077                Revision 2.0  1997/07/14  14:25
00078                Tom Johnson/SAIC/GSC (johnson@ltpmail.gsfc.nasa.gov)
00079                Created from unpack_packet_header and validate_packet
00080 
00081                Revision 1.0  1997/06/18  16:40 EDT
00082                Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
00083                Baseline from Version 1.
00084 
00085 !Team-unique Header:
00086                This software is developed by the MODIS Science 
00087                Data Support Team (SDST) for the National Aeronautics
00088                and Space Administration (NASA), Goddard Space Flight
00089                Center (GSFC), under contract NAS5-32373.
00090 
00091 !References and Credits:
00092                None
00093 
00094 !Design Notes: 
00095                The details for the packet header data locations were taken
00096                from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
00097                Requirements List (CDRL) 305, MODIS Engineering Telemetry 
00098                Description, Figures 3-7 and 30-8.
00099 
00100 
00101 !END************************************************************************
00102 */
00103 
00104 {
00105   /***************************************************************************/
00106   /*              Declare and Initialize Local Variables                     */
00107   /***************************************************************************/
00108 
00109   PGSt_SMF_status  returnStatus;   /* SMF-style message returned by function */
00110   PGSt_SMF_status  PGS_status;     /* SMF-style message returned by function */
00111   char             msg[300];       /* amplifying message                     */
00112   int              i;              /* loop counter                           */
00113 
00114   char             *routine = "unpack_secondary_header";
00115 
00116   /***************************************************************************/
00117 
00118 
00119   /***************************************************************************/
00120   /*                                                                         */
00121   /*  Set returnStatus equal to MODIS_S_SUCCESS                              */
00122   /*                                                                         */
00123   /*  set routine to "unpack_secondary_header" (done during declaration)     */
00124   /*                                                                         */
00125   /***************************************************************************/
00126 
00127   returnStatus = MODIS_S_SUCCESS;
00128 
00129   
00130   /***************************************************************************/
00131   /*                                                                         */
00132   /*  FOR i equals all 8 bytes (PH_SEC_TIME_TAG_NUM_BYTES) in secondary      */
00133   /*     header time tag                                                     */
00134   /*     set packet_header->pkt_time_code[i] to pkt secondary header         */
00135   /*        time tag[i]                                                      */
00136   /*  ENDFOR                                                                 */
00137   /*                                                                         */
00138   /***************************************************************************/
00139 
00140   for (i = 0; i < PH_SEC_TIME_TAG_NUM_BYTES; i++)
00141      packet_header->pkt_time_code[i] = 
00142                        (PGSt_scTime) pkt[i+PH_SEC_TIME_TAG_BYTE_OFFSET];
00143 
00144   /***************************************************************************/
00145   /*                                                                         */
00146   /* The MODIS instrument on both the Terra and Aqua spacecraft use segmented*/
00147   /* time codes. This allows the toolkit function PGS_TD_EOSAMtoTAI to be    */
00148   /* used for both terra and aqua spacecrafts.                               */
00149   /*                                                                         */
00150   /* CALL PGS_TD_EOSAMtoTAI to convert the time tag from EOS AM format to TAI*/
00151   /*     INPUT:  packet_header->pkt_time_code                                */
00152   /*     OUTPUT: packet_header->pkt_TAI_time                                 */
00153   /*     RETURN: returnStatus                                                */
00154   /*                                                                         */
00155   /***************************************************************************/
00156 
00157     PGS_status = PGS_TD_EOSAMtoTAI(packet_header->pkt_time_code,
00158        &packet_header->pkt_TAI_time); 
00159 
00160   /***************************************************************************/
00161   /*                                                                         */
00162   /*  CALL PGS_SMF_TestStatusLevel to determine if the time conversion was   */
00163   /*     successful                                                          */
00164   /*    INPUT:  returnStatus                                                 */
00165   /*    OUTPUT: None                                                         */
00166   /*    RETURN: PGS_status                                                   */
00167   /*                                                                         */
00168   /*  IF PGS_status greater than or equal to PGS_SMF_MASK_LEV_E              */
00169   /*  THEN                                                                   */
00170   /*     set returnStatus to MODIS_E_FAILED_TIMECODE_CONV                    */
00171   /*     set msg to "unable to convert secondary header time tag from        */
00172   /*        spacecraft time to TAI"                                          */
00173   /*     CALL log_fmt_msg to report that the secondary header time tag was   */
00174   /*        not converted from Spacecraft time to TAI                        */
00175   /*       INPUTS: returnStatus, routine, msg                                */
00176   /*       OUTPUT: None                                                      */
00177   /*       RETURN: None                                                      */
00178   /*  ENDIF                                                                  */
00179   /*                                                                         */
00180   /***************************************************************************/
00181 
00182   if (PGS_SMF_TestStatusLevel(PGS_status) >= PGS_SMF_MASK_LEV_E) 
00183     {
00184      returnStatus = MODIS_E_FAILED_TIMECODE_CONV;
00185      strcpy (msg, "unable to convert secondary header time tag from Spacecraft time to TAI");
00186      log_fmt_msg (MODIS_E_FAILED_TIMECODE_CONV, routine, msg);
00187     }
00188 
00189 
00190   /***************************************************************************/
00191   /*                                                                         */
00192   /*  CALL extr_bits to extract the quick look flag from the packet secondary*/
00193   /*     header                                                              */
00194   /*    INPUTS: pkt, PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET,                      */
00195   /*            PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET,                          */
00196   /*            PH_SEC_QUICK_LOOK_FLAG_NUM_BITS                              */
00197   /*    OUTPUT: None                                                         */
00198   /*    RETURN: packet_header->QL_flag                                       */
00199   /*                                                                         */
00200   /*  IF packet_header->QL_flag is equal to PH_SEC_QUICK_LOOK_FLAG_SET       */
00201   /*  THEN                                                                   */
00202   /*     set returnStatus to MODIS_E_INV_QL_FLAG                             */
00203   /*     set msg to "QL flag set to %d in the packet secondary header"       */
00204   /*     CALL log_fmt_msg to report that an invalid QL flag set has been     */
00205   /*        detected in the packet secondary header"                         */
00206   /*       INPUTS: returnStatus, routine, msg                                */
00207   /*       OUTPUT: None                                                      */
00208   /*       RETURN: None                                                      */
00209   /*  ENDIF                                                                  */
00210   /*                                                                         */
00211   /***************************************************************************/
00212 
00213   packet_header->QL_flag = extr_bits (pkt, PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET,
00214      PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET, PH_SEC_QUICK_LOOK_FLAG_NUM_BITS);
00215 
00216   if (packet_header->QL_flag == PH_SEC_QUICK_LOOK_FLAG_SET)
00217     {
00218      returnStatus = MODIS_E_INV_QL_FLAG;
00219      sprintf(msg, "QL flag set to %d in the packet secondary header", 
00220              packet_header->QL_flag);
00221      log_fmt_msg (MODIS_E_INV_QL_FLAG, routine, msg);
00222     }
00223 
00224 
00225   /***************************************************************************/
00226   /*                                                                         */
00227   /*  CALL extr_bits to extract the packet type from the packet secondary    */
00228   /*     header                                                              */
00229   /*    INPUTS: pkt, PH_SEC_PKT_TYPE_BIT_OFFSET, PH_SEC_PKT_TYPE_BYTE_OFFSET,*/ 
00230   /*            PH_SEC_PKT_TYPE_NUM_BITS                                     */
00231   /*    OUTPUT: None                                                         */
00232   /*    RETURN: packet_header->pkt_type                                      */
00233   /*                                                                         */
00234   /***************************************************************************/
00235 
00236   packet_header->pkt_type = extr_bits (pkt, PH_SEC_PKT_TYPE_BIT_OFFSET, 
00237      PH_SEC_PKT_TYPE_BYTE_OFFSET, PH_SEC_PKT_TYPE_NUM_BITS);
00238 
00239   /***************************************************************************/
00240   /*                                                                         */
00241   /* The pkt_type is a 3 bit field in the secondary header. The valid values */
00242   /* for this field are 0, 1, 2, and 4. The other possible values 3, 5, 6,   */
00243   /* and 7 are spare values.                                                 */
00244   /***************************************************************************/
00245   /*                                                                         */
00246   /* IF the value of the pkt_type is a spare value                           */
00247   /* THEN                                                                    */
00248   /*   set returnStatus to MODIS_E_INV_PKT_TYPE                              */
00249   /*   set msg to "Packet Type: %d in the packet secondary header"           */
00250   /*   CALL log_fmt_msg to print an error message in LogStatus stating that  */
00251   /*      an invalid packet type has been detected in the packet secondary   */
00252   /*       header.                                                           */
00253   /*     INPUTS: MODIS_E_INV_PKT_TYPE, routine, msg                          */
00254   /*     OUTPUTS: None                                                       */
00255   /*     RETURNS: None                                                       */
00256   /* ENDIF                                                                   */
00257   /*                                                                         */
00258   /***************************************************************************/
00259 
00260   if (packet_header->pkt_type > PH_SEC_PKT_TYPE_ENG2_GROUP ||
00261       packet_header->pkt_type == PH_SEC_PKT_TYPE_SPARE)
00262     {
00263      returnStatus = MODIS_E_INV_PKT_TYPE;
00264      sprintf(msg, "Packet Type: %d in the packet secondary header", 
00265              packet_header->pkt_type);
00266      log_fmt_msg (MODIS_E_INV_PKT_TYPE, routine, msg);
00267     }
00268 
00269 
00270   /***************************************************************************/
00271   /*                                                                         */
00272   /*  CALL extr_bits to extract the scan count from the packet secondary     */
00273   /*     header                                                              */
00274   /*     INPUTS: pkt, PH_SEC_SCAN_CNT_BIT_OFFSET,                            */
00275   /*             PH_SEC_SCAN_CNT_BYTE_OFFSET, PH_SEC_SCAN_CNT_NUM_BITS       */
00276   /*     OUTPUT: None                                                        */
00277   /*     RETURN: packet_header->scan_cnt                                     */
00278   /*                                                                         */
00279   /***************************************************************************/
00280 
00281   packet_header->scan_cnt = extr_bits (pkt, PH_SEC_SCAN_CNT_BIT_OFFSET,
00282      PH_SEC_SCAN_CNT_BYTE_OFFSET, PH_SEC_SCAN_CNT_NUM_BITS);
00283 
00284 
00285   /***************************************************************************/
00286   /*                                                                         */
00287   /*  CALL extr_bits to extract the mirror side from the packet secondary    */
00288   /*     header                                                              */
00289   /*    INPUTS: pkt, PH_SEC_MIRROR_SIDE_BIT_OFFSET,                          */
00290   /*            PH_SEC_MIRROR_SIDE_BYTE_OFFSET, PH_SEC_MIRROR_SIDE_NUM_BITS  */
00291   /*    OUTPUT: None                                                         */
00292   /*    RETURN: packet_header->mirror_side                                   */
00293   /*                                                                         */
00294   /***************************************************************************/
00295 
00296   packet_header->mirror_side = extr_bits (pkt, PH_SEC_MIRROR_SIDE_BIT_OFFSET,
00297      PH_SEC_MIRROR_SIDE_BYTE_OFFSET, PH_SEC_MIRROR_SIDE_NUM_BITS);
00298 
00299 
00300   /***************************************************************************/
00301   /*                                                                         */
00302   /*  RETURN  returnStatus                                                   */
00303   /*                                                                         */
00304   /***************************************************************************/
00305 
00306   return (returnStatus);
00307 
00308 }