ocssw  1.0
/disk01/web/ocssw/build/src/libosmi/get_cal_osmi.c (r8087/r3)
Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002     File: get_cal.c
00003 
00004     Contents:
00005         get_cal         -  opens the given calibration HDF file, retrieves 
00006                the sensor calibration data, calculates knee counts 
00007                and radiances, closes the file and returns status 
00008 
00009     Other relevant files:
00010         get_cal.h       -  various #defined constants, and also includes hdf.h
00011         getcal_proto.h  -  prototypes for get_cal functions
00012         get_cal_misc.c  -  a lower layer of calibration input functions
00013 
00014     Notes:
00015         o A test program appears at the end of this file.  It reads the     
00016           given calibration file.  The input calibration file name is hard 
00017       coded.  To test the code, uncomment the TESTCODE section
00018       and compile with -DTESTCODE on the compile line.  
00019           To get debug output include, "-DDEBUG" on the compile line.
00020 
00021         Modification history:
00022           Programmer     Organization      Date      Description of change
00023         --------------   ------------    --------    ---------------------
00024         Lakshmi Kumar    Hughes STX      03/11/94    Original development
00025         Lakshmi Kumar    Hughes STX      06/07/94    Updated to reflect v3.1 
00026                             interface spcifications
00027     Lakshmi Kumar    Hughes STX      11/15/94    Modified comments
00028     Lakshmi Kumar    Hughes STX  05/22/96    Modified to read revised 
00029                              calibration table
00030                              Removed time_factor
00031                              Added output arguments
00032                              reference year, day,
00033                              min, t_const, t_linear,
00034                              t_quadratic & cal_offs.
00035                                      Ref. V5.0 I/O specs.
00036     Lakshmi Kumar    Hughes STX  11/01/96    fixed output parameters 
00037                              of get_ref_time call.
00038     Lakshmi Kumar    Hughes STX  03/17/97    Chnaged idoffs[8][4] to
00039                              idoffs[8][16] and non-
00040                              prototype declarations 
00041                              have been removed
00042 ------------------------------------------------------------------------------*/
00043 
00044 #include "get_cal_osmi.h"
00045 #include "getcal_proto_osmi.h"
00046 /*-----------------------------------------------------------------------------
00047     Function: get_cal  
00048 
00049     Returns: int32 (status)
00050     Returns a status code of 0 when successful.  Otherwise returns
00051         -1 - to indicate file open/close error
00052     -2 - to indicate read error
00053     -3 - to indicate time error (if the given time cannot be found)
00054     -4 - to indicate insufficient memory error
00055 
00056     Description:
00057         The function get_cal reads given HDF file, determines the detector 
00058     combination to be used, calculates knee counts and radiances.
00059 
00060     Arguments: (in calling order)
00061       Type       Name             I/O     Description
00062       ----       ----             ---     -----------
00063       char *     cal_path          I      calibration file path 
00064       int16      syear             I      year of data start time
00065       int16      sday              I      day of year for data start time
00066       int16      eday              I      day of year for data end time
00067       int32      msec              I      milliseconds of the day
00068       char  *    dtype             I      data type flag 
00069       int16 *    tdi               I      input TDI for all 8 bands
00070       int16 *    cal_year      O      the year the calibration table entry
00071                         was make
00072       int16 *    cal_day       O      the day of year the calibration table
00073                         entry was made
00074       float32    temps[256][8]     O      temperature correction coefficients 
00075       float32    scan_mod[2][1285] O      scan modulation correction factors
00076       float32    mirror[2][8]      O      mirror side-0 & 1 correction factors  
00077       float32    counts[8][4][5]   O      Digital cnts corresponding to eh knee
00078       float32    rads[8][4][5]     O      Radiances corresponding to each knee
00079 
00080     Notes:
00081 
00082     Modification history:
00083           Programmer     Organization      Date      Description of change
00084         --------------   ------------    --------    ---------------------
00085         Lakshmi Kumar    Hughes STX      03/11/94    Original development
00086         Lakshmi Kumar    Hughes STX      06/07/94    Updated to reflect v3.0 
00087                             interface spcifications
00088     Lakshmi Kumar    Hughes STX  02/07/95    Added output arguments
00089                              cal_year and cal_day
00090                              (ref. I/O specs v4.2)
00091     Lakshmi Kumar    Hughes STX  05/22/96    Modified to read revised 
00092                              calibration table
00093     Lakshmi Kumar    Hughes STX  11/01/96    removed '&' sign from
00094                              ref_year, ref_day & ref_
00095                              minute variables.
00096 ------------------------------------------------------------------------------*/
00097 int32 get_cal_osmi(char *cal_path, int16 syear, int16 sday, int16 eday, int32 msec, 
00098            int16 *cal_year, int16 *cal_day, int32 *cal_msec,
00099            float32 *eoffset, float32 *egain, float32 *temp, 
00100            float32 *mirror, float32 *t_const,
00101            float32 *t_linear, float32 *t_quadratic, 
00102            float32 *slope, float32 *dc, 
00103            float32 *sm)
00104 {
00105   int32   fid, sdfid, status = 0, index = 0; 
00106   
00107 
00108   /*  open given HDF file  */
00109   if ((fid = Hopen(cal_path, DFACC_RDONLY, 0)) < 0)
00110     return FAIL;
00111 
00112   sdfid = SDstart(cal_path, DFACC_RDONLY);   
00113   Vstart(fid);
00114   /*
00115    * Read global attributes Reference Year, Reference Day and Reference Minute
00116    *  from calibration data file
00117    */
00118 
00119 
00120   if ((index = get_index_osmi(fid, syear, sday, eday, msec, cal_year, cal_day, cal_msec)) < 0)
00121         return index;
00122 
00123   if ((status = read_parm_data_osmi(fid, sdfid, index, eoffset, egain, temp, mirror,  
00124         t_const, t_linear, t_quadratic, 
00125         slope, dc, sm)) < 0)
00126     return status;
00127 
00128   /* close the given HDF file */
00129   Vend(fid);
00130   if ((Hclose(fid)) < 0)
00131       return FAIL; 
00132   if ((SDend(sdfid)) < 0)
00133       return FAIL;
00134   return  SUCCEED; 
00135 }