OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unpack_MODIS_header.c
Go to the documentation of this file.
1 #include "PGS_SMF.h"
2 #include "PGS_TD.h"
3 #include "PGS_IO.h"
4 #include "PGS_IO_L0.h"
5 #include "PGS_TYPES.h"
6 #include "PH_pkt_hdr.h"
7 #include "PD_pkt_data.h"
8 #include "PGS_MODIS_35005.h"
9 #include "L1A_prototype.h"
10 
11 PGSt_SMF_status unpack_MODIS_header (PGSt_IO_L0_Packet *pkt,
12  PH_PACKET_HEADER_t *packet_header )
13 
14 /*
15 !C************************************************************************
16 
17 !Description: This function extracts the MODIS header information
18  contained in the MODIS packet and places each item into the
19  appropriate variable in the PH_PACKET_HEADER_t structure.
20 
21 !Input Parameters:
22  PGSt_IO_L0_Packet *pkt ** The MODIS packet **
23 
24 !Output Parameters:
25  PH_PACKET_HEADER_t *packet_header ** Pointer to structure
26  that contains unpacked
27  contents of the primary
28  header, secondary header,
29  and MODIS header **
30 
31 Return Values:
32  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
33  MODIS_E_EARTH_FR_CNT_INVALID (PGS_MODIS_35005.h)
34  MODIS_E_CAL_FR_CNT_INVALID (PGS_MODIS_35005.h)
35 
36 Externally Defined:
37  PGSt_IO_L0_Packet (PGS_IO.h)
38  PGSt_SMF_status (PGS_SMF.h)
39  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
40  PH_SEC_PKT_TYPE_ENG1_GROUP (PH_pkt_hdr.h)
41  PH_SEC_PKT_TYPE_ENG2_GROUP (PH_pkt_hdr.h)
42  PH_MOD_SOURCE_ID_TYPE_FLAG_BYTE_OFFSET (PH_pkt_hdr.h)
43  PH_MOD_SOURCE_ID_TYPE_FLAG_BIT_OFFSET (PH_pkt_hdr.h)
44  PH_MOD_SOURCE_ID_TYPE_FLAG_NUM_BITS (PH_pkt_hdr.h)
45  PH_MOD_SOURCE_ID_TYPE_FLAG_EARTH (PH_pkt_hdr.h)
46  PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BYTE_OFFSET (PH_pkt_hdr.h)
47  PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BIT_OFFSET (PH_pkt_hdr.h)
48  PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_NUM_BITS (PH_pkt_hdr.h)
49  PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_LIMIT (PH_pkt_hdr.h)
50  PH_MOD_SOURCE_ID_CAL_TYPE_BYTE_OFFSET (PH_pkt_hdr.h)
51  PH_MOD_SOURCE_ID_CAL_TYPE_BIT_OFFSET (PH_pkt_hdr.h)
52  PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS (PH_pkt_hdr.h)
53  PH_MOD_SOURCE_ID_CAL_MODE_BYTE_OFFSET (PH_pkt_hdr.h)
54  PH_MOD_SOURCE_ID_CAL_MODE_BIT_OFFSET (PH_pkt_hdr.h)
55  PH_MOD_SOURCE_ID_CAL_MODE_NUM_BITS (PH_pkt_hdr.h)
56  PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BYTE_OFFSET (PH_pkt_hdr.h)
57  PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BIT_OFFSET (PH_pkt_hdr.h)
58  PH_MOD_SOURCE_ID_CAL_FRAME_CNT_NUM_BITS (PH_pkt_hdr.h)
59  PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX (PH_pkt_hdr.h)
60  PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS (PH_pkt_hdr.h)
61  PH_MOD_FPA_AEM_CONFIG_BYTE_OFFSET (PH_pkt_hdr.h)
62  PH_MOD_FPA_AEM_CONFIG_BIT_OFFSET (PH_pkt_hdr.h)
63  PH_MOD_FPA_AEM_CONFIG_NUM_BITS (PH_pkt_hdr.h)
64  PH_MOD_SCI_STATE_BYTE_OFFSET (PH_pkt_hdr.h)
65  PH_MOD_SCI_STATE_BIT_OFFSET (PH_pkt_hdr.h)
66  PH_MOD_SCI_STATE_NUM_BITS (PH_pkt_hdr.h)
67  PH_MOD_SCI_ABNORM_BYTE_OFFSET (PH_pkt_hdr.h)
68  PH_MOD_SCI_ABNORM_BIT_OFFSET (PH_pkt_hdr.h)
69  PH_MOD_SCI_ABNORM_NUM_BITS (PH_pkt_hdr.h)
70  PD_NUM_BITS_IN_BYTE (PD_pkt_data.h)
71 
72 Called By:
73  unpack_packet_header
74 
75 Routines Called:
76  extr_bits
77  log_fmt_msg
78 
79 !Revision History:
80  James Kuyper Jr: James.R.Kuyper@nasa.gov
81 
82  $Log: unpack_MODIS_header.c,v $
83  Revision 6.4 2015/08/22 20:36:00 jkuyper
84  Changed to treat frame counts less than 1 as invalid.
85 
86  Revision 6.3 2014/10/22 18:33:26 jkuyper
87  Corrected second error message the same way as the first one.
88 
89  Revision 6.2 2014/10/20 21:27:46 jkuyper
90  Resolve Bug 5570 by moving the line that sets the earth_frame_count to a fill value.
91 
92  Revision 6.1 2010/08/25 18:26:28 kuyper
93  Changed to always extract the source_ID_type_flag, even for engineering data
94  packets.
95 
96  Revision 5.1 2005/12/30 19:30:32 vlin
97  validate frame counts using 1354
98 
99 
100 !Team-unique Header:
101  This software is developed by the MODIS Science
102  Data Support Team (SDST) for the National Aeronautics
103  and Space Administration (NASA), Goddard Space Flight
104  Center (GSFC), under contract NAS5-32373.
105 
106 Design Notes:
107  The details for the packet header data locations were taken
108  from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
109  Requirements List (CDRL) 305, MODIS Engineering Telemetry
110  Description, Figures 3-7 and 30-8.
111 
112 
113 !END************************************************************************
114 */
115 
116 
117 {
118 
119  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
120  char *routine = "unpack_MODIS_header";
121  char msg[300];
122  int i;
123 
124 
125  returnStatus = MODIS_S_SUCCESS;
126 
127  packet_header->source_ID_type_flag = extr_bits (pkt,
131 
132  if ((packet_header->pkt_type != PH_SEC_PKT_TYPE_ENG1_GROUP) &&
133  (packet_header->pkt_type != PH_SEC_PKT_TYPE_ENG2_GROUP))
134  {
136  {
137  packet_header->earth_frame_cnt = extr_bits (pkt,
141 
142  if (packet_header->earth_frame_cnt < 1 ||
144  {
145  returnStatus = MODIS_E_EARTH_FR_CNT_INVALID;
146  sprintf(msg, "Earth Frame Count: %d",
147  packet_header->earth_frame_cnt);
149 
150  packet_header->earth_frame_cnt = -1;
151  }
152 
153  }
154 
155  else
156  {
159 
162 
163  packet_header->cal_frame_cnt = extr_bits (pkt,
167 
168  if (packet_header->cal_frame_cnt < 1 ||
170  {
171  returnStatus = MODIS_E_CAL_FR_CNT_INVALID;
172  sprintf(msg, "Calibration Frame Count: %d",
173  packet_header->cal_frame_cnt);
175  packet_header->cal_frame_cnt = -1;
176  }
177  }
178  }
179 
180  for ( i = 0; i < PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS; i++ )
181  packet_header->fpa_aem_config[i] = extr_bits(pkt,
186 
187  packet_header->sci_state = extr_bits (pkt, PH_MOD_SCI_STATE_BIT_OFFSET,
189 
190  packet_header->sci_abnorm = extr_bits (pkt, PH_MOD_SCI_ABNORM_BIT_OFFSET,
192 
193  return (returnStatus);
194 
195 }
#define PH_MOD_SOURCE_ID_CAL_MODE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:205
#define PH_MOD_SCI_STATE_NUM_BITS
Definition: PH_pkt_hdr.h:225
#define PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BIT_OFFSET
Definition: PH_pkt_hdr.h:214
#define PH_MOD_SOURCE_ID_CAL_FRAME_CNT_NUM_BITS
Definition: PH_pkt_hdr.h:215
#define PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS
Definition: PH_pkt_hdr.h:199
#define PH_MOD_FPA_AEM_CONFIG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:218
PGSt_SMF_status unpack_MODIS_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define PH_MOD_SOURCE_ID_CAL_TYPE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:197
#define MODIS_E_EARTH_FR_CNT_INVALID
int8 fpa_aem_config[PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS]
Definition: PH_pkt_hdr.h:261
#define PH_MOD_SOURCE_ID_CAL_MODE_BIT_OFFSET
Definition: PH_pkt_hdr.h:206
#define PD_NUM_BITS_IN_BYTE
Definition: PD_pkt_data.h:71
#define PH_MOD_SOURCE_ID_CAL_FRAME_CNT_MAX
Definition: PH_pkt_hdr.h:216
#define PH_MOD_SCI_STATE_BIT_OFFSET
Definition: PH_pkt_hdr.h:224
#define PH_SEC_PKT_TYPE_ENG2_GROUP
Definition: PH_pkt_hdr.h:164
#define PH_MOD_FPA_AEM_CONFIG_BIT_OFFSET
Definition: PH_pkt_hdr.h:219
#define PH_MOD_SCI_ABNORM_BIT_OFFSET
Definition: PH_pkt_hdr.h:230
#define MODIS_E_CAL_FR_CNT_INVALID
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BYTE_OFFSET
Definition: PH_pkt_hdr.h:191
#define PH_MOD_SOURCE_ID_TYPE_FLAG_EARTH
Definition: PH_pkt_hdr.h:188
#define PH_MOD_FPA_AEM_CONFIG_NUM_BITS
Definition: PH_pkt_hdr.h:220
#define PH_MOD_SCI_ABNORM_NUM_BITS
Definition: PH_pkt_hdr.h:231
uint32 extr_bits(uint8 *a, int start_bit, int start_byte, int num_bits)
Definition: extr_bits.c:6
#define PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_NUM_BITS
Definition: PH_pkt_hdr.h:193
#define PH_MOD_SOURCE_ID_CAL_MODE_NUM_BITS
Definition: PH_pkt_hdr.h:207
#define PH_SEC_PKT_TYPE_ENG1_GROUP
Definition: PH_pkt_hdr.h:163
#define PH_MOD_SCI_ABNORM_BYTE_OFFSET
Definition: PH_pkt_hdr.h:229
#define MODIS_S_SUCCESS
#define PH_MOD_SOURCE_ID_CAL_TYPE_BIT_OFFSET
Definition: PH_pkt_hdr.h:198
#define PH_MOD_SOURCE_ID_CAL_FRAME_CNT_BYTE_OFFSET
Definition: PH_pkt_hdr.h:213
#define PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS
Definition: PH_pkt_hdr.h:221
#define PH_MOD_SCI_STATE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:223
string msg
Definition: mapgen.py:227
#define PH_MOD_SOURCE_ID_TYPE_FLAG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:185
int i
Definition: decode_rs.h:71
#define PH_MOD_SOURCE_ID_TYPE_FLAG_NUM_BITS
Definition: PH_pkt_hdr.h:187
#define PH_MOD_SOURCE_ID_TYPE_FLAG_BIT_OFFSET
Definition: PH_pkt_hdr.h:186
#define PH_MOD_SOURCE_ID_EARTH_FRAME_CNT_BIT_OFFSET
Definition: PH_pkt_hdr.h:192
#define PH_REALISTIC_NUM_EV_FRAMES
Definition: PH_pkt_hdr.h:94