/* * 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_src.c 1.3 05/08/19 SwRI" #include "libbase_idfs.h" /******************************************************************************* * * * IR_FIND_START_OF_SPIN_SRC SUBROUTINE * * * * DESCRIPTION * * This routine is called after a call to read_drec() and uses the * * time period for each element of the current sweep to look for the start of * * the current spin. * * * * INPUT VARIABLES * * SDDAS_USHORT max_ele the number of elements in the sweep * * SDDAS_USHORT *index_val element within sweep at which spin started * * SDDAS_CHAR same_times flag indicating if the same time range is * * applicable to all steps of the vector * * SDDAS_FLOAT *frac the percentage of the spin period covered * * by the current sample * * SDDAS_SHORT spin_btime_yr start of spin year component * * SDDAS_SHORT spin_btime_day start of spin day of year component * * SDDAS_LONG spin_btime_msec start of spin milliseconds time component * * SDDAS_LONG spin_btime_nsec start of spin nanoseconds time component * * SDDAS_SHORT spin_etime_yr end of spin year component * * SDDAS_SHORT spin_etime_day end of spin day of year component * * SDDAS_LONG spin_etime_msec end of spin milliseconds time component * * SDDAS_LONG spin_etime_nsec end of spin nanoseconds time component * * 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_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) * * * * USAGE * * x = ir_find_start_of_spin_src (max_ele, &index_val, same_times, &frac, * * spin_btime_yr, spin_btime_day, spin_btime_ms, * * spin_btime_ns, spin_etime_yr, spin_etime_day, * * spin_etime_ms, spin_etime_ns, &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) * * * * NECESSARY SUBPROGRAMS * * ir_spin_calc_time_frac () determines the percentage of the current * * spin period covered by the current sweep * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_LONG *bptr_ms, pointers to the start time memory locations * * *bptr_ns * * reg SDDAS_LONG *eptr_ms, pointers to the end time memory locations * * *eptr_ns * * reg SDDAS_SHORT *bptr_yr, pointers to the start time memory locations * * *bptr_day * * reg SDDAS_SHORT *eptr_yr, pointers to the end time memory locations * * *eptr_day * * SDDAS_USHORT num_vals number of steps to examine * * SDDAS_LONG btime_combo start of spin year/day time combination * * SDDAS_LONG etime_combo end of spin year/day time combination * * SDDAS_LONG stime_combo start of current step year/day time combo * * SDDAS_LONG day_msec upper millisecond limit for time comparison * * SDDAS_LONG day_nsec upper nanosecond limit for time comparison * * SDDAS_USHORT loop looping variable * * SDDAS_CHAR diff_day flag indicating day crossing for spin period * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_CHAR ir_find_start_of_spin_src (SDDAS_USHORT max_ele, SDDAS_USHORT *index_val, SDDAS_CHAR same_times, SDDAS_FLOAT *frac, SDDAS_SHORT spin_btime_yr, SDDAS_SHORT spin_btime_day, SDDAS_LONG spin_btime_msec, SDDAS_LONG spin_btime_nsec, SDDAS_SHORT spin_etime_yr, SDDAS_SHORT spin_etime_day, SDDAS_LONG spin_etime_msec, SDDAS_LONG spin_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_CHAR *use_start) { register SDDAS_LONG *bptr_ms, *bptr_ns, *eptr_ms, *eptr_ns; register SDDAS_SHORT *bptr_yr, *bptr_day, *eptr_yr, *eptr_day; SDDAS_USHORT num_vals; SDDAS_LONG btime_combo, etime_combo, stime_combo, day_msec, day_nsec; SDDAS_USHORT loop; SDDAS_CHAR diff_day; /**************************************************************************/ /* Get start and end time of the spin from the start of spin data source. */ /**************************************************************************/ btime_combo = spin_btime_yr * spin_btime_day; etime_combo = spin_etime_yr * spin_etime_day; diff_day = (btime_combo == etime_combo) ? 0 : 1; *use_start = 0; #ifdef SPIN_SRC_CHECK #include SDDAS_LONG new_nano, temp; SDDAS_SHORT hr, min, sec; new_nano = ((spin_btime_msec % 1000) * 1000000) + spin_btime_nsec; temp = spin_btime_msec / 1000; hr = temp / 3600; temp = temp % 3600; min = temp / 60; sec = temp % 60; printf ("\n data source start time = %04d:%03d %02d:%02d:%02d.%ld", spin_btime_yr, spin_btime_day, hr, min, sec, new_nano); new_nano = ((spin_etime_msec % 1000) * 1000000) + spin_etime_nsec; temp = spin_etime_msec / 1000; hr = temp / 3600; temp = temp % 3600; min = temp / 60; sec = temp % 60; printf ("\n data source end time = %04d:%03d %02d:%02d:%02d.%ld", spin_etime_yr, spin_etime_day, hr, min, sec, new_nano); #endif /****************************************************************************/ /* Set pointers to the start time components for each element of the sweep. */ /****************************************************************************/ bptr_yr = swp_btime_yr; bptr_day = swp_btime_day; bptr_ms = swp_btime_ms; bptr_ns = swp_btime_ns; eptr_yr = swp_etime_yr; eptr_day = swp_etime_day; eptr_ms = swp_etime_ms; eptr_ns = swp_etime_ns; /****************************************************************************/ /* This code assumes that a spin can be no more than a day in length. */ /****************************************************************************/ num_vals = (same_times) ? 1 : max_ele; for (loop = 0; loop < num_vals; ++loop, ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns, ++eptr_yr, ++eptr_day, ++eptr_ms, ++eptr_ns) { stime_combo = *bptr_yr * *bptr_day; /*********************************************************************/ /* Same year and day of year value as start time of spin source? */ /*********************************************************************/ if (stime_combo == btime_combo) { /*********************************************************************/ /* Start time of this element is equal to or past the start time */ /* of the spin, so compare with the end time of the spin. */ /*********************************************************************/ if (spin_btime_msec < *bptr_ms || (spin_btime_msec == *bptr_ms && spin_btime_nsec <= *bptr_ns)) { /******************************************************************/ /* If the spin controller crosses a day boundary, compare start */ /* time against the upper limit of time in a day. */ /******************************************************************/ day_msec = (diff_day) ? 86400000 : spin_etime_msec; day_nsec = (diff_day) ? 0 : spin_etime_nsec; /****************************************************************/ /* Start time of this element starts within the spin range? */ /****************************************************************/ if (*bptr_ms < day_msec || (*bptr_ms == day_msec && *bptr_ns <= day_nsec)) { /****************************************************************/ /* Stop time of this element is less than or equal to the end */ /* time of the spin, so this sample is contained totally within*/ /* the spin range. */ /****************************************************************/ if (*eptr_ms < spin_etime_msec || (*eptr_ms == spin_etime_msec && *eptr_ns <= spin_etime_nsec)) *frac = 1.0; /****************************************************************/ /* Determine what part of this sweep is contained within this */ /* spin period. */ /****************************************************************/ else { *use_start = 0; *frac = ir_spin_calc_time_frac (spin_btime_yr, spin_btime_day, spin_btime_msec, spin_btime_nsec, spin_etime_yr, spin_etime_day, spin_etime_msec, spin_etime_nsec, *bptr_yr, *bptr_day, *bptr_ms, *bptr_ns, *eptr_yr, *eptr_day, *eptr_ms, *eptr_ns, *use_start); } *index_val = loop; return (1); } } /*********************************************************************/ /* Start time begins prior to this spin but is the end time of this */ /* sample contained within the range of the spin? */ /*********************************************************************/ else if (spin_btime_msec < *eptr_ms || (spin_btime_msec == *eptr_ms && spin_btime_nsec <= *eptr_ns)) { /******************************************************************/ /* If the spin controller crosses a day boundary, compare against*/ /* the upper limit of time in a day. */ /******************************************************************/ day_msec = (diff_day) ? 86400000 : spin_etime_msec; day_nsec = (diff_day) ? 0 : spin_etime_nsec; /*******************************************************************/ /* Stop time of this element is less than or equal to the end */ /* time of the spin, so this sample starts within the spin range. */ /*******************************************************************/ if (*eptr_ms < day_msec || (*eptr_ms == day_msec && *eptr_ns <= day_nsec)) { *use_start = 1; *frac = ir_spin_calc_time_frac (spin_btime_yr, spin_btime_day, spin_btime_msec, spin_btime_nsec, spin_etime_yr, spin_etime_day, spin_etime_msec, spin_etime_nsec, *bptr_yr, *bptr_day, *bptr_ms, *bptr_ns, *eptr_yr, *eptr_day, *eptr_ms, *eptr_ns, *use_start); *index_val = loop; return (1); } } } /*********************************************************************/ /* Same year and day of year value as end time of spin source? */ /* This case will only be executed IF the start of spin data source */ /* crosses a day boundary. */ /*********************************************************************/ else if (stime_combo == etime_combo) { /******************************************************************/ /* Start time of this element is less than or equal to the end */ /* time of the spin. No need to compare against start time since*/ /* a day boundary was crossed. */ /******************************************************************/ if (*bptr_ms < spin_etime_msec || (*bptr_ms == spin_etime_msec && *bptr_ns <= spin_etime_nsec)) { /*******************************************************************/ /* Stop time of this element is less than or equal to the end */ /* time of the spin, so this sample is contained totally within */ /* the spin range. */ /*******************************************************************/ if (*eptr_ms < spin_etime_msec || (*eptr_ms == spin_etime_msec && *eptr_ns <= spin_etime_nsec)) *frac = 1.0; /*******************************************************************/ /* Determine what part of this sweep is contained within this */ /* spin period. */ /*******************************************************************/ else { *use_start = 0; *frac = ir_spin_calc_time_frac (spin_btime_yr, spin_btime_day, spin_btime_msec, spin_btime_nsec, spin_etime_yr, spin_etime_day, spin_etime_msec, spin_etime_nsec, *bptr_yr, *bptr_day, *bptr_ms, *bptr_ns, *eptr_yr, *eptr_day, *eptr_ms, *eptr_ns, *use_start); } *index_val = loop; return (1); } } } /***************************************************************************/ /* Start of spin NOT FOUND within this sweep of data. */ /***************************************************************************/ return (0); }