/* * 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_mode.c 1.9 05/08/19 SwRI" #include "ret_codes.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_GET_SWEEP_MODE_DATA SUBROUTINE * * * * DESCRIPTION * * This routine retrieves and averages NUM_SWPS consecutive data samples * * for all requested mode values. 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 the module is re-entered.* * * * 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 * * 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_CHAR reset_called flag indicating if LOCATE_EX was called * * * * USAGE * * x = ir_get_sweep_mode_data (data_key, exten, idf_data_ptr, num_swps, * * &s_time_yr, &s_time_day, &s_time_sec, &s_time_nsec,* * &hdr_change, reset_called) * * * * NECESSARY SUBPROGRAMS * * read_drec () universal read routine that retrieves * * data for the time sample being processed * * ir_process_sweep_mode_data () processes the data for all requested * * mode values * * * * 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_mode *mptr pointer to the fill_mode structure being * * processed * * register SDDAS_SHORT loop looping variable * * SDDAS_USHORT vnum version number to be associated with this* * combination (allows for multiple opens) * * 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 set_time flag specifying when to save the time * * char more_data terminate data processing flag * * of data * * char first_time flag indicating first sweep processed * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_get_sweep_mode_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, 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_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_mode *mptr; register SDDAS_SHORT loop; SDDAS_USHORT vnum; SDDAS_SHORT ret_val, send_code = ALL_OKAY, read_code, sensor; SDDAS_CHAR set_time; char more_data = 1, first_time = 1; /***********************************************************************/ /* Set pointers to the correct data set. */ /***********************************************************************/ ex = ginfo.expt; vnum = ex->version; ptr = ex->info_ptr; mptr = ex->mode_arrays; EXP_DATA = (struct idf_data *) idf_data_ptr; *hdr_change = 0; /***********************************************************************/ /* Pick up the requested number of sweeps. */ /***********************************************************************/ while (more_data) { /********************************************************************/ /* Since all modes are returned with one call to read_drec(), just */ /* use the first sensor in the sensor set and advance in time. */ /* Left the FOR loop in for the sake of utilizing BREAK statements. */ /********************************************************************/ for (loop = 0; loop < 1; ++loop) { sensor = *ptr->SENSOR_INDEX; set_time = (*mptr->bpix == num_swps) ? 1 : 0; ir_block_adv = 1; read_code = read_drec (data_key, exten, vnum, idf_data_ptr, sensor, 1, 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; mptr = ex->mode_arrays; if (EXP_DATA->hdr_change) *hdr_change = 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; --*mptr->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. Since we */ /* are using the 1st sensor in the set, EXP_DATA.filled_data */ /* should always be set to 1 unless LOS_STATUS/NEXT_FILE_STATUS */ /* was encountered on header/data record access. */ /******************************************************************/ else if ((read_code == LOS_STATUS || read_code == NEXT_FILE_STATUS) && !EXP_DATA->filled_data) { more_data = 0; send_code = read_code; break; } ret_val = ir_process_sweep_mode_data (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 = *mptr->btime_yr; *s_time_day = *mptr->btime_day; *s_time_sec = *mptr->btime_sec; *s_time_nsec = *mptr->btime_nsec; } /******************************************************************/ /* EOF was encountered on advancement. */ /******************************************************************/ if (read_code == DREC_EOF_SENSOR || read_code == DREC_EOF_NO_SENSOR) { 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; } } /*****************************************************************/ /* Have the number of sweeps been read and processed? */ /*****************************************************************/ if (*mptr->bpix == 0) more_data = 0; } return (send_code); }