/* * 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 "@(#) assign_ptrs.c 1.21 05/08/19 SwRI" #include "gen_defs.h" #include "ret_codes.h" #include "libbase_idfs.h" #include "libVIDF.h" /* for header format comparison */ /***************************************************************************** * * * IR_ASSIGN_POINTERS SUBROUTINE * * * * DESCRIPTION * * This routine is called to set up the pointers to the header and data * * record elements. These pointers are set to point to elements that are * * single variables, in other words, within the header or data record * * structure, these elements do not come after a variable-length array. For * * elements that do come after a variable-length array, the routine * * ir_fix_pointers is called to assign the pointers. * * * * INPUT VARIABLES * * SDDAS_CHAR header_ptrs flag which indicates that the header * * pointers need to be reset * * SDDAS_CHAR data_ptrs flag which indicates that the data * * pointers need to be reset * * void *idf_data_ptr ptr to memory location for structure that * * holds returned data values (read_drec) * * * * USAGE * * x = ir_assign_pointers (header_ptrs, data_ptrs, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * sizeof () the size of the specified object in bytes * * ir_fix_pointers () assigns the pointers for those elements * * whose size may vary from header to header * * * * 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 ptr_rec *ptr a pointer to the structure which holds * * all pointers to the header and data for * * the experiment of interest * * SDDAS_LONG offset index into the memory allocated for the * * header and data information * * SDDAS_SHORT rval the value returned by the called routine * * size_t num_bytes_slong number of bytes needed for a SDDAS_LONG * * size_t num_bytes_sshort number of bytes needed for a SDDAS_SHORT * * * * SUBSYSTEM * * Display Level * * * *****************************************************************************/ SDDAS_SHORT ir_assign_pointers (SDDAS_CHAR header_ptrs, SDDAS_CHAR data_ptrs, void *idf_data_ptr) { extern struct general_info ginfo; register struct experiment_info *ex; register struct ptr_rec *ptr; SDDAS_LONG offset; SDDAS_SHORT rval; size_t num_bytes_slong, num_bytes_sshort; /***************************************************************************/ /* Set a pointer to the structure which holds all pointers for header and */ /* data information for the experiment currently being processed. */ /***************************************************************************/ ex = ginfo.expt; ptr = ex->info_ptr; num_bytes_slong = sizeof (SDDAS_LONG); num_bytes_sshort = sizeof (SDDAS_SHORT); if (header_ptrs) { /************************************************************************/ /* Assign the pointers for the header information. Year starts at an */ /* offset since header length is first. */ /************************************************************************/ offset = num_bytes_sshort; ptr->YEAR = (SDDAS_SHORT *)(ex->HEADER_MEM + offset); offset += num_bytes_sshort; ptr->DAYOFYEAR = (SDDAS_SHORT *)(ex->HEADER_MEM + offset); offset += num_bytes_sshort; ptr->TIME_UNITS = (SDDAS_CHAR *)(ex->HEADER_MEM + offset); offset += sizeof (SDDAS_CHAR); ptr->I_MODE = (SDDAS_UCHAR *)(ex->HEADER_MEM + offset); offset += sizeof (SDDAS_UCHAR); ptr->DATA_ACCUM = (SDDAS_LONG *)(ex->HEADER_MEM + offset); offset += num_bytes_slong; ptr->DATA_LAT = (SDDAS_LONG *)(ex->HEADER_MEM + offset); offset += num_bytes_slong; ptr->SWP_RESET = (SDDAS_LONG *)(ex->HEADER_MEM + offset); offset += num_bytes_slong; ptr->SEN_RESET = (SDDAS_LONG *)(ex->HEADER_MEM + offset); offset += num_bytes_slong; ptr->N_SEN = (SDDAS_SHORT *)(ex->HEADER_MEM + offset); offset += num_bytes_sshort; if (ex->header_format == ORIGINAL_HEADER) { ptr->hdr_fmt1_ptr->N_SAMPLE = (SDDAS_USHORT *)(ex->HEADER_MEM + offset); offset += sizeof (SDDAS_USHORT); ptr->hdr_fmt1_ptr->SAMP_INDEX = (SDDAS_SHORT *)(ex->HEADER_MEM + offset); } /* Old legacy systems need DQUAL_SIZE to be on a word boundary. */ else { ptr->hdr_fmt2_ptr->WORD_PAD = (SDDAS_SHORT *)(ex->HEADER_MEM + offset); offset += sizeof (SDDAS_SHORT); ptr->hdr_fmt2_ptr->DQUAL_SIZE = (SDDAS_ULONG *)(ex->HEADER_MEM + offset); } } if (data_ptrs) { /*************************************************************************/ /* Assign the pointers for the data information. */ /*************************************************************************/ ptr->TIME = (SDDAS_LONG *) (ex->DATA_MEM); offset = num_bytes_slong; ptr->SPIN = (SDDAS_LONG *) (ex->DATA_MEM + offset); offset += num_bytes_slong; ptr->SUN_SEN = (SDDAS_LONG *) (ex->DATA_MEM + offset); offset += num_bytes_slong; ptr->HDR_OFF = (SDDAS_LONG *) (ex->DATA_MEM + offset); /*************************************************************************/ /* HDR_OFF is an array of SDDAS_LONGs whose dimension is max_nss. */ /*************************************************************************/ offset += num_bytes_slong * ex->max_nss; ptr->NSS = (SDDAS_LONG *) (ex->DATA_MEM + offset); offset += num_bytes_slong; /*************************************************************************/ /* If a nansecond time adjustment factor is present, it will be placed */ /* at the beginning of the data array within the data record. If one */ /* is not defined, the value will be set to point to nothing. */ /*************************************************************************/ if (ex->nano_defined) { ptr->NANO_RES = (SDDAS_LONG *) (ex->DATA_MEM + offset); offset += num_bytes_slong; } else ptr->NANO_RES = NO_MEMORY; ptr->DATA = (SDDAS_UCHAR *) (ex->DATA_MEM + offset); } /****************************************************************************/ /* Set pointers that depend upon information read from a header record. */ /****************************************************************************/ if (header_ptrs) { rval = ir_fix_pointers (idf_data_ptr); if (rval != ALL_OKAY) return (rval); } return (ALL_OKAY); }