/* * 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 "@(#) spin_swp_times.c 1.3 05/08/19 SwRI" #include "ret_codes.h" #include "libbase_idfs.h" /**************************************************************************** * * * IR_SPIN_SWEEP_TIMES SUBROUTINE * * * * DESCRIPTION * * This routine is called in order to compute the time range for each * * element of the sweep for the parent data set which utilizes a start of * * spin data source to match up spins. This routine is very similar to * * ir_compute_idfs_sweep_times (), except that the year and day of year * * value are also processed for spin determination. * * * * INPUT VARIABLES * * SDDAS_SHORT sensor the sensor for which data is requested * * SDDAS_USHORT max_ele the number of elements in the sweep * * SDDAS_CHAR *same_times flag indicating if the same time range is * * applicable to all steps of the vector * * SDDAS_SHORT base_time_yr, time correction constants * * base_time_day * * 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 * * * * USAGE * * ir_spin_sweep_times (sensor, max_ele, &same_times, base_time_yr, * * base_time_day, &swp_btime_yr, &swp_btime_day, * * &swp_btime_ms, &swp_btime_ns, &swp_etime_yr, * * &swp_etime_day, &swp_etime_ms, &swp_etime_ns) * * * * NECESSARY SUBPROGRAMS * * ir_sample_time () returns the time associated with a single * * data sample (row, column) * * adjust_time () corrects time elements if too many seconds * * (day crossing) or too many days (year xing) * * ir_adjust_year_day () adjust the dayofyear and year values * * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure that holds * * *ex specific experiment information * * struct ptr_rec *ptr a pointer to the structure which holds all * * pointers to the header and data for the * * experiment of interest * * 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_LONG *time_end loop termination variable * * reg SDDAS_SHORT *s1 fast SDDAS_SHORT pointer looper * * 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_FLOAT time_accum_ms, acquisition time of a single measurement * * time_accum_ns * * SDDAS_LONG btime_ms start time of measurement in milliseconds * * SDDAS_LONG btime_ns start time of measurement in nanoseconds * * SDDAS_LONG etime_ms end time of the measurement in milliseconds * * SDDAS_LONG etime_ns end time of the measurement in nanoseconds * * SDDAS_LONG base_time_ms, time correction constant * * base_time_ns * * SDDAS_USHORT time_row the matrix row being processed * * SDDAS_SHORT base_swp_off sweep step offset for 1st element in column * * SDDAS_SHORT time_col the matrix column being processed * * SDDAS_CHAR decrement_bday flag indicating if start day needs to be * * modified (if btime ends up negative) * * SDDAS_CHAR decrement_eday flag indicating if end day needs to be * * modified (if etime ends up negative) * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ void ir_spin_sweep_times (SDDAS_SHORT sensor, SDDAS_USHORT max_ele, SDDAS_CHAR *same_times, SDDAS_SHORT base_time_yr, SDDAS_SHORT base_time_day, 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) { extern struct general_info ginfo; struct experiment_info *ex; struct ptr_rec *ptr; register SDDAS_LONG *bptr_ms, *bptr_ns, *eptr_ms, *eptr_ns, *time_end; register SDDAS_SHORT *s1, *bptr_yr, *bptr_day, *eptr_yr, *eptr_day; SDDAS_FLOAT time_accum_ms, time_accum_ns; SDDAS_LONG btime_ms, etime_ms, btime_ns, etime_ns, base_time_ms, base_time_ns; SDDAS_USHORT time_row; SDDAS_SHORT base_swp_off, time_col; SDDAS_CHAR decrement_bday, decrement_eday; /************************************************************************/ /* We use time_row since we need to pick up the rest of the elements */ /* in that column being processed (for both SEN_MODE = 0 and 4) and */ /* time_row tells us how many have already been processed for that */ /* sensor. Make sure nanosecond component is not over one millisecond.*/ /************************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; time_row = (SDDAS_USHORT) ptr->time_row; time_accum_ms = ex->accum_ms + ex->lat_ms; time_accum_ns = ex->accum_ns + ex->lat_ns; while (time_accum_ns >= 1000000) { ++time_accum_ms; time_accum_ns -= 1000000; } /*******************************************************************/ /* Code for initial time setting copied from read_drec() and */ /* ir_read_drec_times (). */ /*******************************************************************/ base_time_ms = ex->btime_ms % 86400000; base_time_ns = ex->btime_ns; bptr_yr = swp_btime_yr; bptr_day = swp_btime_day; bptr_ms = swp_btime_ms; bptr_ns = swp_btime_ns; time_end = swp_btime_ms + max_ele; /*******************************************************************/ /* If time advances down the column and the column timing is */ /* sequential, use DA_METHOD to determine start time of sample. */ /*******************************************************************/ if (ex->sen_mode == 0 || ex->sen_mode == 2) { /*******************************************************************/ /* DA_METHOD only applies to a vector instrument, not a scalar. */ /*******************************************************************/ if (ex->smp_id != 2) switch (ex->da_method) { case 0: btime_ms = (SDDAS_LONG) (time_row * time_accum_ms); btime_ns = (SDDAS_LONG) (time_row * time_accum_ns); /**********************************************************************/ /* For optimization purposes, it's advised to use ++x instead of x++.*/ /**********************************************************************/ for (; bptr_ms < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; btime_ms += (SDDAS_LONG) time_accum_ms; btime_ns += (SDDAS_LONG) time_accum_ns; } break; case 1: /**********************************************************************/ /* For optimization purposes, it's advised to use ++x instead of x++.*/ /**********************************************************************/ s1 = ptr->hdr_fmt1_ptr->SAMP_INDEX + time_row; for (; bptr_ms < time_end; ++s1, ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG) (*s1 * time_accum_ms); btime_ns = (SDDAS_LONG) (*s1 * time_accum_ns); *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } break; case 2: case 3: /**********************************************************************/ /* For optimization purposes, it's advised to use ++x instead of x++.*/ /**********************************************************************/ s1 = ptr->hdr_fmt1_ptr->SAMP_INDEX + time_row; base_swp_off = *ptr->hdr_fmt1_ptr->SAMP_INDEX; if (*ptr->hdr_fmt1_ptr->SAMP_INDEX > *(ptr->hdr_fmt1_ptr->SAMP_INDEX + 1)) { for (; bptr_ms < time_end; ++s1, ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG)((base_swp_off - *s1) * time_accum_ms); btime_ns = (SDDAS_LONG)((base_swp_off - *s1) * time_accum_ns); *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } } else { for (; bptr_ms < time_end; ++s1, ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG) ((*s1 - base_swp_off) * time_accum_ms); btime_ns = (SDDAS_LONG) ((*s1 - base_swp_off) * time_accum_ns); *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } } break; } else { /***********************************************************************/ /* Basically, same code as da_method = 0 EXCEPT since the time tags */ /* already take into account which row IF a scalar source is stepping */ /* through packed data one sample at a time, no need for btime_ms */ /* factor. */ /***********************************************************************/ btime_ms = 0; btime_ns = 0; /**********************************************************************/ /* For optimization purposes, it's advised to use ++x instead of x++.*/ /**********************************************************************/ for (; bptr_ms < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; btime_ms += (SDDAS_LONG) time_accum_ms; btime_ns += (SDDAS_LONG) time_accum_ns; } } /******************************************************************/ /* Check for valid time elements. */ /******************************************************************/ bptr_yr = swp_btime_yr; bptr_day = swp_btime_day; bptr_ms = swp_btime_ms; bptr_ns = swp_btime_ns; time_end = swp_btime_ns + max_ele; for (; bptr_ns < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns) { /******************************************************************/ /* Make sure nanosecond component is not over one millisecond. */ /******************************************************************/ while (*bptr_ns >= 1000000) { ++*bptr_ms; *bptr_ns -= 1000000; } adjust_time (bptr_yr, bptr_day, bptr_ms, 2); } /*****************************************************************/ /* For a sweeping instrument, the end time of the sample is */ /* equal to the start time of the next sample, except for the */ /* last sample. */ /*****************************************************************/ eptr_yr = swp_etime_yr; eptr_day = swp_etime_day; eptr_ms = swp_etime_ms; eptr_ns = swp_etime_ns; if (max_ele != 1) { bptr_yr = swp_btime_yr + 1; bptr_day = swp_btime_day + 1; bptr_ms = swp_btime_ms + 1; bptr_ns = swp_btime_ns + 1; time_end = swp_btime_ms + max_ele; for (; bptr_ms < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns, ++eptr_yr, ++eptr_day, ++eptr_ms, ++eptr_ns) { *eptr_yr = *bptr_yr; *eptr_day = *bptr_day; *eptr_ms = *bptr_ms; *eptr_ns = *bptr_ns; } /*******************************************************************/ /* Time setting copied from read_drec() and ir_read_drec_times ().*/ /*******************************************************************/ *eptr_yr = *ptr->YEAR; *eptr_day = *ptr->DAYOFYEAR; *eptr_day += ex->etime_ms / 86400000; *eptr_ms = ex->etime_ms % 86400000; *eptr_ns = ex->etime_ns; } else { if (ex->da_method == 0) { *eptr_yr = *swp_btime_yr; *eptr_day = *swp_btime_day; *eptr_ms = *swp_btime_ms + (SDDAS_LONG) time_accum_ms; *eptr_ns = *swp_btime_ns + (SDDAS_LONG) time_accum_ns; } } } else { /****************************************************************/ /* If time advances down the column and the column timing is */ /* parallel, use start time of first element being returned */ /****************************************************************/ eptr_yr = swp_etime_yr; eptr_day = swp_etime_day; eptr_ms = swp_etime_ms; eptr_ns = swp_etime_ns; if (ex->sen_mode == 1 || ex->sen_mode == 3) { /**********************************************************************/ /* For optimization purposes, it's advised to use ++x instead of x++.*/ /**********************************************************************/ for (; bptr_ms < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns, ++eptr_yr, ++eptr_day, ++eptr_ms, ++eptr_ns) { *bptr_yr = base_time_yr; *bptr_day = base_time_day; *bptr_ms = base_time_ms; *bptr_ns = base_time_ns; /*******************************************************************/ /* Time setting copied from read_drec() and ir_read_drec_times ().*/ /*******************************************************************/ *eptr_yr = *ptr->YEAR; *eptr_day = *ptr->DAYOFYEAR; *eptr_day += ex->etime_ms / 86400000; *eptr_ms = ex->etime_ms % 86400000; *eptr_ns = ex->etime_ns; } } else { /****************************************************************/ /* Determine the time for the sample being processed. */ /****************************************************************/ time_col = ptr->time_col; for (; bptr_ms < time_end; ++bptr_yr, ++bptr_day, ++bptr_ms, ++bptr_ns, ++eptr_yr, ++eptr_day, ++eptr_ms, ++eptr_ns) { *bptr_yr = *ptr->YEAR; *bptr_day = *ptr->DAYOFYEAR; *eptr_yr = *ptr->YEAR; *eptr_day = *ptr->DAYOFYEAR; ir_sample_time (max_ele, sensor, time_row, time_col, &btime_ms, &btime_ns, &etime_ms, &etime_ns, &decrement_bday, &decrement_eday); if (decrement_bday) ir_adjust_year_day (bptr_yr, bptr_day, decrement_bday); if (decrement_eday) ir_adjust_year_day (eptr_yr, eptr_day, decrement_eday); *bptr_ms = btime_ms; *bptr_ns = btime_ns; *eptr_ms = etime_ms; *eptr_ns = etime_ns; ++time_row; } } } /************************************************************************/ /* Send back a flag to indicate if the times of each step are the same.*/ /************************************************************************/ *same_times = 1; bptr_ms = swp_btime_ms; bptr_ns = swp_btime_ns; time_end = swp_btime_ms + max_ele; btime_ms = *bptr_ms++; btime_ns = *bptr_ns++; for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns) { if (*bptr_ms != btime_ms) { *same_times = 0; break; } else if (*bptr_ns != btime_ns) { *same_times = 0; break; } } }