#include #include #include "ret_codes.h" #include "user_defs.h" #include "libtrec_idfs.h" #include "libCfg.h" #include "libdb.h" SDDAS_SHORT get_error_str (SDDAS_SHORT, SDDAS_CHAR *, SDDAS_LONG); void main(int argc, char **argv) { 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; SDDAS_DOUBLE frac_sec; SDDAS_LONG btime_sec, etime_sec, tbl_oper[5]; SDDAS_LONG *start_time_sec, *start_time_nano, *end_time_sec, *end_time_nano; SDDAS_LONG offset_unit, etime_nsec, btime_nsec; short hr, min, sec; SDDAS_SHORT sensor, ret_val, accum_bin_stat, *sen_numbers, num_sen; SDDAS_SHORT *num_units, data_block, uind_raw, sen_units; SDDAS_SHORT num_bands, fill_code, btime_yr; SDDAS_SHORT btime_day, etime_yr, etime_day, *start_time_yr, *start_time_day; SDDAS_SHORT *end_time_yr, *end_time_day, spin_sen_ctrl; SDDAS_CHAR extension[3], data_type, hdr_change, num_tbls, err_str[200]; SDDAS_CHAR *ret_bin, *bin_stat, *base_bin; SDDAS_CHAR tbls_to_apply[5], num_center_band; char more_data = 1, first_time = 1; void *idf_data_ptr; btime_yr = 2002; btime_day = 301; btime_sec = (19 * 3600) + (30 * 60) + 0; btime_nsec = 0; etime_yr = 2002; etime_day = 301; etime_sec = (19 * 3600) + (30 * 60) + 20; 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 ("CLUSTERII", "CLUSTER-2", "PEACE", "3DR", "CP3DRH", &data_key); if (ret_val != ALL_OKAY) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } get_version_number (&vnum); /************************************************************************/ /* Create one instance of the data structure. */ /************************************************************************/ ret_val = create_idf_data_structure (&idf_data_ptr); if (ret_val != ALL_OKAY) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /*********************************************************************/ /* 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) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /***********************************************************************/ /* Find the position in the data file closest to the requested */ /* start time for this data set. Unlike real-time, if an error is */ /* encountered, the system should terminate - no need to retry in */ /* anticipation of incoming data. */ /***********************************************************************/ ret_val = 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 (ret_val != ALL_OKAY) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } spin_sen_ctrl = 0; /* sensor 0 as time controller */ ret_val = start_of_spin (data_key, extension, vnum, spin_sen_ctrl, etime_yr, etime_day, etime_sec, etime_nsec); if (ret_val != ALL_OKAY) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /*************************************************************************/ /* Get the data for all sensors. */ /*************************************************************************/ EXP_DATA = (struct idf_data *) idf_data_ptr; while (more_data) { /********************************************************************/ /* Some items need to be set just once. */ /********************************************************************/ if (first_time) { /*****************************************************************/ /* Select sensor data for sensor zero. */ /*****************************************************************/ first_time = 0; num_tbls = 0; tbls_to_apply[0] = 1; tbl_oper[0] = 0; data_type = SENSOR; sen_min = VALID_MIN; sen_max = VALID_MAX; sensor = spin_sen_ctrl; 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) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /*******************************************************************/ /* Create the data bins. */ /*******************************************************************/ num_center_band = 0; ret_val = set_bin_info (data_key, extension, vnum, VARIABLE_SWEEP, 0.0, 93.0, 1.0, 93, 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) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /******************************************************************/ /* The scan units should be in terms of electron volts. */ /******************************************************************/ num_tbls = 0; 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) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } /******************************************************************/ /* Since all sensors use the same scan range, any valid sensor */ /* number can be passed in as the required argument. */ /******************************************************************/ ret_val = center_and_band_values (data_key, extension, vnum, idf_data_ptr, sensor, 1, 1, ¢er_ptr, &band_low, &band_high, &num_bands); if (ret_val != ALL_OKAY) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } } /********************************************************************/ /* Some items need to be set just once. */ /********************************************************************/ fill_code = spin_data (data_key, extension, vnum, &sen_numbers, &ret_data, &ret_frac, &ret_bin, &num_sen, &num_units, &data_block, &start_time_yr, &start_time_day, &start_time_sec, &start_time_nano, &end_time_yr, &end_time_day, &end_time_sec, &end_time_nano, &hdr_change); if (fill_code != ALL_OKAY) { get_error_str (fill_code, err_str, 200); printf ("%s\n", err_str); exit (-1); } /****************************************************************/ /* Loop over sensors processed by the SPIN_DATA routine. */ /****************************************************************/ for (i = 0; i < num_sen; ++i) { if (*(sen_numbers + i) == sensor) { offset_unit = *(num_units + i) * data_block; base_data = ret_data + offset_unit; base_frac = ret_frac + offset_unit; base_bin = ret_bin + offset_unit; num_tbls = 0; tbls_to_apply[0] = 1; tbl_oper[0] = 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) { get_error_str (ret_val, err_str, 200); printf ("%s\n", err_str); exit (-1); } if (fill_code == ALL_OKAY) { /*************************************************/ /* Print the raw units data. */ /*************************************************/ offset_unit = uind_raw * data_block; dptr = base_data + offset_unit; frac = base_frac + offset_unit; bin_stat = base_bin + 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) { frac_sec = *start_time_nano / 1000000000.0; printf ("\nTIME %04d %03d ", *start_time_yr, *start_time_day); hr = *start_time_sec / 3600; sec = *start_time_sec % 3600; min = sec / 60; sec = sec % 60; printf ("%02d %02d %02d %9.6f", hr, min, sec, frac_sec); for (loop = 0; loop < data_block; ++loop) { if (*(bin_stat + loop) != 0) printf ("\n%8.3f %3.0f",*(dptr+loop) / *(frac+loop), (float) loop); else printf ("\n%10.2e %3.0f", *(dptr + loop), (float) loop); } } } } } if (*start_time_yr == etime_yr && *start_time_day == etime_day && *start_time_sec > etime_sec) more_data = 0; else if (*start_time_yr == etime_yr && *start_time_day == etime_day && *start_time_sec == etime_sec && *start_time_nano > etime_nsec) more_data = 0; } free_experiment_info(); }