Go to the documentation of this file.
30 #include <sys/types.h>
47 #define NOVALIDPIX 111
54 int main(
int argc,
char *argv[]) {
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",
154 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
157 printf(
"-E- %s: Error reading L2 data %s.\n", argv[0],
input->ifile[0]);
163 if (l2_str.mside ==
NULL) {
164 printf(
"-E- %s: mside is missing from the L2 data file %s.\n", argv[0],
168 if (l2_str.detnum ==
NULL) {
169 printf(
"-E- %s: detnum is missing from the L2 data file %s.\n", argv[0],
173 if (l2_str.pixnum ==
NULL) {
174 printf(
"-E- %s: pixnum is missing from the L2 data file %s.\n", argv[0],
185 for (
j = 0;
j < l2_str.nprod;
j++) {
186 if (strncmp(l2_str.prodname[
j],
"l2_flags", 8) == 0)
188 if (strncmp(l2_str.prodname[
j],
"Lt_", 3) == 0) {
192 if (strncmp(l2_str.prodname[
j],
"vLt_", 4) == 0) {
199 "-E- %s: Lt TOA calibration data are missing from the L2 data file %s.\n",
200 argv[0], l2_str.filename);
205 "-E- %s: vLt TOA calibration data are missing from the L2 data file %s.\n",
206 argv[0], l2_str.filename);
211 nprods = l2_str.nprod;
213 strcpy(vars1Dnames[0],
"lon");
214 strcpy(vars1Dnames[1],
"lat");
221 strcat(l2_flags, l2_flag_lname[
i]);
223 strcat(l2_flags,
",\0");
225 l = strlen(l2_flags);
228 printf(
"-E- %s: Error setting up L2 flags.\n", argv[0]);
240 for (
i = 0;
i < nprods;
i++) {
241 strcpy(outprod[
i], l2_str.prodname[
i]);
244 printf(
"\n%s: Appending file: %s.\n", argv[0],
input->ifile[0]);
264 printf(
"-E- %s: scan and pixel limits make no sense.\n", argv[0]);
265 printf(
" start scan = %d\n", sscan + 1);
266 printf(
" end scan = %d\n", escan + 1);
267 printf(
" start pixel = %d\n",
spix + 1);
268 printf(
" end pixel = %d\n",
epix + 1);
273 nscan = (escan - sscan) / dscan + 1;
275 int quarterscans = floor(
nscan / 4);
277 if ((iptr = (int8 *) malloc(
nscan *
sizeof (int8))) ==
NULL) {
278 printf(
"-E- %s: Error allocating memory to the pixel index.\n",
288 printf(
"%s: Error reading L2 data file %s at scan %d.\n", argv[0],
289 l2_str.filename,
iscan);
292 if ((
iscan % quarterscans) == 0)
293 printf(
"Selecting valid pixels for scan %d\n",
iscan);
299 if (((l2_str.l2_flags[ipix] & flagusemask) == 0)
300 && (l2_str.l2_data[vLtinx][ipix] > 0.0)) {
309 "%s: Error: Incorrect number of pixels %d obtained in the scan %d.\n",
310 argv[0], opix, oscan);
320 printf(
"Number of valid cross-calibration pixels %d in file %s\n", npixs,
329 vars1Dnames, &runCounter,
CROSSCAL);
333 if ((calrecArray = (calstr **) malloc(npixs *
sizeof (calstr *)))
336 "-E- : Error allocating memory for crosscal record structures\n");
339 for (
j = 0;
j < npixs;
j++) {
349 if ((
iscan % quarterscans) == 0)
350 printf(
"Storing pixels at scan %d\n",
iscan);
354 printf(
"%s: Error reading L2 data file %s at scan %d.\n",
355 argv[0], l2_str.filename,
iscan);
362 if (((l2_str.l2_flags[ipix] & flagusemask) == 0)
363 && (l2_str.l2_data[Ltinx][ipix] > 0.0)
364 && (l2_str.l2_data[Ltinx][ipix] < 10000.)
365 && (l2_str.l2_data[vLtinx][ipix] > 0.0)) {
367 calrecArray[np]->sensorID =
sensorID;
368 calrecArray[np]->year = (
int16) l2_str.year;
369 calrecArray[np]->day = (
int16) l2_str.day;
370 calrecArray[np]->msec = (int32) l2_str.msec;
372 calrecArray[np]->mside = (int32) (l2_str.mside[
iscan]);
373 calrecArray[np]->detnum = (int32) (l2_str.detnum[
iscan]);
374 calrecArray[np]->pixnum = (int32) (l2_str.pixnum[ipix]);
375 calrecArray[np]->vars1D[0] = l2_str.longitude[ipix];
376 calrecArray[np]->vars1D[1] = l2_str.latitude[ipix];
378 calrecArray[np]->Lt[
j][0] =
379 (
float) l2_str.l2_data[Ltinx +
j][ipix];
380 calrecArray[np]->vLt[
j][0] =
381 (
float) l2_str.l2_data[vLtinx +
j][ipix];
384 for (
j = 0;
j < nprods;
j++) {
385 if (strcmp(l2_str.prodname[
j],
"pixnum") != 0
386 && strcmp(l2_str.prodname[
j],
"mside") != 0
387 && strncmp(l2_str.prodname[
j],
"Lt", 2) != 0
388 && strncmp(l2_str.prodname[
j],
"vLt", 3) != 0
389 && strcmp(l2_str.prodname[
j],
"detnum") != 0
390 && strcmp(l2_str.prodname[
j],
"l2_flags") != 0) {
393 calrecArray[np]->data[
j][0] = l2_str.l2_data[
j][ipix];
408 "%s: Error: Incorrect number of pixels %d obtained in the scan %d.\n",
409 argv[0], opix, oscan);
414 for (
j = 0;
j < np;
j++) {
424 for (
i = 0;
i < np;
i++) {
433 printf(
"Trouble closing file %s\n",
input->ofile[0]);
436 printf(
"Completed processing file %s\n",
input->ifile[0]);
439 printf(
"Completed processing file %s, but no valid pixels were found\n",
input->ifile[0]);
int32_t openL2(const char *fname, char *plist, l2_prod *l2_str)
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)
void setupflags(char *flagdef, char *flaguse, uint32_t *flagusemask, uint32_t *required, int *status)
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]