/* * 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, Texa 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 "@(#) find_start_spin.c 1.2 05/08/19 SwRI" #include "libbase_idfs.h" /******************************************************************************* * * * IR_FIND_START_OF_SPIN_ANGLE SUBROUTINE * * * * DESCRIPTION * * This routine is called after a call to read_drec() and uses the * * azimuthal angle values to look for the start of spin indicator. The code * * is actually looking for the cross over at some angle value, where the * * default is 0 degrees unless specified in the VIDF. Since the exact angle * * may not be returned, a tolerance factor is utilized. * * * * INPUT VARIABLES * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * SDDAS_FLOAT tolerance number of degrees per sample * * SDDAS_USHORT *index_val element within the sweep at which spin started * * SDDAS_CHAR increasing_angles flag indicating if angles are increasing * * or decreasing within the sweep * * SDDAS_FLOAT azimuthal_cross_over angle where start of spin is flagged * * SDDAS_FLOAT last_swp_last_step_az az. angle value for last element of * * last sweep processed used to check for gaps * * * * USAGE * * x = ir_find_start_of_spin_angle (idf_data_ptr, tolerance, &index_val, * * increasing_angles, azimuthal_cross_over,* * last_swp_last_step_az) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * struct idf_data structure holding all of the currently * * *EXP_DATA returned data values to be processed * * reg SDDAS_USHORT loop looping variable * * SDDAS_FLOAT start_ang start azimuthal angle for the element * * SDDAS_FLOAT stop_ang stop azimuthal angle for the element * * SDDAS_FLOAT plus_cross_ang angle at which the start of spin is marked, * * adjusted for tolerance factor * * SDDAS_USHORT last_index index value for last angle in array * * SDDAS_CHAR roll_over flag indicating angle roll-over condition within* * last step * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_CHAR ir_find_start_of_spin_angle (void *idf_data_ptr, SDDAS_FLOAT tolerance, SDDAS_USHORT *index_val, SDDAS_CHAR increasing_angles, SDDAS_FLOAT azimuthal_cross_over, SDDAS_FLOAT last_swp_last_step_az) { struct idf_data *EXP_DATA; register SDDAS_USHORT loop; SDDAS_FLOAT start_ang, stop_ang, plus_cross_ang; SDDAS_USHORT last_index; SDDAS_CHAR roll_over; /*******************************************************************************/ /* Since the exact angle may not be returned, a tolerance factor is utilized. */ /* Make sure angle is less than 360 degree maximum. Only allow for a forward */ /* tolerance, not a backward tolerance. By allowing for the tolerance, we */ /* are basically looking for an angle within the range of azimuthal_cross_over*/ /* and plus_cross_ang. */ /*******************************************************************************/ plus_cross_ang = azimuthal_cross_over + tolerance; if (plus_cross_ang >= 360.0) plus_cross_ang -= 360.0; /****************************************************************************/ /* Angles increasing down the sweep (positive direction)? */ /****************************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; if (increasing_angles) { /*************************************************************************/ /* If the last starting angle value is greater than the first starting */ /* angle value AND the first starting angle value is greater than the */ /* cross over angle value and the cross over angle value adjusted for */ /* tolerance, there is no need to check any of the values since a */ /* roll-over did not over within the sweep. */ /*************************************************************************/ last_index = EXP_DATA->num_angle - 1; start_ang = EXP_DATA->start_az[0]; stop_ang = EXP_DATA->start_az[last_index]; roll_over = (EXP_DATA->stop_az[last_index] < stop_ang) ? 1 : 0; if (stop_ang > start_ang && !roll_over && (start_ang > azimuthal_cross_over && start_ang > plus_cross_ang)) { /**********************************************************************/ /* Before returning flag indicating angle not found, make sure */ /* requested angle is NOT within a gap. If it is, then the 1st */ /* element of this sweep should be flagged as the starting element. */ /**********************************************************************/ if (last_swp_last_step_az < start_ang) { if (last_swp_last_step_az < azimuthal_cross_over && azimuthal_cross_over < start_ang) { *index_val = 0; return (1); } } /**********************************************************************/ /* Angles wrapped around 360 degree boundary, so see if angle being */ /* searched for is within either of these 2 regions. Use <= only */ /* for numeric angle value within conditional. */ /**********************************************************************/ else { if (last_swp_last_step_az < azimuthal_cross_over && azimuthal_cross_over <= 360.0) { *index_val = 0; return (1); } /***********************************************************************/ /* Could be equal to, which implies no gap, but > implies wrap-around */ /* Had to check for the 1st conditional since very 1st sweep examined */ /* has no previous sweep to save as last_swp so code sets it to start */ /* az. value of current sweep (element 0). */ /***********************************************************************/ if (last_swp_last_step_az > start_ang && azimuthal_cross_over < start_ang) { *index_val = 0; return (1); } } return (0); } for (loop = 0; loop < EXP_DATA->num_angle; ++loop) { start_ang = EXP_DATA->start_az[loop]; stop_ang = EXP_DATA->stop_az[loop]; /*********************************************************************/ /* Start should always be less than stop UNLESS cross over 0 degree */ /* boundary. */ /*********************************************************************/ if (start_ang > stop_ang) { /*********************************************************************/ /* Did we find the cross over angle value? */ /*********************************************************************/ if (start_ang <= azimuthal_cross_over || azimuthal_cross_over <= stop_ang) { *index_val = loop; return (1); } /*********************************************************************/ /* Did we find the cross over angle value adjusted within tolerance?*/ /*********************************************************************/ if (start_ang <= plus_cross_ang || plus_cross_ang <= stop_ang) { *index_val = loop; return (1); } } /*********************************************************************/ /* Does this step hold the cross over angle value? */ /*********************************************************************/ else if (start_ang <= azimuthal_cross_over && azimuthal_cross_over <= stop_ang) { *index_val = loop; return (1); } /*********************************************************************/ /* Does this step hold the cross over angle value adjusted within */ /* tolerance? */ /*********************************************************************/ else if (start_ang <= plus_cross_ang && plus_cross_ang <= stop_ang) { *index_val = loop; return (1); } } } /****************************************************************************/ /* Angles decreasing down the sweep (negative direction)? */ /****************************************************************************/ else { /*************************************************************************/ /* If the first starting angle value is greater than the last starting */ /* angle value AND the last starting angle value is greater than the */ /* cross over angle value and the cross over angle value adjusted for */ /* tolerance, there is no need to check any of the values since a */ /* roll-over did not over within the sweep. */ /*************************************************************************/ last_index = EXP_DATA->num_angle - 1; start_ang = EXP_DATA->start_az[0]; stop_ang = EXP_DATA->start_az[last_index]; if (start_ang > stop_ang && (stop_ang > azimuthal_cross_over && stop_ang > plus_cross_ang)) { /**********************************************************************/ /* Before returning flag indicating angle not found, make sure */ /* requested angle is NOT within a gap. If it is, then the 1st */ /* element of this sweep should be flagged as the starting element. */ /**********************************************************************/ if (last_swp_last_step_az > start_ang) { if (last_swp_last_step_az > azimuthal_cross_over && azimuthal_cross_over > start_ang) { *index_val = 0; return (1); } } /**********************************************************************/ /* Angles wrapped around 360 degree boundary, so see if angle being */ /* searched for is within either of these 2 regions. Use <= only */ /* for numeric angle value within conditional. */ /**********************************************************************/ else { if (last_swp_last_step_az > azimuthal_cross_over && azimuthal_cross_over >= 0.0) { *index_val = 0; return (1); } /***********************************************************************/ /* Could be equal to, which implies no gap, but < implies wrap-around */ /* Had to check for the 1st conditional since very 1st sweep examined */ /* has no previous sweep to save as last_swp so code sets it to start */ /* az. value of current sweep (element 0). */ /***********************************************************************/ if (last_swp_last_step_az < start_ang && azimuthal_cross_over > start_ang) { *index_val = 0; return (1); } } return (0); } for (loop = 0; loop < EXP_DATA->num_angle; ++loop) { start_ang = EXP_DATA->start_az[loop]; stop_ang = EXP_DATA->stop_az[loop]; /*********************************************************************/ /* Start should always be greater than stop UNLESS cross over 0 */ /* degree boundary. */ /*********************************************************************/ if (start_ang < stop_ang) { /*********************************************************************/ /* Did we find the cross over angle value? */ /*********************************************************************/ if (azimuthal_cross_over <= start_ang || stop_ang <= azimuthal_cross_over) { *index_val = loop; return (1); } /*********************************************************************/ /* Did we find the cross over angle value adjusted within tolerance?*/ /*********************************************************************/ if (plus_cross_ang <= start_ang || stop_ang <= plus_cross_ang) { *index_val = loop; return (1); } } /*********************************************************************/ /* Does this step hold the cross over angle value? */ /*********************************************************************/ else if (stop_ang <= azimuthal_cross_over && azimuthal_cross_over <= start_ang) { *index_val = loop; return (1); } /*********************************************************************/ /* Does this step hold the cross over angle value adjusted within */ /* tolerance? */ /*********************************************************************/ else if (stop_ang <= plus_cross_ang && plus_cross_ang <= start_ang) { *index_val = loop; return (1); } } } /***************************************************************************/ /* Start of spin NOT FOUND within this sweep of data. */ /***************************************************************************/ return (0); }