/* * 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 "@(#) $Id: ancillary_los.c 20511 2009-09-28 15:00:43Z carrie $ SwRI" #include "ret_codes.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_ANCILLARY_DATA_LOS_NEXT_FILE SUBROUTINE * * * * DESCRIPTION * * This routine is called whenever the LOS_STATUS or NEXT_FILE_STATUS code * * is returned by read_drec() for the ancillary data product being processed. * * The existing data set is closed and the next set of IDFS files are * * retrieved so that the processing of the algorithm can continue. If the * * data files are not online, the code does not attempt to promote the data; * * an error code will be returned if the attempt to open the next IDFS data * * set cannot be accomplished. This code works on the assumption of playback * * mode. It does not work for real-time. * * * * INPUT VARIABLES * * SDDAS_ULONG data_key key which uniquely identifies the ancillary * * data set being processed * * SDDAS_CHAR *exten filename extension for the ancillary data * * to be used * * SDDAS_USHORT vnum version number to be associated with this * * combination (allows for multiple opens) * * void *idf_data_ptr ptr to the memory location that holds the * * address of the structure that holds returned* * data values (read_drec) * * struct time_span structure that holds the time period for * * src_time the current delta-t being processed * * SDDAS_SHORT stop_year end time used for parent * * SDDAS_SHORT stop_day end time used for parent * * SDDAS_LONG stop_sec end time used for parent * * SDDAS_LONG stop_nano end time used for parent * * SDDAS_CHAR ancillary_done flag indicating ex struct for ancillary data* * is done with * * SDDAS_SHORT *file_status status value from RESET_EXPERIMENT_INFO() * * for ancillary IDFS data set returned * * * * USAGE * * x = ir_ancillary_data_los_next_file (data_key, exten, vnum, idf_data_ptr,* * src_time, stop_year, stop_day, * * stop_sec, stop_nano, ancillary_done,* * &file_status) * * * * NECESSARY SUBPROGRAMS * * ir_locate_ex() determines if requested combination has * * already been pand points to the * * correct structure allocated for the combo * * file_pos() positions the data/header files for the * * data source at the desired start time * * reset_experiment_info () closes the opened IDFS data set and gets * * the next set of IDFS data files * * adjust_time () corrects time elements if too many seconds * * (day crossing) or too many days (year * * crossing) * * * * EXTERNAL VARIABLES * * struct general_info structure holding information concerning * * ginfo the experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure that holds * * *ex specific experiment information * * struct idf_data *ANC_DATA structure holding the data for the ancillary* * data product being processed * * SDDAS_LONG new_start_sec, the time of day being requested for the * * new_start_nsec next set of IDFS data files * * SDDAS_LONG time_nsec the nanoseconds component for the time of * * day, which is modified by 1 millisecond * * SDDAS_LONG time_diff time value for calculating new nanosecond * * SDDAS_SHORT ret_val holds value returned by called module * * SDDAS_SHORT new_year, new_day year/ day time values for next data file * * SDDAS_CHAR stop_acq flag indicating end time has been reached * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_ancillary_data_los_next_file (SDDAS_ULONG data_key, SDDAS_CHAR *exten, SDDAS_USHORT vnum, void *idf_data_ptr, struct time_span src_time, SDDAS_SHORT stop_year, SDDAS_SHORT stop_day, SDDAS_LONG stop_sec, SDDAS_LONG stop_nano, SDDAS_CHAR ancillary_done, SDDAS_SHORT *file_status) { extern struct general_info ginfo; struct experiment_info *ex; struct idf_data *ANC_DATA; SDDAS_LONG new_start_sec, new_start_nsec, time_nsec, time_diff; SDDAS_SHORT ret_val, new_year, new_day; SDDAS_CHAR stop_acq = 1; /*********************************************************************/ /* Get the end time of the current ancillary data. */ /*********************************************************************/ ANC_DATA = (struct idf_data *) idf_data_ptr; new_year = ANC_DATA->eyear; new_day = ANC_DATA->eday; time_nsec = ANC_DATA->enano; new_start_sec = (ANC_DATA->emilli + (time_nsec / 1000000)) / 1000; time_diff = ANC_DATA->emilli - (new_start_sec * 1000); time_nsec += time_diff * 1000000; new_start_nsec = time_nsec % 1000000000; adjust_time (&new_year, &new_day, &new_start_sec, 1); /***********************************************************************/ /* Before we assume that the next file is actually needed, check */ /* to see if the time of the current step goes past the time that the */ /* current ancillary sample is good for. The duration for which the */ /* ancillary data is valid could be large and could start before */ /* the start time and go past the end time. */ /***********************************************************************/ if (ANC_DATA->eyear == src_time.eyear) { if (ANC_DATA->eday == src_time.eday) { if (ANC_DATA->emilli > src_time.emilli) stop_acq = 0; else if (ANC_DATA->emilli == src_time.emilli && ANC_DATA->enano > src_time.enano) stop_acq = 0; } else if (ANC_DATA->eday > src_time.eday) stop_acq = 0; } else if (ANC_DATA->eyear > src_time.eyear) stop_acq = 0; if (!stop_acq) return (ALL_OKAY); /*********************************************************************/ /* Update the start time to reflect when processing stopped for the */ /* current data file. An attempt is made to get the next data file */ /* (if one exists) to continue processing. Since the database */ /* resolution is in terms of milliseconds, add 1 millisecond to */ /* ensure that the next data file, not the current data file, will */ /* be retrieved from the database. */ /*********************************************************************/ new_year = ANC_DATA->eyear; new_day = ANC_DATA->eday; time_nsec = ANC_DATA->enano + 1000000; new_start_sec = (ANC_DATA->emilli + (time_nsec / 1000000)) / 1000; time_diff = ANC_DATA->emilli - (new_start_sec * 1000); time_nsec += time_diff * 1000000; new_start_nsec = time_nsec % 1000000000; adjust_time (&new_year, &new_day, &new_start_sec, 1); *file_status = reset_experiment_info (data_key, exten, vnum, new_year, new_day, new_start_sec, new_start_nsec, stop_year, stop_day, stop_sec, stop_nano); /*************************************************************************/ /* Reset this element of the structure even if an error was encountered */ /* IF an experiment_info structure was allocated. */ /*************************************************************************/ ret_val = ir_locate_ex (data_key, exten, vnum, 0); if (ret_val == ALL_OKAY) { ex = ginfo.expt; ex->mode_done = ancillary_done; } if (*file_status != ALL_OKAY) return (*file_status); /*********************************************************************/ /* Position the data file at the requested start time. Must be */ /* called again if NEXT_FILE_STATUS or LOS_STATUS is encountered. */ /*********************************************************************/ ret_val = file_pos (data_key, exten, vnum, idf_data_ptr, new_year, new_day, new_start_sec, new_start_nsec, stop_year, stop_day, stop_sec, stop_nano); if (ret_val != ALL_OKAY) return (ret_val); return (ALL_OKAY); }