#include #include #include #include "ret_codes.h" #include "user_defs.h" #include "libbase_idfs.h" #include "libCfg.h" #include "libdb.h" #include "libVIDF.h" SDDAS_SHORT get_error_str (SDDAS_SHORT, SDDAS_CHAR *, SDDAS_LONG); /* This routine processes real-time data for all RTLA sensors. */ int main (void) { struct idf_data *EXP_DATA; struct transformation_info *trans_ptr; register SDDAS_USHORT loop; SDDAS_FLOAT slope, intercept, conv_data[1000]; SDDAS_LONG btime_sec, btime_nano, etime_sec, etime_nano, rval, tbl_oper[2]; SDDAS_LONG new_start_sec, new_start_nsec; SDDAS_ULONG data_key; SDDAS_USHORT version; SDDAS_SHORT rcode, sensor, ret_val, num_sensor; SDDAS_SHORT btime_yr, btime_day, etime_yr, etime_day; SDDAS_SHORT new_year, new_day; SDDAS_CHAR extension[3], full_swp = 1, fwd = 1, tbls_to_apply[2], num_tbls, more_data = 1; SDDAS_CHAR error_str[150]; void *idf_data_ptr; /**************************************************************************/ /* Set the start and stop time. This example uses year 1984, day 257, */ /* starting at 13:20:00 (hh:mm:ss) - 48000 seconds - and ending at */ /* 13:20:20 (hh:mm:ss) - 48020 seconds. */ /**************************************************************************/ /* btime_yr = 2002; btime_day = 7; btime_sec = (19 * 3600) + (50 * 60) + 0; btime_nano = 0; etime_yr = 2002; etime_day = 7; etime_sec = (19 * 3600) + (51 * 60) + 10; etime_nano = 0; */ btime_yr = 2001; btime_day = 61; btime_sec = (23 * 3600) + (55 * 60) + 0; btime_nano = 0; etime_yr = 2001; etime_day = 62; etime_sec = (0 * 3600) + (1 * 60) + 0; etime_nano = 0; strcpy (extension,""); CfgInit(); dbInitialize (); init_idfs (); /***********************************************************************/ /* Retreive the key that is associated with the project, mission, */ /* experiment, instrument and virtual instrument specified. */ /***********************************************************************/ printf ("\n CLUSTERII CLUSTER-1 PEACE 3DX1 CPXP1L\n"); ret_val = get_data_key ("CLUSTERII", "CLUSTER-1", "PEACE", "3DX1", "CPXP1L", &data_key); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } get_version_number (&version); /*********************************************************************/ /* Open the data files associated with the time period selected for */ /* this data set/extension/version combination. */ /*********************************************************************/ ret_val = file_open (data_key, extension, version, btime_yr, btime_day, btime_sec, btime_nano, etime_yr, etime_day, etime_sec, etime_nano, 0); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } slope = 1.0; intercept = 1.5; ret_val = override_potential_polynomial (data_key, extension, version, slope, intercept); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } /************************************************************************/ /* 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, error_str, 150); printf ("%s\n", error_str); exit (-1); } /**********************************************************************/ /* 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). */ /**********************************************************************/ ret_val = file_pos (data_key, extension, version, idf_data_ptr, btime_yr, btime_day, btime_sec, btime_nano, etime_yr, etime_day, etime_sec, etime_nano); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } /************************************************************************/ /* Find out the number of sensors defined for this virtual instrument. */ /************************************************************************/ rval = read_idf (data_key, extension, version, (char *) &num_sensor, _SEN, 0, 0L, 1); if (rval < 0) { get_error_str (rval, error_str, 150); printf ("%s\n", error_str); exit (-1); } /************************************************************************/ /* Turn on euler angle computations. */ /************************************************************************/ ret_val = turn_on_euler_angle_computations (data_key, extension, version); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } /************************************************************************/ /* Turn on celestial position angular computations. */ /************************************************************************/ ret_val = turn_on_celestial_position_computations (data_key, extension, version); if (ret_val != ALL_OKAY) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } /*********************************************************************/ /* Retrieve the raw units for the data. */ /*********************************************************************/ num_tbls = 0; /* tbls_to_apply = NULL; tbl_oper = NULL; */ /*************************************************************************/ /* Get the data for all sensors. */ /*************************************************************************/ while (more_data) { for (sensor = 0; sensor < num_sensor; ++sensor) { /******************************************************************/ /* Advance to the next data set only if the last sensor is */ /* being processed to ensure all samples which occur at the same */ /* time are processed simultaneously. */ /******************************************************************/ fwd = (sensor == num_sensor - 1) ? 1 : 0; ret_val = read_drec (data_key, extension, version, idf_data_ptr, sensor, fwd, full_swp); if (ret_val < 0) { get_error_str (ret_val, error_str, 150); printf ("%s\n", error_str); exit (-1); } /*****************************************************************/ /* The sensor data was found within the time being processed. */ /*****************************************************************/ /* if (sensor != 0) continue; */ EXP_DATA = (struct idf_data *) idf_data_ptr; if (ret_val == ALL_OKAY || EXP_DATA->filled_data) { /***************************************************************/ /* Print data values, 6 values per row, in exponential format.*/ /***************************************************************/ num_tbls = 1; tbls_to_apply[0] = 15; tbl_oper[0] = 0; /* tbls_to_apply = NULL; tbl_oper = NULL; */ rcode = convert_to_units (data_key, extension, version, idf_data_ptr, sensor, SC_POTENTIAL, 0, num_tbls, tbls_to_apply, tbl_oper, conv_data, 0, 0L); if (rcode != ALL_OKAY) { get_error_str (rcode, error_str, 150); printf ("%s\n", error_str); exit (-1); } /***************************************************************/ /* Print the times for the sample being returned. */ /***************************************************************/ SDDAS_LONG new_nano, temp; SDDAS_SHORT hr, min, sec; new_nano = EXP_DATA->bnsec; temp = EXP_DATA->bmilli / 1000; hr = temp / 3600; temp = temp % 3600; min = temp / 60; sec = temp % 60; printf ("\n\nSENSOR %d's START TIME_MS = %02d:%02d:%02d.%ld", sensor, hr, min, sec, (long int) new_nano); new_nano = EXP_DATA->ensec; temp = EXP_DATA->emilli / 1000; hr = temp / 3600; temp = temp % 3600; min = temp / 60; sec = temp % 60; printf ("\nSENSOR %d's END TIME_MS = %02d:%02d:%02d.%ld", sensor, hr, min, sec, (long int) new_nano); /* printf ("\n num_potential = %d", EXP_DATA->num_potential); for (k = 0; k < EXP_DATA->num_potential; ++k) { if (k % 6 == 0) printf ("\n"); printf ("%10.2e ", conv_data[k]); } */ num_tbls = 0; rcode = convert_to_units (data_key, extension, version, idf_data_ptr, sensor, PITCH_ANGLE, 0, num_tbls, tbls_to_apply, tbl_oper, conv_data, 0, 0L); if (rcode != ALL_OKAY) { get_error_str (rcode, error_str, 150); printf ("%s\n", error_str); exit (-1); } /* printf ("\n num_pitch = %d", EXP_DATA->num_pitch); for (k = 0; k < EXP_DATA->num_pitch; ++k) { if (k % 6 == 0) printf ("\n"); printf ("%10.2e ", conv_data[k]); } */ trans_ptr = EXP_DATA->idfs_transformation; /* printf ("\n num_euler = %d\n", trans_ptr->num_euler); offset = 0; for (k = 0; k < EXP_DATA->num_sample; ++k) { for (loop = 0; loop < trans_ptr->num_euler; ++loop, ++offset) { printf ("%05.2f %d ", *(trans_ptr->euler_angles + offset), *(trans_ptr->euler_rot_axis + loop)); } printf ("\n"); } */ printf ("\n num_celestial = %d num_sample = %d\n", trans_ptr->num_celestial, EXP_DATA->num_sample); printf ("\n Declination Rt. Ascension\n"); for (loop = 0; loop < trans_ptr->num_celestial; ++loop) { printf (" %05.2f %05.2f \n", *(trans_ptr->declination_angles + loop), *(trans_ptr->rt_ascension_angles + loop)); } printf ("\n"); printf ("\n\n"); } if (EXP_DATA->byear > etime_yr) more_data = 0; else if (EXP_DATA->byear == etime_yr && EXP_DATA->bday > etime_day) more_data = 0; else if (EXP_DATA->byear == etime_yr && EXP_DATA->bday == etime_day && EXP_DATA->bsec > etime_sec) more_data = 0; if (ret_val == LOS_STATUS || ret_val == NEXT_FILE_STATUS) { /***************************************************************/ /* Get the start time to use to get the next data file. */ /***************************************************************/ rcode = next_file_start_time (data_key, extension, version, 0, &new_year, &new_day, &new_start_sec, &new_start_nsec); if (rcode != ALL_OKAY) { printf ("\n Error %d from next_file_start_time.\n", rcode); exit (-1); } rcode = reset_experiment_info (data_key, extension, version, new_year, new_day, new_start_sec, new_start_nsec, etime_yr, etime_day, etime_sec, etime_nano); if (rcode == NO_DATA) { more_data = 0; break; } if (rcode != ALL_OKAY) { get_error_str (rcode, error_str, 150); printf ("%s\n", error_str); exit (-1); } rcode = file_pos (data_key, extension, version, idf_data_ptr, new_year, new_day, new_start_sec, new_start_nsec, etime_yr, etime_day, etime_sec, etime_nano); if (rcode != ALL_OKAY) { printf ("\n Error %d from file_pos.\n", rcode); exit (-1); } } } } free_experiment_info(); return (0); }