/* * 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 "@(#) set_scan.c 1.23 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libtrec_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * SET_SCAN_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to specify the tables/operations to be applied to * * arrive at the desired units for the sweep step values that are associated * * with the data bins. These sweep step values are used when storing the * * data into the data bins. There will either be one scan range defined for * * all sensors to use or there is the possibility that each sensor can define * * its own scan range. * * * * INPUT VARIABLES * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_CHAR *exten the filename extension for the data to be used* * SDDAS_USHORT vnum version number to be associated with this * * combination (allows for multiple opens) * * SDDAS_CHAR num_tbls no. of tables to apply for sweep step values * * SDDAS_CHAR *swp_tbls tables to be applied for the sweep step values* * SDDAS_LONG *tbl_oper operations to be applied to tables * * * * USAGE * * x = set_scan_info (data_key, exten, vnum, num_tbls, swp_tbls, tbl_oper) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * realloc() reallocates memory * * read_idf() reads information from the IDF file * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * SDDAS_UINT ir_tmp_bytes number of bytes allocated for scratch space * * void *ir_tmp_space scratch space for various uses * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure that holds * * *ex specific experiment information * * struct bin_info *bptr a pointer to the structure that holds sweep * * binning 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 * * register SDDAS_SHORT sen looping variable * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * int rval holds value returned by called module * * SDDAS_LONG comp_val comparison value * * SDDAS_LONG *tbl_offs table offset values for all sensors * * SDDAS_LONG offset offset into the allocated memory * * SDDAS_SHORT ret_val holds value returned by the called routine * * SDDAS_SHORT first_sen the first sensor being utilized (not all * * sensors for a virtual inst. may be needed) * * SDDAS_CHAR i looping variable * * SDDAS_CHAR which_tbl the table being processed * * char one_scan_range flag indicating one scan range for all sensors* * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT set_scan_info (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, SDDAS_CHAR num_tbls, SDDAS_CHAR *swp_tbls, SDDAS_LONG *tbl_oper) { extern struct general_info ginfo; extern SDDAS_UINT ir_tmp_bytes; extern void *ir_tmp_space; struct experiment_info *ex; struct bin_info *bptr; struct inst_tbl_info *tbl_info_ptr; register SDDAS_SHORT sen; SDDAS_LONG comp_val, *tbl_offs, offset; SDDAS_SHORT ret_val, first_sen; SDDAS_CHAR i, which_tbl; /* Leave variables as is, no typedefs. */ char one_scan_range; size_t bytes, num_bytes_slong; int rval; void *tmp_ptr; /***************************************************************************/ /* Check to see if the requested combination exists. Since a 0 is passed */ /* for the last parameter, the only possible error is that the combo was */ /* not found. */ /***************************************************************************/ if (!ginfo.called_locate) { ret_val = ir_locate_ex (data_key, exten, vnum, 0); if (ret_val != ALL_OKAY) return (SET_SCAN_NOT_FOUND); } /***********************************************************************/ /* Set_bin_info MUST be called by the user BEFORE this routine can be */ /* called. */ /***********************************************************************/ ex = ginfo.expt; if (ex->bin_ptr == NO_MEMORY) return (SCAN_BIN_MISSING); /***********************************************************************/ /* The first call with at least one table will set up the info.; the */ /* other calls will be ignored. */ /***********************************************************************/ bptr = ex->bin_ptr; if (bptr->tbl_info == NO_MEMORY) { /************************************************************************/ /* Find the first sensor being utilized. */ /************************************************************************/ for (sen = 0; sen < ex->num_sensor; ++sen) if (*(ex->sensors_needed + sen) != 0) { first_sen = sen; break; } /******************************************************************/ /* Allocate space to hold table offset values. */ /******************************************************************/ num_bytes_slong = sizeof (SDDAS_LONG); one_scan_range = 1; bytes = ex->num_sensor * num_bytes_slong; if (bytes > ir_tmp_bytes) { if ((tmp_ptr = realloc (ir_tmp_space, bytes)) == NO_MEMORY) return (SCAN_INDEX_MALLOC); ir_tmp_space = tmp_ptr; ir_tmp_bytes = (SDDAS_UINT) bytes; } /******************************************************************/ /* Are there tables to be applied to get the sweep step values? */ /******************************************************************/ if (num_tbls != 0) { bytes = (num_bytes_slong + sizeof (SDDAS_CHAR)) * num_tbls; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SET_SCAN_TBL_MALLOC); bptr->tbl_info = tmp_ptr; /* Cast tbl_info to char * since void * and offset is in bytes. */ bptr->tbl_oper = (SDDAS_LONG *) bptr->tbl_info; offset = num_tbls * num_bytes_slong; bptr->swp_tbls = (SDDAS_CHAR *) ((SDDAS_CHAR *) bptr->tbl_info + offset); bptr->num_tbls = num_tbls; for (i = 0; i < num_tbls; ++i) { *(bptr->swp_tbls + i) = *(swp_tbls + i); *(bptr->tbl_oper + i) = *(tbl_oper + i); /*****************************************************************/ /* -1 is used with combination buffer operations, in which case,*/ /* no table is specified. */ /*****************************************************************/ which_tbl = *(swp_tbls + i); if (which_tbl == -1) continue; /*****************************************************************/ /* This table is a function of a calibration set. */ /*****************************************************************/ tbl_info_ptr = ex->tbl_info_ptr + which_tbl; if (tbl_info_ptr->tbl_var < 0) ex->cal_mod_swp = 1; /*****************************************************************/ /* This table is a function of spacecraft potential data. */ /*****************************************************************/ else if (tbl_info_ptr->tbl_var == FN_SC_POTENTIAL) ex->pot_mod_swp = 1; /******************************************************************/ /* Look at the table offset values for the sweep tables to */ /* determine if center/band values are per sensor or per virtual.*/ /******************************************************************/ rval = read_idf (data_key, exten, vnum, (SDDAS_CHAR *) ir_tmp_space, _TBL_OFF, which_tbl, (SDDAS_LONG) 0, -1); if (rval < 0) { switch (rval) { case VIDF_ELEMENT_NOT_FOUND: return (SCAN_IDF_ELE_NOT_FOUND); case IDF_MANY_BYTES: return (SCAN_IDF_MANY_BYTES); case IDF_TBL_NUM: return (SCAN_IDF_TBL_NUM); case IDF_CON_NUM: return (SCAN_IDF_CON_NUM); case IDF_NO_ENTRY: return (SCAN_IDF_NO_ENTRY); default: return ((SDDAS_SHORT) rval); } } /******************************************************************/ /* If any of the offset values for the sensors being utilized are*/ /* different, different center/band values are to be calculated. */ /******************************************************************/ tbl_offs = (SDDAS_LONG *) ir_tmp_space; comp_val = *(tbl_offs + first_sen); for (sen = first_sen + 1; sen < ex->num_sensor; ++sen) if (*(ex->sensors_needed + sen) != 0 && *(tbl_offs + sen) != comp_val) one_scan_range = 0; } } /******************************************************************/ /* For variable sweep processing, only one scan range defined. */ /* Set this flag so that the "correct" scan values are used for */ /* each sensor when the data is stuffed into the bins. */ /******************************************************************/ if (bptr->swp_type == VARIABLE_SWEEP && !one_scan_range) { ex->cal_mod_swp = 1; ex->pot_mod_swp = 1; one_scan_range = 1; } /************************************************************************/ /* Set the indexes to specify that there is one center/band per sensor.*/ /************************************************************************/ if (!one_scan_range) { first_sen = 0; for (sen = 0; sen < ex->num_sensor; ++sen) if (*(ex->sensors_needed + sen) != 0) { *(bptr->sen_index + sen) = first_sen; ++first_sen; } bptr->num_center_band = first_sen; } } return (ALL_OKAY); }