Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
fillenv.c
Go to the documentation of this file.
1 /*********************************************************************
2  * fillenv_annot
3  *
4  * fillenv_annot - fills array with DAAC-type annotations read from file
5  *
6  * Contains sscanf format for reading two double-quoted (") strings on
7  * a line.
8  * Author: Brian D. Schieber GSC/SAIC 5/93
9  *********************************************************************/
10 
11 #include <mfhdf.h>
12 #include "ancil.h"
13 #include "ancnrt_proto.h"
14 
16 
17  int cnt;
18  FILE *fp;
19  char s[MAXDESCLEN];
20  char Tlabel[MAXLABLEN];
21  char Ttype[MAXLABLEN];
22  char Tdescr[MAXDESCLEN];
23  struct annotation *tannot;
24 
25  if ((tannot = (struct annotation *)
26  malloc(sizeof (struct annotation) * 100))
27  == NULL) pexit("malloc Annotation");
28 
29  if ((fp = fopen(filename, "r")) == NULL) {
30  printf("Error opening %s\n", filename);
31  exit(1);
32  }
33 
34  cnt = 0;
35  while (fgets(s, 200, fp) != NULL) {
36  if (!strncmp(&s[0], "#", 1)) continue;
37 
38  /* sscanf(&s[1], "%[^'\"] \" \" %[^'\"]", Tlabel, Tdescr); */
39 
40  sscanf(&s[1], "%[^'\"] \" \" %[^'\"] \" \" %[^'\"]",
41  Tlabel, Ttype, Tdescr);
42 
43  /* printf("Count [%d]: [%s] [%s] [%s]\n", cnt, Tlabel, Ttype, Tdescr); */
44 
45  strcpy(tannot[cnt].label, Tlabel);
46  if (!strcmp(Ttype, "DFNT_CHAR")) tannot[cnt].type = DFNT_CHAR;
47  else if (!strcmp(Ttype, "DFNT_INT16")) tannot[cnt].type = DFNT_INT16;
48  else if (!strcmp(Ttype, "DFNT_INT32")) tannot[cnt].type = DFNT_INT32;
49  else if (!strcmp(Ttype, "DFNT_FLOAT32")) tannot[cnt].type = DFNT_FLOAT32;
50  else {
51  printf("Error finding datatype in fillenv.c\n");
52  break;
53  }
54  strcpy(tannot[cnt].descr, Tdescr);
55 
56  strcpy(Tlabel, "");
57  strcpy(Ttype, "");
58  strcpy(Tdescr, "");
59 
60  cnt++;
61  }
62 
63  if (fclose(fp) != 0) {
64  printf("Error closing %s\n", filename);
65  exit(1);
66  }
67  return (tannot);
68 
69 } /* fillenv_annot() */
int32_t type
Definition: ancil.h:73
#define NULL
Definition: decode_rs.h:63
#define MAXDESCLEN
Definition: ancil.h:42
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
char descr[MAXDESCLEN]
Definition: ancil.h:72
#define MAXLABLEN
Definition: ancil.h:41
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
struct annotation * fillenv_annot(char *filename)
Definition: fillenv.c:15
void pexit(char *string)
Definition: pexit.c:10
data_t s[NROOTS]
Definition: decode_rs.h:75
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")