6 #define jul_day_1958 2436205
7 #define sec_per_day 86400
37 int month, dom, jul_day, hour,
min, sec, h5_stat;
38 int16_t lcl_margin[2];
40 struct tm *lcltime, init_tim, *new_tim;
46 if (
h5io_openr(ctl->in_geo_file, 0, &(in_rec->geo_fid)) != 0) {
47 printf(
"%s - could not open HDF 5 file: %s\n",
48 __FILE__, ctl->in_geo_file);
56 printf(
"%s, %d - Geo file indicates detailed scan format information\n",
58 if (
h5io_rd_attr(&(in_rec->geo_fid),
"scn_fmt", &(in_rec->scn_fmt))
60 printf(
"%s, %d - failed to read the scn_fmt attribute\n",
64 if ((in_rec->scn_fmt < 0) || (in_rec->scn_fmt > 2)) {
65 printf(
"%s, %d - scn_fmt attribute outside valid range\n",
69 if (
h5io_rd_attr(&(in_rec->geo_fid),
"ndet", &(in_rec->ndet_scan))
71 printf(
"%s, %d - failed to read the ndet attribute\n",
73 printf(
" (after reading scn_fmt attribute)\n");
76 if (
h5io_rd_attr(&(in_rec->geo_fid),
"margin", lcl_margin) != 0) {
77 printf(
"%s, %d - failed to read the margin attribute\n",
79 printf(
" (after reading scn_fmt attribute)\n");
82 in_rec->margin[0] = lcl_margin[0];
83 in_rec->margin[1] = lcl_margin[1];
86 in_rec->margin[0] = 0;
87 in_rec->margin[1] = 0;
88 in_rec->ndet_scan =
NDET;
90 printf(
"%s, %d - scn_fmt = %d, ndet_scan: %d, margin = %d %d\n",
91 __FILE__, __LINE__, in_rec->scn_fmt, in_rec->ndet_scan, in_rec->margin[0],
96 if (
h5io_rd_attr(&(in_rec->geo_fid),
"year", &(sdr_info->year))
98 printf(
"%s - failed to read the year attribute\n", __FILE__);
101 if (
h5io_rd_attr(&(in_rec->geo_fid),
"day", &(sdr_info->day))
103 printf(
"%s - failed to read the day attribute\n", __FILE__);
107 &(sdr_info->start_sec)) != 0) {
108 printf(
"%s - failed to read the start_sec attribute\n", __FILE__);
111 if (
h5io_rd_attr(&(in_rec->geo_fid),
"npix", &(in_rec->npix))
113 printf(
"%s - failed to read the npix attribute\n", __FILE__);
116 if (
h5io_rd_attr(&(in_rec->geo_fid),
"nlin", &(in_rec->nlin))
118 printf(
"%s - failed to read the nlin attribute\n", __FILE__);
121 if (
h5io_rd_attr(&(in_rec->geo_fid),
"nscan", &(in_rec->nscan))
123 printf(
"%s - failed to read the nscan attribute\n", __FILE__);
131 if ((sdr_info->geo_pos = (
float *) malloc(in_rec->nscan * 3 *
132 sizeof (
float))) ==
NULL) {
133 printf(
"%s:%d - failed to allocate space for geo_pos dataset\n", __FILE__,
137 if (
h5io_grab_ds(&(in_rec->geo_fid),
"pos", (
void *) sdr_info->geo_pos)
139 printf(
"%s:%d - failed to grab the geo_pos dataset\n", __FILE__,
144 if ((sdr_info->geo_vel = (
float *) malloc(in_rec->nscan * 3 *
145 sizeof (
float))) ==
NULL) {
146 printf(
"%s:%d - failed to allocate space for geo_vel dataset\n", __FILE__,
150 if (
h5io_grab_ds(&(in_rec->geo_fid),
"vel", (
void *) sdr_info->geo_vel)
152 printf(
"%s:%d - failed to grab the geo_vel dataset\n", __FILE__,
157 if ((sdr_info->scan_time =
158 (
double *) malloc(in_rec->nscan * sizeof (
double)))
160 printf(
"%s:%d - failed to allocate space for scan_time dataset\n",
165 (
void *) sdr_info->scan_time) != 0) {
166 printf(
"%s:%d - failed to grab the scan_time dataset\n", __FILE__,
171 if ((sdr_info->geo_att = (
float *) malloc(in_rec->nscan * 3 *
172 sizeof (
float))) ==
NULL) {
173 printf(
"%s:%d - failed to allocate space for geo_att dataset\n", __FILE__,
177 if (
h5io_grab_ds(&(in_rec->geo_fid),
"att_arr", (
void *) sdr_info->geo_att)
179 printf(
"%s:%d - failed to grab the geo_att dataset\n", __FILE__,
184 printf(
"%s: year, day, start_sec: %d %d %f\n", __FILE__, sdr_info->year,
185 sdr_info->day, sdr_info->start_sec);
186 printf(
"%s: npix, nlin, nscan: %d %d %d\n", __FILE__, in_rec->npix,
187 in_rec->nlin, in_rec->nscan);
192 day2mday(sdr_info->year, sdr_info->day, &month, &dom);
193 jul_day =
jd_c(sdr_info->year, month, dom);
198 sdr_info->st_58_t = sdr_info->t58_day + sdr_info->start_sec * 1.e6;
199 sdr_info->en_58_t = sdr_info->st_58_t +
SEC_PER_SCAN * in_rec->nscan * 1.e6;
206 if (strcmp(ctl->cre_time,
"Unspecified") == 0) {
208 lcltime = localtime(&sec_time);
209 sprintf(sdr_info->cre_date,
"%4.4d%2.2d%2.2d", lcltime->tm_year + 1900,
210 lcltime->tm_mon + 1, lcltime->tm_mday);
212 sprintf(sdr_info->cre_time,
"%2.2d%2.2d%2.2d.000000Z",
213 lcltime->tm_hour, lcltime->tm_min, lcltime->tm_sec);
215 strncpy(sdr_info->cre_date, ctl->cre_time, 8);
216 sdr_info->cre_date[8] = 0;
217 strncpy(sdr_info->cre_time, ctl->cre_time + 9, 13);
218 sdr_info->cre_time[13] =
'Z';
219 sdr_info->cre_time[14] = 0;
225 hour = (
int) (sdr_info->start_sec / 3600.);
226 min = (
int) (sdr_info->start_sec / 60.) % 60;
227 sec = (
int) (sdr_info->start_sec) % 60;
228 sprintf(sdr_info->ofile_base,
"%4.4d%3.3d%2.2d%2.2d%2.2d",
229 sdr_info->year, sdr_info->day, hour,
min, sec);
234 if (putenv(
"TZ=GMT 0") != 0) {
235 printf(
"%s, %d: GMT time zone switch error\n", __FILE__, __LINE__);
238 day2mday(sdr_info->year, sdr_info->day, &month, &dom);
239 sprintf(sdr_info->st_date,
"%4.4d%2.2d%2.2d", sdr_info->year,
241 st_sec = sdr_info->start_sec;
242 init_tim.tm_year = sdr_info->year - 1900;
243 init_tim.tm_mday = sdr_info->day;
245 init_tim.tm_hour = 0;
247 init_tim.tm_sec = (
int) st_sec;
248 init_tim.tm_isdst = 0;
249 extra_sec = 1.e6 * (st_sec - init_tim.tm_sec);
250 sec_time = mktime(&init_tim);
251 new_tim = localtime(&sec_time);
252 sprintf(sdr_info->st_time,
"%2.2d%2.2d%2.2d.%6.6ldZ", new_tim->tm_hour,
253 new_tim->tm_min, new_tim->tm_sec, extra_sec);
255 init_tim.tm_hour = 0;
259 extra_sec = 1.e6 * (st_sec + (in_rec->nscan - 1) *
SEC_PER_SCAN
262 sec_time = mktime(&init_tim);
263 new_tim = localtime(&sec_time);
265 if (unsetenv(
"TZ") != 0) {
266 printf(
"%s, %d: GMT time zone unset error\n", __FILE__, __LINE__);
270 sprintf(sdr_info->en_date,
"%4.4d%2.2d%2.2d", new_tim->tm_year + 1900,
271 new_tim->tm_mon + 1, new_tim->tm_mday);
272 sprintf(sdr_info->en_time,
"%2.2d%2.2d%2.2d.%6.6ldZ", new_tim->tm_hour,
273 new_tim->tm_min, new_tim->tm_sec, extra_sec);