ocssw  1.0
/disk01/web/ocssw/build/src/l1agen_modis/unpack_MODIS_header.c (r9873/r7924)
Go to the documentation of this file.
00001 #include "PGS_SMF.h"
00002 #include "PGS_TD.h"
00003 #include "PGS_IO.h"
00004 #include "PGS_IO_L0.h"
00005 #include "PGS_TYPES.h"
00006 #include "PH_pkt_hdr.h"
00007 #include "PD_pkt_data.h"
00008 #include "PGS_MODIS_35005.h"
00009 #include "L1A_prototype.h"
00010 
00011 PGSt_SMF_status   unpack_MODIS_header (PGSt_IO_L0_Packet   *pkt,
00012                                        PH_PACKET_HEADER_t  *packet_header )
00013 
00014 /*
00015 !C************************************************************************
00016 
00017 !Description:  This function extracts the MODIS 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 
00026                                                     that contains unpacked 
00027                                                     contents of the primary
00028                                                     header, secondary header, 
00029                                                     and MODIS header    **
00030 
00031 Return Values: 
00032                MODIS_S_SUCCESS                               (PGS_MODIS_35005.h)
00033                MODIS_E_EARTH_FR_CNT_EXC_LIM                  (PGS_MODIS_35005.h)
00034                MODIS_E_CAL_FR_CNT_EXC_LIM                    (PGS_MODIS_35005.h)
00035 
00036 Externally Defined:
00037                PGSt_IO_L0_Packet                             (PGS_IO.h)
00038                PGSt_SMF_status                               (PGS_SMF.h)
00039                PH_PACKET_HEADER_t                            (PH_pkt_hdr.h)
00040                PH_SEC_PKT_TYPE_ENG1_GROUP                    (PH_pkt_hdr.h)
00041                PH_SEC_PKT_TYPE_ENG2_GROUP                    (PH_pkt_hdr.h)
00042                PH_MOD_SOURCE_ID_TYPE_FLAG_BYTE_OFFSET        (PH_pkt_hdr.h)
00043                PH_MOD_SOURCE_ID_TYPE_FLAG_BIT_OFFSET         (PH_pkt_hdr.h)
00044                PH_MOD_SOURCE_ID_TYPE_FLAG_NUM_BITS           (PH_pkt_hdr.h)
00045                PH_MOD_SOURCE_ID_TYPE_FLAG_EARTH              (PH_pkt_hdr.h)
00046                PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BYTE_OFFSET  (PH_pkt_hdr.h)
00047                PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BIT_OFFSET   (PH_pkt_hdr.h)
00048                PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_NUM_BITS     (PH_pkt_hdr.h)
00049                PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_LIMIT        (PH_pkt_hdr.h)
00050                PH_MOD_SOURCE_ID_CAL_TYPE_BYTE_OFFSET         (PH_pkt_hdr.h)
00051                PH_MOD_SOURCE_ID_CAL_TYPE_BIT_OFFSET          (PH_pkt_hdr.h)
00052                PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS            (PH_pkt_hdr.h)
00053                PH_MOD_SOURCE_ID_CAL_MODE_BYTE_OFFSET         (PH_pkt_hdr.h)
00054                PH_MOD_SOURCE_ID_CAL_MODE_BIT_OFFSET          (PH_pkt_hdr.h)
00055                PH_MOD_SOURCE_ID_CAL_MODE_NUM_BITS            (PH_pkt_hdr.h)
00056                PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BYTE_OFFSET    (PH_pkt_hdr.h)
00057                PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BIT_OFFSET     (PH_pkt_hdr.h)
00058                PH_MOD_SOURCE_ID_CAL_FRAME_CNT_NUM_BITS       (PH_pkt_hdr.h)
00059                PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX            (PH_pkt_hdr.h)
00060                PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS            (PH_pkt_hdr.h)
00061                PH_MOD_FPA_AEM_CONFIG_BYTE_OFFSET             (PH_pkt_hdr.h)
00062                PH_MOD_FPA_AEM_CONFIG_BIT_OFFSET              (PH_pkt_hdr.h)
00063                PH_MOD_FPA_AEM_CONFIG_NUM_BITS                (PH_pkt_hdr.h)
00064                PH_MOD_SCI_STATE_BYTE_OFFSET                  (PH_pkt_hdr.h)
00065                PH_MOD_SCI_STATE_BIT_OFFSET                   (PH_pkt_hdr.h)
00066                PH_MOD_SCI_STATE_NUM_BITS                     (PH_pkt_hdr.h)
00067                PH_MOD_SCI_ABNORM_BYTE_OFFSET                 (PH_pkt_hdr.h)
00068                PH_MOD_SCI_ABNORM_BIT_OFFSET                  (PH_pkt_hdr.h)
00069                PH_MOD_SCI_ABNORM_NUM_BITS                    (PH_pkt_hdr.h)
00070                PD_NUM_BITS_IN_BYTE                           (PD_pkt_data.h)
00071 
00072 Called By:
00073                unpack_packet_header
00074 
00075 Routines Called:
00076                extr_bits                       
00077                log_fmt_msg
00078 
00079 !Revision History:
00080   $Log: unpack_MODIS_header.c,v $
00081   Revision 6.1  2010/08/25 18:26:28  kuyper
00082   Changed to always extract the source_ID_type_flag, even for engineering data
00083     packets.
00084 
00085   Revision 5.1  2005/12/30 19:30:32  vlin
00086   validate frame counts using 1354
00087 
00088 
00089 !Team-unique Header:
00090                This software is developed by the MODIS Science 
00091                Data Support Team (SDST) for the National Aeronautics
00092                and Space Administration (NASA), Goddard Space Flight
00093                Center (GSFC), under contract NAS5-32373.
00094 
00095 Design Notes: 
00096                The details for the packet header data locations were taken
00097                from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
00098                Requirements List (CDRL) 305, MODIS Engineering Telemetry 
00099                Description, Figures 3-7 and 30-8.
00100 
00101 
00102 !END************************************************************************
00103 */
00104 
00105 
00106 {
00107 
00108   PGSt_SMF_status  returnStatus;   /* SMF-style message returned by function */
00109   char             *routine = "unpack_MODIS_header";
00110   char             msg[300];
00111   int              i;
00112 
00113 
00114   returnStatus = MODIS_S_SUCCESS;
00115 
00116   packet_header->source_ID_type_flag = extr_bits (pkt,
00117       PH_MOD_SOURCE_ID_TYPE_FLAG_BIT_OFFSET,
00118       PH_MOD_SOURCE_ID_TYPE_FLAG_BYTE_OFFSET,
00119       PH_MOD_SOURCE_ID_TYPE_FLAG_NUM_BITS);
00120 
00121   if ((packet_header->pkt_type != PH_SEC_PKT_TYPE_ENG1_GROUP) &&
00122      (packet_header->pkt_type != PH_SEC_PKT_TYPE_ENG2_GROUP))
00123     {
00124      if (packet_header->source_ID_type_flag == PH_MOD_SOURCE_ID_TYPE_FLAG_EARTH)
00125        {
00126         packet_header->earth_frame_cnt = extr_bits (pkt,
00127            PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BIT_OFFSET,
00128            PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BYTE_OFFSET,
00129            PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_NUM_BITS);
00130 
00131         if (packet_header->earth_frame_cnt > 1354)
00132           {
00133            packet_header->earth_frame_cnt = -1;
00134            returnStatus = MODIS_E_EARTH_FR_CNT_EXC_LIM;
00135            sprintf(msg, "Earth Frame Count: %d", packet_header->earth_frame_cnt);
00136            log_fmt_msg (MODIS_E_EARTH_FR_CNT_EXC_LIM, routine, msg);
00137           }
00138 
00139        }
00140 
00141      else
00142        {
00143         packet_header->cal_type = extr_bits (pkt, PH_MOD_SOURCE_ID_CAL_TYPE_BIT_OFFSET,
00144            PH_MOD_SOURCE_ID_CAL_TYPE_BYTE_OFFSET, PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS);
00145 
00146         packet_header->cal_mode = extr_bits (pkt, PH_MOD_SOURCE_ID_CAL_MODE_BIT_OFFSET,
00147            PH_MOD_SOURCE_ID_CAL_MODE_BYTE_OFFSET, PH_MOD_SOURCE_ID_CAL_MODE_NUM_BITS);
00148 
00149         packet_header->cal_frame_cnt = extr_bits (pkt,
00150            PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BIT_OFFSET,
00151            PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BYTE_OFFSET,
00152            PH_MOD_SOURCE_ID_CAL_FRAME_CNT_NUM_BITS);
00153 
00154         if (packet_header->cal_frame_cnt > PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX)
00155           {
00156            packet_header->cal_frame_cnt = -1;
00157            returnStatus = MODIS_E_CAL_FR_CNT_EXC_LIM;
00158            sprintf(msg, "Calibration Frame Count: %d", packet_header->cal_frame_cnt);
00159            log_fmt_msg (MODIS_E_CAL_FR_CNT_EXC_LIM, routine, msg);
00160           }
00161        }
00162     }
00163 
00164   for ( i = 0; i < PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS; i++ )
00165      packet_header->fpa_aem_config[i] = extr_bits(pkt,
00166         ((PH_MOD_FPA_AEM_CONFIG_BIT_OFFSET + i) % PD_NUM_BITS_IN_BYTE),
00167         (PH_MOD_FPA_AEM_CONFIG_BYTE_OFFSET +
00168         ((PH_MOD_FPA_AEM_CONFIG_BIT_OFFSET + i) / PD_NUM_BITS_IN_BYTE)),
00169         PH_MOD_FPA_AEM_CONFIG_NUM_BITS);
00170 
00171   packet_header->sci_state = extr_bits (pkt, PH_MOD_SCI_STATE_BIT_OFFSET,
00172      PH_MOD_SCI_STATE_BYTE_OFFSET, PH_MOD_SCI_STATE_NUM_BITS);
00173 
00174   packet_header->sci_abnorm = extr_bits (pkt, PH_MOD_SCI_ABNORM_BIT_OFFSET,
00175      PH_MOD_SCI_ABNORM_BYTE_OFFSET, PH_MOD_SCI_ABNORM_NUM_BITS);
00176 
00177   return (returnStatus);
00178 
00179 }