/* * 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 "@(#) end_mode.c 1.15 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "libtrec_idfs.h" /******************************************************************************* * * * IR_END_MODE_EQUAL_WORKING SUBROUTINE * * * * DESCRIPTION * * This routine is called to process mode data when the stop pixel location * * is equal to the working pixel location and the start pixel is less than * * the end pixel. In other words, time went backwards and covered the time * * period associated with the current pixel location. (ex. pix = 4, start = 2,* * stop = 4). Since the data is not contained in a single pixel, use bfrac * * and efrac, not time_frac. The current working buffer may either be a full * * or partial buffer, depending upon the fraction of the data associated with * * that pixel. The data is added to the working buffer and this buffer * * remains as the current working buffer. The buffer for the starting pixel * * is flagged as being ready to process since time went backwards. It is up * * to the user whether to include this data or not. The MORE_DATA flag is * * set to terminate processing so that the full buffers can be accessed. * * There may be full buffers in between the start and working locations, as * * reflected in the example shown above where the data covers pixel 3 * * completely. * * * * INPUT VARIABLES * * SDDAS_LONG pix_start starting pixel location which this data set * * is associated with * * SDDAS_LONG pix_end ending pixel location which this data set * * is associated with * * SDDAS_CHAR buf_num the buffer being processed (0 - 4) * * SDDAS_SHORT index indexing variable used to access the correct * * mode variables * * SDDAS_FLOAT bfrac fraction of the data associated with the start* * time's pixel location (start time of the data)* * SDDAS_FLOAT efrac fraction of the data associated with the end * * time's pixel location (end time of the data) * * SDDAS_CHAR *more_data flag indicating when to terminate processing * * of data * * SDDAS_CHAR *last_buf the last buffer processed (0 - 4) * * SDDAS_CHAR chk_buffers flag that indicates if there is a need to * * check if all buffers have been utilized * * SDDAS_SHORT *pix_yr, start time, in terms of the base time and * * *pix_day resolution, for the buffer's start pixel * * SDDAS_LONG *pix_sec, start time, in terms of the base time and * * *pix_nsec resolution, for the buffer's start pixel * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * * * USAGE * * x = ir_end_mode_equal_working (pix_start, pix_end, buf_num, index, bfrac,* * efrac, &more_data, &last_buf, chk_buffers, * * &pix_yr, &pix_day, &pix_sec, &pix_nsec, * * idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_full_mode_pixels() processes buffers which utilize 100% of the * * data (data spans many pixels) * * ir_mode_buffer () stores values in the data buffers returned * * ir_get_mode_buffer_number() returns the next available buffer * * adjust_time () corrects time elements if too many seconds * * (day crossing) or too many days (year * * crossing) * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure that holds information concerning * * the experiment that is being processed * * SDDAS_FLOAT *ir_units_data buffer space used to hold the values from the * * call to convert_to_units for each data level * * requested (used so only 1 call is needed per * * data value) * * * * INTERNAL VARIABLES * * struct experiment_info a pointer to the structure that holds * * *ex specific experiment information * * struct fill_mode *fptr pointer to the fill_mode structure being * * processed * * struct fill_sensor *sptr pointer to the fill_sensor structure being * * processed * * struct in_fill *mptr pointer to the data level combination being * * processed * * struct in_fill *mptr_end loop termination variable * * reg SDDAS_FLOAT *tmp_buf pointer to the converted data levels * * register SDDAS_FLOAT *dptr pointer to the data array * * reg SDDAS_FLOAT *tfrac pointer to the normalization factors * * reg SDDAS_CHAR *bin_stat pointer to the bin status array * * SDDAS_FLOAT set_frac the fraction of the data value to be added * * to or included in the buffer * * SDDAS_FLOAT *base_data pointer to BUFFER 0 for this mode * * SDDAS_FLOAT *base_frac pointer to BUFFER 0 normalization factors for * * this mode * * SDDAS_LONG offset offset value to get to the data of interest * * SDDAS_LONG save_sec, save_nsec start time of pixel before modification * * SDDAS_LONG end_sec, end time, in terms of the base time and * * end_nsec resolution, for the buffer's start pixel * * SDDAS_SHORT new_buffer next free buffer to be used * * SDDAS_SHORT yr, day temporary year and dayofyear values * * SDDAS_CHAR *base_bin pointer to BUFFER 0 bin status array for * * this mode * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_end_mode_equal_working (SDDAS_LONG pix_start, SDDAS_LONG pix_end, SDDAS_CHAR buf_num, SDDAS_SHORT index, SDDAS_FLOAT bfrac, SDDAS_FLOAT efrac, SDDAS_CHAR *more_data, SDDAS_CHAR *last_buf, SDDAS_CHAR chk_buffers, SDDAS_SHORT *pix_yr, SDDAS_SHORT *pix_day, SDDAS_LONG *pix_sec, SDDAS_LONG *pix_nsec, void *idf_data_ptr) { extern struct general_info ginfo; extern SDDAS_FLOAT *ir_units_data; struct experiment_info *ex; struct fill_mode *fptr; struct fill_sensor *sptr; struct in_fill *mptr, *mptr_end; register SDDAS_FLOAT *tmp_buf, *dptr, *tfrac; register SDDAS_CHAR *bin_stat; SDDAS_FLOAT set_frac, *base_data, *base_frac; SDDAS_LONG offset, save_sec, save_nsec, end_sec, end_nsec; SDDAS_SHORT new_buffer, yr, day; SDDAS_CHAR *base_bin; /************************************************************************/ /* Set pointers to the memory allocated to process the current mode, */ /* with index used to get to the correct mode offset. Set the data */ /* pointer to the beginning of the first buffer (buffer 0) for this */ /* mode. */ /************************************************************************/ ex = ginfo.expt; fptr = ex->mode_arrays; sptr = ex->mode_info_ptr + *(fptr->ind_fill_mode + index); offset = NUM_BUFFERS * *(fptr->num_units + index); base_data = fptr->data + offset; base_frac = fptr->tot_frac + offset; base_bin = fptr->bin_stat + offset; /**********************************************************************/ /* Include the fraction of the data that belongs to the current */ /* working pixel. This buffer will remain as the current working */ /* buffer. If the fraction indicates a partial pixel, the buffer is */ /* flagged as a working partial buffer. If the ending pixel is 100% */ /* covered by the data value, this buffer is ready to be plotted. */ /* Set the data pointer to the first sub-buffer associated with the */ /* data buffer (0-4) being processed. */ /**********************************************************************/ *last_buf = buf_num; set_frac = efrac; if (efrac < 1.0) *(fptr->buf_stat + buf_num) = PARTIAL_WORKING; else { *(fptr->epix + buf_num) = pix_end; *(fptr->buf_stat + buf_num) = BUFFER_READY; } /********************************************************************/ /* Point to the data for the current buffer being processed. */ /********************************************************************/ offset = buf_num * sptr->num_units; dptr = base_data + offset; tfrac = base_frac + offset; bin_stat = base_bin + offset; /**********************************************************************/ /* Transfer the converted data into the buffers for all data levels. */ /* Index into ir_units_data by one since only one mode value is */ /* returned by READ_DREC(). */ /**********************************************************************/ offset = 0; tmp_buf = ir_units_data; mptr = sptr->min_max_app; mptr_end = mptr + sptr->num_units; for (; mptr < mptr_end; ++mptr, ++offset, ++tmp_buf) ir_mode_buffer (&mptr->sen_min, set_frac, offset, dptr, tfrac, bin_stat, tmp_buf); /*********************************************************************/ /* Get the next available free buffer. */ /*********************************************************************/ new_buffer = ir_get_mode_buffer_number (buf_num, chk_buffers); if (new_buffer < 0) return (new_buffer); buf_num = (SDDAS_CHAR) new_buffer; /**********************************************************************/ /* The data value spans many pixels. */ /**********************************************************************/ save_sec = *pix_sec; save_nsec = *pix_nsec; if (pix_end - pix_start > 1) { new_buffer = ir_full_mode_pixels (pix_start, pix_end, buf_num, index, chk_buffers, pix_yr, pix_day, pix_sec, pix_nsec, idf_data_ptr); if (new_buffer < 0) return (new_buffer); buf_num = (SDDAS_CHAR) new_buffer; } /**********************************************************************/ /* Set the fraction of the data that belongs to the starting pixel. */ /* No need for += since new buffer is being used. Time variables */ /* are cumulative from the base reference time; nanosecond component */ /* already adjusted to stay within boundary range. */ /**********************************************************************/ set_frac = 1.0 - bfrac; yr = *pix_yr; day = *pix_day; end_sec = save_sec; adjust_time (&yr, &day, &end_sec, 1); *(fptr->bpix + buf_num) = pix_start; *(fptr->epix + buf_num) = pix_start; *(fptr->btime_sec + buf_num) = end_sec; *(fptr->btime_nsec + buf_num) = save_nsec; *(fptr->btime_day + buf_num) = day; *(fptr->btime_yr + buf_num) = yr; end_sec = save_sec; end_nsec = save_nsec; ir_next_pixel_time (1, &end_sec, &end_nsec, 1); yr = *pix_yr; day = *pix_day; adjust_time (&yr, &day, &end_sec, 1); *(fptr->etime_sec + buf_num) = end_sec; *(fptr->etime_nsec + buf_num) = end_nsec; *(fptr->etime_day + buf_num) = day; *(fptr->etime_yr + buf_num) = yr; *(fptr->buf_stat + buf_num) = BUFFER_READY; /********************************************************************/ /* Set the data pointer to the first sub-buffer associated with */ /* the data buffer (0-4) being processed. */ /********************************************************************/ offset = buf_num * sptr->num_units; dptr = base_data + offset; tfrac = base_frac + offset; bin_stat = base_bin + offset; /**********************************************************************/ /* Transfer the converted data into the buffers for all data levels. */ /* Index into ir_units_data by one since only one mode value is */ /* returned by READ_DREC(). */ /**********************************************************************/ offset = 0; tmp_buf = ir_units_data; mptr = sptr->min_max_app; mptr_end = mptr + sptr->num_units; for (; mptr < mptr_end; ++mptr, ++offset, ++tmp_buf) ir_mode_buffer (&mptr->sen_min, set_frac, offset, dptr, tfrac, bin_stat, tmp_buf); *more_data = 0; return (ALL_OKAY); }