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

📄 epr_dsd.c

📁 Insar图像处理软件
💻 C
📖 第 1 页 / 共 2 页
字号:
                    epr_set_err(e_err_invalid_data_format,                                "epr_read_each_dsd: invalid file name");                    epr_free_dsd(dsd);                    return NULL;                }            }            /* DS_OFFSET to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "DS_OFFSET=+", EPR_LENGTH_DS_OFFSEN_IDENTIFIER) == 0)            {                if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DS_OFFSEN_FIELD)) || (strncmp(code_block + strlen(code_block) - strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))                {                    epr_set_err(e_err_invalid_data_format,                                 "epr_read_each_dsd: invalid dataset filename format");                    epr_free_dsd(dsd);                    return NULL;                }                tmp = epr_sub_string(code_block, EPR_LENGTH_DS_OFFSEN_IDENTIFIER, strlen(code_block) - strlen("<bytes>") - EPR_LENGTH_DS_OFFSEN_IDENTIFIER - 1);                            dsd->ds_offset = (uint)epr_str_to_number(tmp);                epr_free_string(tmp);                if (dsd->ds_offset == -1)                {                    epr_set_err(e_err_invalid_data_format,                                "epr_read_each_dsd: invalid OFFSET value");                    epr_free_dsd(dsd);                    return NULL;                }            }                            /* DS_SIZE to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "DS_SIZE=+", EPR_LENGTH_DS_SIZE_IDENTIFIER) == 0)            {                if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DS_SIZE_FIELD)) || (strncmp(code_block + strlen(code_block) - strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))                {                    epr_set_err(e_err_invalid_data_format,                                 "epr_read_each_dsd: invalid dataset filename format");                    epr_free_dsd(dsd);                    return NULL;                }                tmp = epr_sub_string(code_block, EPR_LENGTH_DS_SIZE_IDENTIFIER, strlen(code_block) - strlen("<bytes>") - EPR_LENGTH_DS_SIZE_IDENTIFIER - 1);                            dsd->ds_size = (uint)epr_str_to_number(tmp);                epr_free_string(tmp);                if (dsd->ds_size == -1)                {                    epr_set_err(e_err_invalid_data_format,                                "epr_read_each_dsd: invalid OFFSET value");                    epr_free_dsd(dsd);                    return NULL;                }            }            /* NUM_DSR to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "NUM_DSR=+", EPR_LENGTH_NUM_DSR_IDENTIFIER) == 0)            {                if ((uint)strlen(code_block) != (uint)(EPR_LENGTH_NUM_DSR_FIELD))                {                    epr_set_err(e_err_invalid_data_format,                                 "epr_read_each_dsd: invalid dataset record number format");                    epr_free_dsd(dsd);                    return NULL;                }                tmp = epr_sub_string(code_block, EPR_LENGTH_NUM_DSR_IDENTIFIER, strlen(code_block) - EPR_LENGTH_NUM_DSR_IDENTIFIER - 1);                            dsd->num_dsr = (uint)epr_str_to_number(tmp);                epr_free_string(tmp);                if (dsd->num_dsr == -1)                {                    epr_set_err(e_err_invalid_data_format,                                "epr_read_each_dsd: invalid dsr number value");                    epr_free_dsd(dsd);                    return NULL;                }            }            /* DSR_SIZE to be searched for */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if (strncmp (code_block, "DSR_SIZE=+", EPR_LENGTH_DSR_SIZE_IDENTIFIER) == 0)            {                if (((uint)strlen(code_block) != (uint)(EPR_LENGTH_DSR_SIZE_FIELD)) || (strncmp(code_block + strlen(code_block) - strlen("<bytes>") - 1, "<bytes>", strlen("<bytes>")) != 0))                {                    epr_set_err(e_err_invalid_data_format,                                 "epr_read_each_dsd: invalid dataset record size format");                    epr_free_dsd(dsd);                    return NULL;                }                tmp = epr_sub_string(code_block, EPR_LENGTH_DSR_SIZE_IDENTIFIER, strlen(code_block) - strlen("<bytes>") - EPR_LENGTH_DSR_SIZE_IDENTIFIER - 1);                            dsd->dsr_size = (uint)epr_str_to_number(tmp);                epr_free_string(tmp);                if (dsd->dsr_size == -1)                {                    epr_set_err(e_err_invalid_data_format,                                "epr_read_each_dsd: invalid record size value");                    epr_free_dsd(dsd);                    return NULL;                }            }            /* EMPTY LINE BETWEEN DSD's */            fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);            if ((strlen(code_block) > 0) && (code_block[0] != ' '))             {                epr_set_err(e_err_invalid_data_format,                            "epr_read_each_dsd: invalid code_block, must be empty");                epr_free_dsd(dsd);                return NULL;            }            *pos = *pos + 1;            return dsd;        }    }    epr_free_dsd(dsd);    return NULL;}/** * Finds the first 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 sph_length [bytes] the length of SPH part from the given ENVISAT product file, *        must not be <code>NULL</code> * @return the offset to first searched for dsd or <code>0</code> if not found. */uint epr_find_first_dsd(FILE* envisat_source_file, uint sph_length){    uint l;    char code_block[EPR_LINE_MAX_LENGTH];    if (envisat_source_file == NULL)    {            epr_set_err(e_err_file_access_denied,                     "epr_find_first_dsd: the product file handle must not be NULL");        return 0;    }    l = 0;    while (l < sph_length)     {        fgets(code_block, EPR_LINE_MAX_LENGTH, envisat_source_file);        if (strncmp (code_block, "DS_NAME=\"", EPR_LENGTH_DS_NAME_IDENTIFIER) == 0)        {            return l;        }        else {            l += strlen(code_block);        }    }    return 0;}#define EPR_LENGTH_NUM_DSD_FIELD        20/** * Reads all dataset descriptions from an ENVISAT product file.  *  * @param product_id the file identifier, if <code>NULL</code> the function *        immediately returns <code>NULL</code>. * @return an array of dataset descriptions or <code>NULL</code> if an error occured. */EPR_SPtrArray* epr_read_all_dsds(EPR_SProductId* product_id){    EPR_SPtrArray* dsds_array = NULL;    EPR_SRecord* dsd_record = NULL;    const EPR_SField* field;    EPR_SDSD* dsd;    uint sph_length;    char* code_block;    int numread;    ulong dsd_number = 0;    ulong dsd_begin = 0;    uint dsd_index;    if (product_id == NULL) {            epr_set_err(e_err_null_pointer,                     "epr_read_all_dsds: product_id must not be NULL");        return NULL;    }        dsds_array = epr_create_ptr_array(32);    field = epr_get_field(product_id->mph_record, "NUM_DSD");    dsd_number = ((ulong*) field->elems)[0];    /*dsd_begin = epr_api.epr_head_size - dsd_number * EPR_DSD_SIZE;*/    if (fseek(product_id->istream, EPR_MPH_SIZE, SEEK_SET) != 0) {        epr_set_err(e_err_file_access_denied,                     "epr_read_all_dsds: file seek failed");        if (dsds_array != NULL) {            epr_free_ptr_array(dsds_array);        }        return NULL;    }    field = epr_get_field(product_id->mph_record, "SPH_SIZE");    sph_length = ((ulong*) field->elems)[0];    dsd_begin = EPR_MPH_SIZE + (ulong)epr_find_first_dsd(product_id->istream, sph_length);    if (dsd_begin == EPR_MPH_SIZE) {        epr_set_err(e_err_file_access_denied,                     "epr_read_all_dsds: no DS_NAME in SPH");        if (dsds_array != NULL) {            epr_free_ptr_array(dsds_array);        }        return NULL;    }    for(dsd_index = 0; dsd_index < dsd_number; dsd_index ++) {        if (fseek(product_id->istream, dsd_begin + dsd_index * EPR_DSD_SIZE, SEEK_SET) != 0) {            epr_set_err(e_err_file_access_denied,                         "epr_read_all_dsds: file seek failed");            if (dsds_array != NULL) {                epr_free_ptr_array(dsds_array);            }            return NULL;        }        code_block = epr_create_string(EPR_DSD_SIZE);        numread = fread(code_block, 1, EPR_DSD_SIZE, product_id->istream);        if ((uint)numread != EPR_DSD_SIZE) {            epr_set_err(e_err_file_read_error,                 "epr_read_all_dsds: error in reading SPH from product data file");            if (code_block != NULL) {                epr_free_string(code_block);                code_block = NULL;            }            if (dsds_array != NULL) {                epr_free_ptr_array(dsds_array);            }            return NULL;        }        /* If this is NOT an empty DSD (empty DSD's seem to be quite 'normal')          */        if ((strlen(code_block) > 0) && (code_block[0] != ' ')) {            dsd_record = epr_parse_header("dsd", code_block);            dsd = epr_create_dsd(dsd_index);            if (dsd == NULL) {                epr_set_err(e_err_out_of_memory,                             "epr_read_all_dsds: out of memory");                if (code_block != NULL) {                    epr_free_string(code_block);                    code_block = NULL;                }                if (dsd_record != NULL) {                    epr_free_record_info(dsd_record->info);                    dsd_record->info = NULL;                    epr_free_record(dsd_record);                    dsd_record = NULL;                }                if (dsds_array != NULL) {                    epr_free_ptr_array(dsds_array);                }                return NULL;            }            field = epr_get_field(dsd_record, "DS_NAME");            dsd->ds_name = epr_clone_string((char*)field->elems);            field = epr_get_field(dsd_record, "DS_TYPE");            dsd->ds_type = epr_sub_string((char*)field->elems, 0, sizeof(uchar));            field = epr_get_field(dsd_record, "FILENAME");            dsd->filename = epr_clone_string((char*)field->elems);            field = epr_get_field(dsd_record, "DS_OFFSET");            dsd->ds_offset = (uint)((ulong*) field->elems)[0];            field = epr_get_field(dsd_record, "DS_SIZE");            dsd->ds_size = (uint)((ulong*) field->elems)[0];            field = epr_get_field(dsd_record, "NUM_DSR");            dsd->num_dsr = (uint)((ulong*) field->elems)[0];            field = epr_get_field(dsd_record, "DSR_SIZE");            dsd->dsr_size = (uint)((ulong*) field->elems)[0];            epr_add_ptr_array_elem(dsds_array, dsd);            if (dsd_record != NULL) {                /* NOTE:dsd_record->info is not a shared object, it is NOT used by                 * multiple instances of a DSD record, and thus, we free it here!                 */                epr_free_record_info(dsd_record->info);                dsd_record->info = NULL;                epr_free_record(dsd_record);                dsd_record = NULL;            } else {                printf("%s\n", epr_get_last_err_message());            }        } else {            epr_log(e_log_debug, "empty DSD seen (don't worry)");        }                epr_free_string(code_block);        code_block = NULL;    }    rewind(product_id->istream);    return dsds_array;}uint epr_get_num_dsds(const EPR_SProductId* product_id){    return product_id->dsd_array->length;}EPR_SDSD* epr_get_dsd_at(const EPR_SProductId* product_id, uint dsd_index){    EPR_SDSD* dsd = NULL;    dsd = (EPR_SDSD*) epr_get_ptr_array_elem_at(product_id->dsd_array, dsd_index);    return dsd;}

⌨️ 快捷键说明

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