/* * 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_bin.c 1.31 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libtrec_idfs.h" /******************************************************************************* * * * SET_BIN_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to allocate a structure that holds all of the * * information that is pertinent to the binning of the data for the buffers * * and the data matrices used for the collapsing over dimensions. One * * bin_info structure is allocated for the data set being requested if it has * * not been already allocated. If the structure has already been allocated * * and initialized, the routine simply returns to the calling routine; * * therefore, the first call to this module will set the binning information * * to be used for all plots. This action is necessary since data matrices * * are allocated based upon this information and all plots use the same data * * matrices. * * * * 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 swp_type flag indicating if the bins are to be created * * assuming a fixed sweep (pps) or variable sweep* * SDDAS_FLOAT start center value for the start bin for variable * * sweep processing * * SDDAS_FLOAT stop center value for the stop bin for variable * * sweep processing * * SDDAS_FLOAT delta the delta value (skip increment) to use to * * create the bins for variable sweep processing * * SDDAS_SHORT num_bins the number of center bin values * * SDDAS_CHAR swp_fmt indicates if the bins are to be created with * * zero, log, linear or variable width spacing * * SDDAS_CHAR num_center number of tables to apply to get center values* * for variable width scan bins * * SDDAS_CHAR *center_tbls array of tables to be applied to get center * * values for variable width scan bins * * SDDAS_LONG *center_opers array of operations to be applied to tables * * for variable width scan bins * * SDDAS_CHAR num_calc_band number of tables to apply to get band values * * for variable width scan bins * * SDDAS_CHAR *band_tbls array of tables to be applied to get band * * values for variable width scan bins * * SDDAS_LONG *band_opers array of operations to be applied to tables * * for variable width scan bins * * SDDAS_CHAR num_upper_band number of tables to apply to get upper edge * * band values for variable width scan bins that * * specify the actual (fmt = 'A') values * * SDDAS_CHAR *upper_band_tbls array of tables to be applied to get band * * values for variable width scan bins that * * specify the actual (fmt = 'A') values * * SDDAS_LONG *upper_band_opers array of operations to be applied to * * tables for variable width scan bins that * * specify the actual (fmt = 'A') values * * SDDAS_CHAR vfmt the format flag for variable width band values* * SDDAS_CHAR input_fmt indicates if POINT or BAND storage is desired * * SDDAS_CHAR bin_fill indicates how missing data bins are to be * * filled in * * * * USAGE * * x = set_bin_info (data_key, exten, vnum, swp_type, start, stop, delta, * * num_bins, swp_fmt, num_center, center_tbls, * * center_opers, num_calc_band, band_tbls, band_opers, * * num_upper_band, upper_band_tbls, upper_band_opers, * * vfmt, input_fmt, bin_fill) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * ir_reset_collapse_data () re-initializes the collapse_data structure * * set_collapse_info () allocates the space that is needed to hold * * information that is pertinent to collapsing * * of the data over multiple dimensions * * ir_set_vwidth_info () sets up the information for variable width * * scan bins * * * * 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 * * *ex specific experiment information * * struct bin_info *bptr a pointer to the structure that holds sweep * * binning information * * size_t bytes the number of bytes to allocate * * register SDDAS_SHORT i looping variable * * SDDAS_FLOAT fdummy floating point parameter placeholder * * SDDAS_FLOAT delta_phi the requested resolution for the phi angle * * averaging (determines no. of bins) * * SDDAS_SHORT ret_val holds value returned by the called routine * * SDDAS_SHORT num_units the total number of units or data levels to * * be returned for all sensors (should be the * * same for all sensors) * * SDDAS_CHAR interleave flag indicating if the data is to be inter- * * leaved (data not cleared out if missing on * * next sweep) * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT set_bin_info (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, SDDAS_CHAR swp_type, SDDAS_FLOAT start, SDDAS_FLOAT stop, SDDAS_FLOAT delta, SDDAS_SHORT num_bins, SDDAS_CHAR swp_fmt, SDDAS_CHAR num_center, SDDAS_CHAR *center_tbls, SDDAS_LONG *center_opers, SDDAS_CHAR num_calc_band, SDDAS_CHAR *band_tbls, SDDAS_LONG *band_opers, SDDAS_CHAR num_upper_band, SDDAS_CHAR *upper_band_tbls, SDDAS_LONG *upper_band_opers, SDDAS_CHAR vfmt, SDDAS_CHAR input_fmt, SDDAS_CHAR bin_fill) { extern struct general_info ginfo; struct experiment_info *ex; struct bin_info *bptr; register SDDAS_SHORT i; size_t bytes; SDDAS_FLOAT fdummy, delta_phi; SDDAS_SHORT ret_val, num_units; SDDAS_CHAR interleave; 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_BIN_NOT_FOUND); } /**************************************************************************/ /* Scalar instruments can only use FIXED SWEEP processing and for the */ /* sake of argument, set swp_fmt to LINEAR spacing. */ /**************************************************************************/ ex = ginfo.expt; if (ex->smp_id == 2) { swp_type = FIXED_SWEEP; swp_fmt = LIN_SPACING; } /**************************************************************************/ /* DA_METHOD = 1 can not use BAND STORAGE for VARIABLE SWEEPS. */ /**************************************************************************/ else if (ex->da_method == 1 && swp_type == VARIABLE_SWEEP) input_fmt = POINT_STORAGE; /***************************************************************************/ /* For fixed sweep usage, always allocate swp_len bins regardless of what */ /* the user asks for. */ /***************************************************************************/ if (swp_type == FIXED_SWEEP) num_bins = ex->swp_len; /**************************************************************************/ /* Zero Spacing and Variable Width Spacing can only be selected with */ /* Fixed Sweep processing. */ /**************************************************************************/ if ((swp_fmt == ZERO_SPACING || swp_fmt == VARIABLE_SPACING) && swp_type != FIXED_SWEEP) return (SET_BIN_BAD_FMT); /**************************************************************************/ /* Allocate the bin_info structure for this data set if it has not been */ /* already allocated. This information is only pertinent once. */ /* Successive calls with the same key value will be ignored. This is */ /* necessary since data matrices are allocated based upon this info. */ /**************************************************************************/ if (ex->bin_ptr == NO_MEMORY) { bytes = sizeof (struct bin_info); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SET_BIN_MALLOC); ex->bmem.base_bin = tmp_ptr; ex->bin_ptr = (struct bin_info *) ex->bmem.base_bin; bptr = ex->bin_ptr; bptr->num_tbls = 0; bptr->tbl_info = NO_MEMORY; bptr->swp_tbls = NO_MEMORY; bptr->tbl_oper = NO_MEMORY; bptr->bin_fill = bin_fill; bptr->input_fmt = input_fmt; bptr->swp_type = swp_type; bptr->num_bins = num_bins; bptr->start_center = start; bptr->stop_center = stop; bptr->delta_bin = delta; bptr->swp_fmt = swp_fmt; bptr->base_center = NO_MEMORY; bptr->base_bands = NO_MEMORY; bptr->center_val = NO_MEMORY; bptr->band_low = NO_MEMORY; bptr->band_high = NO_MEMORY; bptr->num_center_band = 1; bptr->num_converted = bptr->num_bins; /************************************************************************/ /* Malloc space for the sensor index array that gives offsets into */ /* the center and band arrays. */ /************************************************************************/ bytes = ex->num_sensor * sizeof (SDDAS_SHORT); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SET_BIN_INDEX_MALLOC); bptr->base_index = tmp_ptr; bptr->sen_index = (SDDAS_SHORT *) bptr->base_index; for (i = 0; i < ex->num_sensor; ++i) *(bptr->sen_index + i) = 0; ret_val = ir_set_vwidth_info (num_center, center_tbls, center_opers, num_calc_band, band_tbls, band_opers, num_upper_band, upper_band_tbls, upper_band_opers, vfmt); if (ret_val != ALL_OKAY) return (ret_val); /**********************************************************************/ /* If the user called set_collapse_info BEFORE calling set_bin_info, */ /* reset since the number of bins is used to allocate space. */ /**********************************************************************/ if (ex->bmem.base_collapse != NO_MEMORY) { ir_reset_collapse_data (); interleave = ex->collapse_ptr->interleave; num_units = ex->collapse_ptr->num_units; delta_phi = ex->collapse_ptr->delta_phi; ret_val = set_collapse_info (data_key, exten, vnum, num_units, delta_phi, &fdummy, interleave); if (ret_val != ALL_OKAY) return (ret_val); } } return (ALL_OKAY); }