/* * 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 "@(#) proc_disc.c 1.17 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "gen_defs.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_PROCESS_DISCONTINUOUS_DATA SUBROUTINE * * * * DESCRIPTION * * This routine processes discontinuous data for the time sample just * * retrieved by the call to READ_DREC(). If data is returned for the * * sensor, it is converted into the data level(s) requested for this * * sensor. Otherwise, the data is set to OUTSIDE_MIN indicating that no * * data was found. These values will not be included in the discontinuous * * data matrices since these values are outside the range of -180 to 180. * * The pixel locations that are associated with the start time of the data * * and the end time of the data are determined so that the data can be * * placed into the correct buffers. There is always a current working * * pixel location and a current working buffer that is in use. * * * * INPUT VARIABLES * * SDDAS_SHORT sensor sensor for which data is to be retrieved * * SDDAS_CHAR *more_data terminate data processing flag * * SDDAS_CHAR found_data flag indicating if data was returned for * * requested sensor * * 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 recalc_swp recalculate sweep values flag * * SDDAS_CHAR find_pix flag indicating if the pixel locations * * need to be determined * * SDDAS_LONG *save_info array that holds the pixel start, stop and * * time values * * SDDAS_FLOAT *save_frac array that holds the fractions associated * * with the pixel information * * void *idf_data_ptr ptr to memory location for the structure * * that holds returned data values (read_drec)* * * * USAGE * * x = ir_process_discontinuous_data (sensor, &more_data, found_data, * * buf_num, &last_buf, chk_buffers, recalc_swp, &save_info, * * &save_frac, find_pix, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_find_pixel () returns the pixel a given time period is * * associated with * * ir_start_disc_equal_working() processes the discontinuous data when * * start time pixel location is equal to the * * working pixel * * ir_end_disc_equal_working () processes the discontinuous data when * * end time pixel location is equal to the * * working pixel * * ir_working_disc_not_included() processes the discontinuous data when * * the range of start and end pixel locations * * exclude the working pixel * * ir_working_disc_between () processes discontinuous data when the * * working pixel is located in between start * * and end pixels * * ir_calc_time_frac () calculates the percentage of the requested * * pixel time resolution covered by the * * current sweep of data * * ir_process_sensor_data_levels () transforms sensor data into all data * * levels (units) requested * * adjust_time () corrects time elements if too many seconds * * (day crossing) or too many days (year * * crossing) * * * * EXTERNAL VARIABLES * * struct general_info ginfo structure holding information concerning * * the experiment that is being processed * * * * INTERNAL VARIABLES * * struct idf_data *EXP_DATA structure holding all of the currently * * returned data values to be processed * * 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 * * reg SDDAS_SHORT index index variable * * register SDDAS_CHAR *c1 pointer to the sensor usage flags * * register SDDAS_CHAR *c_end loop termination variable * * SDDAS_FLOAT bfrac fraction of the data associated with start * * time's pixel location (start time of data) * * SDDAS_FLOAT efrac fraction of the data associated with end * * time's pixel location (end time of data) * * SDDAS_FLOAT time_frac percentage of the time resolution covered * * by the sweep * * SDDAS_LONG working_pix the current pixel location being processed * * SDDAS_LONG pix_start pixel location associated with start time * * SDDAS_LONG pix_end pixel location associated with end time * * SDDAS_LONG time_sec seconds component of the current time * * SDDAS_LONG time_nano nanoseconds component of the current time * * SDDAS_LONG pix_sec, start time, in terms of the base time and * * pix_nsec resolution, for the buffer's start pixel * * SDDAS_LONG end_sec, end time, in terms of the base time and * * end_nsec resolution, for the buffer's start pixel * * SDDAS_LONG ldummy dummy placeholder for long parameter * * SDDAS_SHORT rval holds values returned various routines * * SDDAS_SHORT time_index index to get to the timing structure for * * the sensor being processed * * SDDAS_SHORT yr, day temporary year and dayofyear values * * SDDAS_SHORT pix_yr, start time, in terms of the base time and * * pix_day resolution, for the buffer's start pixel * * SDDAS_SHORT sdummy dummy placeholder for short parameter * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_process_discontinuous_data (SDDAS_SHORT sensor, SDDAS_CHAR *more_data, SDDAS_CHAR found_data, SDDAS_CHAR buf_num, SDDAS_CHAR *last_buf, SDDAS_CHAR chk_buffers, SDDAS_CHAR recalc_swp, SDDAS_LONG *save_info, SDDAS_FLOAT *save_frac, SDDAS_CHAR find_pix, void *idf_data_ptr) { extern struct general_info ginfo; struct idf_data *EXP_DATA; struct experiment_info *ex; struct fill_data *fptr; register SDDAS_SHORT index; register SDDAS_CHAR *c1, *c_end; SDDAS_FLOAT bfrac, efrac, time_frac; SDDAS_LONG working_pix, pix_start, pix_end; SDDAS_LONG time_sec, time_nano, pix_sec, pix_nsec, ldummy, end_sec, end_nsec; SDDAS_SHORT rval, time_index, yr, day, pix_yr, pix_day, sdummy; /*********************************************************************/ /* Set a pointer to the correct fill_discontinuous_data structure. */ /*********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; fptr = ex->fill_arrays; /**********************************************************************/ /* Set pointers to the correct element in the arrays for this sensor.*/ /**********************************************************************/ c1 = ex->sensors_needed; c_end = c1 + sensor; for (index = 0; c1 < c_end; ) index += *c1++; /*****************************************************************/ /* Is this sensor to be included in the processing? */ /*****************************************************************/ if (*(ex->sensors_needed + sensor) == 1) { rval = ir_process_sensor_data_levels (sensor, found_data, recalc_swp, idf_data_ptr, index); if (rval != ALL_OKAY) return (rval); } /******************************************************************/ /* Determine the pixel location associated with the start time. */ /******************************************************************/ if (find_pix) { time_index = (ex->all_or_one) ? sensor : 0; time_frac = ir_calc_time_frac (0, idf_data_ptr); time_sec = EXP_DATA->bsec; time_nano = EXP_DATA->bnsec; pix_start = ir_find_pixel (EXP_DATA->byear, EXP_DATA->bday, time_sec, time_nano, &bfrac, LEADING_EDGE, &pix_yr, &pix_day, &pix_sec, &pix_nsec, time_index); *save_info = pix_start; *(save_info + 2) = pix_sec; *(save_info + 3) = pix_nsec; *(save_info + 4) = (SDDAS_LONG) pix_yr; *(save_info + 5) = (SDDAS_LONG) pix_day; *save_frac = bfrac; *(save_frac + 2) = time_frac; } else { pix_start = *save_info; pix_sec = *(save_info + 2); pix_nsec = *(save_info + 3); pix_yr = (SDDAS_SHORT) *(save_info + 4); pix_day = (SDDAS_SHORT) *(save_info + 5); time_frac = *(save_frac + 2); bfrac = *save_frac; } /******************************************************************/ /* If the buffer is a new working buffer, initialize the buffer; */ /* otherwise, determine the working pixel location. The year/day */ /* elements are time-rectified from read_drec() call, but */ /* pix_sec is cumulative. */ /******************************************************************/ if ((*(fptr->buf_stat + buf_num) == UNTOUCHED_BUFFER) || (*(fptr->buf_stat + buf_num) == FREE_BUFFER)) { yr = pix_yr; day = pix_day; time_sec = pix_sec; adjust_time (&yr, &day, &time_sec, 1); *(fptr->bpix + buf_num) = pix_start; *(fptr->buf_stat + buf_num) = PARTIAL_WORKING; *(fptr->btime_sec + buf_num) = time_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; working_pix = pix_start; } else working_pix = *(fptr->bpix + buf_num); /******************************************************************/ /* Determine the pixel location associated with the end time. */ /******************************************************************/ if (find_pix) { time_index = (ex->all_or_one) ? sensor : 0; time_sec = EXP_DATA->esec; time_nano = EXP_DATA->ensec; pix_end = ir_find_pixel (EXP_DATA->eyear, EXP_DATA->eday, time_sec, time_nano, &efrac, TRAILING_EDGE, &sdummy, &sdummy, &ldummy, &ldummy, time_index); *(save_info + 1) = pix_end; *(save_frac + 1) = efrac; } else { pix_end = *(save_info + 1); efrac = *(save_frac + 1); } /******************************************************************/ /* This start time of this sample includes the working pixel. */ /* This sample may cover only this pixel or more pixels. */ /* (ex. pix = 4, start = 4, stop = 5) */ /******************************************************************/ if (pix_start == working_pix) { rval = ir_start_disc_equal_working (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, EXP_DATA->num_sample, last_buf, chk_buffers, found_data, sensor, time_frac, &pix_yr, &pix_day, &pix_sec, &pix_nsec, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } /******************************************************************/ /* This end time of this sample includes the working pixel. */ /* Since the start time does not work off this pixel and it is */ /* always true that the pix_start will be <= pix_end, it is */ /* implied that time backed up some (one or more pixels). */ /* (ex. pix = 4, start = 3, stop = 4) */ /******************************************************************/ else if (pix_end == working_pix) { rval = ir_end_disc_equal_working (pix_start, pix_end, buf_num, index, bfrac, efrac, more_data, EXP_DATA->num_sample, last_buf, chk_buffers, found_data, sensor, &pix_yr, &pix_day, &pix_sec, &pix_nsec, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } /******************************************************************/ /* The range of the start and stop pixel exclude the working */ /* pixel; time either advanced past the current pixel or went */ /* backwards. (ex. pix = 4, start = 7, stop = 8) */ /******************************************************************/ else if ((pix_start > working_pix && pix_end > working_pix) || (pix_start < working_pix && pix_end < working_pix)) { rval = ir_working_disc_not_included (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, EXP_DATA->num_sample, last_buf, chk_buffers, found_data, sensor, time_frac, &pix_yr, &pix_day, &pix_sec, &pix_nsec, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } /*******************************************************************/ /* The range of the start and stop pixel include the working */ /* pixel indicating that the start time backed off the pixel */ /* (time backed up a little). (ex. pix = 4, start = 3, stop = 5) */ /*******************************************************************/ else { rval = ir_working_disc_between (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, EXP_DATA->num_sample, last_buf, chk_buffers, found_data, sensor, &pix_yr, &pix_day, &pix_sec, &pix_nsec, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } return (ALL_OKAY); }