OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unpack_packet_contents.c
Go to the documentation of this file.
1 #include "PGS_IO.h"
2 #include "hdfi.h"
3 #include "PH_pkt_hdr.h"
4 #include "PD_pkt_data.h"
5 #include "L1A_prototype.h"
6 
7 void unpack_packet_contents (PGSt_IO_L0_Packet *pkt,
8  PH_PACKET_HEADER_t *pkt_header,
9  uint16 *pkt_contents)
10 
11 /*
12 !C************************************************************************
13 
14 !Description: This function extracts the contents contained in the data
15  field in the MODIS packet. The contents is extracted from
16  the MODIS packet in 12 bit words and converted it into 16
17  bit words and placed in an array.
18 
19 !Input Parameters:
20  PGSt_IO_L0_Packet *pkt ** The current MODIS packet to **
21  ** be unpacked **
22 
23  PH_PACKET_HEADER_t *pkt_header ** The current MODIS **
24  ** packet's packet header **
25 
26 !Output Parameters:
27  uint16 *pkt_contents ** The unpacked data **
28  ** structure; every **
29  ** 12-bit set is unpacked**
30  ** into 16 bits. **
31 
32 Return Values:
33  None
34 
35 Externally Defined:
36  PD_NUM_ELMTS_IN_DATA_FIELD_NIGHT_PKT (PD_pkt_data.h)
37  PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT (PD_pkt_data.h)
38  PH_NUM_12BIT_WORDS_IN_HEADER (PH_pkt_hdr.h)
39  PH_SEC_PKT_TYPE_NIGHT_GROUP (PH_pkt_hdr.h)
40  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
41  PGSt_IO_L0_Packet (PGS_IO.h)
42  uint16 (hdfi.h)
43 
44 Called by:
45  load_eng_data
46  process_a_packet
47  process_a_scan
48 
49 Routines Called:
50  extr_bits
51 
52 !Revision History:
53  Revision 2.0 1997/08/14 13:45 EDT
54  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
55  Recreating module per Version 2 development.
56 
57  Revision 1.0 1997/06/18 16:40 EDT
58  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
59  Baseline from Version 1.
60 
61 !Team-unique Header:
62  This software is developed by the MODIS Science
63  Data Support Team (SDST) for the National Aeronautics
64  and Space Administration (NASA), Goddard Space Flight
65  Center (GSFC), under contract NAS5-32373.
66 
67 !References and Credits:
68  None
69 
70 !Design Notes:
71  The CODE below was developed in C language.
72 
73 !END***********************************************************************
74 */
75 
76  {
77  /**************************************************************************/
78  /* */
79  /* Define and Initialize Local Variables */
80  /* */
81  /**************************************************************************/
82 
83  int num_12bit_words; /* number of unpacked words that will be */
84  /* created from the packet */
85  int i; /* loop variable */
86 
87  PGSt_IO_L0_Packet a[3], b; /* temporary variables to hold bytes */
88  uint16 nibble1, nibble2; /* temporary variables to hold words */
89  uint16 f1, f2; /* temporary variables to hold words */
90  int cnt; /* counter for the 12-bit fields */
91  int offset; /* offset inside the packet */
92 
93  num_12bit_words = 0;
94 
95  /**************************************************************************/
96  /* */
97  /* Determine the number of 12 bit words in the data field based on the */
98  /* packet type. All non-night packets have the longer number of elements */
99  /* */
100  /* IF PH_PACKET_HEADER_t.pkt_type equals PH_SEC_PKT_TYPE_NIGHT_GROUP */
101  /* THEN */
102  /* Set num_12bit_words equal to PH_NUM_12BIT_WORDS_IN_HEADER + */
103  /* PD_NUM_ELMTS_IN_DATA_FIELD_NIGHT_PKT + 1 */
104  /* ELSE */
105  /* Set num_12bit_words equal to PH_NUM_12BIT_WORDS_IN_HEADER + */
106  /* PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT + 1 */
107  /* ENDIF */
108  /* */
109  /**************************************************************************/
110 
111  if (pkt_header->pkt_type == PH_SEC_PKT_TYPE_NIGHT_GROUP)
112  num_12bit_words = PH_NUM_12BIT_WORDS_IN_HEADER +
114  else
115  num_12bit_words = PH_NUM_12BIT_WORDS_IN_HEADER +
117 
118 
119  /**************************************************************************/
120  /* */
121  /* FOR i equal to 0 upto (num_12bit_words/2) */
122  /* */
123  /* read 3 bytes from pkt and place them into the array a[3] */
124  /* */
125  /**************************************************************************/
126 
127  cnt = num_12bit_words/2;
128  for (i=0; i<cnt; i++)
129  {
130  offset = i*3;
131 
132  a[0] = *(pkt+offset);
133  a[1] = *(pkt+offset+1);
134  a[2] = *(pkt+offset+2);
135 
136 
137  /**************************************************************************/
138  /* */
139  /* extract low 4 bits from the middle byte */
140  /* */
141  /* extract high 4 bits from the middle byte */
142  /* */
143  /**************************************************************************/
144 
145  b = a[1];
146  nibble1 = b & 0x0f;
147  nibble2 = (b & 0xf0) >>4;
148 
149 
150  /**************************************************************************/
151  /* */
152  /* put low 4 bits with third byte together */
153  /* */
154  /* put high 4 bits with first byte together */
155  /* */
156  /**************************************************************************/
157 
158  f2 = a[2] | ((uint16)nibble1)<<8;
159  f1 = nibble2 | ((uint16)a[0])<<4;
160 
161 
162  /**************************************************************************/
163  /* */
164  /* place padded values into pkt_contents[] */
165  /* */
166  /* ENDFOR */
167  /* */
168  /**************************************************************************/
169 
170  pkt_contents[i*2] = f1;
171  pkt_contents[i*2+1] = f2;
172  }
173 
174  } /* End of routine unpack_packet_contents */
#define PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT
Definition: PD_pkt_data.h:79
float f1(float x)
#define PD_NUM_ELMTS_IN_DATA_FIELD_NIGHT_PKT
Definition: PD_pkt_data.h:78
void unpack_packet_contents(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, uint16 *pkt_contents)
float f2(float y)
#define PH_NUM_12BIT_WORDS_IN_HEADER
Definition: PH_pkt_hdr.h:78
#define PH_SEC_PKT_TYPE_NIGHT_GROUP
Definition: PH_pkt_hdr.h:162
data_t b[NROOTS+1]
Definition: decode_rs.h:77
l2prod offset
int i
Definition: decode_rs.h:71
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424