/* * 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 "@(#) calc_bands.c 1.29 05/08/19 SwRI" #include #include #include "user_defs.h" #include "libtrec_idfs.h" #include "ret_codes.h" /******************************************************************************* * * * IR_CALC_BAND_WIDTHS SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate the sweep band width values for the * * virtual instrument being processed. The calculation is dependent upon the * * sweep format. If the sweep format is zero spacing or variable width * * spacing, the bands are non-contiguous. For zero spacing, the lower and * * upper band values are the same, set to the center values. This should be * * true only for scalar instruments. For variable width spacing, the lower * * and upper band values are different but they are not assumed to be * * contiguous. For the other formats, only bands are contiguous and thus, * * there is no need to hold an upper and lower value - the upper limit of the * * current band is the lower limit of the next band. * * * * INPUT VARIABLES * * SDDAS_FLOAT *center pointer to the center sweep values * * SDDAS_FLOAT *band_low pointer to the location for the lower bands * * for non-contiguous bands or all band widths * * for contiguous bands * * SDDAS_FLOAT *band_high pointer to the location for the upper bands * * for non-contiguous bands * * SDDAS_SHORT num_bins the number of center bin values * * SDDAS_FLOAT delta_bin the bin width for a single bin * * SDDAS_CHAR swp_fmt format of the sweep * * SDDAS_SHORT sensor the sensor for which the bands are being * * created * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * * * USAGE * * x = ir_calc_band_widths (center, &band_low, &band_high, num_bins, * * delta_bin, swp_fmt, sensor, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * exp() returns double-precision exponential function * * of the argument * * log() returns double-precision natural logarithm of * * the argument * * convert_to_units() converts the specified data type into the * * data format requested * * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * SDDAS_FLOAT ir_conv_fill[] temporary array that holds the values returned* * by convert_to_units() * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure that holds all of the currently * * returned data values to be processed * * 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 ptr_rec *ptr a pointer to the structure which holds all * * pointers to the header and data for the * * experiment of interest * * register SDDAS_FLOAT *cptr pointer to center sweep values * * register SDDAS_FLOAT *blow pointer to lower band width values * * reg SDDAS_FLOAT *bhigh pointer to upper band width values * * reg SDDAS_FLOAT *stop_loop loop termination variable * * reg SDDAS_FLOAT *conv_ptr pointer to variable width correction values * * reg SDDAS_LONG *swp_data pointer to sample sequence values * * register SDDAS_SHORT bin looping variable * * reg SDDAS_SHORT *samp_ptr pointer to SAMP_INDEX values returned * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_USHORT vnum version number to be associated with this * * combination (allows for multiple opens) * * SDDAS_LONG fill_value the value identified as the FILL value * * SDDAS_LONG *end_loop loop termination variable * * SDDAS_SHORT rval holds value returned by called module * * SDDAS_SHORT old_swp_size the number of elements in the sample sequence * * array before possible reallocation * * SDDAS_CHAR exten[] filename extension for the data to be used * * SDDAS_CHAR chk_fill flag indicating if the data is to be checked * * for FILL values * * SDDAS_CHAR bad_last_step flag indicating if last step processed was * * an illegal value for LOG scaling * * double step1, step2 values used to create the bands from the * * center values * * double ret_val holds double precision value returned * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_calc_band_widths (SDDAS_FLOAT *center, SDDAS_FLOAT *band_low, SDDAS_FLOAT *band_high, SDDAS_SHORT num_bins, SDDAS_FLOAT delta_bin, SDDAS_CHAR swp_fmt, SDDAS_SHORT sensor, void *idf_data_ptr) { extern struct general_info ginfo; extern SDDAS_FLOAT ir_conv_fill[]; struct idf_data *EXP_DATA; struct experiment_info *ex; struct bin_info *bptr; struct ptr_rec *ptr; register SDDAS_FLOAT *cptr, *blow, *bhigh, *stop_loop, *conv_ptr; register SDDAS_LONG *swp_data; register SDDAS_SHORT bin, *samp_ptr; SDDAS_ULONG data_key; SDDAS_USHORT vnum; SDDAS_LONG fill_value, *end_loop; SDDAS_SHORT rval, old_swp_size; SDDAS_CHAR exten[3], chk_fill, bad_last_step; double ret_val, step1, step2; cptr = center; blow = band_low; bhigh = band_high; /**************************************************************************/ /* User requested a single bin. */ /**************************************************************************/ if (swp_fmt == LIN_SPACING && num_bins == 1) { *blow++ = *cptr - 0.5 * delta_bin; *blow = *cptr + 0.5 * delta_bin; } /*************************************************************************/ /* Determine the bands using the center values with linear spacing. */ /*************************************************************************/ else if (swp_fmt == LIN_SPACING) { step1 = *cptr; step2 = *(cptr + 1); *blow++ = step1 - 0.5 * (step2 - step1); stop_loop = band_low + num_bins; for (; blow < stop_loop;) { step1 = *cptr++; step2 = *cptr; *blow++ = step2 - 0.5 * (step2 - step1); } *blow = step2 + 0.5 * (step2 - step1); } /**************************************************************************/ /* User requested a single bin. The delta value for LOG spacing should */ /* be in terms of slope (log already taken). */ /**************************************************************************/ else if (swp_fmt == LOG_SPACING && num_bins == 1) { ret_val = log ((double) *cptr) - 0.5 * delta_bin; *blow++ = (SDDAS_FLOAT) ret_val; ret_val = log ((double) *cptr) + 0.5 * delta_bin; *blow = (SDDAS_FLOAT) ret_val; } /*************************************************************************/ /* Determine the bands using the center values with logarithmic spacing.*/ /*************************************************************************/ else if (swp_fmt == LOG_SPACING) { /**********************************************************************/ /* Check for negative or zero band values. */ /**********************************************************************/ if (*cptr <= 0.0000 || *(cptr + 1) <= 0.0000) *blow++ = OUTSIDE_MIN; else { step1 = log ((double) *cptr); step2 = log ((double) *(cptr + 1)); ret_val = exp (step1 - 0.5 * (step2 - step1)); *blow++ = (SDDAS_FLOAT) ret_val; } stop_loop = band_low + num_bins; for (; blow < stop_loop;) { bad_last_step = 0; if (*cptr <= 0.0000 || *(cptr + 1) <= 0.0000) { *blow++ = OUTSIDE_MIN; cptr++; bad_last_step = 1; } else { step1 = log ((double) *cptr++); step2 = log ((double) *cptr); ret_val = exp (step2 - 0.5 * (step2 - step1)); *blow++ = (SDDAS_FLOAT) ret_val; } } if (bad_last_step) *blow = OUTSIDE_MIN; else { ret_val = exp (step2 + 0.5 * (step2 - step1)); *blow = (SDDAS_FLOAT) ret_val; } } /*************************************************************************/ /* Determine the bands using the center values and the tables that were */ /* specified to create the bands. */ /*************************************************************************/ else if (swp_fmt == VARIABLE_SPACING) { EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; data_key = ex->data_key; vnum = ex->version; strcpy (exten, ex->exten); chk_fill = ex->fill_flag; fill_value = ex->fill_value; bptr = ex->bin_ptr; ptr = ex->info_ptr; /***********************************************************************/ /* Set the sample sequence values from 0 to swp_len to cover the full */ /* range. */ /***********************************************************************/ old_swp_size = EXP_DATA->num_swp_steps; EXP_DATA->num_swp_steps = num_bins; swp_data = EXP_DATA->swp_data; for (bin = 0; bin < num_bins; ++bin, ++swp_data) *swp_data = bin; rval = convert_to_units (data_key, exten, vnum, idf_data_ptr, sensor, SWEEP_STEP, 0, bptr->num_calc_bands, bptr->band_tbls, bptr->band_opers, ir_conv_fill, chk_fill, fill_value); if (rval != ALL_OKAY) return (rval); stop_loop = band_low + num_bins; conv_ptr = &ir_conv_fill[0]; if (bptr->vfmt == 'L' || bptr->vfmt == 'l') { for (; blow < stop_loop; ++cptr, ++conv_ptr) { *blow++ = *cptr; *bhigh++ = *cptr + *conv_ptr; } } else if (bptr->vfmt == 'C' || bptr->vfmt == 'c') { for (; blow < stop_loop; ++cptr, ++conv_ptr) { step1 = *conv_ptr * 0.5; *blow++ = *cptr - step1; *bhigh++ = *cptr + step1; } } else if (bptr->vfmt == 'U' || bptr->vfmt == 'u') { for (; blow < stop_loop; ++cptr, ++conv_ptr) { *blow++ = *cptr - *conv_ptr; *bhigh++ = *cptr; } } else if (bptr->vfmt == 'E' || bptr->vfmt == 'e') { for (; blow < stop_loop; ++cptr, ++conv_ptr) { *blow++ = *cptr; *bhigh++ = *conv_ptr; } } /*************************************************************************/ /* This definition states that there are tables in the VIDF which return*/ /* the "actual" center, lower edge and upper edge scan values. So, no */ /* longer are deltas provided to be applied to the centers in order to */ /* compute the edges. */ /*************************************************************************/ else if (bptr->vfmt == 'A' || bptr->vfmt == 'a') { for (; blow < stop_loop; ) *blow++ = *conv_ptr++; /*********************************************************************/ /* Retrieve the "actual" upper edge values. */ /*********************************************************************/ rval = convert_to_units (data_key, exten, vnum, idf_data_ptr, sensor, SWEEP_STEP, 0, bptr->num_upper_band, bptr->upper_band_tbls, bptr->upper_band_opers, ir_conv_fill, chk_fill, fill_value); if (rval != ALL_OKAY) return (rval); stop_loop = band_high + num_bins; conv_ptr = &ir_conv_fill[0]; for (; bhigh < stop_loop; ) *bhigh++ = *conv_ptr++; } else return (BAD_VFMT); /************************************************************************/ /* Put back the previous sample sequence values. */ /************************************************************************/ EXP_DATA->num_swp_steps = old_swp_size; swp_data = EXP_DATA->swp_data; samp_ptr = ptr->hdr_fmt1_ptr->SAMP_INDEX; end_loop = swp_data + EXP_DATA->num_swp_steps; for (; swp_data < end_loop;) *swp_data++ = *samp_ptr++; } /*************************************************************************/ /* The bands are non-contiguous. */ /*************************************************************************/ else if (swp_fmt == ZERO_SPACING) { stop_loop = cptr + num_bins; for (; cptr < stop_loop;) { *blow++ = *cptr; *bhigh++ = *cptr++; } } return (ALL_OKAY); }