/* * 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_mode.c 1.18 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_CONVERT_MODE_DATA SUBROUTINE * * * * DESCRIPTION * * This routine is called to convert the mode data for the requested * * mode into 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. * * * * INPUT VARIABLES * * SDDAS_SHORT which_mode the mode 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_FLOAT *ret_data array in which the data is returned in the * * converted units * * void *idf_data_ptr ptr to the memory location for the structure* * that holds returned data values (read_drec) * * * * USAGE * * x = ir_convert_mode_data (which_mode, num_tbls, tbls_to_apply, tbl_oper, * * &ret_data, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_transfer_data () converts the raw integer telemetry to the * * raw units (integer or SDDAS_FLOAT) * * ir_idf_ex_func () performs higher order table operations * * IDF_OPER[]._math_drv () performs the 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 that holds information concerning * * the experiment that is being processed * * struct def_oper IDF_OPER[] array of pointers to the routines that * * perform the arithmetic operation defined * * 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 that holds all of the currently * * returned data values to be processed * * struct experiment_info *ex a pointer to the structure that holds * * specific experiment information * * struct mode_tables *mptr a pointer to the structure which holds the * * mode-dependent table information * * 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_CHAR i, j looping variables * * 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 * * SDDAS_LONG num_data the number of data values being returned * * SDDAS_LONG hold_val the 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 the table being applied * * 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 from_buf_num accumulator defined as the from data buffer * * SDDAS_SHORT to_buf_num accumulator defined as the to data buffer * * SDDAS_CHAR *mode pointer to the mode data from READ_DREC() * * SDDAS_CHAR cur_tbl the current table being processed * * SDDAS_CHAR dtype the format of the data - uns int, int, float* * SDDAS_CHAR *data_tbl pointer to the data values which the table * * values are to be applied to * * SDDAS_CHAR tdw_len word-length of data item * * SDDAS_CHAR tbl_ind index to get to the table in question * * SDDAS_CHAR tbl_var the functional dependence of the table * * size_t num_bytes_sfloat the number of bytes needed for a SDDAS_FLOAT* * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_convert_mode_data (SDDAS_SHORT which_mode, SDDAS_CHAR num_tbls, SDDAS_CHAR *tbls_to_apply, SDDAS_LONG *tbl_oper, SDDAS_FLOAT *ret_data, 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 mode_tables *mptr; struct inst_tbl_info *tbl_info_ptr; register SDDAS_CHAR i, j; SDDAS_FLOAT *which_data, *from_data_ptr, *to_data_ptr; SDDAS_LONG data_start, num_data, hold_val, num_ele_in_tbl; SDDAS_LONG oper_index, tbl_operator, data_offset; SDDAS_SHORT from_buf_num, to_buf_num; SDDAS_CHAR *mode, cur_tbl, dtype, *data_tbl, tdw_len, tbl_ind; SDDAS_CHAR tbl_var; size_t num_bytes_sfloat; /***********************************************************************/ /* Bad mode value? */ /***********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; if (which_mode >= (SDDAS_SHORT) EXP_DATA->mode_len) return (CONV_MODE_BAD_MODE); /***********************************************************************/ /* Transfer the integer raw value into the data array to be returned */ /* to the user. There is no D_TYPE for mode data. It is always an */ /* unsigned long. Return just the mode in question, so one value. */ /***********************************************************************/ ex = ginfo.expt; mode = (SDDAS_CHAR *) EXP_DATA->mode; data_start = which_mode; num_data = 1; ir_transfer_data (ret_data, mode, num_data, 0, 0, data_start); /***********************************************************************/ /* Since tdw_len is used in the IDF_OPER routines only when dtype = 1,*/ /* set this value to zero. (dtype = 0 or 2 for mode values) */ /***********************************************************************/ mptr = ex->mode_tbl_ptr + which_mode; tdw_len = 0; num_bytes_sfloat = sizeof (SDDAS_FLOAT); /*********************************************************************/ /* 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; } /********************************************************************/ /* Find the requested table in the array of tables held for modes. */ /********************************************************************/ cur_tbl = *(tbls_to_apply + i); tbl_info_ptr = ex->tbl_info_ptr + cur_tbl; tbl_ind = -1; for (j = 0; j < mptr->num_tbls; ++j) { if (*(mptr->tbl_num + j) == cur_tbl) { tbl_ind = j; break; } } if (tbl_ind == -1) return (CONV_MODE_BAD_TBL_NUM); /********************************************************************/ /* A check is made upfront for ASCII tables. */ /********************************************************************/ if (tbl_info_ptr->tbl_type == ASCII_TBL) continue; if (tbl_info_ptr->tbl_var != FN_RAW_MODE && tbl_info_ptr->tbl_var != FN_PROCESSED_MODE) return (CONV_MODE_MISMATCH); /********************************************************************/ /* 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. */ /********************************************************************/ to_buf_num = tbl_operator / 1000; if (*(mptr->tbl_size + tbl_ind) != 0) { tbl_var = *(mptr->tbl_var + tbl_ind); 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; hold_val = 1; /************************************************************/ /* The table is a function of raw mode data. */ /************************************************************/ if (tbl_var == FN_RAW_MODE) { data_tbl = mode; dtype = 0; data_start = which_mode; } /***************************************************************/ /* The table is a function of a processed mode data, which is */ /* always floating point data (since processed). */ /***************************************************************/ else { 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; data_start = 0; } /****************************************************************/ /* Perform the operation defined for the table. */ /****************************************************************/ if (tbl_info_ptr->tbl_type == INTEGER_SCAN_TBL) num_ele_in_tbl = *(mptr->tbl_size + tbl_ind) / ex->swp_len; else num_ele_in_tbl = *(mptr->tbl_size + tbl_ind); IDF_OPER[oper_index % 10]._math_drv (which_data, data_tbl, data_start, *(mptr->tbl_ptr + tbl_ind), num_ele_in_tbl, num_data, *(mptr->tbl_expand + tbl_ind), dtype, hold_val, tbl_info_ptr->mode_fn_of_raw, tdw_len, 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); } } return (ALL_OKAY); }