/* * 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 "@(#) center_bands.c 1.27 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libtrec_idfs.h" /******************************************************************************* * * * CENTER_AND_BAND_VALUES SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate the center sweep values and/or the * * sweep band widths for the specified data set. The user must call * * SET_BIN_INFO() prior to calling this module so that all information is * * known concerning bin storage. If this was not the case, an error code is * * returned to the calling module. Memory is allocated to hold the band * * widths and the center values if it has not already been allocated. The * * amount of memory and storage locations for the band width values is * * dependent upon the format of the sweep. If the sweep format is 0, the * * bands are non-contiguous so both upper and lower bands must be kept. For * * the other formats, only one array is needed to hold the contiguous band * * values and one extra bin is needed. The address of the locations where * * these values are held are returned to the user. * * * * 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) * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * SDDAS_CHAR ret_center flag indicating if the center sweep values * * are to be returned * * SDDAS_CHAR ret_band flag indicating if the band widths for the * * sweep are to be returned * * SDDAS_FLOAT **center_ptr pointer to the location that holds the center * * values * * SDDAS_FLOAT **low_ptr pointer to the location for the lower bands * * for non-contiguous bands or all band widths * * for contiguous bands * * SDDAS_FLOAT **high_ptr pointer to the location for the upper bands * * for non-contiguous bands * * SDDAS_SHORT *num_bands the number of band values * * SDDAS_SHORT sensor the sensor of interest * * SDDAS_SHORT *num_converted the number of band values converted to units * * * * USAGE * * x = center_and_band_values (data_key, exten, vnum, idf_data_ptr, sensor, * * ret_center, ret_band, ¢er_ptr, &low_ptr, * * &high_ptr, &num_bands, &num_converted) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * ir_allocate_bands() allocate space for band width values * * ir_allocate_center() allocate space for center sweep values * * ir_calc_center_sweep() calculates the center sweep values * * ir_calc_band_widths() calculates the sweep band widths * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure that holds information concerning * * the experiment that is being processed * * 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 * * register SDDAS_SHORT sen looping variable * * SDDAS_FLOAT *center pointer to the center sweep values * * SDDAS_FLOAT *blow pointer to the lower band width values * * SDDAS_FLOAT *bhigh pointer to the upper band width values * * SDDAS_FLOAT last_low last converted low band width value * * SDDAS_FLOAT last_high last converted high band width value * * SDDAS_LONG offset indexing variable * * SDDAS_LONG bhigh_off offset to get to band_high pointer * * SDDAS_SHORT rval holds value returned by called module * * SDDAS_SHORT fill_index looping variable * * char reset_called flag indicating if LOCATE_EX was called * * char center_space flag indicating space allocated for centers * * char band_space flag indicating space allocated for bands * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT center_and_band_values (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_SHORT sensor, SDDAS_CHAR ret_center, SDDAS_CHAR ret_band, SDDAS_FLOAT **center_ptr, SDDAS_FLOAT **low_ptr, SDDAS_FLOAT **high_ptr, SDDAS_SHORT *num_bands, SDDAS_SHORT *num_converted) { extern struct general_info ginfo; extern void *ir_tmp_space; register struct experiment_info *ex; register SDDAS_SHORT sen; struct bin_info *bptr; SDDAS_FLOAT *center, *blow, *bhigh, last_low, last_high; SDDAS_LONG offset, bhigh_off; SDDAS_SHORT rval, fill_index; char reset_called, center_space = 0, band_space = 0; /**************************************************************************/ /* Check to see if the combination being processed has been processed */ /* before. If not, an error condition - probably didn't call FILE_OPEN. */ /* The user must call SET_BIN_INFO prior to calling this module so that */ /* all information is known concerning bin storage. */ /**************************************************************************/ if (!ginfo.called_locate) { rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (CENTER_NOT_FOUND); ginfo.called_locate = 1; reset_called = 1; } else reset_called = 0; ex = ginfo.expt; if (ex->bin_ptr == NO_MEMORY) return (BPTR_NOT_FOUND); /************************************************************************/ /* Make sure that sensor asked for is being processed. */ /************************************************************************/ if (*(ex->sensors_needed + sensor) == 0) return (CENTER_NO_SENSOR); /************************************************************************/ /* Allocate space to hold the band widths if memory has not already */ /* been allocated. Sweep format 0 is non-contiguous so both upper */ /* and lower bands must be kept. For the other formats, one extra */ /* bin is needed since the one array holds the contiguous band values. */ /************************************************************************/ bptr = ex->bin_ptr; if (ret_band && bptr->base_bands == NO_MEMORY) { band_space = 1; rval = ir_allocate_bands (); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } } /************************************************************************/ /* Allocate space to hold the center band values if memory has not */ /* already been allocated. */ /************************************************************************/ if (ret_center && bptr->base_center == NO_MEMORY) { center_space = 1; rval = ir_allocate_center (1); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } } /***********************************************************************/ /* The first time space is allocated, make sure all center values are */ /* computed for each sensor being processed. */ /***********************************************************************/ if (center_space && bptr->num_center_band != 1) { for (sen = 0; sen < ex->num_sensor; ++sen) if (*(ex->sensors_needed + sen) != 0) { offset = *(bptr->sen_index + sen) * bptr->num_bins; center = (SDDAS_FLOAT *) (bptr->center_val + offset); rval = ir_calc_center_sweep (center, sen, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /*******************************************************************/ /* Be sure to reset ex structure since module calls read_drec() */ /* and VIDF file crossing may cause a reallocation of the existing */ /* ex structures so address may change. */ /*******************************************************************/ ex = ginfo.expt; bptr = ex->bin_ptr; } } /**********************************************************************/ /* Return the center band values if the user requested these values. */ /**********************************************************************/ else if (ret_center) { offset = *(bptr->sen_index + sensor) * bptr->num_bins; center = (SDDAS_FLOAT *) (bptr->center_val + offset); rval = ir_calc_center_sweep (center, sensor, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /*******************************************************************/ /* Be sure to reset ex structure since module calls read_drec() */ /* and VIDF file crossing may cause a reallocation of the existing */ /* ex structures so address may change. */ /*******************************************************************/ ex = ginfo.expt; bptr = ex->bin_ptr; } /**********************************************************************/ /* The center values are needed for the band calculations. If the */ /* user wants only the band widths, and the center values have never */ /* been calculated, allocate temporary space to hold center values */ /* and calculate the center values. Otherwise, set a pointer to */ /* the center values. */ /**********************************************************************/ if (ret_band) { if (bptr->center_val == NO_MEMORY) { rval = ir_allocate_center (0); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } center = (SDDAS_FLOAT *) ir_tmp_space; } if (band_space && bptr->num_center_band != 1) { for (sen = 0; sen < ex->num_sensor; ++sen) if (*(ex->sensors_needed + sen) != 0) { offset = *(bptr->sen_index + sen) * bptr->num_bins; if (bptr->center_val == NO_MEMORY) { rval = ir_calc_center_sweep (center, sen, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /***************************************************************/ /* Be sure to reset ex structure since module calls read_drec()*/ /* and VIDF file crossing may cause a reallocation of the */ /* existing ex structures so address may change. */ /***************************************************************/ ex = ginfo.expt; bptr = ex->bin_ptr; } else center = (SDDAS_FLOAT *) (bptr->center_val + offset); if (bptr->swp_fmt == ZERO_SPACING || bptr->swp_fmt == VARIABLE_SPACING) { offset = *(bptr->sen_index + sen) * bptr->num_bins; bhigh_off = offset; } else { offset = *(bptr->sen_index + sen) * (bptr->num_bins + 1); bhigh_off = 0; /* No band high values since contiguous. */ } blow = (SDDAS_FLOAT *) (bptr->band_low + offset); bhigh = (SDDAS_FLOAT *) (bptr->band_high + bhigh_off); rval = ir_calc_band_widths (center, blow, bhigh, bptr->num_converted, bptr->delta_bin, bptr->swp_fmt, sen, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /* Set the empty slots to the last value computed so ALWAYS continually increasing */ /* or decreasing. */ if (bptr->num_bins != bptr->num_converted) { last_low = *(blow + bptr->num_converted - 1); if (bhigh == 0) for (fill_index = bptr->num_converted; fill_index <= bptr->num_bins; ++fill_index) *(blow + fill_index) = last_low; else { last_high = *(bhigh + bptr->num_converted - 1); for (fill_index = bptr->num_converted; fill_index < bptr->num_bins; ++fill_index) { *(blow + fill_index) = last_low; *(bhigh + fill_index) = last_high; } } } } } else { offset = *(bptr->sen_index + sensor) * bptr->num_bins; if (bptr->center_val == NO_MEMORY) { rval = ir_calc_center_sweep (center, sensor, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /*******************************************************************/ /* Be sure to reset ex structure since module calls read_drec() */ /* and VIDF file crossing may cause a reallocation of the existing */ /* ex structures so address may change. */ /*******************************************************************/ ex = ginfo.expt; bptr = ex->bin_ptr; } else center = (SDDAS_FLOAT *) (bptr->center_val + offset); if (bptr->swp_fmt == ZERO_SPACING || bptr->swp_fmt == VARIABLE_SPACING) { offset = *(bptr->sen_index + sensor) * bptr->num_bins; bhigh_off = offset; } else { offset = *(bptr->sen_index + sensor) * (bptr->num_bins + 1); bhigh_off = 0; /* No band high values since contiguous. */ } blow = (SDDAS_FLOAT *) (bptr->band_low + offset); bhigh = (SDDAS_FLOAT *) (bptr->band_high + bhigh_off); rval = ir_calc_band_widths (center, blow, bhigh, bptr->num_converted, bptr->delta_bin, bptr->swp_fmt, sensor, idf_data_ptr); if (rval != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /* Set the empty slots to the last value computed so ALWAYS continually increasing */ /* or decreasing. */ if (bptr->num_bins != bptr->num_converted) { last_low = *(blow + bptr->num_converted - 1); if (bhigh == 0) for (fill_index = bptr->num_converted; fill_index <= bptr->num_bins; ++fill_index) *(blow + fill_index) = last_low; else { last_high = *(bhigh + bptr->num_converted - 1); for (fill_index = bptr->num_converted; fill_index < bptr->num_bins; ++fill_index) { *(blow + fill_index) = last_low; *(bhigh + fill_index) = last_high; } } } } } /**********************************************************************/ /* Set the pointers to the memory that holds the calculated values. */ /**********************************************************************/ offset = *(bptr->sen_index + sensor) * bptr->num_bins; *center_ptr = (SDDAS_FLOAT *) (bptr->center_val + offset); if (bptr->swp_fmt == ZERO_SPACING || bptr->swp_fmt == VARIABLE_SPACING) { offset = *(bptr->sen_index + sensor) * bptr->num_bins; bhigh_off = offset; } else { offset = *(bptr->sen_index + sensor) * (bptr->num_bins + 1); bhigh_off = 0; /* No band high values since contiguous. */ } *low_ptr = (SDDAS_FLOAT *) (bptr->band_low + offset); *high_ptr = (SDDAS_FLOAT *) (bptr->band_high + bhigh_off); *num_bands = bptr->num_bins; *num_converted = bptr->num_converted; if (reset_called) ginfo.called_locate = 0; if (bptr->num_bins != bptr->num_converted) return (CENTER_CONVERSION); else return (ALL_OKAY); }