static void print_attributes(FILE *f, coda_type *type) { coda_type *attributes; long num_record_fields; long i; coda_type_get_attributes(type, &attributes); coda_type_get_num_record_fields(attributes, &num_record_fields); for (i = 0; i < num_record_fields; i++) { coda_type_class field_type_class; coda_type *field_type; const char *real_name; int available; coda_type_get_record_field_real_name(attributes, i, &real_name); coda_type_get_record_field_available_status(attributes, i, &available); coda_type_get_record_field_type(attributes, i, &field_type); coda_type_get_class(field_type, &field_type_class); fprintf(f, "<xs:attribute name=\"%s\"", real_name); if (available == 1) { fprintf(f, " use=\"required\""); } switch (field_type_class) { case coda_integer_class: fprintf(f, " type=\"xs:integer\""); break; case coda_real_class: fprintf(f, " type=\"xs:float\""); break; case coda_text_class: fprintf(f, " type=\"xs:string\""); break; default: assert(0); exit(1); } fprintf(f, "/>"); } }
static int get_product_group_availability(coda_product *product, const char *group_name, int *group_available) { coda_type *root_type; long num_fields; long i; if (coda_get_product_root_type(product, &root_type) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_type_get_num_record_fields(root_type, &num_fields) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } for (i = 0; i < num_fields; i++) { const char *field_name; if (coda_type_get_record_field_real_name(root_type, i, &field_name) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (strcmp(field_name, group_name) == 0) { *group_available = 1; return 0; } } *group_available = 0; return 0; }
static void traverse_data() { coda_type_class type_class; if (coda_type_get_class(traverse_info.type[traverse_info.current_depth], &type_class) != 0) { handle_coda_error(); } switch (type_class) { case coda_record_class: { long num_fields; long index; if (traverse_info.current_depth >= CODA_CURSOR_MAXDEPTH - 1) { /* don't traverse further, since we can't navigate to it with a CODA cursor */ break; } #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_enter_record(); } #endif traverse_info.num_records++; if (coda_type_get_num_record_fields(traverse_info.type[traverse_info.current_depth], &num_fields) != 0) { handle_coda_error(); } traverse_info.current_depth++; if (traverse_info.filter[traverse_info.filter_depth] != NULL) { codadump_filter *filter; filter = traverse_info.filter[traverse_info.filter_depth]; while (traverse_info.filter[traverse_info.filter_depth] != NULL) { const char *name; name = codadump_filter_get_fieldname(traverse_info.filter[traverse_info.filter_depth]); assert(name != NULL); if (coda_type_get_record_field_index_from_name (traverse_info.type[traverse_info.current_depth - 1], name, &index) != 0) { if (coda_errno == CODA_ERROR_INVALID_NAME) { fprintf(stderr, "ERROR: incorrect filter - incorrect fieldname (%s)\n", name); exit(1); } handle_coda_error(); } traverse_info.filter[traverse_info.filter_depth + 1] = codadump_filter_get_subfilter(traverse_info.filter[traverse_info.filter_depth]); traverse_info.filter_depth++; traverse_record(index, 1); traverse_info.filter_depth--; traverse_info.filter[traverse_info.filter_depth] = codadump_filter_get_next_filter(traverse_info.filter[traverse_info.filter_depth]); } traverse_info.filter[traverse_info.filter_depth] = filter; } else { for (index = 0; index < num_fields; index++) { traverse_record(index, 0); } } traverse_info.current_depth--; traverse_info.num_records--; #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_leave_record(); } #endif } break; case coda_array_class: { if (traverse_info.current_depth >= CODA_CURSOR_MAXDEPTH - 1) { /* don't traverse further, since we can't navigate to it with a CODA cursor */ break; } dim_enter_array(); #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_enter_array(); } #endif traverse_info.num_arrays++; traverse_info.current_depth++; if (coda_type_get_array_base_type(traverse_info.type[traverse_info.current_depth - 1], &traverse_info.type[traverse_info.current_depth]) != 0) { handle_coda_error(); } traverse_data(); traverse_info.current_depth--; traverse_info.num_arrays--; #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_leave_array(); } #endif dim_leave_array(); } break; case coda_integer_class: case coda_real_class: case coda_text_class: case coda_raw_class: { coda_native_type read_type; if (coda_type_get_read_type(traverse_info.type[traverse_info.current_depth], &read_type) != 0) { handle_coda_error(); } switch (read_type) { case coda_native_type_string: case coda_native_type_bytes: dim_enter_array(); #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_enter_array(); } #endif traverse_info.num_arrays++; handle_data_element(); traverse_info.num_arrays--; #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_leave_array(); } #endif dim_leave_array(); break; default: handle_data_element(); break; } } break; case coda_special_class: { coda_special_type special_type; if (coda_get_option_bypass_special_types()) { /* use the base type for all special types */ if (coda_type_get_special_base_type(traverse_info.type[traverse_info.current_depth], &traverse_info.type[traverse_info.current_depth]) != 0) { handle_coda_error(); } traverse_data(); return; } if (coda_type_get_special_type(traverse_info.type[traverse_info.current_depth], &special_type) != 0) { handle_coda_error(); } switch (special_type) { case coda_special_no_data: /* ignore */ return; case coda_special_vsf_integer: case coda_special_time: handle_data_element(); break; case coda_special_complex: dim_enter_array(); #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_enter_array(); } #endif traverse_info.num_arrays++; handle_data_element(); traverse_info.num_arrays--; #ifdef HAVE_HDF4 if (run_mode == RUN_MODE_HDF4) { hdf4_leave_array(); } #endif dim_leave_array(); break; } } break; } }
static void print_xml_element(FILE *f, coda_type *type) { coda_type_class type_class; long num_record_fields; long i; coda_type_get_class(type, &type_class); assert(type_class == coda_record_class); fprintf(f, "<xs:complexType><xs:sequence>"); coda_type_get_num_record_fields(type, &num_record_fields); for (i = 0; i < num_record_fields; i++) { coda_type_class field_type_class; coda_type *field_type; const char *real_name; coda_format format; coda_type_get_record_field_real_name(type, i, &real_name); coda_type_get_record_field_type(type, i, &field_type); coda_type_get_class(field_type, &field_type_class); coda_type_get_format(field_type, &format); fprintf(f, "<xs:element name=\"%s\"", real_name); if (field_type_class == coda_array_class && format == coda_format_xml) { fprintf(f, " minOccurs=\"0\" maxOccurs=\"unbounded\""); coda_type_get_array_base_type(field_type, &field_type); coda_type_get_class(field_type, &field_type_class); coda_type_get_format(field_type, &format); } if (field_type_class == coda_special_class) { coda_type_get_special_base_type(field_type, &field_type); coda_type_get_class(field_type, &field_type_class); coda_type_get_format(field_type, &format); } if (field_type_class == coda_record_class) { fprintf(f, ">"); print_xml_element(f, field_type); } else { const char *xsdtype; int has_attributes; switch (field_type_class) { case coda_array_class: assert(format != coda_format_xml); xsdtype = "string"; break; case coda_integer_class: xsdtype = "integer"; break; case coda_real_class: xsdtype = "float"; break; case coda_text_class: xsdtype = "string"; break; default: assert(0); exit(1); } coda_type_has_attributes(field_type, &has_attributes); if (has_attributes) { fprintf(f, ">"); fprintf(f, "<xs:complexType>"); fprintf(f, "<xs:simpleContent>"); fprintf(f, "<xs:extension base=\"xs:%s\">", xsdtype); print_attributes(f, field_type); fprintf(f, "</xs:extension>"); fprintf(f, "</xs:simpleContent>"); fprintf(f, "</xs:complexType>"); } else { fprintf(f, " type=\"xs:%s\">", xsdtype); } } fprintf(f, "</xs:element>"); } fprintf(f, "</xs:sequence>"); print_attributes(f, type); fprintf(f, "</xs:complexType>"); }