/* * 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 "@(#) alloc_exp.c 1.33 05/08/19 SwRI" #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" #include "libVIDF.h" /******************************************************************************* * * * IR_ALLOC_EXP_ONCE SUBROUTINE * * * * DESCRIPTION * * This routine is called to allocate memory for an experiment_info * * structure which holds the information read from the header and data records* * associated with the data set being processed. One structure is allocated * * for each of the different data sets. Once memory has been allocated, * * pointers to the header and data elements are assigned. * * * * INPUT VARIABLES * * SDDAS_SHORT btime_yr start time requested (year component) * * SDDAS_SHORT btime_day start time requested (day component) * * SDDAS_LONG btime_sec start time requested (seconds component) * * SDDAS_LONG btime_nsec start time requested (nanoseconds) * * SDDAS_SHORT etime_yr stop time requested (year component) * * SDDAS_SHORT etime_day stop time requested (day component) * * SDDAS_LONG etime_sec stop time requested (seconds component) * * SDDAS_LONG etime_nsec stop time requested (nanoseconds) * * void *data_ptr ptr to memory location for the structure * * that holds returned data values (either * * idf_data or tensor_data) * * * * USAGE * * x = ir_alloc_exp_once (btime_yr, btime_day, btime_sec, btime_nsec, * * etime_yr, etime_day, etime_sec, etime_nsec, * * data_ptr) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * free () frees previously allocated memory * * ir_read_header() reads data from the header file * * ir_sensor_combo() determines how many unique combinations * * exist among the tables used by all sensors * * ir_get_mode_info() retrieves any mode-dependent tables * * ReadVIDF() reads information from the VIDF file * * ir_alloc_timing () allocates and initializes some timing * * structures that are needed by FILL_DATA() * * * * 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 SDDAS_LONG *toff pointer to time offset values * * reg SDDAS_LONG *stop_toff loop termination variable * * SDDAS_ULONG data_key key which uniquely identifies the data set * * being processed * * SDDAS_LONG base_off comparison time offset value * * SDDAS_LONG offset index into allocated memory * * SDDAS_LONG start_at_zero param. passed to ReadVIDF to avoid casting * * SDDAS_LONG max_size_slong number of bytes needed for max_size elements* * which are SDDAS_LONG data types * * SDDAS_SHORT ret_val holds value returned by called routine * * SDDAS_SHORT max_size max. size for packed scalars or max elements* * in a sweep for a sweeping instrument * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * int rval the value returned by the called routine * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_alloc_exp_once (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, void *data_ptr) { extern struct general_info ginfo; struct experiment_info *ex; register SDDAS_LONG *toff, *stop_toff; SDDAS_ULONG data_key; SDDAS_LONG base_off, offset, start_at_zero, max_size_slong; SDDAS_SHORT ret_val, max_size; /* Leave variables as is, no typedefs. */ size_t bytes, num_bytes_slong; int rval; void *tmp_ptr; /*********************************************************************/ /* If the memory for the experiment_info structure associated with */ /* the experiment / virtual / extension combination has already */ /* been allocated, simply return. */ /*********************************************************************/ ex = ginfo.expt; data_key = ex->data_key; if (ex->info_ptr->h_size != -1) return (ALL_OKAY); /************************************************************************/ /* Get the different table combinations used by the various sensors. */ /************************************************************************/ ret_val = ir_sensor_combo (btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val != ALL_OKAY) return (ret_val); /************************************************************************/ /* Get the table(s) for the modes. */ /************************************************************************/ ret_val = ir_get_mode_info (btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val != ALL_OKAY) return (ret_val); /*************************************************************************/ /* Retrieve the information from the header record. */ /*************************************************************************/ ret_val = ir_read_header (data_ptr); if (ret_val != ALL_OKAY) { if (ret_val == RHDR_READ_ERROR) return (ALLOC_HDR_READ_ERROR); else if (ret_val == RHDR_HDR_MALLOC) return (ALLOC_HDR_MALLOC); else if (ret_val == RHDR_HDR_REALLOC) return (ALLOC_HDR_REALLOC); else return (ret_val); } /****************************************************************************/ /* Allocate space to save the milliseconds and nanoseconds start/stop time */ /* component for each sample. Cannot assume that the start of B = the end */ /* of A since timing may be parallel down the column so need two arrays. */ /* If instrument is a scalar, use the max_packing value in case of packed */ /* scalars, which will return 1 pitch for each packed value. */ /****************************************************************************/ num_bytes_slong = sizeof (SDDAS_LONG); if (ex->smp_id == 2) max_size = ex->max_packing; else max_size = ex->swp_len; max_size_slong = max_size * num_bytes_slong; /****************************************************************************/ /* Make sure memory has NOT already been allocated; either initial call or */ /* called when getting next file (LOS or EOF). If space has been */ /* previously allocated, free old memory before new space is allocated. */ /****************************************************************************/ if (ex->swp_times.base_time != NO_MEMORY) { free (ex->swp_times.base_time); ex->swp_times.base_time = NO_MEMORY; ex->swp_times.btime_ms = NO_MEMORY; ex->swp_times.btime_ns = NO_MEMORY; ex->swp_times.etime_ms = NO_MEMORY; ex->swp_times.etime_ns = NO_MEMORY; } bytes = (4 * num_bytes_slong) * max_size; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (SWEEP_TIME_MALLOC); ex->swp_times.base_time = tmp_ptr; ex->swp_times.btime_ms = (SDDAS_LONG *) ex->swp_times.base_time; /* Cast base_time to a char. ptr since it is void and offset is in bytes.*/ offset = max_size_slong; ex->swp_times.btime_ns = (SDDAS_LONG *)((SDDAS_CHAR *) ex->swp_times.base_time + offset); offset += max_size_slong; ex->swp_times.etime_ms = (SDDAS_LONG *)((SDDAS_CHAR *) ex->swp_times.base_time + offset); offset += max_size_slong; ex->swp_times.etime_ns = (SDDAS_LONG *)((SDDAS_CHAR *) ex->swp_times.base_time + offset); ex->swp_times.get_times = 1; /**************************************************************************/ /* Allocate the space that holds the time offset values for each sensor. */ /* Read in the offset values. If space has been previously allocated, */ /* free old memory before new space is allocated. */ /**************************************************************************/ bytes = ex->num_sensor * num_bytes_slong; if (ex->bmem.base_time_off != NO_MEMORY) { free (ex->bmem.base_time_off); ex->bmem.base_time_off = NO_MEMORY; } if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (TIME_OFF_MALLOC); ex->bmem.base_time_off = tmp_ptr; ex->time_off = (SDDAS_LONG *) ex->bmem.base_time_off; start_at_zero = 0; rval = ReadVIDF (data_key, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, (SDDAS_CHAR *) ex->time_off, _TIME_OFF, 0, start_at_zero, -1); if (rval < 0) { switch (rval) { case IDF_MANY_BYTES: return (EXP_IDF_MANY_BYTES); case IDF_TBL_NUM: return (EXP_IDF_TBL_NUM); case IDF_CON_NUM: return (EXP_IDF_CON_NUM); case IDF_NO_ENTRY: return (EXP_IDF_NO_ENTRY); case VIDF_ELEMENT_NOT_FOUND: return (EXP_IDF_ELE_NOT_FOUND); default: return ((SDDAS_SHORT) rval); } } /**********************************************************************/ /* If all time offsets are not the same, need to check each sensor's */ /* pixel location at each read. */ /**********************************************************************/ toff = ex->time_off; base_off = *toff++; stop_toff = ex->time_off + ex->num_sensor; for (; toff < stop_toff; ++toff) { if (*toff != base_off) { ex->all_or_one = 1; break; } } ret_val = ir_alloc_timing (); if (ret_val != ALL_OKAY) return (ret_val); return (ALL_OKAY); }