OB.DAAC Logo
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 
26 #include <hdf.h>
27 #include <mfhdf.h>
28 
29 
30 #define NEW_CACHE_SIZE 16000000
31 #define NEW_CACHE_NELEMS 2003
32 #define NEW_CACHE_PREEMPTION .75
33 
34 #define ROUND(x) ((((x) >= 0)?0.5:-0.5) + (x))
35 
36 int s2u(const char *in, char *out) {
37  int i;
38  int l = strlen(in);
39  for (i = 0; i < l; i++) {
40  if (in[i] == ' ')
41  out[i] = '_';
42  else
43  out[i] = in[i];
44  }
45  out[l] = 0;
46  return 0;
47 }
48 
49 int8_t findAttr(idDS ds_id, const char *nam) {
50  int32_t attr_index = -1;
51  if (ds_id.fftype == DS_HDF) {
52  if (ds_id.fid > 0) {
53  attr_index = SDfindattr(ds_id.fid, nam);
54  } else {
55  attr_index = SDfindattr(ds_id.sid, nam);
56  }
57 
58  } else if (ds_id.fftype == DS_NCDF) {
59  int status;
60  if (ds_id.fid > 0) {
61  status = nc_inq_attid(ds_id.fid, NC_GLOBAL, nam, (int32_t *) & attr_index);
62  } else {
63  status = nc_inq_attid(-ds_id.fid, ds_id.sid, nam, (int32_t *) & attr_index);
64  }
65  if (status != NC_NOERR) {
66  attr_index = -1;
67  }
68  } else {
69  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
70  exit(1);
71  }
72  return attr_index;
73 }
74 
75 int readAttr(idDS ds_id, const char *nam, VOIDP data) {
76  int status;
77  if (ds_id.fftype == DS_HDF) {
78  if (ds_id.fid > 0)
79  status = getHDFattr(ds_id.fid, nam, "", data);
80  else
81  status = getHDFattr(ds_id.sid, nam, "", data);
82  } else if (ds_id.fftype == DS_NCDF) {
83  if (ds_id.fid > 0) {
84  status = nc_get_att(ds_id.fid, NC_GLOBAL, nam, data);
85  } else {
86  status = nc_get_att(-ds_id.fid, ds_id.sid, nam, data);
87  }
88  } else {
89  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
90  exit(EXIT_FAILURE);
91  }
92  return status;
93 }
94 
102 char* readAttrStr(idDS ds_id, const char *name) {
103  char* data;
104  int status = 0;
105  char buf[128];
106 
107  if (ds_id.fftype == DS_HDF) {
108  int32_t dtype;
109  int32_t count;
110  if (ds_id.fid > 0) {
111  status = SDattrinfo(ds_id.fid, SDfindattr(ds_id.fid, name), buf, &dtype, &count);
112  if (status)
113  return NULL;
114  if (dtype != DFNT_CHAR)
115  return NULL;
116  data = (char*) malloc(count + 1);
117  if (!data)
118  goto memoryError;
119  status = getHDFattr(ds_id.fid, name, "", data);
120  data[count] = 0; // NULL terminate the string
121  } else {
122  status = SDattrinfo(ds_id.sid, SDfindattr(ds_id.sid, name), buf, &dtype, &count);
123  if (status)
124  return NULL;
125  if (dtype != DFNT_CHAR)
126  return NULL;
127  data = (char*) malloc(count + 1);
128  if (!data)
129  goto memoryError;
130  status = getHDFattr(ds_id.sid, name, "", data);
131  data[count] = 0; // NULL terminate the string
132  }
133  } else if (ds_id.fftype == DS_NCDF) {
134  int32_t dtype;
135  size_t count;
136  if (ds_id.fid > 0) {
137  status = nc_inq_att(ds_id.fid, NC_GLOBAL, name, &dtype, &count);
138  if (status != NC_NOERR)
139  return NULL;
140  if(dtype == NC_CHAR) {
141  data = (char*) malloc(count + 1);
142  if (!data)
143  goto memoryError;
144  status = nc_get_att(ds_id.fid, NC_GLOBAL, name, data);
145  data[count] = 0; // NULL terminate the string
146  } else if(dtype == NC_STRING) {
147  if(count < 1)
148  return NULL;
149  char *list[count];
150  status = nc_get_att(ds_id.fid, NC_GLOBAL, name, list);
151  data = strdup(list[0]);
152  nc_free_string(count, list);
153  } else
154  return NULL;
155  } else {
156  status = nc_inq_att(-ds_id.fid, ds_id.sid, name, &dtype, &count);
157  if (status != NC_NOERR)
158  return NULL;
159  if (dtype != NC_STRING && dtype != NC_CHAR)
160  return NULL;
161  data = (char*) malloc(count + 1);
162  if (!data)
163  goto memoryError;
164  status = nc_get_att(-ds_id.fid, ds_id.sid, name, data);
165  data[count] = 0; // NULL terminate the string
166  }
167  } else {
168  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
169  exit(1);
170  }
171  if (status) {
172  free(data);
173  return NULL;
174  }
175  return data;
176 
177 memoryError:
178  printf("-E- %s %d Could not allocate memory for reading attribute %s\n", __FILE__, __LINE__, name);
179  exit(1);
180 }
181 
191 int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count) {
192  int32_t attr_index;
193  int status;
194  char buf[128];
195  if (ds_id.fftype == DS_HDF) {
196  if (ds_id.fid > 0) {
197  attr_index = SDfindattr(ds_id.fid, nam);
198  status = SDattrinfo(ds_id.fid, attr_index, buf, dtype, count);
199  } else {
200  attr_index = SDfindattr(ds_id.sid, nam);
201  status = SDattrinfo(ds_id.sid, attr_index, buf, dtype, count);
202  }
203  } else if (ds_id.fftype == DS_NCDF) {
204  size_t cnt;
205  if (ds_id.fid > 0) {
206  status = nc_inq_att(ds_id.fid, NC_GLOBAL, nam, (int32_t *) dtype, &cnt);
207  *count = cnt;
208  } else {
209  status = nc_inq_att(-ds_id.fid, ds_id.sid, nam, (int32_t *) dtype, &cnt);
210  *count = cnt;
211  }
212  } else {
213  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
214  exit(1);
215  }
216  return status;
217 }
218 
219 int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void* data) {
220  int status;
221  if (ds_id.fftype == DS_HDF) {
222  status = sd_setattr(ds_id.sid, (char*) nam, typ, cnt, (VOIDP) data);
223  } else if (ds_id.fftype == DS_NCDF) {
224  status = nc_put_att(ds_id.fid, ds_id.sid, nam, typ, cnt, data);
225  if (status != NC_NOERR) {
226  printf("-E- %s %d: %s for %s\n",
227  __FILE__, __LINE__, nc_strerror(status), nam);
228  }
229  } else {
230  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
231  exit(1);
232  }
233  return status;
234 }
235 
236 int SetChrGA(idDS ds_id, const char *name, const char *value) {
237  int status;
238  if (ds_id.fftype == DS_HDF) {
239  status = sd_setattr(ds_id.fid, name, DFNT_CHAR, strlen(value) + 1, value);
240  } else if (ds_id.fftype == DS_NCDF) {
241  status = nc_put_att_text(ds_id.fid, NC_GLOBAL, name,
242  strlen(value) + 1, value);
243  if (status != NC_NOERR) {
244  printf("-E- %s %d: %s for %s\n",
245  __FILE__, __LINE__, nc_strerror(status), name);
246  }
247  } else {
248  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
249  exit(1);
250  }
251  return (status);
252 }
253 
254 int SetF64GA(idDS ds_id, const char *name, float64 value) {
255  int status;
256  if (ds_id.fftype == DS_HDF) {
257  status = sd_setattr(ds_id.fid, name, DFNT_FLOAT64, 1, (VOIDP) & value);
258  } else if (ds_id.fftype == DS_NCDF) {
259  status = nc_put_att_double(ds_id.fid, NC_GLOBAL, name,
260  NC_DOUBLE, 1, (const double *) &value);
261  if (status != NC_NOERR) {
262  printf("-E- %s %d: %s for %s\n",
263  __FILE__, __LINE__, nc_strerror(status), name);
264  }
265  } else {
266  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
267  exit(1);
268  }
269  return (status);
270 }
271 
272 int SetF32GA(idDS ds_id, const char *name, float32 value) {
273  int status;
274  if (ds_id.fftype == DS_HDF) {
275  status = sd_setattr(ds_id.fid, name, DFNT_FLOAT32, 1, (VOIDP) & value);
276  } else if (ds_id.fftype == DS_NCDF) {
277  status = nc_put_att_float(ds_id.fid, NC_GLOBAL, name,
278  NC_FLOAT, 1, (const float *) &value);
279  if (status != NC_NOERR) {
280  printf("-E- %s %d: %s for %s\n",
281  __FILE__, __LINE__, nc_strerror(status), name);
282  }
283  } else {
284  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
285  exit(1);
286  }
287  return (status);
288 }
289 
290 int SetI16GA(idDS ds_id, const char *name, int16 value) {
291  int status;
292  if (ds_id.fftype == DS_HDF) {
293  status = sd_setattr(ds_id.fid, name, DFNT_INT16, 1, (VOIDP) & value);
294  } else if (ds_id.fftype == DS_NCDF) {
295  status = nc_put_att_short(ds_id.fid, NC_GLOBAL, name,
296  NC_SHORT, 1, (const short *) &value);
297  if (status != NC_NOERR) {
298  printf("-E- %s %d: %s for %s\n",
299  __FILE__, __LINE__, nc_strerror(status), name);
300  }
301  } else {
302  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
303  exit(1);
304  }
305  return (status);
306 }
307 
308 int SetI8GA(idDS ds_id, const char *name, uint8 value) {
309  int status;
310  if (ds_id.fftype == DS_HDF) {
311  status = sd_setattr(ds_id.fid, name, DFNT_UINT8, 1, (VOIDP) & value);
312  } else if (ds_id.fftype == DS_NCDF) {
313  status = nc_put_att_uchar(ds_id.fid, NC_GLOBAL, name,
314  NC_BYTE, 1, (const uint8 *) &value);
315  if (status != NC_NOERR) {
316  printf("-E- %s %d: %s for %s\n",
317  __FILE__, __LINE__, nc_strerror(status), name);
318  }
319  } else {
320  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
321  exit(1);
322  }
323  return (status);
324 }
325 
326 int SetI32GA(idDS ds_id, const char *name, int32_t value) {
327  int status;
328  if (ds_id.fftype == DS_HDF) {
329  status = sd_setattr(ds_id.fid, name, DFNT_INT32, 1, (VOIDP) & value);
330  } else if (ds_id.fftype == DS_NCDF) {
331  status = nc_put_att_int(ds_id.fid, NC_GLOBAL, name,
332  NC_INT, 1, (const int *) &value);
333  if (status != NC_NOERR) {
334  printf("-E- %s %d: %s for %s\n",
335  __FILE__, __LINE__, nc_strerror(status), name);
336  }
337  } else {
338  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
339  exit(1);
340  }
341  return (status);
342 }
343 
344 int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3],
345  const char dm_name[3][80]) {
346  static productInfo_t* p_info;
347 
348  if (p_info == NULL) {
349  p_info = allocateProductInfo();
350  }
351 
352  if (findProductInfo(sname, sensorId, p_info)) {
353  return createDS2(ds_id, sname, p_info, dm, dm_name);
354  } else {
355  printf("%s not found in XML product table\n", sname);
356  exit(1);
357  }
358 }
359 
360 int createDS2(idDS ds_id, const char *sname, productInfo_t* p_info, int32_t dm[3],
361  const char dm_name[3][80]) {
362  int i, status;
363  int32_t nt; /* data type */
364 
365  if (ds_id.fftype == DS_HDF) {
366 
367  if (strcmp(p_info->dataType, "byte") == 0)
368  nt = DFNT_INT8;
369  else if (strcmp(p_info->dataType, "ubyte") == 0)
370  nt = DFNT_UINT8;
371  else if (strcmp(p_info->dataType, "short") == 0)
372  nt = DFNT_INT16;
373  else if (strcmp(p_info->dataType, "ushort") == 0)
374  nt = DFNT_UINT16;
375  else if (strcmp(p_info->dataType, "int") == 0)
376  nt = DFNT_INT32;
377  else if (strcmp(p_info->dataType, "uint") == 0)
378  nt = DFNT_UINT32;
379  else if (strcmp(p_info->dataType, "float") == 0)
380  nt = DFNT_FLOAT32;
381  else if (strcmp(p_info->dataType, "double") == 0)
382  nt = DFNT_FLOAT64;
383  else {
384  printf("-E- %s %d: datatype %s is not valid\n", __FILE__, __LINE__, p_info->dataType);
385  exit(1);
386  }
387 
388  status = CreateSDS(ds_id.fid, sname, p_info->description, p_info->standardName,
389  p_info->units, p_info->validMin, p_info->validMax, p_info->scaleFactor,
390  p_info->addOffset, nt, p_info->rank, dm[0], dm[1], dm[2],
391  dm_name[0], dm_name[1], dm_name[2]);
392 
393  } else if (ds_id.fftype == DS_NCDF) {
394  int32_t dimids[3];
395  char buf[512];
396  for (i = 0; i < p_info->rank; i++) {
397  s2u(dm_name[i], buf);
398  status = nc_inq_dimid(ds_id.fid, buf, &dimids[i]);
399  if (status != NC_NOERR) {
400  printf("-E- %s %d: %s for %s\n",
401  __FILE__, __LINE__, nc_strerror(status), dm_name[i]);
402  exit(1);
403  }
404  }
405 
406  if (strcmp(p_info->dataType, "byte") == 0)
407  nt = NC_BYTE;
408  else if (strcmp(p_info->dataType, "ubyte") == 0)
409  nt = NC_UBYTE;
410  else if (strcmp(p_info->dataType, "short") == 0)
411  nt = NC_SHORT;
412  else if (strcmp(p_info->dataType, "ushort") == 0)
413  nt = NC_USHORT;
414  else if (strcmp(p_info->dataType, "int") == 0)
415  nt = NC_INT;
416  else if (strcmp(p_info->dataType, "uint") == 0)
417  nt = NC_UINT;
418  else if (strcmp(p_info->dataType, "float") == 0)
419  nt = NC_FLOAT;
420  else if (strcmp(p_info->dataType, "double") == 0)
421  nt = NC_DOUBLE;
422  else {
423  printf("-E- %s %d datatype %s not defined\n", __FILE__, __LINE__, p_info->dataType);
424  exit(1);
425  }
426 
427  status = CreateNCDF(ds_id, sname, p_info->description, p_info->standardName,
428  p_info->reference, p_info->comment, p_info->units, p_info->validMin,
429  p_info->validMax, p_info->scaleFactor, p_info->addOffset,
430  p_info->fillValue, nt, p_info->rank, dimids);
431  } else {
432  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
433  exit(1);
434  }
435  return status;
436 }
437 
438 int32_t selectDS(idDS ds_id, const char *l2_prod_name) {
439  int32_t outid;
440  if (ds_id.fftype == DS_HDF) {
441  outid = SDselect(ds_id.fid, SDnametoindex(ds_id.fid, l2_prod_name));
442  } else if (ds_id.fftype == DS_NCDF) {
443  int status;
444  status = nc_inq_varid(ds_id.fid, l2_prod_name, (int32_t *) & outid);
445  if (status != NC_NOERR) {
446  outid = -1;
447  }
448  } else {
449  printf("-E- %s %d fftype %d not defined\n", __FILE__, __LINE__, ds_id.fftype);
450  exit(1);
451  }
452  return outid;
453 }
454 
455 int32 checkDS(idDS ds_id, const char *l2_prod_name) {
456  int32 outid;
457  if (ds_id.fftype == DS_HDF) {
458  outid = SDselect(ds_id.fid, SDnametoindex(ds_id.fid, l2_prod_name));
459  if (outid != -1) {
460  SDendaccess(outid);
461  }
462  } else if (ds_id.fftype == DS_NCDF) {
463  int status;
464  status = nc_inq_varid(ds_id.fid, l2_prod_name, (int32_t *) & outid);
465  if (status != NC_NOERR) {
466  outid = -1;
467  }
468  } else {
469  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
470  exit(1);
471  }
472  return outid;
473 }
474 
476  idDS ds_id,
477  const char *name,
478  const void* data,
479  int32_t s0,
480  int32_t s1,
481  int32_t s2,
482  int32_t e0,
483  int32_t e1,
484  int32_t e2) {
485 
486  idDS ds_id0 = ds_id;
487 
488  if (ds_id0.fftype == DS_HDF) {
489  PTB(sd_writedata(ds_id0.fid, name, data, s0, s1, s2, e0, e1, e2));
490  } else if (ds_id0.fftype == DS_NCDF) {
491  int status = NC_NOERR;
492  size_t startp[3] = {s0, s1, s2};
493  size_t countp[3] = {e0, e1, e2};
494  status = nc_inq_varid(ds_id0.fid, name, (int32_t *) & ds_id0.sid);
495  if (status != NC_NOERR) {
496  printf("-E- %s %d: %s for %s\n",
497  __FILE__, __LINE__, nc_strerror(status), name);
498  exit(1);
499  }
500  status = nc_put_vara(ds_id0.fid, ds_id0.sid, startp, countp, data);
501  if (status != NC_NOERR) {
502  printf("-E- %s %d: %s for %s\n",
503  __FILE__, __LINE__, nc_strerror(status), name);
504  exit(1);
505  }
506 
507  } else {
508  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
509  exit(1);
510  }
511  return 0;
512 }
513 
514 int readDS(
515  idDS ds_id,
516  const char *name,
517  int32_t *start,
518  int32_t *stride,
519  int32_t *count,
520  VOIDP data) {
521 
522  idDS ds_id0 = ds_id;
523  int32_t s0 = start[0], s1 = start[1], s2 = start[2];
524  int32_t e0 = count[0], e1 = count[1], e2 = count[2];
525 
526  if (ds_id0.fftype == DS_HDF) {
527  PTB(sd_readdata(ds_id0.fid, name, data, s0, s1, s2, e0, e1, e2));
528  } else if (ds_id0.fftype == DS_NCDF) {
529  int status = NC_NOERR;
530  size_t startp[3] = {start[0], start[1], start[2]};
531  size_t countp[3] = {count[0], count[1], count[2]};
532  status = nc_inq_varid(ds_id0.fid, name, (int32_t *) & ds_id0.sid);
533  if (status != NC_NOERR) {
534  printf("-E- %s %d: %s for %s\n",
535  __FILE__, __LINE__, nc_strerror(status), name);
536  return status;
537  }
538  status = nc_get_vara(ds_id0.fid, ds_id0.sid, startp, countp, data);
539  if (status != NC_NOERR) {
540  printf("-E- %s %d: %s for %s\n",
541  __FILE__, __LINE__, nc_strerror(status), name);
542  return status;
543  }
544  } else {
545  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
546  exit(1);
547  }
548  return 0;
549 }
550 
561 idDS startDS(const char *filename, ds_format_t format, ds_access_t access,
562  int32_t deflate) {
563  idDS ds_id;
564  ds_id.fftype = format;
565  ds_id.deflate = deflate;
566 
567  if (format == DS_HDF) {
568  int32_t hdfAccess;
569  if (access == DS_READ)
570  hdfAccess = DFACC_RDONLY;
571  else
572  hdfAccess = DFACC_CREATE;
573  ds_id.fid = SDstart(filename, hdfAccess);
574  if (ds_id.fid == -1) {
575  fprintf(stderr, "-E- %s line %d: SDstart failure, %s .\n",
576  __FILE__, __LINE__, filename);
577  }
578  } else if (format == DS_NCDF) {
579  int status;
580 
581  if (access == DS_READ) {
582  status = nc_open(filename, NC_NOWRITE, &ds_id.fid);
583  if (status != NC_NOERR) {
584  ds_id.fid = -1;
585  }
586  } else {
587  /* Change chunk cache. */
589  if (status != NC_NOERR) {
590  fprintf(stderr,
591  "-E- %s line %d: Could not set NCDF4 cache size for file, %s .\n",
592  __FILE__, __LINE__, filename);
593  }
594  status = nc_create(filename, NC_NETCDF4, &ds_id.fid);
595  if (status != NC_NOERR) {
596  fprintf(stderr,
597  "-E- %s line %d: Could not create NCDF4 file, %s .\n",
598  __FILE__, __LINE__, filename);
599  ds_id.fid = -1;
600  }
601  }
602  } else {
603  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
604  exit(1);
605  }
606  return ds_id;
607 }
608 
609 /*
610  * open a data file for reading. This routine figures out if the
611  * file is HDF4 or netCDF4. Must use endDS() to close the file.
612  *
613  * @param filename path to file
614  * @return a data set structure. ds_id.fid = -1 if there was a problem.
615  */
616 idDS openDS(const char *filename) {
617  ds_format_t fileformat;
618 
619  if (Hishdf(filename)) {
620  fileformat = DS_HDF;
621  } else {
622  fileformat = DS_NCDF;
623  }
624  return startDS(filename, fileformat, DS_READ, 0);
625 }
626 
627 int endaccessDS(idDS ds_id) {
628  if (ds_id.fftype == DS_HDF) {
629  PTB(SDendaccess(ds_id.sid));
630  }
631  return 0;
632 }
633 
634 int endDS(idDS ds_id) {
635  if (ds_id.fftype == DS_HDF) {
636  return SDend(ds_id.fid);
637  } else if (ds_id.fftype == DS_NCDF) {
638  return nc_close(ds_id.fid);
639  } else {
640  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
641  exit(1);
642  }
643  return 0;
644 }
645 
646 int getDimsDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME],
647  int32_t dims[H4_MAX_VAR_DIMS]) {
648 
649  int status;
650  if (ds_id.fftype == DS_HDF) {
651  status = getDims(ds_id.fid, sdsname, dims);
652  } else if (ds_id.fftype == DS_NCDF) {
653  int32_t varid;
654  status = nc_inq_varid(ds_id.fid, sdsname, &varid);
655  if (status != NC_NOERR) {
656  printf("-E- %s %d: %s for %s\n",
657  __FILE__, __LINE__, nc_strerror(status), sdsname);
658  } else {
659  int ndims;
660  int dimids[H4_MAX_VAR_DIMS];
661  status = nc_inq_var(ds_id.fid, varid, NULL, NULL, &ndims, dimids, NULL);
662  if (status != NC_NOERR) {
663  printf("-E- %s %d: %s for %s\n",
664  __FILE__, __LINE__, nc_strerror(status), sdsname);
665  } else {
666  int i;
667  size_t dim;
668  for (i = 0; i < ndims; i++) {
669  status = nc_inq_dimlen(ds_id.fid, dimids[i], &dim);
670  dims[i] = dim;
671  }
672  }
673  }
674  } else {
675  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
676  exit(1);
677  }
678  return status;
679 }
680 
681 int getTypeDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t *dtype) {
682  int status;
683  if (ds_id.fftype == DS_HDF) {
684  status = get_type(ds_id.fid, sdsname, dtype);
685  } else if (ds_id.fftype == DS_NCDF) {
686  int32_t varid;
687  status = nc_inq_varid(ds_id.fid, sdsname, &varid);
688  if (status != NC_NOERR) {
689  printf("-E- %s %d: %s for %s\n",
690  __FILE__, __LINE__, nc_strerror(status), sdsname);
691  } else {
692  status = nc_inq_vartype(ds_id.fid, varid, dtype);
693  if (status != NC_NOERR) {
694  printf("-E- %s %d: %s for %s\n",
695  __FILE__, __LINE__, nc_strerror(status), sdsname);
696  }
697  }
698  } else {
699  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
700  exit(1);
701  }
702  return status;
703 }
704 
705 int fileInfo(idDS ds_id, int32_t *n_datasets, int32_t *n_globalattr) {
706  int status;
707  if (ds_id.fftype == DS_HDF) {
708  status = SDfileinfo(ds_id.fid, n_datasets, n_globalattr);
709  } else if (ds_id.fftype == DS_NCDF) {
710  status = nc_inq(ds_id.fid, NULL, n_datasets, n_globalattr, NULL);
711  if (status != NC_NOERR) {
712  printf("-E- %s %d: %s\n", __FILE__, __LINE__, nc_strerror(status));
713  }
714  } else {
715  printf("-E- %s %d fftype not defined\n", __FILE__, __LINE__);
716  exit(1);
717  }
718  return status;
719 }
720 
721 int getProdlist(const char *fname, char **prodlist, int32_t *l2_flags_type) {
722 
723  size_t i;
724  char buffer[2048 * 8];
725  int32_t listlen = 0;
726  char *cptr;
727 
728  if (filesize(fname) == -1) {
729  printf("-E- File %s does not exist\n", fname);
730  exit(1);
731  }
732 
733  if (Hishdf(fname) == 1) {
734 
735  int32_t HDFfid;
736  int32_t vg_ref;
737  int32_t vgid;
738  int32_t tag;
739  int32_t ref;
740  int32_t sd_id;
741  int32_t sds_id;
742  int32_t dims[8];
743  int32_t rank;
744  int32_t dtype;
745  int32_t nattrs;
746 
747  HDFfid = Hopen(fname, DFACC_READ, 0);
748 
749  if (HDFfid == -1) {
750  printf("\n%s not found or is corrupt.\n", fname);
751  exit(1);
752  }
753 
754  sd_id = SDstart(fname, DFACC_RDONLY);
755  if (sd_id == -1) {
756  printf("Error opening (SDstart) %s\n", fname);
757  exit(-1);
758  }
759 
760  Vstart(HDFfid);
761  vg_ref = Vfind(HDFfid, "Geophysical Data");
762  vgid = Vattach(HDFfid, vg_ref, "r");
763 
764  for (i = 0; i < Vntagrefs(vgid); i++) {
765  Vgettagref(vgid, i, &tag, &ref);
766  sds_id = SDselect(sd_id, SDreftoindex(sd_id, ref));
767  if (sds_id == -1) {
768  printf("Error accessing SDS (reference #: %d) in: %s .\n", ref,
769  fname);
770  exit(-1);
771  }
772  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
773  if (strcmp(buffer, "l2_flags") != 0) {
774  listlen += strlen(buffer) + 1;
775  }
776  SDendaccess(sds_id);
777  }
778 
779  *prodlist = (char *) calloc(listlen + 1, sizeof (char));
780  cptr = *prodlist;
781 
782  for (i = 0; i < Vntagrefs(vgid); i++) {
783  Vgettagref(vgid, i, &tag, &ref);
784  sds_id = SDselect(sd_id, SDreftoindex(sd_id, ref));
785  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
786  if (strcmp(buffer, "l2_flags") != 0) {
787  if (i == 0)
788  strcpy(*prodlist, buffer);
789  else
790  strcat(*prodlist, buffer);
791  strcat(*prodlist, ":");
792  } else {
793  *l2_flags_type = dtype;
794  }
795  SDendaccess(sds_id);
796  }
797  cptr[listlen - 1] = 0;
798 
799  SDend(sd_id);
800  Vdetach(vgid);
801  Vend(HDFfid);
802 
803  Hclose(HDFfid);
804 
805  } else {
806 
807  int ncid, grp_ncid, nvars;
808  if (nc_open(fname, NC_NOWRITE, &ncid) == NC_NOERR) {
809  nc_inq_ncid(ncid, "geophysical_data", &grp_ncid);
810  nc_inq(grp_ncid, NULL, &nvars, NULL, NULL);
811  for (i = 0; i < nvars; i++) {
812  nc_inq_varname(grp_ncid, i, buffer);
813  if (strcmp(buffer, "l2_flags") != 0) {
814  listlen += strlen(buffer) + 1;
815  }
816  }
817 
818  *prodlist = (char *) calloc(listlen + 1, sizeof (char));
819  cptr = *prodlist;
820 
821  for (i = 0; i < nvars; i++) {
822  nc_inq_varname(grp_ncid, i, buffer);
823  if (strcmp(buffer, "l2_flags") != 0) {
824  if (i == 0)
825  strcpy(*prodlist, buffer);
826  else
827  strcat(*prodlist, buffer);
828  strcat(*prodlist, ":");
829  } else {
830  nc_inq_vartype(grp_ncid, i, l2_flags_type);
831  }
832  }
833  } else {
834  printf("-E- Can not open NetCDF file %s\n", fname);
835  exit(EXIT_FAILURE);
836  }
837  cptr[listlen - 1] = 0;
838  nc_close(ncid);
839  }
840 
841  return 0;
842 }
843 
844 /* -------------------------------------------------------------------- */
845 /* Create an NCDF variable using the wrappers for the NCDF routines */
846 
847 /* -------------------------------------------------------------------- */
849  idDS ds_id,
850  const char *sname, /* short name */
851  const char *lname, /* long name */
852  const char *standard_name, /* NetCDF standard name (not set if passed NULL or "") */
853  const char *reference,
854  const char *comment,
855  const char *units, /* units (not set if passed NULL or "") */
856  double low, /* low end of valid range */
857  double high, /* high end of range (no range set if low >= high) */
858  float scale_factor, /* scale factor (not set if 1.0) */
859  float add_offset, /* scaling offset (not set if 0.0) */
860  int32_t fillValue, /* fill value */
861  int32_t nt, /* NCDF number type */
862  int32_t rank, /* number of dimensions (must be <= 3) */
863  int32_t dimids[3]/* dimension ids */
864  ) {
865 
866  int32_t nc_id = ds_id.fid;
867  int32_t var_id;
868  int i;
869  int status;
870  size_t chunksize[3] = {0, 0, 0};
871  char *validnames[2] = {"valid_min", "valid_max"};
872 
873  /* Create the NCDF dataset */
874  status = nc_def_var(nc_id, sname, nt, rank, dimids, &var_id);
875  if (status != NC_NOERR) {
876  printf("-E- %s %d: %s for %s\n",
877  __FILE__, __LINE__, nc_strerror(status), sname);
878  exit(1);
879  }
880  if (ds_id.deflate > 0)
881  nc_init_compress(nc_id, var_id, dimids, rank, chunksize, (int) ds_id.deflate);
882 
883  /* Add a "long_name" attribute */
884  status = nc_put_att_text(nc_id, var_id, "long_name", strlen(lname), lname);
885  if (status != NC_NOERR) {
886  printf("-E- %s %d: %s for %s\n",
887  __FILE__, __LINE__, nc_strerror(status), "long_name");
888  exit(1);
889  }
890 
891  /* Add a "scale_factor" attribute and an "add_offset" attribute */
892  if (nt != NC_FLOAT && nt != NC_DOUBLE) {
893  if (scale_factor != 1.0 || add_offset != 0.0) {
894  status = nc_put_att_float(nc_id, var_id, "scale_factor", NC_FLOAT, 1, &scale_factor);
895  if (status != NC_NOERR) {
896  printf("-E- %s %d: %s for %s\n",
897  __FILE__, __LINE__, nc_strerror(status), "scale_factor");
898  exit(1);
899  }
900  status = nc_put_att_float(nc_id, var_id, "add_offset", NC_FLOAT, 1, &add_offset);
901  if (status != NC_NOERR) {
902  printf("-E- %s %d: %s for %s\n",
903  __FILE__, __LINE__, nc_strerror(status), "add_offset");
904  exit(1);
905  }
906  }
907  }
908 
909  /* Add a "units" attribute if one is specified */
910  if (units != NULL
911  && units[0] != 0
912  && strcasecmp(units, "dimensionless") != 0
913  && strcasecmp(units, "unitless") != 0) {
914  status = nc_put_att_text(nc_id, var_id, "units", strlen(units), units);
915  if (status != NC_NOERR) {
916  printf("-E- %s %d: %s for %s\n",
917  __FILE__, __LINE__, nc_strerror(status), "units");
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  default:
1015  fprintf(stderr, "-E- %s line %d: ", __FILE__, __LINE__);
1016  fprintf(stderr, "Got unsupported fill values number type (%d) ", nt);
1017  fprintf(stderr, "while trying to create NCDF variable, \"%s\", ", sname);
1018  return (PROGRAMMER_BOOBOO);
1019  }
1020 
1021 skip_fill:
1022  /* Add "valid_min" & "valid_max" attributes if low is less than high
1023  * (i.e. they were properly defined in the product.xml)
1024  */
1025  if (low < high) {
1026  switch (nt) { /* Use the appropriate number type */
1027  case NC_BYTE:
1028  {
1029  int8_t vr[2];
1030  vr[0] = (int8_t) ROUND((low - add_offset) / scale_factor);
1031  vr[1] = (int8_t) ROUND((high - add_offset) / scale_factor);
1032  for (i = 0; i < 2; i++) {
1033  status = nc_put_att_schar(nc_id, var_id, validnames[i], NC_BYTE,
1034  1, (const signed char *) &vr[i]);
1035  if (status != NC_NOERR) {
1036  printf("-E- %s %d: %s for %s\n",
1037  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1038  exit(1);
1039  }
1040  }
1041  }
1042  break;
1043  case NC_UBYTE:
1044  {
1045  uint8_t vr[2];
1046  vr[0] = (uint8_t) ROUND((low - add_offset) / scale_factor);
1047  vr[1] = (uint8_t) ROUND((high - add_offset) / scale_factor);
1048  for (i = 0; i < 2; i++) {
1049  status = nc_put_att_uchar(nc_id, var_id, validnames[i], NC_UBYTE,
1050  1, (const unsigned char *) &vr[i]);
1051  if (status != NC_NOERR) {
1052  printf("-E- %s %d: %s for %s\n",
1053  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1054  exit(1);
1055  }
1056  }
1057  }
1058  break;
1059  case NC_SHORT:
1060  {
1061  int16_t vr[2];
1062  vr[0] = (int16_t) ROUND((low - add_offset) / scale_factor);
1063  vr[1] = (int16_t) ROUND((high - add_offset) / scale_factor);
1064  for (i = 0; i < 2; i++) {
1065  status = nc_put_att_short(nc_id, var_id, validnames[i], NC_SHORT,
1066  1, &vr[i]);
1067  if (status != NC_NOERR) {
1068  printf("-E- %s %d: %s for %s\n",
1069  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1070  exit(1);
1071  }
1072  }
1073  }
1074  break;
1075  case NC_USHORT:
1076  {
1077  uint16_t vr[2];
1078  vr[0] = (uint16_t) ROUND((low - add_offset) / scale_factor);
1079  vr[1] = (uint16_t) ROUND((high - add_offset) / scale_factor);
1080  for (i = 0; i < 2; i++) {
1081  status = nc_put_att_ushort(nc_id, var_id, validnames[i], NC_USHORT,
1082  1, &vr[i]);
1083  if (status != NC_NOERR) {
1084  printf("-E- %s %d: %s for %s\n",
1085  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1086  exit(1);
1087  }
1088  }
1089  }
1090  break;
1091  case NC_INT:
1092  {
1093  int32_t vr[2];
1094  vr[0] = (int32_t) ROUND((low - add_offset) / scale_factor);
1095  vr[1] = (int32_t) ROUND((high - add_offset) / scale_factor);
1096  for (i = 0; i < 2; i++) {
1097  status = nc_put_att_int(nc_id, var_id, validnames[i], NC_INT,
1098  1, &vr[i]);
1099  if (status != NC_NOERR) {
1100  printf("-E- %s %d: %s for %s\n",
1101  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1102  exit(1);
1103  }
1104  }
1105  }
1106  break;
1107  case NC_UINT:
1108  {
1109  uint32_t vr[2];
1110  vr[0] = (uint32_t) ROUND((low - add_offset) / scale_factor);
1111  vr[1] = (uint32_t) ROUND((high - add_offset) / scale_factor);
1112  for (i = 0; i < 2; i++) {
1113  status = nc_put_att_uint(nc_id, var_id, validnames[i], NC_UINT,
1114  1, &vr[i]);
1115  if (status != NC_NOERR) {
1116  printf("-E- %s %d: %s for %s\n",
1117  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1118  exit(1);
1119  }
1120  }
1121  }
1122  break;
1123  case NC_FLOAT:
1124  {
1125  float vr[2];
1126  vr[0] = (float) low;
1127  vr[1] = (float) high;
1128  for (i = 0; i < 2; i++) {
1129  status = nc_put_att_float(nc_id, var_id, validnames[i], NC_FLOAT,
1130  1, &vr[i]);
1131  if (status != NC_NOERR) {
1132  printf("-E- %s %d: %s for %s\n",
1133  __FILE__, __LINE__, nc_strerror(status), validnames[i]);
1134  exit(1);
1135  }
1136  }
1137  }
1138  break;
1139  default:
1140  fprintf(stderr, "-E- %s line %d: ", __FILE__, __LINE__);
1141  fprintf(stderr, "Got unsupported number type (%d) ", nt);
1142  fprintf(stderr, "while trying to create NCDF variable, \"%s\", ", sname);
1143  return (PROGRAMMER_BOOBOO);
1144  }
1145  }
1146 
1147  /* Add a "reference" attribute */
1148  if (reference != NULL && strcmp(reference, "") != 0) {
1149  status = nc_put_att_text(nc_id, var_id, "reference",
1150  strlen(reference), reference);
1151  if (status != NC_NOERR) {
1152  printf("-E- %s %d: %s for %s\n",
1153  __FILE__, __LINE__, nc_strerror(status), "reference");
1154  exit(1);
1155  }
1156  }
1157 
1158  /* Add a "comment" attribute */
1159  if (comment != NULL && strcmp(comment, "") != 0) {
1160  status = nc_put_att_text(nc_id, var_id, "comment",
1161  strlen(comment), comment);
1162  if (status != NC_NOERR) {
1163  printf("-E- %s %d: %s for %s\n",
1164  __FILE__, __LINE__, nc_strerror(status), "comment");
1165  exit(1);
1166  }
1167  }
1168 
1169  return (LIFE_IS_GOOD);
1170 }
int SetI32GA(idDS ds_id, const char *name, int32_t value)
Definition: wrapper.c:326
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:627
#define NEW_CACHE_NELEMS
Definition: wrapper.c:31
int status
Definition: l1_czcs_hdf.c:32
list(APPEND LIBS ${PGSTK_LIBRARIES}) add_executable(atteph_info_modis atteph_info_modis.c) target_link_libraries(atteph_info_modis $
Definition: CMakeLists.txt:7
int getDimsDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t dims[H4_MAX_VAR_DIMS])
Definition: wrapper.c:646
int getTypeDS(idDS ds_id, const char sdsname[H4_MAX_NC_NAME], int32_t *dtype)
Definition: wrapper.c:681
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:360
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:705
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:102
ds_format_t fftype
Definition: dfutils.h:31
ds_access_t
Definition: dfutils.h:23
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
#define NEW_CACHE_SIZE
Definition: wrapper.c:30
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:36
int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3], const char dm_name[3][80])
Definition: wrapper.c:344
productInfo_t * allocateProductInfo()
char * strdup(const char *)
#define NEW_CACHE_PREEMPTION
Definition: wrapper.c:32
int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void *data)
Definition: wrapper.c:219
int getHDFattr(int32_t fileID, const char attrname[], const char sdsname[], void *data)
int endDS(idDS ds_id)
Definition: wrapper.c:634
int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count)
Definition: wrapper.c:191
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
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:49
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:475
@ 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:721
idDS startDS(const char *filename, ds_format_t format, ds_access_t access, int32_t deflate)
Definition: wrapper.c:561
int32_t sid
Definition: dfutils.h:30
int SetChrGA(idDS ds_id, const char *name, const char *value)
Definition: wrapper.c:236
int SetF32GA(idDS ds_id, const char *name, float32 value)
Definition: wrapper.c:272
int findProductInfo(const char *productName, int sensorId, productInfo_t *info)
#define ROUND(x)
Definition: wrapper.c:34
int readDS(idDS ds_id, const char *name, int32_t *start, int32_t *stride, int32_t *count, VOIDP data)
Definition: wrapper.c:514
dtype
Definition: DDataset.hpp:31
int32_t fid
Definition: dfutils.h:29
Extra metadata that will be written to the HDF4 file l2prod rank
int32 checkDS(idDS ds_id, const char *l2_prod_name)
Definition: wrapper.c:455
@ 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:848
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:616
int32_t selectDS(idDS ds_id, const char *l2_prod_name)
Definition: wrapper.c:438
int SetI16GA(idDS ds_id, const char *name, int16 value)
Definition: wrapper.c:290
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]
INT32 filesize(const char *filename)
Definition: swl0_utils.c:93
int SetI8GA(idDS ds_id, const char *name, uint8 value)
Definition: wrapper.c:308
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:75
int SetF64GA(idDS ds_id, const char *name, float64 value)
Definition: wrapper.c:254
#define PROGRAMMER_BOOBOO
Definition: passthebuck.h:8
int count
Definition: decode_rs.h:79