/* * 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 "@(#) get_tbl_info.c 1.26 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * IR_GET_TBL_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called in order to retrieve the table information for * * all integer tables. Ascii tables are not considered in this module; the * * ascii information is kept in a different structure if it is needed. * * Since the number of tables vary from virtual instrument to virtual * * instrument, the space to hold the table information must be allocated * * as the information becomes known. * * * * INPUT VARIABLES * * SDDAS_SHORT sen the sensor being processed * * SDDAS_SHORT sensor_index index into the SPTR structure to point to the * * correct sensor combination structure * * 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_get_tbl_info (sen, sensor_index, 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 * * free () frees allocated memory * * malloc() allocates memory * * ReadVIDF() reads information from the VIDF file * * ir_tbl_size () determines the total number of bytes needed to * * hold all integer table values for all tables * * ir_get_new_tbl() reads the requested table for the sensor from * * the VIDF file * * * * 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 * * *ex specific experiment information * * struct sensor_tables a pointer to the structure which holds the * * *sptr various information for the tables utilized * * by sensor-table combination being processed * * struct inst_tbl_info a pointer to the structure which holds the * * *tbl_info_ptr non-array table definition information for * * each table defined for the data source * * register SDDAS_SHORT i looping variable * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_LONG offset indexing variable * * SDDAS_LONG half_tbl offset used to position table[0] location at * * the middle of the table (for signed int) * * SDDAS_UINT bytes the number of bytes to allocate * * SDDAS_SHORT rval holds the value returned by called routine * * int ret_val the value returned by the called routine * * void *tmp_ptr pointer which holds address passed back by the * * call to the MALLOC routine * * size_t num_bytes_schar the number of bytes needed for a SDDAS_CHAR * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_get_tbl_info (SDDAS_SHORT sen, SDDAS_SHORT sensor_index, 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 sensor_tables *sptr; struct inst_tbl_info *tbl_info_ptr; register SDDAS_SHORT i; SDDAS_ULONG data_key; SDDAS_LONG offset, half_tbl; SDDAS_UINT bytes; SDDAS_SHORT rval; /* Leave variables as is, no typedefs. */ int ret_val; void *tmp_ptr; size_t num_bytes_schar, num_bytes_slong; /*************************************************************************/ /* Point to the correct sensor_tables structure. */ /*************************************************************************/ ex = ginfo.expt; data_key = ex->data_key; sptr = ex->sen_tbl_ptr + sensor_index; sptr->base_tbls = NO_MEMORY; sptr->base_misc_tbls = NO_MEMORY; sptr->num_tbls = 0; /************************************************************************/ /* Include only non-ascii tables when counting the number of tables to */ /* be applied. Do not include mode-dependent tables. */ /************************************************************************/ for (i = 0; i < ex->num_tbls; ++i) { tbl_info_ptr = ex->tbl_info_ptr + i; if (tbl_info_ptr->tbl_var == FN_RAW_MODE || tbl_info_ptr->tbl_var == FN_PROCESSED_MODE) continue; if (tbl_info_ptr->tbl_type != ASCII_TBL) ++sptr->num_tbls; } /************************************************************************/ /* Pick up all INTEGER tables. */ /************************************************************************/ if (sptr->num_tbls != 0) { /***********************************************************************/ /* Allocate the space to hold the expand, fmt, size, and pointer to */ /* the table values for each integer table. */ /***********************************************************************/ num_bytes_schar = sizeof (SDDAS_CHAR); num_bytes_slong = sizeof (SDDAS_LONG); if (sptr->base_misc_tbls != NO_MEMORY) { free (sptr->base_misc_tbls); sptr->base_misc_tbls = NO_MEMORY; } bytes = (num_bytes_slong + sizeof (SDDAS_FLOAT *) + num_bytes_schar + num_bytes_schar) * sptr->num_tbls; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (TBL_MISC_MALLOC); sptr->base_misc_tbls = tmp_ptr; /***********************************************************************/ /* Set various pointers to the space allocated to hold table info. */ /***********************************************************************/ sptr->tbl_size = (SDDAS_LONG *) sptr->base_misc_tbls; offset = sptr->num_tbls * num_bytes_slong; /* Cast base_misc_tbls to char * since void * and offset is in bytes. */ sptr->tbl_ptr = (SDDAS_FLOAT **) ((SDDAS_CHAR *) sptr->base_misc_tbls + offset); offset += sptr->num_tbls * sizeof (SDDAS_FLOAT *); sptr->tbl_expand = (SDDAS_CHAR *) ((SDDAS_CHAR *) sptr->base_misc_tbls + offset); offset += sptr->num_tbls * num_bytes_schar; sptr->tbl_fmt = (SDDAS_CHAR *) ((SDDAS_CHAR *) sptr->base_misc_tbls + offset); /***********************************************************************/ /* Loop over all defined tables for this virtual instrument. */ /***********************************************************************/ for (i = 0; i < ex->num_tbls; ++i) { /********************************************************************/ /* Exclude mode-dependent tables. */ /********************************************************************/ tbl_info_ptr = ex->tbl_info_ptr + i; if (tbl_info_ptr->tbl_var == FN_RAW_MODE || tbl_info_ptr->tbl_var == FN_PROCESSED_MODE) continue; /********************************************************************/ /* Integer information is processed, not ASCII information. We can*/ /* directly use index i even though only sptr->num_tbls is used to */ /* allocate space since we added the restiction that all ASCII/MODE*/ /* tables be defined AFTER all other tables. */ /********************************************************************/ if (tbl_info_ptr->tbl_type != ASCII_TBL) { ret_val = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *)(sptr->tbl_fmt + i), _TBL_FMT, i, (SDDAS_LONG) sen, 1); if (ret_val < 0) { switch (ret_val) { case IDF_MANY_BYTES: return (TBL_IDF_MANY_BYTES); case IDF_TBL_NUM: return (TBL_IDF_TBL_NUM); case IDF_CON_NUM: return (TBL_IDF_CON_NUM); case IDF_NO_ENTRY: return (TBL_IDF_NO_ENTRY); case VIDF_ELEMENT_NOT_FOUND: return (TBL_IDF_ELE_NOT_FOUND); default: return ((SDDAS_SHORT) ret_val); } } /******************************************************************/ /* New error checks added. If tbl_fmt = 0, only raw data can be */ /* used as look up values into the table. */ /******************************************************************/ if (*(sptr->tbl_fmt + i) == 0) { /***************************************************************/ /* Only raw cal. data allowed for sweep length dependent */ /* tables. */ /***************************************************************/ if (tbl_info_ptr->tbl_type == INTEGER_SCAN_TBL && tbl_info_ptr->tbl_var >= 0) return (TBL_VAR_NOT_CAL); /***************************************************************/ /* TBL_VAR = 1 means processed data, which is not allowed, */ /* must be raw. */ /***************************************************************/ else if (tbl_info_ptr->tbl_type == INTEGER_TBL && tbl_info_ptr->tbl_var == FN_PROCESSED_DATA) return (TBL_VAR_NOT_RAW); } /*****************************************************************/ /* The TBL_EXPAND flag pertains to polynomial coefficients only.*/ /* Always set the flag to a 1 for lookup tables. For the tables*/ /* defined for each step, do not expand coefficients for now */ /* for sake of size. */ /*****************************************************************/ if (*(sptr->tbl_fmt + i) > 0) *(sptr->tbl_expand + i) = (tbl_info_ptr->tbl_type == INTEGER_SCAN_TBL) ? 0 : tbl_info_ptr->tbl_expand; else *(sptr->tbl_expand + i) = 1; } } /*********************************************************************/ /* Determine how much space to allocate for INTEGER table values. */ /* Ascii strings are saved in a different structure. */ /*********************************************************************/ ir_tbl_size (sensor_index, &bytes); /***********************************************************************/ /* If all tables are ASCII tables, no space needs to be allocated to */ /* hold INTEGER values and the pointers can be set to indicate no */ /* memory for integer values. */ /***********************************************************************/ if (bytes == 0) { sptr->base_tbls = NO_MEMORY; sptr->tbls = NO_MEMORY; } /*********************************************************************/ /* Allocate the space to hold the different table values. */ /*********************************************************************/ else { if (sptr->base_tbls != NO_MEMORY) { free (sptr->base_tbls); sptr->base_tbls = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (TBL_MALLOC); sptr->base_tbls = tmp_ptr; sptr->tbls = (SDDAS_FLOAT *) sptr->base_tbls; /********************************************************************/ /* Loop over all defined tables for this virtual instrument. */ /********************************************************************/ offset = 0; for (i = 0; i < ex->num_tbls; ++i) { /*****************************************************************/ /* Exclude mode-dependent tables. */ /*****************************************************************/ tbl_info_ptr = ex->tbl_info_ptr + i; if (tbl_info_ptr->tbl_var == FN_RAW_MODE || tbl_info_ptr->tbl_var == FN_PROCESSED_MODE) continue; /************************************************************/ /* Retrieve all integer (non-ascii) tables. */ /************************************************************/ if (tbl_info_ptr->tbl_type != ASCII_TBL) { /************************************************************/ /* If the format is negative, this table is not used. */ /* Otherwise, retrieve the table values. */ /************************************************************/ if (*(sptr->tbl_fmt + i) >= 0) { *(sptr->tbl_ptr + i) = sptr->tbls + offset; rval = ir_get_new_tbl (sen, i, *(sptr->tbl_expand + i), *(sptr->tbl_fmt + i), *(sptr->tbl_ptr + i), *(sptr->tbl_size + i), (SDDAS_LONG) -1, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) return (rval); offset += *(sptr->tbl_size + i); /************************************************************/ /* If the injest data is a signed binary quantity, table */ /* is a fn of raw sensor data which contains coefficients, */ /* and the table has been expanded, move the table pointer */ /* to the middle of the table so that indexing can be done */ /* for negative values (index by -n). */ /************************************************************/ if (*(ex->d_type + sen) == 1 && tbl_info_ptr->tbl_var == FN_RAW_SENSOR && *(sptr->tbl_fmt + i) > 0 && *(sptr->tbl_expand + i) == 1) { half_tbl = *(sptr->tbl_size + i) / 2; *(sptr->tbl_ptr + i) += half_tbl; } } } } } } return (ALL_OKAY); }