/* * 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 "@(#) get_swp_disc.c 1.9 05/08/19 SwRI" #include "ret_codes.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_GET_SWEEP_DISCONTINUOUS_DATA SUBROUTINE * * * * DESCRIPTION * * This routine retrieves and average NUM_SWPS consecutive data samples * * for all sensors in the sensor set(s) processed for discontinuous data. * * If all NUM_SWPS samples were not available at the current iteration, * * the processing continues as usual, picking up the remainder number of * * sweeps when this module is re-entered. This module currently works * * only for discontinuous data with a range of -180 to 180. * * * * INPUT VARIABLES * * SDDAS_ULONG data_key key which uniquely identifies the data * * set being processed * * SDDAS_CHAR *exten filename extension of data to be used * * SDDAS_USHORT vnum version number associated with this * * combination (allows for multiple opens) * * void *idf_data_ptr ptr to memory location for structure that* * holds returned data values (read_drec) * * SDDAS_LONG num_swps the number of sweeps to retrieve * * SDDAS_SHORT *s_time_yr the start year associated with the first * * sweep processed * * SDDAS_SHORT *s_time_day the start day associated with the first * * sweep processed * * SDDAS_LONG *s_time_sec the start time associated with the first * * sweep processed (in seconds) * * SDDAS_LONG *s_time_nsec the start time associated with the first * * sweep processed (residual in nanoseconds)* * SDDAS_CHAR *hdr_change flag indicating a header change occurred * * SDDAS_UCHAR exclude_dqual data is to be excluded if the d_qual flag* * for the data is set to the specified * * value * * SDDAS_CHAR reset_called flag indicating if LOCATE_EX was called * * * * USAGE * * x=ir_get_sweep_discontinuous_data(data_key, exten, vnum, idf_data_ptr,* * num_swps, &s_time_yr, &s_time_day, &s_time_sec, * * &s_time_nsec, &hdr_change, exclude_dqual, reset_called) * * * * NECESSARY SUBPROGRAMS * * read_drec () universal read routine that retrieves * * data for the time sample being processed * * ir_process_sweep_discontinuous_data() processes the discontinuous data* * for the sensor * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concern- * * ing experiment that is being processed * * SDDAS_CHAR ir_reset_sensors flag indicating if a new header was read,* * in which case, new sensors may be * * returned * * SDDAS_CHAR ir_block_adv flag indicating if time advancement * * should be blocked * * * * 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 holding * * *ex specific experiment information * * struct ptr_rec *ptr a pointer to structure which holds all * * pointers to the header and data for the * * experiment of interest * * struct fill_data *fptr pointer to the fill_data structure being * * processed * * register SDDAS_SHORT *s1 pointer to the sensor values * * register SDDAS_SHORT *s_beg pointer to the first sensor value * * register SDDAS_SHORT *s_end pointer to the last sensor value * * SDDAS_SHORT ret_val the value returned by the called routine * * SDDAS_SHORT send_code status code returned to calling module * * SDDAS_SHORT read_code status code returned from READ_DREC() * * SDDAS_SHORT sensor sensor for which data is to be retrieved * * SDDAS_CHAR fwd flag indicating when to advance to the * * time sample * * SDDAS_CHAR found_data flag indicating if data was returned for * * requested sensor * * SDDAS_CHAR recalc_swp recalculate sweep values flag * * SDDAS_CHAR set_time flag specifying when to save the time * * char more_data terminate data processing flag * * char first_time flag indicating first sweep processed * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_get_sweep_discontinuous_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_LONG num_swps, SDDAS_SHORT *s_time_yr, SDDAS_SHORT *s_time_day, SDDAS_LONG *s_time_sec, SDDAS_LONG *s_time_nsec, SDDAS_CHAR *hdr_change, SDDAS_UCHAR exclude_dqual, SDDAS_CHAR reset_called) { extern struct general_info ginfo; extern SDDAS_CHAR ir_reset_sensors, ir_block_adv; struct idf_data *EXP_DATA; struct experiment_info *ex; struct ptr_rec *ptr; struct fill_data *fptr; register SDDAS_SHORT *s1, *s_beg, *s_end; SDDAS_SHORT ret_val, send_code = ALL_OKAY, read_code, sensor; SDDAS_CHAR fwd, found_data, recalc_swp, set_time; char more_data = 1, first_time = 1; /***********************************************************************/ /* Set pointers to the correct data set. */ /***********************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; fptr = ex->fill_arrays; EXP_DATA = (struct idf_data *) idf_data_ptr; *hdr_change = 0; recalc_swp = 1; /***********************************************************************/ /* Pick up the requested number of sweeps. */ /***********************************************************************/ while (more_data) { /********************************************************************/ /* Loop over those sensors contained within the current sensor set. */ /********************************************************************/ s1 = ptr->SENSOR_INDEX; s_beg = ptr->SENSOR_INDEX; s_end = ptr->SENSOR_INDEX + *ptr->N_SEN - 1; for (; s1 <= s_end; ++s1) { /******************************************************************/ /* Advance to the next data set only if the last sensor is */ /* being processed to ensure all samples which occur at the same */ /* time are processed simultaneously. */ /******************************************************************/ sensor = *s1; fwd = (s1 == s_end) ? 1 : 0; set_time = (s1 == s_beg && *fptr->bpix == num_swps) ? 1 : (s1 == s_beg) ? 2 : 0; ir_block_adv = 1; read_code = read_drec (data_key, exten, vnum, idf_data_ptr, sensor, fwd, 0); ir_block_adv = 0; /*******************************************************************/ /* Be sure to reset ex structure after calling read_drec() since */ /* VIDF file crossing means a reallocation of the existing ex */ /* structures so address may change (do this regardless of code). */ /*******************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; fptr = ex->fill_arrays; if (EXP_DATA->hdr_change) { *hdr_change = 1; recalc_swp = 1; } /******************************************************************/ /* Header changed at top of read_drec since data and/or header */ /* record was missing at time of last access (real-time). Break */ /* out to get a possible new set of sensors. */ /******************************************************************/ if (ir_reset_sensors) break; /******************************************************************/ /* Last sensor in the sensor set? If so, one more sweep has */ /* been processed. */ /******************************************************************/ if (s1 == s_end) --*fptr->bpix; /*****************************************************************/ /* If an error was encountered, return to the calling routine. */ /*****************************************************************/ if (read_code < 0) { if (reset_called) ginfo.called_locate = 0; return (read_code); } /******************************************************************/ /* If no more data is forthcoming or if the next file needs to */ /* be opened, simply return the status code and have the caller */ /* call the module to open the next set of files, if need be. */ /* When this module is re-entered, the processing continues as */ /* usual, picking up the remainder number of sweeps. */ /******************************************************************/ else if ((read_code == LOS_STATUS || read_code == NEXT_FILE_STATUS) && !EXP_DATA->filled_data) { more_data = 0; send_code = read_code; break; } /******************************************************************/ /* If the first sensor returned EOF status and there are more */ /* than one sensor in the set, all will return EOF since no */ /* advancement (fwd) till the last sensor. If only one sensor, */ /* go ahead and plot this data. */ /******************************************************************/ else if (s1 == s_beg && fwd == 0 && (read_code == DREC_EOF_SENSOR || read_code == DREC_EOF_NO_SENSOR)) { more_data = 0; send_code = EOF_STATUS; break; } found_data = (read_code == DREC_NO_SENSOR || read_code == DREC_EOF_NO_SENSOR || EXP_DATA->d_qual == exclude_dqual || !EXP_DATA->filled_data) ? 0 : 1; ret_val = ir_process_sweep_discontinuous_data (sensor, found_data, recalc_swp, idf_data_ptr, set_time); if (ret_val != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /*************************************************************/ /* Retrieve the start time for the first sweep processed. */ /*************************************************************/ if (first_time) { first_time = 0; *s_time_yr = *fptr->btime_yr; *s_time_day = *fptr->btime_day; *s_time_sec = *fptr->btime_sec; *s_time_nsec = *fptr->btime_nsec; } /******************************************************************/ /* EOF was encountered for last sensor in sensor set. */ /******************************************************************/ if ((read_code == DREC_EOF_SENSOR || read_code == DREC_EOF_NO_SENSOR) && s1 == s_end) { more_data = 0; send_code = EOF_STATUS; break; } else if (read_code == LOS_STATUS || read_code == NEXT_FILE_STATUS) { more_data = 0; send_code = read_code; break; } recalc_swp = 0; } /*****************************************************************/ /* Have the number of sweeps been read and processed? */ /*****************************************************************/ if (*fptr->bpix == 0) more_data = 0; } return (send_code); }