/* * 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 19949 2008-10-15 19:59:53Z carrie $ SwRI" #include #include "ret_codes.h" #include "libtrec_idfs.h" /**************************************************************************** * * * 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 vector data set being processed. * * * * INPUT VARIABLES * * void *idf_data_ptr ptr to memory location for the structure * * that holds returned data values (read_drec) * * SDDAS_SHORT sensor the sensor being processed * * 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 * * * * USAGE * * x = ir_compute_sweep_times (idf_data_ptr, sensor, &use_end_yr_day, * * &same_times) * * * * NECESSARY SUBPROGRAMS * * ir_sample_time () returns the time associated with a single * * data sample (row, column) * * sizeof () the size of the specified object in bytes * * realloc() reallocates previously allocated memory * * * * EXTERNAL VARIABLES * * struct general_info structure holding information concerning * * ginfo experiment that is being processed * * SDDAS_UINT ir_tmp_bytes number of bytes allocated for scratch space * * void *ir_tmp_space scratch space for various uses * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure that holds all of the currently * * returned data values to be processed * * struct experiment_info a pointer to the structure holding specific * * *ex 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 * * register SDDAS_LONG *l1 fast long pointer looper * * SDDAS_FLOAT time_accum_ms, acquisition time of a single measurement * * time_accum_ns * * SDDAS_LONG btime_ms start time of the measurement in milliseconds * * SDDAS_LONG etime_ms end time of the measurement in milliseconds * * SDDAS_LONG btime_ns start time of the measurement in nanoseconds * * SDDAS_LONG etime_ns end time of the measurement in nanoseconds * * SDDAS_LONG base_time_ms, time correction constant * * base_time_ns * * SDDAS_LONG base_swp_off sweep step offset for first element in column * * 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 offset offset value to get to the data of interest * * SDDAS_USHORT time_row the matrix row being processed * * SDDAS_USHORT max_ele the number of elements in the sweep * * 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) * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * void *tmp_ptr pointer which holds address passed back by * * the call to the REALLOC routine * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_compute_sweep_times (void *idf_data_ptr, SDDAS_SHORT sensor, SDDAS_CHAR *use_end_yr_day, SDDAS_CHAR *same_times) { extern struct general_info ginfo; extern SDDAS_UINT ir_tmp_bytes; extern void *ir_tmp_space; struct idf_data *EXP_DATA; struct experiment_info *ex; struct ptr_rec *ptr; register SDDAS_LONG *bptr_ms, *bptr_ns, *eptr_ms, *eptr_ns, *time_end; register SDDAS_LONG *l1; 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_LONG base_swp_off, max_size_slong; SDDAS_LONG *tmp_btime_ms, *tmp_btime_ns, *tmp_etime_ms, *tmp_etime_ns, offset; SDDAS_USHORT time_row, max_ele; SDDAS_CHAR decrement_bday, decrement_eday; size_t bytes, num_bytes_slong; void *tmp_ptr; EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; ptr = ex->info_ptr; max_ele = EXP_DATA->num_sample; /********************************************************************/ /* Allocate space to save the start/stop time component for each */ /* sample. Cannot assume that the start of B = the end of A since */ /* timing may be parallel down the column so need start and stop. */ /* The 4 represents two start and two stop arrays since use nano. */ /* This is a reusable scratch space. */ /********************************************************************/ num_bytes_slong = sizeof (SDDAS_LONG); bytes = num_bytes_slong * 4 * max_ele; if (bytes > ir_tmp_bytes) { if ((tmp_ptr = realloc (ir_tmp_space, bytes)) == NULL) return (SWP_TIMES_TMP_MALLOC); ir_tmp_space = tmp_ptr; ir_tmp_bytes = (SDDAS_UINT) bytes; } /* Cast pointer to char * since void * and offset is in bytes. */ max_size_slong = num_bytes_slong * max_ele; 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); /************************************************************************/ /* 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. It should always be zero for a sweeping instrument. 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. */ /* Use EXP_DATA->bmilli and EXP_DATA->bnano since we are at the */ /* sweep of interest. */ /*******************************************************************/ base_time_ms = EXP_DATA->bmilli % 86400000; base_time_ns = EXP_DATA->bnano; bptr_ms = tmp_btime_ms; bptr_ns = tmp_btime_ns; time_end = tmp_btime_ms + max_ele; if (ex->sen_mode == 0 || ex->sen_mode == 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 (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns) { *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: l1 = EXP_DATA->swp_data + time_row; for (; bptr_ms < time_end; ++l1, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG) (*l1 * time_accum_ms); btime_ns = (SDDAS_LONG) (*l1 * time_accum_ns); *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } break; case 2: case 3: l1 = EXP_DATA->swp_data + time_row; base_swp_off = *EXP_DATA->swp_data; if (*EXP_DATA->swp_data > *(EXP_DATA->swp_data + 1)) { for (; bptr_ms < time_end; ++l1, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG)((base_swp_off - *l1) * time_accum_ms); btime_ns = (SDDAS_LONG)((base_swp_off - *l1) * time_accum_ns); *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } } else { for (; bptr_ms < time_end; ++l1, ++bptr_ms, ++bptr_ns) { btime_ms = (SDDAS_LONG) ((*l1 - base_swp_off) * time_accum_ms); btime_ns = (SDDAS_LONG) ((*l1 - base_swp_off) * time_accum_ns); *bptr_ms = btime_ms + base_time_ms; *bptr_ns = btime_ns + base_time_ns; } } break; } /******************************************************************/ /* Make sure nanosecond component is not over one millisecond. */ /******************************************************************/ while (*tmp_btime_ns >= 1000000) { ++*tmp_btime_ms; *tmp_btime_ns -= 1000000; } /*****************************************************************/ /* The end time of the sample is equal to the start time of the */ /* next sample, except for the last sample. Make sure */ /* nanosecond component is not over one millisecond. */ /*****************************************************************/ eptr_ms = tmp_etime_ms; eptr_ns = tmp_etime_ns; bptr_ms = tmp_btime_ms + 1; bptr_ns = tmp_btime_ns + 1; time_end = tmp_btime_ms + max_ele; for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns, ++eptr_ms, ++eptr_ns) { while (*bptr_ns >= 1000000) { ++*bptr_ms; *bptr_ns -= 1000000; } *eptr_ms = *bptr_ms; *eptr_ns = *bptr_ns; } *eptr_ms = EXP_DATA->emilli % 86400000; *eptr_ns = EXP_DATA->enano; *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 = tmp_etime_ms; eptr_ns = tmp_etime_ns; *use_end_yr_day = 1; if (ex->sen_mode == 1 || ex->sen_mode == 3) { 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 = EXP_DATA->emilli % 86400000; *eptr_ns = EXP_DATA->enano; } } else { /****************************************************************/ /* Determine the time for the sample being processed. */ /* Do not worry about negative times since calling module will */ /* adjust times when using each step. */ /****************************************************************/ for (; bptr_ms < time_end; ++bptr_ms, ++bptr_ns, ++eptr_ms, ++eptr_ns) { ir_sample_time (max_ele, sensor, time_row, ptr->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.*/ /************************************************************************/ *same_times = 1; bptr_ms = tmp_btime_ms; bptr_ns = tmp_btime_ns; time_end = tmp_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; } } return (ALL_OKAY); }