/* * 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: swp_times.c 19959 2008-10-21 19:52:01Z carrie $ SwRI" #include "ret_codes.h" #include "libbase_idfs.h" #include "libVIDF.h" /* for header format comparison */ /**************************************************************************** * * * IR_COMPUTE_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. This is only done when * * pitch angle and/or spacecraft potential computations require the time * * per step values. The only possible flaw to this scheme is that the * * routine is called once for ALL sensors, based upon the fwd flag passed * * to read_drec(). So if each sensor has different timings, this will not * * be taken into account. However, before the code was changed to compute * * the times once to be shared by pitch angle and potential data, the * * existing code for pitch angle and spacecraft potential also had this * * restriction. So this code is consistent with heritage code when pitch * * angle and potential computed the times separately. * * * * INPUT 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 * * SDDAS_USHORT max_ele the number of elements in the sweep * * SDDAS_SHORT sensor the sensor for which data is requested * * * * USAGE * * x = ir_compute_idfs_sweep_times (ex, ptr, max_ele, sensor) * * * * NECESSARY SUBPROGRAMS * * ir_sample_time () returns the time associated with a single * * data sample (row, column) * * * * 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_LONG *time_end loop termination variable * * reg SDDAS_SHORT *s1 fast SDDAS_SHORT pointer looper * * SDDAS_LONG time_accum_ms, acquisition time of a single measurement * * time_accum_ns * * SDDAS_LONG mod_time_ms temporary variable used to compute once * * SDDAS_LONG btime_ms start time of the measurement in milliseconds * * SDDAS_LONG btime_ns start time of the 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 * * * ***************************************************************************/ SDDAS_SHORT ir_compute_idfs_sweep_times (struct experiment_info *ex, struct ptr_rec *ptr, SDDAS_USHORT max_ele, SDDAS_SHORT sensor) { register SDDAS_LONG *bptr_ms, *bptr_ns, *eptr_ms, *eptr_ns, *time_end; register SDDAS_SHORT *s1; SDDAS_LONG time_accum_ms, time_accum_ns, mod_time_ms; 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.*/ /************************************************************************/ 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; } /*******************************************************************/ /* If time advances down the column and the column timing is */ /* sequential, use DA_METHOD to determine start time of sample. */ /*******************************************************************/ base_time_ms = ex->btime_ms % 86400000; base_time_ns = ex->btime_ns; bptr_ms = ex->swp_times.btime_ms; bptr_ns = ex->swp_times.btime_ns; time_end = ex->swp_times.btime_ms + max_ele; 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_ms, ++bptr_ns) { *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; btime_ms += time_accum_ms; btime_ns += 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_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG) (*s1 * time_accum_ms); btime_ns = (SDDAS_LONG) (*s1 * time_accum_ns); *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_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_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } } else { for (; bptr_ms < time_end; ++s1, ++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_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_ms, ++bptr_ns) { *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; btime_ms += time_accum_ms; btime_ns += time_accum_ns; } } /******************************************************************/ /* Make sure nanosecond component is not over one millisecond. */ /******************************************************************/ bptr_ms = ex->swp_times.btime_ms; bptr_ns = ex->swp_times.btime_ns; time_end = ex->swp_times.btime_ns + max_ele; for (; bptr_ns < time_end; ++bptr_ms, ++bptr_ns) { while (*bptr_ns >= 1000000) { ++*bptr_ms; *bptr_ns -= 1000000; } } /*****************************************************************/ /* 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_ms = ex->swp_times.etime_ms; eptr_ns = ex->swp_times.etime_ns; if (max_ele != 1) { bptr_ms = ex->swp_times.btime_ms + 1; bptr_ns = ex->swp_times.btime_ns + 1; time_end = ex->swp_times.btime_ms + max_ele; for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns, ++eptr_ms, ++eptr_ns) { *eptr_ms = *bptr_ms; *eptr_ns = *bptr_ns; } *eptr_ms = ex->etime_ms % 86400000; *eptr_ns = ex->etime_ns; } else { if (ex->da_method == 0) { *eptr_ms = *ex->swp_times.btime_ms + time_accum_ms; *eptr_ns = *ex->swp_times.btime_ns + time_accum_ns; } } ex->swp_times.use_end_yr_day = 0; } else { /****************************************************************/ /* If time advances down the column and the column timing is */ /* parallel, use start time of first element being returned */ /****************************************************************/ eptr_ms = ex->swp_times.etime_ms; eptr_ns = ex->swp_times.etime_ns; ex->swp_times.use_end_yr_day = 1; if (ex->sen_mode == 1 || ex->sen_mode == 3) { mod_time_ms = ex->etime_ms % 86400000; for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns, ++eptr_ms, ++eptr_ns) { *bptr_ms = base_time_ms; *bptr_ns = base_time_ns; *eptr_ms = mod_time_ms; *eptr_ns = ex->etime_ns; } } else { /****************************************************************/ /* Determine the time for the sample being processed. Day */ /* value is not used so no need to check decrement_day flag. */ /****************************************************************/ time_col = ptr->time_col; for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns, ++eptr_ms, ++eptr_ns) { ir_sample_time (max_ele, sensor, time_row, time_col, &btime_ms, &btime_ns, &etime_ms, &etime_ns, &decrement_bday, &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.*/ /************************************************************************/ ex->swp_times.same_times = 1; bptr_ms = ex->swp_times.btime_ms; bptr_ns = ex->swp_times.btime_ns; time_end = ex->swp_times.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) { ex->swp_times.same_times = 0; break; } else if (*bptr_ns != btime_ns) { ex->swp_times.same_times = 0; break; } } return (ALL_OKAY); }