/* * 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_finfo.c 1.27 05/08/19 SwRI" #include #include "ret_codes.h" #include "user_defs.h" #include "gen_defs.h" #include "libtrec_idfs.h" /******************************************************************************* * * * IR_ALLOC_FILL_INFO SUBROUTINE * * * * DESCRIPTION * * This routine is called in order to allocate the space that is needed to * * hold the information that is being returned by the FILL_DATA routine. For * * each sensor being processed, there are 5 (NUM_BUFFERS) working buffers. * * For each of the buffers, there are status flags that indicate the status * * of the buffer, 8 time values (btime_yr, btime_day, btime_sec, btime_nsec, * * etime_yr, etime_day, etime_sec and etime_nsec) that indicate the start and * * end time, in terms of the base time and resolution, of the start and stop * * pixel and an array of start pixel and end pixel values. For each sensor, * * there is one short allocated to hold the sensor number, one short allocated* * as an index value into another structure and one short to hold the number * * of units cumulative from the first sensor processed up to, but not * * including the sensor being processed. The data, bin status and * * normalization factors are also allocated by this routine. * * * * INPUT VARIABLES * * SDDAS_CHAR data_envelope flag indicating if data envelope (min/max) * * or just the data sample is being processed * * * * USAGE * * x = ir_alloc_fill_info (data_envelope) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * malloc() allocates memory * * ir_alloc_fill_data () allocates the space needed to hold the data * * and bin status buffers being processed and * * returned * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure that holds information concern- * * ing the experiment that is being processed * * * * INTERNAL VARIABLES * * struct experiment_info *ex a pointer to the structure that holds * * specific experiment information * * struct fill_data *fptr pointer to the fill_data structure being * * processed * * struct fill_sensor *sptr pointer to the fill_sensor structure being * * processed * * register SDDAS_SHORT i looping variable * * register SDDAS_SHORT sensor looping variable for sensor checkout * * size_t bytes_per_sensor the number of bytes for each sensor * * size_t bytes the number of bytes to allocate * * size_t num_bytes_slong the number of bytes needed for a SDDAS_LONG * * size_t num_bytes_sshort the number of bytes needed for a SDDAS_SHORT* * SDDAS_LONG offset offset into the allocated memory * * SDDAS_LONG max_size_slong number of bytes needed for NUM_BUFFER * * elements which are SDDAS_LONG data types * * SDDAS_LONG max_size_sshort number of bytes needed for maximum number of* * elements which are SDDAS_SHORT data types * * SDDAS_SHORT index index variable * * SDDAS_SHORT ret_val holds value returned by the called routine * * SDDAS_SHORT num_units the number of units or data levels for all * * sensors prior to the sensor being processed * * void *tmp_ptr pointer which holds address passed back by * * the call to the MALLOC routine * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_alloc_fill_info (SDDAS_CHAR data_envelope) { extern struct general_info ginfo; struct experiment_info *ex; struct fill_data *fptr; struct fill_sensor *sptr; register SDDAS_SHORT i, sensor; size_t bytes_per_sensor, bytes, num_bytes_slong, num_bytes_sshort; SDDAS_LONG offset, max_size_slong, max_size_sshort; SDDAS_SHORT index, ret_val, num_units; void *tmp_ptr; /**************************************************************************/ /* Five (NUM_BUFFERS) buffers are allocated, to handle the case where a */ /* previous partial exists, the new start is a partial of a new pixel, */ /* and the end is a partial of yet another pixel and there are full */ /* pixels in between. For example, work pix=4, start pix=2, stop pix=6. */ /**************************************************************************/ ex = ginfo.expt; fptr = ex->fill_arrays; /*************************************************************************/ /* Determine how many sensors are being processed. */ /*************************************************************************/ fptr->sensors_used = 0; for (sensor = 0; sensor < ex->num_sensor; ++sensor) fptr->sensors_used += ex->sensors_needed[sensor]; /***************************************************************************/ /* For each sensor, there needs to be a sensor number, index value and */ /* num_units entries. For each buffer, there needs to be bpix[num_buf], */ /* epix[num_buf], buf_status[num_buf], btime_yr[buf_num], */ /* btime_day[num_buf], btime_sec[num_buf], btime_nsec[num_buf] */ /* etime_yr[buf_num], etime_day[num_buf], etime_sec[num_buf] and */ /* etime_nsec[num_buf]. */ /***************************************************************************/ num_bytes_slong = sizeof (SDDAS_LONG); num_bytes_sshort = sizeof (SDDAS_SHORT); bytes_per_sensor = num_bytes_sshort + num_bytes_sshort + num_bytes_sshort; bytes = (bytes_per_sensor * fptr->sensors_used) + (num_bytes_slong + num_bytes_slong + sizeof (SDDAS_CHAR) + num_bytes_sshort + num_bytes_sshort + num_bytes_slong + num_bytes_slong + num_bytes_sshort + num_bytes_sshort + num_bytes_slong + num_bytes_slong) * NUM_BUFFERS; if ((tmp_ptr = malloc (bytes)) == NO_MEMORY) return (FILL_INFO_MALLOC); fptr->base = tmp_ptr; /*************************************************************************/ /* Set pointers to the allocated memory for the various variables. */ /* Cast base to char * since void * and offset is in bytes. */ /*************************************************************************/ max_size_slong = NUM_BUFFERS * num_bytes_slong; fptr->bpix = (SDDAS_LONG *) (fptr->base); offset = max_size_slong; fptr->epix = (SDDAS_LONG *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_slong; fptr->btime_sec = (SDDAS_LONG *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_slong; fptr->btime_nsec = (SDDAS_LONG *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_slong; fptr->etime_sec = (SDDAS_LONG *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_slong; fptr->etime_nsec = (SDDAS_LONG *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_slong; max_size_sshort = NUM_BUFFERS * num_bytes_sshort; fptr->btime_yr = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->btime_day = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->etime_yr = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->etime_day = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; max_size_sshort = num_bytes_sshort * fptr->sensors_used; fptr->sensors = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->ind_fill_sen = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->num_units = (SDDAS_SHORT *) ((SDDAS_CHAR *) fptr->base + offset); offset += max_size_sshort; fptr->buf_stat = (SDDAS_CHAR *) ((SDDAS_CHAR *) fptr->base + offset); /***************************************************************************/ /* Initialize the 5 (NUM_BUFFERS) buffers. */ /***************************************************************************/ for (i = 0; i < NUM_BUFFERS; ++i) { *(fptr->bpix + i) = -1; *(fptr->epix + i) = -1; *(fptr->btime_sec + i) = 0; *(fptr->btime_nsec + i) = 0; *(fptr->btime_day + i) = 0; *(fptr->btime_yr + i) = 0; *(fptr->etime_sec + i) = 0; *(fptr->etime_nsec + i) = 0; *(fptr->etime_day + i) = 0; *(fptr->etime_yr + i) = 0; *(fptr->buf_stat + i) = UNTOUCHED_BUFFER; } /*************************************************************************/ /* Set the flags to indicate that no sensor has yet to be processed. */ /*************************************************************************/ for (i = 0; i < fptr->sensors_used; ++i) *(fptr->sensors + i) = -1; /**************************************************************************/ /* Set the index value to the structure which holds the table application*/ /* flags and data cutoff points for each sensor being processed. */ /**************************************************************************/ for (sensor = 0, index = 0; sensor < ex->num_sensor; ++sensor) if (ex->sensors_needed[sensor] != 0) { /***********************************************************************/ /* Loop over all structures that were filled in by FILL_SENSOR_INFO().*/ /***********************************************************************/ for (i = 0; i < ex->num_fill_sensor; ++i) { sptr = ex->fill_sen_ptr + i; if (sensor == sptr->sensor_num) { *(fptr->ind_fill_sen + index) = i; ++index; break; } } } /*****************************************************************/ /* Determine the number of data level (units) buffers for all */ /* sensors prior to the sensor being processed. */ /*****************************************************************/ for (num_units = 0, i = 0; i < fptr->sensors_used; ++i) { sptr = ex->fill_sen_ptr + *(fptr->ind_fill_sen + i); *(fptr->num_units + i) = num_units; num_units += sptr->num_units; } /*****************************************************************/ /* Allocate the memory to hold the data values. */ /*****************************************************************/ ret_val = ir_alloc_fill_data (data_envelope); if (ret_val != ALL_OKAY) return (ret_val); return (ALL_OKAY); }