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

📄 epr_dsd.c

📁 Insar图像处理软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id: epr_dsd.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 "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"/** * Opens dsd for a dataset description,  * obtained from an ENVISAT product file. * * @param dsd_index the number of dsd (zero-based), emrty dsd inclusive * * @return the the pointer at the dsd information. */EPR_SDSD* epr_create_dsd(int dsd_index){    EPR_SDSD* dsd;    dsd = (EPR_SDSD*) calloc(1, sizeof (EPR_SDSD));    if (dsd == NULL) {        epr_set_err(e_err_out_of_memory,                     "epr_create_dsd: out of memory");        return NULL;    }    dsd->index = dsd_index;    return dsd;}uint epr_get_num_datasets(EPR_SProductId* product_id){    epr_clear_err();    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_num_datasets: product_id must not be NULL");        return (uint)-1;    }    return product_id->dataset_ids->length;}EPR_SDatasetId* epr_get_dataset_id_at(EPR_SProductId* product_id, uint index){    EPR_SDatasetId* dataset_id = NULL;    epr_clear_err();    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_dataset_id_at: product_id must not be NULL");        return NULL;    }    if (index >= product_id->dataset_ids->length){        epr_set_err(e_err_index_out_of_range,                     "epr_get_dataset_id_at: dataset index out of range");        return NULL;    }    dataset_id = (EPR_SDatasetId*)epr_get_ptr_array_elem_at(product_id->dataset_ids, index);    return dataset_id;}EPR_SDatasetId* epr_get_dataset_id(EPR_SProductId* product_id, const char* dataset_name){    EPR_SDatasetId* dataset_id = NULL;    int datasets_num, i;    epr_clear_err();    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_dataset_id: product_id must not be NULL");        return NULL;    }    if (dataset_name == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_get_dataset_id: dataset_name must not be NULL");        return NULL;    }    datasets_num = epr_get_num_datasets(product_id);    for (i = 0; i < datasets_num; i ++) {			dataset_id = epr_get_dataset_id_at(product_id, i);        if (epr_equal_names(dataset_name, epr_get_dataset_name(dataset_id)))             return dataset_id;	}    epr_set_err(e_err_invalid_band_name,                 "epr_get_dataset_id: dataset_id not found");    return NULL;}int epr_detect_meris_iodd_version(EPR_SProductId* product_id){	EPR_SDSD** elems;	int size = 0;	int rec_size = 0;	int i;	char* name;    if (strncmp("MER_RR__1P", product_id->id_string, 10) == 0		|| strncmp("MER_FR__1P", product_id->id_string, 10) == 0) {		elems = (EPR_SDSD**)product_id->dsd_array->elems;		size = product_id->dsd_array->length;		for (i=0; i< size;i++){				name = elems[i]->ds_name;			if (strcmp("Flags MDS(16)", name) == 0) {				rec_size = elems[i]->dsr_size;				break;			}		}	}	if (rec_size == 2255 || rec_size == 4495) {		return 5;	} else if (rec_size == 3376 || rec_size == 6736) {		return 6;	} else {		return 6;	}/*    EPR_SDatasetId*  dataset_id = NULL;    if (strncmp("MER_RR__1P", product_id->id_string, 10) == 0){	    dataset_id = epr_get_dataset_id(product_id, "Flags");	    switch (dataset_id->dsd->dsr_size) {        case (2255) :          return 5;        case (3376)  :          return 6;        default:          return -1;		}    } else if (strncmp("MER_FR__1P", product_id->id_string, 10) == 0){	    dataset_id = epr_get_dataset_id(product_id, "Flags");	    switch (dataset_id->dsd->dsr_size) {        case (4495) :          return 5;        case (6736)  :          return 6;        default:          return -1;		}    } else		return 6; */}/** * Release the memory allocated through a dataset ID. *  * @param dsd the dataset description identifier, if <code>NULL</code> the function *        immediately returns zero. * @return zero for success, an error code otherwise */void epr_free_dsd(EPR_SDSD* dsd){    if (dsd == NULL)         return;    epr_free_string(dsd->ds_name);    dsd->ds_name   = NULL;    epr_free_string(dsd->ds_type);    dsd->ds_type   = NULL;    epr_free_string(dsd->filename);    dsd->filename  = NULL;    dsd->index = 0;    dsd->ds_offset = 0;    dsd->ds_size   = 0;    dsd->num_dsr   = 0;    dsd->dsr_size  = 0;    free(dsd);}#define EPR_LENGTH_DS_NAME_IDENTIFIER      9#define EPR_LENGTH_DS_TYPE_IDENTIFIER      8#define EPR_LENGTH_FILENAME_IDENTIFIER    10#define EPR_LENGTH_DS_OFFSEN_IDENTIFIER   11#define EPR_LENGTH_DS_SIZE_IDENTIFIER      9#define EPR_LENGTH_NUM_DSR_IDENTIFIER      9#define EPR_LENGTH_DSR_SIZE_IDENTIFIER    10#define EPR_LENGTH_DS_NAME_FIELD          39#define EPR_LENGTH_DS_TYPE_FIELD          10#define EPR_LENGTH_DS_FILENAME_FIELD      74#define EPR_LENGTH_DS_OFFSEN_FIELD        39#define EPR_LENGTH_DS_SIZE_FIELD          37#define EPR_LENGTH_NUM_DSR_FIELD          20#define EPR_LENGTH_DSR_SIZE_FIELD         28#define EPR_LENGTH_EMPTY_FIELD            33/** * Reads a dataset description from an ENVISAT product file.  *  * @param envisat_source_file the handle of the given ENVISAT product file, *        must not be <code>NULL</code> * @param pos number of the dataset description in ENVISAT product file, * @return a new dataset description or <code>NULL</code> if an error occured. */EPR_SDSD* epr_read_each_dsd(FILE* envisat_source_file, int* pos){    uint l;    uint l_limit;    char code_block[EPR_LINE_MAX_LENGTH];    EPR_SDSD* dsd;    int  ch = '"';    char* tmp;    if (envisat_source_file == NULL)    {            epr_set_err(e_err_file_access_denied,                     "epr_read_each_dsd: the product file handle must not be NULL");        return NULL;    }    dsd = (EPR_SDSD*) calloc(1, sizeof (EPR_SDSD));    if (dsd == NULL)     {        epr_set_err(e_err_out_of_memory,                     "epr_read_each_dsd: out of memory");        return NULL;    }    if (* pos == 0)    {        l_limit = 9999;    }    else l_limit = 0;        for (l = 0; l <= l_limit; l++)     {        fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);        if (strncmp (code_block, "DS_NAME=\"", EPR_LENGTH_DS_NAME_IDENTIFIER) == 0)        {            /* DS_NAME to be searched for */            if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DS_NAME_FIELD)) || ((uint)(strrchr(code_block, ch) - code_block) != (uint)(strlen(code_block) - 2)))            {                epr_set_err(e_err_invalid_data_format,                             "epr_read_each_dsd: invalid dataset name format");                epr_free_dsd(dsd);                return NULL;            }            dsd->ds_name = epr_sub_string(code_block, EPR_LENGTH_DS_NAME_IDENTIFIER, strlen(code_block) - EPR_LENGTH_DS_NAME_IDENTIFIER - 2);            if (dsd->ds_name == NULL)            {                epr_set_err(e_err_invalid_value,                            "epr_read_each_dsd: invalid DS_NAME value");                epr_free_dsd(dsd);                return NULL;            }            /* DS_TYPE to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "DS_TYPE=", EPR_LENGTH_DS_TYPE_IDENTIFIER) == 0)            {                dsd->ds_type = epr_sub_string(code_block, EPR_LENGTH_DS_TYPE_IDENTIFIER, strlen(code_block) - EPR_LENGTH_DS_TYPE_IDENTIFIER - 1);                if (dsd->ds_type == NULL)                {                    epr_set_err(e_err_invalid_value,                                "epr_read_each_dsd: invalid DS_TYPE value");                    epr_free_dsd(dsd);                    return NULL;                }            }            /* FILENAME to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "FILENAME=\"", EPR_LENGTH_FILENAME_IDENTIFIER) == 0)            {                if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DS_FILENAME_FIELD)) || ((uint)(strrchr(code_block, ch) - code_block) != (uint)(strlen(code_block) - 2)))                {                    epr_set_err(e_err_invalid_data_format,                                 "epr_read_each_dsd: invalid dataset filename format");                    epr_free_dsd(dsd);                    return NULL;                }                dsd->filename = epr_sub_string(code_block, EPR_LENGTH_FILENAME_IDENTIFIER, strlen(code_block) - EPR_LENGTH_FILENAME_IDENTIFIER - 1);                if (dsd->ds_name == NULL)                {

⌨️ 快捷键说明

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