/* * 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: get_pot_info.c 20988 2011-01-19 22:24:20Z carrie $ SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "user_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * IR_GET_POTENTIAL_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to retrieve information from the VIDF file * * concerning spacecraft potential data source information. It is only * * called if the IDFS source has the potential_defined VIDF flag set to one. * * * * INPUT VARIABLES * * SDDAS_SHORT btime_yr the start time requested (year component) * * SDDAS_SHORT btime_day the start time requested (day component) * * SDDAS_LONG btime_sec the start time requested (seconds component)* * SDDAS_LONG btime_nsec the start time requested (nanoseconds) * * 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 = ir_get_potential_info (btime_yr, btime_day, btime_sec, btime_nsec, * * etime_yr, etime_day, etime_sec, etime_nsec) * * * * NECESSARY SUBPROGRAMS * * strcpy() copies a string to another string variable * * get_version_number () returns the next available version number * * ir_locate_ex() determines if requested combo. has already * * been processed and points to the correct * * structure allocated for the combo * * ReadVIDF() reads information from the VIDF file * * select_sensor() specifies which sensors are to be processed * * create_idf_data_structure() creates the idf_data structure that will * * hold data from the spacecraft potential * * IDFS source * * ir_file_setup() opens the data, header and vidf file and * * retrieves information from the VIDF file * * ir_get_pot_info_rval () returns an error code unique to this module * * for each possible ReadVIDF() error code * * ir_alloc_potential_info () allocates the structure that holds the * * spacecraft potential information * * ir_potential_data_src () determines IDFS data source for spacecraft * * potential * * ir_potential_tbl_info () retrieves unit information for spacecraft * * potential * * ir_locate_ex() determines if requested combo. has already * * been processed and points to the correct * * structure allocated for the combo * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure that holds information concerning * * the experiment that is being processed * * SDDAS_CHAR ir_inside_reset_exp flag indicating in RESET_EXPERIMENT_INFO * * module (needed for FILE_OPEN logic) * * * * INTERNAL VARIABLES * * struct experiment_info *ex, a pointer to the structure that holds * * *ex_pot specific experiment information * * reg struct potential_info a pointer to the structure that holds * * *potential_ptr spacecraft potential information * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_ULONG old_dkey data key for parent source * * SDDAS_LONG closest_btime_sec the start time closest to user-requested * * SDDAS_LONG closest_btime_nsec the start time closest to user-requested * * SDDAS_LONG VIDF_btime_sec start time to use when requested VIDF info. * * SDDAS_LONG VIDF_btime_nsec start time to use when requested VIDF info. * * SDDAS_SHORT closest_btime_yr the start time closest to user-requested * * SDDAS_SHORT closest_btime_day the start time closest to user-requested * * SDDAS_LONG start_at_zero param. passed to ReadVIDF to avoid casting * * SDDAS_USHORT old_version version number for parent source * * SDDAS_SHORT rval holds value returned by called module * * SDDAS_SHORT VIDF_btime_yr start time to use when requested VIDF info. * * SDDAS_SHORT VIDF_btime_day start time to use when requested VIDF info. * * SDDAS_CHAR old_exten[] filename extension for parent source * * SDDAS_BOOL update_times flag indicating closest times are desired * * int ret_val holds value returned by called module * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_get_potential_info (SDDAS_SHORT btime_yr, SDDAS_SHORT btime_day, SDDAS_LONG btime_sec, SDDAS_LONG btime_nsec, SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec) { extern struct general_info ginfo; extern SDDAS_CHAR ir_inside_reset_exp; struct experiment_info *ex, *ex_pot; register struct potential_info *potential_ptr; SDDAS_ULONG data_key, old_dkey; SDDAS_LONG start_at_zero; SDDAS_LONG closest_btime_sec, closest_btime_nsec; SDDAS_LONG VIDF_btime_sec, VIDF_btime_nsec; SDDAS_USHORT old_version; SDDAS_SHORT closest_btime_yr, closest_btime_day; SDDAS_SHORT rval; SDDAS_SHORT VIDF_btime_yr, VIDF_btime_day; SDDAS_CHAR old_exten[3]; SDDAS_BOOL update_times = sFalse; /* Leave variable as is, no typedefs. */ int ret_val; /***************************************************************************/ /* Allocate the structure that holds the spacecraft potential information.*/ /***************************************************************************/ ex = ginfo.expt; data_key = ex->data_key; old_dkey = ex->data_key; old_version = ex->version; strcpy (old_exten, ex->exten); /**************************************************************************/ /* If parent source has not been positioned yet, as indicated by the */ /* status flag being used, use the user-requested time, not the */ /* "closest time" which may be what is represented by the arguments */ /* provided, since info. from VIDF picked up PRIOR to this call was made */ /* with the user-requested time, which could represent a different VIDF */ /* file from the closest time. */ /**************************************************************************/ if (ex->ancillary_opened == sFalse) { VIDF_btime_yr = ex->requested_time.btime_year; VIDF_btime_day = ex->requested_time.btime_day; VIDF_btime_sec = ex->requested_time.btime_sec; VIDF_btime_nsec = ex->requested_time.btime_nsec; } else { VIDF_btime_yr = btime_yr; VIDF_btime_day = btime_day; VIDF_btime_sec = btime_sec; VIDF_btime_nsec = btime_nsec; } if (ex->bmem.base_potential_info == NO_MEMORY) { rval = ir_alloc_potential_info (etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) return (rval); } /****************************************************************************/ /* If reset_experiment_info invoked this routine, the ex structure for */ /* the spacecraft potential data has been allocated so point back to this */ /* structure. If not called by reset_experiment_info, get a new version */ /* number and set now so that this value is set PRIOR to a return caused */ /* by an error. */ /****************************************************************************/ potential_ptr = ex->potential; if (!ir_inside_reset_exp) { get_version_number (&potential_ptr->version); ex->potential_version = potential_ptr->version; } else potential_ptr->version = ex->potential_version; start_at_zero = 0; ret_val = ReadVIDF (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &potential_ptr->scpot_format, _POT_SRC_FORMAT, 0, start_at_zero, 1); if (ret_val < 0) { potential_ptr->file_status = ir_get_pot_info_rval (ret_val); return (ALL_OKAY); } /****************************************************************************/ /* Retrieve pertinent information from the VIDF file for spacecraft */ /* potential data source designation where dynamic values are defined as */ /* opposed to being a pre-defined constant value. */ /****************************************************************************/ if (potential_ptr->scpot_format == SCPOT_DSRC) { /*********************************************************************/ /* Calling routine just makes necessary calls to get info from VIDF */ /* so send VIDF start times. */ /*********************************************************************/ rval = ir_potential_data_src (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &potential_ptr->data_key); if (rval != ALL_OKAY) { potential_ptr->file_status = rval; return (ALL_OKAY); } ret_val = ReadVIDF (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &potential_ptr->sensor, _POT_SRC_SENSOR, 0, start_at_zero, -1); if (ret_val < 0) { potential_ptr->file_status = ir_get_pot_info_rval (ret_val); return (ALL_OKAY); } /*********************************************************************/ /* Calling routine just makes necessary calls to get info from VIDF */ /* so send VIDF start times. */ /*********************************************************************/ rval = ir_potential_tbl_info (VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rval != ALL_OKAY) { potential_ptr->file_status = rval; return (ALL_OKAY); } /*************************************************************************/ /* Initialize to some obscure value to indicate value was not retrieved.*/ /*************************************************************************/ potential_ptr->constant_val = OUTSIDE_MIN; ret_val = ReadVIDF (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &potential_ptr->constant_val, _POT_CONSTANT_VAL, 0, start_at_zero, -1); if (ret_val < 0) { potential_ptr->file_status = ir_get_pot_info_rval (ret_val); return (ALL_OKAY); } /************************************************************************/ /* Try to open the necessary files using a new version number in order */ /* to get separate file descriptor. If reset_experiment_info invoked */ /* this routine, the ex structure for the spacecraft potential data */ /* has been allocated so point back to this structure. */ /************************************************************************/ potential_ptr->file_status = ir_file_setup (potential_ptr->data_key, potential_ptr->exten, potential_ptr->version, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &closest_btime_yr, &closest_btime_day, &closest_btime_sec, &closest_btime_nsec, update_times); if (potential_ptr->file_status != ALL_OKAY) { /********************************************************************/ /* Clean up before return. No mode processing for spacecraft pot. */ /* source. Since we don't call FILE_OPEN(), manually set it in */ /* this module. Set the mode_done flag such that these ex */ /* structures can be bypassed since they hinge off the parent */ /* source. Also, reset the fnext flag if called due to file */ /* boundary crossings. */ /********************************************************************/ ex_pot = ginfo.expt; ex_pot->mode_version = ex_pot->version; ex_pot->mode_done = POTENTIAL_FLAG; if (ir_inside_reset_exp) ex_pot->fnext = 0; return (ALL_OKAY); } /***********************************************************************/ /* Use only the sensor needed to compute the spacecraft potential. */ /***********************************************************************/ rval = select_sensor (potential_ptr->data_key, potential_ptr->exten, potential_ptr->version, potential_ptr->sensor); if (rval != ALL_OKAY) { potential_ptr->file_status = rval; return (ALL_OKAY); } rval = create_idf_data_structure (&potential_ptr->idf_data_ptr); if (rval != ALL_OKAY) { potential_ptr->file_status = rval; return (ALL_OKAY); } /***********************************************************************/ /* Make sure spacecraft potential IDFS source is a scalar instrument. */ /***********************************************************************/ ex_pot = ginfo.expt; if (ex_pot->smp_id != 2) { potential_ptr->file_status = POT_BAD_SRC; return (ALL_OKAY); } /***********************************************************************/ /* No mode processing for spacecraft potential source. Since we */ /* don't call FILE_OPEN(), manually set it in this module. Set the */ /* mode_done flag such that these ex structures can be bypassed since */ /* they hinge off the parent source. Also, reset the fnext flag if */ /* called due to file boundary crossings. */ /***********************************************************************/ ex_pot->mode_version = ex_pot->version; ex_pot->mode_done = POTENTIAL_FLAG; if (ir_inside_reset_exp) ex_pot->fnext = 0; /************************************************************************/ /* Set flag in parent source indicating that times per step are needed */ /* due to potential. After this is done, call LOCATE_EX to point */ /* back to ex structure for potential data since calling module */ /* expects this. */ /************************************************************************/ rval = ir_locate_ex (old_dkey, old_exten, old_version, 0); ex = ginfo.expt; ex->swp_times.pot_times = 1; rval = ir_locate_ex (ex_pot->data_key, ex_pot->exten, ex_pot->version, 0); } else if (potential_ptr->scpot_format == SCPOT_CONSTANT) { /***********************************************************************/ /* Regardless if error or not, potential_ptr->file_status needs to be */ /* set. */ /***********************************************************************/ ret_val = ReadVIDF (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) &potential_ptr->constant_val, _POT_CONSTANT_VAL, 0, start_at_zero, -1); potential_ptr->file_status = ir_get_pot_info_rval (ret_val); } else return (BAD_SCPOT_FORMAT); return (ALL_OKAY); } /******************************************************************************* * * * IR_GET_POT_INFO_RVAL SUBROUTINE * * * * DESCRIPTION * * This routine returns an error code unique to IR_GET_POTENTIAL_INFO() * * based upon the error code returned by the call to ReadVIDF(). * * * * INPUT VARIABLES * * int ret_val the error code returned by ReadVIDF() * * * * USAGE * * x = ir_get_pot_info_rval (ret_val) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * None * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_get_pot_info_rval (int ret_val) { switch (ret_val) { case IDF_MANY_BYTES: return (POT_INFO_IDF_MANY_BYTES); case IDF_TBL_NUM: return (POT_INFO_IDF_TBL_NUM); case IDF_CON_NUM: return (POT_INFO_IDF_CON_NUM); case IDF_NO_ENTRY: return (POT_INFO_IDF_NO_ENTRY); case VIDF_ELEMENT_NOT_FOUND: return (POT_INFO_IDF_ELE_NOT_FOUND); default: return ((SDDAS_SHORT) ret_val); } }