/* * 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 "@(#) sen_combo.c 1.33 05/08/19 SwRI" #include #include #include #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * IR_SENSOR_COMBO SUBROUTINE * * * * DESCRIPTION * * This routine is called to determine the number of different combinations * * possible for the tables used by the sensors that are being utilized. The * * TBL_OFF values for all tables and the CRIT_STATUS values are used and * * compared to see how many unique combinations of these tables are necessary * * instead of allocating space for every table for the sensors that are being * * utilized. Once the number of combinations have been determined, space is * * allocated for the structure(s) that hold the information for the combos. * * * * INPUT VARIABLES * * SDDAS_SHORT btime_yr start time requested (year component) * * SDDAS_SHORT btime_day start time requested (day component) * * SDDAS_LONG btime_sec start time requested (seconds component) * * SDDAS_LONG btime_nsec start time requested (nanoseconds) * * SDDAS_SHORT etime_yr stop time requested (year component) * * SDDAS_SHORT etime_day stop time requested (day component) * * SDDAS_LONG etime_sec stop time requested (seconds component) * * SDDAS_LONG etime_nsec stop time requested (nanoseconds) * * * * USAGE * * x = ir_sensor_combo (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 * * malloc() allocates memory * * free() frees allocated memory * * memset () memory initialization routine * * ReadVIDF() reads information from the VIDF file * * ir_count_combo() determines the number of different combinations * * ir_get_sensor_tables() reads table offset values from the VIDF file * * ir_init_sensor_ptr() initializes the sensor_ptr structures which * * hold the table information for the combinations * * * * 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 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 * * SDDAS_LONG **tbl_ptrs an array of pointers to memory that holds the * * offset values for each table defined * * SDDAS_LONG offset, next_tbl index values into allocated memory * * SDDAS_LONG sensor_block offset to get to next sensor block * * SDDAS_SHORT i looping variable * * SDDAS_SHORT rval holds the value returned by the called routine * * SDDAS_SHORT num_combo the number of unique table combinations needed * * for all sensors for the virtual instrument being* * processed * * SDDAS_CHAR *chk_tbl an array of flags which indicates if the table * * offset values need to be checked in the combo * * comparison (one flag per table) * * SDDAS_CHAR *chk_crit an array of flags which indicates if the * * crit_status values need to be checked in the * * combo comparison * * SDDAS_CHAR first_time flag indicating the first time this module is * * called for the combination being processed * * SDDAS_CHAR crit_tbl the table flagged as the critical status table * * SDDAS_CHAR **crit_stat_ptrs array of ptrs to memory that holds the * * crit_status values * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * size_t num_bytes_schar the number of bytes needed for a SDDAS_CHAR * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * void *base_tables memory that is allocated to hold all the offset * * values for the various tables for all sensors * * void *base_ptr pointer to memory that holds pointers to the * * memory for the different offset values * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_sensor_combo (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 inst_tbl_info *tbl_info_ptr; SDDAS_LONG **tbl_ptrs, offset, next_tbl, sensor_block; SDDAS_SHORT i, rval, num_combo; SDDAS_CHAR *chk_tbl, *chk_crit, first_time, crit_tbl, **crit_stat_ptrs; /* Leave variables as is, no typedefs. */ size_t bytes, num_bytes_slong, num_bytes_schar; void *tmp_ptr, *base_tables, *base_ptr; /****************************************************************************/ /* Determine the number of bytes needed to compare all table offset values */ /* for each sensor (offsets are longs) and the crit_status values, which */ /* are characters. Return error code on malloc error. */ /****************************************************************************/ ex = ginfo.expt; num_bytes_slong = sizeof (SDDAS_LONG); num_bytes_schar = sizeof (SDDAS_CHAR); bytes = (ex->num_tbls * ex->num_sensor * num_bytes_slong) + (ex->num_tbls * ex->num_sensor * num_bytes_schar); if (bytes == 0) base_tables = NO_MEMORY; else { if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SCOM_TBL_MALLOC); base_tables = tmp_ptr; memset (base_tables, '0', bytes); } /****************************************************************************/ /* Allocate space to hold pointers to the memory for the different offset */ /* values being compared and to hold flags that indicate if the offsets */ /* need to be checked in the combination comparisons. */ /****************************************************************************/ bytes = (ex->num_tbls * sizeof (SDDAS_LONG *)) + (ex->num_tbls * sizeof (SDDAS_CHAR *)) + (ex->num_tbls * num_bytes_schar) + (ex->num_tbls * num_bytes_schar); if (bytes == 0) base_ptr = NO_MEMORY; else { if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SCOM_PTR_MALLOC); base_ptr = tmp_ptr; } /* Cast base_ptr to char * since void * and offset is in bytes. */ tbl_ptrs = (SDDAS_LONG **) base_ptr; offset = ex->num_tbls * sizeof (SDDAS_LONG *); crit_stat_ptrs = (SDDAS_CHAR **) ((SDDAS_CHAR *) base_ptr + offset); offset += (ex->num_tbls * sizeof (SDDAS_CHAR *)); chk_tbl = (SDDAS_CHAR *) ((SDDAS_CHAR *) base_ptr + offset); offset += ex->num_tbls * num_bytes_schar; chk_crit = (SDDAS_CHAR *) ((SDDAS_CHAR *) base_ptr + offset); offset = ex->num_tbls * ex->num_sensor * num_bytes_slong; ex->crit_action = 0; sensor_block = 0; for (i = 0; i < ex->num_tbls; ++i, sensor_block += ex->num_sensor) { next_tbl = num_bytes_slong * sensor_block; *(tbl_ptrs + i) = (SDDAS_LONG *) ((SDDAS_CHAR *) base_tables + next_tbl); *(chk_tbl + i) = 1; *(crit_stat_ptrs + i) = (SDDAS_CHAR *) ((SDDAS_CHAR *) base_tables + offset + sensor_block); tbl_info_ptr = ex->tbl_info_ptr + i; *(chk_crit + i) = (tbl_info_ptr->crit_act_sz == 0) ? 0 : 1; ex->crit_action += (tbl_info_ptr->crit_act_sz == 0) ? 0 : 1; } /**************************************************************************/ /* Retrieve information from the VIDF file. */ /**************************************************************************/ rval = ir_get_sensor_tables (chk_tbl, chk_crit, tbl_ptrs, crit_stat_ptrs, &crit_tbl, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) return (rval); /************************************************************************/ /* Malloc space for the sensor index array that indicates which combo */ /* the sensor utilizes and initialize the values. -1 means that the */ /* sensor is not being plotted so no combination was assigned. */ /************************************************************************/ if (ex->bmem.base_tbl_index != NO_MEMORY) { free (ex->bmem.base_tbl_index); ex->bmem.base_tbl_index = NO_MEMORY; } bytes = ex->num_sensor * sizeof (SDDAS_SHORT); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SCOM_INDEX_MALLOC); ex->bmem.base_tbl_index = tmp_ptr; ex->index_sen_tbl = (SDDAS_SHORT *) ex->bmem.base_tbl_index; for (i = 0; i < ex->num_sensor; ++i) *(ex->index_sen_tbl + i) = -1; /*************************************************************************/ /* Determine the number of unique combinations necessary to process all */ /* requested sensors for the virtual instrument being processed. */ /*************************************************************************/ num_combo = ir_count_combo (chk_tbl, chk_crit, tbl_ptrs, crit_stat_ptrs, crit_tbl); if (num_combo < 0) return (num_combo); /*************************************************************************/ /* Malloc the space to hold all the combinations requested. Initialize */ /* the structure(s) which hold the unique combination offsets. */ /*************************************************************************/ if (ex->bmem.base_sen_ptr != NO_MEMORY) { free (ex->bmem.base_sen_ptr); ex->bmem.base_sen_ptr = NO_MEMORY; first_time = 0; } else first_time = 1; bytes = sizeof (struct sensor_tables) * num_combo; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SCOM_SEN_PTR_MALLOC); ex->bmem.base_sen_ptr = tmp_ptr; ex->sen_tbl_ptr = (struct sensor_tables *) ex->bmem.base_sen_ptr; ex->num_combo = num_combo; /*********************************************************************/ /* Reset chk_crit values since ir_get_sensor_tables() may modify */ /* the values in preparation for the call to ir_count_combo (). */ /*********************************************************************/ for (i = 0; i < ex->num_tbls; ++i) { tbl_info_ptr = ex->tbl_info_ptr + i; *(chk_crit + i) = (tbl_info_ptr->crit_act_sz == 0) ? 0 : 1; } rval = ir_init_sensor_ptr (num_combo, crit_stat_ptrs, first_time, crit_tbl, chk_crit, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) return (rval); /***************************************************************************/ /* Free memory that does not need to be saved (used for holding purposes).*/ /***************************************************************************/ if (base_tables != NO_MEMORY) free (base_tables); if (base_ptr != NO_MEMORY) free (base_ptr); return (ALL_OKAY); }