/* * 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_pinfo.c 1.15 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * IR_GET_PITCH_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to retrieve information from the VIDF file * * concerning pitch angle calculations. It is only called if the IDFS source * * has the pa_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_pitch_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 pitch angle IDFS source * * ir_file_setup() opens the data, header and vidf file and * * retrieves information from the VIDF file * * ir_get_pinfo_rval () returns an error code unique to this module * * for each possible ReadVIDF() error code * * ir_alloc_pitch_info () allocates the structure that holds the * * pitch angle information * * ir_get_unit_normals () retrieves the unit normal to the aperture * * and computes the magnitude of the vector * * ir_pitch_angle_data_src () determines IDFS data source for pitch angles* * ir_pitch_angle_tbl_info () retrieves unit information for pitch angles * * ir_get_pitch_angle_constants() retrieves the pitch angle constants * * defined in the VIDF for the parent source * * * * 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_pa specific experiment information * * register struct pitch_info a pointer to the structure that holds pitch * * *pa_ptr angle information * * register SDDAS_SHORT i looping variable * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_ULONG old_dkey data key for parent source * * SDDAS_LONG start_at_zero param. passed to ReadVIDF to avoid casting * * 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_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_pitch_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_pa; register struct pitch_info *pa_ptr; register SDDAS_SHORT i; SDDAS_ULONG data_key, old_dkey; SDDAS_LONG closest_btime_sec, closest_btime_nsec; SDDAS_LONG start_at_zero; 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 pitch angle information. */ /**************************************************************************/ ex = ginfo.expt; data_key = ex->data_key; old_dkey = ex->data_key; old_version = ex->version; strcpy (old_exten, ex->exten); start_at_zero = 0; /**************************************************************************/ /* 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_pitch_info == NO_MEMORY) { rval = ir_alloc_pitch_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 pitch angle 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. */ /****************************************************************************/ pa_ptr = ex->pitch_angles; if (!ir_inside_reset_exp) { get_version_number (&pa_ptr->version); ex->pa_version = pa_ptr->version; } else pa_ptr->version = ex->pa_version; 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 *) &pa_ptr->pa_format, _PA_FORMAT, 0, start_at_zero, 1); if (ret_val < 0) { pa_ptr->file_status = ir_get_pinfo_rval (ret_val); return (ALL_OKAY); } /***************************************************************************/ /* Retrieve pertinent information from the VIDF file for pitch angle */ /* processing where computations are made as opposed to being pre-defined.*/ /***************************************************************************/ if (pa_ptr->pa_format == PA_COMPUTE) { 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 *) pa_ptr->sensor, _PA_BXBYBZ, 0, start_at_zero, -1); if (ret_val < 0) { pa_ptr->file_status = ir_get_pinfo_rval (ret_val); return (ALL_OKAY); } /*********************************************************************/ /* Calling routine just makes necessary calls to get info from VIDF */ /* so send VIDF start times. */ /*********************************************************************/ rval = ir_pitch_angle_data_src (data_key, VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, &pa_ptr->data_key); if (rval != ALL_OKAY) { pa_ptr->file_status = rval; return (ALL_OKAY); } rval = ir_pitch_angle_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) { pa_ptr->file_status = rval; return (ALL_OKAY); } /***********************************************************************/ /* Retrieve the unit normal to the aperture. */ /***********************************************************************/ ret_val = ir_get_unit_normals (VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val < 0) { pa_ptr->file_status = ir_get_pinfo_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 pitch angle data has been */ /* allocated so point back to this structure. */ /************************************************************************/ pa_ptr->file_status = ir_file_setup (pa_ptr->data_key, pa_ptr->exten, pa_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 (pa_ptr->file_status != ALL_OKAY) { /********************************************************************/ /* Clean up before return. No mode processing for pitch angle */ /* 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_pa = ginfo.expt; ex_pa->mode_version = ex_pa->version; ex_pa->mode_done = PITCH_FLAG; if (ir_inside_reset_exp) ex_pa->fnext = 0; return (ALL_OKAY); } /***********************************************************************/ /* Use only those sensors needed to compute pitch angles. */ /***********************************************************************/ for (i = 0; i < 3; ++i) { rval = select_sensor (pa_ptr->data_key, pa_ptr->exten, pa_ptr->version, pa_ptr->sensor[i]); if (rval != ALL_OKAY) { pa_ptr->file_status = rval; return (ALL_OKAY); } rval = create_idf_data_structure (&pa_ptr->idf_data_ptr[i]); if (rval != ALL_OKAY) { pa_ptr->file_status = rval; return (ALL_OKAY); } } /***********************************************************************/ /* Make sure pitch angle IDFS source is a scalar instrument. */ /***********************************************************************/ ex_pa = ginfo.expt; if (ex_pa->smp_id != 2) { pa_ptr->file_status = PA_BAD_SRC; return (ALL_OKAY); } /***********************************************************************/ /* No mode processing for pitch angle 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_pa->mode_version = ex_pa->version; ex_pa->mode_done = PITCH_FLAG; if (ir_inside_reset_exp) ex_pa->fnext = 0; /************************************************************************/ /* Set flag in parent source indicating that times per step are needed */ /* due to pitch angle. After this is done, call LOCATE_EX to point */ /* back to ex structure for pitch angle data since calling module */ /* expects this. */ /************************************************************************/ rval = ir_locate_ex (old_dkey, old_exten, old_version, 0); ex = ginfo.expt; ex->swp_times.pa_times = 1; rval = ir_locate_ex (ex_pa->data_key, ex_pa->exten, ex_pa->version, 0); } else if (pa_ptr->pa_format == PA_CONSTANT) { /*********************************************************************/ /* Calling routine just makes necessary calls to get info from VIDF */ /* so send VIDF start times. */ /*********************************************************************/ ret_val = ir_get_pitch_angle_constants (VIDF_btime_yr, VIDF_btime_day, VIDF_btime_sec, VIDF_btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); /***********************************************************************/ /* Regardless if error or not, pa_ptr->file_status needs to be set. */ /***********************************************************************/ pa_ptr->file_status = ir_get_pinfo_rval (ret_val); } else return (BAD_PA_FORMAT); return (ALL_OKAY); } /******************************************************************************* * * * IR_GET_PINFO_RVAL SUBROUTINE * * * * DESCRIPTION * * This routine returns an error code unique to the module GET_PITCH_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_pinfo_rval (ret_val) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * None * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_get_pinfo_rval (int ret_val) { switch (ret_val) { case IDF_MANY_BYTES: return (PINFO_IDF_MANY_BYTES); case IDF_TBL_NUM: return (PINFO_IDF_TBL_NUM); case IDF_CON_NUM: return (PINFO_IDF_CON_NUM); case IDF_NO_ENTRY: return (PINFO_IDF_NO_ENTRY); case VIDF_ELEMENT_NOT_FOUND: return (PINFO_IDF_ELE_NOT_FOUND); default: return ((SDDAS_SHORT) ret_val); } }