/* ************************************************************** */ /* * Module RT * This module contains functions to measure the resistance and * temperature of a magnet as a function of time. * * Zachary Wolf * 12/18/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "param.h" #include "runparam.h" #include "imag.h" #include "imagparam.h" #include "imagui.h" #include "vmag.h" #include "vmagparam.h" #include "tmag.h" #include "tmagparam.h" #include "tmagui.h" #include "rtui.h" /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static char log_file[80]; static char dat_file[80]; static char plt_file[80]; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void rt_init(void); void rt_meas(void); void rt_dat_meas(int meas_num, double imag, double vmag, double rmag, int num_probes, double probe_temps[]); void rt_plt_meas(int meas_num, double imag, double vmag, double rmag, int num_probes, double probe_temps[]); void rt_exit(void); void rt_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ rt_init(); /* Perform the measurements */ rt_meas(); /* Exit all systems */ rt_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * rt_init * This function is used to initialize RT measurements. * * Zachary Wolf * 12/18/00 */ void rt_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; struct imag_param_struct imag_param; struct vmag_param_struct vmag_param; struct tmag_param_struct tmag_param; int i; char par_file[80]; /* Get the run parameters from the user */ try_again: runparam_get_run_param(&run_param); /* Create all output files */ err = runparam_create_file(run_param, "rtlog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "rtdat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "rtplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "rtpar", par_file); if (err != 0) goto try_again; /* Save the parameter file */ err = CopyFile("param.h", par_file); if (err != 0) printf("Error saving parameter file"); /* Update the run index file */ runparam_update_index(run_param); /* Write file headers */ runparam_write_header(run_param, log_file); runparam_write_header(run_param, dat_file); imag_write_header(log_file, RT_NUM_STAND_CYCLES, RT_STAND_MAX, RT_STAND_MIN, RT_NUM_TEST_CURRENTS, RT_TEST_CURRENTS); imag_write_header(dat_file, RT_NUM_STAND_CYCLES, RT_STAND_MAX, RT_STAND_MIN, RT_NUM_TEST_CURRENTS, RT_TEST_CURRENTS); /* Fill system parameter structures */ imagparam_fill_param_struct(&imag_param); vmagparam_fill_param_struct(&vmag_param); tmagparam_fill_param_struct(&tmag_param); /* Initialize user interfaces */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); imagui_init(25, 685, imag_param); imagui_scale_horiz_axis(RT_NUM_STAND_CYCLES, RT_STAND_MIN, RT_STAND_MAX, RT_NUM_TEST_CURRENTS, RT_TEST_CURRENTS); tmagui_init(25, 350, tmag_param); rtui_init(25, 15); /* Message */ printf("\n\n*** Resistance and temperature measurement program RT ***\n"); /* Initialize the measurement systems */ imag_init(log_file, imag_param); vmag_init(log_file, vmag_param); tmag_init(log_file, tmag_param); /* Done */ return; } /* ************************************************************** */ /* * rt_meas * This function measures the magnet's resistance and temperature * as a function of time. * * Zachary Wolf * 12/18/00 */ void rt_meas(void) { /* Declare variables */ int i, j, k; int num_meas; int hr, min, sec; long t_start, t_now; double imag, vmag, rmag; int num_probes; double probe_temp[TMAG_MAX_NUM_PROBES]; /* Standardize the magnet */ if (RT_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(RT_STAND_MAX, RT_STAND_MIN, RT_NUM_STAND_CYCLES); } /* Message */ printf("\nBeginning the resistance and temperature measurements...\n"); /* Loop over the test currents */ for (i = 0; i < RT_NUM_TEST_CURRENTS; i++) { /* Ramp the magnet */ imag_ramp(RT_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(RT_TEST_CURRENTS[i]); /* Perform the resistance and temperature measurements */ num_meas = RT_TIME_TO_MEASURE_SEC / RT_TIME_BTWN_MEAS_SEC; for (k = 1; k <= num_meas; k++) { /* Get the starting time */ GetSystemTime(&hr, &min, &sec); t_start = hr*3600 + min*60 + sec; /* Measure the magnet current */ imag_get_current(&imag); /* Measure the magnet voltage */ vmag_get_voltage(&vmag); /* Compute the magnet resistance */ if (fabs(imag) > 0.01) rmag = fabs(vmag) / fabs(imag); else rmag = 0.; /* Measure all temperatures */ tmag_get_num_probes(&num_probes); for (i = 0; i < num_probes; i++) tmag_get_probe_temp(i, &probe_temp[i]); /* Write the result to the dat file */ rt_dat_meas(k+1, imag, vmag, rmag, num_probes, probe_temp); /* Write the result to the plt file */ rt_plt_meas(k+1, imag, vmag, rmag, num_probes, probe_temp); /* Display the results */ rtui_update(imag, vmag, rmag); tmagui_update(num_probes, probe_temp); /* Wait until it is time to do the next measurement */ do { GetSystemTime(&hr, &min, &sec); t_now = hr*3600 + min*60 + sec; } while (t_now - t_start < RT_TIME_BTWN_MEAS_SEC); } /* End loop over test currents */ } /* Done */ return; } /* ************************************************************** */ /* * rt_dat_meas * This function writes the results of an RT measurement * to the data file. * * Input: * meas_num, measurement number * imag, magnet current (A) * vmag, magnet voltage (V) * rmag, magnet resistance (ohms) * num_probes, number of temperature probes * probe_temps[0 to num_probes - 1], probe temperatures (deg C) * * Zachary Wolf * 12/20/00 */ void rt_dat_meas(int meas_num, double imag, double vmag, double rmag, int num_probes, double probe_temps[]) { /* Declare variables */ FILE* file_ptr; static int call_num; char probe_name[TMAG_MAX_NAME_LENGTH]; int i; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("rt_dat_meas: Unable to open dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Resistance and Temperature Measurements\n"); fprintf(file_ptr, "\n"); for (i = 0; i < num_probes; i++) { tmag_get_probe_name(i, probe_name); fprintf(file_ptr, "T%i = %s\n", i, probe_name); } fprintf(file_ptr, "\n"); fprintf(file_ptr, " Time Imag Rmag "); for (i = 0; i < num_probes; i++) fprintf(file_ptr, " T%i ", i); fprintf(file_ptr, "\n"); fprintf(file_ptr, " (A) (mohm) "); for (i = 0; i < num_probes; i++) fprintf(file_ptr, " (deg C)"); fprintf(file_ptr, "\n"); fprintf(file_ptr, "-------- ------- --------"); for (i = 0; i < num_probes; i++) fprintf(file_ptr, " -------"); fprintf(file_ptr, "\n"); } /* Write the data */ fprintf(file_ptr, "%s %7.2f %8.2f", TimeStr(), imag, rmag*1000.); for (i = 0; i < num_probes; i++) fprintf(file_ptr, " %7.2f", probe_temps[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * rt_plt_meas * This function writes the results of an RT measurement * to the plot file. * * Input: * meas_num, measurement number * imag, magnet current (A) * vmag, magnet voltage (V) * rmag, magnet resistance (ohms) * num_probes, number of temperature probes * probe_temps[0 to num_probes - 1], probe temperatures (deg C) * * Zachary Wolf * 12/20/00 */ void rt_plt_meas(int meas_num, double imag, double vmag, double rmag, int num_probes, double probe_temps[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int hr, min, sec; static long t_0; long t_now; int i; /* Open the dat file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { printf("rt_plt_meas: Unable to open magnet strength plt file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, ";time(min), imag(A), rmag(mohm), T0(C), T1(C), ...\n"); } /* Get a time reference on the first call */ if (call_num == 1) { GetSystemTime(&hr, &min, &sec); t_0 = hr*3600 + min*60 + sec; } /* Write the data */ GetSystemTime(&hr, &min, &sec); t_now = hr*3600 + min*60 + sec; fprintf(file_ptr, "%8.2f %7.2f %8.2f", (t_now - t_0) / 60., imag, rmag*1000.); for (i = 0; i < num_probes; i++) fprintf(file_ptr, " %7.2f", probe_temps[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ void rt_exit(void) { /* Exit the magnet current system */ imag_exit(); /* Exit the magnet voltage system */ vmag_exit(); /* Exit the temperature system */ tmag_exit(); /* Done */ return; } /* ************************************************************** */ /* * rt_error * This function handles errors for the Bhall vs Z module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void rt_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); }