/* ************************************************************** */ /* * Module WireScan * This module contains functions which control wire scan measurements. * * Zachary Wolf * 3/27/00 */ /* ************************************************************* */ /* INCLUDE FILES */ #include #include #include #include #include #include "param.h" #include "runparam.h" #include "blscan.h" #include "blscanparam.h" #include "blscanui.h" #include "vtscan.h" #include "vtscanparam.h" #include "vtscanui.h" #include "imag.h" #include "imagparam.h" #include "imagui.h" /* ************************************************************* */ /* PRIVATE FUNCTIONS */ void wire_scan_init(void); void wire_scan_meas(void); void wire_scan_exit(void); void wire_scan_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ wire_scan_init(); /* Perform the measurements */ wire_scan_meas(); /* Exit all systems */ wire_scan_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ void wire_scan_init(void) { /* Declare variables */ struct run_param_struct run_param; int err; char log_file[80]; char dat_file[80]; char plt_file[80]; struct blscan_param_struct blscan_param; struct vtscan_param_struct vtscan_param; struct imag_param_struct imag_param; 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, "scanlog", log_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "scandat", dat_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "scanplt", plt_file); if (err != 0) goto try_again; err = runparam_create_file(run_param, "scanpar", 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, SCAN_NUM_STAND_CYCLES, SCAN_STAND_MAX, SCAN_STAND_MIN, SCAN_NUM_TEST_CURRENTS, SCAN_TEST_CURRENTS); imag_write_header(dat_file, SCAN_NUM_STAND_CYCLES, SCAN_STAND_MAX, SCAN_STAND_MIN, SCAN_NUM_TEST_CURRENTS, SCAN_TEST_CURRENTS); /* Get all parameters */ vtscanparam_fill_param_struct(&vtscan_param); blscanparam_fill_param_struct(&blscan_param); imagparam_fill_param_struct(&imag_param); /* Initialize the user interface */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); vtscanui_init(25, 15, vtscan_param); blscanui_init(25, 350, blscan_param); imagui_init(25, 685, imag_param); imagui_scale_horiz_axis(SCAN_NUM_STAND_CYCLES, SCAN_STAND_MIN, SCAN_STAND_MAX, SCAN_NUM_TEST_CURRENTS, SCAN_TEST_CURRENTS); /* Message */ printf("\n\n*** Wire Scan Measurement System ***\n"); /* Initialize all systems */ vtscan_init(log_file, vtscan_param); blscan_init(log_file, dat_file, plt_file, blscan_param); imag_init(log_file, imag_param); /* Done */ return; } /* ************************************************************** */ void wire_scan_meas(void) { /* Declare variables */ int i, j, k; double imag_ave, imag_rms; double bln_double_coil_ave[SCAN_NUM_HAR + 1]; double bln_double_coil_rms[SCAN_NUM_HAR + 1]; double bln_single_coil_ave[SCAN_NUM_HAR + 1]; double bln_single_coil_rms[SCAN_NUM_HAR + 1]; double bln_wire_ave[SCAN_NUM_HAR + 1]; double bln_wire_rms[SCAN_NUM_HAR + 1]; double bln_ave[SCAN_NUM_HAR + 1]; double bln_rms[SCAN_NUM_HAR + 1]; /* Move the wire to the global offset position and zero the stages */ printf("\nMoving to the global offset position...\n"); vtscan_move_wire_abs(SCAN_X0_POS_GLOBAL_OFFSET); vtscan_zero_pos(); /* Standardize the magnet */ if (SCAN_NUM_STAND_CYCLES > 0) { printf("\nStandardizing the magnet...\n"); imag_standardize(SCAN_STAND_MAX, SCAN_STAND_MIN, SCAN_NUM_STAND_CYCLES); } /* Loop over the test currents */ for (i = 0; i < SCAN_NUM_TEST_CURRENTS; i++) { /* Ramp the magnet */ imag_ramp(SCAN_TEST_CURRENTS[i]); for (j = 1; j <= 30; j++) imagui_update(SCAN_TEST_CURRENTS[i]); /* Measure the magnet current */ imag_get_ave_current(&imag_ave, &imag_rms); /* Message */ printf("\nBeginning the wire measurements...\n"); /* Perform the scan with the wire */ blscan_get_bln_ave(BLSCAN_WIRE, SCAN_NUM_HAR, bln_wire_ave, bln_wire_rms); /* Write the result to the dat file */ blscan_dat_bln_config_ave(BLSCAN_WIRE, imag_ave, imag_rms, SCAN_NUM_HAR, bln_wire_ave, bln_wire_rms); /* Message */ printf("\nBeginning the single coil measurements...\n"); /* Perform the scan with the single coil */ blscan_get_bln_ave(BLSCAN_SINGLE_COIL, SCAN_NUM_HAR, bln_single_coil_ave, bln_single_coil_rms); /* Write the result to the dat file */ blscan_dat_bln_config_ave(BLSCAN_SINGLE_COIL, imag_ave, imag_rms, SCAN_NUM_HAR, bln_single_coil_ave, bln_single_coil_rms); /* Message */ printf("\nBeginning the double coil measurements...\n"); /* Perform the scan with the double coil */ blscan_get_bln_ave(BLSCAN_DOUBLE_COIL, SCAN_NUM_HAR, bln_double_coil_ave, bln_double_coil_rms); /* Write the result to the dat file */ blscan_dat_bln_config_ave(BLSCAN_DOUBLE_COIL, imag_ave, imag_rms, SCAN_NUM_HAR, bln_double_coil_ave, bln_double_coil_rms); /* Summarize the results */ for (k = 1; k <= 1; k++) { bln_ave[k] = bln_wire_ave[k]; bln_rms[k] = bln_wire_rms[k]; } for (k = 2; k <= 3; k++) { bln_ave[k] = bln_single_coil_ave[k]; bln_rms[k] = bln_single_coil_rms[k]; } for (k = 4; k <= SCAN_NUM_HAR; k++) { bln_ave[k] = bln_double_coil_ave[k]; bln_rms[k] = bln_double_coil_rms[k]; } /* Write the result to the dat file */ blscan_dat_bln_ave(imag_ave, imag_rms, SCAN_NUM_HAR, bln_ave, bln_rms); /* Write the result to the plt file */ blscan_plt_bln_ave(imag_ave, imag_rms, SCAN_NUM_HAR, bln_ave, bln_rms); /* Move the wire back to the zero position */ printf("\nMoving back to the zero position...\n"); vtscan_move_wire_abs(0.); /* End loop over test currents */ } /* Take out the global coordinate system offset and rezero the stages */ printf("\nMoving back to the global zero position...\n"); vtscan_move_wire_abs(-SCAN_X0_POS_GLOBAL_OFFSET); vtscan_zero_pos(); /* Done */ return; } /* ************************************************************** */ void wire_scan_exit(void) { /* Declare variables */ char buf[80]; /* Exit the VTscan system */ vtscan_exit(); /* Exit the magnet current system */ imag_exit(); /* Pause to let the operator view the display */ printf("\nPress ENTER to exit the program.\n"); fgets(buf, 80, stdin); /* Done */ return; } /* ************************************************************** */ /* * wire_scan_error * This function handles errors for the stretched wire module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void wire_scan_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); }