OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
initialize_level1a.c
Go to the documentation of this file.
1 #include "PGS_TD.h"
2 #include "PGS_IO.h"
3 #include "PGS_SMF.h"
4 #include "PGS_PC_9.h"
5 #include "PGS_IO_L0.h"
6 #include "PGS_TYPES.h"
7 #include "PH_pkt_hdr.h"
8 #include "EN_eng_data.h"
9 #include "PC_pcf_info.h"
10 #include "PGS_MODIS_35005.h"
11 #include "L1A_prototype.h"
12 
13 
14 PGSt_SMF_status initialize_level1a (PCF_CONFIG_t *pcf_config,
15  EN_VDATA_TYPE_t *eng_data,
16  PGSt_IO_L0_Packet *pkt,
17  PH_PACKET_HEADER_t *pkt_header,
18  PGSt_IO_L0_VirtualDataSet *L0_file)
19 
20 /*************************************************************************
21 !C
22 
23 !Description: This function will call various routines to get the PCF
24  parameters, open the L0 file, read the Engineering Data
25  structures from a file. It will also set the L0 file
26  pointer to a point before the start of the first L1A granule
27  to be produced, and also preload the eng_data structure.
28 
29 !Input Parameters: None
30 
31 !Output Parameters:
32  PCF_CONFIG_t *pcf_config
33  ** Configuration parameters **
34  ** extracted from the PCF **
35  EN_VDATA_TYPE_t *eng_data
36  ** The structure containing the **
37  ** de-commutated engineering data **
38  PGSt_IO_L0_Packet *pkt ** Packet buffer which contains **
39  ** packed packet **
40  PH_PACKET_HEADER_t *pkt_header
41  ** Buffer that contains the pkt **
42  ** header info of the packet **
43  PGSt_IO_L0_VirtualDataSet *L0_file
44  ** The L0 file that contains **
45  ** packet information **
46 
47 Return Values:
48  MODIS_E_NULL_POINTER
49  MODIS_F_GETREF_FAILED
50  MODIS_F_INVAL_L0_FILE_RET
51  MODIS_F_L0_SETSTART_FAILED
52  MODIS_F_NO_PCF_CONFIG_DATA
53  MODIS_F_PKT_READ_FAILED
54  MODIS_S_SUCCESS
55  MODIS_W_NO_MORE_PACKETS
56  MODIS_W_PRELOAD_ENG_DATA
57 
58 Externally Defined:
59  EN_VDATA_TYPE_t (EN_eng_data.h)
60  global_first_gran_start_time (L1A_prototype.h)
61  global_last_gran_stop_time (L1A_prototype.h)
62  global_L0_logical (PC_pcf_info.h)
63  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
64  MODIS_F_GETREF_FAILED (PGS_MODIS_35005.h)
65  MODIS_F_INVAL_L0_FILE_RET (PGS_MODIS_35005.h)
66  MOIDS_F_INVALID_ENG_DATA_LIST(PGS_MODIS_35005.h)
67  MODIS_F_L0_SETSTART_FAILED (PGS_MODIS_35005.h)
68  MODIS_F_NO_PCF_CONFIG_DATA (PGS_MODIS_35005.h)
69  MODIS_F_PKT_READ_FAILED (PGS_MODIS_35005.h)
70  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
71  MODIS_W_NO_MORE_PACKETS (PGS_MODIS_35005.h)
72  MODIS_W_PRELOAD_ENG_DATA (PGS_MODIS_35005.h)
73  PC_CURRENT_L0_PCF_ID (PC_pcf_info.h)
74  PC_PRIOR_L0_PCF_ID (PC_pcf_info.h)
75  PCF_CONFIG_t (PC_pcf_info.h)
76  PGSPC_E_DATA_ACCESS_ERROR (PGS_PC_9.h)
77  PGSPC_W_NO_REFERENCE_FOUND (PGS_PC_9.h)
78  PGSd_EOS_AM1 (PGS_TD.h)
79  PGSd_FILE_PATH_MAX (PGS_PC.h)
80  PGSt_double (PGS_types.h)
81  PGSt_integer (PGS_types.h)
82  PGSt_IO_L0_Packet (PGS_IO.h)
83  PGSt_IO_L0_VirtualDataSet (PGS_IO_LO.h)
84  PGSt_Logical (PGS_types.h)
85  PGSt_SMF_status (PGS_SMF.h)
86  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
87 
88 Called By: level1a
89 
90 Routines Called:
91  PGS_PC_GetReference
92  get_pcf_config_data
93  compute_global_time_offsets
94  get_valid_L0_file
95  load_eng_data
96  parse_eng_data_list
97  set_start_position
98  log_fmt_msg
99 
100 !Revision History:
101  $Log: initialize_level1a.c,v $
102  Revision 4.2 2003/01/10 15:43:14 vlin
103  Check for NULL pointers in the beginning.
104 
105  Revision 4.1 2002/10/09 17:49:24 vlin
106  Updated after code walkthrough.
107 
108  Revision 3.1 2002/09/16 21:26:02 vlin
109  Updated according to initialize_level1a.pdl revision 3.2
110 
111  Revision 2.2 2000/07/14
112  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
113  Added changes for Aqua instrument.
114 
115  Revision 2.1 1997/08/25 14:20 EDT
116  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
117  Original Code Development.
118 
119  Revision 2.0 1997/07/15 14:40 EDT
120  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
121  Recreated Module per Version2 development.
122 
123  Revision 1.0 1997/06/18 16:40 EDT
124  Timi Adelekan/SAIC/GSC (adelekan@ltpmail.gsfc.nasa.gov)
125  Baseline from Version 1.
126 
127 !Team-unique Header:
128 
129  This software is developed by the MODIS Science Data Support
130  Team for the National Aeronautics and Space Administration,
131  Goddard Space Flight Center, under contract NAS5-32373.
132 
133 !END
134 ***********************************************************************/
135 
136 {
137  char routine[] = "initialize_level1a";
138  char msg[300];
139  PGSt_SMF_status returnStatus = MODIS_S_SUCCESS;
140  PGSt_SMF_status tempStatus; /* SMF-style message returned by function */
141  PGSt_double L0_start_time, L0_stop_time;
142  /* L0 start time and L0 stop time (TAI) */
143  /* returned by PGS_IO_L0_Open function */
144  PGSt_double preload_start_time = 0.0;
145  /* Time to start loading engineering data */
146  /* prior to first product */
147  PGSt_integer version = 1; /* Version number needed by */
148  /* PGS_PC_GetReference */
149  char refID[PGSd_PC_FILE_PATH_MAX];
150  /* Char buffer needed by */
151  /* PGS_PC_GetReference */
152 
153  if (pcf_config == NULL || eng_data == NULL || pkt == NULL ||
154  pkt_header == NULL || L0_file == NULL) {
155  log_fmt_msg(MODIS_E_NULL_POINTER, routine, "");
156  return MODIS_E_NULL_POINTER;
157  }
158 
159  returnStatus = get_pcf_config_data(pcf_config);
162  if (returnStatus == MODIS_S_SUCCESS) {
164  tempStatus = PGS_PC_GetReference(PC_PRIOR_L0_PCF_ID, &version, refID);
165  if (tempStatus == PGSPC_E_DATA_ACCESS_ERROR) {
166  returnStatus = MODIS_F_GETREF_FAILED;
167  sprintf(msg, "LUN Number: %d", PC_PRIOR_L0_PCF_ID);
169  }
170  else {
171  if (tempStatus == PGS_S_SUCCESS)
173  else if (tempStatus == PGSPC_W_NO_REFERENCE_FOUND)
175 
176  returnStatus = parse_eng_data_list(eng_data);
177  if (returnStatus != MODIS_S_SUCCESS)
179  "error occurred trying to parse the engineering data list file");
180  else if (pcf_config->instrument != eng_data->instrument) {
181  returnStatus = MODIS_F_INVALID_ENG_DATA_LIST;
182  sprintf(msg, "PCF instrument = %d, LUT instrument = %d",
183  pcf_config->instrument, eng_data->instrument);
185  }
186  else if (strcmp(pcf_config->lutrevision, eng_data->revision)) {
187  returnStatus = MODIS_F_INVALID_ENG_DATA_LIST;
188  sprintf(msg, "Expected LUT revision = %s, actual revision = %s",
189  pcf_config->lutrevision, eng_data->revision);
191  }
192  else
193  returnStatus = get_valid_L0_file(PGSd_EOS_AM1, L0_file,
194  &L0_start_time, &L0_stop_time);
195 
196  if (returnStatus == MODIS_S_SUCCESS) {
197  preload_start_time = pcf_config->first_gran_start_time - (65 * 1.024);
198  returnStatus = set_start_position (*L0_file,
199  &preload_start_time, L0_start_time, L0_stop_time);
200  if (returnStatus == MODIS_S_SUCCESS) {
201  returnStatus = load_eng_data(pcf_config->scan_rate, eng_data,
202  pkt, pkt_header, *L0_file);
203  if (returnStatus == MODIS_W_PRELOAD_ENG_DATA)
205  "Warning: Could not preload any Eng Data");
206  else if (returnStatus == MODIS_W_NO_MORE_PACKETS)
207  log_fmt_msg(MODIS_W_NO_MORE_PACKETS, routine, "Reached "
208  "the end of L0 data while trying to preload eng data");
209  else if (returnStatus == MODIS_F_PKT_READ_FAILED)
211  "error reading packet data during engineering preload");
212  }
213  else {
214  returnStatus = MODIS_F_L0_SETSTART_FAILED;
216  }
217  }
218  else {
219  returnStatus = MODIS_F_INVAL_L0_FILE_RET;
220  sprintf(msg, "L0 LUN: %u", (unsigned)global_L0_logical);
222  } /* else get_valid_L0_file fails */
223  }
224  }
225  else {
226  returnStatus = MODIS_F_NO_PCF_CONFIG_DATA;
227  log_fmt_msg(MODIS_F_NO_PCF_CONFIG_DATA, routine, "error occured in "
228  "trying to get PCF config data values Granule Length or Scan Rate");
229  }
230 
231  return returnStatus;
232 
233 }
PGSt_PC_Logical global_L0_logical
Definition: level1a.c:35
#define MODIS_F_NO_PCF_CONFIG_DATA
#define NULL
Definition: decode_rs.h:63
PGSt_tag instrument
Definition: PC_pcf_info.h:89
#define PC_CURRENT_L0_PCF_ID
Definition: PC_pcf_info.h:52
PGSt_SMF_status get_valid_L0_file(PGSt_tag spacecraft_tag, PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_double *start_time, PGSt_double *stop_time)
PGSt_SMF_status parse_eng_data_list(EN_VDATA_TYPE_t *eng_data)
PGSt_SMF_status initialize_level1a(PCF_CONFIG_t *pcf_config, EN_VDATA_TYPE_t *eng_data, PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_VirtualDataSet *L0_file)
#define MODIS_F_INVAL_L0_FILE_RET
void compute_global_time_offsets(PGSt_double scan_rate)
PGSt_double scan_rate
Definition: PC_pcf_info.h:84
PGSt_double first_gran_start_time
Definition: PC_pcf_info.h:81
#define MODIS_F_INVALID_ENG_DATA_LIST
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_double global_last_gran_stop_time
Definition: level1a.c:31
PGSt_tag instrument
Definition: EN_eng_data.h:127
PGSt_double global_first_gran_start_time
Definition: level1a.c:30
#define MODIS_W_PRELOAD_ENG_DATA
PGSt_double last_gran_stop_time
Definition: PC_pcf_info.h:82
char lutrevision[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:86
#define MODIS_S_SUCCESS
PGSt_SMF_status get_pcf_config_data(PCF_CONFIG_t *pcf_config)
#define MODIS_W_NO_MORE_PACKETS
#define MODIS_F_PKT_READ_FAILED
string msg
Definition: mapgen.py:227
#define MODIS_F_GETREF_FAILED
PGSt_SMF_status load_eng_data(PGSt_double scan_rate, EN_VDATA_TYPE_t *eng_data, PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, PGSt_IO_L0_VirtualDataSet L0_file)
Definition: load_eng_data.c:10
#define MODIS_E_NULL_POINTER
#define PC_PRIOR_L0_PCF_ID
Definition: PC_pcf_info.h:51
#define MODIS_F_L0_SETSTART_FAILED
PGSt_SMF_status set_start_position(PGSt_IO_L0_VirtualDataSet L0_file, PGSt_double *preload_start_time, PGSt_double start_time, PGSt_double stop_time)
version
Definition: setup.py:15
char revision[PGSd_PC_VALUE_LENGTH_MAX]
Definition: EN_eng_data.h:126