NASA Logo
Ocean Color Science Software

ocssw V2022
wrapper.c
Go to the documentation of this file.
1 /* =========================================================== */
2 /* Module wrapper.c */
3 /* */
4 /* HDF/NCDF I/O wrappers */
5 /* */
6 /* Written By: */
7 /* Joel Gales, Futuretech */
8 /* */
9 /* Modification History: */
10 /* Joel Gales, Futuretech, OBPG Project, Nov 2013. */
11 /* Add support for CF-compliant metadata */
12 /* =========================================================== */
13 
14 #include <netcdf.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdint.h>
18 #include <string.h>
19 #include <time.h>
20 #include <math.h>
21 #include <productInfo.h>
22 
23 #include <dfutils.h>
24 #include <genutils.h>
25 #include <nc4utils.h>
26 
27 #include <hdf.h>
28 #include <mfhdf.h>
29 
30 
31 #define ROUND(x) ((((x) >= 0)?0.5:-0.5) + (x))
32 
33 int s2u(const char *in, char *out) {
34  int i;
35  int l = strlen(in);
36  for (i = 0; i < l; i++) {
37  if (in[i] == ' ')
38  out[i] = '_';
39  else
40  out[i] = in[i];
41  }
42  out[l] = 0;
43  return 0;
44 }
45 
46 int8_t findAttr(idDS ds_id, const char *nam) {
47  int32_t attr_index = -1;
48  if (ds_id.fftype == DS_HDF) {
49  if (ds_id.fid > 0) {
50  attr_index = SDfindattr(ds_id.fid, nam);
51  } else {
52  attr_index = SDfindattr(ds_id.sid, nam);
53  }
54 
55  } else if (ds_id.fftype == DS_NCDF) {
56  int status;
57  if (ds_id.fid > 0) {
58  status = nc_inq_attid(ds_id.fid, NC_GLOBAL, nam, (int32_t *) & attr_index);
59  } else {
60  status = nc_inq_attid(-ds_id.fid, ds_id.sid, nam, (int32_t *) & attr_index);
61  }
62  if (status != NC_NOERR) {
63  attr_index = -1;
64  }
65  } else {
66  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
67  exit(1);
68  }
69  return attr_index;
70 }
71 
72 int readAttr(idDS ds_id, const char *nam, VOIDP data) {
73  int status;
74  if (ds_id.fftype == DS_HDF) {
75  if (ds_id.fid > 0)
76  status = getHDFattr(ds_id.fid, nam, "", data);
77  else
78  status = getHDFattr(ds_id.sid, nam, "", data);
79  } else if (ds_id.fftype == DS_NCDF) {
80  if (ds_id.fid > 0) {
81  status = nc_get_att(ds_id.fid, NC_GLOBAL, nam, data);
82  } else {
83  status = nc_get_att(-ds_id.fid, ds_id.sid, nam, data);
84  }
85  } else {
86  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
87  exit(EXIT_FAILURE);
88  }
89  return status;
90 }
91 
99 char* readAttrStr(idDS ds_id, const char *name) {
100  char* data;
101  int status = 0;
102  char buf[128];
103 
104  if (ds_id.fftype == DS_HDF) {
105  int32_t dtype;
106  int32_t count;
107  if (ds_id.fid > 0) {
108  status = SDattrinfo(ds_id.fid, SDfindattr(ds_id.fid, name), buf, &dtype, &count);
109  if (status)
110  return NULL;
111  if (dtype != DFNT_CHAR)
112  return NULL;
113  data = (char*) malloc(count + 1);
114  if (!data)
115  goto memoryError;
116  status = getHDFattr(ds_id.fid, name, "", data);
117  data[count] = 0; // NULL terminate the string
118  } else {
119  status = SDattrinfo(ds_id.sid, SDfindattr(ds_id.sid, name), buf, &dtype, &count);
120  if (status)
121  return NULL;
122  if (dtype != DFNT_CHAR)
123  return NULL;
124  data = (char*) malloc(count + 1);
125  if (!data)
126  goto memoryError;
127  status = getHDFattr(ds_id.sid, name, "", data);
128  data[count] = 0; // NULL terminate the string
129  }
130  } else if (ds_id.fftype == DS_NCDF) {
131  int32_t dtype;
132  size_t count;
133  if (ds_id.fid > 0) {
134  status = nc_inq_att(ds_id.fid, NC_GLOBAL, name, &dtype, &count);
135  if (status != NC_NOERR)
136  return NULL;
137  if(dtype == NC_CHAR) {
138  data = (char*) malloc(count + 1);
139  if (!data)
140  goto memoryError;
141  status = nc_get_att(ds_id.fid, NC_GLOBAL, name, data);
142  data[count] = 0; // NULL terminate the string
143  } else if(dtype == NC_STRING) {
144  if(count < 1)
145  return NULL;
146  char *list[count];
147  status = nc_get_att(ds_id.fid, NC_GLOBAL, name, list);
148  data = strdup(list[0]);
149  nc_free_string(count, list);
150  } else
151  return NULL;
152  } else {
153  status = nc_inq_att(-ds_id.fid, ds_id.sid, name, &dtype, &count);
154  if (status != NC_NOERR)
155  return NULL;
156  if (dtype != NC_STRING && dtype != NC_CHAR)
157  return NULL;
158  data = (char*) malloc(count + 1);
159  if (!data)
160  goto memoryError;
161  status = nc_get_att(-ds_id.fid, ds_id.sid, name, data);
162  data[count] = 0; // NULL terminate the string
163  }
164  } else {
165  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
166  exit(1);
167  }
168  if (status) {
169  free(data);
170  return NULL;
171  }
172  return data;
173 
174 memoryError:
175  printf("-E- %s %d Could not allocate memory for reading attribute %s\n", __FILE__, __LINE__, name);
176  exit(1);
177 }
178 
188 int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count) {
189  int32_t attr_index;
190  int status;
191  char buf[128];
192  if (ds_id.fftype == DS_HDF) {
193  if (ds_id.fid > 0) {
194  attr_index = SDfindattr(ds_id.fid, nam);
195  status = SDattrinfo(ds_id.fid, attr_index, buf, dtype, count);
196  } else {
197  attr_index = SDfindattr(ds_id.sid, nam);
198  status = SDattrinfo(ds_id.sid, attr_index, buf, dtype, count);
199  }
200  } else if (ds_id.fftype == DS_NCDF) {
201  size_t cnt;
202  if (ds_id.fid > 0) {
203  status = nc_inq_att(ds_id.fid, NC_GLOBAL, nam, (int32_t *) dtype, &cnt);
204  *count = cnt;
205  } else {
206  status = nc_inq_att(-ds_id.fid, ds_id.sid, nam, (int32_t *) dtype, &cnt);
207  *count = cnt;
208  }
209  } else {
210  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
211  exit(1);
212  }
213  return status;
214 }
215 
216 int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void* data) {
217  int status;
218  if (ds_id.fftype == DS_HDF) {
219  status = sd_setattr(ds_id.sid, (char*) nam, typ, cnt, (VOIDP) data);
220  } else if (ds_id.fftype == DS_NCDF) {
221  status = nc_put_att(ds_id.fid, ds_id.sid, nam, typ, cnt, data);
222  if (status != NC_NOERR) {
223  printf("-E- %s %d: %s for %s\n",
224  __FILE__, __LINE__, nc_strerror(status), nam);
225  }
226  } else {
227  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
228  exit(1);
229  }
230  return status;
231 }
232 
233 int SetChrGA(idDS ds_id, const char *name, const char *value) {
234  int status;
235  if (ds_id.fftype == DS_HDF) {
236  status = sd_setattr(ds_id.fid, name, DFNT_CHAR, strlen(value) + 1, value);
237  } else if (ds_id.fftype == DS_NCDF) {
238  status = nc_put_att_text(ds_id.fid, NC_GLOBAL, name,
239  strlen(value) + 1, value);
240  if (status != NC_NOERR) {
241  printf("-E- %s %d: %s for %s\n",
242  __FILE__, __LINE__, nc_strerror(status), name);
243  }
244  } else {
245  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
246  exit(1);
247  }
248  return (status);
249 }
250 
251 int SetF64GA(idDS ds_id, const char *name, float64 value) {
252  int status;
253  if (ds_id.fftype == DS_HDF) {
254  status = sd_setattr(ds_id.fid, name, DFNT_FLOAT64, 1, (VOIDP) & value);
255  } else if (ds_id.fftype == DS_NCDF) {
256  status = nc_put_att_double(ds_id.fid, NC_GLOBAL, name,
257  NC_DOUBLE, 1, (const double *) &value);
258  if (status != NC_NOERR) {
259  printf("-E- %s %d: %s for %s\n",
260  __FILE__, __LINE__, nc_strerror(status), name);
261  }
262  } else {
263  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
264  exit(1);
265  }
266  return (status);
267 }
268 
269 int SetF32GA(idDS ds_id, const char *name, float32 value) {
270  int status;
271  if (ds_id.fftype == DS_HDF) {
272  status = sd_setattr(ds_id.fid, name, DFNT_FLOAT32, 1, (VOIDP) & value);
273  } else if (ds_id.fftype == DS_NCDF) {
274  status = nc_put_att_float(ds_id.fid, NC_GLOBAL, name,
275  NC_FLOAT, 1, (const float *) &value);
276  if (status != NC_NOERR) {
277  printf("-E- %s %d: %s for %s\n",
278  __FILE__, __LINE__, nc_strerror(status), name);
279  }
280  } else {
281  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
282  exit(1);
283  }
284  return (status);
285 }
286 
287 int SetI16GA(idDS ds_id, const char *name, int16 value) {
288  int status;
289  if (ds_id.fftype == DS_HDF) {
290  status = sd_setattr(ds_id.fid, name, DFNT_INT16, 1, (VOIDP) & value);
291  } else if (ds_id.fftype == DS_NCDF) {
292  status = nc_put_att_short(ds_id.fid, NC_GLOBAL, name,
293  NC_SHORT, 1, (const short *) &value);
294  if (status != NC_NOERR) {
295  printf("-E- %s %d: %s for %s\n",
296  __FILE__, __LINE__, nc_strerror(status), name);
297  }
298  } else {
299  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
300  exit(1);
301  }
302  return (status);
303 }
304 
305 int SetI8GA(idDS ds_id, const char *name, uint8 value) {
306  int status;
307  if (ds_id.fftype == DS_HDF) {
308  status = sd_setattr(ds_id.fid, name, DFNT_UINT8, 1, (VOIDP) & value);
309  } else if (ds_id.fftype == DS_NCDF) {
310  status = nc_put_att_uchar(ds_id.fid, NC_GLOBAL, name,
311  NC_BYTE, 1, (const uint8 *) &value);
312  if (status != NC_NOERR) {
313  printf("-E- %s %d: %s for %s\n",
314  __FILE__, __LINE__, nc_strerror(status), name);
315  }
316  } else {
317  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
318  exit(1);
319  }
320  return (status);
321 }
322 
323 int SetI32GA(idDS ds_id, const char *name, int32_t value) {
324  int status;
325  if (ds_id.fftype == DS_HDF) {
326  status = sd_setattr(ds_id.fid, name, DFNT_INT32, 1, (VOIDP) & value);
327  } else if (ds_id.fftype == DS_NCDF) {
328  status = nc_put_att_int(ds_id.fid, NC_GLOBAL, name,
329  NC_INT, 1, (const int *) &value);
330  if (status != NC_NOERR) {
331  printf("-E- %s %d: %s for %s\n",
332  __FILE__, __LINE__, nc_strerror(status), name);
333  }
334  } else {
335  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
336  exit(1);
337  }
338  return (status);
339 }
340 
341 int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3],
342  const char dm_name[3][80]) {
343  static productInfo_t* p_info;
344 
345  if (p_info == NULL) {
346  p_info = allocateProductInfo();
347  }
348 
349  if (findProductInfo(sname, sensorId, p_info)) {
350  return createDS2(ds_id, sname, p_info, dm, dm_name);
351  } else {
352  printf("%s not found in XML product table\n", sname);
353  exit(1);
354  }
355 }
356 
357 int createDS2(idDS ds_id, const char *sname, productInfo_t* p_info, int32_t dm[3],
358  const char dm_name[3][80]) {
359  int i, status;
360  int32_t nt; /* data type */
361 
362  if (ds_id.fftype == DS_HDF) {
363 
364  if (strcmp(p_info->dataType, "byte") == 0)
365  nt = DFNT_INT8;
366  else if (strcmp(p_info->dataType, "ubyte") == 0)
367  nt = DFNT_UINT8;
368  else if (strcmp(p_info->dataType, "short") == 0)
369  nt = DFNT_INT16;
370  else if (strcmp(p_info->dataType, "ushort") == 0)
371  nt = DFNT_UINT16;
372  else if (strcmp(p_info->dataType, "int") == 0)
373  nt = DFNT_INT32;
374  else if (strcmp(p_info->dataType, "uint") == 0)
375  nt = DFNT_UINT32;
376  else if (strcmp(p_info->dataType, "float") == 0)
377  nt = DFNT_FLOAT32;
378  else if (strcmp(p_info->dataType, "double") == 0)
379  nt = DFNT_FLOAT64;
380  else {
381  printf("-E- %s %d: datatype %s is not valid\n", __FILE__, __LINE__, p_info->dataType);
382  exit(1);
383  }
384 
385  status = CreateSDS(ds_id.fid, sname, p_info->description, p_info->standardName,
386  p_info->units, p_info->validMin, p_info->validMax, p_info->scaleFactor,
387  p_info->addOffset, nt, p_info->rank, dm[0], dm[1], dm[2],
388  dm_name[0], dm_name[1], dm_name[2]);
389 
390  } else if (ds_id.fftype == DS_NCDF) {
391  int32_t dimids[3];
392  char buf[512];
393  for (i = 0; i < p_info->rank; i++) {
394  s2u(dm_name[i], buf);
395  status = nc_inq_dimid(ds_id.fid, buf, &dimids[i]);
396  if (status != NC_NOERR) {
397  printf("-E- %s %d: %s for %s\n",
398  __FILE__, __LINE__, nc_strerror(status), dm_name[i]);
399  exit(1);
400  }
401  }
402 
403  if (strcmp(p_info->dataType, "byte") == 0)
404  nt = NC_BYTE;
405  else if (strcmp(p_info->dataType, "ubyte") == 0)
406  nt = NC_UBYTE;
407  else if (strcmp(p_info->dataType, "short") == 0)
408  nt = NC_SHORT;
409  else if (strcmp(p_info->dataType, "ushort") == 0)
410  nt = NC_USHORT;
411  else if (strcmp(p_info->dataType, "int") == 0)
412  nt = NC_INT;
413  else if (strcmp(p_info->dataType, "uint") == 0)
414  nt = NC_UINT;
415  else if (strcmp(p_info->dataType, "float") == 0)
416  nt = NC_FLOAT;
417  else if (strcmp(p_info->dataType, "double") == 0)
418  nt = NC_DOUBLE;
419  else {
420  printf("-E- %s %d datatype %s not defined\n", __FILE__, __LINE__, p_info->dataType);
421  exit(1);
422  }
423 
424  status = CreateNCDF(ds_id, sname, p_info->description, p_info->standardName,
425  p_info->reference, p_info->comment, p_info->units, p_info->validMin,
426  p_info->validMax, p_info->scaleFactor, p_info->addOffset,
427  p_info->fillValue, nt, p_info->rank, dimids);
428  } else {
429  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
430  exit(1);
431  }
432  return status;
433 }
434 
435 int32_t selectDS(idDS ds_id, const char *l2_prod_name) {
436  int32_t outid;
437  if (ds_id.fftype == DS_HDF) {
438  outid = SDselect(ds_id.fid, SDnametoindex(ds_id.fid, l2_prod_name));
439  } else if (ds_id.fftype == DS_NCDF) {
440  int status;
441  status = nc_inq_varid(ds_id.fid, l2_prod_name, (int32_t *) & outid);
442  if (status != NC_NOERR) {
443  outid = -1;
444  }
445  } else {
446  printf("-E- %s %d fftype %d not defined\n", __FILE__, __LINE__, ds_id.fftype);
447  exit(1);
448  }
449  return outid;
450 }
451 
452 int32 checkDS(idDS ds_id, const char *l2_prod_name) {
453  int32 outid;
454  if (ds_id.fftype == DS_HDF) {
455  outid = SDselect(ds_id.fid, SDnametoindex(ds_id.fid, l2_prod_name));
456  if (outid != -1) {
457  SDendaccess(outid);
458  }
459  } else if (ds_id.fftype == DS_NCDF) {
460  int status;
461  status = nc_inq_varid(ds_id.fid, l2_prod_name, (int32_t *) & outid);
462  if (status != NC_NOERR) {
463  outid = -1;
464  }
465  } else {
466  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
467  exit(1);
468  }
469  return outid;
470 }
471 
473  idDS ds_id,
474  const char *name,
475  const void* data,
476  int32_t s0,
477  int32_t s1,
478  int32_t s2,
479  int32_t e0,
480  int32_t e1,
481  int32_t e2) {
482 
483  idDS ds_id0 = ds_id;
484 
485  if (ds_id0.fftype == DS_HDF) {
486  PTB(sd_writedata(ds_id0.fid, name, data, s0, s1, s2, e0, e1, e2));
487  } else if (ds_id0.fftype == DS_NCDF) {
488  int status = NC_NOERR;
489  size_t startp[3] = {s0, s1, s2};
490  size_t countp[3] = {e0, e1, e2};
491  status = nc_inq_varid(ds_id0.fid, name, (int32_t *) & ds_id0.sid);
492  if (status != NC_NOERR) {
493  printf("-E- %s %d: %s for %s\n",
494  __FILE__, __LINE__, nc_strerror(status), name);
495  exit(1);
496  }
497  status = nc_put_vara(ds_id0.fid, ds_id0.sid, startp, countp, data);
498  if (status != NC_NOERR) {
499  printf("-E- %s %d: %s for %s\n",
500  __FILE__, __LINE__, nc_strerror(status), name);
501  exit(1);
502  }
503 
504  } else {
505  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
506  exit(1);
507  }
508  return 0;
509 }
510 
511 int readDS(
512  idDS ds_id,
513  const char *name,
514  int32_t *start,
515  int32_t *stride,
516  int32_t *count,
517  VOIDP data) {
518 
519  idDS ds_id0 = ds_id;
520  int32_t s0 = start[0], s1 = start[1], s2 = start[2];
521  int32_t e0 = count[0], e1 = count[1], e2 = count[2];
522 
523  if (ds_id0.fftype == DS_HDF) {
524  PTB(sd_readdata(ds_id0.fid, name, data, s0, s1, s2, e0, e1, e2));
525  } else if (ds_id0.fftype == DS_NCDF) {
526  int status = NC_NOERR;
527  size_t startp[3] = {start[0], start[1], start[2]};
528  size_t countp[3] = {count[0], count[1], count[2]};
529  status = nc_inq_varid(ds_id0.fid, name, (int32_t *) & ds_id0.sid);
530  if (status != NC_NOERR) {
531  printf("-E- %s %d: %s for %s\n",
532  __FILE__, __LINE__, nc_strerror(status), name);
533  return status;
534  }
535  status = nc_get_vara(ds_id0.fid, ds_id0.sid, startp, countp, data);
536  if (status != NC_NOERR) {
537  printf("-E- %s %d: %s for %s\n",
538  __FILE__, __LINE__, nc_strerror(status), name);
539  return status;
540  }
541  } else {
542  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
543  exit(1);
544  }
545  return 0;
546 }
547 
558 idDS startDS(const char *filename, ds_format_t format, ds_access_t access,
559  int32_t deflate) {
560  idDS ds_id;
561  ds_id.fftype = format;
562  ds_id.deflate = deflate;
563 
564  if (format == DS_HDF) {
565  int32_t hdfAccess;
566  if (access == DS_READ)
567  hdfAccess = DFACC_RDONLY;
568  else
569  hdfAccess = DFACC_CREATE;
570  ds_id.fid = SDstart(filename, hdfAccess);
571  if (ds_id.fid == -1) {
572  fprintf(stderr, "-E- %s line %d: SDstart failure, %s .\n",
573  __FILE__, __LINE__, filename);
574  }
575  } else if (format == DS_NCDF) {
577  int status;
578  if (access == DS_READ) {
579  status = nc_open(filename, NC_NOWRITE, &ds_id.fid);
580  if (status != NC_NOERR) {
581  ds_id.fid = -1;
582  }
583  } else {
584  status = nc_create(filename, NC_NETCDF4, &ds_id.fid);
585  if (status != NC_NOERR) {
586  fprintf(stderr,
587  "-E- %s line %d: Could not create NCDF4 file, %s .\n",
588  __FILE__, __LINE__, filename);
589  ds_id.fid = -1;
590  }
591  }
592  } else {
593  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
594  exit(1);
595  }
596  return ds_id;
597 }
598 
599 /*
600  * open a data file for reading. This routine figures out if the
601  * file is HDF4 or netCDF4. Must use endDS() to close the file.
602  *
603  * @param filename path to file
604  * @return a data set structure. ds_id.fid = -1 if there was a problem.
605  */
606 idDS openDS(const char *filename) {
607  ds_format_t fileformat;
608 
609  if (Hishdf(filename)) {
610  fileformat = DS_HDF;
611  } else {
612  fileformat = DS_NCDF;
613  }
614  return startDS(filename, fileformat, DS_READ, 0);
615 }
616 
617 int endaccessDS(idDS ds_id) {
618  if (ds_id.fftype == DS_HDF) {
619  PTB(SDendaccess(ds_id.sid));
620  }
621  return 0;
622 }
623 
624 int endDS(idDS ds_id) {
625  if (ds_id.fftype == DS_HDF) {
626  return SDend(ds_id.fid);
627  } else if (ds_id.fftype == DS_NCDF) {
628  return nc_close(ds_id.fid);
629  } else {
630  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
631  exit(1);
632  }
633  return 0;
634 }
635 
636 int getDimsDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME],
637  int32_t dims[H4_MAX_VAR_DIMS]) {
638 
639  int status;
640  if (ds_id.fftype == DS_HDF) {
641  status = getDims(ds_id.fid, sdsname, dims);
642  } else if (ds_id.fftype == DS_NCDF) {
643  int32_t varid;
644  status = nc_inq_varid(ds_id.fid, sdsname, &varid);
645  if (status != NC_NOERR) {
646  printf("-E- %s %d: %s for %s\n",
647  __FILE__, __LINE__, nc_strerror(status), sdsname);
648  } else {
649  int ndims;
650  int dimids[H4_MAX_VAR_DIMS];
651  status = nc_inq_var(ds_id.fid, varid, NULL, NULL, &ndims, dimids, NULL);
652  if (status != NC_NOERR) {
653  printf("-E- %s %d: %s for %s\n",
654  __FILE__, __LINE__, nc_strerror(status), sdsname);
655  } else {
656  int i;
657  size_t dim;
658  for (i = 0; i < ndims; i++) {
659  status = nc_inq_dimlen(ds_id.fid, dimids[i], &dim);
660  dims[i] = dim;
661  }
662  }
663  }
664  } else {
665  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
666  exit(1);
667  }
668  return status;
669 }
670 
671 int getTypeDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t *dtype) {
672  int status;
673  if (ds_id.fftype == DS_HDF) {
674  status = get_type(ds_id.fid, sdsname, dtype);
675  } else if (ds_id.fftype == DS_NCDF) {
676  int32_t varid;
677  status = nc_inq_varid(ds_id.fid, sdsname, &varid);
678  if (status != NC_NOERR) {
679  printf("-E- %s %d: %s for %s\n",
680  __FILE__, __LINE__, nc_strerror(status), sdsname);
681  } else {
682  status = nc_inq_vartype(ds_id.fid, varid, dtype);
683  if (status != NC_NOERR) {
684  printf("-E- %s %d: %s for %s\n",
685  __FILE__, __LINE__, nc_strerror(status), sdsname);
686  }
687  }
688  } else {
689  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
690  exit(1);
691  }
692  return status;
693 }
694 
695 int fileInfo(idDS ds_id, int32_t *n_datasets, int32_t *n_globalattr) {
696  int status;
697  if (ds_id.fftype == DS_HDF) {
698  status = SDfileinfo(ds_id.fid, n_datasets, n_globalattr);
699  } else if (ds_id.fftype == DS_NCDF) {
700  status = nc_inq(ds_id.fid, NULL, n_datasets, n_globalattr, NULL);
701  if (status != NC_NOERR) {
702  printf("-E- %s %d: %s\n", __FILE__, __LINE__, nc_strerror(status));
703  }
704  } else {
705  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
706  exit(1);
707  }
708  return status;
709 }
710 
711 int getProdlist(const char *fname, char **prodlist, int32_t *l2_flags_type) {
712 
713  size_t i;
714  char buffer[2048 * 8];
715  int32_t listlen = 0;
716  char *cptr;
717 
718  if (filesize(fname) == -1) {
719  printf("-E- File %s does not exist\n", fname);
720  exit(1);
721  }
722 
723  if (Hishdf(fname) == 1) {
724 
725  int32_t HDFfid;
726  int32_t vg_ref;
727  int32_t vgid;
728  int32_t tag;
729  int32_t ref;
730  int32_t sd_id;
731  int32_t sds_id;
732  int32_t dims[8];
733  int32_t rank;
734  int32_t dtype;
735  int32_t nattrs;
736 
737  HDFfid = Hopen(fname, DFACC_READ, 0);
738 
739  if (HDFfid == -1) {
740  printf("\n%s not found or is corrupt.\n", fname);
741  exit(1);
742  }
743 
744  sd_id = SDstart(fname, DFACC_RDONLY);
745  if (sd_id == -1) {
746  printf("Error opening (SDstart) %s\n", fname);
747  exit(-1);
748  }
749 
750  Vstart(HDFfid);
751  vg_ref = Vfind(HDFfid, "Geophysical Data");
752  vgid = Vattach(HDFfid, vg_ref, "r");
753 
754  for (i = 0; i < Vntagrefs(vgid); i++) {
755  Vgettagref(vgid, i, &tag, &ref);
756  sds_id = SDselect(sd_id, SDreftoindex(sd_id, ref));
757  if (sds_id == -1) {
758  printf("Error accessing SDS (reference #: %d) in: %s .\n", ref,
759  fname);
760  exit(-1);
761  }
762  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
763  if (strcmp(buffer, "l2_flags") != 0) {
764  listlen += strlen(buffer) + 1;
765  }
766  SDendaccess(sds_id);
767  }
768 
769  *prodlist = (char *) calloc(listlen + 1, sizeof (char));
770  cptr = *prodlist;
771 
772  for (i = 0; i < Vntagrefs(vgid); i++) {
773  Vgettagref(vgid, i, &tag, &ref);
774  sds_id = SDselect(sd_id, SDreftoindex(sd_id, ref));
775  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
776  if (strcmp(buffer, "l2_flags") != 0) {
777  if (i == 0)
778  strcpy(*prodlist, buffer);
779  else
780  strcat(*prodlist, buffer);
781  strcat(*prodlist, ",");
782  } else {
783  *l2_flags_type = dtype;
784  }
785  SDendaccess(sds_id);
786  }
787  cptr[listlen - 1] = 0;
788 
789  SDend(sd_id);
790  Vdetach(vgid);
791  Vend(HDFfid);
792 
793  Hclose(HDFfid);
794 
795  } else {
796 
797  int ncid, grp_ncid, nvars;
798  if (nc_open(fname, NC_NOWRITE, &ncid) == NC_NOERR) {
799  nc_inq_ncid(ncid, "geophysical_data", &grp_ncid);
800  nc_inq(grp_ncid, NULL, &nvars, NULL, NULL);
801  for (i = 0; i < nvars; i++) {
802  nc_inq_varname(grp_ncid, i, buffer);
803  if (strcmp(buffer, "l2_flags") != 0) {
804  listlen += strlen(buffer) + 1;
805  }
806  }
807 
808  *prodlist = (char *) calloc(listlen + 1, sizeof (char));
809  cptr = *prodlist;
810 
811  for (i = 0; i < nvars; i++) {
812  nc_inq_varname(grp_ncid, i, buffer);
813  if (strcmp(buffer, "l2_flags") != 0) {
814  if (i == 0)
815  strcpy(*prodlist, buffer);
816  else
817  strcat(*prodlist, buffer);
818  strcat(*prodlist, ",");
819  } else {
820  nc_inq_vartype(grp_ncid, i, l2_flags_type);
821  }
822  }
823  } else {
824  printf("-E- Can not open NetCDF file %s\n", fname);
825  exit(EXIT_FAILURE);
826  }
827  cptr[listlen - 1] = 0;
828  nc_close(ncid);
829  }
830 
831  return 0;
832 }
833 
834 /* -------------------------------------------------------------------- */
835 /* Create an NCDF variable using the wrappers for the NCDF routines */
836 
837 /* -------------------------------------------------------------------- */
839  idDS ds_id,
840  const char *sname, /* short name */
841  const char *lname, /* long name */
842  const char *standard_name, /* NetCDF standard name (not set if passed NULL or "") */
843  const char *reference,
844  const char *comment,
845  const char *units, /* units (not set if passed NULL or "") */
846  double low, /* low end of valid range */
847  double high, /* high end of range (no range set if low >= high) */
848  float scale_factor, /* scale factor (not set if 1.0) */
849  float add_offset, /* scaling offset (not set if 0.0) */
850  int32_t fillValue, /* fill value */
851  int32_t nt, /* NCDF number type */
852  int32_t rank, /* number of dimensions (must be <= 3) */
853  int32_t dimids[3]/* dimension ids */
854  ) {
855 
856  int32_t nc_id = ds_id.fid;
857  int32_t var_id;
858  int i;
859  int status;
860  size_t chunksize[3] = {0, 0, 0};
861  char *validnames[2] = {"valid_min", "valid_max"};
862 
863  /* Create the NCDF dataset */
864  status = nc_def_var(nc_id, sname, nt, rank, dimids, &var_id);
865  if (status != NC_NOERR) {
866  printf("-E- %s %d: %s for %s\n",
867  __FILE__, __LINE__, nc_strerror(status), sname);
868  exit(1);
869  }
870  if (ds_id.deflate > 0)
871  nc_init_compress(nc_id, var_id, dimids, rank, chunksize, (int) ds_id.deflate);
872 
873  /* Add a "long_name" attribute */
874  status = nc_put_att_text(nc_id, var_id, "long_name", strlen(lname), lname);
875  if (status != NC_NOERR) {
876  printf("-E- %s %d: %s for %s\n",
877  __FILE__, __LINE__, nc_strerror(status), "long_name");
878  exit(1);
879  }
880 
881  /* Add a "scale_factor" attribute and an "add_offset" attribute */
882  if (nt != NC_FLOAT && nt != NC_DOUBLE) {
883  if (scale_factor != 1.0 || add_offset != 0.0) {
884  status = nc_put_att_float(nc_id, var_id, "scale_factor", NC_FLOAT, 1, &scale_factor);
885  if (status != NC_NOERR) {
886  printf("-E- %s %d: %s for %s\n",
887  __FILE__, __LINE__, nc_strerror(status), "scale_factor");
888  exit(1);
889  }
890  status = nc_put_att_float(nc_id, var_id, "add_offset", NC_FLOAT, 1, &add_offset);
891  if (status != NC_NOERR) {
892  printf("-E- %s %d: %s for %s\n",
893  __FILE__, __LINE__, nc_strerror(status), "add_offset");
894  exit(1);
895  }
896  }
897  }
898 
899  /* Add a "units" attribute if one is specified */
900  if (units != NULL
901  && units[0] != 0
902  && strcasecmp(units, "dimensionless") != 0
903  && strcasecmp(units, "unitless") != 0) {
904  status = nc_put_att_text(nc_id, var_id, "units", strlen(units), units);
905  if (status != NC_NOERR) {
906  printf("-E- %s %d: %s for %s\n",
907  __FILE__, __LINE__, nc_strerror(status), "units");
908  exit(1);
909  }
910  }
911 
912  /* add coordinates if rank > 1 */
913  if (rank > 1 && strcasecmp(sname, "longitude") != 0 && strcasecmp(sname, "latitude") != 0) {
914  status = nc_put_att_text(nc_id, var_id, "coordinates", 18, "longitude latitude");
915  if (status != NC_NOERR) {
916  printf("-E- %s %d: %s for %s\n",
917  __FILE__, __LINE__, nc_strerror(status), "coordinates");
918  exit(1);
919  }
920  }
921 
922  /* Add a "standard_name" attribute */
923  if (standard_name != NULL && strcmp(standard_name, "") != 0) {
924  status = nc_put_att_text(nc_id, var_id, "standard_name",
925  strlen(standard_name), standard_name);
926  if (status != NC_NOERR) {
927  printf("-E- %s %d: %s for %s\n",
928  __FILE__, __LINE__, nc_strerror(status), "standard_name");
929  exit(1);
930  }
931  }
932 
933  if (strstr(sname, "flag_") == sname ||
934  strstr(sname, "l2_flags") != NULL)
935  goto skip_fill;
936 
937  /* Add a "_FillValue" attribute */
938  switch (nt) { /* Use the appropriate number type */
939  case NC_BYTE:
940  {
941  uint8_t fv_i8 = 255;
942  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_i8);
943  if (status != NC_NOERR) {
944  printf("-E- %s %d: %s for %s\n",
945  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
946  exit(1);
947  }
948  break;
949  }
950  case NC_UBYTE:
951  {
952  uint8_t fv_i8 = -128;
953  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_i8);
954  if (status != NC_NOERR) {
955  printf("-E- %s %d: %s for %s\n",
956  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
957  exit(1);
958  }
959  break;
960  }
961  case NC_USHORT:
962  {
963  uint16_t fv_i16 = (uint16_t) fillValue;
964  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_i16);
965  if (status != NC_NOERR) {
966  printf("-E- %s %d: %s for %s\n",
967  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
968  exit(1);
969  }
970  break;
971  }
972  case NC_SHORT:
973  {
974  int16_t fv_i16 = (int16_t) fillValue;
975  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_i16);
976  if (status != NC_NOERR) {
977  printf("-E- %s %d: %s for %s\n",
978  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
979  exit(1);
980  }
981  break;
982  }
983  case NC_INT:
984  {
985  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fillValue);
986  if (status != NC_NOERR) {
987  printf("-E- %s %d: %s for %s\n",
988  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
989  exit(1);
990  }
991  break;
992  }
993  case NC_UINT:
994  {
995  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fillValue);
996  if (status != NC_NOERR) {
997  printf("-E- %s %d: %s for %s\n",
998  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
999  exit(1);
1000  }
1001  break;
1002  }
1003  case NC_FLOAT:
1004  {
1005  float fv_f32 = (float) fillValue;
1006  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_f32);
1007  if (status != NC_NOERR) {
1008  printf("-E- %s %d: %s for %s\n",
1009  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
1010  exit(1);
1011  }
1012  break;
1013  }
1014  case NC_DOUBLE:
1015  {
1016  double fv_f64 = (double) fillValue;
1017  status = nc_put_att(nc_id, var_id, "_FillValue", nt, 1, &fv_f64);
1018  if (status != NC_NOERR) {
1019  printf("-E- %s %d: %s for %s\n",
1020  __FILE__, __LINE__, nc_strerror(status), "_FillValue");
1021  exit(1);
1022  }
1023  break;
1024  }
1025  default:
1026  fprintf(stderr, "-E- %s line %d: ", __FILE__, __LINE__);
1027  fprintf(stderr, "Got unsupported fill values number type (%d) ", nt);
1028  fprintf(stderr, "while trying to create NCDF variable, \"%s\", ", sname);
1029  return (PROGRAMMER_BOOBOO);
1030  }
1031 
1032 skip_fill:
1033  /* Add "valid_min" & "valid_max" attributes if low is less than high
1034  * and they are not default values
1035  * (i.e. they were properly defined in the product.xml)
1036  */
1037  if ((low < high) && (low != PRODUCT_DEFAULT_validMin || high != PRODUCT_DEFAULT_validMax)) {
1038  switch (nt) { /* Use the appropriate number type */
1039  case NC_BYTE:
1040  {
1041  int8_t vr[2];
1042  vr[0] = (int8_t) ROUND((low - add_offset) / scale_factor);
1043  vr[1] = (int8_t) ROUND((high - add_offset) / scale_factor);
1044  for (i = 0; i < 2; i++) {
1045  status = nc_put_att_schar(nc_id, var_id, validnames[i], NC_BYTE,
1046  1, (const signed char *) &vr[i]);
1047  if (status != NC_NOERR) {
1048  printf("-E- %s %d: %s for %s\n",
1049  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1050  exit(1);
1051  }
1052  }
1053  }
1054  break;
1055  case NC_UBYTE:
1056  {
1057  uint8_t vr[2];
1058  vr[0] = (uint8_t) ROUND((low - add_offset) / scale_factor);
1059  vr[1] = (uint8_t) ROUND((high - add_offset) / scale_factor);
1060  for (i = 0; i < 2; i++) {
1061  status = nc_put_att_uchar(nc_id, var_id, validnames[i], NC_UBYTE,
1062  1, (const unsigned char *) &vr[i]);
1063  if (status != NC_NOERR) {
1064  printf("-E- %s %d: %s for %s\n",
1065  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1066  exit(1);
1067  }
1068  }
1069  }
1070  break;
1071  case NC_SHORT:
1072  {
1073  int16_t vr[2];
1074  vr[0] = (int16_t) ROUND((low - add_offset) / scale_factor);
1075  vr[1] = (int16_t) ROUND((high - add_offset) / scale_factor);
1076  for (i = 0; i < 2; i++) {
1077  status = nc_put_att_short(nc_id, var_id, validnames[i], NC_SHORT,
1078  1, &vr[i]);
1079  if (status != NC_NOERR) {
1080  printf("-E- %s %d: %s for %s\n",
1081  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1082  exit(1);
1083  }
1084  }
1085  }
1086  break;
1087  case NC_USHORT:
1088  {
1089  uint16_t vr[2];
1090  vr[0] = (uint16_t) ROUND((low - add_offset) / scale_factor);
1091  vr[1] = (uint16_t) ROUND((high - add_offset) / scale_factor);
1092  for (i = 0; i < 2; i++) {
1093  status = nc_put_att_ushort(nc_id, var_id, validnames[i], NC_USHORT,
1094  1, &vr[i]);
1095  if (status != NC_NOERR) {
1096  printf("-E- %s %d: %s for %s\n",
1097  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1098  exit(1);
1099  }
1100  }
1101  }
1102  break;
1103  case NC_INT:
1104  {
1105  int32_t vr[2];
1106  vr[0] = (int32_t) ROUND((low - add_offset) / scale_factor);
1107  vr[1] = (int32_t) ROUND((high - add_offset) / scale_factor);
1108  for (i = 0; i < 2; i++) {
1109  status = nc_put_att_int(nc_id, var_id, validnames[i], NC_INT,
1110  1, &vr[i]);
1111  if (status != NC_NOERR) {
1112  printf("-E- %s %d: %s for %s\n",
1113  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1114  exit(1);
1115  }
1116  }
1117  }
1118  break;
1119  case NC_UINT:
1120  {
1121  uint32_t vr[2];
1122  vr[0] = (uint32_t) ROUND((low - add_offset) / scale_factor);
1123  vr[1] = (uint32_t) ROUND((high - add_offset) / scale_factor);
1124  for (i = 0; i < 2; i++) {
1125  status = nc_put_att_uint(nc_id, var_id, validnames[i], NC_UINT,
1126  1, &vr[i]);
1127  if (status != NC_NOERR) {
1128  printf("-E- %s %d: %s for %s\n",
1129  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1130  exit(1);
1131  }
1132  }
1133  }
1134  break;
1135  case NC_FLOAT:
1136  {
1137  float vr[2];
1138  vr[0] = (float) low;
1139  vr[1] = (float) high;
1140  for (i = 0; i < 2; i++) {
1141  status = nc_put_att_float(nc_id, var_id, validnames[i], NC_FLOAT,
1142  1, &vr[i]);
1143  if (status != NC_NOERR) {
1144  printf("-E- %s %d: %s for %s\n",
1145  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1146  exit(1);
1147  }
1148  }
1149  }
1150  break;
1151  default:
1152  fprintf(stderr, "-E- %s line %d: ", __FILE__, __LINE__);
1153  fprintf(stderr, "Got unsupported number type (%d) ", nt);
1154  fprintf(stderr, "while trying to create NCDF variable, \"%s\", ", sname);
1155  return (PROGRAMMER_BOOBOO);
1156  }
1157  }
1158 
1159  /* Add a "reference" attribute */
1160  if (reference != NULL && strcmp(reference, "") != 0) {
1161  status = nc_put_att_text(nc_id, var_id, "reference",
1162  strlen(reference), reference);
1163  if (status != NC_NOERR) {
1164  printf("-E- %s %d: %s for %s\n",
1165  __FILE__, __LINE__, nc_strerror(status), "reference");
1166  exit(1);
1167  }
1168  }
1169 
1170  /* Add a "comment" attribute */
1171  if (comment != NULL && strcmp(comment, "") != 0) {
1172  status = nc_put_att_text(nc_id, var_id, "comment",
1173  strlen(comment), comment);
1174  if (status != NC_NOERR) {
1175  printf("-E- %s %d: %s for %s\n",
1176  __FILE__, __LINE__, nc_strerror(status), "comment");
1177  exit(1);
1178  }
1179  }
1180 
1181  return (LIFE_IS_GOOD);
1182 }
int SetI32GA(idDS ds_id, const char *name, int32_t value)
Definition: wrapper.c:323
int CreateSDS(int32_t sd_id, const char *sname, const char *lname, const char *standard_name, const char *units, double low, double high, float slope, float offset, int32_t nt, int32_t rank, int32_t d0, int32_t d1, int32_t d2, const char *dn0, const char *dn1, const char *dn2)
Definition: hdf_utils.c:77
@ DS_READ
Definition: dfutils.h:24
integer, parameter int16
Definition: cubeio.f90:3
int32 value
Definition: Granule.c:1235
int endaccessDS(idDS ds_id)
Definition: wrapper.c:617
int status
Definition: l1_czcs_hdf.c:32
int getDimsDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t dims[H4_MAX_VAR_DIMS])
Definition: wrapper.c:636
#define PRODUCT_DEFAULT_validMax
Definition: productInfo.h:35
int getTypeDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t *dtype)
Definition: wrapper.c:671
void nc_init_compress(int32_t nc_id, int32_t var_id, int32_t *dimids, int32_t rank, size_t *chunksize, int deflate_level)
#define NULL
Definition: decode_rs.h:63
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
int createDS2(idDS ds_id, const char *sname, productInfo_t *p_info, int32_t dm[3], const char dm_name[3][80])
Definition: wrapper.c:357
int sd_readdata(int32_t sd_id, const char *name, void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
int fileInfo(idDS ds_id, int32_t *n_datasets, int32_t *n_globalattr)
Definition: wrapper.c:695
int32_t deflate
Definition: dfutils.h:32
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
char * readAttrStr(idDS ds_id, const char *name)
Definition: wrapper.c:99
ds_format_t fftype
Definition: dfutils.h:31
ds_access_t
Definition: dfutils.h:23
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
int32_t filesize(const char *filename)
Definition: filesize.c:8
int sd_setattr(int32_t id, const char *nam, int32_t typ, int32_t cnt, const void *data)
Definition: hdf_utils.c:216
int32_t prodlist(int32_t sensorID, int32_t evalmask, const char *inprod, const char *defprod, char outprod[L1_MAXPROD][32])
int getDims(int32_t fileID, const char sdsname[], int32_t dims[])
int s2u(const char *in, char *out)
Definition: wrapper.c:33
list(APPEND LIBS ${NETCDF_LIBRARIES}) find_package(GSL REQUIRED) include_directories($
Definition: CMakeLists.txt:8
int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3], const char dm_name[3][80])
Definition: wrapper.c:341
productInfo_t * allocateProductInfo()
char * strdup(const char *)
int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void *data)
Definition: wrapper.c:216
int getHDFattr(int32_t fileID, const char attrname[], const char sdsname[], void *data)
int endDS(idDS ds_id)
Definition: wrapper.c:624
int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count)
Definition: wrapper.c:188
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
integer, parameter double
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
int get_type(int32_t fileID, const char sdsname[], int32_t *dtype)
int8_t findAttr(idDS ds_id, const char *nam)
Definition: wrapper.c:46
int writeDS(idDS ds_id, const char *name, const void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
Definition: wrapper.c:472
@ DS_NCDF
Definition: dfutils.h:20
#define PTB(function)
Definition: passthebuck.h:16
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int getProdlist(const char *fname, char **prodlist, int32_t *l2_flags_type)
Definition: wrapper.c:711
idDS startDS(const char *filename, ds_format_t format, ds_access_t access, int32_t deflate)
Definition: wrapper.c:558
int32_t sid
Definition: dfutils.h:30
int SetChrGA(idDS ds_id, const char *name, const char *value)
Definition: wrapper.c:233
int SetF32GA(idDS ds_id, const char *name, float32 value)
Definition: wrapper.c:269
int findProductInfo(const char *productName, int sensorId, productInfo_t *info)
#define ROUND(x)
Definition: wrapper.c:31
int readDS(idDS ds_id, const char *name, int32_t *start, int32_t *stride, int32_t *count, VOIDP data)
Definition: wrapper.c:511
dtype
Definition: DDataset.hpp:31
int32_t fid
Definition: dfutils.h:29
Extra metadata that will be written to the HDF4 file l2prod rank
#define PRODUCT_DEFAULT_validMin
Definition: productInfo.h:34
int32 checkDS(idDS ds_id, const char *l2_prod_name)
Definition: wrapper.c:452
@ DS_HDF
Definition: dfutils.h:19
Definition: dfutils.h:28
int sd_writedata(int32_t sd_id, const char *name, const void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
Definition: hdf_utils.c:293
int CreateNCDF(idDS ds_id, const char *sname, const char *lname, const char *standard_name, const char *reference, const char *comment, const char *units, double low, double high, float scale_factor, float add_offset, int32_t fillValue, int32_t nt, int32_t rank, int32_t dimids[3])
Definition: wrapper.c:838
void nc_init_chunk_cache()
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
ds_format_t
Definition: dfutils.h:18
idDS openDS(const char *filename)
Definition: wrapper.c:606
int32_t selectDS(idDS ds_id, const char *l2_prod_name)
Definition: wrapper.c:435
int SetI16GA(idDS ds_id, const char *name, int16 value)
Definition: wrapper.c:287
These two strings are used for the product XML output If product_id is not set then prefix is used If the last char of the name_prefix is _ then it is removed If algorithm_id is not set then name_suffix is used If the first char is _ then it is removed l2prod standard_name[0]
int SetI8GA(idDS ds_id, const char *name, uint8 value)
Definition: wrapper.c:305
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int readAttr(idDS ds_id, const char *nam, VOIDP data)
Definition: wrapper.c:72
int SetF64GA(idDS ds_id, const char *name, float64 value)
Definition: wrapper.c:251
#define PROGRAMMER_BOOBOO
Definition: passthebuck.h:8
int count
Definition: decode_rs.h:79