/* * 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 "@(#) fill_phi_pps.c 1.24 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_FILL_PHI_PPS SUBROUTINE * * * * DESCRIPTION * * This routine is called to fill in the phi data matrix with the data * * returned for the processed sensor. This routine is only invoked if the * * data storage is of type FIXED_STORAGE. There is one data set for each * * different set of units being requested. The start and stop azimuthal * * angles are used to determine which phi bins are processed. There is * * one set of start/stop azimuthal angles for each sweep step returned. * * The data is stored in the appropriate sweep bin by using the header * * returned sweep step number associated with the data sample(s). * * * * INPUT VARIABLES * * SDDAS_SHORT index index for the sensor being processed * * SDDAS_SHORT sensor sensor for which data is to be processed * * SDDAS_USHORT num_sample the number of elements per data buffer * * SDDAS_FLOAT time_frac percentage of the time resolution covered * * by the sweep * * void *idf_data_ptr ptr to memory location for the structure * * that holds returned data values (read_drec)* * SDDAS_CHAR cur_buf the buffer being processed (0 - 4) * * * * USAGE * * x = ir_fill_phi_pps (index, sensor, num_sample, time_frac, * * idf_data_ptr, cur_buf) * * * * NECESSARY SUBPROGRAMS * * ir_find_bin () determines the bin(s) a value falls within * * ir_mk_both_fracs() determins the fractional bin coverages by * * the data point * * ir_discrete_phi () stores data into phi bins using the sweep * * bands to find the bin(s) covered by the * * sample * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concerning * * the experiment that is being processed * * SDDAS_FLOAT *ir_units_data buffer space holding the values from the * * call to convert_to_units for each data * * level requested (used so only 1 call is * * needed data value) * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure holding the currently returned * * data values to be processed * * struct experiment_info pointer to the structure holding specific * * *ex experiment information * * struct fill_data *fptr pointer to current fill_data structure * * struct fill_sensor *sptr pointer to current fill_sensor structure * * struct collapse_data *cptr pointer to current collapse_data structure * * struct in_fill *mptr pointer to current data level combination * * struct in_fill *end_mptr last element in *mptr array * * struct bin_info *bptr pointer to current sweep binning info struc* * reg SDDAS_FLOAT *tbuf_ele pointer to individual element of converted * * data level sub-buffers * * register SDDAS_FLOAT *f1 pointer to fracs array * * register SDDAS_FLOAT *f4 pointer to minimum edge in phi step * * register SDDAS_FLOAT *f5 pointer to maximum edge in phi step * * reg SDDAS_FLOAT *f5_end last element in stop_phi array * * register SDDAS_LONG *l1 pointer to sweep steps * * SDDAS_FLOAT *tmp_buf pointer to converted data level sub-buffers* * SDDAS_FLOAT *tmp_plow pointer to lowest phi edge * * SDDAS_FLOAT *tmp_phigh pointer to higest phi edge * * SDDAS_FLOAT *dptr pointer to data matrix being initialized * * SDDAS_FLOAT *tfrac pointer to the normalization factors * * SDDAS_FLOAT *base_data pointer to current phi matrix bins * * SDDAS_FLOAT *base_frac pointer to current normalization factors * * SDDAS_FLOAT stop_az ending azimuthal angle * * SDDAS_FLOAT pmxmn[] overall min and max phi bin values * * SDDAS_FLOAT fracs[] array of fraction bin coverages. There * * are 5 elements: (0) % of data in start phi * * bin; (1) % of data in end phi bin; (2) % * * data in time interval; (3) % data in start * * sweep bin; (4) % data in end sweep bin * * SDDAS_FLOAT *phi_low pointer to lowest phi bin edge * * SDDAS_FLOAT *phi_high pointer to higest phi bin edge * * SDDAS_FLOAT *temp temporary pointer * * SDDAS_LONG offset holds various offsets into arrays * * SDDAS_SHORT num_theta number of theta bins (may be one per * * sensor if no elevation constants) * * SDDAS_SHORT pbins[] low and high phi bin elements * * SDDAS_CHAR *base_bin pointer to the beginning of the bin status * * array for the phi bin being processed * * SDDAS_CHAR *bin_stat pointer to the bin status array * * char pos_dir flag indicating if instrument is spinning * * in a positive or negative direction * * SUBSYSTEM * * Display Level * * * * OPTIMAZATION STATUS * * Fully optimized * * * * HANDLES * * This routine handles the demand that the several demands that were * * introduced while optimizing lower routine including * * 1) The correct incrementing of the tmp_buf pointer * * 2) The computation of the maximum phi and sweep bin values * * 3) The correct ordering of the bin arrays * ***************************************************************************/ SDDAS_SHORT ir_fill_phi_pps (SDDAS_SHORT index, SDDAS_SHORT sensor, SDDAS_USHORT num_sample, SDDAS_FLOAT time_frac, void *idf_data_ptr, SDDAS_CHAR cur_buf) { extern struct general_info ginfo; extern SDDAS_FLOAT *ir_units_data; struct idf_data *EXP_DATA; struct experiment_info *ex; struct fill_data *fptr; struct fill_sensor *sptr; struct collapse_data *cptr; struct in_fill *mptr, *end_mptr; struct bin_info *bptr; register SDDAS_FLOAT *tbuf_ele, *f1, *f4, *f5, *f5_end; register SDDAS_LONG *l1; SDDAS_FLOAT *tmp_plow, *tmp_phigh, *dptr, *tfrac, *base_data, *base_frac; SDDAS_FLOAT stop_az, pmxmn[2], fracs[5], *phi_low, *phi_high, *temp; SDDAS_FLOAT *tmp_buf; SDDAS_LONG offset; SDDAS_SHORT num_theta, pbins[2]; SDDAS_CHAR *base_bin, *bin_stat; char pos_dir; /*********************************************************************/ /* Set up pointers to the structures which will be used in this */ /* routine */ /*********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; bptr = ex->bin_ptr; cptr = ex->collapse_ptr; fptr = ex->fill_arrays; sptr = ex->fill_sen_ptr + *(fptr->ind_fill_sen + index); /*********************************************************************/ /* First condition for this routine to work correctly is that all */ /* of the sensors must be processing the same number of phi */ /* matrices - one per requested physical units */ /*********************************************************************/ if (sptr->num_units != cptr->num_units) return (PHI_DIFF_UNITS); /*********************************************************************/ /* Begin a somewhat lengthy setup of all of the arrays which will */ /* used in placing the data. The setups perform several functions. */ /* The first is to establish the location of the band edges of the */ /* bins in which the data is to be placed. In the case of discrete */ /* bands the band edges are stored in separate arrays, one for the */ /* set of low edges and one for the set of upper edges. In the case */ /* of continuous bands the upper edge of one band is the lower edge */ /* of the next band. This must be set for the sweep step arrays, */ /* the created sweep band arrays, and the phi angle arrays. */ /*********************************************************************/ phi_low = cptr->phi_bands; phi_high = phi_low + 1; /*********************************************************************/ /* Now that the edge locations of the different band edges have been */ /* located we must save the location of the lower and upper edges of */ /* the sweep and phi bins. These are needed for the computation of */ /* the fractional filling. There are saved because when the band */ /* edges are shuffled so that the lower edge becomes also the edge */ /* with the minimum value the original designation is lost */ /*********************************************************************/ tmp_plow = phi_low; tmp_phigh = phi_high; /*********************************************************************/ /* Third, the search routines which locate the apprpriate bins in */ /* which the data is to be placed want to see the bins presented in */ /* ascending order - that is the lower edge being the smaller in */ /* of the two edges. At this time if the band edges need to be */ /* switched go ahead and do so. At the same time grab the least and */ /* greatest value which can be stored within these bands. This will */ /* be used to prevent try to locate a bin for a data value which has */ /* none within these bins. */ /*********************************************************************/ if (*phi_low < *phi_high) { pmxmn[0] = *phi_low; pmxmn[1] = *(phi_high + cptr->phi_bins - 1); } else { pmxmn[0] = *(phi_high + cptr->phi_bins - 1); pmxmn[1] = *phi_low; temp = phi_low; phi_low = phi_high; phi_high = temp; } /*********************************************************************/ /* Set the inital offsets into the correct set of bins for the */ /* sensor being processed */ /*********************************************************************/ offset = (cptr->theta_bins >= 0) ? *(cptr->sensor_bin + sensor) * bptr->num_bins * cptr->phi_bins : sensor * bptr->num_bins * cptr->phi_bins; base_data = *(cptr->data_4d_ptr + cur_buf) + offset; base_frac = *(cptr->tot_frac_4d_ptr + cur_buf) + offset; base_bin = *(cptr->bin_stat_ptr + cur_buf) + offset; num_theta = (cptr->theta_bins <= 0) ? ex->num_sensor : cptr->theta_bins; /*********************************************************************/ /* Set up some initial constants - these are: */ /* 1) pointer to fracs array which will hold all fractional filling */ /* values. */ /* 2) set second element in fracs array to time_frac */ /* 3) set a loop terminator to last element in phi stop angle array */ /* 4) set direction of phi array */ /*********************************************************************/ f1 = fracs; *(f1+2) = time_frac; f5_end = EXP_DATA->stop_az + num_sample; pos_dir = (EXP_DATA->start_az[0] < EXP_DATA->stop_az[0]) ? 1 : 0; /*********************************************************************/ /* Set up the intial pointers into the phi storage matrices. These */ /* hold the data (tmp_buf), the fractional filling of each element */ /* (tfrac), and status values for each element */ /*********************************************************************/ offset = bptr->num_bins * num_theta * cptr->phi_bins; tmp_buf = ir_units_data; dptr = base_data; tfrac = base_frac; bin_stat = base_bin; mptr = sptr->min_max_app; end_mptr = mptr + sptr->num_units; /*********************************************************************/ /* The of the phi array begins here according to the following */ /* outine */ /* */ /* 1) Outside loop loops over each of the possible sets of physical */ /* units that must be loaded */ /* 2) Set up intial pointers the data edges. */ /* 3) At this time the processing is split depending on whether the */ /* data phi angles are increasing or decreasing. The processing */ /* is identical with the exception of which phi edge is used as */ /* the intial and final band edge */ /* 4) Set up initial and final phi band edges */ /* 5) Set the stop phi angle to a temporary value (it needs further */ /* processing and we don't what to change the original value */ /* 6) The ending phi value must be put in the range 0-360 degrees */ /* 7) Find the phi bins covered by the data */ /* 8) Find the fractional coverage in the phi bins */ /* 9) If the phi angles were not within the bin - whoops - get out */ /* 10) Find the sweep bins covered by the data */ /* 11) Find the fractional coverage in the sweep bins */ /* 12) If the sweep value is in the bin range go ahead and stuff the */ /* data into the phi array */ /*********************************************************************/ for ( ; mptr < end_mptr; ++mptr, dptr += offset, tfrac += offset, bin_stat += offset, tmp_buf += ex->swp_len) { l1 = EXP_DATA->swp_data; tbuf_ele = tmp_buf; if (pos_dir) { f4 = EXP_DATA->start_az; f5 = EXP_DATA->stop_az; for ( ; f5 < f5_end; ++tbuf_ele) { stop_az = *f5++; if (stop_az < 0.0) stop_az += 360.0; else if (stop_az > 360.0) stop_az -= 360.0; ir_find_bin (*f4, stop_az, phi_low, phi_high, pmxmn, pbins, BAND_STORAGE, LIN_SPACING, cptr->phi_bins); ir_mk_both_fracs (*f4++, stop_az, tmp_plow, tmp_phigh, pbins, f1); if (pbins[0] == -1) return (FILL_PHI_FIRST); else if (pbins[1] == -1) return (FILL_PHI_LAST); ir_discrete_phi (dptr, tfrac, bin_stat, tbuf_ele, &mptr->sen_min, pbins, (SDDAS_SHORT)*l1++, fracs); } } else { f5 = EXP_DATA->start_az; f4 = EXP_DATA->stop_az; for ( ; f4 < f5_end; ++tbuf_ele) { stop_az = *f4++; if (stop_az < 0.0) stop_az += 360.0; else if (stop_az > 360.0) stop_az -= 360.0; ir_find_bin (stop_az, *f5, phi_low, phi_high, pmxmn, pbins, BAND_STORAGE, LIN_SPACING, cptr->phi_bins); ir_mk_both_fracs (stop_az, *f5++, tmp_plow, tmp_phigh, pbins, f1); if (pbins[0] == -1) return (FILL_PHI_FIRST); else if (pbins[1] == -1) return (FILL_PHI_LAST); ir_discrete_phi (dptr, tfrac, bin_stat, tbuf_ele, &mptr->sen_min, pbins, (SDDAS_SHORT)*l1++, fracs); } } } return (ALL_OKAY); }