/* * 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: trap_int_ang_c02_sx20.c 21649 2011-12-05 20:50:45Z carrie $ SwRI" #include #include "user_defs.h" #include "libIDFSMath.h" /******************************************************************************* * * * IDFSMATH_TRAPEZOIDAL_INT_ANGLE_C02_SX20 SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate a trapezoidal integration method on * * data which exists in a band, which means that X[n] is the starting location* * of the band, X[n+1] is the ending location of the band, and Y[n] is the * * ampltude of the band. Assume that the Y[n] values are measured at the * * centers of the bands. There are terms number of bands, so there are terms * * values of Y and terms+1 values of X. When converted to trapezoids, there * * are terms-1 trapezoids. Points are measured as X, Y pairs. This routine * * is called when the power of the cosine term is 0 and the power of the * * sine term is 2 OR when the power of the cosine term is 2 and the power of * * the sine term is 0. * * * * INPUT VARIABLES * * SDDAS_FLOAT *X pointer to the band values (x component) * * SDDAS_FLOAT *Y pointer to the data values (y component) * * SDDAS_DOUBLE *X_rad pointer to band values expressed in radians * * SDDAS_DOUBLE *X_centers pointer to center band values expressed in * * radians * * SDDAS_DOUBLE *Sin_Xc pointer to the result of the sin function * * for the center band values * * SDDAS_DOUBLE *Cos_Xc pointer to the result of the cos function * * for the center band values * * SDDAS_DOUBLE *width pointer to the widths between bin centers * * SDDAS_DOUBLE *M ptr to the slope of each Y between centers * * SDDAS_DOUBLE *B ptr to intercept of each Y between centers * * SDDAS_LONG skip number of elements to add to get to next * * data element * * SDDAS_LONG terms number of bands or terms to integrate * * SDDAS_FLOAT start starting value to integrate over in X * * SDDAS_FLOAT stop ending value to integrate over in X * * 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_trapezoidal_int_angle_c02_sx20 (&X, &Y, &X_rad, &X_centers, * * &Sin_Xc, &Cos_Xc, &width, &M, &B, skip, terms, * * start, stop, which_dimen, norm, power_sx, power_c) * * * * NECESSARY SUBPROGRAMS * * cos() returns double-precision cosine function of * * the argument * * sin() returns double-precision sine function of * * the argument * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_LONG i, next_i looping / indexing variables * * SDDAS_DOUBLE start_rad start integration value expressed in radians * * SDDAS_DOUBLE stop_rad end integration value expressed in radians * * SDDAS_DOUBLE c_factor constant factor computed once used repeatedly* * SDDAS_DOUBLE width_low width between bin centers used when start * * of integration is at or less than 1st center * * SDDAS_DOUBLE M_low slope of Y between centers used when start * * of integration is at or less than 1st center * * SDDAS_DOUBLE B_low intercept of Y between centers used if start * * of integration is at or less than 1st center * * SDDAS_DOUBLE width_high width between bin centers used when end * * of integration is greater than last center * * SDDAS_DOUBLE M_high slope of Y between centers used when end * * of integration is greater than last center * * SDDAS_DOUBLE B_high intercept of Y between centers used if end * * of integration is greater than last center * * SDDAS_DOUBLE sum summation value of integration * * SDDAS_DOUBLE sumx normalization factor * * SDDAS_DOUBLE x1, x2 first and last band for trap. area * * SDDAS_DOUBLE sine_x1, the result of the sine function for the 1st * * sine_x2 and last band value used for trap. area * * SDDAS_DOUBLE cosine_x1, the result of the cosine function for the 1st* * cosine_x2 and last band value used for trap. area * * SDDAS_DOUBLE upper1, upper2, used to accumulate trapezoid area * * upper3, upper4, upper5, * * lower1, lower2, lower3, * * lower4, lower5 * * SDDAS_DOUBLE X1, X2 values of X used to get rid of indexing for * * speed up issues * * SDDAS_FLOAT y1, y2 first and last data value * * SDDAS_LONG terms_minus_one number of terms to integrate reduced by one * * SDDAS_CHAR wrap flag indicating data is cyclic and wraps * * around boundary point * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_DOUBLE IDFSMath_trapezoidal_int_angle_c02_sx20 (SDDAS_FLOAT *X, SDDAS_FLOAT *Y, SDDAS_DOUBLE *X_rad, SDDAS_DOUBLE *X_centers, SDDAS_DOUBLE *Sin_Xc, SDDAS_DOUBLE *Cos_Xc, SDDAS_DOUBLE *width, SDDAS_DOUBLE *M, SDDAS_DOUBLE *B, 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) { register SDDAS_LONG i, next_i; SDDAS_DOUBLE width_low, M_low, B_low, width_high, M_high, B_high; SDDAS_DOUBLE sum, sumx, x1, x2, sine_x1, sine_x2, cosine_x1, cosine_x2; SDDAS_DOUBLE upper1, upper2, upper3, upper4, upper5; SDDAS_DOUBLE lower1, lower2, lower3, lower4, lower5; SDDAS_DOUBLE start_rad, stop_rad, c_factor, X1, X2; SDDAS_FLOAT y1, y2; SDDAS_LONG terms_minus_one; SDDAS_CHAR wrap; terms_minus_one = terms - 1; wrap = (which_dimen == PHI_DIMEN) ? 1 : 0; if (wrap) { X1 = X_centers[0]; X2 = X_centers[terms_minus_one]; y1 = *Y; /* Y value of first band */ y2 = *(Y + terms_minus_one * skip); /* Y value of last band */ c_factor = 2.0 * M_PI; width_low = X1 - (X2 - c_factor); width_high = (X1 + c_factor) - X2; if (y1 >= VALID_MIN && y2 >= VALID_MIN) /* if data good */ { M_low = (y1 - y2) / width_low; B_low = (X1 * y2 - (X2 - c_factor) * y1) / width_low; M_high = (y1 - y2) / width_high; B_high = ((X1 + c_factor) * y2 - X2 * y1) / width_high; } else { M_low = OUTSIDE_MIN; B_low = OUTSIDE_MIN; M_high = OUTSIDE_MIN; B_high = OUTSIDE_MIN; } } sumx = 0.0; /* initialize X covered area */ sum = 0.0; /* initialize integration amp*/ start_rad = start * M_PI / 180.0; stop_rad = stop * M_PI / 180.0; /*****************************************************************************/ /* Start is at or below the first center. */ /*****************************************************************************/ if (start_rad < X_centers[0]) { /*************************************************************************/ /* Integrate from the first data or start if bigger. */ /*************************************************************************/ if (start <= X[0]) x1 = X_rad[0]; else x1 = start_rad; /*************************************************************************/ /* Integrate to the first data center or the stop if it is less. */ /*************************************************************************/ if (stop_rad >= X_centers[0]) x2 = X_centers[0]; else x2 = stop_rad; sine_x1 = sin (x1); sine_x2 = sin (x2); cosine_x1 = cos (x1); cosine_x2 = cos (x2); /*************************************************************************/ /* Data wrapped accumulate trapezoidal area. */ /*************************************************************************/ if (wrap) { if (M_low >= VALID_MIN) { upper1 = 0.25 * M_low * x2 * x2; upper2 = 0.5 * B_low * x2; upper3 = 0.125 * M_low * sine_x2 * sine_x2; upper4 = -0.125 * M_low * cosine_x2 * cosine_x2; upper5 = -0.5 * sine_x2 * cosine_x2 * (M_low * x2 + B_low); lower1 = 0.25 * M_low * x1 * x1; lower2 = 0.5 * B_low * x1; lower3 = 0.125 * M_low * sine_x1 * sine_x1; lower4 = -0.125 * M_low * cosine_x1 * cosine_x1; lower5 = -0.5 * sine_x1 * cosine_x1 * (M_low * x1 + B_low); if (power_c == 2 && power_sx == 0) { upper3 = -upper3; upper4 = -upper4; upper5 = -upper5; lower3 = -lower3; lower4 = -lower4; lower5 = -lower5; } sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ sum += upper3 - lower3; /* accumulate trapazoid area */ sum += upper4 - lower4; /* accumulate trapazoid area */ sum += upper5 - lower5; /* accumulate trapazoid area */ sumx += x2 - x1; /* accumulate the width */ } } else if (Y[0] >= VALID_MIN) { sum += Y[0] * (x2 - x1); /* accumulate the rect area */ sumx += x2 - x1; /* accumulate the width */ } } /**************************************************************************/ /* Search through all of the data bands - accumulate them. */ /**************************************************************************/ for (i = 0, next_i = 1; i < terms_minus_one; ++i, ++next_i) { if (M[i] < VALID_MIN) continue; X2 = X_centers[next_i]; X1 = X_centers[i]; /***********************************************************************/ /* Band is between start and stop, so accumulate this area. */ /***********************************************************************/ if (start_rad < X1 && X2 < stop_rad) { x1 = X1; x2 = X2; sine_x1 = Sin_Xc[i]; sine_x2 = Sin_Xc[next_i]; cosine_x1 = Cos_Xc[i]; cosine_x2 = Cos_Xc[next_i]; upper1 = 0.25 * M[i] * x2 * x2; upper2 = 0.5 * B[i] * x2; upper3 = 0.125 * M[i] * sine_x2 * sine_x2; upper4 = -0.125 * M[i] * cosine_x2 * cosine_x2; upper5 = -0.5 * sine_x2 * cosine_x2 * (M[i] * x2 + B[i]); lower1 = 0.25 * M[i] * x1 * x1; lower2 = 0.5 * B[i] * x1; lower3 = 0.125 * M[i] * sine_x1 * sine_x1; lower4 = -0.125 * M[i] * cosine_x1 * cosine_x1; lower5 = -0.5 * sine_x1 * cosine_x1 * (M[i] * x1 + B[i]); if (power_c == 2 && power_sx == 0) { upper3 = -upper3; upper4 = -upper4; upper5 = -upper5; lower3 = -lower3; lower4 = -lower4; lower5 = -lower5; } sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ sum += upper3 - lower3; /* accumulate trapazoid area */ sum += upper4 - lower4; /* accumulate trapazoid area */ sum += upper5 - lower5; /* accumulate trapazoid area */ sumx += x2 - x1; /* accumulate the width */ } /***********************************************************************/ /* The start is within the trapazoid of the data. */ /***********************************************************************/ else if (X1 <= start_rad && start_rad < X2) { /********************************************************************/ /* The stop is within the trapazoid of the data. */ /********************************************************************/ if (stop_rad <= X2) { x1 = start_rad; x2 = stop_rad; } /********************************************************************/ /* The start is within the trapazoid, but stop is not. */ /********************************************************************/ else { x1 = start_rad; x2 = X2; } sine_x1 = sin (x1); sine_x2 = sin (x2); cosine_x1 = cos (x1); cosine_x2 = cos (x2); upper1 = 0.25 * M[i] * x2 * x2; upper2 = 0.5 * B[i] * x2; upper3 = 0.125 * M[i] * sine_x2 * sine_x2; upper4 = -0.125 * M[i] * cosine_x2 * cosine_x2; upper5 = -0.5 * sine_x2 * cosine_x2 * (M[i] * x2 + B[i]); lower1 = 0.25 * M[i] * x1 * x1; lower2 = 0.5 * B[i] * x1; lower3 = 0.125 * M[i] * sine_x1 * sine_x1; lower4 = -0.125 * M[i] * cosine_x1 * cosine_x1; lower5 = -0.5 * sine_x1 * cosine_x1 * (M[i] * x1 + B[i]); if (power_c == 2 && power_sx == 0) { upper3 = -upper3; upper4 = -upper4; upper5 = -upper5; lower3 = -lower3; lower4 = -lower4; lower5 = -lower5; } sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ sum += upper3 - lower3; /* accumulate trapazoid area */ sum += upper4 - lower4; /* accumulate trapazoid area */ sum += upper5 - lower5; /* accumulate trapazoid area */ sumx += x2 - x1; /* accumulate the width */ } /***********************************************************************/ /* The stop is within the trapazoid of the data. */ /***********************************************************************/ else if (X1 < stop_rad && stop_rad <= X2) { /********************************************************************/ /* The start is within the trapazoid of the data. */ /********************************************************************/ if (start_rad >= X1) { x1 = start_rad; x2 = stop_rad; } /********************************************************************/ /* The start is within the trapazoid, but stop is not. */ /********************************************************************/ else { x1 = X1; x2 = stop_rad; } sine_x1 = sin (x1); sine_x2 = sin (x2); cosine_x1 = cos (x1); cosine_x2 = cos (x2); upper1 = 0.25 * M[i] * x2 * x2; upper2 = 0.5 * B[i] * x2; upper3 = 0.125 * M[i] * sine_x2 * sine_x2; upper4 = -0.125 * M[i] * cosine_x2 * cosine_x2; upper5 = -0.5 * sine_x2 * cosine_x2 * (M[i] * x2 + B[i]); lower1 = 0.25 * M[i] * x1 * x1; lower2 = 0.5 * B[i] * x1; lower3 = 0.125 * M[i] * sine_x1 * sine_x1; lower4 = -0.125 * M[i] * cosine_x1 * cosine_x1; lower5 = -0.5 * sine_x1 * cosine_x1 * (M[i] * x1 + B[i]); if (power_c == 2 && power_sx == 0) { upper3 = -upper3; upper4 = -upper4; upper5 = -upper5; lower3 = -lower3; lower4 = -lower4; lower5 = -lower5; } sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ sum += upper3 - lower3; /* accumulate trapazoid area */ sum += upper4 - lower4; /* accumulate trapazoid area */ sum += upper5 - lower5; /* accumulate trapazoid area */ sumx += x2 - x1; /* accumulate the width */ } } /**************************************************************************/ /* Stop is above last center. */ /**************************************************************************/ if (stop_rad > X_centers[terms_minus_one]) { /*************************************************************************/ /* Integrate from the last data or stop if its bigger. */ /*************************************************************************/ if (stop >= X[terms]) x2 = X_rad[terms]; else x2 = stop_rad; /*************************************************************************/ /* Integrate to the first data center or the stop if it is less. */ /*************************************************************************/ if (start_rad <= X_centers[terms_minus_one]) x1 = X_centers[terms_minus_one]; else x1 = start_rad; y2 = *(Y + terms_minus_one * skip); /* Y value of last band */ sine_x1 = sin (x1); sine_x2 = sin (x2); cosine_x1 = cos (x1); cosine_x2 = cos (x2); /*************************************************************************/ /* Data wrapped accumulate trapazoidal area. */ /*************************************************************************/ if (wrap) { if (M_high >= VALID_MIN) { upper1 = 0.25 * M_high * x2 * x2; upper2 = 0.5 * B_high * x2; upper3 = 0.125 * M_high * sine_x2 * sine_x2; upper4 = -0.125 * M_high * cosine_x2 * cosine_x2; upper5 = -0.5 * sine_x2 * cosine_x2 * (M_high * x2 + B_high); lower1 = 0.25 * M_high * x1 * x1; lower2 = 0.5 * B_high * x1; lower3 = 0.125 * M_high * sine_x1 * sine_x1; lower4 = -0.125 * M_high * cosine_x1 * cosine_x1; lower5 = -0.5 * sine_x1 * cosine_x1 * (M_high * x1 + B_high); if (power_c == 2 && power_sx == 0) { upper3 = -upper3; upper4 = -upper4; upper5 = -upper5; lower3 = -lower3; lower4 = -lower4; lower5 = -lower5; } sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ sum += upper3 - lower3; /* accumulate trapazoid area */ sum += upper4 - lower4; /* accumulate trapazoid area */ sum += upper5 - lower5; /* accumulate trapazoid area */ sumx += x2 - x1; /* accumulate the width */ } } else if (y2 >= VALID_MIN) { sum += y2 * (x2 - x1); /* accumulate the rect area */ sumx += x2 - x1; /* accumulate the width */ } } /**************************************************************************/ /* Normalize the data to the start and stop distance. Note that this is */ /* 1.0 when start and stop lie within the data range with no gap. */ /**************************************************************************/ if (norm && sumx > 0.0) { sum /= sumx; sum *= (stop_rad - start_rad); } /************************************************************************/ /* 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. The old way would return a 0.0 which implied that */ /* data was there so the NORM flag had no bearing because the code */ /* for later integrations thought nothing was missing. */ /************************************************************************/ if (sumx > 0.0) return (sum); else return (OUTSIDE_MIN); }