/* * 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 "@(#) start_spin.c 1.14 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * START_OF_SPIN SUBROUTINE * * * * DESCRIPTION * * This routine will find the start of spin for the data set of interest. * * This routine should be called AFTER file_pos has been called. This ensures* * that the record with the time closest to the user-requested start time has * * been found. From that point, the start of spin is searched for. The * * start of spin is found for each individual sensor that is to be processed. * * This is necessary since angle is based upon time and each sensor can have * * a different time_off value which could result in slightly different times. * * This routine will not work for IDFS multi-dimensional data (tensor). An * * equivalent module exists for tensor data. * * * * 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 spin_sen_ctrl sensor which serves as controller for timing * * relating to full spins * * SDDAS_SHORT etime_yr the stop time requested (year component) * * SDDAS_SHORT etime_day the stop time requested (day component) * * SDDAS_LONG etime_sec the stop time requested (seconds component) * * SDDAS_LONG etime_nsec the stop time requested (nanoseconds) * * * * USAGE * * x = start_of_spin (data_key, exten, vnum, spin_sen_ctrl, etime_yr, * * etime_day, etime_sec, etime_nsec) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if the requested combination has * * already been processed and points to the * * correct structure allocated for the combo * * malloc() allocates memory * * sizeof () the size of the specified object in bytes * * free () frees previously allocated memory * * free_version_info () frees allocated experiment_info structures * * tagged with the specified version number * * file_open() opens the necessary header, data, and VIDF files* * for the requested data set * * file_pos() positions the data/header files for the data * * source at the desired start time * * get_version_number () returns the next available version number * * ir_sensor_start_of_spin_angle () finds start of spin for sensor of * * interest using angular information * * ir_sensor_start_of_spin_src () finds start of spin for sensor of * * interest using time period of spin data source * * ir_init_sensor_spin_struct () initializes the newly allocated structure * * which hold all spin info for each sensor that * * is processed * * ir_alloc_spin_sweep_times () allocates space to hold time per step * * create_idf_data_structure () creates an instance of the idf_data * * structure that holds data returned by read_drec * * read_drec() the universal read routine that retrieves * * the data for the time sample being processed * * adjust_time () corrects time elements if too many seconds * * (day crossing) or too many days(year crossing) * * * * 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 idf_data structure holding the data for the start of * * *SPIN_SRC_DATA spin data source * * struct experiment_info a pointer to the structure that holds specific * * *ex, *new_ex experiment information * * struct ptr_rec *ptr a pointer to the structure which holds all * * pointers to the header and data for the * * experiment of interest * * struct start_spin_info *sptr a pointer to the structure which holds all * * spin information for the sensor being processed * * struct spin_src_info a pointer to the structure that holds * * *spin_src_ptr start of spin data source information * * reg SDDAS_SHORT loop_sen looping variable over sensor * * reg SDDAS_SHORT loop_index looping variable * * SDDAS_FLOAT start_frac the percentage of the spin period covered * * by the current sample * * SDDAS_LONG btime_sec user-requested start time * * SDDAS_LONG btime_nsec user-requested start time * * SDDAS_USHORT found_ele element within the sweep at which spin started * * SDDAS_USHORT new_vnum version number for sensors to be processed * * SDDAS_SHORT rval value returned by called module * * SDDAS_SHORT btime_yr user-requested start time * * SDDAS_SHORT btime_day user-requested start time * * SDDAS_SHORT spin_method method to use to determine start of spin * * SDDAS_SHORT num_requested no. of sensors processed for start of spin * * SDDAS_SHORT num_skip no. of sensors that could not find start of spin* * SDDAS_SHORT good_sensor last sensor start of spin could be found * * SDDAS_BOOL return_pitch_angles flag indicating whether pitch angle data * * is to be computed and returned or not * * SDDAS_BOOL return_euler_angles flag indicating whether euler angle data * * is to be computed and returned or not * * SDDAS_BOOL return_celestial_pos flag indicating whether celestial * * position data is to be computed and returned * * SDDAS_CHAR process_mode_data flag indicating if mode data is being * * processed for the data set in question * * size_t bytes the number of bytes to allocate * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT start_of_spin (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, SDDAS_SHORT spin_sen_ctrl, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec) { extern struct general_info ginfo; struct idf_data *EXP_DATA, *SPIN_SRC_DATA; struct experiment_info *ex, *new_ex; struct ptr_rec *ptr; struct start_spin_info *sptr; struct spin_src_info *spin_src_ptr; register SDDAS_SHORT loop_sen, loop_index; SDDAS_FLOAT start_frac; SDDAS_LONG btime_sec, btime_nsec; SDDAS_USHORT found_ele, new_vnum; SDDAS_SHORT rval, btime_yr, btime_day, spin_method, num_requested, num_skip; SDDAS_SHORT good_sensor; SDDAS_BOOL return_pitch_angles, return_euler_angles, return_celestial_pos; SDDAS_CHAR process_mode_data; /* Leave variables as is. */ size_t bytes; void *tmp_ptr, *idf_data_ptr; /**************************************************************************/ /* Check to see if the combination being processed has been processed */ /* before. If not, an error condition - probably didn't call FILE_OPEN. */ /* Since a 0 is passed for the last parameter, the only possible error is*/ /* that the requested combination was not found among processed combos. */ /* Do not utilize internal reset_called flag since file_pos () is called */ /* from within this module and it causes major problems. */ /**************************************************************************/ rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (START_SPIN_NOT_FOUND); /***************************************************************************/ /* Set a pointer to the structure which holds all pointers for header and */ /* data information for the experiment currently being processed. */ /* FILE_POS was not called for this data set? */ /***************************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; if (!ex->fnext) return (START_SPIN_NO_POS); /***************************************************************************/ /* Multi-dimensional data must be handled by start_of_spin_tensor(). */ /***************************************************************************/ if (ex->header_format != ORIGINAL_HEADER) return (WRONG_HEADER_FORMAT); /***************************************************************************/ /* The instrument is not spinning. */ /***************************************************************************/ if (*ptr->SPIN == 0) return (START_SPIN_NO_SPIN); /***************************************************************************/ /* Allocate space to hold start of spin information for each sensor. */ /***************************************************************************/ return_pitch_angles = ex->return_pitch_angles; return_euler_angles = ex->return_euler_angles; return_celestial_pos = ex->return_celestial_pos; spin_method = ex->spin_method; if (ex->bmem.base_start_spin_info != NO_MEMORY) { sptr = ex->start_sptr; for (loop_sen = 0; loop_sen < ex->num_sensor; ++loop_sen, ++sptr) if (*(ex->sensors_needed + loop_sen) != 0) free_version_info (sptr->spin_vnum); free (ex->bmem.base_start_spin_info); ex->bmem.base_start_spin_info = NO_MEMORY; ex->start_sptr = NO_MEMORY; } bytes = ex->num_sensor * sizeof (struct start_spin_info); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (START_SPIN_MALLOC); ex->bmem.base_start_spin_info = tmp_ptr; ex->start_sptr = (struct start_spin_info *) ex->bmem.base_start_spin_info; /*********************************************************************/ /* Make sure pointers are all initialized to NO_MEMORY in case an */ /* error is encountered as the sensors are processed one at a time. */ /*********************************************************************/ sptr = ex->start_sptr; for (loop_sen = 0; loop_sen < ex->num_sensor; ++loop_sen, ++sptr) { sptr->data_ptr = NO_MEMORY; sptr->time_per_step.base_time = NO_MEMORY; } /**********************************************************************/ /* If there is a data source that defines the start of spin, use the */ /* first sensor returned in the data record pointed to; otherwise, */ /* use the sensor passed in to this module. */ /**********************************************************************/ if (spin_method == DSRC_CALC) { ex->spin_sen_ctrl = *ptr->SENSOR_INDEX; /*******************************************************************/ /* Make sure to call read_drec since it reads and THEN advances */ /* so that the time pointers are ready when the NEXT spin needs */ /* to be picked up. */ /*******************************************************************/ spin_src_ptr = ex->spin_src; rval = read_drec (spin_src_ptr->data_key, spin_src_ptr->exten, spin_src_ptr->version, spin_src_ptr->idf_data_ptr, spin_src_ptr->sensor, 1, 0); spin_src_ptr->no_acquire = 0; rval = ir_locate_ex (data_key, exten, vnum, 0); /*******************************************************************/ /* Adjust this spin period by the correction factors defined in */ /* the VIDF file. These time correction factors can be either */ /* positive or negative, so make sure adjustments are made */ /* correctly. Work on second boundaries for time adjustments. */ /* 1 second = 1000 millisecond = 1000000000 nanoseconds. */ /*******************************************************************/ SPIN_SRC_DATA = (struct idf_data *) spin_src_ptr->idf_data_ptr; SPIN_SRC_DATA->bmilli += spin_src_ptr->msec_adj; SPIN_SRC_DATA->bnano += spin_src_ptr->nsec_adj; while (SPIN_SRC_DATA->bnano < 0) { SPIN_SRC_DATA->bmilli -= 1000; SPIN_SRC_DATA->bnano += 1000000000; } while (SPIN_SRC_DATA->bnano >= 1000000000) { SPIN_SRC_DATA->bmilli += 1000; SPIN_SRC_DATA->bnano -= 1000000000; } adjust_time (&SPIN_SRC_DATA->byear, &SPIN_SRC_DATA->bday, &SPIN_SRC_DATA->bmilli, 2); SPIN_SRC_DATA->bsec = (SPIN_SRC_DATA->bmilli + (SPIN_SRC_DATA->bnano / 1000000)) / 1000; SPIN_SRC_DATA->bnsec = (SPIN_SRC_DATA->bmilli % 1000) * 1000000 + SPIN_SRC_DATA->bnano; SPIN_SRC_DATA->emilli += spin_src_ptr->msec_adj; SPIN_SRC_DATA->enano += spin_src_ptr->nsec_adj; while (SPIN_SRC_DATA->enano < 0) { SPIN_SRC_DATA->emilli -= 1000; SPIN_SRC_DATA->enano += 1000000000; } while (SPIN_SRC_DATA->enano >= 1000000000) { SPIN_SRC_DATA->emilli += 1000; SPIN_SRC_DATA->enano -= 1000000000; } adjust_time (&SPIN_SRC_DATA->eyear, &SPIN_SRC_DATA->eday, &SPIN_SRC_DATA->emilli, 2); SPIN_SRC_DATA->esec = (SPIN_SRC_DATA->emilli + (SPIN_SRC_DATA->enano / 1000000)) / 1000; SPIN_SRC_DATA->ensec = (SPIN_SRC_DATA->emilli % 1000) * 1000000 + SPIN_SRC_DATA->enano; /*******************************************************************/ /* By this time, the start of spin data source has been opened */ /* and positioned to the closest time as requested by the user, */ /* so all sensors need to be positioned using the time returned */ /* by the start of spin data source. */ /*******************************************************************/ btime_yr = SPIN_SRC_DATA->byear; btime_day = SPIN_SRC_DATA->bday; btime_sec = SPIN_SRC_DATA->bsec; btime_nsec = SPIN_SRC_DATA->bnsec; } else { start_frac = 1.0; /* for angle, use 100% of data in starting element */ ex->spin_sen_ctrl = spin_sen_ctrl; /*******************************************************************/ /* Since no data source to define the timing, all sensors need to */ /* be positioned using the time returned by file_pos () that is */ /* as close to the user-requested start time as possible. */ /*******************************************************************/ btime_yr = ex->requested_time.btime_year; btime_day = ex->requested_time.btime_day; btime_sec = ex->requested_time.btime_sec; btime_nsec = ex->requested_time.btime_nsec; } /*********************************************************************/ /* Process all of the IDFS sensors that are to be accessed. */ /* Either file_open() selected all or SELECT_SENSOR() was called. */ /*********************************************************************/ sptr = ex->start_sptr; process_mode_data = (ex->mode_version != ex->version) ? 1 : 0; num_skip = 0; num_requested = 0; for (loop_sen = 0; loop_sen < ex->num_sensor; ++loop_sen, ++sptr) { ir_init_sensor_spin_struct (sptr); if (*(ex->sensors_needed + loop_sen) != 0) { ++num_requested; get_version_number (&new_vnum); sptr->spin_vnum = new_vnum; /*************************************************************************/ /* Allocate space to save year, day, milliseconds and nanoseconds start */ /* and stop time component for each sample in the parent source. */ /*************************************************************************/ if (spin_method == DSRC_CALC) { rval = ir_alloc_spin_sweep_times (&sptr->time_per_step, -1); if (rval != ALL_OKAY) return (rval); } /**************************************************************************/ /* Allocate space to hold the addresses of all allocated data structures.*/ /* Start out with space for 10 pointers. */ /**************************************************************************/ bytes = 10 * sizeof (void *); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (START_SPIN_ALL_MALLOC); sptr->data_ptr = (void **) tmp_ptr; sptr->num_data_ptr = 10; for (loop_index = 0; loop_index < 10; ++loop_index) *(sptr->data_ptr + loop_index) = NO_MEMORY; /************************************************************************/ /* Create an instance of the data structure, so that data and timing */ /* values can be preserved when the start/stop of spin is found. */ /************************************************************************/ rval = create_idf_data_structure (&idf_data_ptr); if (rval != ALL_OKAY) return (rval); *sptr->data_ptr = idf_data_ptr; /*********************************************************************/ /* Open the data files associated with the time period selected for */ /* this data set/extension/version combination. */ /*********************************************************************/ rval = file_open (data_key, exten, new_vnum, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, process_mode_data); if (rval != ALL_OKAY) return (rval); new_ex = ginfo.expt; new_ex->return_pitch_angles = return_pitch_angles; new_ex->return_euler_angles = return_euler_angles; new_ex->return_celestial_pos = return_celestial_pos; /***********************************************************************/ /* Find the position in the data file closest to the requested */ /* start time for this data set. */ /***********************************************************************/ rval = file_pos (data_key, exten, new_vnum, *sptr->data_ptr, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) return (rval); /***********************************************************************/ /* Find the start of spin for the IDFS sensor being processed. */ /***********************************************************************/ if (spin_method == ANGLE_CALC) { /*******************************************************************/ /* 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 *) *sptr->data_ptr; if (EXP_DATA->header_format != ORIGINAL_HEADER) return (WRONG_DATA_STRUCTURE); /********************************************************************/ /* Since this is the first sweep being examined to see if part of */ /* the spin, set this variable to the start az. angle for the 1st */ /* element of this sweep (in other words, no previous last sweep). */ /********************************************************************/ sptr->last_swp_last_step_az = EXP_DATA->start_az[0]; rval = ir_sensor_start_of_spin_angle (data_key, exten, new_vnum, *sptr->data_ptr, loop_sen, &found_ele, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &sptr->azimuthal_cross_over, vnum); } else { /*******************************************************************/ /* Make sure to call read_drec since it reads and THEN advances */ /* so that the time pointers are ready when the NEXT spin needs */ /* to be picked up. */ /*******************************************************************/ new_ex = ginfo.expt; spin_src_ptr = new_ex->spin_src; rval = read_drec (spin_src_ptr->data_key, spin_src_ptr->exten, spin_src_ptr->version, spin_src_ptr->idf_data_ptr, spin_src_ptr->sensor, 1, 0); spin_src_ptr->no_acquire = 0; /*******************************************************************/ /* Adjust this spin period by the correction factors defined in */ /* the VIDF file. These time correction factors can be either */ /* positive or negative, so make sure adjustments are made */ /* correctly. Work on second boundaries for time adjustments. */ /* 1 second = 1000 millisecond = 1000000000 nanoseconds. */ /*******************************************************************/ SPIN_SRC_DATA = (struct idf_data *) spin_src_ptr->idf_data_ptr; SPIN_SRC_DATA->bmilli += spin_src_ptr->msec_adj; SPIN_SRC_DATA->bnano += spin_src_ptr->nsec_adj; while (SPIN_SRC_DATA->bnano < 0) { SPIN_SRC_DATA->bmilli -= 1000; SPIN_SRC_DATA->bnano += 1000000000; } while (SPIN_SRC_DATA->bnano >= 1000000000) { SPIN_SRC_DATA->bmilli += 1000; SPIN_SRC_DATA->bnano -= 1000000000; } adjust_time (&SPIN_SRC_DATA->byear, &SPIN_SRC_DATA->bday, &SPIN_SRC_DATA->bmilli, 2); SPIN_SRC_DATA->bsec = (SPIN_SRC_DATA->bmilli + (SPIN_SRC_DATA->bnano / 1000000)) / 1000; SPIN_SRC_DATA->bnsec = (SPIN_SRC_DATA->bmilli % 1000) * 1000000 + SPIN_SRC_DATA->bnano; SPIN_SRC_DATA->emilli += spin_src_ptr->msec_adj; SPIN_SRC_DATA->enano += spin_src_ptr->nsec_adj; while (SPIN_SRC_DATA->enano < 0) { SPIN_SRC_DATA->emilli -= 1000; SPIN_SRC_DATA->enano += 1000000000; } while (SPIN_SRC_DATA->enano >= 1000000000) { SPIN_SRC_DATA->emilli += 1000; SPIN_SRC_DATA->enano -= 1000000000; } adjust_time (&SPIN_SRC_DATA->eyear, &SPIN_SRC_DATA->eday, &SPIN_SRC_DATA->emilli, 2); SPIN_SRC_DATA->esec = (SPIN_SRC_DATA->emilli + (SPIN_SRC_DATA->enano / 1000000)) / 1000; SPIN_SRC_DATA->ensec = (SPIN_SRC_DATA->emilli % 1000) * 1000000 + SPIN_SRC_DATA->enano; rval = ir_locate_ex (data_key, exten, vnum, 0); rval = ir_sensor_start_of_spin_src (data_key, exten, new_vnum, *sptr->data_ptr, loop_sen, &found_ele, etime_yr, etime_day, etime_sec, etime_nsec, sptr->time_per_step.btime_yr, sptr->time_per_step.btime_day, sptr->time_per_step.btime_ms, sptr->time_per_step.btime_ns, sptr->time_per_step.etime_yr, sptr->time_per_step.etime_day, sptr->time_per_step.etime_ms, sptr->time_per_step.etime_ns, &start_frac); } if (rval != ALL_OKAY) { if (rval == START_SPIN_ETIME && spin_method == ANGLE_CALC) { /***********************************************************************/ /* Set this so no further processing. */ /***********************************************************************/ sptr->skip = sTrue; ++num_skip; /***********************************************************************/ /* Need these last few lines; otherwise, code generates a core trying */ /* to access ex->sensors_needed. */ /***********************************************************************/ rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (START_SPIN_NOT_FOUND); ex = ginfo.expt; ptr = ex->info_ptr; /***********************************************************************/ /* Need to find another controller if other sensors can find the */ /* start of spin. */ /***********************************************************************/ if (loop_sen == spin_sen_ctrl) ex->spin_sen_ctrl = -1; continue; } return (rval); } /***********************************************************************/ /* Need these last few lines; otherwise, code generates a core trying */ /* to access ex->sensors_needed. */ /***********************************************************************/ rval = ir_locate_ex (data_key, exten, vnum, 0); if (rval != ALL_OKAY) return (START_SPIN_NOT_FOUND); ex = ginfo.expt; ptr = ex->info_ptr; sptr->spin_start_ele = found_ele; sptr->last_spin_start_ele = found_ele; sptr->start_ele_frac = start_frac; sptr->last_spin_start_ele_frac = start_frac; /***********************************************************************/ /* Save time of this sample to make sure time does not go backwards. */ /***********************************************************************/ EXP_DATA = (struct idf_data *) *sptr->data_ptr; if (EXP_DATA->header_format != ORIGINAL_HEADER) return (WRONG_DATA_STRUCTURE); sptr->last_swp.byear = EXP_DATA->byear; sptr->last_swp.bday = EXP_DATA->bday; sptr->last_swp.bmilli = EXP_DATA->bmilli; sptr->last_swp.bnano = EXP_DATA->bnano; sptr->last_swp.eyear = EXP_DATA->eyear; sptr->last_swp.eday = EXP_DATA->eday; sptr->last_swp.emilli = EXP_DATA->emilli; sptr->last_swp.enano = EXP_DATA->enano; good_sensor = EXP_DATA->sensor; } } /***********************************************************************/ /* The start of spin could not be found for any of the sensors? */ /***********************************************************************/ if (num_skip == num_requested) return (START_SPIN_ETIME); else { /***********************************************************************/ /* New time controller must be set since start of spin not found for */ /* designated time controller? */ /***********************************************************************/ if (ex->spin_sen_ctrl == -1) ex->spin_sen_ctrl = good_sensor; return (ALL_OKAY); } }