/* * 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 "@(#) sweep_mode.c 1.11 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "libtrec_idfs.h" /**************************************************************************** * * * SWEEP_MODE_DATA SUBROUTINE * * * * DESCRIPTION * * This routine returns instrument status (mode) data that is associated * * with a scalar and/or a sweeping instrument, sample averaged. That is, * * this routine will average NUM_SWPS consecutive data samples for all * * requested mode values. The number of modes being processed is returned * * to the user, along with an array of mode numbers indicating which mode * * returns data (-1 indicates no data found, values 0-n are mode numbers). * * If all NUM_SWPS samples were acquired on the previous call to this * * routine, all data buffers are reset; otherwise, the data buffers are * * preserved and data acquisition continues. The data that is returned * * has not been normalized, the normalization factor are returned to the * * user. For each mode, there are N many sub-buffers that hold the data * * in each of the data levels requested. * * * * 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 **ret_modes an array holding the mode number(s) for * * which data is being returned * * SDDAS_FLOAT **ret_data an array holding the data values being * * returned (data for all modes) * * SDDAS_FLOAT **ret_frac an array holding the normalization * * factors to be applied to the data values * * SDDAS_CHAR **bin_stat array holding the status of the bins * * (data stored in bin or empty bin) * * SDDAS_SHORT *num_modes the number of modes processed * * SDDAS_SHORT **num_units array holding the number of data sets * * to bypass to get to the data for the * * specified mode * * SDDAS_SHORT *block_size max. number of elements in the data set * * (used for indexing into data array) * * 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_SHORT *e_time_yr the stop year associated with the last * * sweep processed * * SDDAS_SHORT *e_time_day the stop day associated with the last * * sweep processed * * SDDAS_LONG *e_time_sec the stop time associated with the last * * sweep processed (in seconds) * * SDDAS_LONG *e_time_nsec the stop time associated with the last * * sweep processed (residual in nanoseconds)* * SDDAS_CHAR *hdr_change flag indicating a header change occurred * * SDDAS_CHAR *complete_acq flag indicating if all sweeps were * * processed before return from the module * * * * USAGE * * x = sweep_mode_data (data_key, exten, vnum, idf_data_ptr, num_swps, * * &ret_modes, &ret_data, &ret_frac, &bin_stat, * * &num_modes, &num_units, &block_size, &s_time_yr, * * &s_time_day, &s_time_sec, &s_time_nsec, * * &e_time_yr, &e_time_day, &e_time_sec, * * &e_time_nsec, &hdr_change, &complete_acq) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if requested combination has * * already been processed and points to the * * correct structure allocated for combo * * ir_alloc_mode_arrays () allocates structure(s) utilized by this * * module, one per experiment_info structure* * ir_alloc_sweep_mode_info () allocates space needed to hold the info * * that is being returned by this module * * ir_reset_sweep_mode_buffer() resets (reinitializes) buffer information* * ir_get_sweep_mode_data() retrieves the sweeps of mode data * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concern- * * ing experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure holding * * *ex specific experiment information * * struct fill_mode *mptr pointer to the fill_mode structure being * * processed * * SDDAS_USHORT mode_vnum version number for mode data associated * * with this combination * * SDDAS_SHORT ret_val the value returned by the called routine * * char reset_called flag indicating if LOCATE_EX was called * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT sweep_mode_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_LONG num_swps, SDDAS_SHORT **ret_modes, SDDAS_FLOAT **ret_data, SDDAS_FLOAT **ret_frac, SDDAS_CHAR **bin_stat, SDDAS_SHORT *num_modes, SDDAS_SHORT **num_units, SDDAS_SHORT *block_size, SDDAS_SHORT *s_time_yr, SDDAS_SHORT *s_time_day, SDDAS_LONG *s_time_sec, SDDAS_LONG *s_time_nsec, SDDAS_SHORT *e_time_yr, SDDAS_SHORT *e_time_day, SDDAS_LONG *e_time_sec, SDDAS_LONG *e_time_nsec, SDDAS_CHAR *hdr_change, SDDAS_CHAR *complete_acq) { extern struct general_info ginfo; struct experiment_info *ex; struct fill_mode *mptr; SDDAS_SHORT ret_val; SDDAS_USHORT mode_vnum; char reset_called; /***********************************************************************/ /* Retrieve the ex structure requested by the user and then point to */ /* the ex structure which holds mode-relevant information. */ /***********************************************************************/ *complete_acq = 0; if (!ginfo.called_locate) { ret_val = ir_locate_ex (data_key, exten, vnum, 0); if (ret_val != ALL_OKAY) return (SWEEP_MODE_NOT_FOUND); /************************************************************************/ /* User did not call file_open requesting mode data? */ /************************************************************************/ ex = ginfo.expt; if (ex->mode_version == ex->version) return (SWEEP_MODE_FILE_OPEN); mode_vnum = ex->mode_version; ret_val = ir_locate_ex (data_key, exten, mode_vnum, 0); if (ret_val != ALL_OKAY) return (SWEEP_MODE_INFO_DUP); ginfo.called_locate = 1; reset_called = 1; } else reset_called = 0; ex = ginfo.expt; /*************************************************************************/ /* A call to FILL_MODE_INFO was not made for this combination. If the */ /* data_name is an empty string, the data base did not have data for */ /* the virtual and experiment in question. */ /*************************************************************************/ if (ex->num_mode_info == 0 && ex->data_name[0] != '\0') return (SWEEP_MODES_NOT_REQUESTED); /***********************************************************************/ /* Allocate a fill_mode structure for the data set being processed */ /* if the memory has yet to be allocated. */ /***********************************************************************/ if (ex->bmem.base_mode_arrays == NO_MEMORY) if ((ret_val = ir_alloc_mode_arrays ()) != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /***********************************************************************/ /* Allocate the space needed to hold the information for processing if */ /* the memory for this particular combination has yet to be allocated. */ /* Since SWEEP_MODE_DATA and FILL_MODE_DATA use the same structures, */ /* the two cannot be used in conjunction on the same ex structure. */ /***********************************************************************/ mptr = ex->mode_arrays; if (mptr->base == NO_MEMORY) { if ((ret_val = ir_alloc_sweep_mode_info ()) != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } } else if (mptr->buf_stat != NO_MEMORY) return (SWEEP_MODE_WITH_FILL); /**********************************************************************/ /* Free data area for this iteration if the previous acquisition was */ /* successful in picking up all requested sweeps. */ /**********************************************************************/ if (*mptr->bpix == 0) { *mptr->bpix = num_swps; ir_reset_sweep_mode_buffer (); } /***********************************************************************/ /* Pick up the requested number of sweeps. */ /***********************************************************************/ ret_val = 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); if (ret_val < 0) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /*******************************************************************/ /* Be sure to reset ex structure since module calls read_drec() */ /* and VIDF file crossing may cause a reallocation of the existing */ /* ex structures so address may change. */ /*******************************************************************/ ex = ginfo.expt; mptr = ex->mode_arrays; /*****************************************************************/ /* Compute the time of the last data sample in the data record. */ /*****************************************************************/ *e_time_yr = *mptr->etime_yr; *e_time_day = *mptr->etime_day; *e_time_sec = *mptr->etime_sec; *e_time_nsec = *mptr->etime_nsec; /*********************************************************************/ /* Set pointers to return data, normalization factors, bin status */ /* and modes processed to calling routine. */ /*********************************************************************/ *ret_data = mptr->data; *ret_frac = mptr->tot_frac; *bin_stat = mptr->bin_stat; *ret_modes = mptr->modes; *block_size = 1; *num_units = mptr->num_units; *num_modes = ex->num_mode_info; if (reset_called) ginfo.called_locate = 0; if (*mptr->bpix == 0) *complete_acq = 1; return (ret_val); }