/* * 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_background.c 22018 2012-12-05 18:59:24Z carrie $ SwRI" #include #include #include "ret_codes.h" #include "gen_defs.h" #include "libbase_idfs.h" /******************************************************************************* * * * IR_ALLOC_BACKGROUND_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called to allocate the structure that holds background * * 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 background_format specifies method of background computation* * * * USAGE * * x = ir_alloc_background_info (etime_yr, etime_day, etime_sec, etime_nsec,* * background_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 background_info a pointer to the structure that holds * * *bkgd_ptr background information * * register SDDAS_SHORT i looping variable * * SDDAS_LONG offset index into allocated memory * * SDDAS_LONG num_elements number of elements to process * * 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_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_background_info (SDDAS_SHORT etime_yr, SDDAS_SHORT etime_day, SDDAS_LONG etime_sec, SDDAS_LONG etime_nsec, SDDAS_SHORT background_format) { extern struct general_info ginfo; struct experiment_info *ex; register struct background_info *bkgd_ptr; register SDDAS_SHORT i; SDDAS_LONG offset, num_elements; SDDAS_SHORT max_size; size_t bytes, num_bytes_sfloat, num_bytes_sshort, num_bytes_schar; void *tmp_ptr; /**************************************************************************/ /* Allocate the structure that holds the background info. */ /**************************************************************************/ ex = ginfo.expt; bytes = sizeof (struct background_info); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (BKGD_MALLOC); ex->bmem.base_background_info = tmp_ptr; ex->background = (struct background_info *) ex->bmem.base_background_info; bkgd_ptr = ex->background; bkgd_ptr->background_format = background_format; strcpy (bkgd_ptr->exten, ex->exten); bkgd_ptr->get_background_data = 1; bkgd_ptr->file_status = 0; /**************************************************************************/ /* Save time passed to FILE_OPEN for parent data set. */ /**************************************************************************/ bkgd_ptr->stop_year = etime_yr; bkgd_ptr->stop_day = etime_day; bkgd_ptr->stop_sec = etime_sec; bkgd_ptr->stop_nano = etime_nsec; /**************************************************************************/ /* Initialize those values not read from the VIDF file. */ /**************************************************************************/ bkgd_ptr->copy_next_data = sFalse; bkgd_ptr->copy_all_done = sFalse; bkgd_ptr->last_comp_frac = 0.0; bkgd_ptr->base_tbls = NO_MEMORY; bkgd_ptr->tbl_apply = NO_MEMORY; bkgd_ptr->tbl_oper = NO_MEMORY; bkgd_ptr->tbl_offset = NO_MEMORY; bkgd_ptr->base_sensors = NO_MEMORY; bkgd_ptr->data_values = NO_MEMORY; bkgd_ptr->last_data_value = NO_MEMORY; bkgd_ptr->sensor = NO_MEMORY; bkgd_ptr->time_frac = NO_MEMORY; bkgd_ptr->next_data = NO_MEMORY; bkgd_ptr->all_done = NO_MEMORY; bkgd_ptr->num_tbls = 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. */ /****************************************************************************/ bkgd_ptr->cur_time.byear = 0; bkgd_ptr->cur_time.bday = 0; bkgd_ptr->cur_time.bmilli = 0; bkgd_ptr->cur_time.bnano = 0; bkgd_ptr->cur_time.eyear = 0; bkgd_ptr->cur_time.eday = 0; bkgd_ptr->cur_time.emilli = 0; bkgd_ptr->cur_time.enano = 0; /*************************************************************************/ /* The background information is to be retrieved from the IDFS data */ /* source using the sensors specified, which is of the data type */ /* SDDAS_SHORT. Once converted, data is transferred to 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. */ /*************************************************************************/ num_bytes_sfloat = sizeof (SDDAS_FLOAT); num_bytes_sshort = sizeof (SDDAS_SHORT); num_bytes_schar = sizeof (SDDAS_CHAR); if (bkgd_ptr->background_format == BKGD_DSRC) { if (ex->smp_id == 2) max_size = ex->max_packing; else max_size = ex->swp_len; num_elements = ex->num_sensor * max_size; bytes = (num_bytes_sfloat + num_bytes_sfloat) * num_elements; bytes += (num_bytes_sshort) * ex->num_sensor; bytes += (num_bytes_schar + num_bytes_schar + num_bytes_schar) * ex->num_sensor; /************************************************************************/ /* Don't forget to save the last background value read for each sensor. */ /************************************************************************/ bytes += num_bytes_sfloat * ex->num_sensor; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (BKGD_DATA_MALLOC); bkgd_ptr->base_sensors = tmp_ptr; bkgd_ptr->data_values = (SDDAS_FLOAT *) bkgd_ptr->base_sensors; /* Cast base_sensors to a char. ptr since void and offset is in bytes. */ offset = num_elements * num_bytes_sfloat; bkgd_ptr->time_frac = (SDDAS_FLOAT *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); offset += num_elements * num_bytes_sfloat; bkgd_ptr->sensor = (SDDAS_SHORT *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); /*************************************************************************/ /* Since there is one idf_data structure per defined sensor, need */ /* ex->num_sensor file manipulation flags. */ /*************************************************************************/ offset += ex->num_sensor * num_bytes_sshort; bkgd_ptr->next_data = (SDDAS_CHAR *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); offset += ex->num_sensor * num_bytes_schar; bkgd_ptr->all_done = (SDDAS_CHAR *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); offset += ex->num_sensor * num_bytes_schar; bkgd_ptr->num_tbls = (SDDAS_CHAR *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); offset += ex->num_sensor * num_bytes_schar; bkgd_ptr->last_data_value = (SDDAS_FLOAT *) ((SDDAS_CHAR *) bkgd_ptr->base_sensors + offset); /**************************************************************************/ /* Allocate space to hold the addresses of all allocated data structures.*/ /**************************************************************************/ bytes = ex->num_sensor * sizeof (void *); if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (BKGD_IDF_DATA_MALLOC); bkgd_ptr->idf_data_ptr = (void **) tmp_ptr; for (i = 0; i < ex->num_sensor; ++i) { *(bkgd_ptr->idf_data_ptr + i) = NO_MEMORY; *(bkgd_ptr->last_data_value + i) = NO_MEMORY; *(bkgd_ptr->next_data + i) = 1; *(bkgd_ptr->all_done + i) = 0; *(bkgd_ptr->num_tbls + i) = 0; } } /****************************************************************************/ /* The background info. 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 (bkgd_ptr->background_format == BKGD_CONSTANT) { bytes = num_bytes_sfloat * ex->num_sensor; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (BKGD_DATA_MALLOC); bkgd_ptr->base_sensors = tmp_ptr; bkgd_ptr->data_values = (SDDAS_FLOAT *) bkgd_ptr->base_sensors; /* No idf_data structures needed. */ bkgd_ptr->idf_data_ptr = NO_MEMORY; } return (ALL_OKAY); }