OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_product_table.c
Go to the documentation of this file.
1 #include <get_product_table.h>
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 
7 
8 
9 #define MAX_LINE_LENGTH 1024
10 
11 product_table_t* get_product_table(char *file_name, int32_t *num_entries) {
12  FILE *fp;
13  char buf[MAX_LINE_LENGTH];
14  product_table_t* table;
15  int32_t i;
16  char* cptr;
17 
18  *num_entries = 0;
19 
20  /* open product table file */
21  fp = fopen(file_name, "r");
22  if (fp == 0x0) {
23  fprintf(stderr, "get_product_table - product table \"%s\" not found.\n", file_name);
24  return NULL;
25  }
26 
27  // loop through the file and count the nember of entries
28  while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) {
29  if ((buf[0] >= 0x41) && (buf[0] <= 0x5a))
30  (*num_entries)++;
31  }
32  fseek(fp, 0, SEEK_SET);
33 
34  if (*num_entries == 0) {
35  fprintf(stderr, "get_product_table - no entries found in file \"%s\"\n", file_name);
36  return NULL;
37  }
38 
39  table = (product_table_t*) malloc(sizeof (product_table_t) * *num_entries);
40  if (table == NULL) {
41  fprintf(stderr, "get_product_table - could not allocate memory.\n");
42  return NULL;
43  }
44 
45  i = 0;
46  while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) {
47  if ((buf[0] >= 0x41) && (buf[0] <= 0x5a)) {
48 
49  cptr = strtok(buf, ":");
50  table[i].description = strdup(cptr);
51 
52  cptr = strtok(NULL, ":");
53  table[i].name = strdup(cptr);
54 
55  cptr = strtok(NULL, ":");
56  table[i].units = strdup(cptr);
57 
58  cptr = strtok(NULL, ":");
59  table[i].scaling = strdup(cptr);
60 
61  cptr = strtok(NULL, ":");
62  table[i].min = (float) atof(cptr);
63 
64  cptr = strtok(NULL, ":");
65  table[i].max = (float) atof(cptr);
66 
67  cptr = strtok(NULL, ":");
68  table[i].precision = strdup(cptr);
69 
70  cptr = strtok(NULL, "\n");
71  table[i].palette = strdup(cptr);
72 
73  i++;
74  } // if buff[0] is capital letter
75  } // while more lines
76  fclose(fp);
77 
78  if (i != *num_entries) {
79  fprintf(stderr, "get_product_table - number_entries does not equal lines read.\n");
80  *num_entries = 0;
81  return NULL;
82  }
83 
84 
85  return table;
86 }
87 
88 void free_product_table(product_table_t* table, int32_t num_entries) {
89  int32_t i;
90 
91  if (table) {
92  for (i = 0; i < num_entries; i++) {
93  free(table[i].description);
94  free(table[i].name);
95  free(table[i].units);
96  free(table[i].scaling);
97  free(table[i].precision);
98  free(table[i].palette);
99  }
100  free(table);
101  }
102 }
103 
104 int32_t search_product_table(product_table_t* table, int32_t num_entries, char* name) {
105  int32_t i;
106 
107  if (table == NULL)
108  return -1;
109 
110  if (name == NULL)
111  return -1;
112 
113  for (i = 0; i < num_entries; i++) {
114  if (table[i].name) {
115  if (strcmp(table[i].name, name) == 0) {
116  return i;
117  }
118  }
119  }
120 
121  return -1;
122 }
123 
124 
int32_t search_product_table(product_table_t *table, int32_t num_entries, char *name)
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT table(e.g. m1) to be used for interpolation. The table values will be linearly interpolated using the tables corresponding to the node times bracketing the granule time. If the granule time falls before the time of the first node or after the time of the last node
#define NULL
Definition: decode_rs.h:63
#define MAX_LINE_LENGTH
product_table_t * get_product_table(char *file_name, int32_t *num_entries)
char * strdup(const char *)
char name[100]
Definition: novas.h:70
description
Definition: setup.py:16
void free_product_table(product_table_t *table, int32_t num_entries)
int i
Definition: decode_rs.h:71