/* * 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 "@(#) compute_pa.c 1.10 05/08/19 SwRI" #include #include "user_defs.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_COMPUTE_PITCH_ANGLE SUBROUTINE * * * * DESCRIPTION * * This routine computes the pitch angle for each time period associated * * with each element of the sweep. The dot product of the unit normal to the * * detector aperture with the local magnetic field is computed. The value * * computed is in terms of radians, so the value is converted to degrees * * before it is returned. * * * * INPUT VARIABLES * * struct pitch_info *pa_ptr a pointer to the structure that holds pitch * * angle information * * SDDAS_FLOAT *pitch_data pointer to the memory where the pitch angles * * are returned * * SDDAS_SHORT sensor the sensor for which data is requested * * SDDAS_USHORT max_ele the number of elements in the sweep * * struct direction_cos *dcos_ptr ptr to the direction cosine structure * * * * USAGE * * ir_compute_pitch_angle (pa_ptr, &pitch_data, sensor, max_ele, * * dcos_ptr) * * * * NECESSARY SUBPROGRAMS * * sqrt () returns the square root of the argument * * acos () returns arc cosine of input * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_DOUBLE *unit_vec ptr to the unit normal vector * * reg SDDAS_DOUBLE *mag_vec ptr to the magnetic field vector * * reg SDDAS_DOUBLE *vec_end loop termination variable * * reg SDDAS_FLOAT *dcos_val ptr to the direction cosine array * * reg SDDAS_USHORT swp_step the sweep step being processed * * SDDAS_DOUBLE top_val the result of calculation for the numerator * * SDDAS_DOUBLE mag_sum the summation of the magnetic field elements * * SDDAS_DOUBLE bot_val the result of the calculation for denominator* * SDDAS_DOUBLE dot_data the computed dot product value * * SDDAS_DOUBLE ret_data the computed pitch angle value * * SDDAS_DOUBLE xval x component of the vector * * SDDAS_DOUBLE yval y component of the vector * * SDDAS_DOUBLE zval z component of the vector * * SDDAS_DOUBLE *start_az ptr to computed start az. angles for dir. * * cos. data * * SDDAS_DOUBLE *stop_az ptr to computed stop az. angles for dir. * * cos. data * * SDDAS_DOUBLE *start_theta ptr to computed start theta angles for dir. * * cos. data * * SDDAS_DOUBLE *stop_theta ptr to computed stop theta angles for dir. * * cos. data * * SDDAS_FLOAT *sa_ptr ptr to start az. angles for dir. cos. data * * returned along with pitch angle data * * SDDAS_FLOAT *ea_ptr ptr to stop az. angles for dir. cos. data * * returned along with pitch angle data * * SDDAS_FLOAT *st_ptr ptr to start theta angles for dir. cos. data * * returned along with pitch angle data * * SDDAS_FLOAT *et_ptr ptr to stop theta angles for dir. cos. data * * returned along with pitch angle data * * SDDAS_LONG offset offset into allocated memory * * SDDAS_SHORT sensor_index offset based on sensor being processed * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ void ir_compute_pitch_angle (struct pitch_info *pa_ptr, SDDAS_FLOAT *pitch_data, SDDAS_SHORT sensor, SDDAS_USHORT max_ele, struct direction_cos *dcos_ptr) { register SDDAS_DOUBLE *unit_vec, *mag_vec, *vec_end; register SDDAS_FLOAT *dcos_val; register SDDAS_USHORT swp_step; SDDAS_DOUBLE top_val, mag_sum, bot_val, dot_data, ret_data; SDDAS_DOUBLE xval, yval, zval; SDDAS_DOUBLE *start_az, *stop_az, *start_theta, *stop_theta; SDDAS_FLOAT *sa_ptr, *ea_ptr, *st_ptr, *et_ptr; SDDAS_LONG offset; SDDAS_SHORT sensor_index; /*********************************************************************/ /* Process each element of the sweep. */ /* Addition is faster than multiplication (used for sensor_index). */ /*********************************************************************/ sensor_index = sensor + sensor + sensor; offset = 0; for (swp_step = 0; swp_step < max_ele; ++swp_step, offset += 3) { /*********************************************************************/ /* Set pointers to the two vectors and initialize variables. */ /*********************************************************************/ mag_vec = pa_ptr->data_val + offset; vec_end = mag_vec + 3; unit_vec = pa_ptr->unit_normals + sensor_index; xval = *mag_vec; yval = *(mag_vec + 1); zval = *(mag_vec + 2); /*********************************************************************/ /* If any of the three components indicate missing data, then set */ /* the pitch angle value to indicate missing data. */ /*********************************************************************/ if (xval < VALID_MIN || yval < VALID_MIN || zval < VALID_MIN) { *(pitch_data + swp_step) = OUTSIDE_MIN; /*********************************************************************/ /* Determine the direction cosines for the three components. For */ /* the direction cosine data and angles, the values are laid as */ /* triplets, for each sweep step processed. */ /*********************************************************************/ dcos_val = dcos_ptr->dir_cos123 + offset; *dcos_val++ = OUTSIDE_MIN; *dcos_val++ = OUTSIDE_MIN; *dcos_val = OUTSIDE_MIN; } else { /*********************************************************************/ /* Do a summation from 1 to N for the numerator and denominator. */ /* Since the unit normal are constants, the magnitude was computed */ /* when the three components were retrieved. */ /*********************************************************************/ mag_sum = top_val = 0.0; for (; mag_vec < vec_end; ++unit_vec, ++mag_vec) { top_val += *unit_vec * *mag_vec; mag_sum += *mag_vec * *mag_vec; } /*********************************************************************/ /* Solve for the denominator and compute the dot product. */ /*********************************************************************/ mag_sum = sqrt (mag_sum); bot_val = pa_ptr->mag_normal[sensor] * mag_sum; dot_data = (-1 * top_val) / bot_val; ret_data = acos (dot_data); *(pitch_data + swp_step) = (SDDAS_FLOAT) (ret_data / TORAD); /*********************************************************************/ /* Determine the direction cosines for the three components. For */ /* the direction cosine data and angles, the values are laid as */ /* triplets, for each sweep step processed. */ /*********************************************************************/ dcos_val = dcos_ptr->dir_cos123 + offset; *dcos_val++ = (SDDAS_FLOAT) (xval / mag_sum); *dcos_val++ = (SDDAS_FLOAT) (yval / mag_sum); *dcos_val = (SDDAS_FLOAT) (zval / mag_sum); } /*********************************************************************/ /* For the direction cosine angles, the values are laid as triplets,*/ /* for each sweep step processed. */ /*********************************************************************/ start_az = pa_ptr->start_az + offset; sa_ptr = dcos_ptr->start_az123 + offset; *sa_ptr++ = (SDDAS_FLOAT) *start_az++; *sa_ptr++ = (SDDAS_FLOAT) *start_az++; *sa_ptr = (SDDAS_FLOAT) *start_az; stop_az = pa_ptr->stop_az + offset; ea_ptr = dcos_ptr->stop_az123 + offset; *ea_ptr++ = (SDDAS_FLOAT) *stop_az++; *ea_ptr++ = (SDDAS_FLOAT) *stop_az++; *ea_ptr = (SDDAS_FLOAT) *stop_az; start_theta = pa_ptr->start_theta + offset; st_ptr = dcos_ptr->start_theta123 + offset; *st_ptr++ = (SDDAS_FLOAT) *start_theta++; *st_ptr++ = (SDDAS_FLOAT) *start_theta++; *st_ptr = (SDDAS_FLOAT) *start_theta; stop_theta = pa_ptr->stop_theta + offset; et_ptr = dcos_ptr->stop_theta123 + offset; *et_ptr++ = (SDDAS_FLOAT) *stop_theta++; *et_ptr++ = (SDDAS_FLOAT) *stop_theta++; *et_ptr = (SDDAS_FLOAT) *stop_theta; } }