/* * 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. * */ #include #include #include "ret_codes.h" #include "user_defs.h" #include "libVIDF.h" #include "libtrec_idfs.h" #include "libCfg.h" #include "libdb.h" /* This routine processes real-time data for all RTLA sensors. */ void main (void) { struct idf_data *EXP_DATA; register SDDAS_FLOAT *dptr, *frac; register SDDAS_SHORT loop, i; SDDAS_ULONG data_key; SDDAS_USHORT vnum; SDDAS_FLOAT *ret_data, *ret_frac, sen_min, sen_max, *base_data, *base_frac; SDDAS_FLOAT *center_ptr, *band_low, *band_high, actual_phi, *data_ptr; SDDAS_FLOAT start_range[6], stop_range[6]; SDDAS_LONG btime_sec, btime_nsec, etime_sec, etime_nsec, rval, base_sec; SDDAS_LONG res_sec, res_nano, *start_time_sec, *start_time_nano; SDDAS_LONG *end_time_sec, *end_time_nano, *bpix, *epix; SDDAS_LONG offset_buf, offset_unit, base_nano, base_pix, tbl_oper[2]; SDDAS_SHORT sensor, ret_val, accum_bin_stat, num_sensor, *sen_numbers; SDDAS_SHORT *num_units, data_block, uind_raw, uind_base, buf_num, sen_units; SDDAS_SHORT num_bands, num_converted, rcode, fill_code, num_sen; SDDAS_SHORT btime_yr, btime_day, etime_yr, etime_day; SDDAS_SHORT *start_yr, *start_day, *end_yr, *end_day; SDDAS_CHAR extension[3], data_type, hdr_change, num_tbls; SDDAS_CHAR *buf_stat, *ret_bin, *bin_stat, *base_bin, last_plot; SDDAS_CHAR tbls_to_apply[2], num_center_band, dimen_status[6]; char more_data = 1, first_time = 1; void *idf_data_ptr; /**********************************************************************/ /* Set the start and stop time (in this case to reflect real-time */ /* scenario) and select the data file of interest ("" means default */ /* file is to be used). */ /**********************************************************************/ btime_yr = 1992; btime_day = 216; btime_sec = (17 * 3600) + (25 * 60) + 0; btime_nsec = 0; etime_yr = 1992; etime_day = 216; etime_sec = (17 * 3600) + (45 * 60) + 0; etime_nsec = 0; strcpy (extension,""); CfgInit(); dbInitialize (); init_idfs (); /***********************************************************************/ /* Retreive the key that is associated with the project, mission, */ /* experiment, instrument and virtual instrument specified. */ /***********************************************************************/ ret_val = get_data_key ("TSS", "TSS-1", "RETE", "RETE", "RTLA", &data_key); if (ret_val != ALL_OKAY) { printf ("\n Error %d from get_data_key routine.\n", ret_val); exit (-1); } get_version_number (&vnum); ret_val = create_idf_data_structure (&idf_data_ptr); if (ret_val != ALL_OKAY) { printf ("\n Error %d from create_idf_data_structure routine.\n", ret_val); exit (-1); } EXP_DATA = (struct idf_data *) idf_data_ptr; /*********************************************************************/ /* The data will be collapsed over the scan dimension to squash */ /* the data over the entire frequency range for this virtual */ /* instrument. */ /*********************************************************************/ dimen_status[0] = DIMEN_ON; start_range[0] = 0.16; stop_range[0] = 0.9; start_range[1] = stop_range[1] = 0.0; start_range[2] = stop_range[2] = 0.0; start_range[3] = stop_range[3] = 0.0; start_range[4] = stop_range[4] = 0.0; start_range[5] = stop_range[5] = 0.0; dimen_status[1] = DIMEN_OFF; dimen_status[2] = DIMEN_OFF; dimen_status[3] = DIMEN_OFF; dimen_status[4] = DIMEN_OFF; dimen_status[5] = DIMEN_OFF; /*********************************************************************/ /* Open the data files associated with the time period selected for */ /* this data set/extension/version combination. */ /*********************************************************************/ ret_val = file_open (data_key, extension, vnum, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec, 0); if (ret_val != ALL_OKAY) { printf ("\n Error %d from file_open routine.\n", ret_val); exit (-1); } /************************************************************************/ /* Find out the number of sensors defined for this virtual instrument. */ /************************************************************************/ rval = read_idf (data_key, extension, vnum, (SDDAS_CHAR *) &num_sensor, _SEN, 0, 0, 1); if (rval < 0) { printf ("\n Error %ld from read_idf routine.\n", (long int) rval); exit (-1); } /*************************************************************************/ /* Get the data for all sensors. */ /*************************************************************************/ while (more_data) { /********************************************************************/ /* Find the position in the data file closest to the requested */ /* start time for this data set. If the file has been positioned */ /* correctly, future calls to this routine just return the ALL_OKAY*/ /* status; otherwise, the routine keeps trying to read from the */ /* files and to position the file pointers (records may not have */ /* been written to disk yet). */ /********************************************************************/ rcode = file_pos (data_key, extension, vnum, idf_data_ptr, btime_yr, btime_day, btime_sec, btime_nsec, etime_yr, etime_day, etime_sec, etime_nsec); if (rcode == LOS_STATUS) more_data = 0; else if (rcode == NEXT_FILE_STATUS) { /*************************************************************/ /* For realtime processing, btime_sec is set to -1 so that */ /* when files are crossed, the routines will position the */ /* file at the beginning of that next file. */ /*************************************************************/ ret_val = reset_experiment_info (data_key, extension, vnum, -1, -1, -1, -1, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val != ALL_OKAY) { printf ("\nError %d from reset_experiment_info.\n", ret_val); exit (-1); } } else if (rcode != ALL_OKAY && rcode != EOF_STATUS) { printf ("\n Error %d from file_pos routine.\n", rcode); exit (-1); } /********************************************************************/ /* Some items need to be set just once. */ /********************************************************************/ if (first_time) { first_time = 0; /*****************************************************************/ /* Set the base reference time, location and duration for the */ /* data buffers. */ /*****************************************************************/ ret_val = read_drec (data_key, extension, vnum, idf_data_ptr, 0, 0, 0); if (ret_val < 0) { printf ("\nError %d from read_drec.\n", ret_val); exit (-1); } base_sec = EXP_DATA->bsec; base_nano = EXP_DATA->bnsec; base_pix = 0; res_sec = 9; res_nano = 216000000; set_time_values (vnum, EXP_DATA->byear, EXP_DATA->bday, base_sec, base_nano, base_pix, res_sec, res_nano); /*****************************************************************/ /* Select sensor data in raw units for all sensors. */ /*****************************************************************/ num_tbls = 0; data_type = SENSOR; sen_min = VALID_MIN; sen_max = VALID_MAX; for (sensor = 0; sensor < num_sensor; ++sensor) { ret_val = fill_sensor_info (data_key, extension, vnum, sensor, sen_min, sen_max, num_tbls, tbls_to_apply, tbl_oper, data_type, 0); if (ret_val != ALL_OKAY) { printf ("\nError %d from fill_sensor_info.\n", ret_val); exit (-1); } } /*****************************************************************/ /* Select sensor data in base units for all sensors. */ /*****************************************************************/ num_tbls = 2; tbls_to_apply[0] = 0; tbls_to_apply[1] = 1; tbl_oper[0] = 0; tbl_oper[1] = 3; for (sensor = 0; sensor < num_sensor; ++sensor) { ret_val = fill_sensor_info (data_key, extension, vnum, sensor, sen_min, sen_max, num_tbls, tbls_to_apply, tbl_oper, data_type, 0); if (ret_val != ALL_OKAY) { printf ("\nError %d from fill_sensor_info.\n", ret_val); exit (-1); } } /*******************************************************************/ /* Specify that 8 linear center bins from 0.16 to 0.86 (.1 delta) */ /* are to be created and missing bins are to be left empty. No */ /* need to call SET_SCAN_INFO since raw sweep step values are */ /* desired for this sweeping instrument. Since num_center_band */ /* is 0, the contents of tbl_oper and tbls_to_apply don't matter. */ /*******************************************************************/ num_center_band = 0; ret_val = set_bin_info (data_key, extension, vnum, VARIABLE_SWEEP, 0.16, 0.86, 0.1, 8, LIN_SPACING, num_center_band, tbls_to_apply, tbl_oper, num_center_band, tbls_to_apply, tbl_oper, num_center_band, tbls_to_apply, tbl_oper, 'L', POINT_STORAGE, NO_BIN_FILL); if (ret_val != ALL_OKAY) { printf ("\nError %d from set_bin_info.\n", ret_val); exit (-1); } /******************************************************************/ /* The scan units should be in terms of frequency. */ /******************************************************************/ num_tbls = 1; tbls_to_apply[0] = 0; tbl_oper[0] = 0; ret_val = set_scan_info (data_key, extension, vnum, num_tbls, tbls_to_apply, tbl_oper); if (ret_val != ALL_OKAY) { printf ("\nError %d from set_scan_info.\n", ret_val); exit (-1); } /******************************************************************/ /* Since all sensors use the same scan range, any valid sensor */ /* number can be passed in as the required argument. */ /******************************************************************/ sensor = 0; ret_val = center_and_band_values (data_key, extension, vnum, idf_data_ptr, sensor, 1, 1, ¢er_ptr, &band_low, &band_high, &num_bands, &num_converted); if (ret_val != ALL_OKAY && ret_val != CENTER_CONVERSION) { printf ("\nError %d from center_and_band_values.\n", ret_val); exit (-1); } /*****************************************************************/ /* Specify that data will be collapsed for 2 units, but no PHI */ /* dimension and do not interleave the data. */ /*****************************************************************/ ret_val = set_collapse_info (data_key, extension, vnum, 2, 360.0, &actual_phi, 0); if (ret_val != ALL_OKAY) { printf ("\nError %d from set_collapse_info.\n", ret_val); exit (-1); } } if (rcode == ALL_OKAY) { fill_code = fill_data (data_key, extension, vnum, idf_data_ptr, &sen_numbers, &ret_data, &ret_frac, &ret_bin, &bpix, &epix, &buf_stat, &num_sen, &num_units, &data_block, &start_yr, &start_day, &start_time_sec, &start_time_nano, &end_yr, &end_day, &end_time_sec, &end_time_nano, &hdr_change, 255); if (fill_code != ALL_OKAY && fill_code != LOS_STATUS && fill_code != EOF_STATUS && fill_code != NEXT_FILE_STATUS) { printf ("\nError %d from fill_data.\n", fill_code); exit (-1); } /*******************************************************************/ /* Loop over all defined sensors. */ /*******************************************************************/ for (sensor = 0; sensor < num_sensor; ++sensor) { /****************************************************************/ /* Loop over sensors processed by the FILL_DATA routine. */ /****************************************************************/ for (i = 0; i < num_sen; ++i) { if (*(sen_numbers + i) == sensor) { offset_unit = *(num_units + i) * NUM_BUFFERS * data_block; base_data = ret_data + offset_unit; base_frac = ret_frac + offset_unit; base_bin = ret_bin + offset_unit; num_tbls = 0; ret_val = units_index (data_key, extension, vnum, sensor, sen_min, sen_max, tbls_to_apply, tbl_oper, data_type, 0, &uind_raw, &sen_units, num_tbls); if (ret_val != ALL_OKAY) { printf ("\nError %d from units_index.\n", ret_val); exit (-1); } num_tbls = 2; tbls_to_apply[0] = 0; tbls_to_apply[1] = 1; tbl_oper[0] = 0; tbl_oper[1] = 3; ret_val = units_index (data_key, extension, vnum, sensor, sen_min, sen_max, tbls_to_apply, tbl_oper, data_type, 0, &uind_base, &sen_units, num_tbls); if (ret_val != ALL_OKAY) { printf ("\nError %d from units_index.\n", ret_val); exit (-1); } for (buf_num = 0; buf_num < NUM_BUFFERS; ++buf_num) if (*(buf_stat + buf_num) == BUFFER_READY) { /*************************************************/ /* Print the raw units data. */ /*************************************************/ offset_buf = buf_num * sen_units * data_block; offset_unit = uind_raw * data_block; dptr = base_data + offset_buf + offset_unit; frac = base_frac + offset_buf + offset_unit; bin_stat = base_bin + offset_buf + offset_unit; accum_bin_stat = 0; for (loop = 0; loop < data_block; ++loop) accum_bin_stat += *(bin_stat + loop); /*************************************************/ /* Make sure there is some data in the buffers. */ /* Still check bin_stat since frac will be 0.0 */ /* if bin_stat = 0. For this data set, it is */ /* known that the sweep values are contiguous. */ /*************************************************/ if (accum_bin_stat != 0) { printf ("\n\n sensor %d information", sensor); printf ("\n start_pix = %ld", (long int) *(bpix + buf_num)); printf ("\n end_pix = %ld", (long int) *(epix + buf_num)); for (loop = 0; loop < data_block; ++loop) { if (*(bin_stat + loop) != 0) printf ("\n raw data[%d] = %10.2e from freq bin %.2f to %.2f",loop,*(dptr+loop) / *(frac+loop), *(band_low + loop), *(band_low + loop + 1)); else printf ("\n raw data[%d] = %10.2e from freq bin %.2f to %.2f", loop, *(dptr + loop), *(band_low + loop), *(band_low + loop + 1)); } } /*************************************************/ /* Print the base units data. */ /*************************************************/ offset_unit = uind_base * data_block; dptr = base_data + offset_buf + offset_unit; frac = base_frac + offset_buf + offset_unit; bin_stat = base_bin + offset_buf + offset_unit; accum_bin_stat = 0; for (loop = 0; loop < data_block; ++loop) accum_bin_stat += *(bin_stat + loop); if (accum_bin_stat != 0) { printf ("\n\n sensor %d information\n", sensor); printf ("\n start_pix = %ld", (long int) *(bpix + buf_num)); printf ("\n end_pix = %ld", (long int) *(epix + buf_num)); for (loop = 0; loop < data_block; ++loop) { if (*(bin_stat + loop) != 0) printf ("\n base data[%d] = %10.2e from freq bin %.2f to %.2f",loop,*(dptr+loop) / *(frac+loop), *(band_low + loop), *(band_low + loop + 1)); else printf ("\n base data[%d] = %10.2e from freq bin %.2f to %.2f", loop, *(dptr + loop), *(band_low + loop), *(band_low + loop + 1)); } } } } } } /******************************************************************/ /* Collapse the data over the scan dimension. */ /******************************************************************/ for (buf_num = 0; buf_num < NUM_BUFFERS; ++buf_num) if (*(buf_stat + buf_num) == BUFFER_READY) { /***************************************************************/ /* Place the data for the current buffer into the matrix used */ /* to collapse data over the theta and/or scan dimensions (no */ /* phi, mass or charge dimensions). */ /***************************************************************/ ret_val = fill_theta_matrix (data_key, extension, vnum, num_sen, sen_numbers, ret_data, ret_frac, ret_bin, num_units, buf_num, sen_units); if (ret_val != ALL_OKAY) { printf ("\nError %d from fill_theta_matrix.\n", ret_val); exit (-1); } for (sensor = 0; sensor < num_sensor; ++sensor) { /***********************************************************/ /* Collapse over scan dimension for the raw data. */ /* The single value will be set to -3.4e38 (OUTSIDE_MIN) */ /* if no data was present in the data buffers for the */ /* sensor in question. */ /***********************************************************/ ret_val = collapse_dimensions (data_key, extension, vnum, sensor, dimen_status, start_range, stop_range, STRAIGHT_AVG, 0, &data_ptr, 0, 1, 2, 0.0, 1, 0, 0, 0, 1, buf_num); if (ret_val != ALL_OKAY) { printf ("\nError %d from collapse_dimensions.\n", ret_val); exit (-1); } if (*data_ptr > OUTSIDE_MIN) printf ("\n data from collapsing raw units for sensor %d is %10.2e", sensor, *data_ptr); /***********************************************************/ /* Collapse over scan dimension for the base data. The */ /* single value will be set to -3.4e38 (OUTSIDE_MIN) if no*/ /* data was present in the data buffers for the sensor in */ /* question. */ /***********************************************************/ last_plot = (sensor == num_sensor - 1) ? 1 : 0; ret_val = collapse_dimensions (data_key, extension, vnum, sensor, dimen_status, start_range, stop_range, STRAIGHT_AVG, 0, &data_ptr, 0, 1, 2, 0.0, 1, 0, 1, last_plot, 1, buf_num); if (ret_val != ALL_OKAY) { printf ("\nError %d from collapse_dimensions.\n", ret_val); exit (-1); } if (*data_ptr > OUTSIDE_MIN) printf ("\n data from collapsing base units for sensor %d is %10.2e", sensor, *data_ptr); } } if (fill_code == LOS_STATUS) more_data = 0; else if (fill_code == NEXT_FILE_STATUS) { /*************************************************************/ /* For realtime processing, btime_sec is set to -1 so that */ /* when files are crossed, the routines will position the */ /* file at the beginning of that next file. The mandatory */ /* call to file_pos can be found at the top of while loop. */ /*************************************************************/ ret_val = reset_experiment_info (data_key, extension, vnum, -1, -1, -1, -1, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val != ALL_OKAY) { printf ("\nError %d from reset_experiment_info.\n", ret_val); exit (-1); } } } } free_experiment_info(); }