Go to the documentation of this file.
11 #include <sys/types.h>
50 long* numExistingRecords,
caltype ctype) {
54 *numExistingRecords = 0;
56 int start[3] = {0, 0, 0};
57 int stride[3] = {1, 1, 1};
58 int count[3] = {1, 1, 0};
64 nvars1d, l2prods, vars1Dnames, ctype);
66 printf(
"Whoops! problem creating output file %s\n",
ofile);
75 "Sorry, Charlie, output file %s already exists, but does not contain fileID array...try a new output file\n",
85 *numExistingRecords = dm[0];
89 char *oldfile = (
char *) malloc(strlen(
ofile) + 5);
91 strcat(oldfile,
".old");
93 sprintf(
cmd,
"mv %s %s",
ofile, oldfile);
96 ydim += *numExistingRecords;
98 nvars1d, l2prods, vars1Dnames, ctype);
100 printf(
"Whoops! problem creating output file %s\n",
ofile);
106 old_ds_id =
openDS(oldfile);
108 printf(
"Whoops! problem opening old file %s\n", oldfile);
120 for (
i = 0;
i < fileIDold + 1;
i++) {
121 sprintf(
name,
"filename%03d",
i);
149 for (
i = 0;
i < nvars1d;
i++) {
178 for (
i = 0;
i < nprods;
i++) {
180 for (
j = 0;
j < nvars1d;
j++) {
181 if (strcmp(l2prods[
i], vars1Dnames[
j]) == 0) {
186 if (skip == 0 && strcmp(l2prods[
i],
"pixnum") != 0
187 && strcmp(l2prods[
i],
"mside") != 0
188 && strcmp(l2prods[
i],
"detnum") != 0
189 && strcmp(l2prods[
i],
"l2_flags") != 0) {
198 sprintf(
cmd,
"rm -f %s", oldfile);
231 int nprods,
int nvars1d,
char l2prods[
L1_MAXPROD][32],
240 const char dm_name[3][80];
246 strcpy((
char *) dm_name[0],
"runs");
247 strcpy((
char *) dm_name[1],
"detectors");
249 "%s Level-1 detector/mirror-side runs of consecutive pixels",
253 strcpy((
char *) dm_name[0],
"pixels");
254 strcpy((
char *) dm_name[1],
"xdim");
255 sprintf(
title,
"%s Level-2 cross-calibration pixels",
259 strcpy((
char *) dm_name[0],
"pixels");
260 strcpy((
char *) dm_name[1],
"L2L3");
261 sprintf(
title,
"%s Level-2/3 matched pixels",
265 fprintf(
stderr,
"Unknown caltype! \n");
270 if (strcmp(
input->oformat,
"netCDF4") == 0) {
272 for (
i = 0;
i < 2;
i++) {
273 status = nc_def_dim((*ds_id).fid, dm_name[
i], dm[
i], &dumdim);
303 for (
i = 0;
i < nvars1d;
i++) {
311 for (
i = 0;
i < nprods;
i++) {
313 for (
j = 0;
j < nvars1d;
j++) {
314 if (strcmp(l2prods[
i], vars1Dnames[
j]) == 0) {
319 if (skip == 0 && strcmp(l2prods[
i],
"pixnum") != 0
320 && strcmp(l2prods[
i],
"mside") != 0
321 && strcmp(l2prods[
i],
"detnum") != 0
322 && strcmp(l2prods[
i],
"l2_flags") != 0) {
353 static int firstWrite = 1;
354 static l2prodstr** prodptr;
358 static productInfo_t **v1Dp_info;
359 static productInfo_t **p_info;
362 if ((v1Dp_info = (productInfo_t **) malloc(nvars1d *
sizeof (
struct productInfo_t *))) ==
NULL) {
363 printf(
"%s -Error: Cannot allocate memory to productInfo data\n",
367 if ((p_info = (productInfo_t **) malloc(nprods *
sizeof (
struct productInfo_t *))) ==
NULL) {
368 printf(
"%s -Error: Cannot allocate memory to productInfo data\n",
372 rdsensorinfo(calrec->sensorID, 0,
"iwave", (
void **) &iwave_p);
374 iwave[
i] = iwave_p[
i];
376 if ((prodptr = (l2prodstr **) malloc(
L1_MAXPROD *
sizeof (l2prodstr *)))
379 "-E- : Error allocating memory for product info record structures\n");
382 for (
i = 0;
i < nprods;
i++) {
385 printf(
"%s not found in XML product table\n", l2prods[
i]);
390 fprintf(
stderr,
"-E- %s line %d: product index failure.\n",
395 for (
i = 0;
i < nvars1d;
i++) {
398 printf(
"%s not found in XML product table\n", vars1Dnames[
i]);
404 fprintf(
stderr,
"-E- %s line %d: product index failure.\n",
413 PTB(
writeDS(ds_id,
"year", (VOIDP) & (calrec->year),
recnum, 0, 0, 1, 1, 1));
415 PTB(
writeDS(ds_id,
"msec", (VOIDP) & (calrec->msec),
recnum, 0, 0, 1, 1, 1));
416 PTB(
writeDS(ds_id,
"iscan", (VOIDP) & (calrec->iscan),
recnum, 0, 0, 1, 1, 1));
417 for (
i = 0;
i < nvars1d;
i++) {
419 if ((v1Dp_info[
i])->scaleFactor == 1.0 && (v1Dp_info[
i])->addOffset == 0.0)
420 pbuf = (VOIDP) & calrec->vars1D[
i];
425 for (
i = 0;
i < xdim;
i++) {
426 PTB(
writeDS(ds_id,
"pixnum", (VOIDP) & (calrec->pixnum),
recnum,
i, 0, 1, 1, 1));
428 PTB(
writeDS(ds_id,
"mside", (VOIDP) & (calrec->mside),
recnum, 0, 0, 1, 1, 1));
431 PTB(
writeDS(ds_id,
"detnum", (VOIDP) & (calrec->detnum),
recnum, 0, 0, 1, 1, 1));
435 for (
i = 0;
i < nprods;
i++) {
437 for (
j = 0;
j < nvars1d;
j++) {
438 if (strcmp(l2prods[
i], vars1Dnames[
j]) == 0) {
443 if (skip == 0 && strcmp(l2prods[
i],
"pixnum") != 0
444 && strcmp(l2prods[
i],
"mside") != 0
445 && strcmp(l2prods[
i],
"detnum") != 0
446 && strcmp(l2prods[
i],
"l2_flags") != 0) {
448 if (strncmp(l2prods[
i],
"Lt", 2) == 0) {
449 pbuf = (VOIDP) calrec->Lt[Ltix++];
450 }
else if (strncmp(l2prods[
i],
"vLt", 3) == 0) {
451 pbuf = (VOIDP) calrec->vLt[vLtix++];
453 if ((p_info[
i])->scaleFactor == 1.0 && (p_info[
i])->addOffset == 0.0)
454 pbuf = (VOIDP) calrec->data[
i];
490 for (kscan =
iscan; kscan <
iscan + ndets; kscan++) {
518 calstr* record = calloc(1,
sizeof (calstr));
521 if ((record->Lt = (
float **) malloc(
nbands *
sizeof (
float *))) ==
NULL) {
522 printf(
"%s -Error: Cannot allocate memory to detector data\n",
526 if ((record->vLt = (
float **) malloc(
nbands *
sizeof (
float *))) ==
NULL) {
527 printf(
"%s -Error: Cannot allocate memory to detector data\n",
532 if ((record->data = (
float **) malloc(nprods *
sizeof (
float *))) ==
NULL) {
533 printf(
"%s -Error: Cannot allocate memory to detector data\n",
538 if ((record->vars1D = (
float *) calloc(nvar1d,
sizeof (
float))) ==
NULL) {
539 printf(
"%s -Error: Cannot allocate memory to 1D data array\n",
546 if ((record->Lt[
band] = (
float *) calloc(ydim,
sizeof (
float)))
548 printf(
"%s -Error: Cannot allocate memory to detector data\n",
552 if ((record->vLt[
band] = (
float *) calloc(ydim,
sizeof (
float)))
554 printf(
"%s -Error: Cannot allocate memory to detector data\n",
560 for (prod = 0; prod < nprods; prod++) {
561 if ((record->data[prod] = (
float *) calloc(ydim,
sizeof (
float)))
563 printf(
"%s -Error: Cannot allocate memory to detector data\n",
581 free(calrec->Lt[
band]);
582 free(calrec->vLt[
band]);
584 for (prod = 0; prod < nprods; prod++) {
585 free(calrec->data[prod]);
590 free(calrec->vars1D);
int getDimsDS(idDS ds_id, const char sdsname[], int32_t dims[])
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)
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second band
int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3], const char dm_name[3][80])
char * readAttrStr(idDS ds_id, const char *name)
productInfo_t * allocateProductInfo()
idDS startDS(const char *filename, ds_format_t format, ds_access_t accessmode, int32_t deflate)
void free_prodptr(l2prodstr **p)
void free_calrec(calstr *calrec, int nbands, int nprods)
int writeDS(idDS ds_id, const char *name, const void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
int readDS(idDS ds_id, const char *name, int32_t *start, int32_t *stride, int32_t *count, void *data)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
int SetI32GA(idDS ds_id, const char *name, int32_t value)
int findProductInfo(const char *productName, int sensorId, productInfo_t *info)
calstr * alloc_calrec(int ydim, int nbands, int nprods, int nvar1d)
void inversion_init(long ndets, long iscan, int nbands, long ipix, aestr *aerec, tgstr *tgrec)
const char * sensorId2SensorName(int sensorId)
int SetChrGA(idDS ds_id, const char *name, const char *value)
void * scale_sds(float *data, productInfo_t *p, int32_t npix)
This should be set to the NetCDF standard name if exists for this product Create a function that computes your product edit get_myprod c add prototype to l12_proto h add get_myprod c to add_executable for l2gen and l3gen in CMakeLists txt Add an entry to the output routine to call your function edit prodgen c edit function prodgen() case CAT_myprod pbuf
int calfile_create(char *ofile, idDS *ds_id, int sensorID, int ydim, int xdim, int nprods, int nvars1d, char l2prods[L1_MAXPROD][32], char vars1Dnames[L1_MAXPROD][32], caltype ctype)
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)
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]
int32_t get_l2prod_index(const l2_prod &l2, const char *prodname)