/* * 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 "@(#) read_drec_spin.c 1.9 05/08/19 SwRI" #include "gen_defs.h" #include "ret_codes.h" #include "libVIDF.h" #include "libbase_idfs.h" /******************************************************************************* * * * READ_DREC_SPIN SUBROUTINE * * * * DESCRIPTION * * This routine will return a full spin of data for the sensor specified * * for the data set of interest. This routine MUST be called after the * * start_of_spin module has been called. * * * * INPUT VARIABLES * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_CHAR *exten the filename extension for the data to be used * * SDDAS_USHORT vnum version number to be associated with this * * combination (allows for multiple opens) * * SDDAS_SHORT sensor sensor value of interest * * SDDAS_USHORT *start_ele element number within the sweep where the spin * * starts for the sensor in question * * SDDAS_FLOAT *start_frac the percentage of the spin period covered * * by element flagged as the start of spin * * SDDAS_USHORT *stop_ele element number within the sweep where the spin * * stops for the sensor in question * * SDDAS_FLOAT *stop_frac the percentage of the spin period covered * * by element flagged as the end of spin * * SDDAS_LONG *num_sweeps the number of sweeps contained within the spin * * void ***data_arrays pointer to the array of addresses for idf_data * * structures utilized by the sensor to acquire * * the full spin * * * * USAGE * * x = read_drec_spin (data_key, exten, vnum, sensor, &start_ele, * * &start_frac, &stop_ele, &stop_frac, &num_sweeps, * * &data_arrays) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * ir_start_element_of_spin () return element number within sweep at which * * start of spin for the sensor specified was found* * ir_read_drec_spin_angle () gathers a spin's worth of data using the * * angular method * * ir_read_drec_spin_src () gathers a spin's worth of data using the spin * * periods defined by the start of spin data source* * * * EXTERNAL VARIABLES * * struct general_info structure that holds information concerning * * ginfo the experiment that is being processed * * * * INTERNAL VARIABLES * * struct idf_data structure holding all of the currently * * *EXP_DATA returned data values to be processed * * struct experiment_info a pointer to the structure that holds specific * * *ex experiment information * * struct start_spin_info *sptr a pointer to the structure which holds all * * spin information for the sensor being processed * * reg SDDAS_LONG loop_index looping variable * * SDDAS_FLOAT start_gap stop azimuthal angle value for last spin that * * was flagged as a partial spin due to data gap * * SDDAS_FLOAT stop_gap start azimuthal angle value for first sweep in * * the current spin being processed * * SDDAS_SHORT rval value returned by called module * * SDDAS_SHORT spin_method method to use to determine start of spin * * SDDAS_SHORT spin_code holds value returned by called module * * void *data_ptr1, ptr to the memory location for the structure * * *data_ptr2 that holds returned data values * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT read_drec_spin (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, SDDAS_SHORT sensor, SDDAS_USHORT *start_ele, SDDAS_FLOAT *start_frac, SDDAS_USHORT *stop_ele, SDDAS_FLOAT *stop_frac, SDDAS_LONG *num_sweeps, void ***data_arrays) { extern struct general_info ginfo; struct idf_data *EXP_DATA; struct experiment_info *ex; struct start_spin_info *sptr; register SDDAS_LONG loop_index; SDDAS_FLOAT start_gap, stop_gap; SDDAS_SHORT rval, spin_method, spin_code; /* Leave variables as is */ void *data_ptr1, *data_ptr2; /***************************************************************************/ /* DO NOT UTILIZE the reset_called speed-up scheme because it causes */ /* problems. Initialize num_sweeps to 0 in case a partial spin is */ /* encountered (next set of data files are not available). */ /***************************************************************************/ *num_sweeps = 0; rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (READ_SPIN_NOT_FOUND); /***************************************************************************/ /* Set a pointer to the structure which holds all pointers for header and */ /* data information for the experiment currently being processed. */ /* START_OF_SPIN () was not called for this data set? */ /***************************************************************************/ ex = ginfo.expt; if (ex->bmem.base_start_spin_info == NO_MEMORY) return (READ_SPIN_NO_START); /***************************************************************************/ /* Multi-dimensional data must be handled by start_of_spin_tensor(). */ /***************************************************************************/ if (ex->header_format != ORIGINAL_HEADER) return (WRONG_HEADER_FORMAT); /***************************************************************************/ /* This module is ALWAYS at the start of spin, either by being called */ /* AFTER start_of_spin() or by the previous call to this module finding */ /* the end of the previous spin. */ /***************************************************************************/ rval = ir_start_element_of_spin (data_key, exten, vnum, sensor, start_ele); if (rval != ALL_OKAY) return (rval); spin_method = ex->spin_method; sptr = ex->start_sptr + sensor; if (!sptr->first_spin) { /***********************************************************************/ /* Need to swap the address of the last structure into the first */ /* structure since the last structure holds the sweep that terminated */ /* the prior spin and belongs to this spin and by swapping, cut down */ /* on the number of allocated data structures (re-use). */ /***********************************************************************/ --sptr->data_index; data_ptr1 = *(sptr->data_ptr + 0); data_ptr2 = *(sptr->data_ptr + sptr->data_index); *(sptr->data_ptr + 0) = data_ptr2; *(sptr->data_ptr + sptr->data_index) = data_ptr1; /***********************************************************************/ /* Last sweep was a partial due to a data gap. Check to see if this */ /* next sweep is also a partial or reset to say it is complete. */ /* Need to do this BEFORE data structures from last spin are cleared. */ /***********************************************************************/ if (spin_method == ANGLE_CALC && sptr->partial_spin) { /****************************************************************************/ /* Since void pointer, make sure correct type of data structure being used.*/ /* Data structures define the same elements at the beginning of the */ /* structure definition. */ /****************************************************************************/ EXP_DATA = (struct idf_data *) data_ptr2; if (EXP_DATA->header_format != ORIGINAL_HEADER) return (WRONG_DATA_STRUCTURE); start_gap = sptr->last_swp_last_step_az; stop_gap = EXP_DATA->start_az[0]; if (start_gap > stop_gap) { /*********************************************************************/ /* Did we find the cross over angle value? */ /*********************************************************************/ if (start_gap <= sptr->azimuthal_cross_over || sptr->azimuthal_cross_over <= stop_gap) sptr->partial_spin = 0; } /********************************************************************/ /* Angle is between end of last sweep and start of new sweep found */ /* AFTER the previous partial spin so start of new spin is found. */ /********************************************************************/ else if (start_gap <= sptr->azimuthal_cross_over && sptr->azimuthal_cross_over <= stop_gap) sptr->partial_spin = 0; } /***********************************************************************/ /* Initialize flag to say nothing placed in data structure. */ /***********************************************************************/ for (loop_index = 1; loop_index <= sptr->data_index; ++loop_index) { data_ptr1 = *(sptr->data_ptr + loop_index); /****************************************************************************/ /* Since void pointer, make sure correct type of data structure being used.*/ /* Data structures define the same elements at the beginning of the */ /* structure definition. */ /****************************************************************************/ EXP_DATA = (struct idf_data *) data_ptr1; if (EXP_DATA->header_format != ORIGINAL_HEADER) return (WRONG_DATA_STRUCTURE); EXP_DATA->filled_data = 0; } sptr->data_index = 1; } if (spin_method == ANGLE_CALC) spin_code = ir_read_drec_spin_angle (data_key, exten, vnum, sensor, start_ele, start_frac, stop_ele, stop_frac, num_sweeps); else spin_code = ir_read_drec_spin_src (data_key, exten, vnum, sensor, start_ele, start_frac, stop_ele, stop_frac, num_sweeps); if (spin_code != ALL_OKAY && spin_code != READ_SPIN_TERMINATE && spin_code != READ_SPIN_PARTIAL && spin_code != READ_SPIN_DATA_GAP) return (spin_code); /***************************************************************************/ /* The data_arrays argument MUST be 3 pointer references (stars) since */ /* one pointer reference (star) is needed to pass back the address of the */ /* variable that is a double pointer variable (sptr->data_ptr). */ /***************************************************************************/ sptr->first_spin = 0; *data_arrays = sptr->data_ptr; *stop_ele = sptr->spin_stop_ele; *num_sweeps = sptr->num_sweeps; /**************************************************************************/ /* Profiling showed this module called, so no need for conditional test. */ /**************************************************************************/ rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (READ_SPIN_NOT_FOUND); return (spin_code); }