/* * Copyright (C) 1998 by Southwest Research Institute (SwRI) * * All rights reserved under U.S. Copyright Law and International Conventions. * * The development of this Software was supported by contracts NAG5-3148, * NAG5-6855, NAS8-36840, NAG5-2323, and NAG5-7043 issued on behalf of * the United States Government by its National Aeronautics and Space * Administration. Southwest Research Institute grants to the Government, * and others acting on its behalf, a paid-up nonexclusive, irrevocable, * worldwide license to reproduce, prepare derivative works, and perform * publicly and display publicly, by or on behalf of the Government. * Other than those rights granted to the United States Government, no part * of this Software may be reproduced in any form or by any means, electronic * or mechanical, including photocopying, without permission in writing from * Southwest Research Institute. All inquiries should be addressed to: * * Director of Contracts * Southwest Research Institute * P. O. Drawer 28510 * San Antonio, Texas 78228-0510 * * * Use of this Software is governed by the terms of the end user license * agreement, if any, which accompanies or is included with the Software * (the "License Agreement"). An end user will be unable to install any * Software that is accompanied by or includes a License Agreement, unless * the end user first agrees to the terms of the License Agreement. Except * as set forth in the applicable License Agreement, any further copying, * reproduction or distribution of this Software is expressly prohibited. * Installation assistance, product support and maintenance, if any, of the * Software is available from SwRI and/or the Third Party Providers, as the * case may be. * * Disclaimer of Warranty * * SOFTWARE IS WARRANTED, IF AT ALL, IN ACCORDANCE WITH THESE TERMS OF THE * LICENSE AGREEMENT. UNLESS OTHERWISE EXPLICITLY STATED, THIS SOFTWARE IS * PROVIDED "AS IS", IS EXPERIMENTAL, AND IS FOR NON-COMMERCIAL USE ONLY, * AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT * SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. * * Limitation of Liability * * SwRI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED AS A RESULT OF USING, * MODIFYING, CONTRIBUTING, COPYING, DISTRIBUTING, OR DOWNLOADING THIS * SOFTWARE. IN NO EVENT SHALL SwRI BE LIABLE FOR ANY INDIRECT, PUNITIVE, * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGE (INCLUDING LOSS OF BUSINESS, * REVENUE, PROFITS, USE, DATA OR OTHER ECONOMIC ADVANTAGE) HOWEVER IT ARISES, * WHETHER FOR BREACH OF IN TORT, EVEN IF SwRI HAS BEEN PREVIOUSLY ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. YOU HAVE SOLE RESPONSIBILITY FOR ADEQUATE * PROTECTION AND BACKUP OF DATA AND/OR EQUIPMENT USED IN CONNECTION WITH THE * SOFTWARE AND WILL NOT MAKE A CLAIM AGAINST SwRI FOR LOST DATA, RE-RUN TIME, * INACCURATE OUTPUT, WORK DELAYS OR LOST PROFITS RESULTING FROM THE USE OF * THIS SOFTWARE. YOU AGREE TO HOLD SwRI HARMLESS FROM, AND YOU COVENANT NOT * TO SUE SwRI FOR, ANY CLAIMS BASED ON USING THE SOFTWARE. * * Local Laws: Export Control * * You acknowledge and agree this Software is subject to the U.S. Export * Administration Laws and Regulations. Diversion of such Software contrary * to U.S. law is prohibited. You agree that none of the Software, nor any * direct product therefrom, is being or will be acquired for, shipped, * transferred, or reexported, directly or indirectly, to proscribed or * embargoed countries or their nationals, nor be used for nuclear activities, * chemical biological weapons, or missile projects unless authorized by U.S. * Government. Proscribed countries are set forth in the U.S. Export * Administration Regulations. Countries subject to U.S embargo are: Cuba, * Iran, Iraq, Libya, North Korea, Syria, and the Sudan. This list is subject * to change without further notice from SwRI, and you must comply with the * list as it exists in fact. You certify that you are not on the U.S. * Department of Commerce's Denied Persons List or affiliated lists or on the * U.S. Department of Treasury's Specially Designated Nationals List. You agree * to comply strictly with all U.S. export laws and assume sole responsibilities * for obtaining licenses to export or reexport as may be required. * * General * * These Terms represent the entire understanding relating to the use of the * Software and prevail over any prior or contemporaneous, conflicting or * additional, communications. SwRI can revise these Terms at any time * without notice by updating this posting. * * Trademarks * * The SwRI logo is a trademark of SwRI in the United States and other countries. * */ #ident "@(#) read_idf_once.c 1.46 05/08/19 SwRI" #include #include #include "gen_defs.h" #include "ret_codes.h" #include "libbase_idfs.h" #include "user_defs.h" #include "libVIDF.h" #include "libdb.h" SDDAS_SHORT ir_MapCoordSystemStringToNumber (char *); /****************************************************************************** * * * IR_READ_IDF_ONCE SUBROUTINE * * * * DESCRIPTION * * This routine is called to retrieve information from the VIDF file that * * will be utilized by various subroutines. The pertinent information is * * stored in the appropriate experiment_info structure. This information is * * flagged as "non-changeable" data when multiple VIDF files are involved. * * This information should only be "re-read" when a file boundary change is * * incurred (multiple VIDFS that change at file boundary). * * * * INPUT VARIABLES * * SDDAS_SHORT btime_yr the start time requested (year component) * * SDDAS_SHORT btime_day the start time requested (day component) * * SDDAS_LONG btime_sec the start time requested (seconds component) * * SDDAS_LONG btime_nsec the start time requested (nanoseconds) * * SDDAS_SHORT etime_yr the stop time requested (year component) * * SDDAS_SHORT etime_day the stop time requested (day component) * * SDDAS_LONG etime_sec the stop time requested (seconds component) * * SDDAS_LONG etime_nsec the stop time requested (nanoseconds) * * * * USAGE * * x = ir_read_idf_once (btime_yr, btime_day, btime_sec, btime_nsec, * * etime_yr, etime_day, etime_sec, etime_nsec) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * ReadVIDF() reads information from the VIDF file * * malloc() allocates memory * * free () frees previously allocated memory * * ir_once_rval () returns an error code unique to this module * * for each possible ReadVIDF() error code * * ir_assign_pointers() assigns the pointers for the header, data, * * and calibration data elements * * ir_read_idf_update () reads information from the VIDF file (this * * information is flagged as "changeable" when * * multiple VIDF files are involved) * * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure that holds specific * * *ex experiment information * * struct ptr_rec *ptr a pointer to the structure which holds all * * pointers to the header and data for the exper- * * iment of interest * * register SDDAS_SHORT i,j looping variables * * size_t bytes the number of bytes to allocate * * size_t num_bytes_schar the number of bytes needed for a SDDAS_CHAR * * size_t num_bytes_sshort the number of bytes needed for a SDDAS_SHORT * * int ret_val holds the value returned by the called routine * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_LONG offset offset to index into allocated memory * * SDDAS_LONG start_at_zero param. passed to ReadVIDF to avoid casting * * SDDAS_LONG max_ind cumulative index value for memory location * * for array variables * * SDDAS_SHORT rval holds the value returned by the called routine * * SDDAS_SHORT fast_index fastest changing index (the last dimension) * * for the tensor * * SDDAS_CHAR largest_size the largest word length of all sensors in the * * virtual instrument (in bits) * * SDDAS_CHAR *coord_system coordinate system string * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_read_idf_once (SDDAS_SHORT btime_yr, SDDAS_SHORT btime_day, SDDAS_LONG btime_sec, SDDAS_LONG btime_nsec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec) { extern struct general_info ginfo; struct experiment_info *ex; struct ptr_rec *ptr; register SDDAS_SHORT i, j; SDDAS_ULONG data_key; SDDAS_LONG offset, start_at_zero, max_ind; SDDAS_SHORT rval, fast_index; SDDAS_CHAR largest_size, *coord_system = NULL; /* Leave variables as is, no typedefs. */ size_t bytes, num_bytes_schar; int ret_val; void *tmp_ptr; /**************************************************************************/ /* Retrieve pertinent information from the VIDF file that needs to be */ /* stored in the experiment_info structure. */ /**************************************************************************/ start_at_zero = 0; ex = ginfo.expt; data_key = ex->data_key; ptr = ex->info_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->max_nss, _MAX_NSS, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /**************************************************************************/ /* This should be the first attempt to read from the VIDF file so check */ /* that the file is not online. This is new since the old method tried */ /* to open the VIDF file (ex->fdi), which is no longer the case. */ /**************************************************************************/ else if (ret_val == NO_DATA) return (NO_DATA); /**************************************************************************/ /* Retrieve the header format since the value for this field will */ /* determine settings of other VIDF fields. */ /**************************************************************************/ ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->header_format, _HEADER_FORMAT, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /**************************************************************************/ /* Make sure header format is valid before proceeding. */ /**************************************************************************/ if (ex->header_format < ORIGINAL_HEADER || ex->header_format > TENSOR_SINGLE_HEADER) return (ONCE_BAD_HEADER_FMT); /**************************************************************************/ /* Pick up any tensor related information from the VIDF file. */ /**************************************************************************/ if (ex->header_format == TENSOR_SINGLE_HEADER) { ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->tensor_rank, _TENSOR_RANK, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); if (ex->tensor_rank < 1 || ex->tensor_rank > IDFS_MAX_DIMEN) return (ONCE_BAD_TENSOR_RANK); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->tensor_sizes, _TENSOR_LENGTHS, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); for (i = 0; i < ex->tensor_rank; ++i) if (ex->tensor_sizes[i] <= 0) return (ONCE_BAD_TENSOR_LENGTHS); /***************************************************************************/ /* Since a full tensor is ALWAYS written (no partials), compute once. */ /***************************************************************************/ ex->tensor_elements = ex->tensor_sizes[0]; for (i = 1; i < ex->tensor_rank; ++i) ex->tensor_elements *= ex->tensor_sizes[i]; fast_index = ex->tensor_rank - 1; ex->tnext_dimen[fast_index] = 0; for (i = 0; i < fast_index; ++i) { for (max_ind = 1, j = i + 1; j <= fast_index; ++j) max_ind *= ex->tensor_sizes[j]; ex->tnext_dimen[i] = max_ind; } } ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->smp_id, _SMP_ID, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->max_packing, _MAX_PACKING, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->cal_sets, _CAL_SETS, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->da_method, _DA_METHOD, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->num_tbls, _NUM_TBLS, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->num_modes, _STATUS, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /**************************************************************************/ /* Allocate the space to hold the cal target values and the word length */ /* (in bits) for each cal. set. */ /**************************************************************************/ if (ex->cal_target != NO_MEMORY) { free ((void *) ex->cal_target); ex->cal_target = NO_MEMORY; } if (ex->cal_wlen != NO_MEMORY) { free ((void *) ex->cal_wlen); ex->cal_wlen = NO_MEMORY; } if (ex->cal_scope != NO_MEMORY) { free ((void *) ex->cal_scope); ex->cal_scope = NO_MEMORY; } if (ex->cal_d_type != NO_MEMORY) { free ((void *) ex->cal_d_type); ex->cal_d_type = NO_MEMORY; } num_bytes_schar = sizeof (SDDAS_CHAR); bytes = ex->cal_sets * num_bytes_schar; if (bytes != 0) { if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_CTARGET_MALLOC); ex->cal_target = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->cal_target, _CAL_TARGET, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_CLEN_MALLOC); ex->cal_wlen = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->cal_wlen, _CAL_WLEN, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_CSCOPE_MALLOC); ex->cal_scope = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->cal_scope, _CAL_SCOPE, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_CDTYPE_MALLOC); ex->cal_d_type = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->cal_d_type, _CAL_D_TYPE, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); } else { ex->cal_target = NO_MEMORY; ex->cal_wlen = NO_MEMORY; ex->cal_scope = NO_MEMORY; ex->cal_d_type = NO_MEMORY; } /*************************************************************************/ /* An array of SDDAS_SHORT of size CAL_SETS is needed for the cal_use */ /* array and an array of SDDAS_ULONG is needed to hold the number of */ /* elements in each calibration set. If space has been previously */ /* allocated, free old memory before new space is allocated. */ /*************************************************************************/ if (ex->cal_sets != 0) { size_t num_bytes_sshort; num_bytes_sshort = sizeof (SDDAS_SHORT); bytes = (ex->cal_sets * num_bytes_sshort) + (ex->cal_sets * sizeof (SDDAS_ULONG)); if (ex->bmem.base_cal != NO_MEMORY) { free (ex->bmem.base_cal); ex->bmem.base_cal = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (CAL_DATA_MALLOC); ex->bmem.base_cal = tmp_ptr; ex->CSET_NUM = (SDDAS_ULONG *) ((SDDAS_CHAR *) ex->bmem.base_cal); /* Cast base_cal to char * since void * and offset is in bytes. */ offset = (ex->cal_sets * sizeof (SDDAS_ULONG)); ex->CAL_USE = (SDDAS_SHORT *) ((SDDAS_CHAR *) ex->bmem.base_cal + offset); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->CAL_USE, _CAL_USE, 0, start_at_zero, ex->cal_sets); if (ret_val < 0) return (ir_once_rval (ret_val)); } else { ex->bmem.base_cal = NO_MEMORY; ex->CAL_USE = NO_MEMORY; ex->CSET_NUM = NO_MEMORY; } ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->num_sensor, _SEN, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->swp_len, _SWP_LEN, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /************************************************************************/ /* Determine if nano second adjustment factor is present in data array.*/ /************************************************************************/ ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->nano_defined, _NANO_DEFINED, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /************************************************************************/ /* This indicator should only be changed at file boundaries, not */ /* within a data file. If it is not defined (default case for old VIDF*/ /* files), default it to coordinate system info. not defined. Due to */ /* consistency with other code within libVIDF, MUST define space to */ /* hold the string, so this 1st line is necessary since libVIDF assumes*/ /* space exists - it does not create the space. */ /************************************************************************/ /* cs_str[0] = '\0'; sptrs[0] = &cs_str[0]; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &sptrs [0], _COORD_SYSTEM, 0, start_at_zero, 1); */ ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &coord_system, _COORD_SYSTEM, 0, start_at_zero, 1); if (ret_val < 0 && ret_val != VIDF_ELEMENT_NOT_FOUND) return (ir_once_rval (ret_val)); if (ret_val == ALL_OKAY && coord_system != NULL) /* ex->coord_system = ir_MapCoordSystemStringToNumber (cs_str); */ ex->coord_system = ir_MapCoordSystemStringToNumber (coord_system); else ex->coord_system = NO_SPECIFIED_CS; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ptr->d_size, _DATA_LEN, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ptr->d_size, _DATA_LEN, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); /************************************************************************/ /* If space has been previously allocated, free old memory before new */ /* space is allocated. */ /************************************************************************/ bytes = ptr->d_size; if (ex->bmem.base_data != NO_MEMORY) { free (ex->bmem.base_data); ex->bmem.base_data = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_DATA_MALLOC); ex->bmem.base_data = tmp_ptr; ex->DATA_MEM = (SDDAS_CHAR *) ex->bmem.base_data; /**************************************************************************/ /* The last zero represents a null pointer which is valid to set since */ /* that pointer is past on to a module ONLY when setting header pointers */ /* which is NOT indicated by this calling sequence (only data ptrs). */ /**************************************************************************/ rval = ir_assign_pointers (0, 1, 0); if (rval != ALL_OKAY) return (rval); /**************************************************************************/ /* The flags that are being set depend on the sen_mode value and need to */ /* be set only once for use in determining the time of the data sample. */ /**************************************************************************/ ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &ex->sen_mode, _SEN_MODE, 0, start_at_zero, 1); if (ret_val < 0) return (ir_once_rval (ret_val)); ex->TRC = 1 - ex->sen_mode / 4; ex->TRP = 1 - ((ex->sen_mode % 4) / 2); ex->TCP = 1 - (ex->sen_mode % 2); /**************************************************************************/ /* Allocate the space to hold the data format for each sensor. */ /**************************************************************************/ bytes = ex->num_sensor * num_bytes_schar; if (ex->d_type != NO_MEMORY) { free ((void *) ex->d_type); ex->d_type = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_D_TYPE_MALLOC); ex->d_type = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->d_type, _D_TYPE, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); /**************************************************************************/ /* Get the word length for all sensors and find the largest word size */ /* which is used to pack the data in the data array. */ /**************************************************************************/ bytes = ex->num_sensor * num_bytes_schar; if (ex->sen_tdw_len != NO_MEMORY) { free ((void *) ex->sen_tdw_len); ex->sen_tdw_len = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_TDW_LEN_MALLOC); ex->sen_tdw_len = (SDDAS_CHAR *) tmp_ptr; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->sen_tdw_len, _TDW_LEN, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); largest_size = 0; for (i = 0; i < ex->num_sensor; ++i) if (*(ex->sen_tdw_len + i) > largest_size) largest_size = *(ex->sen_tdw_len + i); /**************************************************************************/ /* Modification to include calibration word lengths in the determination */ /* of the largest data size -- c. gurgiolo (3-23-94) */ /**************************************************************************/ if (ex->cal_wlen != NO_MEMORY) { for (i = 0; i < ex->cal_sets; ++i) if (*(ex->cal_wlen + i) > largest_size) largest_size = *(ex->cal_wlen + i); } ex->tdw_len = largest_size; /**************************************************************************/ /* Allocate the space to hold the table type and table var values for */ /* each defined table. The info. is retrieved by ir_read_idf_update(). */ /**************************************************************************/ if (ex->bmem.base_inst_tbl_info != NO_MEMORY) { free (ex->bmem.base_inst_tbl_info); ex->bmem.base_inst_tbl_info = NO_MEMORY; } if (ex->num_tbls != 0) { bytes = ex->num_tbls * sizeof (struct inst_tbl_info); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_TBL_INFO_MALLOC); ex->bmem.base_inst_tbl_info = tmp_ptr; ex->tbl_info_ptr = (struct inst_tbl_info *) ex->bmem.base_inst_tbl_info; } else { ex->bmem.base_inst_tbl_info = NO_MEMORY; ex->tbl_info_ptr = NO_MEMORY; } /**************************************************************************/ /* Allocate the space that holds the start of spin offset values for each*/ /* sensor. Read in the offset values. If space has been previously */ /* allocated, free old memory before new space is allocated. */ /**************************************************************************/ bytes = ex->num_sensor * sizeof (SDDAS_LONG); if (ex->bmem.base_start_spin_off != NO_MEMORY) { free (ex->bmem.base_start_spin_off); ex->bmem.base_start_spin_off = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_SPIN_OFF_MALLOC); ex->bmem.base_start_spin_off = tmp_ptr; ex->start_spin_off = (SDDAS_LONG *) ex->bmem.base_start_spin_off; ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->start_spin_off, _SPIN_TIME_OFF, 0, start_at_zero, -1); if (ret_val < 0) return (ir_once_rval (ret_val)); /**************************************************************************/ /* Allocate the space to the sensor status flags for each sensor. The */ /* information is retrieved by ir_read_idf_update(). */ /**************************************************************************/ bytes = ex->num_sensor * num_bytes_schar; if (ex->sen_status != NO_MEMORY) { free ((void *) ex->sen_status); ex->sen_status = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (ONCE_SEN_STAT_MALLOC); ex->sen_status = (SDDAS_CHAR *) tmp_ptr; /***************************************************************************/ /* Current restrictions on various fields for tensor processing. */ /***************************************************************************/ if (ex->header_format == TENSOR_SINGLE_HEADER) { /* No tables for unit conversion - lua functions specified in VIDF file */ if (ex->num_tbls != 0) return (ONCE_BAD_NUM_TBLS); if (ex->max_nss != 1) return (ONCE_BAD_MAX_NSS); if (ex->smp_id != 3) return (ONCE_BAD_SMP_ID); if (ex->da_method != 0) return (ONCE_BAD_DA_METHOD); if (ex->swp_len != 1) return (ONCE_BAD_SWP_LEN); if (ex->sen_mode != 3 && ex->sen_mode != 7) return (ONCE_BAD_SEN_MODE); /* Make sure values associated with calibration data are valid. */ for (i = 0; i < ex->cal_sets; ++i) if (*(ex->cal_target + i) == 1) return (ONCE_BAD_CAL_TARGET); } /***************************************************************************/ /* Continue retrieving other information from the VIDF file. */ /***************************************************************************/ rval = ir_read_idf_update (btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); return (rval); } /******************************************************************************* * * * IR_ONCE_RVAL SUBROUTINE * * * * DESCRIPTION * * This routine returns an error code unique to IR_READ_IDF_ONCE() based * * upon the error code returned by the call to ReadVIDF(). * * * * INPUT VARIABLES * * int ret_val the error code returned by ReadVIDF() * * * * USAGE * * x = ir_once_rval (ret_val) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * None * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_once_rval (int ret_val) { switch (ret_val) { case IDF_MANY_BYTES: return (ONCE_IDF_MANY_BYTES); case IDF_TBL_NUM: return (ONCE_IDF_TBL_NUM); case IDF_CON_NUM: return (ONCE_IDF_CON_NUM); case IDF_NO_ENTRY: return (ONCE_IDF_NO_ENTRY); case VIDF_ELEMENT_NOT_FOUND: return (ONCE_IDF_ELE_NOT_FOUND); default: return ((SDDAS_SHORT) ret_val); } } SDDAS_SHORT ir_MapCoordSystemStringToNumber (char *cs_str) { SDDAS_SHORT cs_id; int ret_code; /* Set to indicate coordinate system info. not specified. */ /* Will get reset if a match is found. */ cs_id = NO_SPECIFIED_CS; /* Find which coordinate system string was inputted. */ /* Compare the two strings, ignoring the case of the characters. */ if (cs_str[0] == 'S' || cs_str[0] == 's') { ret_code = strcasecmp (cs_str, "SPACECRAFT"); if (ret_code == 0) cs_id = SPACECRAFT_CS; else { ret_code = strcasecmp (cs_str, "SM"); if (ret_code == 0) cs_id = SM_CS; } } else if (cs_str[0] == 'P' || cs_str[0] == 'p') { ret_code = strcasecmp (cs_str, "PMI"); if (ret_code == 0) cs_id = PMI_CS; } else if (cs_str[0] == 'G' || cs_str[0] == 'g') { ret_code = strcasecmp (cs_str, "GEI"); if (ret_code == 0) cs_id = GEI_CS; else { ret_code = strcasecmp (cs_str, "GEO"); if (ret_code == 0) cs_id = GEO_CS; else { ret_code = strcasecmp (cs_str, "GSE"); if (ret_code == 0) cs_id = GSE_CS; else { ret_code = strcasecmp (cs_str, "GSM"); if (ret_code == 0) cs_id = GSM_CS; } } } } else if (cs_str[0] == 'M' || cs_str[0] == 'm') { ret_code = strcasecmp (cs_str, "MAG"); if (ret_code == 0) cs_id = MAG_CS; } else if (cs_str[0] == 'H' || cs_str[0] == 'h') { ret_code = strcasecmp (cs_str, "HEE"); if (ret_code == 0) cs_id = HEE_CS; else { ret_code = strcasecmp (cs_str, "HAE"); if (ret_code == 0) cs_id = HAE_CS; else { ret_code = strcasecmp (cs_str, "HEEQ"); if (ret_code == 0) cs_id = HEEQ_CS; } } } return (cs_id); }