/* * 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: extract1D.c 20910 2010-10-21 20:53:53Z carrie $ SwRI" #include "libIDFSTensor.h" /******************************************************************************* * * * EXTRACT_FROM_1DTENSOR SUBROUTINE * * * * DESCRIPTION * * This routine is called to extract elements from a tensor with a rank of * * one. A single element extraction from the tensor is handled by the * * calling routine. However, for resultants of rank 1, this routine is * * called. The starting position (index) within each dimension of the tensor * * is provided, along with the stop position (index), which taken together, * * define the subset of data to be extracted along each dimension. Since the * * tensor being extraced from is a 1-D tensor, the only scenario under which * * this module is called is the case when the index values represent a subset * * (range) of data values to be extracted from that particular dimension. * * The rank of the resultant is based upon the start/stop index values * * provided. For each pair of start/stop index values that are the same, the * * rank of the resultant should be decremented by one. For example, the * * start/stop index values defined as: * * start_ind[1] = {0} stop_ind[1] = {3} * * should be inferred to result in a 1-D tensor that is 4 elements in size. * * If the index values were defined as: * * start_ind[1] = {2} stop_ind[1] = {2} * * the resultant would be a scalar value of rank 0 and would be extracted by * * the module that calls this routine, not by this routine. * * * * INPUT VARIABLES * * void *tensorA pointer to the input tensor being processed * * void *res_ptr ptr to memory allocated for resultant value(s) * * void *start_ind start index position for each dimension defined* * for the given tensor argument * * void *stop_ind stop index position for each dimension defined * * for the given tensor argument * * SDDAS_BOOL double_precision flag indicating if arguments are double- * * precision values * * * * USAGE * * extract_from_1Dtensor (&tensorA, &res_ptr, &start_ind, &stop_ind, * * double_precision) * * * * NECESSARY SUBPROGRAMS * * None * * * * EXTERNAL VARIABLES * * None * * * * INTERNAL VARIABLES * * reg SDDAS_LONG loop0 looping variable for each dimension of tensor * * reg SDDAS_LONG loop0_end loop termination variable * * reg SDDAS_DOUBLE *tensor_ddata ptr to tensor data (double-precision) * * reg SDDAS_DOUBLE *dresultant ptr to the resultant (double-precision) * * reg SDDAS_FLOAT *tensor_fdata ptr to tensor data (floating point) * * reg SDDAS_FLOAT *fresultant ptr to the resultant (floating point) * * SDDAS_DOUBLE *tensor_double pointer to the input tensor being processed * * SDDAS_DOUBLE *result_double ptr to memory allocated for resultant * * SDDAS_DOUBLE *start_double start index position for each dimension * * defined for the given tensor argument * * SDDAS_DOUBLE *stop_double stop index position for each dimension * * defined for the given tensor argument * * SDDAS_FLOAT *tensor_float pointer to the input tensor being processed * * SDDAS_FLOAT *result_float ptr to memory allocated for resultant * * SDDAS_LONG *start_long start index position for each dimension * * defined for the given tensor argument * * SDDAS_LONG *stop_long stop index position for each dimension * * defined for the given tensor argument * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ void extract_from_1Dtensor (void *tensorA, void *res_ptr, void *start_ind, void *stop_ind, SDDAS_BOOL double_precision) { register SDDAS_LONG loop0, loop0_end; register SDDAS_DOUBLE *tensor_ddata, *dresultant; register SDDAS_FLOAT *tensor_fdata, *fresultant; SDDAS_DOUBLE *tensor_double, *result_double, *start_double, *stop_double; SDDAS_FLOAT *tensor_float, *result_float; SDDAS_LONG *start_long, *stop_long; /* The tensor from which we are extracting is a 1-D tensor. Go over */ /* the desired sub-area, extracting the requested elements. */ /* This code is shared by libbase_idfs and SCF code; SCF deals with */ /* double-precision data and IDFS deals with single-precision floats. */ /* MUST maintain double-precision even for indices; otherwise, code */ /* fails since incorrect values are extracted. */ if (double_precision == sTrue) { tensor_double = (SDDAS_DOUBLE *) tensorA; result_double = (SDDAS_DOUBLE *) res_ptr; start_double = (SDDAS_DOUBLE *) start_ind; stop_double = (SDDAS_DOUBLE *) stop_ind; loop0 = *start_double; loop0_end = *stop_double; tensor_ddata = tensor_double + loop0; dresultant = result_double; for (; loop0 <= loop0_end; ++loop0, ++tensor_ddata, ++dresultant) *dresultant = *tensor_ddata; } else { tensor_float = (SDDAS_FLOAT *) tensorA; result_float = (SDDAS_FLOAT *) res_ptr; start_long = (SDDAS_LONG *) start_ind; stop_long = (SDDAS_LONG *) stop_ind; loop0 = *start_long; loop0_end = *stop_long; tensor_fdata = tensor_float + loop0; fresultant = result_float; for (; loop0 <= loop0_end; ++loop0, ++tensor_fdata, ++fresultant) *fresultant = *tensor_fdata; } }