/* * 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_disc.c 1.10 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "libtrec_idfs.h" #include "user_defs.h" /**************************************************************************** * * * SWEEP_DISCONTINUOUS_DATA SUBROUTINE * * * * DESCRIPTION * * This routine returns discontinuous 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 sensors * * in the sensor set. Some sensors may have data at the current sweep, * * others may not. The number of sensors being processed is returned to * * the user, along with an array of sensor numbers indicating which sensor * * returns data (-1 indicates no data found,values 0-n are sensor 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 factors are returned to the * * user. For each sensor, there are N many sub-buffers that hold the data * * in each of the data levels requested. This module currently works * * only for discontinuous data with a range of -180 to 180. In practice, * * this module is used in conjunction with sweep_data, which should be set * * up to return the continuous data values and using this module to * * retrieve only the discontinuous data set. In order to do this * * correctly, the user must make use of multiple version numbers so that * * the same data files can have more than one file pointer. That is, use * * one version number for continuous data and one for the discontinuous * * data. * * * * 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_sensors an array holding the sensor number(s) * * for which data is being returned * * SDDAS_FLOAT **ret_data an array holding the data values being * * returned (data for all sensors) * * 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 sweep * * bins (data stored in bin or empty bin) * * SDDAS_SHORT *num_sen the number of sensors processed * * SDDAS_SHORT **num_units array holding the number of data sets * * to bypass to get to the data for the * * specified sensor * * 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_UCHAR exclude_dqual data is to be excluded if the d_qual flag* * for the data is set to the specified * * value * * SDDAS_CHAR *complete_acq flag indicating if all sweeps were * * processed before return from the module * * * * USAGE * * x = sweep_discontinuous_data (data_key, exten, vnum, idf_data_ptr, * * num_swps, &ret_sensors, &ret_data, &ret_frac, &bin_stat, * * &num_sen, &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, * * exclude_dqual, &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_reset_sweep_spin_buffer() resets (reinitializes) buffer information* * ir_disc_memory_setup () allocates all memory that will be needed * * by this module * * ir_get_sweep_discontinuous_data() retrieves the sweeps of data * * ir_transfer_disc_data () transfers discontinuous data from temp. * * data matrices to the appropriate buffers * * * * 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_data *fptr pointer to the fill_data structure being * * processed * * SDDAS_SHORT ret_val the value returned by the called routine * * SDDAS_SHORT send_code status code returned to calling module * * char reset_called flag indicating if LOCATE_EX was called * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT sweep_discontinuous_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_LONG num_swps, SDDAS_SHORT **ret_sensors, SDDAS_FLOAT **ret_data, SDDAS_FLOAT **ret_frac, SDDAS_CHAR **bin_stat, SDDAS_SHORT *num_sen, 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_UCHAR exclude_dqual, SDDAS_CHAR *complete_acq) { extern struct general_info ginfo; struct experiment_info *ex; struct fill_data *fptr; SDDAS_SHORT ret_val, send_code; char reset_called; /***********************************************************************/ /* Check to see if requested combination exists. Since a 0 is passed */ /* for last parameter, the only possible error is that the combo was */ /* not found. */ /***********************************************************************/ *complete_acq = 0; if (!ginfo.called_locate) { ret_val = ir_locate_ex (data_key, exten, vnum, 0); if (ret_val != ALL_OKAY) return (SWEEP_DISC_NOT_FOUND); ginfo.called_locate = 1; reset_called = 1; } else reset_called = 0; ex = ginfo.expt; /**********************************************************************/ /* Set_bin_info MUST be called by the user BEFORE this module can be */ /* called. */ /**********************************************************************/ if (ex->bin_ptr == NO_MEMORY) { if (reset_called) ginfo.called_locate = 0; return (SWEEP_DISC_BIN_MISSING); } /**********************************************************************/ /* Center_and_band_values MUST be called by the user BEFORE this */ /* module can be called IF VARIABLE_SWEEP is selected for binning. */ /**********************************************************************/ if (ex->bin_ptr->swp_type == VARIABLE_SWEEP && ex->bin_ptr->band_low == NO_MEMORY) { if (reset_called) ginfo.called_locate = 0; return (SWEEP_DISC_CENTER_BAND_MISSING); } /**********************************************************************/ /* This routine WILL not process data if dimensions specified are */ /* greater than or equal to PHI. */ /**********************************************************************/ if (ex->collapse_ptr != NO_MEMORY && ex->collapse_ptr->phi_bins != 1) { if (reset_called) ginfo.called_locate = 0; return (SWEEP_DISC_NO_PHI); } /***********************************************************************/ /* Make sure all necessary memory has been allocated before any */ /* processing is attempted. */ /***********************************************************************/ ret_val = ir_disc_memory_setup (reset_called, 1); if (ret_val != ALL_OKAY) return (ret_val); /**********************************************************************/ /* Free data area for this iteration if the previous acquisition was */ /* successful in picking up all requested sweeps. */ /**********************************************************************/ fptr = ex->fill_arrays; if (fptr->buf_stat != NO_MEMORY) return (SWEEP_DISC_WITH_FILL); if (*fptr->bpix == 0) { *fptr->bpix = num_swps; ir_reset_sweep_spin_buffer (); } /***********************************************************************/ /* Pick up the requested number of sweeps. */ /***********************************************************************/ send_code = 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); if (send_code < 0) { if (reset_called) ginfo.called_locate = 0; return (send_code); } /*******************************************************************/ /* 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; fptr = ex->fill_arrays; /****************************************************************/ /* Since the buffer is complete, transfer the data from the */ /* temporary data matrices into the buffer of interest. */ /* Since second argument is -1, no need to worry about usage */ /* of NUM_BUFFERS for indexing in the called module. */ /****************************************************************/ if (*fptr->bpix == 0) { ret_val = ir_transfer_disc_data (0, -1, idf_data_ptr); if (ret_val != ALL_OKAY) return (ret_val); } /*****************************************************************/ /* Compute the time of the last data sample in the data record. */ /*****************************************************************/ *e_time_yr = *fptr->etime_yr; *e_time_day = *fptr->etime_day; *e_time_sec = *fptr->etime_sec; *e_time_nsec = *fptr->etime_nsec; /*********************************************************************/ /* Set pointers to return data, normalization factors, bin status, */ /* and sensors processed to calling routine. */ /*********************************************************************/ *ret_data = fptr->data; *ret_frac = fptr->tot_frac; *bin_stat = fptr->bin_stat; *ret_sensors = fptr->sensors; *num_sen = fptr->sensors_used; *num_units = fptr->num_units; *block_size = ex->bin_ptr->num_bins; if (reset_called) ginfo.called_locate = 0; if (*fptr->bpix == 0) *complete_acq = 1; return (send_code); }