Go to the documentation of this file.
30 #include <sys/types.h>
47 #define NOVALIDPIX 111
69 int32_t
i,
j, l, np, Ltinx, vLtinx;
71 static int opened = 0;
80 uint32_t required_mask;
85 char vars1Dnames[nvars1d][32];
106 printf(
"-E- %s: Error parsing input parameters.\n", argv[0]);
110 if (
input->ifile[0][0] ==
'\0') {
111 printf(
"-E- %s: No L2 file provided, exiting...\n", argv[0]);
115 if (access(
input->ifile[0], F_OK) || access(
input->ifile[0], R_OK)) {
116 printf(
"-E- %s: Input file '%s' does not exist or cannot open.\n",
117 argv[0],
input->ifile[0]);
127 int existingSensorID;
132 void *old_client_data;
133 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
136 H5Eset_auto(H5E_DEFAULT,
NULL,
NULL);
142 printf(
"-E- %s: Problem reading output file: %s\n", argv[0],
input->ofile[0]);
147 printf(
"-E- %s: Mixing L2 data from different sensors, %s and %s.\n",
155 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
158 printf(
"-E- %s: Error reading L2 data %s.\n", argv[0],
input->ifile[0]);
166 if (l2_str.mside ==
NULL) {
167 printf(
"-E- %s: mside is missing from the L2 data file %s.\n", argv[0],
171 if (l2_str.detnum ==
NULL) {
172 printf(
"-E- %s: detnum is missing from the L2 data file %s.\n", argv[0],
176 if (l2_str.pixnum ==
NULL) {
177 printf(
"-E- %s: pixnum is missing from the L2 data file %s.\n", argv[0],
188 for (
j = 0;
j < l2_str.nprod;
j++) {
189 if (strncmp(l2_str.prodname[
j],
"l2_flags", 8) == 0)
191 if (strncmp(l2_str.prodname[
j],
"Lt_", 3) == 0) {
195 if (strncmp(l2_str.prodname[
j],
"vLt_", 4) == 0) {
202 "-E- %s: Lt TOA calibration data are missing from the L2 data file %s.\n",
203 argv[0], l2_str.filename);
208 "-E- %s: vLt TOA calibration data are missing from the L2 data file %s.\n",
209 argv[0], l2_str.filename);
214 nprods = l2_str.nprod;
216 strcpy(vars1Dnames[0],
"lon");
217 strcpy(vars1Dnames[1],
"lat");
222 strcpy(l2_flags, l2_str.flagnames);
223 l = strlen(l2_flags);
226 printf(
"-E- %s: Error setting up L2 flags.\n", argv[0]);
237 for (
i = 0;
i < nprods;
i++) {
238 strcpy(outprod[
i], l2_str.prodname[
i]);
241 printf(
"\n%s: Appending file: %s.\n", argv[0],
input->ifile[0]);
261 printf(
"-E- %s: scan and pixel limits make no sense.\n", argv[0]);
262 printf(
" start scan = %d\n", sscan + 1);
263 printf(
" end scan = %d\n", escan + 1);
264 printf(
" start pixel = %d\n",
spix + 1);
265 printf(
" end pixel = %d\n",
epix + 1);
270 nscan = (escan - sscan) / dscan + 1;
272 int quarterscans = floor(
nscan / 4);
274 if ((iptr = (int8 *) malloc(
nscan *
sizeof (int8))) ==
NULL) {
275 printf(
"-E- %s: Error allocating memory to the pixel index.\n",
285 printf(
"%s: Error reading L2 data file %s at scan %d.\n", argv[0],
286 l2_str.filename,
iscan);
289 if ((
iscan % quarterscans) == 0)
290 printf(
"Selecting valid pixels for scan %d\n",
iscan);
296 if (((l2_str.l2_flags[ipix] & flagusemask) == 0)
297 && (l2_str.l2_data[vLtinx][ipix] > 0.0)) {
306 "%s: Error: Incorrect number of pixels %d obtained in the scan %d.\n",
307 argv[0], opix, oscan);
317 printf(
"Number of valid cross-calibration pixels %d in file %s\n", npixs,
326 vars1Dnames, &runCounter,
CROSSCAL);
330 if ((calrecArray = (calstr **) malloc(npixs *
sizeof (calstr *)))
333 "-E- : Error allocating memory for crosscal record structures\n");
336 for (
j = 0;
j < npixs;
j++) {
346 if ((
iscan % quarterscans) == 0)
347 printf(
"Storing pixels at scan %d\n",
iscan);
351 printf(
"%s: Error reading L2 data file %s at scan %d.\n",
352 argv[0], l2_str.filename,
iscan);
359 if (((l2_str.l2_flags[ipix] & flagusemask) == 0)
360 && (l2_str.l2_data[Ltinx][ipix] > 0.0)
361 && (l2_str.l2_data[Ltinx][ipix] < 10000.)
362 && (l2_str.l2_data[vLtinx][ipix] > 0.0)) {
364 calrecArray[np]->sensorID =
sensorID;
365 calrecArray[np]->year = (
int16) l2_str.year;
366 calrecArray[np]->day = (
int16) l2_str.day;
367 calrecArray[np]->msec = (int32) l2_str.msec;
369 calrecArray[np]->mside = (int32) (l2_str.mside[
iscan]);
370 calrecArray[np]->detnum = (int32) (l2_str.detnum[
iscan]);
371 calrecArray[np]->pixnum = (int32) (l2_str.pixnum[ipix]);
372 calrecArray[np]->vars1D[0] = l2_str.longitude[ipix];
373 calrecArray[np]->vars1D[1] = l2_str.latitude[ipix];
375 calrecArray[np]->Lt[
j][0] =
376 (
float) l2_str.l2_data[Ltinx +
j][ipix];
377 calrecArray[np]->vLt[
j][0] =
378 (
float) l2_str.l2_data[vLtinx +
j][ipix];
381 for (
j = 0;
j < nprods;
j++) {
382 if (strcmp(l2_str.prodname[
j],
"pixnum") != 0
383 && strcmp(l2_str.prodname[
j],
"mside") != 0
384 && strncmp(l2_str.prodname[
j],
"Lt", 2) != 0
385 && strncmp(l2_str.prodname[
j],
"vLt", 3) != 0
386 && strcmp(l2_str.prodname[
j],
"detnum") != 0
387 && strcmp(l2_str.prodname[
j],
"l2_flags") != 0) {
390 calrecArray[np]->data[
j][0] = l2_str.l2_data[
j][ipix];
405 "%s: Error: Incorrect number of pixels %d obtained in the scan %d.\n",
406 argv[0], opix, oscan);
411 for (
j = 0;
j < np;
j++) {
421 for (
i = 0;
i < np;
i++) {
430 printf(
"Trouble closing file %s\n",
input->ofile[0]);
433 printf(
"Completed processing file %s\n",
input->ifile[0]);
436 printf(
"Completed processing file %s, but no valid pixels were found\n",
input->ifile[0]);
void setupflags(char *flagdef, char *flaguse, uint32_t *flagusemask, uint32_t *required, int *status, int32_t *BITS)
int msl12_input(int argc, char *argv[], const char *progName, filehandle *l1file)
idDS openDS(const char *filename)
int calfile_write(idDS ds_id, calstr *calrec, int recnum, int ydim, int xdim, int nprods, int nbands, int nvars1d, char l2prods[L1_MAXPROD][32], char vars1Dnames[L1_MAXPROD][32], caltype ctype)
void filehandle_init(filehandle *file)
int32_t readL2(l2_prod *l2_str, int32_t ifile, int32_t recnum, int32_t iprod, unsigned char *scan_in_rowgroup)
int l2gen_usage(const char *prog)
int readAttr(idDS ds_id, const char *nam, void *data)
int32_t openL2(const char *fname, const char *plist, l2_prod *l2_str)
void free_calrec(calstr *calrec, int nbands, int nprods)
int main(int argc, char *argv[])
calstr * alloc_calrec(int ydim, int nbands, int nprods, int nvar1d)
const char * sensorId2SensorName(int sensorId)
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
int calfile_close(idDS ds_id)
idDS calfile_open(char *ofile, int sensorID, int ydim, int xdim, int nprods, int nvars1d, char l2prods[L1_MAXPROD][32], char vars1Dnames[L1_MAXPROD][32], long *numExistingRecords, caltype ctype)
int32 l2file(int32 sdfid, int32 *nsamp, int32 *nscans, char *dtype)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int32_t sensorID[MAXNFILES]