OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
write_eng_data.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "EN_eng_data.h"
3 #include "PGS_MODIS_35005.h"
4 #include "PGS_SMF.h"
5 #include "hdfi.h"
6 #include "hdf.h"
7 #include "hntdefs.h"
8 
9 
10 PGSt_SMF_status write_eng_data (EN_VDATA_TYPE_t *eng_data)
11 
12 /*
13 !C****************************************************************************
14 
15 !Description: This function writes the eng data values for the current scan
16  to the L1A file .
17 
18 !Input Parameters:
19  EN_VDATA_TYPE_t *eng_data ** The eng_data array structure **
20 
21 !Output Parameters:
22  None
23 
24 Return Values:
25  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
26  MODIS_F_WRITE_ENG_DATA_FAIL (PGS_MODIS_35005.h)
27 
28 Externally Defined:
29  EN_VDATA_TYPE_t (EN_eng_data.h)
30  EN_NUM_VDATAS (EN_eng_data.h)
31  EN_MAX_FIELDS_PER_VDATA (EN_eng_data.h)
32  PGSt_SMF_status (PGS_SMF.h)
33  MODIS_E_WRITE_VDATA (PGS_MODIS_35005.h)
34  EN_SC_ANCILLARY_VDATA_START (EN_eng_data.h)
35  EN_SC_ANCILLARY_VDATA_STOP (EN_eng_data.h)
36  EN_ANCIL_VDATA_BUFFER_SIZE (EN_eng_data.h)
37  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
38  MODIS_E_VDATA_BUFFER_OVERFLOW (PGS_MODIS_35005.h)
39 
40 Called By:
41  write_scan
42  handle_missing_scans
43 
44 Routines Called:
45  write_Vdata
46  log_fmt_msg
47 
48 !Revision History:
49  Revision 2.0 1998/10/26 11:05 EST
50  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
51  Code added to write the Current/Prior S/C Ancillary
52  Vdatas, which contain multiple size and order data.
53 
54  Revision 1.1 1997/09/03 10:55
55  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
56  Incorporate walkthrough comments
57 
58  Revision 1.0 1997/07/14 15:58 EDT
59  David Catozzi/SAIC/GSC (cato@ltpmail.gsfc.nasa.gov)
60  Original design.
61 
62 !Team-unique Header:
63  This software is developed by the MODIS Science
64  Data Support Team (SDST) for the National Aeronautics
65  and Space Administration (NASA), Goddard Space Flight
66  Center (GSFC), under contract NAS5-32373.
67 
68 !References and Credits:
69  None
70 
71 !Design Notes:
72  None
73 
74 !END***************************************************************************
75 */
76 
77 {
78  /***************************************************************************/
79  /* */
80  /* Declare Local Variables */
81  /* */
82  /* --------------------------------------------------------------- */
83  /* */
84  /* Allocate record_values[EN_MAX_FIELDS_PER_VDATA] as temporary */
85  /* space to hold the field values to be written for the current */
86  /* Vdata (eng_data[i]) */
87  /* */
88  /***************************************************************************/
89 
90  int i, j, k;
91 
92  char *routine = "write_eng_data";
93 
94  char msg[300];
95 
96  PGSt_SMF_status returnStatus;
97 
98  PGSt_SMF_status tempStatus;
99 
100  uint16 record_values[EN_MAX_FIELDS_PER_VDATA];
101 
102  unsigned char *record = (unsigned char *) record_values;
103 
104  unsigned char buffer[EN_ANCIL_VDATA_BUFFER_SIZE]="";
105 
106  unsigned char *p;
107 
108  int cur_pos_in_buf=0;
109 
110 
111 
112  /***************************************************************************/
113  /* */
114  /* Set routine to "write_eng_data" (done during declaration) */
115  /* */
116  /* Set returnStatus to MODIS_S_SUCCESS */
117  /* */
118  /***************************************************************************/
119 
120  returnStatus = MODIS_S_SUCCESS;
121 
122  /***************************************************************************/
123  /* if input parameters equal NULL */
124  /* THEN */
125  /* CALL log_fmt_msg to record error in LogStatus file */
126  /* INPUTS: MODIS_E_NULL_POINTER, routine, " " */
127  /* OUTPUTS: None */
128  /* RETURNS: None */
129  /* */
130  /* return MODIS_F_WRITE_ENG_DATA_FAIL */
131  /* ENDIF */
132  /***************************************************************************/
133 
134  if (eng_data == NULL) {
135  log_fmt_msg(MODIS_E_NULL_POINTER, routine, " ");
137  }
138 
139 
140  /***************************************************************************/
141  /* */
142  /* DO FOR ( i = 0 to EN_NUM_VDATAS-1 ) */
143  /* */
144  /* IF i = EN_SC_ANCILLARY_VDATA_START or i = EN_SC_ANCILLARY_VDATA_END */
145  /* THEN */
146  /* initialize unsigned char buffer and a pointer into that buffer */
147  /* */
148  /* initialize cur_pos_in_buf equal to zero */
149  /* */
150  /* FOR each field in the Vdata (j) */
151  /* */
152  /* FOR each order within the field (k) */
153  /* */
154  /* IF cur_pos_in_buf > EN_ANCIL_DATA_BUFFER_SIZE */
155  /* THEN */
156  /* CALL log_fmt_msg to record error inthe LogStatus file */
157  /* INPUTS: MODIS_E_VDATA_BUFFER_OVERFLOW, routine, " " */
158  /* OUTPUTS: None */
159  /* RETURNS: None */
160  /* */
161  /* return MODIS_F_WRITE_ENG_DATA_FAIL */
162  /* ENDIF */
163  /* */
164  /* SWITCH on eng_data[i].field[j].type */
165  /* */
166  /* CASE DFNT_INT8 : copy data from */
167  /* eng_data[i].fields[j].union_value.i8type */
168  /* into the buffer */
169  /* */
170  /* increment the pointer into the buffer by the size of*/
171  /* int8 type */
172  /* */
173  /* increment cur_pos_in_buf by size of int8 type */
174  /* */
175  /* break CASE */
176  /* */
177  /* CASE DFNT_UINT8 : copy data from */
178  /* eng_data[i].fields[j].union_value.ui8type */
179  /* into the buffer */
180  /* */
181  /* increment the pointer into the buffer by the size of*/
182  /* uint8 type */
183  /* */
184  /* increment cur_pos_in_buf by size of uint8 type */
185  /* */
186  /* break CASE */
187  /* */
188  /* CASE DFNT_INT16 : copy data from */
189  /* eng_data[i].fields[j].union_value.i16type */
190  /* into the buffer */
191  /* */
192  /* increment cur_pos_in_buf by size of int16 type */
193  /* */
194  /* increment the pointer into the buffer by the size of*/
195  /* int16 type */
196  /* */
197  /* break CASE */
198  /* */
199  /* CASE DFNT_UINT16 : copy data from */
200  /* eng_data[i].fields[j].union_value.ui16type*/
201  /* into the buffer */
202  /* */
203  /* increment cur_pos_in_buf by size of uint16 type */
204  /* */
205  /* increment the pointer into the buffer by the size of*/
206  /* uint16 type */
207  /* */
208  /* break CASE */
209  /* */
210  /* CASE DFNT_INT32 : copy data from */
211  /* eng_data[i].fields[j].union_value.i32type */
212  /* into the buffer */
213  /* */
214  /* increment cur_pos_in_buf by size of int32 type */
215  /* */
216  /* increment the pointer into the buffer by the size of*/
217  /* int32 type */
218  /* */
219  /* break CASE */
220  /* */
221  /* CASE DFNT_UINT32 : copy data from */
222  /* eng_data[i].fields[j].union_value.ui32type*/
223  /* into the buffer */
224  /* */
225  /* increment cur_pos_in_buf by size of uint32 type */
226  /* */
227  /* increment the pointer into the buffer by the size of*/
228  /* uint32 type */
229  /* */
230  /* break CASE */
231  /* */
232  /* CASE default : CALL log_fmt_msg to record error in LogStatus*/
233  /* INPUTS: MODIS_E_INVALID_VDATA_TYPE, routine,*/
234  /* " " */
235  /* OUTPUTS: None */
236  /* RETURNS: None */
237  /* */
238  /* break CASE */
239  /* */
240  /* END SWITCH */
241  /* */
242  /* END FOR (k) */
243  /* */
244  /* END FOR (j) */
245  /***************************************************************************/
246 
247  for (i = 0; i < EN_NUM_VDATAS; i++)
248  {
250  memset(buffer, 0, sizeof(buffer));
251  p = buffer;
252  cur_pos_in_buf = 0;
253  for (j = 0; j < eng_data[i].num_fields; j++) {
254  for (k = 0; k < eng_data[i].field[j].order; k++ ) {
255  if (cur_pos_in_buf > EN_ANCIL_VDATA_BUFFER_SIZE) {
256  sprintf(msg, "Current Position: %d Max Buffer Size: %d",
257  cur_pos_in_buf, EN_ANCIL_VDATA_BUFFER_SIZE);
260  }
261 
262  switch (eng_data[i].field[j].type) {
263  case DFNT_INT8 :
264  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].i8type,
265  sizeof(eng_data[i].field[j].union_value[k].i8type));
266  p += sizeof(eng_data[i].field[j].union_value[k].i8type);
267  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].i8type);
268  break;
269  case DFNT_UINT8 :
270  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].ui8type,
271  sizeof(eng_data[i].field[j].union_value[k].ui8type));
272  p += sizeof(eng_data[i].field[j].union_value[k].ui8type);
273  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].ui8type);
274  break;
275  case DFNT_INT16 :
276  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].i16type,
277  sizeof(eng_data[i].field[j].union_value[k].i16type));
278  p += sizeof(eng_data[i].field[j].union_value[k].i16type);
279  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].i16type);
280  break;
281  case DFNT_UINT16 :
282  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].ui16type,
283  sizeof(eng_data[i].field[j].union_value[k].ui16type));
284  p += sizeof(eng_data[i].field[j].union_value[k].ui16type);
285  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].ui16type);
286  break;
287  case DFNT_INT32 :
288  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].i32type,
289  sizeof(eng_data[i].field[j].union_value[k].i32type));
290  p += sizeof(eng_data[i].field[j].union_value[k].i32type);
291  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].i32type);
292  break;
293  case DFNT_UINT32 :
294  memcpy(p, (const void *)&eng_data[i].field[j].union_value[k].ui32type,
295  sizeof(eng_data[i].field[j].union_value[k].ui32type));
296  p += sizeof(eng_data[i].field[j].union_value[k].ui32type);
297  cur_pos_in_buf += sizeof(eng_data[i].field[j].union_value[k].ui32type);
298  break;
299  default :
300  sprintf(msg, "Engineering Data Field Type: %d Valid Range: %d to %d",
301  eng_data[i].field[j].type, EN_MIN_VDATA_TYPE, EN_MAX_VDATA_TYPE);
303  break;
304  } /* switch */
305 
306  } /* end for k */
307 
308  } /* for j */
309 
310  /***************************************************************************/
311  /* CALL write_Vdata to update all fields (write a single consolidated */
312  /* record of different data types for the current Vdata to the */
313  /* file) for this scan */
314  /* INPUTS: eng_data[i].vdata_name, buffer, 1 (Number of Records) */
315  /* OUTPUTS: None */
316  /* RETURN: tempStatus */
317  /***************************************************************************/
318 
319  tempStatus = write_Vdata(eng_data[i].vdata_name, (unsigned char *)buffer, 1);
320 
321  /***************************************************************************/
322  /* IF ( tempStatus is FAIL ) */
323  /* THEN */
324  /* set Status to MODIS_E_WRITE_VDATA */
325  /* CALL log_fmt_msg to report that the fields for a Vdata could not */
326  /* be written to a scan */
327  /* INPUTS: Status, routine, msg */
328  /* OUTPUTS: None */
329  /* RETURN: None */
330  /* set returnStatus to FAIL */
331  /* ENDIF */
332  /***************************************************************************/
333 
334  if (tempStatus == FAIL)
335  {
336  sprintf(msg, "Vdata Name = %s", eng_data[i].vdata_name);
338  returnStatus = MODIS_F_WRITE_ENG_DATA_FAIL;
339  }
340 
341  }
342 
343  /***************************************************************************/
344  /* ELSE */
345  /* */
346  /* set all elements of record_values to 0 */
347  /* */
348  /***************************************************************************/
349 
350  else {
351  memset(record_values, 0, sizeof(record_values));
352 
353 
354  /***************************************************************************/
355  /* */
356  /* DO FOR ( j = 0 to eng_data[i].num_fields-1 ) */
357  /* set record_values[j] to eng_data[i].field[j].value */
358  /* END DO */
359  /* (To consolidate a record (a set of field values) for writing.) */
360  /* */
361  /***************************************************************************/
362 
363  for (j = 0; j < eng_data[i].num_fields; j++)
364  record_values[j] = eng_data[i].field[j].value;
365 
366 
367  /***************************************************************************/
368  /* */
369  /* CALL write_Vdata to update all fields (write a single consolidated */
370  /* record for the current Vdata to the file) for this scan */
371  /* INPUTS: eng_data[i].vdata_name, record_values, 1 */
372  /* OUTPUTS: None */
373  /* RETURN: tempStatus */
374  /* */
375  /* IF (tempStatus is FAIL) */
376  /* THEN */
377  /* set Status to MODIS_E_WRITE_VDATA */
378  /* CALL log_fmt_msg to report that the fields for a Vdata could */
379  /* not be written to a scan */
380  /* INPUTS: Status, routine, msg */
381  /* OUTPUTS: None */
382  /* RETURN: None */
383  /* set returnStatus to MODIS_F_WRITE_ENG_DATA_FAIL */
384  /* ENDIF */
385  /* */
386  /* END DO */
387  /* */
388  /***************************************************************************/
389 
390  tempStatus = write_Vdata(eng_data[i].vdata_name, record, 1);
391  if (tempStatus == FAIL)
392  {
393  sprintf(msg, "Vdata Name = %s", eng_data[i].vdata_name);
395  returnStatus = MODIS_F_WRITE_ENG_DATA_FAIL;
396  }
397  }
398 
399  }
400 
401 
402  /***************************************************************************/
403  /* */
404  /* RETURN returnStatus */
405  /* */
406  /***************************************************************************/
407 
408  return (returnStatus);
409 
410 }
411 
int32 value
Definition: Granule.c:1235
EN_FIELD_TYPE_t field[EN_MAX_FIELDS_PER_VDATA]
Definition: EN_eng_data.h:125
int j
Definition: decode_rs.h:73
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
PGSt_SMF_status write_eng_data(EN_VDATA_TYPE_t *eng_data)
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
#define EN_MIN_VDATA_TYPE
Definition: EN_eng_data.h:98
union EN_FIELD_TYPE_t::@18 union_value[EN_MAX_VDATA_ORDER]
#define EN_SC_ANCILLARY_VDATA_END
Definition: EN_eng_data.h:88
#define EN_SC_ANCILLARY_VDATA_START
Definition: EN_eng_data.h:87
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define EN_MAX_VDATA_TYPE
Definition: EN_eng_data.h:97
#define EN_ANCIL_VDATA_BUFFER_SIZE
Definition: EN_eng_data.h:90
#define MODIS_E_VDATA_BUFFER_OVERFLOW
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
#define MODIS_E_WRITE_VDATA
#define EN_NUM_VDATAS
Definition: EN_eng_data.h:64
#define MODIS_F_WRITE_ENG_DATA_FAIL
#define MODIS_S_SUCCESS
PGSt_SMF_status write_Vdata(char *Vdata_name, unsigned char *data, int32 num_records)
Definition: write_Vdata.c:8
string msg
Definition: mapgen.py:227
#define MODIS_E_INVALID_VDATA_TYPE
int i
Definition: decode_rs.h:71
#define MODIS_E_NULL_POINTER
#define EN_MAX_FIELDS_PER_VDATA
Definition: EN_eng_data.h:69
int k
Definition: decode_rs.h:73
float p[MODELMAX]
Definition: atrem_corl1.h:131