/* * 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 "@(#) fill_mode.c 1.23 05/08/19 SwRI" #include "ret_codes.h" #include "gen_defs.h" #include "libtrec_idfs.h" #include "user_defs.h" /**************************************************************************** * * * FILL_MODE_DATA SUBROUTINE * * * * DESCRIPTION * * This routine returns instrument status (mode) data that is associated * * with a scalar and/or a sweeping instrument, time rectified. That is, * * given a specified time duration (time per pixel) and a base pixel, this * * routine will return data and pixel locations for the data 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). * * Upon return to this module all data buffers that should have been * * processed by the calling module are reset and reused. The data * * returned has not been normalized, the normalization factor is returned * * to the user. For each mode, there are NUM_BUFFER (5) buffers that hold * * the data. To indicate which data set is ready to be plotted, a status * * flag for each buffer is passed back to the calling module - BUFFER_READY* * indicates data is ready to be plotted and PARTIAL_WORKING indicates * * fill routine needs to continue processing this data set. In addition, * * 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_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_LONG **bpix an array holding the starting pixel * * location for each data value returned * * SDDAS_LONG **epix an array holding the ending pixel * * location for each data value returned * * SDDAS_CHAR **ret_stat an array holding the buffer status flags * * 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 an array holding the start year for each * * data value returned * * SDDAS_SHORT **s_time_day an array holding the start day for each * * data value returned * * SDDAS_LONG **s_time_sec an array holding the start time for each * * data value returned (in seconds) * * SDDAS_LONG **s_time_nsec an array holding the start time for each * * data value returned (nanosecond residual)* * SDDAS_SHORT **e_time_yr an array holding the stop year for each * * data value returned * * SDDAS_SHORT **e_time_day an array holding the stop day for each * * data value returned * * SDDAS_LONG **e_time_sec an array holding the stop time for each * * data value returned (in seconds) * * SDDAS_LONG **e_time_nsec an array holding the stop time for each * * data value returned (nanosecond residual)* * 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 * * * * USAGE * * x = fill_mode_data (data_key, exten, vnum, idf_data_ptr, &ret_modes, * * &ret_data, &ret_frac, &bin_stat, &bpix, &epix, * * &ret_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, exclude_dqual) * * * * 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_mode_info () allocates space needed to hold the info * * that is being returned by this module * * ir_reset_mode_buffers () resets (reinitializes) buffer information* * read_drec () universal read routine that retrieves * * data for the time sample being processed * * ir_set_mode_buffer_status () resets buffer status flags when pertinent* * ir_process_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 new_vnum version number to be associated with this* * combination (allows for multiple opens) * * SDDAS_FLOAT save_frac[] array that holds the fractions associated* * with the pixel information * * SDDAS_LONG save_info[] array that holds the pixel start, stop * * and time values * * 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 more_data terminate data processing flag * * of data * * SDDAS_CHAR last_buf the last buffer processed (0 - 4) * * char reset_called flag indicating if LOCATE_EX was called * * char chk_reset flag indicating if the sensors need to * * be reset since header changed * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT fill_mode_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, SDDAS_SHORT **ret_modes, SDDAS_FLOAT **ret_data, SDDAS_FLOAT **ret_frac, SDDAS_CHAR **bin_stat, SDDAS_LONG **bpix, SDDAS_LONG **epix, SDDAS_CHAR **ret_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_UCHAR exclude_dqual) { extern struct general_info ginfo; extern 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 new_vnum; SDDAS_FLOAT save_frac[3]; SDDAS_LONG save_info[6]; SDDAS_SHORT ret_val, send_code = ALL_OKAY, read_code, sensor; SDDAS_CHAR more_data = 1, last_buf; char reset_called, chk_reset; /***********************************************************************/ /* Retrieve the ex structure requested by the user and then point to */ /* the ex structure which holds mode-relevant information. */ /***********************************************************************/ if (!ginfo.called_locate) { ret_val = ir_locate_ex (data_key, exten, vnum, 0); if (ret_val != ALL_OKAY) return (FILL_MODE_NOT_FOUND); /************************************************************************/ /* User did not call file_open requesting mode data? */ /************************************************************************/ ex = ginfo.expt; if (ex->mode_version == ex->version) return (FILL_MODE_FILE_OPEN); new_vnum = ex->mode_version; ret_val = ir_locate_ex (data_key, exten, new_vnum, 0); if (ret_val != ALL_OKAY) return (FILL_MODE_INFO_DUP); ginfo.called_locate = 1; reset_called = 1; } else reset_called = 0; /***********************************************************************/ /* Set pointers to the correct data set. */ /***********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; ptr = ex->info_ptr; *hdr_change = 0; /*************************************************************************/ /* 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 (MODES_NOT_REQUESTED); /***********************************************************************/ /* Set_time_values MUST be called by the user BEFORE fill_mode_data */ /* can be called. */ /***********************************************************************/ if (ex->time_values.base_year == 0) { if (reset_called) ginfo.called_locate = 0; return (FILL_MODE_BASE_TIME_MISSING); } /***********************************************************************/ /* 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. */ /***********************************************************************/ mptr = ex->mode_arrays; if (mptr->base == NO_MEMORY) { if ((ret_val = ir_alloc_mode_info ()) != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } } else if (mptr->buf_stat == NO_MEMORY) return (FILL_WITH_SWEEP_MODE); /**********************************************************************/ /* Free up any buffers that can be utilized this iteration. */ /**********************************************************************/ ir_reset_mode_buffers (); last_buf = -1; /***********************************************************************/ /* Keep processing data until the amount of time asked for has been */ /* accumulated. */ /***********************************************************************/ 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. */ /********************************************************************/ new_vnum = ex->version; chk_reset = 0; for (loop = 0; loop < 1; ++loop) { sensor = *ptr->SENSOR_INDEX; ir_block_adv = 1; read_code = read_drec (data_key, exten, new_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) { chk_reset = 1; break; } /*****************************************************************/ /* 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, terminate the partial working */ /* buffer for all modes that have been processed. Since we are */ /* using the first sensor in the sensor set, EXP_DATA.filled_data*/ /* should always be set to 1 unless LOS_STATUS encountered on */ /* header/data record access. */ /*****************************************************************/ else if (read_code == LOS_STATUS && !EXP_DATA->filled_data) { more_data = 0; ir_set_mode_buffer_status (); send_code = read_code; break; } /******************************************************************/ /* If the next file needs to be opened, have the caller plot the */ /* full buffers (if any) and call the module to open the next set */ /* of files. When this module is re-entered, the previous */ /* working buffer stays the current working buffer and processing */ /* continues as usual. Since we are using the first sensor in */ /* the sensor set, EXP_DATA.filled_data should always be set to 1 */ /* unless NEXT_FILE_STATUS encountered on record access. */ /******************************************************************/ else if (read_code == NEXT_FILE_STATUS && !EXP_DATA->filled_data) { more_data = 0; send_code = read_code; break; } /******************************************************************/ /* If the EXP_DATA was not refilled by read_drec, typically */ /* because of EOF conditions, EXP_DATA holds data that is NOT */ /* pertinent to the current data set. */ /******************************************************************/ else if (data_key != EXP_DATA->data_key) { more_data = 0; send_code = read_code; break; } ret_val = ir_process_mode_data (&more_data, mptr->start_buf, &last_buf, save_info, save_frac, idf_data_ptr); if (ret_val != ALL_OKAY && ret_val != NO_EMPTY_BUFFERS) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /******************************************************************/ /* EOF was encountered on advancement. */ /******************************************************************/ if (read_code == DREC_EOF_SENSOR || read_code == DREC_EOF_NO_SENSOR) { more_data = 0; send_code = read_code; break; } else if (read_code == LOS_STATUS) { more_data = 0; ir_set_mode_buffer_status (); send_code = read_code; break; } else if (read_code == NEXT_FILE_STATUS) { more_data = 0; send_code = read_code; break; } } if (!chk_reset && last_buf != -1) mptr->start_buf = last_buf; } /*****************************************************************/ /* Compute the time of the last data sample in the data record. */ /*****************************************************************/ last_buf = (*(mptr->buf_stat + mptr->start_buf) == BUFFER_READY) ? mptr->start_buf : mptr->start_buf - 1; if (last_buf < 0) last_buf = NUM_BUFFERS - 1; /*********************************************************************/ /* Set pointers to the time range associated with each buffer. */ /*********************************************************************/ *s_time_yr = mptr->btime_yr; *s_time_day = mptr->btime_day; *s_time_sec = mptr->btime_sec; *s_time_nsec = mptr->btime_nsec; *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, bin status, start pixel, stop pixel, */ /* buffer status and modes processed to calling routine. */ /*********************************************************************/ *ret_data = mptr->data; *ret_frac = mptr->tot_frac; *bin_stat = mptr->bin_stat; *bpix = mptr->bpix; *epix = mptr->epix; *ret_stat = mptr->buf_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; return (send_code); }