/* * 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_src.c 1.3 05/08/19 SwRI" #include "ret_codes.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_SENSOR_START_OF_SPIN_SRC SUBROUTINE * * * * DESCRIPTION * * This routine will find the start of spin for the specified sensor for * * the data set of interest. This is necessary since 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 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 sweep at which spin started * * 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_SHORT *swp_btime_yr pointer to start year value for each step * * SDDAS_SHORT *swp_btime_day pointer to start day of year value for * * each step * * SDDAS_LONG *swp_btime_ms pointer to start milliseconds for each step * * SDDAS_LONG *swp_btime_ns pointer to start nanoseconds for each step * * SDDAS_SHORT *swp_etime_yr pointer to end year value for each step * * SDDAS_SHORT *swp_etime_day pointer to end day of year value for * * each step * * SDDAS_LONG *swp_etime_ms pointer to end milliseconds for each step * * SDDAS_LONG *swp_etime_ns pointer to end nanoseconds for each step * * SDDAS_FLOAT *frac the percentage of the spin period covered * * by the current sample * * * * USAGE * * x = ir_sensor_start_of_spin_src (data_key, exten, new_vnum, idf_data_ptr,* * sensor, &found_ele, etime_yr, etime_day, * * etime_sec, etime_nsec, &swp_btime_yr, * * &swp_btime_day, &swp_btime_ms, &swp_btime_ns,* * &swp_etime_yr, &swp_etime_day, &swp_etime_ms,* * &swp_etime_ns, &frac) * * * * 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_src() looks for the start of spin within the * * time periods for each step returned * * 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 * * ir_spin_sweep_times () computes the time period for each element of * * the sweep * * * * 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 idf_data structure holding the data for the start of * * *SPIN_SRC_DATA spin data source * * struct experiment_info a pointer to structure that holds specific * * *ex, *new_ex experiment information * * struct spin_src_info a pointer to the structure that holds * * *spin_src_ptr start of spin data source information * * SDDAS_USHORT max_ele the number of elements in the sweep * * SDDAS_SHORT rval value returned by called module * * SDDAS_SHORT read_code value returned by read routine * * 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_CHAR same_times flag indicating if the same time range is * * applicable to all steps of the vector * * SDDAS_CHAR use_start flag which indicates if computation of * * fraction is with respect to the start of the * * spin or the end of the spin (0 = end) * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_sensor_start_of_spin_src (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT new_vnum, void *idf_data_ptr, SDDAS_SHORT sensor, SDDAS_USHORT *found_ele, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec, SDDAS_SHORT *swp_btime_yr, SDDAS_SHORT *swp_btime_day, SDDAS_LONG *swp_btime_ms, SDDAS_LONG *swp_btime_ns, SDDAS_SHORT *swp_etime_yr, SDDAS_SHORT *swp_etime_day, SDDAS_LONG *swp_etime_ms, SDDAS_LONG *swp_etime_ns, SDDAS_FLOAT *frac) { extern struct general_info ginfo; struct idf_data *EXP_DATA, *SPIN_SRC_DATA; struct experiment_info *ex, *new_ex; struct spin_src_info *spin_src_ptr; SDDAS_USHORT max_ele; SDDAS_SHORT rval, read_code; SDDAS_CHAR full_swp, found_start = 0, fwd, same_times, use_start; /***************************************************************************/ /* Point to the ex structure associated with the sensor being processed. */ /***************************************************************************/ ex = ginfo.expt; /* spin_src_ptr = ex->spin_src; */ full_swp = (ex->smp_id == 2) ? 0 : 1; fwd = 1; while (!found_start) { /***********************************************************************/ /* Call read_drec, 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); new_ex = ginfo.expt; spin_src_ptr = new_ex->spin_src; /***********************************************************************/ /* Check sizes of arrays in 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 samples, looking for the time period which corresponds */ /* to the data source spin controller. */ /************************************************************************/ if (EXP_DATA->filled_data) { /**********************************************************************/ /* Compute the times for each element in the sweep. Use new_ex */ /* since call to read_drec() could modify pointer address. */ /**********************************************************************/ max_ele = EXP_DATA->num_sample; ir_spin_sweep_times (sensor, max_ele, &same_times, EXP_DATA->byear, EXP_DATA->bday, swp_btime_yr, swp_btime_day, swp_btime_ms, swp_btime_ns, swp_etime_yr, swp_etime_day, swp_etime_ms, swp_etime_ns); SPIN_SRC_DATA = (struct idf_data *) spin_src_ptr->idf_data_ptr; found_start = ir_find_start_of_spin_src (max_ele, found_ele, same_times, frac, SPIN_SRC_DATA->byear, SPIN_SRC_DATA->bday, SPIN_SRC_DATA->bmilli, SPIN_SRC_DATA->bnano, SPIN_SRC_DATA->eyear, SPIN_SRC_DATA->eday, SPIN_SRC_DATA->emilli, SPIN_SRC_DATA->enano, swp_btime_yr, swp_btime_day, swp_btime_ms, swp_btime_ns, swp_etime_yr, swp_etime_day, swp_etime_ms, swp_etime_ns, &use_start); #ifdef SPIN_SRC_CHECK #include printf ("\n found_start for sensor %d = %d frac = %f", sensor, found_start, *frac); #endif } else found_start = 0; if (!found_start) { /******************************************************************/ /* The requested end time has been reached and no start of spin? */ /******************************************************************/ 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; } ex->next_offset = 0; return (ALL_OKAY); }