/* * 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 "@(#) count_combo.c 1.23 05/08/19 SwRI" #include #include "gen_defs.h" #include "ret_codes.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_COUNT_COMBO SUBROUTINE * * * * DESCRIPTION * * This routine is called to determine the number of different combinations * * possible for the tables used by the sensors being plotted. The offset * * values for the tables and the CRIT_STATUS arrays are compared to determine * * the number of unique combinations for these tables, which are stored in * * the sensor structure by the calling routine. * * * * INPUT VARIABLES * * SDDAS_CHAR *chk_tbl an array of flags which indicates if the offset * * values of each table need to be checked in the * * combo comparison * * SDDAS_CHAR *chk_crit an array of flags which indicates if the * * crit_status values need to be checked in the * * combo comparison (one flag per table) * * SDDAS_LONG **tbl_ptrs an array of pointers to memory that holds the * * table offset values * * SDDAS_CHAR **crit_stat_ptrs an array of ptrs to memory that holds the * * crit_status values * * SDDAS_CHAR crit_tbl the table flagged as the critical status table * * * * USAGE * * x = ir_count_combo (chk_tbl, chk_crit, tbl_ptrs, crit_stat_ptrs,crit_tbl)* * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * free () frees allocated memory * * * * 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 * * register SDDAS_SHORT i,j looping variables * * SDDAS_LONG *cur_tbl pointer to the current sensor table being * * processed * * SDDAS_LONG *tbl_val array of values being compared against the base * * for each table being compared * * SDDAS_LONG *tbl_comp array of base comparison offset values for each * * table being compared * * SDDAS_SHORT stop_loop looping variables * * SDDAS_SHORT index index for the sensor that is used as the base * * sensor (other sensors compared against this one)* * SDDAS_SHORT comp_index index for the sensors that are compared against * * the base sensor * * SDDAS_SHORT sensors_used the actual number of sensors being utilized for * * the virtual instrument being plotted * * SDDAS_SHORT num_combo the number of unique table combinations needed * * for all sensors for the virtual instrument being* * processed * * SDDAS_SHORT *no_match pointer to the memory allocated to hold the * * sensor number of the sensor(s) that doesn't use * * the same offset values compared to the values * * for the base sensor * * SDDAS_SHORT num_differ the number of sensors that do not use the same * * table offsets as the base sensor * * SDDAS_CHAR crit_val the crit_status value for the base sensor * * SDDAS_CHAR crit_comp crit_status value for the sensor being compared * * SDDAS_CHAR only_one flag that indicates if only one combination is * * being processed * * SDDAS_CHAR diff_val flag indicating that this sensor does not match * * the base offset values for the tables defined * * SDDAS_CHAR crit_stat_chk flag indicating if the critical status values * * need to be checked * * SDDAS_CHAR *cur_crit pointer to the critical status values for the * * table flagged as the critical status table * * SDDAS_CHAR base_dtype the d_type value for comparison purposes * * SDDAS_BOOL different_dtypes flag indicating if d_type varies for sensors * * void *tmp_ptr pointer which holds address passed back by the * * call to the MALLOC routine * * void *base_match pointer to the memory allocated for the array * * that holds the sensor number which does not * * match the combo being tested * * void *base_val pointer to the memory allocated to hold the * * comparison (base) offset values for each table * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_count_combo (SDDAS_CHAR *chk_tbl, SDDAS_CHAR *chk_crit, SDDAS_LONG **tbl_ptrs, SDDAS_CHAR **crit_stat_ptrs, SDDAS_CHAR crit_tbl) { extern struct general_info ginfo; struct experiment_info *ex; register SDDAS_SHORT i, j; SDDAS_LONG *cur_tbl, *tbl_val, *tbl_comp; SDDAS_SHORT stop_loop, index, comp_index, sensors_used, num_combo; SDDAS_SHORT *no_match, num_differ; SDDAS_CHAR crit_val, crit_comp, only_one, diff_val, crit_stat_chk; SDDAS_CHAR *cur_crit, base_dtype; SDDAS_BOOL different_dtypes = sFalse; void *tmp_ptr, *base_match, *base_val; size_t bytes, num_bytes_slong; /***************************************************************************/ /* Determine the number of sensors utilized for the virtual instrument */ /* being processed and initialize the index_sen_tbl value to the first */ /* combo. (all used sensors are initially set to use the same combo) */ /***************************************************************************/ ex = ginfo.expt; base_dtype = *(ex->d_type + 0); for (sensors_used = 0, i = 0; i < ex->num_sensor; ++i) if (*(ex->sensors_needed + i) != 0) { ++sensors_used; *(ex->index_sen_tbl + i) = 0; if (*(ex->d_type + i) != base_dtype) different_dtypes = sTrue; } /***************************************************************************/ /* Determine how many tables are being checked. */ /***************************************************************************/ only_one = 0; crit_stat_chk = 0; for (i = 0; i < ex->num_tbls; ++i) { only_one += *(chk_tbl + i); crit_stat_chk += *(chk_crit + i); } /***************************************************************************/ /* If there is more than one critical action table defined, for now, set */ /* it up so that each sensor needs its own structure. Do the same if the */ /* sensors are NOT the same data type since table expansion depends upon */ /* d_type values. */ /***************************************************************************/ if (ex->crit_action > 1 || different_dtypes == sTrue) { num_combo = 0; for (i = 0; i < ex->num_sensor; ++i) if (*(ex->sensors_needed + i) != 0) { *(ex->index_sen_tbl + i) = num_combo; ++num_combo; } } /***************************************************************************/ /* More than 1 combination is necessary since one of these flags indicated*/ /* that the values were different for the sensors being used. */ /***************************************************************************/ else if (only_one != 0 || crit_stat_chk != 0) { /************************************************************************/ /* Malloc space for the array that holds the sensor number which does */ /* not match the combo being tested and initialize it. */ /************************************************************************/ bytes = sensors_used * sizeof (SDDAS_SHORT); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (CCOM_MATCH_MALLOC); base_match = tmp_ptr; no_match = (SDDAS_SHORT *) base_match; for (j = 0, i = 0; i < ex->num_sensor; ++i) if (*(ex->sensors_needed + i) != 0) { *(no_match + j) = i; ++j; } /*************************************************************************/ /* Allocate space to hold the comparison (base) offset values for each */ /* table and to hold the value being compared against the base. */ /*************************************************************************/ num_bytes_slong = sizeof (SDDAS_LONG); bytes = (ex->num_tbls * num_bytes_slong) + (ex->num_tbls * num_bytes_slong); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (CCOM_VAL_MALLOC); base_val = tmp_ptr; tbl_comp = (SDDAS_LONG *) base_val; /* Cast base_val to char ptr since void and offset is in bytes. */ tbl_val = (SDDAS_LONG *) ((SDDAS_CHAR *) base_val + ex->num_tbls * num_bytes_slong); /*************************************************************************/ /* Determine the number of unique combinations necessary to process all */ /* the requested sensors for the virtual instrument being processed. */ /* Initially, assume the worst case - all sensors are different. */ /*************************************************************************/ num_combo = 0; num_differ = sensors_used; cur_crit = *(crit_stat_ptrs + crit_tbl); /*************************************************************************/ /* Get new base sensor and compare until no differences can be counted. */ /*************************************************************************/ while (num_differ != 0) { /********************************************************************/ /* NO_MATCH[0] holds the base sensor for each iteration. If any */ /* of the tables doesn't need to be included in the comparison, */ /* set the value to 0 for simplification of code. */ /********************************************************************/ index = *(no_match + 0); for (i = 0; i < ex->num_tbls; ++i) { cur_tbl = *(tbl_ptrs + i); *(tbl_comp + i) = (*(chk_tbl + i) == 1) ? *(cur_tbl + index) : 0; } crit_comp = (crit_stat_chk) ? *(cur_crit + index) : 0; stop_loop = num_differ; /*********************************************************************/ /* Compare each of the sensors that did not match the base sensor */ /* in the previous iteration against the new base sensor (values */ /* are set so that the first time thru this while, all sensors */ /* except for the first sensor are checked against the first sensor.*/ /*********************************************************************/ for (i = 1, num_differ = 0; i < stop_loop; ++i) { /******************************************************************/ /* Get the offset values for the sensor being compared against */ /* the base sensor. If any of the tables doesn't need to be */ /* included in the comparison, set the value to 0 for simplifi- */ /* cation of code. */ /******************************************************************/ comp_index = *(no_match + i); for (j = 0; j < ex->num_tbls; ++j) { cur_tbl = *(tbl_ptrs + j); *(tbl_val + j) = (*(chk_tbl+j)==1) ? *(cur_tbl + comp_index) : 0; } crit_val = (crit_stat_chk) ? *(cur_crit + comp_index) : 0; /******************************************************************/ /* If the offset values for this sensor do not match the offset */ /* values for the base sensor, save this sensor number and */ /* increment the counter which indicates how many sensors did */ /* not match the base sensor for this iteration. */ /******************************************************************/ diff_val = 0; for (j = 0; j < ex->num_tbls; ++j) { if (*(tbl_val + j) != *(tbl_comp + j)) diff_val = 1; } if (crit_val != crit_comp) diff_val = 1; if (diff_val) { *(no_match + num_differ) = comp_index; ++num_differ; } } /********************************************************************/ /* Increment the combination counter and set the combination index */ /* value for the sensors that did not match the current base sensor*/ /* to the next combination value. */ /********************************************************************/ ++num_combo; if (num_differ != 0) for (i = 0; i < num_differ; ++i) { index = *(no_match + i); *(ex->index_sen_tbl + index) = num_combo; } } /********************************************************************/ /* Free up temporary space that was allocated. */ /********************************************************************/ free (base_match); free (base_val); } /***************************************************************************/ /* There is only 1 combination since all the table offset and crit_status */ /* values are the same. */ /***************************************************************************/ else num_combo = 1; return (num_combo); }