16 #define ARRAY_CHUNK_SIZE 20
18 static l2prodstr **l2prod_array =
NULL;
19 static int l2prod_num = 0;
20 static int l2prod_storage = 0;
25 l2prod->name_prefix[0] =
'\0';
26 l2prod->name_suffix[0] =
'\0';
35 strcpy(l2prod->title_format,
"no title format yet (%d)");
36 strcpy(l2prod->title,
"no title yet");
37 strcpy(l2prod->units,
"undefined units");
39 l2prod->product_id[0] =
'\0';
40 l2prod->algorithm_id[0] =
'\0';
41 l2prod->standard_name[0] =
'\0';
50 l2prodstr* l2prod = (l2prodstr*) malloc(
sizeof (l2prodstr));
56 if (l2prod_num > l2prod_storage) {
58 l2prod_array = (l2prodstr**) realloc(l2prod_array, l2prod_storage *
sizeof (l2prodstr*));
60 l2prod_array[l2prod_num - 1] = l2prod;
67 if (strcmp(
str,
"byte") == 0)
69 if (strcmp(
str,
"ubyte") == 0)
71 if (strcmp(
str,
"short") == 0)
73 if (strcmp(
str,
"ushort") == 0)
75 if (strcmp(
str,
"int") == 0)
77 if (strcmp(
str,
"uint") == 0)
79 if (strcmp(
str,
"float") == 0)
81 if (strcmp(
str,
"double") == 0)
88 if (strcmp(
str,
"none") == 0)
90 if (strcmp(
str,
"wave") == 0)
92 if (strcmp(
str,
"uv") == 0)
94 if (strcmp(
str,
"visible") == 0)
96 if (strcmp(
str,
"nir") == 0)
98 if (strcmp(
str,
"swir") == 0)
100 if (strcmp(
str,
"emissive") == 0)
102 if (strcmp(
str,
"band") == 0)
104 if (strcmp(
str,
"int") == 0)
143 if (prod1->param_type != prod2->param_type) {
145 printf(
"param_type %d=%d\n", prod1->param_type, prod2->param_type);
147 if (strcmp(prod1->name_prefix, prod2->name_prefix)) {
149 printf(
"name_prefix %s=%s\n", prod1->name_prefix, prod2->name_prefix);
151 if (strcmp(prod1->name_suffix, prod2->name_suffix)) {
153 printf(
"name_suffix %s=%s\n", prod1->name_suffix, prod2->name_suffix);
155 if (prod1->cat_ix != prod2->cat_ix) {
157 printf(
"cat_ix %d=%d\n", prod1->cat_ix, prod2->cat_ix);
159 if (prod1->prod_ix != prod2->prod_ix) {
161 printf(
"prod_ix %d=%d\n", prod1->prod_ix, prod2->prod_ix);
163 if (prod1->datatype != prod2->datatype) {
165 printf(
"datatype %d=%d\n", prod1->datatype, prod2->datatype);
167 if (prod1->slope != prod2->slope) {
169 printf(
"slope %f=%f\n", prod1->slope, prod2->slope);
171 if (prod1->offset != prod2->offset) {
173 printf(
"offset %f=%f\n", prod1->offset, prod2->offset);
175 if (prod1->min != prod2->min) {
177 printf(
"min %f=%f\n", prod1->min, prod2->min);
179 if (prod1->max != prod2->max) {
181 printf(
"max %f=%f\n", prod1->max, prod2->max);
183 if (prod1->rank != prod2->rank) {
185 printf(
"rank %d=%d\n", prod1->rank, prod2->rank);
189 if (strcmp(prod1->title_format, prod2->title_format)) {
191 printf(
"title_format %s=%s\n", prod1->title_format, prod2->title_format);
193 if (strcmp(prod1->title, prod2->title)) {
195 printf(
"title %s=%s\n", prod1->title, prod2->title);
197 if (strcmp(prod1->units, prod2->units)) {
199 printf(
"units %s=%s\n", prod1->units, prod2->units);
201 if (prod1->badData != prod2->badData) {
203 printf(
"badData %f=%f\n", prod1->badData, prod2->badData);
205 if (strcmp(prod1->product_id, prod2->product_id)) {
207 printf(
"product_id %s=%s\n", prod1->product_id, prod2->product_id);
209 if (strcmp(prod1->algorithm_id, prod2->algorithm_id)) {
211 printf(
"algorithm_id %s=%s\n", prod1->algorithm_id, prod2->algorithm_id);
213 if (strcmp(prod1->standard_name, prod2->standard_name)) {
215 printf(
"standard_name %s=%s\n", prod1->standard_name, prod2->standard_name);
232 && productInfo->paramWaveMin == 400
233 && productInfo->paramWaveMax == 725) {
236 strcpy(l2prod->name_prefix, productInfo->prefix);
237 strcpy(l2prod->name_suffix, productInfo->suffix);
238 l2prod->cat_ix = productInfo->cat_ix;
239 l2prod->prod_ix = productInfo->prod_ix;
241 l2prod->slope = productInfo->scaleFactor;
242 l2prod->offset = productInfo->addOffset;
243 l2prod->min = productInfo->validMin;
244 l2prod->max = productInfo->validMax;
245 l2prod->rank = productInfo->rank;
248 strcpy(l2prod->title_format, productInfo->titleFormat);
250 strcpy(l2prod->title, l2prod->title_format);
251 strcpy(l2prod->units, productInfo->units);
252 l2prod->badData = productInfo->fillValue;
253 strcpy(l2prod->product_id, productInfo->productName);
254 strcpy(l2prod->algorithm_id, productInfo->algorithmName);
255 if (productInfo->standardName)
256 strcpy(l2prod->standard_name, productInfo->standardName);
264 if (
product->product_id[0] !=
'\0') {
270 if (
name[strlen(
name) - 1] ==
'_') {
280 strcat(productName,
"_");
281 if (strcmp(productName,
product->name_prefix) == 0)
293 if (
product->algorithm_id[0] !=
'\0') {
299 if (
name[0] ==
'_') {
300 length = strlen(
name);
301 for (
i = 1;
i <= length;
i++) {
311 algorithmName[0] =
'_';
313 if (strcmp(algorithmName,
product->name_suffix) == 0)
387 strcat(
name, prod->name_suffix);
391 strcat(
name, prod->name_suffix);
408 for (productIndex = 0; productIndex < l2prod_num; productIndex++) {
420 fprintf(fout,
"%s, %s, %s, %s, %d, %d, %d, %g, %g, %g, %g, %g, %d, %s, %s, %s\n",
443 static int strLength = 0;
444 static char* buffer =
NULL;
446 if (strpbrk(
str,
"<>&")) {
448 int length = strlen(
str) + 15;
449 if (strLength < length) {
453 buffer = (
char*) malloc(strLength);
456 sprintf(buffer,
"<![CDATA[%s]]>",
str);
463 fprintf(fout,
"<productList>\n");
467 fprintf(fout,
"</productList>\n");
474 fprintf(fout,
" <product name=\"%s\">\n",
name);
478 fprintf(fout,
" </product>\n");
491 if (strlen(
name) > 0) {
492 fprintf(fout,
" <algorithm name=\"%s\">\n",
name);
494 fprintf(fout,
" <algorithm>\n");
502 fprintf(fout,
" </algorithm>\n");
506 l2prodstr **tmpList =
NULL;
507 l2prodstr **sortedList =
NULL;
511 static l2prodstr *chlProd;
519 printf(
"%s Line %d: NULL filename for XML file.\n",
524 if (chlProd ==
NULL) {
526 chlProd = (l2prodstr*) malloc(
sizeof (l2prodstr));
534 strncpy(chlProd->title,
"Chlorophyll Concentration, Default Sensor Algorithm",
TITLELEN);
535 strncpy(chlProd->standard_name,
"chlorophyll_concentration_in_sea_water",
TITLELEN);
539 tmpList = (l2prodstr**) malloc((l2prod_num + 1) *
sizeof (l2prodstr*));
540 sortedList = (l2prodstr**) malloc((l2prod_num + 1) *
sizeof (l2prodstr*));
543 for (productIndex = 0; productIndex < l2prod_num; productIndex++) {
544 tmpList[productIndex] = l2prod_array[productIndex];
548 tmpList[productIndex] = chlProd;
551 for (productIndex = 0; productIndex < l2prod_num + 1; productIndex++) {
552 product = tmpList[productIndex];
555 sortedList[sortedIndex++] =
product;
556 tmpList[productIndex] =
NULL;
559 for (productIndex2 = productIndex + 1; productIndex2 < l2prod_num + 1; productIndex2++) {
560 product2 = tmpList[productIndex2];
563 if (strcasecmp(productName, productName2) == 0) {
564 sortedList[sortedIndex++] = product2;
565 tmpList[productIndex2] =
NULL;
580 for (productIndex = 0; productIndex < l2prod_num + 1; productIndex++) {
581 product = sortedList[productIndex];
585 if (strcasecmp(productName, productName2) != 0) {
586 strcpy(productName2, productName);
617 static int first = 1;
618 static int lastNumPixels = 0;
619 static int default_iprod_chl = -1;
620 static l2prodstr* default_prod_chl =
NULL;
621 static productInfo_t* info;
626 lastNumPixels = numPixels;
631 for (
i = 0;
i < l2prod_num;
i++) {
632 l2prodstr *l2prod = l2prod_array[
i];
633 if (l2prod->rank == 3) {
634 l2prod->dim[0] = numScans;
635 l2prod->dim[1] = numPixels;
636 l2prod->dim[2] = numBands;
640 }
else if (l2prod->rank == 2) {
641 l2prod->dim[0] = numScans;
642 l2prod->dim[1] = numPixels;
647 }
else if (l2prod->rank == 1) {
648 l2prod->dim[0] = numScans;
699 printf(
"%s Line %d: need a default chlorophyll algorithm for this sensor\n",
705 for (prodIndex = 0; prodIndex < l2prod_num; prodIndex++) {
706 p = l2prod_array[prodIndex];
707 if (
p->cat_ix == default_iprod_chl) {
708 default_prod_chl =
p;
713 printf(
"%s Line %d: could not find the default chlorophyll algorithm for this sensor\n",
719 for (prodIndex = 0; prodIndex < l2prod_num; prodIndex++) {
720 p = l2prod_array[prodIndex];
722 sprintf(
p->title,
"%s, CDOM-corrected via Morel",
723 default_prod_chl->title);
730 if (numPixels != lastNumPixels) {
731 lastNumPixels = numPixels;
732 for (
i = 0;
i < l2prod_num;
i++) {
733 l2prodstr *l2prod = l2prod_array[
i];
734 if (l2prod->rank == 2 ) {
735 l2prod->dim[1] = numPixels;
737 if (l2prod->rank == 3) {
738 l2prod->dim[1] = numPixels;
739 l2prod->dim[2] = numBands;
744 if (strcmp(prod_name,
"chl_ocx") == 0) {
745 return default_prod_chl;
749 for (prodIndex = 0; prodIndex < l2prod_num; prodIndex++) {
750 p = l2prod_array[prodIndex];
751 switch (
p->param_type) {
753 sprintf(tmp_pname,
"%s%s",
p->name_prefix,
p->name_suffix);
754 if (strcmp(prod_name, tmp_pname) == 0)
760 if (strncmp(prod_name,
p->name_prefix, strlen(
p->name_prefix)) == 0) {
761 for (
i = 0;
i < numBands;
i++) {
762 sprintf(tmp_pname,
"%s%d%s",
p->name_prefix, wave[
i],
p->name_suffix);
763 if (strcmp(prod_name, tmp_pname) == 0) {
765 sprintf(
p->title,
p->title_format, wave[
i]);
770 p->slope = info->scaleFactor;
771 p->offset = info->addOffset;
772 p->max = info->validMax;
773 p->min = info->validMin;
782 for (
i = 0;
i < numBands;
i++) {
783 sprintf(tmp_pname,
"%s%d%s",
p->name_prefix,
i + 1,
p->name_suffix);
784 if (strcmp(prod_name, tmp_pname) == 0) {
786 sprintf(
p->title,
p->title_format,
i);
791 p->slope = info->scaleFactor;
792 p->offset = info->addOffset;
793 p->max = info->validMax;
794 p->min = info->validMin;
802 if (
p->name_suffix[0] == 0) {
803 if (strncmp(prod_name,
p->name_prefix, strlen(
p->name_prefix)) == 0) {
804 p->prod_ix = atoi(&prod_name[strlen(
p->name_prefix)]);
805 sprintf(
p->title,
p->title_format,
p->prod_ix);
809 p->slope = info->scaleFactor;
810 p->offset = info->addOffset;
811 p->max = info->validMax;
812 p->min = info->validMin;
817 if ((strncmp(prod_name,
p->name_prefix, strlen(
p->name_prefix)) == 0) &&
818 (strcmp(prod_name + strlen(prod_name) - strlen(
p->name_suffix),
p->name_suffix) == 0)) {
819 p->prod_ix = atoi(&prod_name[strlen(
p->name_prefix)]);
820 sprintf(
p->title,
p->title_format,
p->prod_ix);
824 p->slope = info->scaleFactor;
825 p->offset = info->addOffset;
826 p->max = info->validMax;
827 p->min = info->validMin;
838 fprintf(
stderr,
"\n%s - Invalid product name : %s\n", __FILE__, prod_name);