/* * 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 "@(#) sen_start_spin.c 1.5 05/08/19 SwRI" #include "ret_codes.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_SENSOR_START_OF_SPIN_ANGLE SUBROUTINE * * * * DESCRIPTION * * This routine will find the start of spin for the specified sensor for * * the data set of interest using the angular determination method. This is * * necessary since angle is based upon time and each sensor can have a * * different time_off value which could result in slightly different times. * * This routine will have LOS_STATUS and NEXT_FILE_STATUS conditions instead * * of returning status code to calling module. * * * * INPUT VARIABLES * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_CHAR *exten the filename extension for the data to be used * * SDDAS_USHORT new_vnum version number for sensors to be processed * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * SDDAS_SHORT sensor sensor value of interest * * SDDAS_USHORT *found_ele element within the sweep at which spin started * * SDDAS_SHORT btime_yr the start time requested (year component) * * SDDAS_SHORT btime_day the start time requested (day component) * * SDDAS_LONG btime_sec the start time requested (seconds component) * * SDDAS_LONG btime_nsec the start time requested (nanoseconds) * * SDDAS_SHORT etime_yr the stop time requested (year component) * * SDDAS_SHORT etime_day the stop time requested (day component) * * SDDAS_LONG etime_sec the stop time requested (seconds component) * * SDDAS_LONG etime_nsec the stop time requested (nanoseconds) * * SDDAS_FLOAT *azimuthal_cross_over ptr to the angle value which defines * * where start of spin is flagged * * SDDAS_USHORT parent_vnum version number for the parent source * * * * USAGE * * x = ir_sensor_start_of_spin_angle (data_key, exten, new_vnum, * * idf_data_ptr, sensor, &found_ele, btime_yr, * * btime_day, btime_sec, btime_nsec, etime_yr, * * etime_day, etime_sec, etime_nsec, * * &azimuthal_cross_over, parent_vnum) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * read_drec () universal read routine that retrieves data for * * the time sample being processed * * ir_find_start_of_spin_angle () looks for the start of spin within the * * set of angular information passed in * * ir_check_idf_data_memory () makes sure that all allocated arrays in the * * idf_data structure are of sufficient size * * ir_spin_los_next_file () handles the case when an LOS_STATUS or * * NEXT_FILE_STATUS is encountered * * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * * * INTERNAL VARIABLES * * struct idf_data structure holding all of the currently * * *EXP_DATA returned data values to be processed * * struct experiment_info a pointer to the structure that holds specific * * *ex experiment information * * struct experiment_info a pointer to the structure that holds specific * * *parent_ex experiment information for the parent source * * struct ptr_rec *ptr a pointer to the structure which holds all * * pointers to the header and data for the * * experiment of interest * * struct start_spin_info *sptr a pointer to the structure which holds all * * spin information for the sensor being processed * * SDDAS_DOUBLE diff_samp the time covered by the sweep in milliseconds * * SDDAS_FLOAT tolerance number of degrees per sample * * SDDAS_LONG diff_milli the milliseconds difference between the * * start and end time values being utilized * * SDDAS_LONG diff_nano the nanoseconds difference between the * * start and end time values being utilized * * SDDAS_SHORT rval value returned by called module * * SDDAS_SHORT read_code value returned by read routine * * SDDAS_SHORT diff_year the year difference between the start and * * the end of the sweep time period * * SDDAS_SHORT diff_day the day difference between the start and * * the end of the sweep time period * * SDDAS_SHORT days_in_yr the number of days in the year - takes leap * * year into account * * SDDAS_CHAR full_swp flag that indicates if 1 value is being * * requested or all values for the record (for * * a scalar parameter only) * * SDDAS_CHAR found_start flag indicating start of spin found * * SDDAS_CHAR fwd flag that indicates when to advance to the * * time sample * * SDDAS_BOOL constant_id_14 flag indicating if constant 14 was defined * * int ret_val value returned by called module * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_sensor_start_of_spin_angle (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT new_vnum, void *idf_data_ptr, SDDAS_SHORT sensor, SDDAS_USHORT *found_ele, SDDAS_SHORT btime_yr, SDDAS_SHORT btime_day, SDDAS_LONG btime_sec, SDDAS_LONG btime_nsec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec, SDDAS_FLOAT *azimuthal_cross_over, SDDAS_USHORT parent_vnum) { extern struct general_info ginfo; struct idf_data *EXP_DATA; struct experiment_info *ex, *parent_ex; struct ptr_rec *ptr; struct start_spin_info *sptr; SDDAS_DOUBLE diff_samp; SDDAS_FLOAT tolerance; SDDAS_LONG diff_milli, diff_nano; SDDAS_SHORT rval, read_code, diff_year, diff_day, days_in_yr; SDDAS_CHAR full_swp, found_start = 0, fwd; SDDAS_BOOL constant_id_14; int ret_val; /***************************************************************************/ /* Point to the ex structure associated with the sensor being processed. */ /***************************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; /***************************************************************************/ /* Check for definition of constant id 14, start of spin azimuthal angle */ /* offset. If the constant is not defined, default of 0 degrees is used */ /* to mark start of spin. No need to check boolean flag since address */ /* passed into this module is the address in the spin structure where the */ /* start of spin azimuthal angle offset is held (has been initialized.) */ /***************************************************************************/ ret_val = ir_get_start_of_spin_azimuthal_angle_constants (btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, sensor, azimuthal_cross_over, &constant_id_14); if (ret_val != ALL_OKAY) return ((SDDAS_SHORT) ret_val); /***************************************************************************/ /* The start of spin structures are held by the parent source, not by the */ /* experiment_info structure defined for each individual sensor. No need */ /* to check return value. */ /***************************************************************************/ full_swp = (ex->smp_id == 2) ? 0 : 1; fwd = 1; rval = ir_locate_ex (data_key, exten, parent_vnum, 0); parent_ex = ginfo.expt; sptr = parent_ex->start_sptr + sensor; while (!found_start) { /***********************************************************************/ /* Call read_drec to get the values needed to compute start of spin, */ /* Go ahead and advance in time since each sensor uses it's own ex */ /* structure. If an error was encountered, return to calling routine.*/ /***********************************************************************/ read_code = read_drec (data_key, exten, new_vnum, idf_data_ptr, sensor, fwd, full_swp); if (read_code < 0) return (read_code); /*************************************************************/ /* Need to check the sizes of arrays in the idf_data */ /* structure since header changed. */ /*************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; if (EXP_DATA->hdr_change) { rval = ir_check_idf_data_memory (data_key, exten, new_vnum, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } /*****************************************************************/ /* Handle file crossing condition. This is valid since data is */ /* processed and then the file pointer is advanced. */ /*****************************************************************/ if (read_code == LOS_STATUS || read_code == NEXT_FILE_STATUS) { rval = ir_spin_los_next_file (data_key, exten, new_vnum, idf_data_ptr, sensor); if (rval != ALL_OKAY) return (rval); } /*******************************************************************/ /* Loop over all returned start (stop) azimuthal angles, looking */ /* for 0 degrees, within tolerance. */ /*******************************************************************/ if (EXP_DATA->filled_data) { /*******************************************************************/ /* Figure out time duration covered by this sweep in milliseconds.*/ /*******************************************************************/ diff_year = EXP_DATA->eyear - EXP_DATA->byear; diff_day = EXP_DATA->eday - EXP_DATA->bday; diff_milli = EXP_DATA->emilli - EXP_DATA->bmilli; diff_nano = EXP_DATA->enano - EXP_DATA->bnano; if (diff_nano < 0) { --diff_milli; diff_nano += 1000000; /* 1 milli = 1000000 nanoseconds */ } /******************************************************************/ /* The sample's time range covers a day or more? */ /******************************************************************/ if (diff_day != 0 || diff_year != 0) { /******************************************************************/ /* Assumption is no more than a year difference. */ /******************************************************************/ if ((EXP_DATA->byear % 4 == 0 && EXP_DATA->byear % 100 != 0) || EXP_DATA->byear % 400 == 0) days_in_yr = 366; else days_in_yr = 365; diff_samp = (diff_year * days_in_yr * 86400000) + diff_day * 86400000 + diff_milli + (diff_nano / 1000000.0); } else diff_samp = diff_milli + (diff_nano / 1000000.0); /******************************************************************/ /* Now, convert tolerance to degrees per sample for direct */ /* comparison against the azimuthal angles that are computed. */ /* Make sure to include the nanosecond component as a fraction */ /* of time for better accuracy so that tolerance is not TOO wide.*/ /******************************************************************/ tolerance = ptr->deg_per_msec; tolerance *= diff_samp / EXP_DATA->num_sample; found_start = ir_find_start_of_spin_angle (idf_data_ptr, tolerance, found_ele, ptr->increasing_angles, *azimuthal_cross_over, sptr->last_swp_last_step_az); sptr->last_swp_last_step_az = EXP_DATA->stop_az[EXP_DATA->num_sample-1]; } else found_start = 0; if (!found_start) { /******************************************************************/ /* The requested end time has been reached and no start of spin? */ /* Broke up the single if conditional since year component and */ /* day component was being repeatedly checked for equality. */ /******************************************************************/ if (EXP_DATA->byear == etime_yr) { if (EXP_DATA->bday == etime_day) { if (EXP_DATA->bsec > etime_sec || (EXP_DATA->bsec == etime_sec && EXP_DATA->bnsec > etime_nsec)) return (START_SPIN_ETIME); } else if (EXP_DATA->bday > etime_day) return (START_SPIN_ETIME); } else if (EXP_DATA->byear > etime_yr) return (START_SPIN_ETIME); } /*******************************************************************/ /* Be sure to reset ex structure after calling read_drec() since */ /* multiple VIDF file crossing may cause a reallocation of the */ /* existing ex structures so address may change. */ /*******************************************************************/ /**************************************************************************/ /* More time effective to make sure need to find new ex structure BEFORE */ /* incurring subroutine overhead. Most of the time, applications don't */ /* make use of exten. */ /**************************************************************************/ ex = ginfo.expt; if (ex->data_key != data_key || ex->version != new_vnum) { rval = ir_locate_ex (data_key, exten, new_vnum, 0); if (rval != ALL_OKAY) return (START_SPIN_NOT_FOUND); } ex = ginfo.expt; ptr = ex->info_ptr; } ex->next_offset = 0; return (ALL_OKAY); }