OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
create_Vdata.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "PGS_SMF.h"
3 #include "PGS_MODIS_35005.h"
4 #include "VU_vdata_utility.h"
5 #include "hdfi.h"
6 
7 #define WRITE "w"
8 
9 PGSt_SMF_status create_Vdata(char *Vdata_name,
10  char field_names[][VU_MAX_NAME_LENGTH],
11  char data_types[][VU_MAX_DATA_TYPE_STRING_LENGTH],
12  int16 num_fields,
13  uint16 order[])
14 /*
15 !C**************************************************************************
16 
17 !Description: Creates the specified Vdata in the currently open hdf file.
18 
19 !Input Parameters:
20  char *Vdata_name ** name of the Vdata **
21  char field_names[][VU_MAX_NAME_LENGTH]
22  ** an array of field names **
23  ** (each string's length is **
24  ** <= MAX_NAME_LENGTH) **
25 
26  char data_types[][VU_MAX_DATA_TYPE_STRING_LENGTH]
27  ** an array of data type **
28  ** strings which correspond to**
29  ** to the field names (i.e. **
30  ** field_names[i]'s data type **
31  ** is data_types[i]). **
32 
33  int16 num_fields ** the rank of the two arrays.**
34 
35  uint16 order ** the number of data type **
36  ** size entries per record **
37 
38 !Output Parameters:
39  None
40 
41 !Input/Output Parameters:
42  None
43 
44 Return Values:
45  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
46  FAIL (HDF)
47 
48 Externally Defined:
49  PGSt_SMF_status (PGS_SMF.h)
50  VU_MAX_NAME_LENGTH (VU_vdata_utility.h)
51  VU_MAX_DATA_TYPE_STRING_LENGTH (VU_vdata_utility.h)
52  VU_MAX_FIELD_NAME_LIST_SIZE (VU_vdata_utility.h)
53  VU_NEW_VDATA (VU_vdata_utility.h)
54  int16 (hdfi.h)
55  int32 (hdfi.h)
56  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
57  global_H_ID (level1a)
58  MODIS_E_VSSETFIELDS (PGS_MODIS_35005.h)
59 
60 Called By:
61  init_L1A_HDF_vdatas
62 
63 Routines Called:
64  VSattach
65  VSsetname
66  VSsetfields
67  remember
68  create_Vdata_field
69  log_fmt_msg
70 
71 !Revision History:
72  Revision 2.0 1998/10/26 09:58 EST
73  John Seaton/SAIC/GSC (seaton@ltpmail.gsfc.nasa.gov)
74  Allows for an array of orders to be passed in to create
75  Vdata fields that have different orders.
76 
77  Revision 1.1 1997/09/03 10:55
78  Tom Johnson/GSC (johnson@ltpmail.gsfc.nasa.gov)
79  Incorporate walkthrough comments
80 
81  Revision 1.0 1997/07/14 15:58 EDT
82  David Catozzi/SAIC/GSC (cato@ltpmail.gsfc.nasa.gov)
83  Original design.
84 
85 !Team-unique Header:
86  This software is developed by the MODIS Science
87  Data Support Team (SDST) for the National Aeronautics
88  and Space Administration (NASA), Goddard Space Flight
89  Center (GSFC), under contract NAS5-32373.
90 
91 !References and Credits:
92  HDF portions developed at the National Center for
93  Supercomputing Applications at the University of Illinois
94  at Urbana-Champaign.
95 
96 !Design Notes:
97  This code was developed in C language.
98 
99 !END************************************************************************
100 */
101 
102  {
103  /**************************************************************************/
104  /* */
105  /* Declare the global variables. */
106  /* */
107  /**************************************************************************/
108 
109  extern int32 global_H_ID;
110 
111 
112  /**************************************************************************/
113  /* */
114  /* Declare the local variables and initialize them. */
115  /* */
116  /**************************************************************************/
117  /* declare field_name_list to be an array of characters */
118  /* VU_MAX_FIELD_NAME_LIST_SIZE long */
119  /* */
120  /* declare Vdata_id to be a variable of type int32 */
121  /* */
122  /* Set routine to "create_Vdata" */
123  /* */
124  /* Set access_mode to "w" for write access */
125  /* */
126  /* Set returnStatus to MODIS_S_SUCCESS */
127  /* */
128  /**************************************************************************/
129 
130  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
131 
132  PGSt_SMF_status status; /* SMF-style message returned by function */
133 
134  char field_name_list[VU_MAX_FIELD_NAME_LIST_SIZE];
135  /* List to hold the VSsetfields */
136  char msg[300]; /* Array to hold error messages */
137 
138  int32 Vdata_id; /* Vdata access indentifier returned from */
139  /* routine VSattach */
140 
141  char *routine; /* Variable to hold routine name */
142 
143  char *access_mode; /* Mode in which the file is accessed */
144 
145  int i; /* Loop Variable */
146  unsigned long cur_field_name_list_size=0; /* stores size of field array */
147 
148  returnStatus = MODIS_S_SUCCESS;
149  routine = "create_Vdata";
150  access_mode = WRITE;
151 
152  /**************************************************************************/
153  /* */
154  /* IF Vdata_name == NULL */
155  /* THEN */
156  /* CALL log_fmt_msg to report that the new Vdata name passed in is NULL.*/
157  /* INPUTS: MODIS_E_NULL_POINTER, routine, " " */
158  /* OUTPUTS: None */
159  /* RETURNS: None */
160  /* */
161  /* return FAIL */
162  /* ENDIF */
163  /* */
164  /**************************************************************************/
165 
166  if (Vdata_name == NULL) {
167  log_fmt_msg(MODIS_E_NULL_POINTER, routine, " ");
168  return FAIL;
169  }
170 
171  /**************************************************************************/
172  /* */
173  /* CALL VSattach to attach the new Vdata to the file */
174  /* INPUTS: global_H_ID, VU_NEW_VDATA, access_mode */
175  /* OUTPUTS: None */
176  /* RETURNS: Vdata_id */
177  /* */
178  /**************************************************************************/
179 
180  Vdata_id = VSattach(global_H_ID, VU_NEW_VDATA, access_mode);
181 
182 
183  /**************************************************************************/
184  /* */
185  /* IF (Vdata_id equals FAIL) */
186  /* THEN */
187  /* CALL log_fmt_msg to report that the new Vdata could not be attached */
188  /* to the file */
189  /* INPUTS: MODIS_E_ATTACHED_VDATAS, routine, "unable to attach the */
190  /* new Vdata to the file" */
191  /* OUTPUTS: None */
192  /* RETURNS: None */
193  /* */
194  /* set returnStatus to FAIL */
195  /* */
196  /**************************************************************************/
197 
198  if (Vdata_id == FAIL) {
199  sprintf(msg, "Vdata Name: %s", Vdata_name);
201  returnStatus = FAIL;
202  }
203 
204 
205  /**************************************************************************/
206  /* */
207  /* ELSE */
208  /* CALL VSsetname to set the Vdata name */
209  /* INPUTS: Vdata_id, Vdata_name */
210  /* OUTPUTS: None */
211  /* RETURNS: None */
212  /* */
213  /* CALL remember to store the Vdata's name and id as an associated pair*/
214  /* INPUTS: Vdata_name, Vdata_id */
215  /* OUTPUTS: None */
216  /* RETURNS: None */
217  /* */
218  /**************************************************************************/
219 
220  else {
221  VSsetname(Vdata_id, Vdata_name);
222  remember(Vdata_name, Vdata_id);
223 
224 
225  /**************************************************************************/
226  /* initialize array to hold field names to zeros */
227  /* initialize the counter for field name array overrun to 0 */
228  /* FOR (i = 0;i is less than num_fields) AND (returnStatus is equal to */
229  /* MODIS_S_SUCCESS); i++) */
230  /* CALL create_Vdata_field to create a field within this Vdata */
231  /* INPUTS: Vdata_name, Vdata_id, field_names[i], data_types[i], */
232  /* order[i] */
233  /* OUTPUTS: None */
234  /* RETURNS: returnStatus */
235  /* */
236  /* IF field name array overflows it bounds */
237  /* THEN */
238  /* set returnStatus = FAIL */
239  /* set msg to hold the Vdata name that caused failure */
240  /* */
241  /* CALL log_fmt_msg to record the error in LogStatus file */
242  /* INPUTS: MODIS_E_FIELD_NAME_LIST_OVERRUN, routine, msg */
243  /* OUTPUTS: None */
244  /* RETURNS: None */
245  /* */
246  /* ELSE */
247  /* Append a field name (field_names[i]) to the list of field names*/
248  /* (field_name_list) */
249  /* */
250  /* IF (i is less than (num_fields-1)) */
251  /* THEN */
252  /* Append a comma to the list of field names (field_name_list) */
253  /* ENDIF */
254  /* ENDIF */
255  /* END FOR */
256  /* */
257  /**************************************************************************/
258 
259  memset(field_name_list, '\0', sizeof(field_name_list));
260  cur_field_name_list_size = 0;
261  for (i=0; ((i < num_fields) && (returnStatus == MODIS_S_SUCCESS)); i++) {
262  returnStatus = create_Vdata_field(Vdata_name,
263  Vdata_id,
264  field_names[i],
265  data_types[i],
266  (int32) order[i]);
267 
268  cur_field_name_list_size += strlen(field_names[i]);
269  if (cur_field_name_list_size > VU_MAX_FIELD_NAME_LIST_SIZE-1) {
270  returnStatus = MODIS_E_FIELD_NAME_LIST_OVERRUN;
271  sprintf(msg, "Vdata name = %s", Vdata_name);
273 
274  }
275  else {
276  strcat(field_name_list, field_names[i]);
277  if (i < num_fields-1)
278  strcat(field_name_list, ",");
279  }
280  }
281 
282 
283  /**************************************************************************/
284  /* */
285  /* IF (returnStatus == FAIL) */
286  /* THEN */
287  /* CALL log_fmt_msg to report that create_Vdata_field failed. */
288  /* INPUTS: MODIS_E_CREATE_VDATA_FIELD, routine, " " */
289  /* OUTPUTS: None */
290  /* RETURNS: None */
291  /* ENDIF */
292  /* */
293  /* IF (returnStatus == MODIS_E_FIELD_NAME_LIST_OVERRUN) */
294  /* THEN */
295  /* set returnStatus equal to FAIL */
296  /* ENDIF */
297  /* */
298  /* field_name_list is a comma separated list of field names */
299  /* (e.g. "X,Y,Z") */
300  /* */
301  /* CALL VSsetfields to set the fields of the Vdata */
302  /* INPUTS: Vdata_id, field_name_list */
303  /* OUTPUTS: None */
304  /* RETURNS: Status */
305  /* */
306  /* IF ( Status equals FAIL ) */
307  /* THEN */
308  /* CALL log_fmt_msg to report that the fields of the Vdata could */
309  /* not set */
310  /* INPUTS: MODIS_E_VSSETFIELDS, routine, "unable to set the */
311  /* fields of the Vdata" */
312  /* OUTPUTS: None */
313  /* RETURNS: None */
314  /* set returnStatus to FAIL */
315  /* ENDIF */
316  /* ENDIF */
317  /* */
318  /**************************************************************************/
319 
320  if (returnStatus == FAIL) {
321  sprintf(msg, "Vdata Name: %s", Vdata_name);
323  }
324 
325  if (returnStatus == MODIS_E_FIELD_NAME_LIST_OVERRUN)
326  returnStatus = FAIL;
327 
328  status = VSsetfields(Vdata_id, field_name_list);
329 
330  if (status == FAIL) {
331  sprintf(msg, "Vdata Name: %s", Vdata_name);
333  returnStatus = FAIL;
334  }
335  }
336 
337  /**************************************************************************/
338  /* */
339  /* RETURN returnStatus */
340  /* */
341  /**************************************************************************/
342 
343  return returnStatus;
344 
345  } /* End of create_Vdata */
integer, parameter int16
Definition: cubeio.f90:3
int status
Definition: l1_czcs_hdf.c:32
void remember(char *Vdata_name, int32 Vdata_id)
Definition: remember.c:8
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_VSSETFIELDS
int32 global_H_ID
Definition: level1a.c:27
#define MODIS_E_FIELD_NAME_LIST_OVERRUN
#define MODIS_E_CREATE_VDATA_FIELD
#define MODIS_E_CREATE_VDATA
#define VU_NEW_VDATA
PGSt_SMF_status create_Vdata_field(char *Vdata_name, int32 Vdata_id, char *field_name, char *data_type, int32 order)
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define WRITE
Definition: create_Vdata.c:7
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 MODIS_S_SUCCESS
#define VU_MAX_NAME_LENGTH
string msg
Definition: mapgen.py:227
#define VU_MAX_DATA_TYPE_STRING_LENGTH
int i
Definition: decode_rs.h:71
#define MODIS_E_NULL_POINTER
#define VU_MAX_FIELD_NAME_LIST_SIZE