ocssw  1.0
/disk01/web/ocssw/build/src/geogen_modis/GEO_read_L1Atemp_data.c (r10085/r7924)
Go to the documentation of this file.
00001 #include "PGS_MODIS_35251.h"
00002 #include "GEO_input.h"
00003 #include "GEO_geo.h"
00004 #include "GEO_parameters.h"
00005 #include "mapiL1A.h"
00006 #include "mapi.h"
00007 #include "smfio.h"
00008 
00009 PGSt_SMF_status GEO_read_L1Atemp_data(
00010     const GEO_param_struct  * const geo_params,
00011     MODFILE         * const l1a_file,
00012     int         const num_scans,
00013     float32         average_temp[NUM_TEMPS])
00014 
00015 /******************************************************************************
00016 !C
00017 
00018 !Description:   
00019     Subtroutine in the input group of the Level-1A geolocation software to
00020     read in thermometer readings, convert them to temperature values, and
00021     average them over the period of the granule.
00022 
00023 !Input Parameters:
00024     geo_params      Geolocation parameters struct
00025     l1a_file        M-API file handle for the L1A file
00026     num_scans       The number of scans in the granule
00027 
00028 !Output Parameters:
00029     average_temp        The average over the granule of each temperature
00030 
00031 Return Values:
00032     MODIS_E_BAD_INPUT_ARG   If any input argument was invalid.
00033     MODIS_E_GEO     If any subroutine failed.
00034     PGS_S_SUCCESS       Otherwise
00035 
00036 Externally Defined:
00037     M01CR_CP_A_ON_M     "mapiL1A.h"
00038     M01CR_CP_B_ON_M     "mapiL1A.h"
00039     M01CR_RC_CFPA_T1SET "mapiL1A.h"
00040     M01CR_RC_CFPA_T3SET "mapiL1A.h"
00041     M01MAJCYC1OF7       "mapiL1A.h"
00042     M01MAJCYC5AOF7      "mapiL1A.h"
00043     M01MAJCYCALL1       "mapiL1A.h"
00044     M01MAJCYC0OF63      "mapiL1A.h"
00045     M01MAJCYC3OF63      "mapiL1A.h"
00046     M01MAJCYC4OF63      "mapiL1A.h"
00047     M01MAJCYC21OF63     "mapiL1A.h"
00048     M01MAJCYC23OF63     "mapiL1A.h"
00049     M01TA_RC_SMIR_CFPA  "mapiL1A.h"
00050     M01TP_AO_SMIR_OBJ   "mapiL1A.h"
00051     M01TP_MF_CALBKHD_SR "mapiL1A.h"
00052     M01TP_MF_Z_BKHD_BB  "mapiL1A.h"
00053     M01TP_SA_RCT1_MIR   "mapiL1A.h"
00054     M01TP_SR_SNOUT      "mapiL1A.h"
00055     MAPIOK          "mapi.h"
00056     MAX_SCAN_NUMBER     "GEO_geo.h"
00057     MODIS_E_BAD_INPUT_ARG   "PGS_MODIS_35251.h"
00058     MODIS_E_GEO     "PGS_MODIS_35251.h"
00059     NUM_TEMPS       "GEO_parameters.h"
00060     PGS_S_SUCCESS       "PGS_SMF.h"
00061     TEMP_FVALUE     "GEO_geo.h"
00062     TEMP_ORDER      "GEO_parameters.h"
00063 
00064 Called by:
00065     GEO_prepare_l1a_data
00066 
00067 Routines Called:
00068     getMODIStable       "mapi.h"
00069     modsmf          "smfio.h"
00070 
00071 !Revision History:
00072         $Log: GEO_read_L1Atemp_data.c,v $
00073         Revision 4.2  2003/03/17 18:53:23  vlin
00074         Updated after code walkthrough
00075 
00076         Revision 4.1  2003/02/11 15:15:12  vlin
00077         vlin@saicmodis.com
00078 
00079 Requirements:      None
00080 
00081 !Team-unique Header:
00082 
00083     This software is developed by the MODIS Science Data Support
00084     Team for the National Aeronautics and Space Administration,
00085     Goddard Space Flight Center, under contract NAS5-32373.
00086 
00087 !END
00088 ******************************************************************************/
00089 
00090 #define NUM_CONFIGS 4                   /* number of configuration fields */
00091 
00092 {
00093   uint16    readings[NUM_TEMPS+NUM_CONFIGS][MAX_SCAN_NUMBER];
00094                                         /* the thermometer readings */
00095   int       eqn;                        /* used to identify which equation in 
00096                                            each section should be used */
00097   const int base[NUM_TEMPS] = {0, 3, 5, 5, 3, 5};
00098                                         /* used to identify the index for the 
00099                                            first equation in the equation list 
00100                                            that applies for each temperature */
00101   int       field, scan, temp, term;
00102   double    temperature, total[NUM_TEMPS] = {0.0};
00103   int       count[NUM_TEMPS] = {0};
00104   int32  buffsize, tstart = 0L;
00105   char      msg[128];
00106   char      filefunc[] = __FILE__ ", GEO_read_L1Atemp_data";
00107 
00108   struct field{
00109        char *vdata_name;
00110        char *field_name;
00111   } field_list[] = {
00112      {M01MAJCYC1OF7,  M01CR_CP_A_ON_M},
00113      {M01MAJCYC1OF7,  M01CR_CP_B_ON_M},
00114      {M01MAJCYC5AOF7, M01CR_RC_CFPA_T1SET},
00115      {M01MAJCYC5AOF7, M01CR_RC_CFPA_T3SET},
00116      {M01MAJCYCALL1,  M01TA_RC_SMIR_CFPA},
00117      {M01MAJCYC0OF63, M01TP_AO_SMIR_OBJ},
00118      {M01MAJCYC3OF63, M01TP_MF_CALBKHD_SR},
00119      {M01MAJCYC4OF63, M01TP_MF_Z_BKHD_BB},
00120      {M01MAJCYC21OF63,M01TP_SA_RCT1_MIR},
00121      {M01MAJCYC23OF63,M01TP_SR_SNOUT}
00122   };
00123 
00124   if (l1a_file == NULL || geo_params == NULL || average_temp == NULL ||
00125       num_scans < 0 || num_scans > MAX_SCAN_NUMBER) {
00126       sprintf(msg,"l1a_file: %p, geo_params: %p, num_scans: %d, average_temp: "
00127               "%p", (void *)l1a_file, (void *)geo_params, num_scans, 
00128              (void *)average_temp);
00129       modsmf(MODIS_E_BAD_INPUT_ARG, msg, filefunc);
00130       return MODIS_E_BAD_INPUT_ARG;
00131   }
00132 
00133   for (temp = 0; temp < NUM_TEMPS; temp++) 
00134       average_temp[temp] = TEMP_FVALUE;
00135 
00136   if (num_scans == 0)
00137       return PGS_S_SUCCESS;
00138 
00139   for (field = 0; field < NUM_CONFIGS+NUM_TEMPS; field++){
00140      buffsize = (int32)sizeof(readings[field]);
00141      if (getMODIStable(l1a_file, field_list[field].vdata_name, NULL,
00142          field_list[field].field_name, tstart, (int32)num_scans, &buffsize,
00143          (unsigned char *)readings[field]) != MAPIOK) {
00144          sprintf(msg,"getMODIStable(%s, %s)",field_list[field].vdata_name,
00145                  field_list[field].field_name);
00146          modsmf(MODIS_E_GEO, msg, filefunc);
00147          return MODIS_E_GEO;
00148      }
00149   }
00150 
00151   for (scan = 0; scan < num_scans ; scan++) {
00152     /* TA_RC_SMIR_CFPA: an active sensor, with different calibrations
00153                  depending upon which heaters have been turned on. */ 
00154      if (readings[2][scan] == 1 && readings[3][scan] == 0)
00155     eqn = 0;              /* 83 K settings: TA07p83 or TA07f83 */   
00156      else if (readings[2][scan] == 0 && readings[3][scan] == 0)
00157         eqn = 1;              /* 85 K settings: TA07p85 or TA07f85 */
00158      else if (readings[2][scan] == 0 && readings[3][scan] == 1)
00159         eqn = 2;              /* 88 K settings: TA07p88 or TA07f88 */
00160      else
00161         eqn = -1;             /* Invalid combination. */
00162 
00163     /* NUM_CONFIGS is the offset of the first non-configuration reading. */
00164      if (eqn == -1 || readings[NUM_CONFIGS][scan] == 0xFFFF)
00165      temperature = TEMP_FVALUE;
00166      else {
00167          temperature = geo_params->temp_coeff[base[0]+eqn][TEMP_ORDER-1];
00168          for (term = TEMP_ORDER-2; term >= 0; term--)
00169               temperature = temperature*readings[NUM_CONFIGS][scan] +
00170                             geo_params->temp_coeff[base[0]+eqn][term];
00171          total[0] += temperature;
00172      count[0]++;
00173      }
00174 
00175     /* The same equations are used for both electronics sides. */
00176      if (strcmp(geo_params->spacecraft_ID, "Terra") == 0)
00177          eqn = 0;              /* TP01p or TP02p */
00178      else if (readings[0][scan] == 0 && readings[1][scan] == 1)
00179          eqn = 0;              /* TP01fa or TP02fa */
00180      else if (readings[0][scan] == 1 && readings[1][scan] == 0)
00181          eqn = 1;              /* TP01fb or TP02fb */
00182      else
00183          eqn = -1;
00184 
00185      if (eqn == -1)
00186          continue;
00187 
00188      for (temp = 1; temp < NUM_TEMPS; temp++) {
00189          if (readings[temp][scan] == 0xFFFF)
00190              continue;
00191          temperature = geo_params->temp_coeff[base[temp]+eqn][TEMP_ORDER-1];
00192          for (term = TEMP_ORDER-2; term >= 0; term--)
00193               temperature = temperature*readings[NUM_CONFIGS+temp][scan] +
00194                             geo_params->temp_coeff[base[temp]+eqn][term];
00195          total[temp] += temperature;
00196          count[temp]++;
00197      }
00198   }
00199 
00200   for (temp = 0; temp < NUM_TEMPS; temp++)
00201       if (count[temp] > 0)
00202           average_temp[temp] = total[temp]/count[temp];
00203 
00204   return PGS_S_SUCCESS;
00205 }