OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unpack_secondary_header.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35005.h"
2 #include "PGS_SMF.h"
3 #include "PGS_TD.h"
4 #include "PGS_IO.h"
5 #include "PGS_IO_L0.h"
6 #include "PGS_TYPES.h"
7 #include "PH_pkt_hdr.h"
8 #include "PD_pkt_data.h"
9 #include "L1A_prototype.h"
10 
11 PGSt_SMF_status unpack_secondary_header (PGSt_IO_L0_Packet *pkt,
12  PH_PACKET_HEADER_t *packet_header)
13 
14 /*
15 !C**********************************************************************
16 
17 !Description: This function extracts the secondary 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 that
26  contains unpacked contents
27  of the primary header,
28  secondary header, and MODIS
29  header **
30 
31 Return Values:
32  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
33  MODIS_E_FAILED_TIMECODE_CONV (PGS_MODIS_35005.h)
34  MODIS_E_INV_QL_FLAG (PGS_MODIS_35005.h)
35  MODIS_E_INV_PKT_TYPE (PGS_MODIS_35005.h)
36 
37 Externally Defined:
38  PGSt_IO_L0_Packet (PGS_IO.h)
39  PGSt_SMF_status (PGS_SMF.h)
40  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
41  PH_SEC_TIME_TAG_NUM_BYTES (PH_pkt_hdr.h)
42  PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET (PH_pkt_hdr.h)
43  PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET (PH_pkt_hdr.h)
44  PH_SEC_QUICK_LOOK_FLAG_NUM_BITS (PH_pkt_hdr.h)
45  PH_SEC_QUICK_LOOK_FLAG_SET (PH_pkt_hdr.h)
46  PH_SEC_PKT_TYPE_BYTE_OFFSET (PH_pkt_hdr.h)
47  PH_SEC_PKT_TYPE_BIT_OFFSET (PH_pkt_hdr.h)
48  PH_SEC_PKT_TYPE_NUM_BITS (PH_pkt_hdr.h)
49  PH_SEC_PKT_TYPE_ENG2_GROUP (PH_pkt_hdr.h)
50  PH_SEC_SCAN_CNT_BYTE_OFFSET (PH_pkt_hdr.h)
51  PH_SEC_SCAN_CNT_BIT_OFFSET (PH_pkt_hdr.h)
52  PH_SEC_SCAN_CNT_NUM_BITS (PH_pkt_hdr.h)
53  PH_SEC_MIRROR_SIDE_BYTE_OFFSET (PH_pkt_hdr.h)
54  PH_SEC_MIRROR_SIDE_BIT_OFFSET (PH_pkt_hdr.h)
55  PH_SEC_MIRROR_SIDE_NUM_BITS (PH_pkt_hdr.h)
56  PH_SEC_PKT_TYPE_SPARE (PH_pkt_hdr.h)
57 
58 Called By:
59  unpack_packet_header
60 
61 Routines Called:
62  extr_bits
63  log_fmt_msg
64  PGS_TD_EOSAMtoTAI
65  PGS_SMF_TestStatusLevel
66 
67 !Revision History:
68  Revision 2.2 2000/07/14
69  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
70  Implemented Aqua changes.
71 
72  Revision 2.1 1999/08/20 10:25
73  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
74  Updated the verification of the packet type in the
75  secondary header to check for all spare values.
76 
77  Revision 2.0 1997/07/14 14:25
78  Tom Johnson/SAIC/GSC (johnson@ltpmail.gsfc.nasa.gov)
79  Created from unpack_packet_header and validate_packet
80 
81  Revision 1.0 1997/06/18 16:40 EDT
82  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
83  Baseline from Version 1.
84 
85 !Team-unique Header:
86  This software is developed by the MODIS Science
87  Data Support Team (SDST) for the National Aeronautics
88  and Space Administration (NASA), Goddard Space Flight
89  Center (GSFC), under contract NAS5-32373.
90 
91 !References and Credits:
92  None
93 
94 !Design Notes:
95  The details for the packet header data locations were taken
96  from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
97  Requirements List (CDRL) 305, MODIS Engineering Telemetry
98  Description, Figures 3-7 and 30-8.
99 
100 
101 !END************************************************************************
102 */
103 
104 {
105  /***************************************************************************/
106  /* Declare and Initialize Local Variables */
107  /***************************************************************************/
108 
109  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
110  PGSt_SMF_status PGS_status; /* SMF-style message returned by function */
111  char msg[300]; /* amplifying message */
112  int i; /* loop counter */
113 
114  char *routine = "unpack_secondary_header";
115 
116  /***************************************************************************/
117 
118 
119  /***************************************************************************/
120  /* */
121  /* Set returnStatus equal to MODIS_S_SUCCESS */
122  /* */
123  /* set routine to "unpack_secondary_header" (done during declaration) */
124  /* */
125  /***************************************************************************/
126 
127  returnStatus = MODIS_S_SUCCESS;
128 
129 
130  /***************************************************************************/
131  /* */
132  /* FOR i equals all 8 bytes (PH_SEC_TIME_TAG_NUM_BYTES) in secondary */
133  /* header time tag */
134  /* set packet_header->pkt_time_code[i] to pkt secondary header */
135  /* time tag[i] */
136  /* ENDFOR */
137  /* */
138  /***************************************************************************/
139 
140  for (i = 0; i < PH_SEC_TIME_TAG_NUM_BYTES; i++)
141  packet_header->pkt_time_code[i] =
142  (PGSt_scTime) pkt[i+PH_SEC_TIME_TAG_BYTE_OFFSET];
143 
144  /***************************************************************************/
145  /* */
146  /* The MODIS instrument on both the Terra and Aqua spacecraft use segmented*/
147  /* time codes. This allows the toolkit function PGS_TD_EOSAMtoTAI to be */
148  /* used for both terra and aqua spacecrafts. */
149  /* */
150  /* CALL PGS_TD_EOSAMtoTAI to convert the time tag from EOS AM format to TAI*/
151  /* INPUT: packet_header->pkt_time_code */
152  /* OUTPUT: packet_header->pkt_TAI_time */
153  /* RETURN: returnStatus */
154  /* */
155  /***************************************************************************/
156 
157  PGS_status = PGS_TD_EOSAMtoTAI(packet_header->pkt_time_code,
158  &packet_header->pkt_TAI_time);
159 
160  /***************************************************************************/
161  /* */
162  /* CALL PGS_SMF_TestStatusLevel to determine if the time conversion was */
163  /* successful */
164  /* INPUT: returnStatus */
165  /* OUTPUT: None */
166  /* RETURN: PGS_status */
167  /* */
168  /* IF PGS_status greater than or equal to PGS_SMF_MASK_LEV_E */
169  /* THEN */
170  /* set returnStatus to MODIS_E_FAILED_TIMECODE_CONV */
171  /* set msg to "unable to convert secondary header time tag from */
172  /* spacecraft time to TAI" */
173  /* CALL log_fmt_msg to report that the secondary header time tag was */
174  /* not converted from Spacecraft time to TAI */
175  /* INPUTS: returnStatus, routine, msg */
176  /* OUTPUT: None */
177  /* RETURN: None */
178  /* ENDIF */
179  /* */
180  /***************************************************************************/
181 
182  if (PGS_SMF_TestStatusLevel(PGS_status) >= PGS_SMF_MASK_LEV_E)
183  {
184  returnStatus = MODIS_E_FAILED_TIMECODE_CONV;
185  strcpy (msg, "unable to convert secondary header time tag from Spacecraft time to TAI");
187  }
188 
189 
190  /***************************************************************************/
191  /* */
192  /* CALL extr_bits to extract the quick look flag from the packet secondary*/
193  /* header */
194  /* INPUTS: pkt, PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET, */
195  /* PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET, */
196  /* PH_SEC_QUICK_LOOK_FLAG_NUM_BITS */
197  /* OUTPUT: None */
198  /* RETURN: packet_header->QL_flag */
199  /* */
200  /* IF packet_header->QL_flag is equal to PH_SEC_QUICK_LOOK_FLAG_SET */
201  /* THEN */
202  /* set returnStatus to MODIS_E_INV_QL_FLAG */
203  /* set msg to "QL flag set to %d in the packet secondary header" */
204  /* CALL log_fmt_msg to report that an invalid QL flag set has been */
205  /* detected in the packet secondary header" */
206  /* INPUTS: returnStatus, routine, msg */
207  /* OUTPUT: None */
208  /* RETURN: None */
209  /* ENDIF */
210  /* */
211  /***************************************************************************/
212 
213  packet_header->QL_flag = extr_bits (pkt, PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET,
215 
216  if (packet_header->QL_flag == PH_SEC_QUICK_LOOK_FLAG_SET)
217  {
218  returnStatus = MODIS_E_INV_QL_FLAG;
219  sprintf(msg, "QL flag set to %d in the packet secondary header",
220  packet_header->QL_flag);
221  log_fmt_msg (MODIS_E_INV_QL_FLAG, routine, msg);
222  }
223 
224 
225  /***************************************************************************/
226  /* */
227  /* CALL extr_bits to extract the packet type from the packet secondary */
228  /* header */
229  /* INPUTS: pkt, PH_SEC_PKT_TYPE_BIT_OFFSET, PH_SEC_PKT_TYPE_BYTE_OFFSET,*/
230  /* PH_SEC_PKT_TYPE_NUM_BITS */
231  /* OUTPUT: None */
232  /* RETURN: packet_header->pkt_type */
233  /* */
234  /***************************************************************************/
235 
236  packet_header->pkt_type = extr_bits (pkt, PH_SEC_PKT_TYPE_BIT_OFFSET,
238 
239  /***************************************************************************/
240  /* */
241  /* The pkt_type is a 3 bit field in the secondary header. The valid values */
242  /* for this field are 0, 1, 2, and 4. The other possible values 3, 5, 6, */
243  /* and 7 are spare values. */
244  /***************************************************************************/
245  /* */
246  /* IF the value of the pkt_type is a spare value */
247  /* THEN */
248  /* set returnStatus to MODIS_E_INV_PKT_TYPE */
249  /* set msg to "Packet Type: %d in the packet secondary header" */
250  /* CALL log_fmt_msg to print an error message in LogStatus stating that */
251  /* an invalid packet type has been detected in the packet secondary */
252  /* header. */
253  /* INPUTS: MODIS_E_INV_PKT_TYPE, routine, msg */
254  /* OUTPUTS: None */
255  /* RETURNS: None */
256  /* ENDIF */
257  /* */
258  /***************************************************************************/
259 
260  if (packet_header->pkt_type > PH_SEC_PKT_TYPE_ENG2_GROUP ||
261  packet_header->pkt_type == PH_SEC_PKT_TYPE_SPARE)
262  {
263  returnStatus = MODIS_E_INV_PKT_TYPE;
264  sprintf(msg, "Packet Type: %d in the packet secondary header",
265  packet_header->pkt_type);
267  }
268 
269 
270  /***************************************************************************/
271  /* */
272  /* CALL extr_bits to extract the scan count from the packet secondary */
273  /* header */
274  /* INPUTS: pkt, PH_SEC_SCAN_CNT_BIT_OFFSET, */
275  /* PH_SEC_SCAN_CNT_BYTE_OFFSET, PH_SEC_SCAN_CNT_NUM_BITS */
276  /* OUTPUT: None */
277  /* RETURN: packet_header->scan_cnt */
278  /* */
279  /***************************************************************************/
280 
281  packet_header->scan_cnt = extr_bits (pkt, PH_SEC_SCAN_CNT_BIT_OFFSET,
283 
284 
285  /***************************************************************************/
286  /* */
287  /* CALL extr_bits to extract the mirror side from the packet secondary */
288  /* header */
289  /* INPUTS: pkt, PH_SEC_MIRROR_SIDE_BIT_OFFSET, */
290  /* PH_SEC_MIRROR_SIDE_BYTE_OFFSET, PH_SEC_MIRROR_SIDE_NUM_BITS */
291  /* OUTPUT: None */
292  /* RETURN: packet_header->mirror_side */
293  /* */
294  /***************************************************************************/
295 
296  packet_header->mirror_side = extr_bits (pkt, PH_SEC_MIRROR_SIDE_BIT_OFFSET,
298 
299 
300  /***************************************************************************/
301  /* */
302  /* RETURN returnStatus */
303  /* */
304  /***************************************************************************/
305 
306  return (returnStatus);
307 
308 }
#define PH_SEC_PKT_TYPE_NUM_BITS
Definition: PH_pkt_hdr.h:160
#define MODIS_E_FAILED_TIMECODE_CONV
PGSt_scTime pkt_time_code[8]
Definition: PH_pkt_hdr.h:250
#define PH_SEC_PKT_TYPE_BIT_OFFSET
Definition: PH_pkt_hdr.h:159
PGSt_SMF_status unpack_secondary_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define PH_SEC_PKT_TYPE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:158
#define PH_SEC_MIRROR_SIDE_BIT_OFFSET
Definition: PH_pkt_hdr.h:174
#define PH_SEC_PKT_TYPE_SPARE
Definition: PH_pkt_hdr.h:165
#define PH_SEC_SCAN_CNT_BIT_OFFSET
Definition: PH_pkt_hdr.h:169
#define PH_SEC_PKT_TYPE_ENG2_GROUP
Definition: PH_pkt_hdr.h:164
#define PH_SEC_MIRROR_SIDE_NUM_BITS
Definition: PH_pkt_hdr.h:175
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PH_SEC_QUICK_LOOK_FLAG_SET
Definition: PH_pkt_hdr.h:155
#define PH_SEC_SCAN_CNT_BYTE_OFFSET
Definition: PH_pkt_hdr.h:168
PGSt_double pkt_TAI_time
Definition: PH_pkt_hdr.h:251
#define PH_SEC_QUICK_LOOK_FLAG_NUM_BITS
Definition: PH_pkt_hdr.h:154
#define PH_SEC_SCAN_CNT_NUM_BITS
Definition: PH_pkt_hdr.h:170
#define MODIS_E_INV_QL_FLAG
uint32 extr_bits(uint8 *a, int start_bit, int start_byte, int num_bits)
Definition: extr_bits.c:6
#define PH_SEC_MIRROR_SIDE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:173
#define MODIS_S_SUCCESS
#define PH_SEC_QUICK_LOOK_FLAG_BIT_OFFSET
Definition: PH_pkt_hdr.h:153
string msg
Definition: mapgen.py:227
#define MODIS_E_INV_PKT_TYPE
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
#define PH_SEC_TIME_TAG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:149
#define PH_SEC_TIME_TAG_NUM_BYTES
Definition: PH_pkt_hdr.h:150
#define PH_SEC_QUICK_LOOK_FLAG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:152