|
ocssw
1.0
|
00001 /*----------------------------------------------------------------------------- 00002 File : get_cal_misc.c 00003 00004 Contents: 00005 get_index - reads time vdata and returns appropriate index to 00006 access data 00007 read_parm_data - reads parameter data 00008 00009 Other relevant files: 00010 cal.h - various #defined constants, TDI table, and also 00011 includes hdf.h 00012 getcal_proto.h - prototypes for get_cal functions 00013 get_cal.c - a higher layer of calibration input functions 00014 00015 Notes: 00016 00017 Modification history: 00018 Programmer Organization Date Description of change 00019 -------------- ------------ -------- --------------------- 00020 Lakshmi Kumar Hughes STX 03/11/94 Original development 00021 Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1 00022 interface spcifications 00023 Lakshmi Kumar Hughes STX 03/21/96 Corrected non-prototype 00024 declarations 00025 Lakshmi Kumar Hughes STX 03/17/97 Removed non-ANSI proto 00026 declarations. In-detector 00027 offsets are redefined as 00028 idoffs[8][16]. 00029 ------------------------------------------------------------------------------*/ 00030 00031 #include "get_cal_osmi.h" 00032 #include "getcal_proto_osmi.h" 00033 #include <hdf_utils.h> 00034 00035 /*----------------------------------------------------------------------------- 00036 Function: get_index 00037 00038 Returns: int32 (index) 00039 On successful it returns the index of the given time entry and if 00040 time entry not found, returns -3. 00041 00042 Description: 00043 The function get_index reads time vdata and searches for the 00044 given time entry. If the given time found, it rerurns the entry 00045 number to access related information from slopes and parameter vdatas. 00046 00047 Arguments: (in calling order) 00048 Type Name I/O Description 00049 ---- ---- --- ----------- 00050 int32 fid I file ID 00051 int16 syear I year of data start time 00052 int16 sday I day-of-year for data start time 00053 int16 eday I day-of-year for data end time 00054 int32 smsec I milliseconds-of-day for data start time 00055 int16 *cal_year O year the cal entry was made 00056 int16 *cal_day O day of the year the cal entry was made 00057 00058 Notes: 00059 00060 Modification history: 00061 Programmer Organization Date Description of change 00062 -------------- ------------ -------- --------------------- 00063 Lakshmi Kumar Hughes STX 03/11/94 Original development 00064 Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1 00065 interface spcifications 00066 Lakshmi Kumar Hughes STX 02/07/94 Added code to return 00067 cal entry year and day 00068 (ref to I/O specs v4.2) 00069 ------------------------------------------------------------------------------*/ 00070 00071 int32 get_index_osmi(int32 fid, int16 syear, int16 sday, int16 eday, int32 msec, 00072 int16 *cal_year, int16 *cal_day, int32 *cal_msec) 00073 { 00074 00075 int16 dyear, dday, *cal_syear, *cal_sday, *cal_eyear, *cal_eday; 00076 int16 *entry_year, *entry_day; 00077 int32 i, *cal_smsec, *cal_emsec, vsid, elts; 00078 00079 00080 if ((vsid = attach_vdata(fid, TIME)) < 0) 00081 return RDERR; 00082 00083 if ((elts = VSelts(vsid)) < 0) 00084 return RDERR; 00085 if((cal_syear = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00086 return BUFERR; 00087 00088 if((cal_eyear = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00089 return BUFERR; 00090 00091 if((cal_sday = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00092 return BUFERR; 00093 00094 if((cal_eday = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00095 return BUFERR; 00096 00097 if((cal_smsec = (int32 *) malloc(elts * sizeof(int32)))==NULL) 00098 return BUFERR; 00099 00100 if((cal_emsec = (int32 *) malloc(elts * sizeof(int32)))==NULL) 00101 return BUFERR; 00102 00103 if((entry_year = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00104 return BUFERR; 00105 00106 if((entry_day = (int16 *) malloc(elts * sizeof(int16)))==NULL) 00107 return BUFERR; 00108 00109 rdvdata(vsid, SYEAR, 0, elts, (unsigned char *)cal_syear); 00110 rdvdata(vsid, SDAY, 0, elts, (unsigned char *)cal_sday); 00111 rdvdata(vsid, SMSEC, 0, elts, (unsigned char *)cal_smsec); 00112 00113 rdvdata(vsid, EYEAR, 0, elts, (unsigned char *)cal_eyear); 00114 rdvdata(vsid, EDAY, 0, elts, (unsigned char *)cal_eday); 00115 rdvdata(vsid, EMSEC, 0, elts, (unsigned char *)cal_emsec); 00116 00117 rdvdata(vsid, ENTRY_YEAR, 0, elts, (unsigned char *)entry_year); 00118 rdvdata(vsid, ENTRY_DAY, 0, elts, (unsigned char *)entry_day); 00119 00120 dyear = syear; 00121 dday = sday; 00122 if (sday != eday && msec < 43200000) 00123 dday = eday; 00124 if (dday < sday) 00125 dyear += 1; 00126 00127 for(i = elts-1; i >= 0; i--) { 00128 if (cal_eyear[i] == 0){ /* onwards rec */ 00129 if (dyear > cal_syear[i]) 00130 break; 00131 if (dyear == cal_syear[i] && dday > cal_sday[i]) 00132 break; 00133 if (dyear == cal_syear[i] && dday == cal_sday[i] && 00134 msec >= cal_smsec[i]) 00135 break; 00136 } 00137 else { /* not an onwards rec */ 00138 if (dyear > cal_syear[i]) { 00139 if (dyear < cal_eyear[i]) 00140 break; 00141 if (dyear == cal_eyear[i]) { 00142 if (dday < cal_eday[i]) 00143 break; 00144 if (dday == cal_eday[i] && msec <= cal_emsec[i]) 00145 break; 00146 } 00147 } 00148 else 00149 if (dyear == cal_syear[i]) { 00150 if (dyear < cal_eyear[i]) 00151 break; 00152 if (dyear == cal_eyear[i]) { 00153 if (dday >= cal_sday[i] && dday < cal_eday[i]) 00154 break; 00155 if (dday >= cal_sday[i] && dday == cal_eday[i] && 00156 msec <= cal_emsec[i]) 00157 break; 00158 } 00159 } 00160 } 00161 } 00162 00163 *cal_year = cal_syear[i]; 00164 *cal_day = cal_sday[i]; 00165 *cal_msec = cal_smsec[i]; 00166 00167 VSdetach(vsid); 00168 free(cal_syear); 00169 free(cal_sday); 00170 free(cal_smsec); 00171 free(cal_eyear); 00172 free(cal_eday); 00173 free(cal_emsec); 00174 free(entry_year); 00175 free(entry_day); 00176 00177 if (i < 0) 00178 return TMERR; 00179 else 00180 return i; 00181 } 00182 00183 /*----------------------------------------------------------------------------- 00184 Function: read_parm_data 00185 00186 Returns: int32 (Status) 00187 On success returns 0, otherwise returns -2 indicating read error. 00188 Description: 00189 The function attaches to the requested vdata 00190 00191 Arguments: (in calling order) 00192 Type Name I/O Description 00193 ---- ---- --- ----------- 00194 int32 fid I HDF file ID 00195 int32 sdfid I HDF SD file ID 00196 int32 index I element number 00197 int32 idoffs[8][16] O detector zero offset counts 00198 float32 gains[8][16] O slopes (band*detector*gains) 00199 float32 temps[256][2]O temp and ref temp correction factors 00200 float32 scan_mod[2][1285]O scan-modulation buffer 00201 float32 mirror[8][2] O mirror side1 and side2 for all bands 00202 int16 tdi_list[256][4] O TDI values for all 8 bands 00203 00204 Notes: 00205 00206 Modification history: 00207 Programmer Organization Date Description of change 00208 -------------- ------------ -------- --------------------- 00209 Lakshmi Kumar Hughes STX 03/11/94 Original development 00210 Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1 00211 interface spcifications 00212 ------------------------------------------------------------------------------*/ 00213 int32 read_parm_data_osmi(int32 fid, int32 sdfid, int32 index, float32 *eoffset, 00214 float32 *egain, float32 *temp, float32 *mirror, 00215 float32 *t_const, float32 *t_linear, float32 *t_quadratic, 00216 float32 *slope, float32 *dc, float32 *sm) 00217 { 00218 00219 int32 i, j, slpid, parmid; 00220 float32 egain_buf[9]; 00221 if ((slpid = attach_vdata(fid, "Electronics")) < 0) 00222 return RDERR; 00223 if ((rdvdata(slpid, gain_flds, index, 1, (unsigned char *)egain_buf)) < 0) 00224 return RDERR; 00225 VSdetach(slpid); 00226 for(i = 0; i < 8; i++) 00227 egain[i] = egain_buf[i]; 00228 *eoffset = egain_buf[8]; 00229 if ((slpid = attach_vdata(fid, "Mirror")) < 0) 00230 return RDERR; 00231 if ((rdvdata(slpid, mirror_flds, index, 1, (unsigned char *)mirror)) < 0) 00232 return RDERR; 00233 VSdetach(slpid); 00234 00235 if ((slpid = attach_vdata(fid, "Longterm")) < 0) 00236 return RDERR; 00237 if ((rdvdata(slpid, t_const_flds, index, 1, (unsigned char *)t_const)) < 0) 00238 return RDERR; 00239 if ((rdvdata(slpid, t_linear_flds, index, 1, (unsigned char *)t_linear)) < 0) 00240 return RDERR; 00241 if ((rdvdata(slpid, t_quadratic_flds, index, 1, (unsigned char *)t_quadratic)) < 0) 00242 return RDERR; 00243 VSdetach(slpid); 00244 if ((slpid = attach_vdata(fid, "TempCorr")) < 0) 00245 return RDERR; 00246 if ((rdvdata(slpid, temp_flds, index, 1, (unsigned char *)temp)) < 0) 00247 return RDERR; 00248 VSdetach(slpid); 00249 if ((slpid = attach_vdata(fid, "Slopes")) < 0) 00250 return RDERR; 00251 if ((rdvdata(slpid, slope_flds, index, 1, (unsigned char *)slope)) < 0) 00252 return RDERR; 00253 VSdetach(slpid); 00254 if ((slpid = attach_vdata(fid, "DCs")) < 0) 00255 return RDERR; 00256 if ((rdvdata(slpid, dc_flds, index, 1, (unsigned char *)dc)) < 0) 00257 return RDERR; 00258 VSdetach(slpid); 00259 if ((slpid = attach_vdata(fid, "ScanMod")) < 0) 00260 return RDERR; 00261 if ((rdvdata(slpid, sm_flds, index, 1, (unsigned char *)sm)) < 0) 00262 return RDERR; 00263 VSdetach(slpid); 00264 00265 return SUCCEED; 00266 } 00267
1.7.6.1