/* ************************************************************** */ /* * Module BuckingCoil * This module contains functions which control bucking coil measurements. * * Zachary Wolf * 7/13/99 */ /* ************************************************************* */ /* INCLUDE FILES */ #include #include #include #include #include #include "param.h" #include "runparam.h" #include "vtcoil.h" #include "vtcoilparam.h" #include "vtcoilui.h" #include "blhar.h" #include "blharparam.h" #include "blharui.h" #include "imag.h" #include "imagparam.h" #include "imagui.h" #include "vmag.h" #include "vmagparam.h" #include "tmag.h" #include "tmagparam.h" #include "xmag.h" #include "xmagparam.h" #include "testparam.h" /* ************************************************************* */ /* PRIVATE FUNCTIONS */ void bucking_coil_init(void); void bucking_coil_meas(void); void bucking_coil_exit(void); void bucking_coil_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ bucking_coil_init(); /* Perform the measurements */ bucking_coil_meas(); /* Exit all systems */ bucking_coil_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ void bucking_coil_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; char log_file[80]; char str_dat_file[80]; char str_plt_file[80]; char har_dat_file[80]; char har_plt_file[80]; char mag_ctr_file[80]; char tst_par_file[80]; char pgm_par_file[80]; struct imag_param_struct imag_param; struct vmag_param_struct vmag_param; struct tmag_param_struct tmag_param; struct xmag_param_struct xmag_param; struct vtcoil_param_struct vtcoil_param; struct blhar_param_struct blhar_param; /* 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, "logfile", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "strdat", str_dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "strplt", str_plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "hardat", har_dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "harplt", har_plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "ctrdat", mag_ctr_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "tstpar", tst_par_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "pgmpar", pgm_par_file); if (err != 0) goto try_again; /* Save the parameter file */ err = CopyFile("param.h", pgm_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, str_dat_file); runparam_write_header(run_param, har_dat_file); runparam_write_header(run_param, mag_ctr_file); runparam_write_header(run_param, tst_par_file); imag_write_header(log_file, COIL_NUM_STAND_CYCLES, COIL_STAND_MAX, COIL_STAND_MIN, COIL_NUM_TEST_CURRENTS, COIL_TEST_CURRENTS); imag_write_header(str_dat_file, COIL_NUM_STAND_CYCLES, COIL_STAND_MAX, COIL_STAND_MIN, COIL_NUM_TEST_CURRENTS, COIL_TEST_CURRENTS); imag_write_header(har_dat_file, COIL_NUM_STAND_CYCLES, COIL_STAND_MAX, COIL_STAND_MIN, COIL_NUM_TEST_CURRENTS, COIL_TEST_CURRENTS); /* Fill system parameter structures */ vtcoilparam_fill_param_struct(&vtcoil_param); blharparam_fill_param_struct(&blhar_param); imagparam_fill_param_struct(&imag_param); vmagparam_fill_param_struct(&vmag_param); tmagparam_fill_param_struct(&tmag_param); xmagparam_fill_param_struct(&xmag_param); /* Initialize user interfaces */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); vtcoilui_init(25, 15, vtcoil_param); blharui_init(25, 350, blhar_param); blharui_scale_str_vs_imag(COIL_NUM_TEST_CURRENTS, COIL_TEST_CURRENTS); blharui_scale_bln_vs_n(); imagui_init(25, 685, imag_param); imagui_scale_horiz_axis(COIL_NUM_STAND_CYCLES, COIL_STAND_MIN, COIL_STAND_MAX, COIL_NUM_TEST_CURRENTS, COIL_TEST_CURRENTS); /* Message */ printf("\n\n*** Bucking Coil Measurement System ***\n"); /* Initialize measurement systems */ vtcoil_init(log_file, vtcoil_param); blhar_init(log_file, str_dat_file, har_dat_file, str_plt_file, har_plt_file, mag_ctr_file, blhar_param); imag_init(log_file, imag_param); vmag_init(log_file, vmag_param); tmag_init(log_file, tmag_param); xmag_init(log_file, xmag_param); testparam_init(tst_par_file, log_file, log_file); /* Done */ return; } /* ************************************************************** */ void bucking_coil_meas(void) { /* Declare all variables */ int i, j; double imag_ave, imag_rms; int num_str_har; double sl_ave, sl_rms; double th_ave, th_rms; struct blhar_data_struct blhar_data; double x_ave, x_rms; double y_ave, y_rms; char legend[80]; int num_test_param; char test_param_name[TESTPARAM_MAX_NUM_TEST_PARAM][TESTPARAM_MAX_NAME_LENGTH]; double test_param_value[TESTPARAM_MAX_NUM_TEST_PARAM]; /* Set the integrator gain to 1, open all multiplexer channels */ vtcoil_protect(); /* Locate the index pulse */ vtcoil_locate_index(); /* Standardize the magnet */ if (COIL_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(COIL_STAND_MAX, COIL_STAND_MIN, COIL_NUM_STAND_CYCLES); } /* Loop over the test currents */ for (i = 0; i < COIL_NUM_TEST_CURRENTS; i++) { /* Message */ printf("\nBegin measurement at current number %3i of %3i\n", i+1, COIL_NUM_TEST_CURRENTS); /* Set the integrator gain to 1, open all multiplexer channels */ vtcoil_protect(); /* Ramp the magnet */ imag_ramp(COIL_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(COIL_TEST_CURRENTS[i]); /* Measure the actual current */ imag_get_ave_current(&imag_ave, &imag_rms); /* Do a magnet strength measurement */ blhar_get_str_ave(&num_str_har, &sl_ave, &sl_rms, &th_ave, &th_rms); /* Write the results to the data file */ blhar_dat_str_ave(num_str_har, imag_ave, imag_rms, sl_ave, sl_rms, th_ave, th_rms); /* Write the results to the plot file */ blhar_plt_str_ave(num_str_har, imag_ave, imag_rms, sl_ave, sl_rms, th_ave, th_rms); /* Update the strength vs current plot */ blharui_update_str_vs_imag(imag_ave, sl_ave, sl_rms); /* Clear any previous harmonics plot */ blharui_clear_bln_vs_n(); /* Measure magnet test parameters */ testparam_meas(&num_test_param, test_param_name, test_param_value); /* Write the test parameter measurements to the data file */ testparam_dat_meas(num_test_param, test_param_name, test_param_value); /* Measure the harmonics only if requested */ if (COIL_MEAS_HAR_FLAGS[i] > 0) { /* Do a harmonics measurement */ blhar_get_blhar_ave(&blhar_data); /* Calculate the location of the magnetic center */ blhar_calc_magnetic_center(blhar_data, &x_ave, &x_rms, &y_ave, &y_rms); /* Write the results to the data file */ blhar_dat_blhar_ave(imag_ave, imag_rms, blhar_data, x_ave, x_rms, y_ave, y_rms); /* Write the results to the magnetic center data file */ blhar_dat_mag_ctr(imag_ave, x_ave, x_rms, y_ave, y_rms); /* Write the results to the plot file */ Fmt(legend, "%s