示例#1
0
文件: harp-errno.c 项目: stcorp/harp
/** Set the error value and optionally set a custom error message.
 * If \a message is NULL then the default error message for the error number will be used.
 * \param err Value of #harp_errno.
 * \param message Optional error message using printf() format.
 */
LIBHARP_API void harp_set_error(int err, const char *message, ...)
{
    va_list ap;

    harp_errno = err;

    va_start(ap, message);
    set_error_message_vargs(message, ap);
    va_end(ap);

#ifdef HAVE_HDF4
    if (err == HARP_ERROR_HDF4 && message == NULL)
    {
        harp_hdf4_add_error_message();
    }
#endif
#ifdef HAVE_HDF5
    if (err == HARP_ERROR_HDF5 && message == NULL)
    {
        harp_hdf5_add_error_message();
    }
#endif
    if (err == HARP_ERROR_CODA && message == NULL)
    {
        harp_add_error_message("%s", coda_errno_to_string(coda_errno));
    }
}
示例#2
0
static int coda_match_file(coda_expression *expr, NameBuffer *path_name,
                           int (*callback) (const char *, coda_filefilter_status, const char *, void *), void *userdata)
{
    coda_product *product;
    coda_cursor cursor;
    int filter_result;
    int result;

    result = coda_open(path_name->buffer, &product);
    if (result != 0 && coda_errno == CODA_ERROR_FILE_OPEN)
    {
        /* maybe not enough memory space to map the file in memory =>
         * temporarily disable memory mapping of files and try again
         */
        coda_set_option_use_mmap(0);
        result = coda_open(path_name->buffer, &product);
        coda_set_option_use_mmap(1);
    }
    if (result != 0)
    {
        if (coda_errno == CODA_ERROR_UNSUPPORTED_PRODUCT)
        {
            return callback(path_name->buffer, coda_ffs_unsupported_file, NULL, userdata);
        }
        else
        {
            return callback(path_name->buffer, coda_ffs_could_not_open_file, coda_errno_to_string(coda_errno),
                            userdata);
        }
    }

    if (coda_cursor_set_product(&cursor, product) != 0)
    {
        coda_close(product);
        return callback(path_name->buffer, coda_ffs_error, coda_errno_to_string(coda_errno), userdata);
    }
    if (coda_expression_eval_bool(expr, &cursor, &filter_result) != 0)
    {
        return callback(path_name->buffer, coda_ffs_error, coda_errno_to_string(coda_errno), userdata);
    }
    coda_close(product);


    return callback(path_name->buffer, filter_result ? coda_ffs_match : coda_ffs_no_match, NULL, userdata);
}
示例#3
0
int main() {

  printf("Testing CODA version %s\n", libcoda_version);

  int rc = coda_init();

  if (rc) {
    printf("coda_init returned error '%d' -- '%s'", coda_errno, coda_errno_to_string(coda_errno) );
  }

  coda_done();

  return 0;
}
示例#4
0
文件: codadd.c 项目: stcorp/coda
int main(int argc, char *argv[])
{
    int i = 1;

    ascii_col_sep = " ";
    show_type = 0;
    show_unit = 0;
    show_format = 0;
    show_description = 0;
    show_quotes = 0;
    show_hidden = 0;
    show_expressions = 0;
    show_parent_types = 0;
    show_attributes = 0;
    use_special_types = 1;

    if (argc > 1)
    {
        if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
        {
            print_help();
            exit(0);
        }

        if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
        {
            print_version();
            exit(0);
        }
    }

    if (i + 1 < argc && strcmp(argv[i], "-D") == 0)
    {
        coda_set_definition_path(argv[i + 1]);
        i += 2;
    }
    else
    {
#ifdef WIN32
        const char *definition_path = "../definitions";
#else
        const char *definition_path = "../share/" PACKAGE "/definitions";
#endif
        if (coda_set_definition_path_conditional(argv[0], NULL, definition_path) != 0)
        {
            fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno));
            exit(1);
        }
    }

    coda_option_read_all_definitions = 1;
    if (coda_init() != 0)
    {
        fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno));
        exit(1);
    }

    if (i == argc)
    {
        coda_done();
        exit(0);
    }

    coda_set_option_perform_conversions(0);

    if (strcmp(argv[i], "doc") == 0)
    {
        i++;
        if (i != argc - 1)
        {
            fprintf(stderr, "ERROR: invalid arguments\n");
            print_help();
            exit(1);
        }
        generate_html(argv[i]);
    }
    else if (strcmp(argv[i], "list") == 0)
    {
        const char *product_class = NULL;
        const char *product_type = NULL;
        int version = -1;

        i++;
        while (i < argc)
        {
            if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--expr") == 0)
            {
                show_expressions = 1;
            }
            else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quote_strings") == 0)
            {
                show_quotes = 1;
            }
            else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--type") == 0)
            {
                show_type = 1;
            }
            else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--unit") == 0)
            {
                show_unit = 1;
            }
            else if (strcmp(argv[i], "--description") == 0)
            {
                show_description = 1;
            }
            else if (strcmp(argv[i], "--hidden") == 0)
            {
                show_hidden = 1;
            }
            else if (strcmp(argv[i], "--parent-types") == 0)
            {
                show_parent_types = 1;
            }
            else if (strcmp(argv[i], "--attributes") == 0)
            {
                show_attributes = 1;
            }
            else if (strcmp(argv[i], "--no_special_types") == 0)
            {
                use_special_types = 0;
            }
            else if ((strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--column_separator") == 0) &&
                     i + 1 < argc && argv[i + 1][0] != '-')
            {
                i++;
                ascii_col_sep = argv[i];
            }
            else if (argv[i][0] != '-')
            {
                break;
            }
            else
            {
                fprintf(stderr, "ERROR: invalid arguments\n");
                print_help();
                exit(1);
            }
            i++;
        }

        if (i < argc)
        {
            product_class = argv[i];
            i++;
            if (i < argc)
            {
                product_type = argv[i];
                i++;
                if (i < argc)
                {
                    if (sscanf(argv[i], "%d", &version) != 1)
                    {
                        fprintf(stderr, "ERROR: invalid product version argument\n");
                        print_help();
                        exit(1);
                    }
                    i++;
                    if (i < argc)
                    {
                        fprintf(stderr, "ERROR: invalid arguments\n");
                        print_help();
                        exit(1);
                    }
                }
            }
        }
        generate_list(product_class, product_type, version);
    }
    else if (strcmp(argv[i], "xmlschema") == 0)
    {
        const char *output_file_name = NULL;
        const char *product_class = NULL;
        const char *product_type = NULL;
        int version = -1;

        i++;
        while (i < argc)
        {
            if ((strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) &&
                i + 1 < argc && argv[i + 1][0] != '-')
            {
                i++;
                output_file_name = argv[i];
            }
            else if (argv[i][0] != '-')
            {
                break;
            }
            else
            {
                fprintf(stderr, "ERROR: invalid arguments\n");
                print_help();
                exit(1);
            }
            i++;
        }

        if (i != argc - 3)
        {
            fprintf(stderr, "ERROR: invalid arguments\n");
            print_help();
            exit(1);
        }
        product_class = argv[i];
        i++;
        product_type = argv[i];
        i++;
        if (sscanf(argv[i], "%d", &version) != 1)
        {
            fprintf(stderr, "ERROR: invalid product version argument\n");
            print_help();
            exit(1);
        }
        generate_xmlschema(output_file_name, product_class, product_type, version);
    }
    else if (strcmp(argv[i], "dtree") == 0)
    {
        coda_format format;

        i++;
        if (i != argc - 1)
        {
            fprintf(stderr, "ERROR: invalid arguments\n");
            print_help();
            exit(1);
        }
        if (coda_format_from_string(argv[i], &format) != 0)
        {
            fprintf(stderr, "ERROR: invalid arguments\n");
            print_help();
            exit(1);
        }
        generate_detection_tree(format);
    }
    else if (strcmp(argv[i], "definition") == 0)
    {
        const char *output_file_name = NULL;

        i++;
        while (i < argc)
        {
            if ((strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) &&
                i + 1 < argc && argv[i + 1][0] != '-')
            {
                i++;
                output_file_name = argv[i];
            }
            else if (argv[i][0] != '-')
            {
                break;
            }
            else
            {
                fprintf(stderr, "ERROR: invalid arguments\n");
                print_help();
                exit(1);
            }
            i++;
        }

        if (i != argc - 1)
        {
            fprintf(stderr, "ERROR: invalid arguments\n");
            print_help();
            exit(1);
        }
        generate_definition(output_file_name, argv[i]);
    }
    else
    {
        fprintf(stderr, "ERROR: invalid arguments\n");
        print_help();
        exit(1);
    }

    coda_done();

    return 0;
}
示例#5
0
void generate_xmlschema(const char *output_file_name, const char *product_class_name, const char *product_type_name,
                        int version)
{
    FILE *schema_output = stdout;
    coda_product_class *product_class;
    coda_product_type *product_type;
    coda_product_definition *product_definition;
    coda_type_record *root_type;

    product_class = coda_data_dictionary_get_product_class(product_class_name);
    if (product_class == NULL)
    {
        fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno));
        exit(1);
    }

    product_type = coda_product_class_get_product_type(product_class, product_type_name);
    if (product_type == NULL)
    {
        fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno));
        exit(1);
    }

    product_definition = coda_product_type_get_product_definition_by_version(product_type, version);
    if (product_definition == NULL)
    {
        fprintf(stderr, "ERROR: %s\n", coda_errno_to_string(coda_errno));
        exit(1);
    }

    if (product_definition->format != coda_format_xml)
    {
        fprintf(stderr, "ERROR: product is not in XML format\n");
        exit(1);
    }
    if (product_definition->root_type == NULL)
    {
        fprintf(stderr, "ERROR: product does not have a format definition\n");
        exit(1);
    }

    if (output_file_name != NULL)
    {
        schema_output = fopen(output_file_name, "w");
        if (schema_output == NULL)
        {
            fprintf(stderr, "ERROR: could not create output file \"%s\"\n", output_file_name);
            exit(1);
        }
    }

    assert(product_definition->root_type->type_class == coda_record_class);
    root_type = (coda_type_record *)product_definition->root_type;
    assert(root_type->num_fields == 1);

    fprintf(schema_output, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    fprintf(schema_output, "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n");
    fprintf(schema_output, "<xs:element name=\"%s\">", root_type->field[0]->real_name);
    print_xml_element(schema_output, root_type->field[0]->type);
    fprintf(schema_output, "</xs:element>\n");
    fprintf(schema_output, "</xs:schema>\n");

    if (output_file_name != NULL)
    {
        fclose(schema_output);
    }
}