OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_read_L1Atemp_data.c
Go to the documentation of this file.
1 #include "PGS_MODIS_35251.h"
2 #include "GEO_input.h"
3 #include "GEO_geo.h"
4 #include "GEO_parameters.h"
5 #include "mapiL1A.h"
6 #include "mapi.h"
7 #include "smfio.h"
8 
9 PGSt_SMF_status GEO_read_L1Atemp_data(
10  const GEO_param_struct * const geo_params,
11  MODFILE * const l1a_file,
12  int const num_scans,
13  float32 average_temp[NUM_TEMPS])
14 
15 /******************************************************************************
16 !C
17 
18 !Description:
19  Subtroutine in the input group of the Level-1A geolocation software to
20  read in thermometer readings, convert them to temperature values, and
21  average them over the period of the granule.
22 
23 !Input Parameters:
24  geo_params Geolocation parameters struct
25  l1a_file M-API file handle for the L1A file
26  num_scans The number of scans in the granule
27 
28 !Output Parameters:
29  average_temp The average over the granule of each temperature
30 
31 Return Values:
32  MODIS_E_BAD_INPUT_ARG If any input argument was invalid.
33  MODIS_E_GEO If any subroutine failed.
34  PGS_S_SUCCESS Otherwise
35 
36 Externally Defined:
37  M01CR_CP_A_ON_M "mapiL1A.h"
38  M01CR_CP_B_ON_M "mapiL1A.h"
39  M01CR_RC_CFPA_T1SET "mapiL1A.h"
40  M01CR_RC_CFPA_T3SET "mapiL1A.h"
41  M01MAJCYC1OF7 "mapiL1A.h"
42  M01MAJCYC5AOF7 "mapiL1A.h"
43  M01MAJCYCALL1 "mapiL1A.h"
44  M01MAJCYC0OF63 "mapiL1A.h"
45  M01MAJCYC3OF63 "mapiL1A.h"
46  M01MAJCYC4OF63 "mapiL1A.h"
47  M01MAJCYC21OF63 "mapiL1A.h"
48  M01MAJCYC23OF63 "mapiL1A.h"
49  M01TA_RC_SMIR_CFPA "mapiL1A.h"
50  M01TP_AO_SMIR_OBJ "mapiL1A.h"
51  M01TP_MF_CALBKHD_SR "mapiL1A.h"
52  M01TP_MF_Z_BKHD_BB "mapiL1A.h"
53  M01TP_SA_RCT1_MIR "mapiL1A.h"
54  M01TP_SR_SNOUT "mapiL1A.h"
55  MAPIOK "mapi.h"
56  MAX_SCAN_NUMBER "GEO_geo.h"
57  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_35251.h"
58  MODIS_E_GEO "PGS_MODIS_35251.h"
59  NUM_TEMPS "GEO_parameters.h"
60  PGS_S_SUCCESS "PGS_SMF.h"
61  TEMP_FVALUE "GEO_geo.h"
62  TEMP_ORDER "GEO_parameters.h"
63 
64 Called by:
65  GEO_prepare_l1a_data
66 
67 Routines Called:
68  getMODIStable "mapi.h"
69  modsmf "smfio.h"
70 
71 !Revision History:
72  $Log: GEO_read_L1Atemp_data.c,v $
73  Revision 4.2 2003/03/17 18:53:23 vlin
74  Updated after code walkthrough
75 
76  Revision 4.1 2003/02/11 15:15:12 vlin
77  vlin@saicmodis.com
78 
79 Requirements: None
80 
81 !Team-unique Header:
82 
83  This software is developed by the MODIS Science Data Support
84  Team for the National Aeronautics and Space Administration,
85  Goddard Space Flight Center, under contract NAS5-32373.
86 
87 !END
88 ******************************************************************************/
89 
90 #define NUM_CONFIGS 4 /* number of configuration fields */
91 
92 {
93  uint16 readings[NUM_TEMPS+NUM_CONFIGS][MAX_SCAN_NUMBER];
94  /* the thermometer readings */
95  int eqn; /* used to identify which equation in
96  each section should be used */
97  const int base[NUM_TEMPS] = {0, 3, 5, 5, 3, 5};
98  /* used to identify the index for the
99  first equation in the equation list
100  that applies for each temperature */
101  int field, scan, temp, term;
102  double temperature, total[NUM_TEMPS] = {0.0};
103  int count[NUM_TEMPS] = {0};
104  long int buffsize, tstart = 0L;
105  char msg[128];
106  char filefunc[] = __FILE__ ", GEO_read_L1Atemp_data";
107 
108  struct field{
109  char *vdata_name;
110  char *field_name;
111  } field_list[] = {
112  {M01MAJCYC1OF7, M01CR_CP_A_ON_M},
113  {M01MAJCYC1OF7, M01CR_CP_B_ON_M},
114  {M01MAJCYC5AOF7, M01CR_RC_CFPA_T1SET},
115  {M01MAJCYC5AOF7, M01CR_RC_CFPA_T3SET},
116  {M01MAJCYCALL1, M01TA_RC_SMIR_CFPA},
117  {M01MAJCYC0OF63, M01TP_AO_SMIR_OBJ},
118  {M01MAJCYC3OF63, M01TP_MF_CALBKHD_SR},
119  {M01MAJCYC4OF63, M01TP_MF_Z_BKHD_BB},
120  {M01MAJCYC21OF63,M01TP_SA_RCT1_MIR},
121  {M01MAJCYC23OF63,M01TP_SR_SNOUT}
122  };
123 
124  if (l1a_file == NULL || geo_params == NULL || average_temp == NULL ||
125  num_scans < 0 || num_scans > MAX_SCAN_NUMBER) {
126  sprintf(msg,"l1a_file: %p, geo_params: %p, num_scans: %d, average_temp: "
127  "%p", (void *)l1a_file, (void *)geo_params, num_scans,
128  (void *)average_temp);
129  modsmf(MODIS_E_BAD_INPUT_ARG, msg, filefunc);
130  return MODIS_E_BAD_INPUT_ARG;
131  }
132 
133  for (temp = 0; temp < NUM_TEMPS; temp++)
134  average_temp[temp] = TEMP_FVALUE;
135 
136  if (num_scans == 0)
137  return PGS_S_SUCCESS;
138 
139  for (field = 0; field < NUM_CONFIGS+NUM_TEMPS; field++){
140  buffsize = (long)sizeof(readings[field]);
141  if (getMODIStable(l1a_file, field_list[field].vdata_name, NULL,
142  field_list[field].field_name, tstart, (long)num_scans, &buffsize,
143  (unsigned char *)readings[field]) != MAPIOK) {
144  sprintf(msg,"getMODIStable(%s, %s)",field_list[field].vdata_name,
145  field_list[field].field_name);
146  modsmf(MODIS_E_GEO, msg, filefunc);
147  return MODIS_E_GEO;
148  }
149  }
150 
151  for (scan = 0; scan < num_scans ; scan++) {
152  /* TA_RC_SMIR_CFPA: an active sensor, with different calibrations
153  depending upon which heaters have been turned on. */
154  if (readings[2][scan] == 1 && readings[3][scan] == 0)
155  eqn = 0; /* 83 K settings: TA07p83 or TA07f83 */
156  else if (readings[2][scan] == 0 && readings[3][scan] == 0)
157  eqn = 1; /* 85 K settings: TA07p85 or TA07f85 */
158  else if (readings[2][scan] == 0 && readings[3][scan] == 1)
159  eqn = 2; /* 88 K settings: TA07p88 or TA07f88 */
160  else
161  eqn = -1; /* Invalid combination. */
162 
163  /* NUM_CONFIGS is the offset of the first non-configuration reading. */
164  if (eqn == -1 || readings[NUM_CONFIGS][scan] == 0xFFFF)
165  temperature = TEMP_FVALUE;
166  else {
167  temperature = geo_params->temp_coeff[base[0]+eqn][TEMP_ORDER-1];
168  for (term = TEMP_ORDER-2; term >= 0; term--)
169  temperature = temperature*readings[NUM_CONFIGS][scan] +
170  geo_params->temp_coeff[base[0]+eqn][term];
171  total[0] += temperature;
172  count[0]++;
173  }
174 
175  /* The same equations are used for both electronics sides. */
176  if (strcmp(geo_params->spacecraft_ID, "Terra") == 0)
177  eqn = 0; /* TP01p or TP02p */
178  else if (readings[0][scan] == 0 && readings[1][scan] == 1)
179  eqn = 0; /* TP01fa or TP02fa */
180  else if (readings[0][scan] == 1 && readings[1][scan] == 0)
181  eqn = 1; /* TP01fb or TP02fb */
182  else
183  eqn = -1;
184 
185  if (eqn == -1)
186  continue;
187 
188  for (temp = 1; temp < NUM_TEMPS; temp++) {
189  if (readings[temp][scan] == 0xFFFF)
190  continue;
191  temperature = geo_params->temp_coeff[base[temp]+eqn][TEMP_ORDER-1];
192  for (term = TEMP_ORDER-2; term >= 0; term--)
193  temperature = temperature*readings[NUM_CONFIGS+temp][scan] +
194  geo_params->temp_coeff[base[temp]+eqn][term];
195  total[temp] += temperature;
196  count[temp]++;
197  }
198  }
199 
200  for (temp = 0; temp < NUM_TEMPS; temp++)
201  if (count[temp] > 0)
202  average_temp[temp] = total[temp]/count[temp];
203 
204  return PGS_S_SUCCESS;
205 }
#define eqn(a, b, n)
Definition: rice.h:168
#define TEMP_ORDER
#define L(lambda, T)
Definition: PreprocessP.h:185
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define NUM_TEMPS
MOD_PR01 Production producing one five minute granule of output data in each run It can be configured to produce as many as three five minute granules per run Each execution with one construction record and one date file for each dataset In normal these are created by which splits them out of the hour datasets For LANCE they are created by which merges all session MODIS L0 datasets overlapping the requested time and extracts from the merged data those packets which fall within that time period Each scan of data is stored in the L1A granule that covers the start time of that scan
Definition: MOD_PR01_pr.txt:19
float32 base
Definition: maplists.h:106
#define TEMP_FVALUE
Definition: GEO_geo.h:154
PGSt_SMF_status GEO_read_L1Atemp_data(const GEO_param_struct *const geo_params, MODFILE *const l1a_file, int const num_scans, float32 average_temp[NUM_TEMPS])
#define MODIS_E_GEO
MOD_PR02AQUA Production where MYD is the prefix denoting AQUA file output The total
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to already in place for MODIS TERRA was implemented for MODIS AQUA A time dependent LUT was added which gives coefficients for a detector specific crosstalk correction based on the aggregated Band radiances The Band scaled integers are adjusted by the Band correction term
Definition: HISTORY.txt:439
const int MAX_SCAN_NUMBER
string msg
Definition: mapgen.py:227
float32 temp_coeff[NUM_TEMP_EQNS][TEMP_ORDER]
#define NUM_CONFIGS
int count
Definition: decode_rs.h:79