OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_pcf_config_data.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include "L1A_prototype.h"
4 #include "PC_pcf_info.h"
5 #include "PGS_MODIS_35005.h"
6 #include "PGS_PC.h"
7 #include "PGS_SMF.h"
8 #include "PGS_TD.h"
9 #include "PGS_TYPES.h"
10 
11 PGSt_SMF_status get_pcf_config_data(PCF_CONFIG_t *pcf_config)
12 
13 /***************************************************************************
14 !C
15 
16 !Description: This function will read the parameters from the PCF and convert
17  them from strings to the appropriate PGSt types.
18 
19 !Input Parameters:
20  None.
21 
22 !Output Parameters:
23  PCF_CONFIG_t *pcf_config ** Structure to be filled in with **
24  ** PCF configuration parameters **
25 
26 Return Values: MODIS_S_SUCCESS (PGS_MODIS_35005.h)
27  MODIS_E_GETCONFIG_FAILED (PGS_MODIS_35005.h)
28  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
29  MODIS_E_UTC_TO_TAI_FAILED (PGS_MODIS_35005.h)
30 
31 Externally Defined:
32  INSTRUMENT_AQUA (PC_pcf_info.h)
33  INSTRUMENT_TERRA (PC_pcf_info.h)
34  MODIS_E_GETCONFIG_FAILED (PGS_MODIS_35005.h)
35  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
36  MODIS_E_UTC_TO_TAI_FAILED (PGS_MODIS_35005.h)
37  MODIS_S_SUCCESS (PGS_MODIS_39501.h)
38  PC_L1A_FIRST_GRAN_START_TIME (PC_pcf_info.h)
39  PC_L1A_GRAN_TIME_LENGTH (PC_pcf_info.h)
40  PC_L1A_LAST_GRAN_STOP_TIME (PC_pcf_info.h)
41  PC_L1A_PROCESSING_ENVIRONMENT (PC_pcf_info.h)
42  PC_L1A_REPROCESS_ACTUAL (PC_pcf_info.h)
43  PC_L1A_REPROCESS_PLANNED (PC_pcf_info.h)
44  PC_L1A_SCAN_RATE (PC_pcf_info.h)
45  PC_L1A_PGE_VERSION (PC_pcf_info.h)
46  PC_L1A_VERSION (PC_pcf_info.h)
47  PGS_TRUE (PGS_SMF.h)
48  PGS_SMF_MASK_LEV_E (PGS_SMF.h)
49  PGSPC_W_NO_CONFIG_FOR_ID (PGS_PC.h)
50  PGSt_SMF_status (PGS_SMF.h)
51  PGSd_PC_VALUE_LENGTH_MAX (PGS_PC.h)
52  PGSd_EOS_AM1 (PGS_TD.h)
53  PGSd_EOS_PM1 (PGS_TD.h)
54  SYS_NMLN (sys/utsname.h)
55 
56 Called By: initialize_level1a.c
57 
58 Routines Called:
59  PGS_TD_UTCtoTAI
60  PGS_PC_GetConfigData
61  PGS_SMF_TestSuccessLevel
62  PGS_SMF_TestStatusLevel
63  log_fmt_msg
64 
65 !Revision History:
66  $Log: get_pcf_config_data.c,v $
67  Revision 4.1 2002/10/03 16:14:30 kuyper
68  Changed to work correctly, even if getenv() reuses the same buffer on every
69  call.
70 
71  Revision 3.3 2002/10/03 14:27:07 vlin
72  Updated to use getenv() instead of uname(). uname() is a prohibited function.
73 
74  Revision 3.2 2002/10/01 14:53:31 vlin
75  Updated after code walkthrough, PDL v3.5
76  vlin@saicmodis.com
77 
78  Revision 3.1 2002/09/19 17:52:41 vlin
79  Updated according to get_pcf_config_data.PDL revision 3.4
80 
81  Revision 2.2 2001/01/04
82  John Seaton (seaton@ltpmail.gsfc.nasa.gov)
83  Added call to get PGE version from the pcf file.
84 
85 !Team-unique Header:
86 
87  This software is developed by the MODIS Science Data Support Team
88  for the National Aeronautics and Space Administration, Goddard
89  Space Flight Center, under contract NAS5-32373.
90 
91 !END
92 ****************************************************************************/
93 
94 {
95  char *routine = "get_pcf_config_data";
96  char buffer[PGSd_PC_VALUE_LENGTH_MAX] = "";
97  const char *env_var[] = { "OSTYPE", "HOST", "REVISION", "MACHINE"};
98 #define ENVSTRS (sizeof env_var/sizeof env_var[0])
99  char *p, *pend;
100  const char *env_str;
101  int i;
102  PGSt_SMF_status returnStatus = MODIS_S_SUCCESS;
103  PGSt_SMF_status tempStatus;
104 
105  if (pcf_config == NULL) {
106  log_fmt_msg(MODIS_E_NULL_POINTER, routine, "");
107  return MODIS_E_NULL_POINTER;
108  }
109 
110  tempStatus = PGS_PC_GetConfigData(PC_L1A_FIRST_GRAN_START_TIME, buffer);
111 
112  if (PGS_SMF_TestSuccessLevel(tempStatus)) {
113  tempStatus = PGS_TD_UTCtoTAI(buffer, &pcf_config->first_gran_start_time);
114  if (PGS_SMF_TestStatusLevel(tempStatus) >= PGS_SMF_MASK_LEV_E) {
115  returnStatus = MODIS_E_UTC_TO_TAI_FAILED;
116  strcat(buffer, "could not be converted");
117  log_fmt_msg(MODIS_E_UTC_TO_TAI_FAILED, routine, buffer);
118  }
119  }
120  else {
121  returnStatus = MODIS_E_GETCONFIG_FAILED;
123  "The first granule start time could not be retrieved");
124  }
125 
126  tempStatus = PGS_PC_GetConfigData(PC_L1A_LAST_GRAN_STOP_TIME, buffer);
127 
128  if (PGS_SMF_TestSuccessLevel(tempStatus)) {
129  tempStatus = PGS_TD_UTCtoTAI(buffer, &pcf_config->last_gran_stop_time);
130  if (PGS_SMF_TestStatusLevel(tempStatus) >= PGS_SMF_MASK_LEV_E) {
131  returnStatus = MODIS_E_UTC_TO_TAI_FAILED;
132  strcat(buffer, "could not be converted");
133  log_fmt_msg(MODIS_E_UTC_TO_TAI_FAILED, routine, buffer);
134  }
135  }
136  else {
137  returnStatus = MODIS_E_GETCONFIG_FAILED;
139  "The last granule stop time could not be retrieved");
140  }
141 
142  tempStatus = PGS_PC_GetConfigData(PC_L1A_GRAN_TIME_LENGTH, buffer);
143 
144  if (PGS_SMF_TestSuccessLevel(tempStatus))
145  pcf_config->gran_time_length = (PGSt_double) atof(buffer);
146  else {
147  returnStatus = MODIS_E_GETCONFIG_FAILED;
149  "The granule time length could not be retrieved");
150  }
151 
152  tempStatus = PGS_PC_GetConfigData(PC_L1A_SCAN_RATE, buffer);
153 
154  if (PGS_SMF_TestSuccessLevel(tempStatus))
155  pcf_config->scan_rate = (PGSt_double) atof(buffer);
156  else {
157  returnStatus = MODIS_E_GETCONFIG_FAILED;
159  "The scan rate could not be retrieved");
160  }
161 
162  tempStatus = PGS_PC_GetConfigData(PC_L1A_VERSION, pcf_config->localversionid);
163 
164  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
165  returnStatus = MODIS_E_GETCONFIG_FAILED;
167  "The L1A product version could not be retrieved");
168  }
169 
170  tempStatus = PGS_PC_GetConfigData(PC_L1A_LUT_REVISION, pcf_config->lutrevision);
171 
172  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
173  returnStatus = MODIS_E_GETCONFIG_FAILED;
175  "The MOD_PR01 LUT RCS Revision number could not be retrieved");
176  }
177 
178  tempStatus = PGS_PC_GetConfigData(PC_L1A_PGE_VERSION, pcf_config->pgeversion);
179 
180  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
181  returnStatus = MODIS_E_GETCONFIG_FAILED;
183  "The PGE version could not be retrieved");
184  }
185 
186  tempStatus = PGS_PC_GetConfigData(PC_INSTRUMENT, buffer);
187 
188  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
189  pcf_config->instrument = 0;
190  returnStatus = MODIS_E_GETCONFIG_FAILED;
192  "The satellite instrument string could not be retrieved");
193  }
194  else if (strcmp(buffer,INSTRUMENT_AQUA) == 0)
195  pcf_config->instrument = PGSd_EOS_PM1;
196  else if (strcmp(buffer,INSTRUMENT_TERRA) == 0)
197  pcf_config->instrument = PGSd_EOS_AM1;
198  else
199  pcf_config->instrument = 0;
200 
201  tempStatus = PGS_PC_GetConfigData(PC_L1A_PROCESSING_ENVIRONMENT,
202  pcf_config->processingenvironment);
203 
204  if (tempStatus == PGSPC_W_NO_CONFIG_FOR_ID){
205  /* Would like to call uname() here, but that's a prohibited function.
206  * Instead, we'll rely upon certain environment variables being set up.
207  * It's not really very important what this string contains, except in the
208  * MODAPS environment, where the tempStatus should be PGS_S_SUCCESS.
209  */
210  p = pcf_config->processingenvironment;
211  pend = p+sizeof(pcf_config->processingenvironment);
212 
213  for(i=0; i<ENVSTRS; i++)
214  {
215  env_str = getenv(env_var[i]);
216  if(env_str)
217  { /* The string does have a value */
218  if(p!=pcf_config->processingenvironment)
219  { /* We've already found one previous string */
220  *p++=' '; /* So we need a space between them. */
221  *p='\0';
222  }
223 
224  strncat(p, env_str, (int)(pend-p) );
225  p += strlen(p);
226  }
227  }
228  }
229  else if (tempStatus != PGS_S_SUCCESS) {
230  returnStatus = MODIS_E_GETCONFIG_FAILED;
232  "The ProcessingEnvironment string could not be retrieved");
233  }
234 
235  tempStatus = PGS_PC_GetConfigData(PC_L1A_REPROCESS_ACTUAL,
236  pcf_config->reprocessingactual);
237 
238  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
239  returnStatus = MODIS_E_GETCONFIG_FAILED;
241  "The ReprocessingActual string could not be retrieved");
242  }
243 
244  tempStatus = PGS_PC_GetConfigData(PC_L1A_REPROCESS_PLANNED,
245  pcf_config->reprocessingplanned);
246 
247  if (!PGS_SMF_TestSuccessLevel(tempStatus)) {
248  returnStatus = MODIS_E_GETCONFIG_FAILED;
250  "The ReprocessingPlanned string could not be retrieved");
251  }
252 
253  return returnStatus;
254 
255  } /* End of routine get_pcf_config_data */
#define INSTRUMENT_AQUA
Definition: PC_pcf_info.h:72
#define PC_L1A_SCAN_RATE
Definition: PC_pcf_info.h:64
#define PC_L1A_FIRST_GRAN_START_TIME
Definition: PC_pcf_info.h:55
char pgeversion[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:87
char processingenvironment[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:88
#define NULL
Definition: decode_rs.h:63
char localversionid[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:85
PGSt_tag instrument
Definition: PC_pcf_info.h:89
#define PC_L1A_REPROCESS_ACTUAL
Definition: PC_pcf_info.h:62
#define MODIS_E_GETCONFIG_FAILED
PGSt_double scan_rate
Definition: PC_pcf_info.h:84
PGSt_double first_gran_start_time
Definition: PC_pcf_info.h:81
#define INSTRUMENT_TERRA
Definition: PC_pcf_info.h:71
#define PC_L1A_PGE_VERSION
Definition: PC_pcf_info.h:60
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
char reprocessingplanned[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:91
#define PC_L1A_PROCESSING_ENVIRONMENT
Definition: PC_pcf_info.h:61
#define PC_L1A_REPROCESS_PLANNED
Definition: PC_pcf_info.h:63
#define MODIS_E_UTC_TO_TAI_FAILED
#define PC_L1A_LUT_REVISION
Definition: PC_pcf_info.h:57
#define PC_INSTRUMENT
Definition: PC_pcf_info.h:69
PGSt_double last_gran_stop_time
Definition: PC_pcf_info.h:82
char lutrevision[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:86
#define MODIS_S_SUCCESS
PGSt_double gran_time_length
Definition: PC_pcf_info.h:83
#define PC_L1A_LAST_GRAN_STOP_TIME
Definition: PC_pcf_info.h:56
PGSt_SMF_status get_pcf_config_data(PCF_CONFIG_t *pcf_config)
char reprocessingactual[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:90
int i
Definition: decode_rs.h:71
#define MODIS_E_NULL_POINTER
#define PC_L1A_VERSION
Definition: PC_pcf_info.h:65
#define PC_L1A_GRAN_TIME_LENGTH
Definition: PC_pcf_info.h:59
#define ENVSTRS
float p[MODELMAX]
Definition: atrem_corl1.h:131