/* * 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: alloc_euler.c 22016 2012-12-05 18:47:01Z carrie $ SwRI" #include #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_ALLOC_EULER_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to allocate the structure that holds euler angle * * information. Those data elements not retrieved from the VIDF file are * * initialized. * * * * INPUT VARIABLES * * 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) * * SDDAS_SHORT num_pmi_angles number of euler angles defined * * SDDAS_SHORT pmi_format specifies method of euler angle computation * * * * USAGE * * x = ir_alloc_euler_info (etime_yr, etime_day, etime_sec, etime_nsec, * * num_pmi_angles, pmi_format) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * strcpy() copies a string to another string variable * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure that holds information concerning * * the experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info *ex a pointer to the structure that holds * * specific experiment information * * register struct euler_info a pointer to the structure that holds euler * * *pmi_ptr angle information * * register SDDAS_SHORT i looping variable * * SDDAS_LONG offset index into allocated memory * * SDDAS_SHORT max_size max. size for packed scalars or max elements* * in a sweep for a sweeping instrument * * SDDAS_SHORT pmi_array_size the number of euler angles for which space * * needs to be allocated * * size_t bytes the number of bytes to allocate * * size_t num_bytes_sfloat the number of bytes needed for a SDDAS_FLOAT* * size_t num_bytes_sshort the number of bytes needed for a SDDAS_SHORT* * size_t num_bytes_schar the number of bytes needed for a SDDAS_CHAR * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_alloc_euler_info (SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec, SDDAS_SHORT num_pmi_angles, SDDAS_SHORT pmi_format) { extern struct general_info ginfo; struct experiment_info *ex; register struct euler_info *pmi_ptr; register SDDAS_SHORT i; SDDAS_LONG offset; SDDAS_SHORT max_size, pmi_array_size; size_t bytes, num_bytes_sfloat, num_bytes_sshort, num_bytes_schar; void *tmp_ptr; /**************************************************************************/ /* Allocate the structure that holds the euler angle information. */ /**************************************************************************/ ex = ginfo.expt; bytes = sizeof (struct euler_info); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (EULER_MALLOC); ex->bmem.base_euler_info = tmp_ptr; ex->euler_angles = (struct euler_info *) ex->bmem.base_euler_info; pmi_ptr = ex->euler_angles; pmi_ptr->num_pmi_angles = num_pmi_angles; pmi_ptr->pmi_format = pmi_format; strcpy (pmi_ptr->exten, ex->exten); pmi_ptr->get_pmi_data = 1; pmi_ptr->file_status = 0; pmi_ptr->num_tbls = 0; /**************************************************************************/ /* Save time passed to FILE_OPEN for parent data set. */ /**************************************************************************/ pmi_ptr->stop_year = etime_yr; pmi_ptr->stop_day = etime_day; pmi_ptr->stop_sec = etime_sec; pmi_ptr->stop_nano = etime_nsec; /**************************************************************************/ /* Initialize those values not read from the VIDF file. */ /**************************************************************************/ pmi_ptr->copy_next_data = sFalse; pmi_ptr->copy_all_done = sFalse; pmi_ptr->last_comp_frac = 0.0; pmi_ptr->base_tbls = NO_MEMORY; pmi_ptr->tbl_apply = NO_MEMORY; pmi_ptr->tbl_oper = NO_MEMORY; pmi_ptr->base_sensors_axis = NO_MEMORY; pmi_ptr->euler_angle = NO_MEMORY; pmi_ptr->sensor = NO_MEMORY; pmi_ptr->rot_axis = NO_MEMORY; pmi_ptr->time_frac = NO_MEMORY; pmi_ptr->next_data = NO_MEMORY; pmi_ptr->all_done = NO_MEMORY; /****************************************************************************/ /* Since the data set for the sensors could have different TIME_OFF values,*/ /* make sure data from the data set returns one consistent time. */ /****************************************************************************/ pmi_ptr->cur_time.byear = 0; pmi_ptr->cur_time.bday = 0; pmi_ptr->cur_time.bmilli = 0; pmi_ptr->cur_time.bnano = 0; pmi_ptr->cur_time.eyear = 0; pmi_ptr->cur_time.eday = 0; pmi_ptr->cur_time.emilli = 0; pmi_ptr->cur_time.enano = 0; /*************************************************************************/ /* The euler angle information is to be retrieved from the IDFS data */ /* source using the sensors and rotation axes specified, which are both */ /* of the data type SDDAS_SHORT. Once converted, data is transferred */ /* to euler_angle data array (SDDAS_FLOAT), one element per step along */ /* with a normalization factor (SDDAS_FLOAT). For sweeping instruments,*/ /* SWP_LEN is used since the maximum length of the parent sweep is */ /* needed. For scalar instruments, use the max_packing value in case */ /* of packed scalars, which will return 1 value for each packed value. */ /*************************************************************************/ pmi_array_size = pmi_ptr->num_pmi_angles; num_bytes_sfloat = sizeof (SDDAS_FLOAT); num_bytes_sshort = sizeof (SDDAS_SHORT); num_bytes_schar = sizeof (SDDAS_CHAR); if (pmi_format == EULER_DSRC) { if (ex->smp_id == 2) max_size = ex->max_packing; else max_size = ex->swp_len; bytes = (num_bytes_sfloat + num_bytes_sfloat) * pmi_array_size * max_size; bytes += (num_bytes_sshort + num_bytes_sshort) * pmi_array_size; bytes += (num_bytes_schar + num_bytes_schar) * pmi_array_size; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (EULER_AXIS_MALLOC); pmi_ptr->base_sensors_axis = tmp_ptr; pmi_ptr->euler_angle = (SDDAS_FLOAT *) pmi_ptr->base_sensors_axis; /* Cast base_sensors_axis to a char. ptr since void and offset is in bytes. */ offset = max_size * pmi_array_size * num_bytes_sfloat; pmi_ptr->time_frac = (SDDAS_FLOAT *) ((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); offset += max_size * pmi_array_size * num_bytes_sfloat; pmi_ptr->rot_axis = (SDDAS_SHORT *)((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); offset += pmi_array_size * num_bytes_sshort; pmi_ptr->sensor = (SDDAS_SHORT *) ((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); /*************************************************************************/ /* Since there is one idf_data structure per defined euler angle, need */ /* pmi_array_size file manipulation flags. */ /*************************************************************************/ offset += pmi_array_size * num_bytes_sshort; pmi_ptr->next_data = (SDDAS_CHAR *) ((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); offset += pmi_array_size * num_bytes_schar; pmi_ptr->all_done = (SDDAS_CHAR *) ((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); /**************************************************************************/ /* Allocate space to hold the addresses of all allocated data structures.*/ /**************************************************************************/ bytes = pmi_array_size * sizeof (void *); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (EULER_IDF_DATA_MALLOC); pmi_ptr->idf_data_ptr = (void **) tmp_ptr; for (i = 0; i < pmi_array_size; ++i) { *(pmi_ptr->idf_data_ptr + i) = NO_MEMORY; *(pmi_ptr->next_data + i) = 1; *(pmi_ptr->all_done + i) = 0; } } /**************************************************************************/ /* The euler angle information is to be retrieved from the VIDF file. */ /* Since this structure is associated with the experiment_info structure,*/ /* need to grab the constants for ALL sensors at this time. */ /**************************************************************************/ else if (pmi_format == EULER_CONSTANT) { bytes = (num_bytes_sfloat + num_bytes_sshort) * pmi_array_size * ex->num_sensor; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (EULER_AXIS_MALLOC); pmi_ptr->base_sensors_axis = tmp_ptr; pmi_ptr->euler_angle = (SDDAS_FLOAT *) pmi_ptr->base_sensors_axis; /* Cast base address to a char. ptr since void and offset is in bytes. */ offset = ex->num_sensor * pmi_array_size * num_bytes_sfloat; pmi_ptr->rot_axis = (SDDAS_SHORT *)((SDDAS_CHAR *) pmi_ptr->base_sensors_axis + offset); /* No idf_data structures needed. */ pmi_ptr->idf_data_ptr = NO_MEMORY; } return (ALL_OKAY); }