/* * 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 "@(#) conv_sen.c 1.35 05/08/19 SwRI" #include #include "ret_codes.h" #include "user_defs.h" #include "gen_defs.h" #include "libbase_idfs.h" /**************************************************************************** * * * IR_CONVERT_SENSOR_DATA SUBROUTINE * * * * DESCRIPTION * * This routine converts sensor data into physical units by applying the * * specified tables and the table operations in the specified order to * * achieve the desired output. The order is implied by the table * * specification. If the chk_fill flag is set to 1, the data values will * * be compared against the specified FILL value. If the data value is * * identified as a fill value, the value OUTSIDE_MIN will be returned and * * it is up to the user to decide what is to be done with this value. The * * FILL value must be specified in terms of raw telemetry. * * * * INPUT VARIABLES * * SDDAS_SHORT sensor the sensor being processed * * SDDAS_CHAR num_tbls number of tables to apply * * SDDAS_CHAR *tbls_to_apply array of tables to be applied * * SDDAS_LONG *tbl_oper array of operations to be applied to * * tables * * SDDAS_CHAR chk_fill data to be checked for FILL value flag * * SDDAS_FLOAT *ret_data array holding the returned data in * * converted units * * SDDAS_LONG fill_value the value identified as the FILL value * * void *idf_data_ptr ptr to memory location for structure that* * holds returned data values (read_drec) * * * * USAGE * * ir_convert_sensor_data (sensor, num_tbls, tbls_to_apply, tbl_oper, * * &ret_data, chk_fill, fill_value, idf_data_ptr)* * * * NECESSARY SUBPROGRAMS * * ir_transfer_data () converts raw integer telemetry to the * * raw units (integer or SDDAS_FLOAT) * * ir_idf_ex_func () performs higher order table operations * * abs() returns the absolute value of a number * * IDF_OPER[]._math_drv () performs arithmetic operation defined * * for the table being processed * * COMBINE_OPER[]._math_drv() performs the arithmetic operation defined* * to combine the permanent and temporary * * accumulators * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concerning * * the experiment that is being processed * * struct def_oper IDF_OPER[] array of pointers to the routines that * * perform arithmetic operation defined for * * the sensor, sweep, and cal. data tables * * struct def_combine_oper array of pointers to the routines that * * COMBINE_OPER[] perform the arithmetic operation defined * * to combine the permanent and temporary * * accumulators * * void *ir_tmp_space scratch space for various uses * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure holding all of the currently * * returned data values to be processed * * struct experiment_info *ex a pointer to the structure holding * * specific experiment information * * struct sensor_tables *sptr a pointer to the structure holding the * * various information for tables utilized * * by current sensor-table combination * * struct inst_tbl_info a pointer to the structure which holds * * *tbl_info_ptr non-array table definition information * * for each table defined for data source * * register SDDAS_LONG j looping variable * * register SDDAS_ULONG *ul1 pointer to number in each cal set info. * * register SDDAS_CHAR i looping variable * * SDDAS_FLOAT *which_data pointer to the accumulator of interest * * SDDAS_FLOAT *from_data_ptr pointer to the accumulator specified as * * the from data buffer (source) * * SDDAS_FLOAT *to_data_ptr pointer to the accumulator specified as * * the to data buffer (destination) * * SDDAS_LONG data_start offset into the data at which to start * * picking up data values (used for cal.) * * SDDAS_LONG num_data the number of data values being returned * * SDDAS_LONG hold_val number of successive data values within * * a data set that one calibration value is * * to be applied to * * SDDAS_LONG num_ele_in_tbl no. of elements in table being applied * * SDDAS_ULONG *ul_end loop termination variable * * SDDAS_LONG oper_index the table operation to be performed * * SDDAS_LONG tbl_operator the table operator being accessed * * SDDAS_LONG data_offset offset to get to correct advanced buffer * * SDDAS_SHORT index offset to get to the correct SPTR * * structure * * SDDAS_SHORT from_buf_num accumulator defined as from data buffer * * SDDAS_SHORT to_buf_num accumulator defined as to data buffer * * SDDAS_CHAR *sen pointer to sensor data from READ_DREC() * * SDDAS_CHAR *swp pointer to sweep data from READ_DREC() * * SDDAS_CHAR *cal pointer to cal. data from READ_DREC() * * SDDAS_CHAR cur_tbl the current table being processed * * SDDAS_CHAR dtype format of the data - uns int, int, float * * SDDAS_CHAR *data_tbl pointer to data values which the table * * values are to be applied to * * SDDAS_CHAR which_cal the calibration set being processed * * SDDAS_CHAR tbl_var the functional dependence of the table * * SDDAS_CHAR *sc_pot ptr to spacecraft potential data from * * READ_DREC() * * SDDAS_CHAR *background ptr to background data from READ_DREC() * * size_t num_bytes_sfloat number of bytes needed for a SDDAS_FLOAT * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ void ir_convert_sensor_data (SDDAS_SHORT sensor, SDDAS_CHAR num_tbls, SDDAS_CHAR *tbls_to_apply, SDDAS_LONG *tbl_oper, SDDAS_FLOAT *ret_data, SDDAS_CHAR chk_fill, SDDAS_LONG fill_value, void *idf_data_ptr) { extern struct general_info ginfo; extern struct def_oper IDF_OPER[]; extern struct def_combine_oper COMBINE_OPER[]; extern void *ir_tmp_space; struct idf_data *EXP_DATA; struct experiment_info *ex; struct sensor_tables *sptr; struct inst_tbl_info *tbl_info_ptr; register SDDAS_LONG j; register SDDAS_ULONG *ul1; register SDDAS_CHAR i; SDDAS_FLOAT *which_data, *from_data_ptr, *to_data_ptr; SDDAS_LONG data_start, num_data, hold_val, num_ele_in_tbl, oper_index; SDDAS_LONG tbl_operator, data_offset; SDDAS_ULONG *ul_end; SDDAS_SHORT index, from_buf_num, to_buf_num; SDDAS_CHAR *sen, *swp, *cal, cur_tbl, dtype, *data_tbl; SDDAS_CHAR which_cal, tbl_var, *sc_pot, *background; size_t num_bytes_sfloat; /**********************************************************************/ /* Set pointers to sensor, sweep step, and calibration data returned */ /* by the READ_DREC() routine. */ /**********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; sen = (SDDAS_CHAR *) EXP_DATA->sen_data; swp = (SDDAS_CHAR *) EXP_DATA->swp_data; cal = (SDDAS_CHAR *) EXP_DATA->cal_data; sc_pot = (SDDAS_CHAR *) EXP_DATA->potential; background = (SDDAS_CHAR *) EXP_DATA->background; /**********************************************************************/ /* Set pointers to the current sensor being processed. */ /**********************************************************************/ ex = ginfo.expt; index = *(ex->index_sen_tbl + sensor); sptr = ex->sen_tbl_ptr + index; num_data = EXP_DATA->num_sample; num_bytes_sfloat = sizeof (SDDAS_FLOAT); /**********************************************************************/ /* Transfer the integer raw values into the data array to be returned */ /* to the user. */ /**********************************************************************/ ir_transfer_data (ret_data, sen, num_data, *(ex->d_type + sensor), *(ex->sen_tdw_len + sensor), (SDDAS_LONG) 0); /*********************************************************************/ /* If tables are to be applied, convert to the data accordingly. */ /*********************************************************************/ for (i = 0; i < num_tbls; ++i) { /*******************************************************************/ /* Check for combination of accumulators since operations are NOT */ /* table specific. */ /*******************************************************************/ tbl_operator = *(tbl_oper + i); if (tbl_operator > 2000 && tbl_operator < 3000) { which_data = (SDDAS_FLOAT *) ir_tmp_space; oper_index = tbl_operator % 2000; COMBINE_OPER[oper_index % 10]._math_drv (ret_data, which_data, num_data); /************************************************************/ /* Perform the higher order operations. */ /************************************************************/ if (oper_index > 9) ir_idf_ex_func (oper_index/10, ret_data, num_data, idf_data_ptr); continue; } /*******************************************************************/ /* Check for combination of advanced buffers since operations are */ /* NOT table specific. */ /*******************************************************************/ if (tbl_operator > 10000) { /*******************************************************************/ /* Divisions are costly - see if we can change this. */ /*******************************************************************/ from_buf_num = tbl_operator / 10000; to_buf_num = (tbl_operator - from_buf_num * 10000) / 1000; oper_index = tbl_operator - (from_buf_num * 10000) - (to_buf_num * 1000); /* Cast ir_tmp_space to a char. ptr since it is void and offset is in bytes.*/ data_offset = (from_buf_num - 1) * ex->swp_len * num_bytes_sfloat; from_data_ptr = (SDDAS_FLOAT *) ((SDDAS_CHAR *) ir_tmp_space + data_offset); /*******************************************************************/ /* FROM buffer cannot be primary buffer, but TO buffer can be. */ /*******************************************************************/ if (to_buf_num == 0) to_data_ptr = ret_data; else { /* Cast ir_tmp_space to char. ptr since it's void & offset in bytes.*/ data_offset = (to_buf_num - 1) * ex->swp_len * num_bytes_sfloat; to_data_ptr = (SDDAS_FLOAT *) ((SDDAS_CHAR *) ir_tmp_space + data_offset); } COMBINE_OPER[oper_index % 10]._math_drv (to_data_ptr, from_data_ptr, num_data); /************************************************************/ /* Perform the higher order operations. */ /************************************************************/ if (oper_index > 9) ir_idf_ex_func (oper_index/10, to_data_ptr, num_data, idf_data_ptr); continue; } cur_tbl = *(tbls_to_apply + i); tbl_info_ptr = ex->tbl_info_ptr + cur_tbl; tbl_var = tbl_info_ptr->tbl_var; to_buf_num = tbl_operator / 1000; /********************************************************************/ /* A check is made upfront for ASCII tables and tables associated */ /* with status mode information. */ /********************************************************************/ if (tbl_info_ptr->tbl_type == ASCII_TBL) continue; else if (tbl_var == FN_RAW_MODE || tbl_var == FN_PROCESSED_MODE) continue; /********************************************************************/ /* Is this table to be applied for the conversion of the data? */ /* A size of 0 indicates that no table is defined (tbl_fmt < 0); */ /* therefore, this table is bypassed for data conversion. */ /********************************************************************/ if (*(sptr->tbl_size + cur_tbl) != 0) { if (to_buf_num == 0) which_data = ret_data; else { /* Cast ir_tmp_space to char. ptr since it's void & offset in bytes.*/ data_offset = (to_buf_num - 1) * ex->swp_len * num_bytes_sfloat; which_data = (SDDAS_FLOAT *) ((SDDAS_CHAR *) ir_tmp_space + data_offset); } oper_index = tbl_operator % 1000; /*****************************************************************/ /* This table is a function of a calibration set. Determine the */ /* index value to get to the calibration values in question. */ /*****************************************************************/ data_start = 0; if (tbl_var < 0) { which_cal = abs (tbl_var) - 1; /***************************************************************/ /* Okay for data_start to be SDDAS_LONG and not SDDAS_ULONG */ /* since this module is used to convert non-tensor IDFS data. */ /***************************************************************/ ul1 = EXP_DATA->cset_num; ul_end = ul1 + which_cal; for ( ; ul1 < ul_end; ++ul1) data_start += *ul1; /***************************************************************/ /* Determine the number of data elements each cal. value is */ /* to be applied to. A single cal. value is to be applied to */ /* each data element if CAL_USE = 0. */ /***************************************************************/ if (*(ex->CAL_USE + which_cal) == 0) hold_val = EXP_DATA->num_sample; else hold_val = *(ex->CAL_USE + which_cal); data_tbl = cal; dtype = *(ex->cal_d_type + which_cal); } else { /******************************************************************/ /* If the call to read_drec() requested a full_swp (all samples */ /* packed into a sensor set) then hold_val cannot be 1 since */ /* more than 1 value needs to be processed. */ /******************************************************************/ if (ex->smp_id == 2 && num_data != 1) hold_val = num_data; /***************************************************************/ /* Start at the beginning of the data array and there is a one-*/ /* to-one mapping between table elements and data elements. */ /***************************************************************/ else hold_val = 1; /***************************************************************/ /* The table is a function of a processed data, which is */ /* always floating point data (since processed). Place this */ /* conditional first since more than 1 table is most probable. */ /***************************************************************/ if (tbl_var == FN_PROCESSED_DATA) { if (to_buf_num == 0) data_tbl = (SDDAS_CHAR *) ret_data; else { data_offset = (to_buf_num - 1) * ex->swp_len * num_bytes_sfloat; data_tbl = (SDDAS_CHAR *) (ir_tmp_space + data_offset); } dtype = 2; } /************************************************************/ /* The table is a function of raw sensor data. */ /************************************************************/ else if (tbl_var == FN_RAW_SENSOR) { data_tbl = sen; dtype = *(ex->d_type + sensor); } /**************************************************************/ /* The table is a function of raw sweep step data, which is */ /* always unsigned integer binary data. */ /**************************************************************/ else if (tbl_var == FN_RAW_SCAN) { data_tbl = swp; dtype = 0; } /****************************************************************/ /* The table is a function of spacecraft potential data, which */ /* is always floating point data within the EXP_DATA structure.*/ /****************************************************************/ else if (tbl_var == FN_SC_POTENTIAL) { /*************************************************************/ /* No spacecraft potential data? */ /*************************************************************/ if (EXP_DATA->num_potential == 0) continue; data_tbl = sc_pot; dtype = 2; } /****************************************************************/ /* The table is a function of background data, which is always */ /* floating point data within the EXP_DATA structure. */ /****************************************************************/ else if (tbl_var == FN_BACKGROUND) { /*************************************************************/ /* No background data? */ /*************************************************************/ if (EXP_DATA->num_background == 0) continue; data_tbl = background; dtype = 2; } } /****************************************************************/ /* Perform the operation defined for the table. */ /****************************************************************/ if (tbl_info_ptr->tbl_type == INTEGER_SCAN_TBL) num_ele_in_tbl = *(sptr->tbl_size + cur_tbl) / ex->swp_len; else num_ele_in_tbl = *(sptr->tbl_size + cur_tbl); IDF_OPER[oper_index % 10]._math_drv (which_data, data_tbl, data_start, *(sptr->tbl_ptr + cur_tbl), num_ele_in_tbl, num_data, *(sptr->tbl_expand + cur_tbl), dtype, hold_val, tbl_info_ptr->sen_fn_of_raw, *(ex->sen_tdw_len + sensor), tbl_info_ptr->tbl_type, EXP_DATA->swp_data, ex->swp_len); /************************************************************/ /* Perform the higher order operations. */ /************************************************************/ if (oper_index > 9) ir_idf_ex_func (oper_index/10, which_data, num_data, idf_data_ptr); } } /************************************************************************/ /* Check the data for FILL values. If the data is found to be fill */ /* data, the value returned is set to OUTSIDE_MIN. */ /************************************************************************/ if (chk_fill) for (j = 0; j < EXP_DATA->num_sample; ++j) { if (*(EXP_DATA->sen_data + j) == fill_value) *(ret_data + j) = OUTSIDE_MIN; } }