OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
init_L1A_HDF_vdatas.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "VU_vdata_utility.h"
3 #include "PGS_MODIS_35005.h"
4 #include "mapi.h"
5 #include "mapiL1A.h"
6 #include "hdf.h"
7 #include "EN_eng_data.h"
8 #include "SC_scan.h"
9 #include "PGS_SMF.h"
10 #include "hntdefs.h"
11 
12 PGSt_SMF_status init_L1A_HDF_vdatas (EN_VDATA_TYPE_t *eng_data,
13  MODFILE *L1A_file)
14 
15 /*
16 !C*****************************************************************************
17 
18 !Description: This function creates in the L1A file all the Vdatas that
19  will be written to by the L1A processing.
20 
21 !Input Parameters:
22  EN_VDATA_TYPE_t *eng_data ** The Vdata array
23  structure **
24  MODFILE *L1A_file ** The address of MODFILE
25  structure **
26 
27 !Output Parameters:
28  None
29 
30 Return Values:
31  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
32  FAIL (HDF)
33 
34 Externally Defined:
35  EN_VDATA_TYPE_t (EN_eng_data.h)
36  EN_NUM_VDATAS (EN_eng_data.h)
37  EN_MAX_FIELDS_PER_VDATA (EN_eng_data.h)
38  EN_MAX_DATA_TYPE_STRING_LENGTH (EN_eng_data.h)
39  EN_MAX_FIELD_NAME_LENGTH (EN_eng_data.h)
40  EN_SC_ANCILLARY_VDATA_START (EN_eng_data.h)
41  EN_SC_ANCILLARY_VDATA_END (EN_eng_data.h)
42  PGSt_SMF_status (PGS_SMF.h)
43  MODIS_E_START_VDATA_ACCESS_TO_FILE (PGS_MODIS_35005.h)
44  MODIS_E_CREATE_VDATA (PGS_MODIS_35005.h)
45  global_H_ID (level1a)
46  DFNT_INT8 (hntdefs.h)
47  DFNT_UINT8 (hntdefs.h)
48  DFNT_INT16 (hntdefs.h)
49  DFNT_UINT16 (hntdefs.h)
50  DFNT_INT32 (hntdefs.h)
51  DFNT_UINT32 (hntdefs.h)
52  SC_FILL_VALUE (SC_scan.h)
53  VSFIELDMAX
54  VU_MAX_NAME_LENGTH (VU_vdata_utility.h)
55  VU_MAX_DATA_TYPE_STRING_LENGTH (VU_vdata_utility.h)
56  uint16 (hdfi.h)
57  MODIS_E_INVALID_VDATA_TYPE (PGS_MODIS_35005.h)
58  I8 (mapi.h)
59  UI8 (mapi.h)
60  I16 (mapi.h)
61  UI16 (mapi.h)
62  I32 (mapi.h)
63  UI32 (mapi.h)
64 
65 Called By:
66  create_L1A_granule
67 
68 Routines Called:
69  create_Vdata
70  log_fmt_msg
71 
72 !Revision History:
73  Revision 2.0 1998/10/26 10:09 EST
74  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
75  Added logic to allow a Vdata to have different size
76  data types and different size orders.
77 
78  revision 1.0 1997/10/02 17:30:00
79  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
80  Original development
81 
82 !Team-unique Header:
83  This software is developed by the MODIS Science
84  Data Support Team (SDST) for the National Aeronautics
85  and Space Administration (NASA), Goddard Space Flight
86  Center (GSFC), under contract NAS5-32373.
87 
88 !References and Credits:
89  None
90 
91 !Design Notes:
92  None
93 
94 !END************************************************************************
95 */
96 {
97  /**************************************************************************/
98  /* Define Global Variables */
99  /**************************************************************************/
100 
101  extern int32 global_H_ID; /* stores HDF file ID */
102 
103 
104  /**************************************************************************/
105  /* Define Local Variables */
106  /**************************************************************************/
107 
108  char *routine = "init_L1A_HDF_vdatas";
109  char msg[300];
110  PGSt_SMF_status returnStatus = MODIS_S_SUCCESS;
111  char eng_field_names[VSFIELDMAX][VU_MAX_NAME_LENGTH];
112  char eng_data_types[VSFIELDMAX][VU_MAX_DATA_TYPE_STRING_LENGTH];
113  uint16 eng_field_order[VSFIELDMAX];
114  char Vdata_name[EN_MAX_VDATA_NAME_LENGTH];
115  int current_index=0;
116  int i;
117 
118  /**************************************************************************/
119  /* Check for NULL input paramaters */
120  /**************************************************************************/
121 
122  if ((L1A_file == NULL) || (eng_data == NULL)) {
123  log_fmt_msg(MODIS_E_NULL_POINTER, routine, " ");
124  return FAIL;
125  }
126 
127  global_H_ID = (int32)L1A_file->hdf_id;
128 
129 
130  /**************************************************************************/
131  /* Loop through all vdatas from eng_data structure */
132  /**************************************************************************/
133  while ((current_index < EN_NUM_VDATAS) &&
134  (returnStatus == MODIS_S_SUCCESS))
135  {
136  /**************************************************************************/
137  /* Loop through all fields for each Vdata */
138  /**************************************************************************/
139  for (i=0; i<eng_data[current_index].num_fields; i++)
140  {
141  strcpy(eng_field_names[i], eng_data[current_index].field[i].field_name);
142  switch (eng_data[current_index].field[i].type) {
143  case DFNT_INT8 : strcpy(eng_data_types[i], I8); break;
144  case DFNT_UINT8 : strcpy(eng_data_types[i], UI8); break;
145  case DFNT_INT16 : strcpy(eng_data_types[i], I16); break;
146  case DFNT_UINT16 : strcpy(eng_data_types[i], UI16); break;
147  case DFNT_INT32 : strcpy(eng_data_types[i], I32); break;
148  case DFNT_UINT32 : strcpy(eng_data_types[i], UI32); break;
149  default : sprintf(msg, "\nVdata Name: %s Vdata Field: %s Vdata type: %d",
150  eng_data[current_index].vdata_name,
151  eng_data[current_index].field[i].field_name,
152  eng_data[current_index].field[i].type);
154  break;
155  }
156  eng_field_order[i] = eng_data[current_index].field[i].order;
157  }
158 
159  if(current_index == EN_SC_ANCILLARY_VDATA_START ||
160  current_index == EN_SC_ANCILLARY_VDATA_END)
161  {
162  int j,k;
163 
164  for(j=0; j<eng_data[current_index].num_fields; j++)
165  {
166  switch(eng_data[current_index].field[j].type)
167  {
168  case DFNT_INT8:
169  for(k=0; k<eng_data[current_index].field[j].order; k++)
170  eng_data[current_index].field[j].union_value[k].i8type
171  = (int8)SC_FILL_VALUE;
172  break;
173 
174  case DFNT_UINT8:
175  for(k=0; k<eng_data[current_index].field[j].order; k++)
176  eng_data[current_index].field[j].union_value[k].ui8type
177  = (uint8)SC_FILL_VALUE;
178  break;
179 
180  case DFNT_INT16:
181  for(k=0; k<eng_data[current_index].field[j].order; k++)
182  eng_data[current_index].field[j].union_value[k].i16type
183  = (int16)SC_FILL_VALUE;
184  break;
185 
186  case DFNT_UINT16:
187  for(k=0; k<eng_data[current_index].field[j].order; k++)
188  eng_data[current_index].field[j].union_value[k].ui16type
189  = (uint16)SC_FILL_VALUE;
190  break;
191 
192  case DFNT_INT32:
193  for(k=0; k<eng_data[current_index].field[j].order; k++)
194  eng_data[current_index].field[j].union_value[k].i32type
195  = (int32)SC_FILL_VALUE;
196  break;
197 
198  case DFNT_UINT32:
199  for(k=0; k<eng_data[current_index].field[j].order; k++)
200  eng_data[current_index].field[j].union_value[k].ui32type
201  = (uint32)SC_FILL_VALUE;
202  break;
203 
204  /* default: Not needed, since valid type is guaranteed */
205  }
206  }
207  }
208  /**************************************************************************/
209  /* Routine to create the Vdata. */
210  /**************************************************************************/
211  returnStatus = create_Vdata(eng_data[current_index].vdata_name,
212  eng_field_names,
213  eng_data_types,
214  eng_data[current_index].num_fields,
215  eng_field_order);
216 
217  /**************************************************************************/
218  /* Error if create_Vdata returns a fail code. */
219  /**************************************************************************/
220  if (returnStatus != MODIS_S_SUCCESS)
221  {
222  sprintf(msg,"Vdata Name: %s", eng_data[current_index].vdata_name);
224  }
225 
226  current_index ++;
227  }
228 
229  /**************************************************************************/
230  /* Set up discarded packets vdata */
231  /**************************************************************************/
232  if (returnStatus == MODIS_S_SUCCESS)
233  {
234  memset(eng_field_order, 0, sizeof(eng_field_order));
235  eng_field_order[0] = 650;
236  strcpy(Vdata_name, M01DISCARDED_PACKETS);
237  strcpy(eng_field_names[0], M01DISCARDED_PKTS_FIELD);
238  strcpy(eng_data_types[0], I8);
239  returnStatus = create_Vdata(Vdata_name,
240  eng_field_names,
241  eng_data_types,
242  1,
243  eng_field_order);
244 
245  /**************************************************************************/
246  /* Error if create_Vdata returns a fail code. */
247  /**************************************************************************/
248  if (returnStatus != MODIS_S_SUCCESS)
250  "The Discarded Packets Vdata could not be created in the file");
251 
252  }
253 
254  return (returnStatus);
255 
256 }
integer, parameter int16
Definition: cubeio.f90:3
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 init_L1A_HDF_vdatas(EN_VDATA_TYPE_t *eng_data, MODFILE *L1A_file)
int32 global_H_ID
Definition: level1a.c:27
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
#define EN_SC_ANCILLARY_VDATA_END
Definition: EN_eng_data.h:88
#define MODIS_E_CREATE_VDATA
#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_NAME_LENGTH
Definition: EN_eng_data.h:70
#define SC_FILL_VALUE
Definition: SC_scan.h:141
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
PGSt_SMF_status create_Vdata(char *Vdata_name, char field_names[][VU_MAX_NAME_LENGTH], char data_types[][VU_MAX_DATA_TYPE_STRING_LENGTH], int16 num_fields, uint16 order[])
Definition: create_Vdata.c:9
#define EN_NUM_VDATAS
Definition: EN_eng_data.h:64
#define MODIS_S_SUCCESS
#define VU_MAX_NAME_LENGTH
string msg
Definition: mapgen.py:227
#define MODIS_E_INVALID_VDATA_TYPE
#define VU_MAX_DATA_TYPE_STRING_LENGTH
int i
Definition: decode_rs.h:71
#define MODIS_E_NULL_POINTER
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
while(++r<=NROOTS)
Definition: decode_rs.h:169
int k
Definition: decode_rs.h:73