/* * 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_mode.c 1.13 05/08/19 SwRI" #include "ret_codes.h" #include "user_defs.h" #include "gen_defs.h" #include "libtrec_idfs.h" /**************************************************************************** * * * IR_PROCESS_MODE_DATA SUBROUTINE * * * * DESCRIPTION * * This routine processes mode data for the time sample just retrieved by* * the call to READ_DREC(). The data is converted into the data level(s) * * requested for desired status bytes. 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_CHAR *more_data terminate data processing flag * * SDDAS_CHAR buf_num the buffer being processed (0 - 4) * * SDDAS_CHAR *last_buf the last buffer processed (0 - 4) * * 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_mode_data (&more_data, buf_num, &last_buf, &save_info, * * &save_frac, idf_data_ptr) * * * * NECESSARY SUBPROGRAMS * * ir_find_pixel () returns the pixel a given time period is * * associated with * * ir_start_mode_equal_working() processes the data when start time pixel* * location is equal to the working pixel * * ir_end_mode_equal_working () processes the data when end time pixel * * location is equal to the working pixel * * ir_working_mode_not_included() processes the data when the range of * * start and end pixel locations exclude the * * working pixel * * ir_working_mode_between () processes data when the working pixel is * * located in between start and end pixels * * ir_stuff_mode_data () process the data for the time sample just * * retrieved by the call to READ_DREC() * * ir_calc_time_frac () calculates the percentage of the requested * * pixel time resolution covered by the * * current sweep of data * * 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_mode *mptr pointer to the fill_mode structure being * * processed * * struct fill_sensor *sptr pointer to the fill_sensor structure being * * processed * * register SDDAS_SHORT index index variable * * register SDDAS_SHORT mode the mode value being processed * * 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 modes * * 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 * * SDDAS_CHAR chk_buffers flag indicating if there is a need to * * check if all buffers have been utilized * * * * SUBSYSTEM * * Display Level * * * ***************************************************************************/ SDDAS_SHORT ir_process_mode_data (SDDAS_CHAR *more_data, SDDAS_CHAR buf_num, SDDAS_CHAR *last_buf, SDDAS_LONG *save_info, SDDAS_FLOAT *save_frac, void *idf_data_ptr) { extern struct general_info ginfo; struct idf_data *EXP_DATA; struct experiment_info *ex; struct fill_mode *mptr; struct fill_sensor *sptr; register SDDAS_SHORT index, mode; SDDAS_FLOAT bfrac, efrac, time_frac; SDDAS_LONG working_pix, pix_start, pix_end, time_sec, time_nano, pix_sec; SDDAS_LONG pix_nsec, ldummy, end_sec, end_nsec; SDDAS_SHORT rval, time_index, yr, day, pix_yr, pix_day, sdummy; SDDAS_CHAR chk_buffers; /*********************************************************************/ /* Set a pointer to the correct fill_mode structure. */ /*********************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; ex = ginfo.expt; mptr = ex->mode_arrays; /******************************************************************/ /* Determine the pixel location associated with the start time. */ /* Always use the first timing structure allocated. */ /******************************************************************/ time_index = 0; time_frac = ir_calc_time_frac (1, idf_data_ptr); time_sec = EXP_DATA->mode_bmilli / 1000; time_nano = (EXP_DATA->mode_bmilli % 1000) * 1000000 + EXP_DATA->mode_bnano; pix_start = ir_find_pixel (EXP_DATA->mode_byear, EXP_DATA->mode_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; /******************************************************************/ /* 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 ((*(mptr->buf_stat + buf_num) == UNTOUCHED_BUFFER) || (*(mptr->buf_stat + buf_num) == FREE_BUFFER)) { yr = pix_yr; day = pix_day; time_sec = pix_sec; adjust_time (&yr, &day, &time_sec, 1); *(mptr->bpix + buf_num) = pix_start; *(mptr->buf_stat + buf_num) = PARTIAL_WORKING; *(mptr->btime_sec + buf_num) = time_sec; *(mptr->btime_nsec + buf_num) = pix_nsec; *(mptr->btime_day + buf_num) = day; *(mptr->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); *(mptr->etime_sec + buf_num) = end_sec; *(mptr->etime_nsec + buf_num) = end_nsec; *(mptr->etime_day + buf_num) = day; *(mptr->etime_yr + buf_num) = yr; working_pix = pix_start; } else working_pix = *(mptr->bpix + buf_num); /******************************************************************/ /* Determine the pixel location associated with the end time. */ /******************************************************************/ time_sec = EXP_DATA->mode_emilli / 1000; time_nano = (EXP_DATA->mode_emilli % 1000) * 1000000 + EXP_DATA->mode_enano; pix_end = ir_find_pixel (EXP_DATA->mode_eyear, EXP_DATA->mode_eday, time_sec, time_nano, &efrac, TRAILING_EDGE, &sdummy, &sdummy, &ldummy, &ldummy, time_index); *(save_info + 1) = pix_end; *(save_frac + 1) = efrac; /****************************************************************/ /* Loop over all requested mode values. */ /****************************************************************/ chk_buffers = 1; for (index = 0; index < ex->num_mode_info; ++index) { sptr = ex->mode_info_ptr + *(mptr->ind_fill_mode + index); mode = sptr->sensor_num; /****************************************************************/ /* Convert data into all data levels requested for this mode. */ /****************************************************************/ rval = ir_stuff_mode_data (mode, index, idf_data_ptr); if (rval != ALL_OKAY) return (rval); /******************************************************************/ /* 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_mode_equal_working (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, last_buf, chk_buffers, 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_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); 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_mode_not_included (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, last_buf, chk_buffers, 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_mode_between (pix_start, pix_end, working_pix, buf_num, index, bfrac, efrac, more_data, last_buf, chk_buffers, &pix_yr, &pix_day, &pix_sec, &pix_nsec, idf_data_ptr); if (rval != ALL_OKAY) return (rval); } chk_buffers = 0; } return (ALL_OKAY); }