OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
packet_of_scan.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35005.h"
2 #include "L1A_prototype.h"
3 
4 
5 PGSt_SMF_status packet_of_scan ( PH_PACKET_HEADER_t *pkt_header,
6  PGSt_double next_scan_start_time,
7  int8 *previous_scan_count,
8  SC_SCAN_PROC_STATE_t *scan_proc_state,
9  PGSt_IO_L0_VirtualDataSet *L0_file )
10 
11 /*******************************************************************************
12 !C
13 
14 !Description: This routine determines, from the pkt_header, whether a
15  packet belongs in the current scan, the next scan, or is
16  a misplaced packet because of a corrupted time stamp field.
17 
18 !Input Parameters:
19  PH_PACKET_HEADER_t pkt_header Unpacked packet header
20  PGSt_double next_scan_start_time Estimated (maximum) start
21  time of the next scan
22  PGSt_IO_L0_VirtualDataSet L0_file The L0 file that contains the
23  packets
24 
25 !Output Parameters: None
26 
27 !Input/Output Parameters:
28  int8 previous_scan_count scan count field of last
29  valid packet
30  SC_SCAN_PROC_STATE_t scan_proc_state processing state of scan used
31  to identify misplaced packets
32 
33 Return Values:
34  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
35  MODIS_M_PKT_NOT_IN_SCAN (PGS_MODIS_35005.h)
36  MODIS_E_SCANCNT_NOT_VALID (PGS_MODIS_35005.h)
37  MODIS_E_INV_PKT_TIME (PGS_MODIS_35005.h)
38 
39 Externally Defined:
40  int8 (hdfi.h)
41  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
42  MODIS_M_PKT_NOT_IN_SCAN (PGS_MODIS_35005.h)
43  MODIS_E_SCANCNT_NOT_VALID (PGS_MODIS_35005.h)
44  MODIS_E_INV_PKT_TIME (PGS_MODIS_35005.h)
45  PGSt_double (PGS_TYPES.h)
46  PGSt_IO_L0_VirtualDataSet (PGS_SMF.h)
47  PGSt_SMF_status (PGS_SMF.h)
48  PH_MOD_SOURCE_ID_TYPE_FLAG_CAL (PH_pkt_hdr.h)
49  PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS (PH_pkt_hdr.h)
50  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
51  SC_FILL_VALUE (SC_scan.h)
52  SC_SCAN_PROC_STATE_t (SC_scan.h)
53  SC_SCAN_RATE_TOLERANCE (SC_scan.h)
54  uint8 (hdfi.h)
55 
56 Called By:
57  process_a_scan
58 
59 Routines Called:
60  process_next_packet
61 
62 
63 !Revision History:
64  $Log: packet_of_scan.c,v $
65  Revision 5.1 2007/01/26 22:10:33 kuyper
66  Corrected to partially resolve bug 484 by changing the logic for detecting
67  misplaced packets and packets with corrupted scan_cnt values.
68  A full resolution will require major re-design.
69 
70  Revision 4.1 2003/05/09 18:50:04 kuyper
71  Changed to recieve next_pkt_header as a pointer to the look-ahead buffer,
72  rather than as a copy of it.
73 
74  Revision 4.0 2002/11/22 16:13:46 vlin
75  Updated according to packet_of_scan.pdl revision 4.0
76  vlin@saicmodis.com
77 
78  Revision 1.3 2001/04/13 18:09:20 seaton
79  Changed raw_mir_enc to type uint16 and fixed numerous prologs.
80 
81  Revision 1.2 2000/10/03 15:27:01 seaton
82  Split Scan fix
83 
84 !Team-unique Header:
85 
86  This software is developed by the MODIS Science Data Support Team
87  for the National Aeronautics and Space Administration,
88  Goddard Space Flight Center, under contract NAS5-32373.
89 
90 References and Credits:
91 
92 Design Notes:
93 
94 !END
95 *****************************************************************************/
96 
97 {
98 
99  PGSt_SMF_status Status, returnStatus = MODIS_S_SUCCESS;
100  int i;
101  uint8 hash_key;
102  PH_PACKET_HEADER_t *next_pkt_header=NULL;
103 
104  enum {NOPACKETPROCESSED, NOPACKETSHARETIME, MORETHANONEPACKETSHARETIME};
105 
107  hash_key = pkt_header->cal_type;
108  else /* Earth view sector or engineering packets */
109  hash_key = (PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS << 1);
110 
111  if (*previous_scan_count == SC_FILL_VALUE)
112  {
113  *previous_scan_count = pkt_header->scan_cnt;
114  for (i=0; i<5; i++)
115  {
116  scan_proc_state[i].pkt_TAI_time = 0.0;
117  scan_proc_state[i].sector_packet_count = 0;
118  }
119  }
120 
121  if ((pkt_header->pkt_TAI_time + SC_SCAN_RATE_TOLERANCE) >=
122  next_scan_start_time)
123  { /* packet may have an invalid time for this scan */
124  returnStatus = MODIS_M_PKT_NOT_IN_SCAN;
125  *previous_scan_count = pkt_header->scan_cnt;
126  for (i=0; i<5; i++)
127  {
128  scan_proc_state[i].pkt_TAI_time = 0.0;
129  scan_proc_state[i].sector_packet_count = 0;
130  }
131  scan_proc_state[hash_key].pkt_TAI_time = pkt_header->pkt_TAI_time;
132  scan_proc_state[hash_key].sector_packet_count = NOPACKETSHARETIME;
133  }
134  else if (pkt_header->scan_cnt != *previous_scan_count)
135  {
136  /* packet may have an invalid scan count for this scan */
137  Status = process_next_packet(L0_file, &next_pkt_header);
138 
139  if ((Status != MODIS_S_SUCCESS) ||
140  (((*previous_scan_count+1)%8) == pkt_header->scan_cnt &&
141  (next_pkt_header->pkt_TAI_time >= next_scan_start_time ||
142  pkt_header->scan_cnt == next_pkt_header->scan_cnt)))
143  {
144  /* Nothing in next packet refutes the assumption that the current
145  * packet belongs to the next scan
146  */
147  returnStatus = MODIS_M_PKT_NOT_IN_SCAN;
148  *previous_scan_count = pkt_header->scan_cnt;
149  for (i=0; i<5; i++) {
150  scan_proc_state[i].pkt_TAI_time = 0.0;
151  scan_proc_state[i].sector_packet_count = 0;
152  }
153  scan_proc_state[hash_key].pkt_TAI_time = pkt_header->pkt_TAI_time;
154  scan_proc_state[hash_key].sector_packet_count = NOPACKETSHARETIME;
155  }
156  else /* found a misplaced packet or a packet with a corrupted scan_cnt*/
157  returnStatus = MODIS_E_SCANCNT_NOT_VALID;
158  }
159  else switch (scan_proc_state[hash_key].sector_packet_count)
160  { /* packet appears to be part of this scan, but may be a rogue packet */
161  case NOPACKETPROCESSED :
162  /* no packets processed for sector */
163  scan_proc_state[hash_key].pkt_TAI_time = pkt_header->pkt_TAI_time;
164  scan_proc_state[hash_key].sector_packet_count = NOPACKETSHARETIME;
165  break;
166  case NOPACKETSHARETIME :
167  /* no processed packets for sector share the same time */
168  if (scan_proc_state[hash_key].pkt_TAI_time == pkt_header->pkt_TAI_time)
169  scan_proc_state[hash_key].sector_packet_count =
170  MORETHANONEPACKETSHARETIME;
171  else
172  scan_proc_state[hash_key].pkt_TAI_time=pkt_header->pkt_TAI_time;
173  break;
174  case MORETHANONEPACKETSHARETIME :
175  /*more than one packet for sector processed with the same time */
176  if (scan_proc_state[hash_key].pkt_TAI_time != pkt_header->pkt_TAI_time)
177  returnStatus = MODIS_E_INV_PKT_TIME;
178  break;
179  }
180 
181  return returnStatus;
182 }
183 
#define NULL
Definition: decode_rs.h:63
#define PH_MOD_SOURCE_ID_CAL_TYPE_NUM_BITS
Definition: PH_pkt_hdr.h:199
PGSt_double pkt_TAI_time
Definition: SC_scan.h:271
#define MODIS_E_SCANCNT_NOT_VALID
PGSt_SMF_status process_next_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PH_PACKET_HEADER_t **packet_header)
#define SC_SCAN_RATE_TOLERANCE
Definition: SC_scan.h:123
#define SC_FILL_VALUE
Definition: SC_scan.h:141
#define MODIS_E_INV_PKT_TIME
PGSt_double pkt_TAI_time
Definition: PH_pkt_hdr.h:251
int8 sector_packet_count
Definition: SC_scan.h:272
#define PH_MOD_SOURCE_ID_TYPE_FLAG_CAL
Definition: PH_pkt_hdr.h:189
PGSt_SMF_status packet_of_scan(PH_PACKET_HEADER_t *pkt_header, PGSt_double next_scan_start_time, int8 *previous_scan_count, SC_SCAN_PROC_STATE_t *scan_proc_state, PGSt_IO_L0_VirtualDataSet *L0_file)
Definition: packet_of_scan.c:5
#define MODIS_S_SUCCESS
#define MODIS_M_PKT_NOT_IN_SCAN
int i
Definition: decode_rs.h:71