16 } AM2_COMMON_SCANTIME
;
18 void amsr2time_(int *num
, double *tai93
, AM2_COMMON_SCANTIME
*st
){
19 // structure for leap second
27 char *fn
= "leapsec.dat"; // leap second file name
30 int i
, j
; // loop variable
31 char *ret
; // return status
32 char buf
[512]; // text buffer
33 short ibuf
; // integer buffer
34 double rbuf
; // real buffer
35 FILE *hnd
; // file handle
38 short lnum
; // number of leap second from 1993
39 LEAP_SECOND
*ldat
; // leap second data from 1993
41 // leap second working variable
42 int lcnt
; // leap second count
43 int flag
; // strike flag
44 time_t utime
; // unix epoch time
45 struct tm
*stmp
; // struct tm pointer
50 printf("amsr2time: leap second file leapsec.dat open error\n");
54 // count leap second entry
58 ret
= fgets(buf
, 512, hnd
);
61 if(ret
== NULL
) break;
65 sscanf(buf
, "%hd", &ibuf
);
72 // read leap second data
73 ldat
= malloc(sizeof(LEAP_SECOND
) * lnum
);
78 ret
= fgets(buf
, 512, hnd
);
81 if(ret
== NULL
) break;
85 sscanf(buf
, "%hd", &ibuf
);
87 sscanf(buf
, "%hd %hd %lf %lf %lf %lf"
95 // printf("amsr2time: year=%4d month=%2d tai93sec=%14.2lf\n"
104 // printf("amsr2time: number of leap second = %d\n", lnum);
110 for(i
= 0; i
< *num
; ++i
){
111 // negative value is warning
113 printf("amsr2time: negative value warning: "
114 "%14.2lf (scan_by_1origin=%04d)\n", tai93
[i
],i
+1);
115 st
[i
].tai93sec
= tai93
[i
];
127 // check leap second & strike
130 for(j
= lnum
- 1; j
>= 0; --j
){
131 if(tai93
[i
] >= ldat
[j
].tai93sec
){
135 else if(tai93
[i
] >= ldat
[j
].tai93sec
- 1){
142 // convert unix epoch time
143 utime
= tai93
[i
] + 725846400 - lcnt
;
146 stmp
= gmtime(&utime
);
148 // store result in AM2_COMMON_SCANTIME
149 st
[i
].tai93sec
= tai93
[i
];
150 st
[i
].year
= stmp
->tm_year
+ 1900;
151 st
[i
].month
= stmp
->tm_mon
+ 1;
152 st
[i
].day
= stmp
->tm_mday
;
153 st
[i
].hour
= stmp
->tm_hour
;
154 st
[i
].minute
= stmp
->tm_min
;
155 st
[i
].second
= stmp
->tm_sec
;
156 st
[i
].ms
= (int)((tai93
[i
] - (long int)tai93
[i
]) * 1000 + 0.5);
161 // convert unix epoch time
162 utime
= tai93
[i
] + 725846400 - lcnt
- 1;
165 stmp
= gmtime(&utime
);
167 // store result in AM2_COMMON_SCANTIME
168 st
[i
].tai93sec
= tai93
[i
];
169 st
[i
].year
= stmp
->tm_year
+ 1900;
170 st
[i
].month
= stmp
->tm_mon
+ 1;
171 st
[i
].day
= stmp
->tm_mday
;
172 st
[i
].hour
= stmp
->tm_hour
;
173 st
[i
].minute
= stmp
->tm_min
;
175 st
[i
].ms
= (tai93
[i
] - (long int)tai93
[i
]) * 1000 + 0.5;