1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
|
/*
* Copyright (C) 2015-2018 S[&]T, The Netherlands.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "harp-ingestion.h"
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef max
#undef max
#endif
static int max(int a, int b)
{
return (a > b ? a : b);
}
static int vscprintf(const char *format, va_list ap)
{
#ifdef WIN32
return _vscprintf(format, ap);
#else
return vsnprintf(NULL, 0, format, ap);
#endif
}
static int scprintf(const char *format, ...)
{
va_list ap;
int length;
va_start(ap, format);
length = vscprintf(format, ap);
va_end(ap);
assert(length >= 0);
return length;
}
static void fnputc(long n, char c, FILE *stream)
{
while (n > 0)
{
fputc(c, stream);
n--;
}
}
static void print_padded_string(FILE *fout, int column_width, const char *format, ...)
{
va_list ap;
int length;
va_start(ap, format);
length = vfprintf(fout, format, ap);
assert(length >= 0);
if (length < column_width)
{
fnputc(column_width - length, ' ', fout);
}
va_end(ap);
}
static int product_definition_has_mapping_description(const harp_product_definition *product_definition)
{
int i;
if (product_definition->mapping_description != NULL)
{
return 1;
}
for (i = 0; i < product_definition->num_variable_definitions; i++)
{
harp_variable_definition *variable_definition = product_definition->variable_definition[i];
if (variable_definition->num_mappings > 0 || variable_definition->include != NULL)
{
return 1;
}
}
return 0;
}
static int generate_product_definition(const char *filename, const harp_ingestion_module *module,
const harp_product_definition *product_definition)
{
FILE *fout;
int i;
int j;
fout = fopen(filename, "w");
if (fout == NULL)
{
harp_set_error(HARP_ERROR_FILE_OPEN, "could not open file '%s' for writing", filename);
return -1;
}
fputs(":orphan: true\n\n", fout);
fputs(product_definition->name, fout);
fputc('\n', fout);
fnputc((long)strlen(product_definition->name), '=', fout);
fnputc(2, '\n', fout);
fputs("Variables\n", fout);
fputs("---------\n", fout);
fprintf(fout, "The table below lists the variables that are present in the HARP product that results from an "
"ingestion of ``%s`` data.\n\n", product_definition->name);
fputs(".. csv-table::\n", fout);
fputs(" :widths: 25 5 15 15 40\n", fout);
fputs(" :header-rows: 1\n\n", fout);
fputs(" \"field name\", \"type\", \"dimensions\", \"unit\", \"description\"\n", fout);
for (i = 0; i < product_definition->num_variable_definitions; i++)
{
harp_variable_definition *variable_definition = product_definition->variable_definition[i];
fnputc(3, ' ', fout);
fputc('"', fout);
fprintf(fout, "**%s**", variable_definition->name);
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
fputs(harp_get_data_type_name(variable_definition->data_type), fout);
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (variable_definition->num_dimensions > 0)
{
fputc('{', fout);
for (j = 0; j < variable_definition->num_dimensions; j++)
{
if (j > 0)
{
fputs(", ", fout);
}
if (variable_definition->dimension_type[j] == harp_dimension_independent)
{
fprintf(fout, "%ld", variable_definition->dimension[j]);
}
else
{
fprintf(fout, "*%s*", harp_get_dimension_type_name(variable_definition->dimension_type[j]));
}
}
fputc('}', fout);
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (variable_definition->unit != NULL)
{
fputc('[', fout);
if (strlen(variable_definition->unit) > 0)
{
fputs(variable_definition->unit, fout);
}
fputc(']', fout);
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (variable_definition->description != NULL)
{
fputs(variable_definition->description, fout);
}
if (variable_definition->num_enum_values > 0)
{
if (variable_definition->description != NULL)
{
fputs("; ", fout);
}
fputs("enumeration values: ", fout);
for (j = 0; j < variable_definition->num_enum_values; j++)
{
fprintf(fout, "%s (%d)", variable_definition->enum_name[j], j);
if (j < variable_definition->num_enum_values - 1)
{
fputs(", ", fout);
}
}
}
fputc('"', fout);
fputc('\n', fout);
}
if (module->num_option_definitions > 0)
{
fputc('\n', fout);
fputs("Ingestion options\n", fout);
fputs("-----------------\n", fout);
fprintf(fout, "The table below lists the available ingestion options for ``%s`` products.\n\n", module->name);
fputs(".. csv-table::\n", fout);
fputs(" :widths: 15 25 60\n", fout);
fputs(" :header-rows: 1\n\n", fout);
fputs(" \"option name\", \"legal values\", \"description\"\n", fout);
for (j = 0; j < module->num_option_definitions; j++)
{
harp_ingestion_option_definition *option_definition = module->option_definition[j];
fnputc(3, ' ', fout);
fputc('"', fout);
fputs(option_definition->name, fout);
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (option_definition->num_allowed_values > 0)
{
int k;
for (k = 0; k < option_definition->num_allowed_values; k++)
{
fputs(option_definition->allowed_value[k], fout);
if (k + 1 < option_definition->num_allowed_values)
{
fputs(", ", fout);
}
}
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (option_definition->description != NULL)
{
fputs(option_definition->description, fout);
}
fputc('"', fout);
fputc('\n', fout);
}
fputc('\n', fout);
if (product_definition->ingestion_option != NULL)
{
fprintf(fout, "This definition is only applicable when: %s\n", product_definition->ingestion_option);
}
}
if (product_definition_has_mapping_description(product_definition))
{
int column_width[3] = { 0 };
int span_width;
fputc('\n', fout);
fputs("Mapping description\n", fout);
fputs("-------------------\n", fout);
if (product_definition->mapping_description != NULL)
{
fprintf(fout, "%s\n\n", product_definition->mapping_description);
}
fputs("The table below details where and how each variable was retrieved from the input product.\n\n", fout);
for (i = 0; i < product_definition->num_variable_definitions; i++)
{
harp_variable_definition *variable_definition = product_definition->variable_definition[i];
if (variable_definition->num_mappings == 0 && variable_definition->include == NULL)
{
continue;
}
column_width[0] = max(column_width[0], scprintf("**%s**", variable_definition->name));
if (variable_definition->include != NULL)
{
column_width[1] = max(column_width[1], (int)strlen("*available*"));
column_width[2] = max(column_width[2], (int)strlen("optional"));
}
for (j = 0; j < variable_definition->num_mappings; j++)
{
harp_mapping_description *mapping = variable_definition->mapping[j];
if (mapping->ingestion_option != NULL || mapping->condition != NULL)
{
column_width[1] = max(column_width[1], (int)strlen("*condition*"));
if (mapping->ingestion_option != NULL && mapping->condition != NULL)
{
column_width[2] = max(column_width[2], scprintf("%s and %s", mapping->ingestion_option,
mapping->condition));
}
else if (mapping->ingestion_option != NULL)
{
column_width[2] = max(column_width[2], (int)strlen(mapping->ingestion_option));
}
else
{
column_width[2] = max(column_width[2], (int)strlen(mapping->condition));
}
}
if (mapping->path != NULL)
{
column_width[1] = max(column_width[1], (int)strlen("*path*"));
column_width[2] = max(column_width[2], scprintf("**%s**", mapping->path));
}
if (mapping->description != NULL)
{
column_width[1] = max(column_width[1], (int)strlen("*description*"));
column_width[2] = max(column_width[2], (int)strlen(mapping->description));
}
}
}
/* Adjust maximum column widths for the header fields. Note that the second header field spans two columns.
* If the length of the second header field is larger than the maximum widths of the spanned columns combined,
* the width of the last column is increased such that the combined width matches the length of the second
* header field.
*/
column_width[0] = max(column_width[0], (int)strlen("field name"));
span_width = max((int)strlen("mapping description"), column_width[1] + 3 + column_width[2]);
if (span_width > column_width[1] + 3 + column_width[2])
{
column_width[2] = span_width - (column_width[1] + 3);
}
fputc('+', fout);
fnputc(column_width[0] + 2, '-', fout);
fputc('+', fout);
fnputc(span_width + 2, '-', fout);
fputc('+', fout);
fputc('\n', fout);
fputs("| ", fout);
print_padded_string(fout, column_width[0], "%s", "field name");
fputs(" | ", fout);
print_padded_string(fout, span_width, "%s", "mapping description");
fputs(" |\n", fout);
fputc('+', fout);
fnputc(column_width[0] + 2, '=', fout);
fputc('+', fout);
fnputc(column_width[1] + 2, '=', fout);
fputc('+', fout);
fnputc(column_width[2] + 2, '=', fout);
fputc('+', fout);
fputc('\n', fout);
for (i = 0; i < product_definition->num_variable_definitions; i++)
{
harp_variable_definition *variable_definition = product_definition->variable_definition[i];
int first_row = 1;
if (variable_definition->num_mappings == 0 && variable_definition->include == NULL)
{
continue;
}
fputs("| ", fout);
print_padded_string(fout, column_width[0], "**%s**", variable_definition->name);
fputs(" | ", fout);
if (variable_definition->include != NULL)
{
print_padded_string(fout, column_width[1], "%s", "*available*");
fputs(" | ", fout);
print_padded_string(fout, column_width[2], "%s", "optional");
fputs(" |\n", fout);
first_row = 0;
}
for (j = 0; j < variable_definition->num_mappings; j++)
{
harp_mapping_description *mapping = variable_definition->mapping[j];
if (mapping->ingestion_option != NULL || mapping->condition != NULL)
{
if (!first_row)
{
fputc('+', fout);
fnputc(column_width[0] + 2, ' ', fout);
fputc('+', fout);
fnputc(column_width[1] + 2, '-', fout);
fputc('+', fout);
fnputc(column_width[2] + 2, '-', fout);
fputc('+', fout);
fputc('\n', fout);
fputs("| ", fout);
fnputc(column_width[0], ' ', fout);
fputs(" | ", fout);
}
else
{
first_row = 0;
}
print_padded_string(fout, column_width[1], "%s", "*condition*");
fputs(" | ", fout);
if (mapping->ingestion_option != NULL && mapping->condition != NULL)
{
print_padded_string(fout, column_width[2], "%s and %s", mapping->ingestion_option,
mapping->condition);
}
else if (mapping->ingestion_option != NULL)
{
print_padded_string(fout, column_width[2], "%s", mapping->ingestion_option);
}
else
{
print_padded_string(fout, column_width[2], "%s", mapping->condition);
}
fputs(" |\n", fout);
}
if (mapping->path != NULL)
{
if (!first_row)
{
fputc('+', fout);
fnputc(column_width[0] + 2, ' ', fout);
fputc('+', fout);
fnputc(column_width[1] + 2, '-', fout);
fputc('+', fout);
fnputc(column_width[2] + 2, '-', fout);
fputc('+', fout);
fputc('\n', fout);
fputs("| ", fout);
fnputc(column_width[0], ' ', fout);
fputs(" | ", fout);
}
else
{
first_row = 0;
}
print_padded_string(fout, column_width[1], "%s", "*path*");
fputs(" | ", fout);
print_padded_string(fout, column_width[2], "**%s**", mapping->path);
fputs(" |\n", fout);
}
if (mapping->description != NULL)
{
if (!first_row)
{
fputc('+', fout);
fnputc(column_width[0] + 2, ' ', fout);
fputc('+', fout);
fnputc(column_width[1] + 2, '-', fout);
fputc('+', fout);
fnputc(column_width[2] + 2, '-', fout);
fputc('+', fout);
fputc('\n', fout);
fputs("| ", fout);
fnputc(column_width[0], ' ', fout);
fputs(" | ", fout);
}
else
{
first_row = 0;
}
print_padded_string(fout, column_width[1], "%s", "*description*");
fputs(" | ", fout);
print_padded_string(fout, column_width[2], "%s", mapping->description);
fputs(" |\n", fout);
}
}
fputc('+', fout);
fnputc(column_width[0] + 2, '-', fout);
fputc('+', fout);
fnputc(column_width[1] + 2, '-', fout);
fputc('+', fout);
fnputc(column_width[2] + 2, '-', fout);
fputc('+', fout);
fputc('\n', fout);
}
}
fclose(fout);
return 0;
}
static int generate_product_group(FILE *fout, const char *product_group, int num_ingestion_modules,
harp_ingestion_module **ingestion_module)
{
int i;
fprintf(fout, ".. _%s:\n\n", product_group);
fprintf(fout, "%s products\n", product_group);
fnputc((long)strlen(product_group) + 9, '-', fout);
fputc('\n', fout);
fputc('\n', fout);
fputs(".. csv-table::\n", fout);
fputs(" :header-rows: 1\n\n", fout);
fputs(" \"HARP product name\", \"CODA product type\", \"description\"\n", fout);
for (i = 0; i < num_ingestion_modules; i++)
{
const harp_ingestion_module *module = ingestion_module[i];
fnputc(3, ' ', fout);
if (module->num_product_definitions == 1 && strcmp(module->product_definition[0]->name, module->name) == 0)
{
/* don't print details when we only have one conversion (whose name equals that of the module) */
fprintf(fout, "\":doc:`%s`\", ", module->product_definition[0]->name);
}
else
{
fprintf(fout, "\":ref:`%s`\", ", module->name);
}
fputc('"', fout);
if (module->product_class != NULL && module->product_type != NULL)
{
fprintf(fout, "%s/%s", module->product_class, module->product_type);
}
else if (module->product_class != NULL)
{
fputs(module->product_class, fout);
}
else if (module->product_type != NULL)
{
fputs(module->product_type, fout);
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (module->description != NULL)
{
fputs(module->description, fout);
}
fputc('"', fout);
fputc('\n', fout);
}
fputc('\n', fout);
for (i = 0; i < num_ingestion_modules; i++)
{
const harp_ingestion_module *module = ingestion_module[i];
int j;
if (module->num_product_definitions == 1 && strcmp(module->product_definition[0]->name, module->name) == 0)
{
/* skip printing details if we already have a direct link to the conversion (see above) */
continue;
}
fprintf(fout, ".. _%s:\n\n", module->name);
fprintf(fout, "%s\n", module->name);
fnputc((long)strlen(module->name), '^', fout);
fputc('\n', fout);
if (module->description != NULL)
{
fprintf(fout, "%s\n\n", module->description);
}
fprintf(fout, "The table below lists the available product conversions for ``%s`` products.\n\n", module->name);
fputs(".. csv-table::\n", fout);
fputs(" :header-rows: 1\n\n", fout);
fputs(" \"name\", \"ingestion option\", \"description\"\n", fout);
for (j = 0; j < module->num_product_definitions; j++)
{
harp_product_definition *product_definition = module->product_definition[j];
fnputc(3, ' ', fout);
fprintf(fout, "\":doc:`%s`\"", product_definition->name);
fputs(", ", fout);
fputc('"', fout);
if (product_definition->ingestion_option != NULL)
{
fputs(product_definition->ingestion_option, fout);
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (product_definition->description != NULL)
{
fputs(product_definition->description, fout);
}
fputc('"', fout);
fputc('\n', fout);
}
fputc('\n', fout);
if (module->num_option_definitions > 0)
{
fprintf(fout, "The table below lists the available ingestion options for ``%s`` products.\n\n",
module->name);
fputs(".. csv-table::\n", fout);
fputs(" :widths: 15 25 60\n", fout);
fputs(" :header-rows: 1\n\n", fout);
fputs(" \"option name\", \"legal values\", \"description\"\n", fout);
for (j = 0; j < module->num_option_definitions; j++)
{
harp_ingestion_option_definition *option_definition = module->option_definition[j];
fnputc(3, ' ', fout);
fputc('"', fout);
fputs(option_definition->name, fout);
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (option_definition->num_allowed_values > 0)
{
int k;
for (k = 0; k < option_definition->num_allowed_values; k++)
{
fputs(option_definition->allowed_value[k], fout);
if (k + 1 < option_definition->num_allowed_values)
{
fputs(", ", fout);
}
}
}
fputc('"', fout);
fputs(", ", fout);
fputc('"', fout);
if (option_definition->description != NULL)
{
fputs(option_definition->description, fout);
}
fputc('"', fout);
fputc('\n', fout);
}
fputc('\n', fout);
}
}
return 0;
}
static int compare_by_product_group_and_name(const void *a, const void *b)
{
harp_ingestion_module *module_a = *(harp_ingestion_module **)a;
harp_ingestion_module *module_b = *(harp_ingestion_module **)b;
int result;
result = strcmp(module_a->product_group, module_b->product_group);
if (result == 0)
{
result = strcmp(module_a->name, module_b->name);
}
return result;
}
static int generate_index(const char *filename, int num_ingestion_modules, harp_ingestion_module **ingestion_module)
{
FILE *fout;
harp_ingestion_module **sorted_module;
int i;
int j;
fout = fopen(filename, "w");
if (fout == NULL)
{
harp_set_error(HARP_ERROR_FILE_OPEN, "could not open file '%s' for writing", filename);
return -1;
}
fputs("Ingestion definitions\n", fout);
fputs("=====================\n", fout);
fputs("HARP can ingest data from various types of products. The list of supported product types is provided below. "
"HARP will try to automatically determine the product type of each file that you pass to the ingest "
"function. An error will be raised if the product type of a file cannot be determined.\n\n", fout);
fputs("For each ingestion, HARP will return a single HARP product. Each variable in a HARP product represents a "
"specific quantity (e.g. O\\ :sub:`3` number density, cloud fraction, altitude, longitude, latitude, time, "
"*et cetera*). You can customize which variables you want to include using the ``include()`` and "
"``exclude()`` operations that can be passed to the ingest function.\n\n", fout);
fputs("Within a HARP product, dimensions of the same type (*time*, *latitude*, *longitude*, *vertical*, "
"*spectral*) are linked together. This means that, within an ingested product, variables cannot have "
"dimensions of the same type with different lengths.\n\n", fout);
fputs("For each type of product that contains one or more quantities for which dimensions of the same type have "
"different lengths, the ingestion will be split into multiple *conversions*. Each conversion only contains "
"quantities for which the length of each type of dimension is the same. When multiple conversions exist for "
"a product type, HARP will use the first conversion from the list of available conversions by default.\n\n",
fout);
fputs("For example, suppose a certain type of product contains both O\\ :sub:`3` and NO\\ :sub:`2` volume mixing "
"ratios retrieved on different spatial grids. In this case, it is not possible to have a single pair of "
"*longitude* and *latitude* variables that describes the geolocation information for both retrievals. "
"Therefore, two different conversions will be made available for this product type, one for the O\\ :sub:`3` "
"volume mixing ratio, and another for the NO\\ :sub:`2` volume mixing ratio.\n\n", fout);
fputs("For each product type, *ingestion options* may be available. These options can be used, for example, to "
"switch between different product conversions (usually when quantities defined on different grids are "
"present within a single product), or to switch between different variants of a quantity. Ingestion options "
"should be passed to the ingest function as a semi-colon separated string of ``option_name=value`` pairs. ",
fout);
fputs("These options are unrelated to *operations* (filtering, inclusion and exclusion of variables, and adding "
"derived variables). Ingestion options are only meaningful in the context of an ingestion, while operations "
"can be applied both on-the-fly during ingestion, as well as to existing HARP products.\n\n", fout);
fputs("The list below gives an overview of the conversions and ingestion options available for each product type. "
"For each conversion, there is a separate page that describes the resulting HARP product. This includes a "
"list of all the variables, the value type, the dimensions, and the unit of each variable, as well as a full "
"*mapping description* that details where and how HARP retrieved the data from the input product.\n\n", fout);
/* Copy the ingestion module list to sort it without disturbing the original list. */
sorted_module = (harp_ingestion_module **)malloc(num_ingestion_modules * sizeof(harp_ingestion_module *));
if (sorted_module == NULL)
{
harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
num_ingestion_modules * sizeof(harp_ingestion_module *), __FILE__, __LINE__);
fclose(fout);
return -1;
}
memcpy(sorted_module, ingestion_module, num_ingestion_modules * sizeof(harp_ingestion_module *));
/* Sort ingestion module list based on product group name (ascending) and module name within group (ascending) */
qsort(sorted_module, num_ingestion_modules, sizeof(harp_ingestion_module *), compare_by_product_group_and_name);
for (i = 0, j = 0; i < num_ingestion_modules; i++)
{
if (i + 1 < num_ingestion_modules &&
strcmp(sorted_module[i]->product_group, sorted_module[i + 1]->product_group) == 0)
{
/* The next ingestion module is part of the same product group as the ingestion modules before it. */
continue;
}
if (generate_product_group(fout, sorted_module[j]->product_group, i - j + 1, &sorted_module[j]) != 0)
{
free(sorted_module);
fclose(fout);
return -1;
}
j = i + 1;
}
free(sorted_module);
fclose(fout);
return 0;
}
/** Generate reStructuredText documentation for all ingestion definitions.
* \ingroup harp_documentation
* \param path Path to directory in which the documentation files will be written.
* \return
* \arg \c 0, Success.
* \arg \c -1, Error occurred (check #harp_errno).
*/
LIBHARP_API int harp_doc_export_ingestion_definitions(const char *path)
{
harp_ingestion_module_register *module_register;
char *filename;
int i;
int j;
if (path == NULL)
{
harp_set_error(HARP_ERROR_INVALID_ARGUMENT, "path is NULL (%s:%u)", __FILE__, __LINE__);
return -1;
}
if (harp_ingestion_init() != 0)
{
return -1;
}
module_register = harp_ingestion_get_module_register();
assert(module_register != NULL);
filename = (char *)malloc(scprintf("%s/index.rst", path) + 1);
if (filename == NULL)
{
harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate % lu bytes) (%s:%u)",
scprintf("%s/index.rst", path) + 1, __FILE__, __LINE__);
return -1;
}
sprintf(filename, "%s/index.rst", path);
if (generate_index(filename, module_register->num_ingestion_modules, module_register->ingestion_module) != 0)
{
free(filename);
return -1;
}
else
{
free(filename);
}
for (i = 0; i < module_register->num_ingestion_modules; i++)
{
harp_ingestion_module *ingestion_module = module_register->ingestion_module[i];
for (j = 0; j < ingestion_module->num_product_definitions; j++)
{
harp_product_definition *product_definition = ingestion_module->product_definition[j];
filename = (char *)malloc(scprintf("%s/%s.rst", path, product_definition->name) + 1);
if (filename == NULL)
{
harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate % lu bytes) (%s:%u)",
scprintf("%s/%s.rst", path, product_definition->name) + 1, __FILE__, __LINE__);
return -1;
}
sprintf(filename, "%s/%s.rst", path, product_definition->name);
if (generate_product_definition(filename, ingestion_module, product_definition) != 0)
{
free(filename);
return -1;
}
else
{
free(filename);
}
}
}
return 0;
}
|