/* * 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 "@(#) sph_int_pnt_cont.c 1.1 05/08/19 SwRI" #include #include "user_defs.h" #include "libtrec_idfs.h" #define TO_RAD .01745329251994329576 /***************************************************************************** * * * IR_SPHERICAL_INT_POINT_CONT SUBROUTINE * * * * DESCRIPTION * * This routine is called to calculate a spherical trapezoidal integral * * (point) using contiguous band values. This module has not been checked * * so it is not currently utilized. The sin() call is suspect and needs to * * be investigated and although the calling sequence was modified to make * * use of the normalization flag, the code has not been modified to take * * this into account. * * * * 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 norm flag indicating if the result is to be * * normalized * * * * USAGE * * x = ir_spherical_int_point_cont (X, Y, skip, terms, start, stop, norm) * * * * NECESSARY SUBPROGRAMS * * sin() returns double-precision sine function of * * the argument * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_FLOAT *f1, *f2 pointers to band values * * reg SDDAS_FLOAT *f3, *f4 pointers to data values * * register SDDAS_FLOAT sum summation value of integration * * reg SDDAS_FLOAT *f_end end of X array * * SDDAS_FLOAT ret_val resultant value returned to calling module * * SDDAS_FLOAT a, b center of first and second band * * SDDAS_FLOAT c, d, e, f variables used for trapezoidal integration * * SDDAS_FLOAT top upper band * * SDDAS_FLOAT bot lower band * * * * SUBSYSTEM * * Display Level * * * ****************************************************************************/ /*** SPHERICAL TRAPAZOIDAL INTEGRAL, CONTIGUOUS X BANDS ***/ SDDAS_FLOAT ir_spherical_int_point_cont (SDDAS_FLOAT *X, SDDAS_FLOAT *Y, SDDAS_LONG skip, SDDAS_LONG terms, SDDAS_FLOAT start, SDDAS_FLOAT stop, SDDAS_CHAR norm) { register SDDAS_FLOAT *f1, *f2, *f3, *f4, sum, *f_end; SDDAS_FLOAT ret_val = 0.0, a, b, c, d, e, f, top, bot; /* This module has not been checked so it is not currently utilized. */ /* The sin() call is suspect and needs to be investigated and */ /* although the calling sequence was modified to make use of the */ /* normalization flag, the code has not been modified to take this into */ /* account. */ f_end = X + terms; bot = (X[0] + X[1]) / 2.0; top = (*f_end + *(f_end - 1)) / 2.0; /* 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) /* check for special request */ { /* to integrate over all X */ start = bot; /* set start to least X */ stop = top; /* set stop to largest X */ } if (start >= top || stop <= bot) return (OUTSIDE_MIN); f1 = X + 1; f2 = X + 2; f3 = Y; f4 = Y + skip; a = ( *f1 + *(f1 - 1) ) / 2.0; b = ( *f2 + *f1 ) / 2.0; e = sin(a * TO_RAD); f = sin(b * TO_RAD); if (start > a) { while ((start >= b) && (f2 <= f_end)) { a = b; b = ( *(++f2) + *(++f1) ) / 2.0; f3 += skip; f4 += skip; } e = sin(a * TO_RAD); f = sin(b * TO_RAD); if (*f3 >= VALID_MIN && *f4 >= VALID_MIN) { c = (b - a); d = (start - a); ret_val = (*f4 * f - *f3 * e) * (c * c - d * d ) / 2.0 / c; ret_val += (b - start) * *f3 * e; } a = b; e = f; b = ( *(++f2) + *(++f1)) / 2.0; f = sin(b * TO_RAD); f3 += skip; f4 += skip; } else { e = sin(a * TO_RAD); f = sin(b * TO_RAD); } sum = ret_val; while ((stop >= b) && (f2 <= f_end)) { if (*f3 >= VALID_MIN && *f4 >= VALID_MIN) sum += (b - a) * (*f3 * e + *f4 * f); a = b; e = f; b = ( *(++f2) + *(++f1) ) / 2.0; f = sin(b * TO_RAD); f3 += skip; f4 += skip; } ret_val += .5 * sum; if ((stop < top) && (*f3 >= VALID_MIN) && (*f4 >= VALID_MIN)) { c = (b - a); d = (stop - a); ret_val += (*f4 * b - *f3 * a) * d * d / 2.0 / c; ret_val += (stop - a) * *f3; } } else { if (start > stop) /* check for special request */ { /* to integrate over all X */ start = top; /* set start to least X */ stop = bot; /* set stop to largest X */ } if (start >= bot || stop <= top) return (OUTSIDE_MIN); f1 = f_end - 1; f2 = f_end - 2; f3 = Y + (terms - 1) * skip; f4 = Y + (terms - 2) * skip; a = ( *f1 + *(f1 + 1) ) / 2.0; b = ( *f2 + *f1 ) / 2.0; if (start > a) { while ((start >= b) && (f2 >= X)) { a = b; b = ( *(--f2) + *(--f1) ) / 2.0; f3 -= skip; f4 -= skip; } e = sin(a * TO_RAD); f = sin(b * TO_RAD); if (*f3 >= VALID_MIN && *f4 >= VALID_MIN) { c = (b - a); d = (start - a); ret_val = (*f4 * f - *f3 * e) * (c * c - d * d ) / 2.0 / c; ret_val += (b - start) * *f3 * e; } a = b; e = f; b = ( *(--f2) + *(--f1)) / 2.0; f = sin(b * TO_RAD); f3 -= skip; f4 -= skip; } else { e = sin(a * TO_RAD); f = sin(b * TO_RAD); } sum = ret_val; while ((stop >= b) && (f2 >= X)) { if (*f3 >= VALID_MIN && *f4 >= VALID_MIN) sum += (b - a) * (*f3 * e + *f4 * f); a = b; e = f; b = ( *(--f2) + *(--f1) ) / 2.0; f = sin(b * TO_RAD); f3 -= skip; f4 -= skip; } ret_val = 0.5 * sum; if ((stop < bot) && (*f3 >= VALID_MIN) && (*f4 >= VALID_MIN)) { c = (b - a); d = (stop - a); sum += (*f4 * f - *f3 * e) * d * d / 2.0 / c; sum += (stop - a) * *f3 * e; } } /* Should we make sure ret_val is set to some number? If it wasn't */ /* we should be returning OUTSIDE_MIN. */ ret_val *= TO_RAD; return (ret_val); }