/* * 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 "@(#) $Id: set_spin_etime.c 21638 2011-12-01 22:09:59Z carrie $ SwRI" #include "ret_codes.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_SET_SPIN_END_TIME_PERIOD SUBROUTINE * * * * DESCRIPTION * * This routine is called to determine the end time for the spin being * * processed. The first version of the spin software would return the * * end time of the last sweep included in the spin. But utilizing the * * stopping element location and the percentage of the data to include * * results in a more accurate time tag. There is still a one nanosecond * * rounding error that exists. * * * * INPUT VARIABLES * * SDDAS_SHORT sensor sensor being processed * * SDDAS_USHORT stop_ele element number within the sweep where the * * spin stops for the sensor in question * * SDDAS_FLOAT stop_ele_frac the percentage of the spin period covered * * by element flagged as the end of spin * * void *idf_data_ptr ptr to memory location for the structure * * that holds returned data values (read_drec)* * * * USAGE * * x = ir_set_spin_end_time_period (sensor, stop_ele, stop_ele_frac, * * idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_compute_sweep_times () computes the time range for each element * * of the sweep for the vector data set * * sizeof () the size of the specified object in bytes * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concerning * * the experiment that is being processed * * void *ir_tmp_space scratch space for various uses * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure holding all of the currently * * returned data values to be processed * * struct experiment_info a pointer to the structure that holds * * *ex specific experiment information * * struct fill_data *fptr pointer to the fill_data structure being * * processed * * SDDAS_DOUBLE diff_samp time duration in seconds of the step * * SDDAS_DOUBLE add_sec_frac the number of seconds to add to the start * * time of step being processed (floating pt.)* * SDDAS_LONG offset offset value to get to the data of interest* * SDDAS_LONG add_sec the number of seconds to add to the start * * time of step being processed (integer) * * SDDAS_LONG add_nsec the number of nanoseconds to add to start * * time of step being processed (integer) * * SDDAS_LONG max_size_slong number of bytes needed for NUM_BUFFER * * elements which are SDDAS_LONG data types * * SDDAS_LONG *tmp_btime_ms, pointers to the start time memory locations* * *tmp_btime_ns * * SDDAS_LONG *tmp_etime_ms, pointers to the end time memory locations * * *tmp_etime_ns * * SDDAS_LONG btime_ms start time of the step in milliseconds * * SDDAS_LONG btime_ns start time of the step in nanoseconds * * SDDAS_LONG etime_ms end time of the step in milliseconds * * SDDAS_LONG etime_ns end time of the step in nanoseconds * * SDDAS_LONG diff_milli the time of day duration for the step * * SDDAS_LONG diff_nano the time of day residual duration for step * * SDDAS_SHORT rval holds values returned various routines * * SDDAS_SHORT diff_year the year duration for the step * * SDDAS_SHORT diff_day the day duration for the step * * SDDAS_SHORT days_in_yr the number of day in the year - takes leap * * year into account * * SDDAS_CHAR use_end_yr_day flag indicating if end year/day values are * * to be used * * SDDAS_CHAR same_times flag indicating if the same time range is * * applicable to all steps of the vector * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_set_spin_end_time_period (SDDAS_SHORT sensor, SDDAS_USHORT stop_ele, SDDAS_FLOAT stop_ele_frac, void *idf_data_ptr) { extern struct general_info ginfo; extern void *ir_tmp_space; struct idf_data *EXP_DATA; struct experiment_info *ex; struct fill_data *fptr; SDDAS_DOUBLE diff_samp, add_sec_frac; SDDAS_LONG offset, add_sec, add_nsec, max_size_slong; SDDAS_LONG *tmp_btime_ms, *tmp_btime_ns, *tmp_etime_ms, *tmp_etime_ns; SDDAS_LONG btime_ms, btime_ns, etime_ms, etime_ns, diff_milli, diff_nano; SDDAS_SHORT rval, diff_year, diff_day, days_in_yr; SDDAS_CHAR use_end_yr_day, same_times; /***********************************************************************/ /* Save the end time associated with this spin. */ /***********************************************************************/ ex = ginfo.expt; fptr = ex->fill_arrays; EXP_DATA = (struct idf_data *) idf_data_ptr; /***********************************************************************/ /* Compute the times for each step in the vector and get the time of */ /* the step being processed. */ /***********************************************************************/ rval = ir_compute_sweep_times (idf_data_ptr, sensor, &use_end_yr_day, &same_times); if (rval != ALL_OKAY) return (rval); max_size_slong = sizeof (SDDAS_LONG) * EXP_DATA->num_sample; tmp_btime_ms = (SDDAS_LONG *) ir_tmp_space; offset = max_size_slong; tmp_btime_ns = (SDDAS_LONG *) ((SDDAS_CHAR *) ir_tmp_space + offset); offset += max_size_slong; tmp_etime_ms = (SDDAS_LONG *) ((SDDAS_CHAR *) ir_tmp_space + offset); offset += max_size_slong; tmp_etime_ns = (SDDAS_LONG *) ((SDDAS_CHAR *) ir_tmp_space + offset); etime_ms = *(tmp_etime_ms + stop_ele); btime_ms = *(tmp_btime_ms + stop_ele); etime_ns = *(tmp_etime_ns + stop_ele); btime_ns = *(tmp_btime_ns + stop_ele); /***********************************************************************/ /* Determine the time duration for the step being processed. */ /***********************************************************************/ diff_year = EXP_DATA->eyear - EXP_DATA->byear; diff_day = EXP_DATA->eday - EXP_DATA->bday; diff_milli = etime_ms - btime_ms; diff_nano = etime_ns - btime_ns; if (diff_nano < 0) { --diff_milli; diff_nano += 1000000; /* 1 milli = 1000000 nano */ } /******************************************************************/ /* 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 * 86400) + diff_day * 86400 + (diff_milli / 1000.0) + (diff_nano / 1000000000.0); /******************************************************************/ /* Unlike start time setting, use stop_ele_frac in all cases to */ /* determine how much time to add since the additional time is */ /* added to the START TIME of the sample. */ /******************************************************************/ add_sec_frac = diff_samp * stop_ele_frac; add_sec = (SDDAS_LONG) add_sec_frac; add_nsec = (add_sec_frac - add_sec) * 1000000000; *fptr->etime_sec = ((btime_ms + (btime_ns / 1000000)) / 1000) + add_sec; *fptr->etime_nsec = (btime_ms % 1000) * 1000000 + btime_ns + add_nsec; *fptr->etime_yr = (use_end_yr_day) ? EXP_DATA->eyear : EXP_DATA->byear; *fptr->etime_day = (use_end_yr_day) ? EXP_DATA->eday: EXP_DATA->bday; return (ALL_OKAY); }