/* * 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 "@(#) work_dbet.c 1.18 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "libtrec_idfs.h" /******************************************************************************* * * * IR_WORKING_DISC_BETWEEN SUBROUTINE * * * * DESCRIPTION * * This routine is called to process the discontinuous data when the range * * of the start and end pixel locations includes the working pixel. Time * * went backwards and covered the time period associated with the current * * pixel location (ex. pix = 4, start = 2, stop = 6). Since the working * * pixel is found in between the start and stop locations, the buffer * * associated with the working pixel is flagged as a buffer that is ready to * * be accessed, the MORE_DATA flag is set to terminate processing so that the * * full buffers can be accessed, and the current working buffer number is * * updated. The data spans many pixels. The start pixel location is flagged * * as a buffer that is ready to be processed since time went backwards and * * included the current working pixel. The ending pixel buffer may either be * * a full or partial buffer, depending upon the fraction of the data * * associated with that pixel. There may be full buffers in between the * * start and working locations and the working and end locations, as * * reflected in the example shown above where the data covers pixels 3 and 5 * * completely. Remember that the discontinuous data is kept in temporary * * data matrices UNTIL the buffer is flagged as BUFFER_READY, at which point, * * the discontinuous data is transferred into the buffer of interest. * * * * 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_LONG working_pix the current pixel location being processed * * SDDAS_LONG *pix_sec, start time, in terms of the base time and * * *pix_nsec resolution, for the buffer's start pixel * * SDDAS_SHORT *pix_yr, start time, in terms of the base time and * * *pix_day resolution, for the buffer's start pixel * * SDDAS_SHORT index indexing variable used to access the correct * * sensor variables * * SDDAS_USHORT num_sample the number of elements to be processed * * SDDAS_SHORT sensor sensor for which data is to be retrieved * * 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 buf_num the buffer being processed (0 - 4) * * 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_CHAR found_data flag indicating if data was returned for the * * requested sensor * * void *idf_data_ptr ptr to the memory location for the structure * * that holds returned data values (read_drec) * * * * USAGE * * x = ir_working_disc_between (pix_start, pix_end, working_pix, buf_num, * * index, bfrac, efrac, &more_data, num_sample, &last_buf, * * chk_buffers, found_data, sensor, &pix_yr, &pix_day, * * &pix_sec, &pix_nsec, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_full_disc_pixels() processes buffers which utilize 100% of the * * discontinuous data (data spans many pixels) * * ir_pps_discontinuous () stores data into temporary discontinuous * * data arrays according to PPS using * * SAMP_INDEX values * * ir_transfer_disc_data () transfers discontinuous data from temporary * * data matrices to the appropriate buffers * * ir_get_buffer_number() returns the next available buffer * * ir_next_pixel_time () determines the time of a pixel located * * x-many pixels away from current location * * 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_data *fptr pointer to the fill_data 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 * * struct fill_discontinuous pointer to the fill_discontinuous structure * * *disc_ptr being processed * * reg SDDAS_FLOAT *tmp_buf pointer to the converted data levels * * reg SDDAS_FLOAT *dptr pointer to the data array for discontinuous * * data matrices * * reg SDDAS_FLOAT *tfrac pointer to the normalization factors for the * * discontinuous data matrices * * reg SDDAS_FLOAT *last_data pointer to the last_data array for the * * discontinuous data matrices * * reg SDDAS_CHAR *bin_stat pointer to the bin status array for the * * discontinuous data matrices * * reg SDDAS_CHAR *cross_bound pointer to the boundary crossing flags * * SDDAS_FLOAT set_frac the fraction of the data value to be added * * to or included in the buffer * * SDDAS_LONG offset offset value to get to the data of interest * * 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 ret_val holds value returned by called module * * SDDAS_SHORT yr, day temporary year and dayofyear values * * * * SUBSYSTEM * * Display Level * * * ******************************************************************************/ SDDAS_SHORT ir_working_disc_between (SDDAS_LONG pix_start, SDDAS_LONG pix_end, SDDAS_LONG working_pix, SDDAS_CHAR buf_num, SDDAS_SHORT index, SDDAS_FLOAT bfrac, SDDAS_FLOAT efrac, SDDAS_CHAR *more_data, SDDAS_USHORT num_sample, SDDAS_CHAR *last_buf, SDDAS_CHAR chk_buffers, SDDAS_CHAR found_data, SDDAS_SHORT sensor, 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_data *fptr; struct fill_sensor *sptr; struct in_fill *mptr, *mptr_end; struct fill_discontinuous *disc_ptr; register SDDAS_FLOAT *tmp_buf, *dptr, *tfrac, *last_data; register SDDAS_CHAR *bin_stat, *cross_bound; SDDAS_FLOAT set_frac; SDDAS_LONG offset, end_sec, end_nsec; SDDAS_SHORT new_buffer, ret_val, yr, day; /***********************************************************************/ /* Set pointers to the memory allocated to process the current sensor, */ /* with index used to get to the correct sensor offset. There is only */ /* one buffer per sensor since array is temporary working area. */ /***********************************************************************/ ex = ginfo.expt; fptr = ex->fill_arrays; disc_ptr = fptr->fill_disc; sptr = ex->fill_sen_ptr + *(fptr->ind_fill_sen + index); offset = *(fptr->num_units + index) * ex->swp_len; dptr = disc_ptr->tot_data + offset; tfrac = disc_ptr->tot_frac + offset; bin_stat = disc_ptr->bin_stat + offset; last_data = disc_ptr->last_data + offset; cross_bound = disc_ptr->cross_boundary + offset; /*********************************************************************/ /* Add in 100% of the data for the current working pixel and set */ /* the buffer status to indicate that this buffer has been */ /* terminated and is ready to be plotted. It is correct to add in */ /* 100% of the data since data spans this whole pixel. */ /*********************************************************************/ set_frac = 1.00000; *(fptr->epix + buf_num) = working_pix; *(fptr->buf_stat + buf_num) = BUFFER_READY; /*****************************************************************/ /* Is this sensor to be included in the processing? */ /*****************************************************************/ if (*(ex->sensors_needed + sensor) == 1) { /**********************************************************************/ /* Transfer the converted data into the temporary arrays for all */ /* data levels. Index into ir_units_data by swp_len since this holds*/ /* the number of elements 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 += ex->swp_len, tmp_buf += ex->swp_len) ir_pps_discontinuous (num_sample, set_frac, offset, dptr, tfrac, bin_stat, tmp_buf, mptr->data_type, last_data, cross_bound, idf_data_ptr); /*******************************************************************/ /* Since the buffer is terminated, transfer the data from the */ /* temporary data matrices into the buffer of interest. */ /*******************************************************************/ ret_val = ir_transfer_disc_data (buf_num, index, idf_data_ptr); if (ret_val != ALL_OKAY) return (ret_val); } /*********************************************************************/ /* Get the next available free buffer. */ /*********************************************************************/ new_buffer = ir_get_buffer_number (buf_num, chk_buffers); 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 a 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 = *pix_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) = *pix_nsec; *(fptr->btime_day + buf_num) = day; *(fptr->btime_yr + buf_num) = yr; end_sec = *pix_sec; end_nsec = *pix_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; /*****************************************************************/ /* Is this sensor to be included in the processing? */ /*****************************************************************/ if (*(ex->sensors_needed + sensor) == 1) { /**********************************************************************/ /* Transfer the converted data into the temporary arrays for all */ /* data levels. Index into ir_units_data by swp_len since this holds*/ /* the number of elements 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 += ex->swp_len, tmp_buf += ex->swp_len) ir_pps_discontinuous (num_sample, set_frac, offset, dptr, tfrac, bin_stat, tmp_buf, mptr->data_type, last_data, cross_bound, idf_data_ptr); /*******************************************************************/ /* Since the buffer is terminated, transfer the data from the */ /* temporary data matrices into the buffer of interest. */ /*******************************************************************/ ret_val = ir_transfer_disc_data (buf_num, index, idf_data_ptr); if (ret_val != ALL_OKAY) return (ret_val); } /*********************************************************************/ /* Get the next available free buffer. */ /*********************************************************************/ new_buffer = ir_get_buffer_number (buf_num, chk_buffers); if (new_buffer < 0) return (new_buffer); buf_num = (SDDAS_CHAR) new_buffer; /************************************************************************/ /* Determine how many full pixels between the start pixel and the */ /* working pixel locations. */ /************************************************************************/ if (working_pix - pix_start > 1) { new_buffer = ir_full_disc_pixels (pix_start, working_pix, buf_num, index, num_sample, chk_buffers, found_data, sensor, pix_yr, pix_day, pix_sec, pix_nsec, idf_data_ptr); if (new_buffer < 0) return (new_buffer); buf_num = (SDDAS_CHAR) new_buffer; } else ir_next_pixel_time ((SDDAS_LONG) 1, pix_sec, pix_nsec, 1); /************************************************************************/ /* Determine how many full pixels between the working pixel and the */ /* stop pixel locations. */ /************************************************************************/ if (pix_end - working_pix > 1) { new_buffer = ir_full_disc_pixels (working_pix, pix_end, buf_num, index, num_sample, chk_buffers, found_data, sensor, pix_yr, pix_day, pix_sec, pix_nsec, idf_data_ptr); if (new_buffer < 0) return (new_buffer); buf_num = (SDDAS_CHAR) new_buffer; } else ir_next_pixel_time ((SDDAS_LONG) 1, pix_sec, pix_nsec, 1); /*********************************************************************/ /* Set the fraction of the data that belongs to the ending pixel */ /* and set the starting pixel for the current buffer. No need for */ /* += since new buffer. Time variables are cumulative from the */ /* base reference time; nanosecond component already adjusted to */ /* stay within boundary range. */ /*********************************************************************/ set_frac = efrac; yr = *pix_yr; day = *pix_day; end_sec = *pix_sec; adjust_time (&yr, &day, &end_sec, 1); *(fptr->bpix + buf_num) = pix_end; *(fptr->btime_sec + buf_num) = end_sec; *(fptr->btime_nsec + buf_num) = *pix_nsec; *(fptr->btime_day + buf_num) = day; *(fptr->btime_yr + buf_num) = yr; end_sec = *pix_sec; end_nsec = *pix_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; /*****************************************************************/ /* Is this sensor to be included in the processing? */ /*****************************************************************/ if (*(ex->sensors_needed + sensor) == 1) { /**********************************************************************/ /* Transfer the converted data into the temporary arrays for all */ /* data levels. Index into ir_units_data by swp_len since this holds*/ /* the number of elements 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 += ex->swp_len, tmp_buf += ex->swp_len) ir_pps_discontinuous (num_sample, set_frac, offset, dptr, tfrac, bin_stat, tmp_buf, mptr->data_type, last_data, cross_bound, idf_data_ptr); } /**********************************************************************/ /* Set the buffer status to indicate that the buffer is being worked */ /* on if the pixel is a fractional pixel. If the ending pixel is */ /* 100% covered by the data value, this buffer is also ready to be */ /* plotted (efrac will = 1.0 in this case since trailing edge). */ /**********************************************************************/ if (efrac < 1.0) *(fptr->buf_stat + buf_num) = PARTIAL_WORKING; else { /*******************************************************************/ /* Since the buffer is terminated, transfer the data from the */ /* temporary data matrices into the buffer of interest. */ /*******************************************************************/ if (*(ex->sensors_needed + sensor) == 1) { ret_val = ir_transfer_disc_data (buf_num, index, idf_data_ptr); if (ret_val != ALL_OKAY) return (ret_val); } *(fptr->epix + buf_num) = pix_end; *(fptr->buf_stat + buf_num) = BUFFER_READY; } /*********************************************************************/ /* Set the flag to indicate that no more data needs to be */ /* accumulated in order to get a buffer that can be processed. */ /*********************************************************************/ *more_data = 0; *last_buf = buf_num; return (ALL_OKAY); }