⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epr_band.c

📁 Insar图像处理软件
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * $Id: epr_band.c,v 1.2 2003/03/21 16:08:08 norman Exp $ * * Copyright (C) 2002 by Brockmann Consult (info@brockmann-consult.de) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. This program is distributed in the hope it will * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include <assert.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "epr_api.h"#include "epr_core.h"#include "epr_string.h"#include "epr_ptrarray.h"#include "epr_swap.h"#include "epr_field.h"#include "epr_record.h"#include "epr_param.h"#include "epr_dsd.h"#include "epr_msph.h"#include "epr_band.h"#include "epr_bitmask.h"#include "epr_dddb.h"/** * Obtains all bands infos from the dddb.  */EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* product_id){    EPR_SBandId* band_id = NULL;    EPR_SPtrArray* band_ids = NULL;    char test_block[1024];    int bt_index;    int i;    const struct BandDescriptorTable* b_tables;    int num_descr;    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_create_band_ids: product_id must not be NULL");        return NULL;    }    /* @DDDB */    b_tables = dddb_band_tables;    bt_index = -1;    for (i = 0; i < EPR_NUM_BAND_TABLES; i++) {         const char* id = b_tables[i].name;        if (strncmp(product_id->id_string, id, 10) == 0) {            if (product_id->meris_iodd_version == 5) {                if (strcmp(id, "MER_RR__1P_IODD5") == 0 ||                     strcmp(id, "MER_FR__1P_IODD5") == 0) {                    bt_index = i;                }            } else {                bt_index = i;            }        }         if (bt_index != -1) {            break;        }    }    if (bt_index == -1) {        epr_set_err(e_err_null_pointer,                     "epr_create_band_ids: unknown product type");        return NULL;    }    band_ids = epr_create_ptr_array(16);    num_descr = b_tables[bt_index].num_descriptors;    for (i = 0; i < num_descr; i++) {        band_id = (EPR_SBandId*) calloc(1, sizeof (EPR_SBandId));        if (band_id == NULL) {            epr_set_err(e_err_out_of_memory,                         "epr_create_band_ids: out of memory");            return NULL;        }        band_id->magic = EPR_MAGIC_BAND_ID;        band_id->product_id = product_id;        /* 1: band_name */        epr_assign_string(&band_id->band_name, b_tables[bt_index].descriptors[i].id);        /* 2: dataset_name */        band_id->dataset_ref = epr_get_ref_struct(product_id, b_tables[bt_index].descriptors[i].rec_name);        if (band_id->dataset_ref.dataset_id == NULL) {            epr_set_err(e_err_invalid_dataset_name,                         "epr_create_band_ids: invalid dataset name in DDDB");            epr_free_band_id(band_id);            return NULL;        }         /* 3: sample_offset */        band_id->sample_model = b_tables[bt_index].descriptors[i].sample_offset;        /* 4: band_datatype */        band_id->data_type = b_tables[bt_index].descriptors[i].type;        /* 5: spectr_band_index*/        band_id->spectr_band_index = b_tables[bt_index].descriptors[i].spectral_index;        /* 6: scaling_method*/        if (b_tables[bt_index].descriptors[i].scale_method == e_smid_non) {            band_id->scaling_method = 0;            band_id->scaling_offset = 0.0;            band_id->scaling_factor = 1.0;        } else {            band_id->scaling_method = b_tables[bt_index].descriptors[i].scale_method;            /* 7: scaling_offset*/            strcpy (test_block, b_tables[bt_index].descriptors[i].scale_offset);            if (test_block == NULL) {                band_id->scaling_offset = 0.0;            } else {                float scaling_offset = (float)atof(test_block);                if (epr_numeral_suspicion(test_block) == 1) {                    band_id->scaling_offset = scaling_offset;                } else {                    scaling_offset = epr_get_scaling_params(product_id, test_block);                    if (scaling_offset == -909.909) { /* @todo what an ugly return value. Eeeek!*/                        epr_set_err(e_err_invalid_dataset_name,                             "epr_create_band_ids: invalid dataset name in dddb");                        epr_free_band_id(band_id);                        return NULL;                    }                    band_id->scaling_offset = scaling_offset;                }            }            /* 8: scaling_factor*/            strcpy (test_block, b_tables[bt_index].descriptors[i].scale_factor);            if (test_block == NULL) {                band_id->scaling_factor = 0.0;            } else {                float scaling_factor = (float)atof(test_block);                if (epr_numeral_suspicion(test_block) == 1) {                    band_id->scaling_factor = scaling_factor;                } else {                    scaling_factor = epr_get_scaling_params(product_id, test_block);                    if (scaling_factor == -909.909) { /* @todo what an ugly return value. Eeeek!*/                        epr_set_err(e_err_invalid_dataset_name,                             "epr_create_band_ids: invalid dataset name in dddb");                        epr_free_band_id(band_id);                        return NULL;                    }                    band_id->scaling_factor = scaling_factor;                }            }        }        /* 9: bit_expr*/        epr_assign_string(&band_id->bm_expr, b_tables[bt_index].descriptors[i].bitmask_expr);        /* 10: flags_definition_file*/        if (b_tables[bt_index].descriptors[i].flag_coding_name != NULL) {            band_id->flag_coding = epr_create_flag_coding(product_id, b_tables[bt_index].descriptors[i].flag_coding_name);            if (band_id->flag_coding == NULL) {                epr_set_err(e_err_out_of_memory,                     "epr_create_band_ids: out of memory");                epr_free_band_id(band_id);                return NULL;            }        } else {            band_id->flag_coding = NULL;        }        /* 11: unit*/        epr_assign_string(&band_id->unit, b_tables[bt_index].descriptors[i].unit);        /* 12: description*/        epr_assign_string(&band_id->description, b_tables[bt_index].descriptors[i].description);        /* lines_flipped*/        if (strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_MERIS, 3) == 0             || strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_AATSR, 3) == 0) {            band_id->lines_mirrored = TRUE;        } else {            if (strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_ASAR, 3) == 0                && strncmp(product_id->id_string, "ASA_IMG", 7) != 0                && strncmp(product_id->id_string, "ASA_APG", 7) != 0) {                band_id->lines_mirrored = TRUE;            } else {                band_id->lines_mirrored = FALSE;            }        }        epr_add_ptr_array_elem(band_ids, band_id);    }    return band_ids;}uint epr_get_num_bands(EPR_SProductId* product_id){    epr_clear_err();    if (!epr_check_api_init_flag()) {        return 0;    }    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_num_bands: product_id must not be NULL");        return (uint) -1;    }    return product_id->band_ids->length;}EPR_SBandId* epr_get_band_id_at(EPR_SProductId* product_id, uint index){    EPR_SBandId* band_id = NULL;    epr_clear_err();    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_band_id_at: product_id must not be NULL");        return NULL;    }    if (index >= product_id->band_ids->length){        epr_set_err(e_err_index_out_of_range,                     "epr_get_band_id_at: band index out of range");        return NULL;    }    band_id = (EPR_SBandId*)epr_get_ptr_array_elem_at(product_id->band_ids, index);    return band_id;}EPR_SBandId* epr_get_band_id(EPR_SProductId* product_id, const char* band_name){    EPR_SBandId* band_id = NULL;    int num_bands, i;    epr_clear_err();    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_band_id: product_id must not be NULL");        return NULL;    }    if (band_name == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_band_id: dataset_name must not be NULL");        return NULL;    }    num_bands = epr_get_num_bands(product_id);    for (i = 0; i < num_bands; i++) {			band_id = epr_get_band_id_at(product_id, i);        if (epr_equal_names(band_name, epr_get_band_name(band_id))) {            return band_id;        }	}    epr_set_err(e_err_invalid_band_name,                 "epr_get_band_id: band not found");    return NULL;}const char* epr_get_band_name(EPR_SBandId* band_id){    epr_clear_err();        if (band_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_band_name: band_id must not be NULL");        return NULL;    }    return band_id->band_name;}/** * Release the memory allocated through a band ID. *  * @param band the dataset description identifier, if <code>NULL</code> the function *        immediately returns zero. * @return zero for success, an error code otherwise */void epr_free_band_id(EPR_SBandId* band_id){    if (band_id == NULL)         return;    band_id->dataset_ref.elem_index = -1;    band_id->dataset_ref.field_index = -1;    band_id->dataset_ref.dataset_id = NULL;        epr_free_and_null_string(&band_id->band_name);    epr_free_and_null_string(&band_id->bm_expr);    epr_free_flag_coding(band_id->flag_coding);    band_id->flag_coding = NULL;    band_id->spectr_band_index = 0;    band_id->scaling_offset  = 0;    band_id->scaling_factor  = 0;    band_id->data_type = e_tid_unknown;    epr_free_and_null_string(&band_id->unit);    epr_free_and_null_string(&band_id->description);    band_id->lines_mirrored = FALSE;    free(band_id);}/** * Gets the scaling params: factor or offset by the given dataset_id, field_index, elem_index  * * @param product_id the the product file identifier * @param str the string with the name, separator ('.') and indexes. * @return the dataset_id, field_index and elem_index (-1 if no). *    <code>NULL</code> if correspondent dataset name was not found. */float epr_get_scaling_params(EPR_SProductId* product_id,  const char* str){    EPR_SDatasetRef scal_fact;    const EPR_SField* field = NULL;    EPR_SRecord* record = NULL;    float ziff;    scal_fact = epr_get_ref_struct(product_id, str);    if (scal_fact.dataset_id == NULL) {        return (float)(-909.909);    }    /*'Scaling_Factor_GADS'*/    record = epr_create_record(scal_fact.dataset_id);    record = epr_read_record(scal_fact.dataset_id, 0, record);    field = epr_get_field_at(record, scal_fact.field_index - 1);    ziff = epr_get_field_elem_as_float(field, (uint)(scal_fact.elem_index - 1));    epr_free_record(record);    return ziff;}/** * Gets the scaling factor by the given dataset_id, field_index, elem_index  * * @param product_id the the product file identifier * @param str the string with the name, separator ('.') and indexes. * @return the dataset_id, field_index and elem_index (-1 if no). *    <code>NULL</code> if correspondent dataset name was not found. */float epr_get_scaling_factor(EPR_SProductId* product_id,  const char* str)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -