OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_cld_tbl.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "genutils.h"
5 #include "sensorInfo.h"
6 
7 void get_cld_tbl_( int *inst_id, int *fname_id, char *fname, int *status,
8  long len1 )
9  /************************************************************************
10  get_cld_tbl_ - get the cloud table name that is asked for
11 
12  Returns - none
13 
14  int * inst_id I instrument id, see oel_util/libpiutils/
15  sensorDefs.h
16  int * fname_id I table file name id #, see fid_names below
17  char * fname O table file name found
18  int * status O a returned status - 0 is good
19  int len1 I~ length of the fname string
20 
21  The file with the names is in each cloud sensor subdirectory with the
22  name cloud_table_names.txt
23 
24  W. Robinson, SAIC, 14 Sep 2021
25  ************************************************************************/
26  {
27  #define NFILES 25
28  static int get_entered = 0, files_present[NFILES];
29  static char file_store[NFILES][563];
30 
31  char *fid_names[] = { "FAST_TRANS_COEFF_DRY", "FAST_TRANS_COEFF_OZO",
32  "FAST_TRANS_COEFF_WCO", "FAST_TRANS_COEFF_WTL", "FAST_TRANS_COEFF_WTS",
33  "SNOW_ALBEDO", "ECOLOGY_MAP", "GLOBAL_EMISS", "ALBEDO_CLIM",
34  "TRANSMITTANCE_COEFFS", "SINGLE_SCAT",
35  "SCAT_ICE", "SCAT_ICE_03_M_S", "SCAT_ICE_07_M_S", "SCAT_ICE_15_M_S",
36  "SCAT_ICE_SD_03_M_S", "SCAT_ICE_SD_07_M_S", "SCAT_ICE_SD_15_M_S",
37  "SCAT_WATER", "SCAT_WATER_03_M_S", "SCAT_WATER_07_M_S",
38  "SCAT_WATER_15_M_S", "SCAT_WATER_SD_03_M_S", "SCAT_WATER_SD_07_M_S",
39  "SCAT_WATER_SD_15_M_S" };
40  char str[563];
41  char *id, *floc;
42  char file[500], *filep;
43  FILE *rd_stream;
44  int ilin, i, ifound;
45 
46  *status = 0;
47 
48  for( ilin = 0; ilin < len1; ilin++ )
49  fname[ilin] = ' ';
50  // if we haven't gotten the file names, get those
51  if( get_entered == 0 )
52  {
53  get_entered = 1;
54  // initialize the file name storage and present flag
55  for( ilin = 0; ilin < NFILES; ilin++ )
56  {
57  files_present[ilin] = 0;
58  strcpy( file_store[ilin], "NONE" );
59  }
60  // Make name of table file list file, open the file, read each line
61  // and process it
62  if( ( filep = getenv("OCDATAROOT") ) == NULL)
63  {
64  printf( "E: %s, %d: unable to get cloud table namen",
65  __FILE__, __LINE__ );
66  *status = 1;
67  return;
68  }
69  strcpy( file, filep );
70  strcat( file, "/cloud/" );
71  strcat( file, sensorId2SensorDir( *inst_id ) );
72  strcat( file, "/cloud_table_names.txt" );
73 
74  if( ( rd_stream = fopen( file, "r" ) ) == NULL )
75  {
76  printf(
77  "E: %s, %d: Open error for cloud table file: %s\n",
78  __FILE__, __LINE__, file );
79  *status = 1;
80  return;
81  }
82  // get all inputs (name_id=name) from the stream
83  while( fgets( str, 562, rd_stream ) != NULL )
84  {
85  if( *str != '#' )
86  {
87  floc = strchr( str, '=' );
88  if( floc == NULL )
89  {
90  printf( "E: %s, %d: A data line in file: %s\n",
91  __FILE__, __LINE__, file );
92  printf( " Does not have the form NAME_ID=NAME\n" );
93  printf( " Line is: %s\n", str );
94  }
95  *floc = 0;
96  floc++;
97  id = str;
98  // find the name and store the file name
99  ifound = 0;
100  for( ilin = 0; ilin < NFILES; ilin++ )
101  {
102  if( strcmp( upcase( id ), fid_names[ilin] ) == 0 )
103  {
104  files_present[ilin] = 1;
105  strcpy( file_store[ilin], floc );
106  ifound = 1;
107  break;
108  }
109  }
110  if( ifound != 1 )
111  {
112  printf( "I: %s, %d: No match found for cloud table file ID: %s\n",
113  __FILE__, __LINE__, id );
114  }
115  }
116  }
117  fclose( rd_stream );
118  /*
119  * Be sure all the table files are assigned
120  */
121  for( ilin = 0; ilin < NFILES; ilin++ )
122  {
123  if( files_present[ilin] == 0 )
124  {
125  printf( "E: %s, %d: Cloud table: %s was not found\n",
126  __FILE__, __LINE__, fid_names[ilin] );
127  *status = 1;
128  }
129  }
130  }
131  /*
132  * now, here we send back the requested file name
133  */
134  if( *status != 0 ) return;
135 
136  // if the file starts with a '/', assume it is an entire file spec
137  if( file_store[*fname_id][0] == '/' )
138  {
139  strcpy( fname, file_store[*fname_id] );
140  }
141  else
142  {
143  // Otherwise, assume file is in $OCDATAROOT/cloud/(common)|<sensor path>
144  if( ( filep = getenv("OCDATAROOT") ) == NULL)
145  {
146  printf( "E: %s, %d: unable to get cloud table namen",
147  __FILE__, __LINE__ );
148  *status = 1;
149  }
150  else
151  {
152  strcpy( fname, filep );
153  strcat( fname, "/cloud/" );
154  if( *fname_id < 9 )
155  strcat( fname, "common/" );
156  else
157  {
158  strcat( fname, sensorId2SensorDir( *inst_id ) );
159  strcat( fname, "/" );
160  }
161  strcat( fname, file_store[*fname_id] );
162  }
163  }
164  // see if we can pad the string with blanks to end
165  ilin = strlen( fname );
166  for( i = ilin - 1; i < len1; i++ )
167  fname[i] = ' ';
168  /*
169  printf( "%s, %d: temp found file is: %s\n", __FILE__, __LINE__, fname );
170  printf( "from inst: %d, sens: %d, file_store: %s\n", *inst_id, *fname_id, file_store[*fname_id] );
171  */
172  return;
173  }
void get_cld_tbl_(int *inst_id, int *fname_id, char *fname, int *status, long len1)
Definition: get_cld_tbl.c:7
const char * sensorId2SensorDir(int sensorId)
Definition: sensorInfo.c:240
int status
Definition: l1_czcs_hdf.c:32
#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 file
Definition: HISTORY.txt:413
#define NFILES
const char * str
Definition: l1c_msi.cpp:35
char * upcase(char *instr)
Definition: upcase.c:10
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")