/* * 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_cont.C 18484 2007-07-12 18:55:07Z carrie $ SwRI" #include #include "user_defs.h" #include "libIDFSMath.h" /***************************************************************************** * * * IDFSMATH_STR_INT_BAND_CONT SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate a straight, band integral using * * contiguous band values. The IDFSMath_rmie() function converts the * * values to radians for angular dimensions. * * * * INPUT VARIABLES * * SDDAS_FLOAT *X pointer to the band values * * SDDAS_FLOAT *Y pointer to the data values * * SDDAS_LONG skip number of elements to add to get to next * * data element * * SDDAS_LONG terms number of bands * * SDDAS_FLOAT start starting value to integrate over * * SDDAS_FLOAT stop ending value to integrate over * * SDDAS_CHAR which_dimen flag indicating which dimension is being * * integrated over since multiple dimensions * * make use of this code * * SDDAS_CHAR norm flag indicating if the result is to be * * normalized * * 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_cont (X, Y, skip, terms, start, stop, * * which_dimen, norm, 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 WX weighted values for band values * * reg SDDAS_DOUBLE *w_end end of weighted X array * * reg SDDAS_FLOAT *f1, *f2 pointer to band values * * register SDDAS_FLOAT *f3 pointer to data values * * register SDDAS_FLOAT sumx normalization factor * * reg SDDAS_FLOAT *f_end end of X array * * SDDAS_DOUBLE ret_val resultant value returned to calling module * * 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 sum summation value of integration * * SDDAS_LONG loop looping variable * * SDDAS_CHAR valid_data_found flag for data inclusion or missing data * * * * SUBSYSTEM * * Display Level * * * ****************************************************************************/ /*** BAND INTEGRAL, CONTIGUOUS X BANDS ***/ SDDAS_FLOAT IDFSMath_str_int_band_cont (SDDAS_FLOAT *X, SDDAS_FLOAT *Y, SDDAS_LONG skip, SDDAS_LONG terms, SDDAS_FLOAT start, SDDAS_FLOAT stop, SDDAS_CHAR which_dimen, SDDAS_CHAR norm, SDDAS_INT power_sx, SDDAS_INT power_c) { std::vector WX; register SDDAS_DOUBLE *w_end; register SDDAS_FLOAT *f1, *f2, *f3, sumx = 0.0, *f_end; SDDAS_DOUBLE ret_val = 0.0, wstart, wstop, *wa, *wb, sum; SDDAS_LONG loop; SDDAS_CHAR valid_data_found; f_end = X + terms; valid_data_found = 0; /**********************************************************************/ /* 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. Need to account */ /* for the one extra bin that is needed. */ /**********************************************************************/ WX.resize (terms + 1); for (loop = 0; loop <= terms; ++loop) WX[loop] = IDFSMath_rmie (*(X + loop), which_dimen, power_sx, power_c); w_end = &WX[terms]; /* Increasing array of values? Look at first and last instead of first */ /* 2 values. Indexing by terms is okay since the array of band values */ /* are used and there is always one more element at the end. */ if (X[terms] > X[0]) { if (start > stop) { start = X[0]; stop = X[terms]; } if (start >= X[terms] || stop < X[0]) return (OUTSIDE_MIN); wstart = IDFSMath_rmie (start, which_dimen, power_sx, power_c); wstop = IDFSMath_rmie (stop, which_dimen, power_sx, power_c); wa = &WX[0]; wb = &WX[1]; f1 = X; f2 = X + 1; f3 = Y; if (start > *f1) { while ((f2 <= f_end) && (start >= *f2)) { ++f1; ++f2; f3 += skip; ++wa; ++wb; } if (*f3 >= VALID_MIN) { valid_data_found = 1; sumx += *f2 - start; ret_val += *f3 * (*wb - wstart); } ++f1; ++f2; f3 += skip; ++wa; ++wb; } sum = ret_val; while ((f2 <= f_end) && (stop >= *f2)) { if (*f3 >= VALID_MIN) { valid_data_found = 1; sumx += *f2 - *f1; sum += *f3 * (*wb - *wa); } ++f1; ++f2; f3 += skip; ++wa; ++wb; } ret_val = sum; if (stop < X[terms] && *f3 >= VALID_MIN) { valid_data_found = 1; sumx += stop - *f1; ret_val += *f3 * (wstop - *wa); } } else { if (start > stop) { start = X[terms]; stop = X[0]; } if (start >= X[0] || stop < X[terms]) return (OUTSIDE_MIN); wstart = IDFSMath_rmie (start, which_dimen, power_sx, power_c); wstop = IDFSMath_rmie (stop, which_dimen, power_sx, power_c); wa = w_end; wb = w_end - 1; f1 = f_end; f2 = f_end - 1; f3 = Y + (terms - 1) * skip; if (start > *f1) { while ((f2 >= X) && (start >= *f2)) { --f1; --f2; f3 -= skip; --wa; --wb; } if (*f3 >= VALID_MIN) { valid_data_found = 1; sumx += *f2 - start; ret_val = *f3 * (*wb - wstart); } --f1; --f2; f3 -= skip; --wa; --wb; } sum = ret_val; while ((f2 >= X) && (stop >= *f2)) { if (*f3 >= VALID_MIN) { valid_data_found = 1; sumx += *f2 - *f1; sum += *f3 * (*wb - *wa); } --f1; --f2; f3 -= skip; --wa; --wb; } ret_val = sum; if (stop < X[0] && *f3 >= VALID_MIN) { valid_data_found = 1; sumx += stop - *f1; ret_val += *f3 * (wstop - *wa); } } /*************************************************************************/ /* The normalization is done using the original, non-weighted values. */ /*************************************************************************/ if (norm && sumx > 0.0) { ret_val /= sumx; ret_val *= (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) ret_val); }