/* * 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_c0_sx0.c 21649 2011-12-05 20:50:45Z carrie $ SwRI" #include #include "user_defs.h" #include "libIDFSMath.h" /******************************************************************************* * * * IDFSMATH_TRAPEZOIDAL_INT_ANGLE_C0_SX0 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 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 * * * * USAGE * * x = IDFSMath_trapezoidal_int_angle_c0_sx0 (&X, &Y, &X_rad, &X_centers, * * &Sin_Xc, &Cos_Xc, &width, &M, &B, skip, * * terms, start, stop, which_dimen, norm) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_LONG i looping / indexing variable * * reg SDDAS_DOUBLE *slope_ptr fast pointer to slope values * * reg SDDAS_DOUBLE *intercept_ptr fast pointer to intercept values * * 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 slope, intercept variables used to speed-up by getting rid * * repeated pointer referencing * * SDDAS_DOUBLE X1, X2 values of X used to get rid of indexing for * * speed up issues * * SDDAS_DOUBLE upper1, upper2, used to accumulate trapezoid area * * lower1, lower2 * * 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_c0_sx0 (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) { register SDDAS_LONG i; register SDDAS_DOUBLE *slope_ptr, *intercept_ptr; register SDDAS_DOUBLE *cur_Xcenter_val, *next_Xcenter_val; SDDAS_DOUBLE start_rad, stop_rad, c_factor; SDDAS_DOUBLE width_low, M_low, B_low, width_high, M_high, B_high; SDDAS_DOUBLE sum, sumx, x1, x2, slope, intercept, X1, X2; SDDAS_DOUBLE upper1, upper2, lower1, lower2, half_value; 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]) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 1 start_rad (%g) < X_centers[0] (%g)", start_rad, X_centers[0]); #endif /*************************************************************************/ /* 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; /*************************************************************************/ /* Data wrapped accumulate trapezoidal area. */ /*************************************************************************/ if (wrap) { if (M_low >= VALID_MIN) { half_value = 0.5 * M_low; upper1 = half_value * x2 * x2; upper2 = B_low * x2; lower1 = half_value * x1 * x1; lower2 = B_low * x1; sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* 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. */ /**************************************************************************/ slope_ptr = M; intercept_ptr = B; cur_Xcenter_val = &X_centers[0]; next_Xcenter_val = &X_centers[1]; for (i = 0; i < terms_minus_one; ++i, ++cur_Xcenter_val, ++next_Xcenter_val, ++slope_ptr, ++intercept_ptr) { slope = *slope_ptr; intercept = *intercept_ptr; if (slope < VALID_MIN) continue; X2 = *next_Xcenter_val; X1 = *cur_Xcenter_val; #ifdef INT_PRINT printf ("\n Good Data for i = %ld", i); #endif /***********************************************************************/ /* Band is between start and stop, so accumulate this area. */ /***********************************************************************/ if (start_rad < X1 && X2 < stop_rad) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 2 start_rad (%g) < X1 (%g) && X2 (%g) < stop_rad (%g)", start_rad, X1, X2, stop_rad); #endif x1 = X1; x2 = X2; half_value = 0.5 * slope; upper1 = half_value * x2 * x2; upper2 = intercept * x2; lower1 = half_value * x1 * x1; lower2 = intercept * x1; sumx += x2 - x1; /* accumulate the width */ sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ } /***********************************************************************/ /* The start is within the trapazoid of the data. */ /***********************************************************************/ else if (X1 <= start_rad && start_rad < X2) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 3 X1 (%g) <= start_rad (%g) && start_rad (%g) < X2 (%g)", X1, start_rad, start_rad, X2); #endif /********************************************************************/ /* The stop is within the trapazoid of the data. */ /********************************************************************/ if (stop_rad <= X2) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 4 stop_rad (%g) <= X2 (%g)", stop_rad, X2); #endif x1 = start_rad; x2 = stop_rad; } /********************************************************************/ /* The start is within the trapazoid, but stop is not. */ /********************************************************************/ else { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 5 stop_rad (%g) > X2 (%g)", stop_rad, X2); #endif x1 = start_rad; x2 = X2; } sumx += x2 - x1; /* accumulate the width */ half_value = 0.5 * slope; upper1 = half_value * x2 * x2; upper2 = intercept * x2; lower1 = half_value * x1 * x1; lower2 = intercept * x1; sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ } /***********************************************************************/ /* The stop is within the trapazoid of the data. */ /***********************************************************************/ else if (X1 < stop_rad && stop_rad <= X2) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 6 X1 (%g) < stop_rad (%g) && stop_rad (%g) <= X2 (%g)", X1, stop_rad, stop_rad, X2); #endif /********************************************************************/ /* The start is within the trapazoid of the data. */ /********************************************************************/ if (start_rad >= X1) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 7 start_rad (%g) >= X1 (%g)", start_rad, X1); #endif x1 = start_rad; x2 = stop_rad; } /********************************************************************/ /* The start is within the trapazoid, but stop is not. */ /********************************************************************/ else { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 8 start_rad (%g) < X1 (%g)", start_rad, X1); #endif x1 = X1; x2 = stop_rad; } sumx += x2 - x1; /* accumulate the width */ half_value = 0.5 * slope; upper1 = half_value * x2 * x2; upper2 = intercept * x2; lower1 = half_value * x1 * x1; lower2 = intercept * x1; sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* accumulate trapazoid area */ } } /**************************************************************************/ /* Stop is above last center. */ /**************************************************************************/ if (stop_rad > X_centers[terms_minus_one]) { #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 9 stop_rad (%g) > X_centers[%ld] (%g)", stop_rad, terms_minus_one, X_centers[terms_minus_one]); #endif /*************************************************************************/ /* Integrate from the last data or stop if its bigger. */ /*************************************************************************/ #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 10 stop (%g) X[%ld] (%g)", stop, terms, X[terms]); #endif 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. */ /*************************************************************************/ #ifdef INT_PRINT if (which_dimen == PHI_DIMEN) printf ("\n 11 start_rad (%g) X_centers[%ld] (%g)", start_rad, terms_minus_one, X_centers[terms_minus_one]); #endif 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 */ /*************************************************************************/ /* Data wrapped accumulate trapazoidal area. */ /*************************************************************************/ if (wrap) { if (M_high >= VALID_MIN) { half_value = 0.5 * M_high; upper1 = half_value * x2 * x2; upper2 = B_high * x2; lower1 = half_value * x1 * x1; lower2 = B_high * x1; sum += upper1 - lower1; /* accumulate trapazoid area */ sum += upper2 - lower2; /* 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. */ /************************************************************************/ #ifdef INT_PRINT printf ("\n returning back with sumx = %g", sumx); #endif if (sumx > 0.0) return (sum); else return (OUTSIDE_MIN); }