/* * 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 "@(#) $Id: str_int_band_disc.C 18484 2007-07-12 18:55:07Z carrie $ SwRI" #include #include "user_defs.h" #include "libIDFSMath.h" /***************************************************************************** * * * IDFSMATH_STR_INT_BAND_DISC SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate a band integral using non- * * contiguous band values. The IDFSMath_rmie() function converts the * * values to radians for angular dimensions. * * * * INPUT VARIABLES * * SDDAS_FLOAT *XA pointer to lower edges of bands * * SDDAS_FLOAT *XB pointer to upper edges of bands * * SDDAS_FLOAT *Y pointer to the data values * * SDDAS_FLOAT start starting value to integrate over * * SDDAS_FLOAT stop ending value to integrate over * * SDDAS_LONG skip number of elements to add to get to next * * data element * * SDDAS_LONG terms number of bands * * SDDAS_CHAR norm flag indicating if the result is to be * * normalized * * SDDAS_CHAR which_dimen flag indicating which dimension is being * * integrated over since multiple dimensions * * make use of this code * * SDDAS_INT power_sx the power of the extra "x" term or the power * * of the sin term * * SDDAS_INT power_c the power of the cos term * * * * USAGE * * x = IDFSMath_str_int_band_disc (XA, XB ,Y, skip, terms, start, stop, * * norm, which_dimen, power_sx, power_c) * * * * NECESSARY SUBPROGRAMS * * IDFSMath_rmie () returns the weighted values based on the * * extra values that are in the integral * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * std::vector WXA weighted values for lower edges * * std::vector WXB weighted values for upper edges * * reg SDDAS_FLOAT *f1, *f2 pointers to band values * * register SDDAS_FLOAT *f3 pointer to data values * * register SDDAS_FLOAT sumx normalization factor * * reg SDDAS_FLOAT *f_end loop termination variable * * SDDAS_DOUBLE wstart weighted starting value for integration * * SDDAS_DOUBLE wstop weighted ending value for integration * * SDDAS_DOUBLE *wa, *wb pointers to weighted band values * * SDDAS_DOUBLE suma summation value of band integration * * SDDAS_DOUBLE b weighted calculation variable * * SDDAS_FLOAT a calculation variable * * SDDAS_LONG loop looping variable * * SDDAS_CHAR valid_data_found flag for data inclusion or missing data * * * * SUBSYSTEM * * Display Level * * * ****************************************************************************/ /*** BAND INTEGRAL, DISCONTIGUOUS X BANDS ***/ SDDAS_FLOAT IDFSMath_str_int_band_disc (SDDAS_FLOAT *XA, SDDAS_FLOAT *XB, SDDAS_FLOAT *Y, SDDAS_LONG skip, SDDAS_LONG terms, SDDAS_FLOAT start, SDDAS_FLOAT stop, SDDAS_CHAR norm, SDDAS_CHAR which_dimen, SDDAS_INT power_sx, SDDAS_INT power_c) { std::vector WXA, WXB; register SDDAS_FLOAT *f1, *f2, *f3, sumx, *f_end; SDDAS_DOUBLE wstart, wstop, *wa, *wb, suma, b; SDDAS_FLOAT a; SDDAS_LONG loop; SDDAS_CHAR valid_data_found; suma = 0.0; sumx = 0.0; valid_data_found = 0; if (XB[0] > XA[0]) { f1 = XA; f2 = XB; } else { f1 = XB; f2 = XA; } f3 = Y; f_end = Y + terms * skip; if (start > stop) { start = *f1; stop = *(f2 + terms - 1); } /**********************************************************************/ /* Get the weighted values based on the extra values that are in the */ /* integral, as indicated by power_sx and power_c arguments. Due */ /* to possible future threading, better to have a local variable for */ /* scratch space instead of a global re-use area. */ /**********************************************************************/ WXA.resize (terms); WXB.resize (terms); for (loop = 0; loop < terms; ++loop) { WXA[loop] = IDFSMath_rmie (*(f1 + loop), which_dimen, power_sx, power_c); WXB[loop] = IDFSMath_rmie (*(f2 + loop), which_dimen, power_sx, power_c); } wa = &WXA[0]; wb = &WXB[0]; wstart = IDFSMath_rmie (start, which_dimen, power_sx, power_c); wstop = IDFSMath_rmie (stop, which_dimen, power_sx, power_c); while (f3 < f_end) { if (start < *f2 && stop > *f1) { if (start < *f1 && stop > *f2) { a = *f2 - *f1; b = *wb - *wa; } else { if (start >= *f1 && stop <= *f2) { a = stop - start; b = wstop - wstart; } else { a = (start >= *f1) ? *f2 - start : stop - *f1; b = (start >= *f1) ? *wb - wstart : wstop - *wa; } } if (*f3 >= VALID_MIN) { suma += b * *f3; sumx += a; valid_data_found = 1; } } ++f1; ++f2; ++wa; ++wb; f3 += skip; } /*************************************************************************/ /* The normalization is done using the original, non-weighted values. */ /*************************************************************************/ if (norm && sumx > 0.0) { suma /= sumx; suma *= (stop - start); } /************************************************************************/ /* If no data was found (all values set to OUTSIDE_MIN), return */ /* OUTSIDE_MIN so that possible later collapsing will also ignore this */ /* missing data. */ /************************************************************************/ if (!valid_data_found) return (OUTSIDE_MIN); else return ((SDDAS_FLOAT) suma); }