12 static int16_t nline,
npix;
14 static int32_t
spix = 0;
16 static double *scan_start_tai, *scan_stop_tai;
17 static double time_interval;
22 size_t source_w, source_h, source_b;
24 int fileID, xid, yid, band_id, retval, grp_id, sds_id;
29 retval = nc_open(
file->name, NC_NOWRITE, &
fileID);
30 if (retval != NC_NOERR) {
31 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
32 __FILE__, __LINE__,
file->name);
37 retval = nc_inq_dimid(
fileID,
"number_of_scans", &yid);
38 retval = nc_inq_dimid(
fileID,
"number_of_pixels", &xid);
39 retval = nc_inq_dimid(
fileID,
"number_of_bands", &band_id);
40 retval = nc_inq_dimlen(
fileID, xid, &source_w);
41 retval = nc_inq_dimlen(
fileID, yid, &source_h);
42 retval = nc_inq_dimlen(
fileID, band_id, &source_b);
45 printf(
"OCIA L1B Npix :%d Nscans:%d\n", (
int) source_w,
48 npix = (int32_t) source_w;
49 nscan = (int32_t) source_h;
55 file->nbands = source_b;
58 scan_start_tai = (
double *) calloc(
nscan,
sizeof (
double));
59 scan_stop_tai = (
double *) calloc(
nscan,
sizeof (
double));
60 alt = (
float *) calloc(
nscan,
sizeof (
float));
69 nc_inq_ncid(
file->sd_id,
"scan_line_attributes", &grp_id);
71 retval = nc_inq_varid(grp_id,
"altitude", &sds_id);
72 retval = nc_get_vara_float(grp_id, sds_id,
start,
count, alt);
73 if (retval != NC_NOERR) {
75 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
76 __FILE__, __LINE__,
file->name,
"altitude");
80 retval = nc_inq_varid(grp_id,
"scan_start_time", &sds_id);
81 retval = nc_get_vara_double(grp_id, sds_id,
start,
count, scan_start_tai);
82 if (retval != NC_NOERR) {
84 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
85 __FILE__, __LINE__,
file->name,
"scan_start_time");
89 int iscan = 0, i1, i2;
92 if (scan_start_tai[
iscan] > 0) {
93 if (starttime > scan_start_tai[
iscan])starttime = scan_start_tai[
iscan];
106 if (scan_start_tai[
iscan] > 0) {
114 time_interval = (
stoptime - starttime) / ((i2 - i1) + 1);
125 static int firstCall = 1;
129 int32_t ip, ib, ipb, Ibp;
137 printf(
"file->nbands = %d, l1rec->nbands = %d\n",
138 (
int)
file->nbands, (
int)
l1rec->l1file->nbands);
141 for (ip = 0; ip <
npix; ip++) {
142 l1rec->pixnum[ip] = ip;
143 l1rec->flags[ip] = 0;
162 retval = nc_inq_ncid(
file->sd_id,
"geolocation_data", &grp_id);
163 if (retval != NC_NOERR) {
165 "-E- %s line %d: nc_inq_ncid failed for file, %s group, %s.\n",
166 __FILE__, __LINE__,
file->name,
"geolocation_data");
177 lon = (
float *) calloc(
npix,
sizeof (
float));
178 lat = (
float *) calloc(
npix,
sizeof (
float));
179 senz = (
float *) calloc(
npix,
sizeof (
float));
180 sena = (
float *) calloc(
npix,
sizeof (
float));
181 solz = (
float *) calloc(
npix,
sizeof (
float));
182 sola = (
float *) calloc(
npix,
sizeof (
float));
184 retval = nc_inq_varid(grp_id,
"longitude", &band_id);
185 if (retval != NC_NOERR) {
187 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
188 __FILE__, __LINE__,
file->name,
"longitude");
191 retval = nc_get_vara_float(grp_id, band_id,
start,
count,
lon);
192 if (retval != NC_NOERR) {
194 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
195 __FILE__, __LINE__,
file->name,
"longitude");
198 retval = nc_inq_varid(grp_id,
"latitude", &band_id);
199 if (retval != NC_NOERR) {
201 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
202 __FILE__, __LINE__,
file->name,
"latitude");
205 retval = nc_get_vara_float(grp_id, band_id,
start,
count,
lat);
206 if (retval != NC_NOERR) {
208 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
209 __FILE__, __LINE__,
file->name,
"latitude");
216 l1rec->solz[ip] = -999;
217 l1rec->sola[ip] = -999;
218 l1rec->senz[ip] = -999;
219 l1rec->sena[ip] = -999;
222 retval = nc_inq_varid(grp_id,
"sensor_azimuth", &band_id);
224 if (retval != NC_NOERR) {
226 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
227 __FILE__, __LINE__,
file->name,
"sensor_azimuth");
230 retval = nc_inq_varid(grp_id,
"sensor_zenith", &band_id);
232 if (retval != NC_NOERR) {
234 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
235 __FILE__, __LINE__,
file->name,
"sensor_zenith");
238 retval = nc_inq_varid(grp_id,
"solar_azimuth", &band_id);
240 if (retval != NC_NOERR) {
242 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
243 __FILE__, __LINE__,
file->name,
"solar_azimuth");
246 retval = nc_inq_varid(grp_id,
"solar_zenith", &band_id);
248 if (retval != NC_NOERR) {
250 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
251 __FILE__, __LINE__,
file->name,
"solar_zenith");
265 rad_data = (
float *) calloc(
npix*
nbands,
sizeof (
float));
274 nc_inq_ncid(
file->sd_id,
"observation_data", &grp_id);
276 retval = nc_inq_varid(grp_id,
"Lt", &band_id);
277 retval = nc_get_vara_float(grp_id, band_id,
start,
count, rad_data);
278 if (retval != NC_NOERR) {
280 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
281 __FILE__, __LINE__,
file->name,
"Lt_visnir");
285 for (ib = 0; ib <
nbands; ib++) {
290 Ibp = ib *
npix + ip;
291 l1rec->Lt[ipb] = rad_data[Ibp];
295 if (
l1rec->Lt[ipb] < 0.0) {
296 l1rec->Lt[ipb] = 0.0001;
312 l1rec->l1file->sensorID =
file->sensorID;
321 retval = nc_close(
file->sd_id);
322 if (retval != NC_NOERR) {
323 fprintf(
stderr,
"-E- %s line %d: nc_close failed for file, %s.\n",
324 __FILE__, __LINE__,
file->name);
327 free(scan_start_tai);