/* * 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 "@(#) get_spin_data.c 1.3 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "libtrec_idfs.h" #include "libbase_idfs.h" /**************************************************************************** * * * IR_GET_SPIN_DATA SUBROUTINE * * * * DESCRIPTION * * This routine retrieves a spin's worth of data for all sensors * * processed. * * * * 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) * * SDDAS_CHAR *hdr_change flag indicating a header change occurred * * SDDAS_CHAR reset_called flag indicating if LOCATE_EX was called * * SDDAS_CHAR process_pixel flag indicating if pixel information is * * to be defined * * * * USAGE * * x = ir_get_spin_data (data_key, exten, vnum, &hdr_change, * * reset_called, process_pixel) * * * * NECESSARY SUBPROGRAMS * * read_drec_spin () universal read routine that retrieves * * data for the time sample being processed * * ir_process_spin_data () processes the data for the sensor * * ir_find_pixel () returns the pixel a given time period is * * associated with * * locate_ex_ptr() returns pointer to the correct structure * * allocated for requested IDFS combination * * * * 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 idf_data *EXP_DATA structure that holds all of the currently* * returned data values to be processed * * struct fill_data *fptr pointer to the fill_data structure being * * processed * * struct start_spin_info *sptr a pointer to structure which holds all * * spin info. for sensor being processed * * reg SDDAS_SHORT loop_sen looping variable over sensor * * SDDAS_FLOAT frac fraction of the data associated with * * time's pixel location * * SDDAS_FLOAT start_ele_frac the percentage of the spin period covered* * by element flagged as the start of spin * * SDDAS_FLOAT stop_ele_frac the percentage of the spin period covered* * by element flagged as the end of spin * * SDDAS_LONG num_sweeps number of sweeps contained within spin * * SDDAS_LONG rec_bgn_sec starting time of the spin being processed* * SDDAS_LONG rec_bgn_nsec starting time of the spin (nanoseconds) * * SDDAS_LONG rec_end_sec ending time of the spin being processed * * SDDAS_LONG rec_end_nsec ending time of the spin (nanoseconds) * * SDDAS_LONG ldummy dummy placeholder for long parameter * * SDDAS_USHORT start_ele element number within the sweep where the* * spin starts for the sensor in question * * SDDAS_USHORT stop_ele element number within the sweep where the* * spin stops for the sensor in question * * SDDAS_SHORT ret_val the value returned by the called routine * * SDDAS_SHORT byr, bday start year/day for spin being checked * * SDDAS_SHORT eyr, eday end year/day for spin being checked * * SDDAS_SHORT time_index index to get to the timing structure for * * the sensor being processed * * SDDAS_SHORT sdummy dummy placeholder for short parameter * * SDDAS_CHAR set_time flag specifying when to save the time * * void **data_arrays array of addresses for the idf_data * * structures utilized by the sensor to * * acquire a full spin * * void *idf_data_ptr ptr to memory location for structure that* * holds returned data values (read_drec) * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_get_spin_data (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, SDDAS_CHAR *hdr_change, SDDAS_CHAR reset_called, SDDAS_CHAR process_pixel) { extern struct general_info ginfo; struct experiment_info *ex; struct idf_data *EXP_DATA; struct fill_data *fptr; struct start_spin_info *sptr; register SDDAS_SHORT loop_sen; SDDAS_FLOAT frac, start_ele_frac, stop_ele_frac; SDDAS_LONG num_sweeps, rec_bgn_sec, rec_bgn_nsec, rec_end_sec, rec_end_nsec; SDDAS_LONG ldummy; SDDAS_USHORT start_ele, stop_ele; SDDAS_SHORT ret_val, byr, bday, eyr, eday, time_index, sdummy; SDDAS_CHAR set_time; void **data_arrays, *idf_data_ptr; /***********************************************************************/ /* Retrieve and process the spin for the controller. */ /***********************************************************************/ ex = ginfo.expt; *hdr_change = 0; ret_val = read_drec_spin (data_key, exten, vnum, ex->spin_sen_ctrl, &start_ele, &start_ele_frac, &stop_ele, &stop_ele_frac, &num_sweeps, &data_arrays); if (ret_val < 0) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /************************************************************************/ /* Point back to master ex structure since read_drec_spin leaves it at */ /* ex structure for last sensor processed in the spin. */ /************************************************************************/ ginfo.expt = locate_ex_ptr (data_key, exten, vnum); ex = ginfo.expt; fptr = ex->fill_arrays; set_time = 1; ret_val = ir_process_spin_data (ex->spin_sen_ctrl, set_time, hdr_change, start_ele, start_ele_frac, stop_ele, stop_ele_frac, num_sweeps, data_arrays); if (ret_val != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } if (process_pixel) { time_index = (ex->all_or_one) ? ex->spin_sen_ctrl : 0; *fptr->bpix = ir_find_pixel (*fptr->btime_yr, *fptr->btime_day, *fptr->btime_sec, *fptr->btime_nsec, &frac, LEADING_EDGE, &sdummy, &sdummy, &ldummy, &ldummy, time_index); *fptr->epix = ir_find_pixel (*fptr->etime_yr, *fptr->etime_day, *fptr->etime_sec, *fptr->etime_nsec, &frac, TRAILING_EDGE, &sdummy, &sdummy, &ldummy, &ldummy, time_index); } /********************************************************************/ /* Loop over all IDFS sensors, skipping the controller. */ /********************************************************************/ set_time = 0; sptr = ex->start_sptr; for (loop_sen = 0; loop_sen < ex->num_sensor; ++loop_sen, ++sptr) { /************************************************************************/ /* Skip over any sensor not selected for processing and the controller.*/ /************************************************************************/ if (*(ex->sensors_needed + loop_sen) == 0) continue; if (loop_sen == ex->spin_sen_ctrl) continue; /***********************************************************************/ /* The start of spin was not found by start_of_spin() so skip. */ /***********************************************************************/ if (sptr->skip == sTrue) continue; /***********************************************************************/ /* Retrieve the spin for the sensor? */ /***********************************************************************/ if (sptr->next_spin) { ret_val = read_drec_spin (data_key, exten, vnum, loop_sen, &start_ele, &start_ele_frac, &stop_ele, &stop_ele_frac, &num_sweeps, &data_arrays); if (ret_val < 0) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /************************************************************************/ /* Point back to master ex structure since read_drec_spin leaves it at */ /* ex structure for last sensor processed in the spin. */ /************************************************************************/ ginfo.expt = locate_ex_ptr (data_key, exten, vnum); ex = ginfo.expt; fptr = ex->fill_arrays; sptr = ex->start_sptr; } else { data_arrays = sptr->data_ptr; start_ele_frac = sptr->last_spin_start_ele_frac; start_ele = sptr->last_spin_start_ele; stop_ele_frac = sptr->stop_ele_frac; stop_ele = sptr->spin_stop_ele; num_sweeps = sptr->num_sweeps; } /***********************************************************************/ /* Make sure start time of current spin is within the time period */ /* of the controller; otherwise, walk-up by reading another spin or */ /* hold off and save spin for next time. */ /***********************************************************************/ idf_data_ptr = *(data_arrays + 0); EXP_DATA = (struct idf_data *) idf_data_ptr; byr = EXP_DATA->byear; bday = EXP_DATA->bday; rec_bgn_sec = EXP_DATA->bsec; rec_bgn_nsec = EXP_DATA->bnsec; idf_data_ptr = *(data_arrays + num_sweeps - 1); EXP_DATA = (struct idf_data *) idf_data_ptr; eyr = EXP_DATA->eyear; eday = EXP_DATA->eday; rec_end_sec = EXP_DATA->esec; rec_end_nsec = EXP_DATA->ensec; /***********************************************************************/ /* The start time of the current spin is AFTER the end time of the */ /* controller, so just hold on to the data for next time. */ /***********************************************************************/ if (byr == *fptr->etime_yr) { if ((bday > *fptr->etime_day) || (bday == *fptr->etime_day && rec_bgn_sec > *fptr->etime_sec) || (bday == *fptr->etime_day && rec_bgn_sec == *fptr->etime_sec && rec_bgn_nsec > *fptr->etime_nsec)) { sptr->next_spin = 0; continue; } } else if (byr > *fptr->etime_yr) { sptr->next_spin = 0; continue; } /***********************************************************************/ /* The end time of the current spin is BEFORE the start time of the */ /* controller, so need to process sensor again to get the next spin. */ /***********************************************************************/ else if (eyr == *fptr->btime_yr) { if ((eday < *fptr->btime_day) || (eday == *fptr->btime_day && rec_end_sec < *fptr->btime_sec) || (eday == *fptr->btime_day && rec_end_sec == *fptr->btime_sec && rec_end_nsec < *fptr->btime_nsec)) { --loop_sen; --sptr; sptr->next_spin = 1; continue; } } else if (eyr < *fptr->btime_yr) { --loop_sen; --sptr; sptr->next_spin = 1; continue; } /***********************************************************************/ /* Spin must be between controller's time interval so process. */ /***********************************************************************/ ret_val = ir_process_spin_data (loop_sen, set_time, hdr_change, start_ele, start_ele_frac, stop_ele, stop_ele_frac, num_sweeps, data_arrays); if (ret_val != ALL_OKAY) { if (reset_called) ginfo.called_locate = 0; return (ret_val); } /***********************************************************************/ /* This spin has been processed so set flag so new read is performed */ /* next time for this sensor. */ /***********************************************************************/ sptr->next_spin = 1; } return (ALL_OKAY); }