static int get_profile_point(ingest_info *info, const char *datasetname, long index, const char *fieldname, harp_array data) { coda_cursor cursor; if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, datasetname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_array_element_by_index(&cursor, index) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, fieldname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_read_double(&cursor, data.double_data) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } return 0; }
void traverse_product() { int result; result = coda_open(traverse_info.file_name, &traverse_info.pf); 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(traverse_info.file_name, &traverse_info.pf); coda_set_option_use_mmap(1); } if (result != 0) { handle_coda_error(); } if (coda_cursor_set_product(&traverse_info.cursor, traverse_info.pf) != 0) { handle_coda_error(); } if (coda_get_product_root_type(traverse_info.pf, &traverse_info.type[traverse_info.current_depth]) != 0) { handle_coda_error(); } traverse_data(); coda_close(traverse_info.pf); traverse_info.pf = NULL; }
static int init_cursors(ingest_info *info, const char *product_group_name) { coda_cursor cursor; if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (product_group_name == NULL) { if (coda_cursor_goto_first_record_field(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } else { if (coda_cursor_goto_record_field_by_name(&cursor, product_group_name) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } if (coda_cursor_goto_record_field_by_name(&cursor, "STANDARD_MODE") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } info->sensor_mode_cursor = cursor; info->geo_data_cursor = cursor; if (coda_cursor_goto_record_field_by_name(&info->geo_data_cursor, "GEODATA") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } info->observation_cursor = cursor; if (coda_cursor_goto(&info->observation_cursor, "OBSERVATIONS") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } info->instrument_cursor = cursor; if (coda_cursor_goto(&info->instrument_cursor, "INSTRUMENT") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } return 0; }
static int get_pcd_profile(ingest_info *info, const char *datasetname, long pcd_index, harp_array data) { coda_cursor cursor; int i; if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, datasetname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_first_array_element(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } for (i = 0; i < info->num_vertical; i++) { if (coda_cursor_goto_record_field_by_name(&cursor, "pcd") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_array_element_by_index(&cursor, pcd_index) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_read_int16(&cursor, &data.int16_data[info->num_vertical - i - 1]) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } coda_cursor_goto_parent(&cursor); coda_cursor_goto_parent(&cursor); if (i < info->num_vertical - 1) { if (coda_cursor_goto_next_array_element(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } } return 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); }
static int init_dimensions(ingest_info *info) { coda_cursor cursor; if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, "nl_geolocation") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_get_num_elements(&cursor, &info->num_vertical) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } return 0; }
static int init_cursors(ingest_info *info) { const char *wavenumber_path; const char *radiance_path; if (coda_cursor_set_product(&info->wavenumber_cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } info->radiance_cursor = info->wavenumber_cursor; info->time_cursor = info->wavenumber_cursor; info->geometric_info_cursor = info->wavenumber_cursor; if (info->band_id < 6) { wavenumber_path = "exposureAttribute/pointAttribute/RadiometricCorrectionInfo/spectrumObsWavelengthRange_SWIR"; } else { wavenumber_path = "exposureAttribute/pointAttribute/RadiometricCorrectionInfo/spectrumObsWavelengthRange_TIR"; } if (coda_cursor_goto(&info->wavenumber_cursor, wavenumber_path) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } switch (info->band_id) { case 0: case 1: radiance_path = "Spectrum/SWIR/band1/obsWavelength"; break; case 2: case 3: radiance_path = "Spectrum/SWIR/band2/obsWavelength"; break; case 4: case 5: radiance_path = "Spectrum/SWIR/band3/obsWavelength"; break; default: radiance_path = "Spectrum/TIR/band4/obsWavelength"; } if (coda_cursor_goto(&info->radiance_cursor, radiance_path) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto(&info->time_cursor, "exposureAttribute/pointAttribute/Time") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto(&info->geometric_info_cursor, "exposureAttribute/pointAttribute/geometricInfo") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } return 0; }
static int read_illumination_condition(void *user_data, long index, harp_array data) { ingest_info *info = (ingest_info *)user_data; coda_cursor cursor; int32_t condition; (void)index; /* prevent unused warning */ if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, "nl_summary_quality") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_first_array_element(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (info->format_version == 0) { if (coda_cursor_goto_record_field_by_name(&cursor, "limb_flag") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } else { if (coda_cursor_goto_record_field_by_name(&cursor, "obs_illum_cond") != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } if (coda_cursor_read_int32(&cursor, &condition) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } switch (condition) { case 0: data.string_data[0] = strdup("dark"); break; case 1: data.string_data[0] = strdup("bright"); break; case 2: data.string_data[0] = strdup("twilight"); break; case 3: data.string_data[0] = strdup("straylight"); break; case 4: data.string_data[0] = strdup("twilight/straylight"); break; default: harp_set_error(HARP_ERROR_INGESTION, "invalid illumination condition value (%ld) in product", (long)condition); return -1; } if (data.string_data[0] == NULL) { harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not duplicate string) (%s:%u)", __FILE__, __LINE__); return -1; } return 0; }
static int get_std_profile(ingest_info *info, const char *datasetname, const char *fieldname, const char *std_fieldname, harp_array data) { coda_cursor cursor; int i; if (coda_cursor_set_product(&cursor, info->product) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_record_field_by_name(&cursor, datasetname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_goto_first_array_element(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } for (i = 0; i < info->num_vertical; i++) { long index = info->num_vertical - i - 1; if (coda_cursor_goto_record_field_by_name(&cursor, std_fieldname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_read_double(&cursor, &data.double_data[index]) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } coda_cursor_goto_parent(&cursor); if (info->has_absolute_error && strcmp(datasetname, "nl_local_species_density") == 0) { if (data.double_data[index] == 6554) { /* set invalid values to NaN */ data.double_data[index] = harp_nan(); } else { /* perform exponent scaling */ data.double_data[index] = pow(10, 0.005 * data.double_data[index]); } } else { if (data.double_data[index] == 6553.5) { /* set invalid values to NaN */ data.double_data[index] = harp_nan(); } else { double value; if (coda_cursor_goto_record_field_by_name(&cursor, fieldname) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } if (coda_cursor_read_double(&cursor, &value) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } coda_cursor_goto_parent(&cursor); /* scale the relative error in '%' to an absolute error */ data.double_data[index] = fabs(data.double_data[index] * 0.01 * value); } } if (i < info->num_vertical - 1) { if (coda_cursor_goto_next_array_element(&cursor) != 0) { harp_set_error(HARP_ERROR_CODA, NULL); return -1; } } } return 0; }