/* * 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 "@(#) spin_data_pix.c 1.3 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libtrec_idfs.h" /**************************************************************************** * * * SPIN_DATA_PIXEL SUBROUTINE * * * * DESCRIPTION * * This routine returns a full spin's worth of data that is associated * * with a scalar and/or a sweeping instrument. That is, this routine will * * summate over all sweeps that are associated with the current spin for * * all sensors. All sensors that have been selected for processing are * * processed. Although a full spin of data is the emphasis, not a given * * time interval as with fill_data(), there is still the need to utilize * * some form of time control. Therefore, the sensor selected as the * * controller through the call to start_of_spin() will serve as the time * * manager and all sensors that have a start of spin time WITHIN the time * * interval of the controller's spin will be returned as a group. * * The sensors that return data for the current spin are 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).* * A full spin is always returned; therefore, the user MUST extract the * * data upon return from this module since all data buffers are reset * * upon re-entry. The data that is returned has not been normalized, the * * normalization factors are returned to the user. There are N many * * sub-buffers that hold the data in each of the data levels requested. * * In addition, this module is meant to work with graphics applications * * that are time-oriented along the x-axis; therefore, a start and stop * * pixel is returned indicating at which pixel location the spin is * * located along the pixel axis, which is scaled with respect to time. * * * * 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_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_LONG **bpix pointer to the starting pixel location * * for the spin * * SDDAS_LONG **epix pointer to the ending pixel location for * * the spin * * 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 pointer to start year for start of spin * * SDDAS_SHORT **s_time_day pointer to start day for start of spin * * SDDAS_LONG **s_time_sec pointer to start time for start of spin * * SDDAS_LONG **s_time_nsec pointer to start time for start of spin * * (residual in nanoseconds) * * SDDAS_SHORT **e_time_yr pointer to stop year for start of spin * * SDDAS_SHORT **e_time_day pointer to stop day for start of spin * * SDDAS_LONG **e_time_sec pointer to stop time for start of spin * * SDDAS_LONG **e_time_nsec pointer to stop time for start of spin * * (residual in nanoseconds) * * SDDAS_CHAR *hdr_change flag indicating a header change occurred * * * * USAGE * * x = spin_data_pixel(data_key, exten, vnum, idf_data_ptr, &ret_sensors,* * &ret_data, &ret_frac, &bin_stat, &bpix, &epix, &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) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if requested combination has * * already been processed and points to the * * correct structure allocated for combo * * ir_alloc_fill_arrays () allocates structure(s) utilized by this * * module, one per experiment_info structure* * ir_alloc_spin_info () allocates space needed to hold the info * * that is being returned by this module * * ir_reset_sweep_spin_buffer() resets (reinitializes) buffer information* * ir_clear_phi_bins() clears out all the phi bins * * ir_get_spin_data() retrieves the spin of 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_data *fptr pointer to the fill_data structure being * * processed * * struct ptr_rec *ptr a pointer to the structure which holds * * all pointers to the header and data for * * the experiment of interest * * SDDAS_SHORT rval the value returned by the called routine * * SDDAS_CHAR cur_buf the buffer being processed (0 - 4) * * char reset_called flag indicating if LOCATE_EX was called * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT spin_data_pixel (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_SHORT **ret_sensors, SDDAS_FLOAT **ret_data, SDDAS_FLOAT **ret_frac, SDDAS_CHAR **bin_stat, SDDAS_LONG **bpix, SDDAS_LONG **epix, 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) { extern struct general_info ginfo; struct experiment_info *ex; struct fill_data *fptr; struct ptr_rec *ptr; SDDAS_SHORT rval; SDDAS_CHAR cur_buf; 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. */ /***********************************************************************/ if (!ginfo.called_locate) { rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (SPIN_DATA_PIX_NOT_FOUND); ginfo.called_locate = 1; reset_called = 1; } else reset_called = 0; ex = ginfo.expt; ptr = ex->info_ptr; /***********************************************************************/ /* The instrument is not spinning - therefore, no spin processing. */ /***********************************************************************/ if (*ptr->SPIN == 0) { if (reset_called) ginfo.called_locate = 0; return (SPIN_DATA_PIX_NO_SPIN); } /***********************************************************************/ /* Allocate a fill_data structure for the data set being processed */ /* if the memory has yet to be allocated. */ /***********************************************************************/ if (ex->bmem.base_fill_arrays == NO_MEMORY) if ((rval = ir_alloc_fill_arrays ()) != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } /**********************************************************************/ /* Set_bin_info MUST be called by the user BEFORE spin_data_pixel */ /* can be called. */ /**********************************************************************/ if (ex->bin_ptr == NO_MEMORY) { if (reset_called) ginfo.called_locate = 0; return (SPIN_DATA_PIX_BIN_MISSING); } /**********************************************************************/ /* Center_and_band_values MUST be called by the user BEFORE */ /* spin_data_pixel 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 (SPIN_DATA_PIX_CENTER_BAND_MISSING); } /***********************************************************************/ /* Allocate the space needed to hold the information for processing if */ /* the memory for this particular combination has yet to be allocated. */ /***********************************************************************/ fptr = ex->fill_arrays; if (fptr->base == NO_MEMORY) { if ((rval = ir_alloc_spin_info (1)) != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (rval); } } /***********************************************************************/ /* First conditional implies fill_data () has been called; second */ /* condition implies that sweep_data() has been called. */ /***********************************************************************/ else if (fptr->buf_stat != NO_MEMORY || fptr->epix == NO_MEMORY) return (SPIN_DATA_PIX_WITH_FILL_SWEEP); /************************************************************************/ /* If phi collapsing is enabled and there is no interleaving, clear out */ /* all phi column(s) before processing data associated with this call. */ /************************************************************************/ ir_reset_sweep_spin_buffer (); if (ex->collapse_ptr != NO_MEMORY) { for (cur_buf = 0; cur_buf < NUM_BUFFERS; ++cur_buf) { ex->collapse_ptr->filled_phi_matrix[(SDDAS_SHORT)cur_buf] = 0; ex->collapse_ptr->add_phi_matrix[(SDDAS_SHORT) cur_buf] = 0; } /**************************************************************************/ /* Only one buffer is utilized; therefore, no need to set add_phi_matrix */ /* flag since following code only clears if interleave is off. */ /**************************************************************************/ cur_buf = 0; if (ex->collapse_ptr->phi_bins != 1 && !ex->collapse_ptr->interleave) ir_clear_phi_bins (cur_buf); } /***********************************************************************/ /* Pick up a full spin for all sensors to be processed. */ /***********************************************************************/ rval = ir_get_spin_data (data_key, exten, vnum, hdr_change, reset_called, 1); if (rval < 0) { if (reset_called) ginfo.called_locate = 0; return (rval); } /*******************************************************************/ /* 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. Set the time of the first*/ /* and last data sample for the controller's spin. */ /*******************************************************************/ ex = ginfo.expt; fptr = ex->fill_arrays; *s_time_yr = fptr->btime_yr; *s_time_day = fptr->btime_day; *s_time_sec = fptr->btime_sec; *s_time_nsec = fptr->btime_nsec; *e_time_yr = fptr->etime_yr; *e_time_day = fptr->etime_day; *e_time_sec = fptr->etime_sec; *e_time_nsec = fptr->etime_nsec; *bpix = fptr->bpix; *epix = fptr->epix; /*********************************************************************/ /* 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; return (rval); }