/* ************************************************************** */ /* * Module BSCAN * This module contains functions to make magnetic field measurements * from a moving probe. The probe is moved continuously and output * voltage measurements are triggered by an encoder. * * Zachary Wolf * 11/21/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include #include "movez.h" #include "vscan.h" #include "calib.h" #include "bscan.h" #include "bscanui.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static char plt_file[100]; static struct bscan_param_struct bscan_param; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static char msg[BSCAN_MAX_NUM_CHAR]; /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int bscan_check_param(void); void bscan_error(char* message); void bscan_message(char* message); void bscan_log_get_b(double start_pos, double dist_move, int num_samp, double pos_samp[], double v_samp[], double b_samp[]); void bscan_log_calc_b(double v, double b); void bscan_calc_b(double v, double* b); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * bscan_init * This function is used to initialize the magnetic field scan * measurement system. * * Zachary Wolf * 11/21/02 */ void bscan_init(char log_file_in[], char plt_file_in[], struct bscan_param_struct bscan_par) { /* Declare variables */ int err; /* Save parameters for future use */ strcpy(log_file, log_file_in); strcpy(plt_file, plt_file_in); bscan_param = bscan_par; /* Check all parameter values to find any problems */ err = bscan_check_param(); if (err != 0) { bscan_error("Problem with parameter values"); return; } /* Done */ return; } /* ************************************************************** */ /* * bscan_get_b * This function measures the magnetic field from a probe as * the probe is moved. * * Input: * start_pos, start position of the probe (m) * dist_move, distance the probe moves, sign gives the direction (m) * * Output: * num_samp, the number of field samples * pos_samp[0 to num_samp - 1], positions of the samples (m) * v_samp[0 to num_samp - 1], measured probe output voltage samples (V) * b_samp[0 to num_samp - 1], magnetic field values (T) * * Zachary Wolf * 11/21/02 */ void bscan_get_b(double start_pos, double dist_move, int* num_samp, double pos_samp[], double v_samp[], double b_samp[]) { /* Declare variables */ int err; char probe_name[BSCAN_MAX_NUM_CHAR]; /* Check input parameters */ if (fabs(start_pos) > 1.) { bscan_error("bscan_get_b: start_pos has improper value"); return; } if (fabs(dist_move) < 1.e-6 || fabs(dist_move) > 10.) { bscan_error("bscan_get_b: dist_move has improper value"); return; } /* Check all module level parameter values */ err = bscan_check_param(); if (err != 0) { bscan_error("Problem with parameter values"); return; } /* Measure the output voltage from the probe as it is moved */ vscan_get_v(start_pos, dist_move, num_samp, pos_samp, v_samp); /* Read the probe calibration file */ calib_read_calib_data_file(bscan_param.probe_calib_file); void calib_get_calib_data(char calib_data_file_name[], struct calib_data_struct* calib_data); xxx /* Check the name of the probe in the calibration file */ calib_get_probe_name(probe_name); if (strstr(probe_name, bscan_param.probe_name) == NULL) bscan_error("Wrong probe name returned from calibration file"); /* Calculate the magnetic field values from the voltages */ calib_apply_calib_data_cubic_spline(*num_samp, v_samp, b_samp); /* Log the measurement */ bscan_log_get_b(start_pos, dist_move, *num_samp, pos_samp, v_samp, b_samp); /* Done */ return; } /* ************************************************************** */ /* * bscan_plt_b * This function plots the magnetic field from a probe as * the probe is moved. * * Input: * num_samp, the number of field samples * pos_samp[0 to num_samp - 1], positions of the samples (m) * v_samp[0 to num_samp - 1], measured probe output voltage samples (V) * b_samp[0 to num_samp - 1], magnetic field values (T) * * Zachary Wolf * 12/12/02 */ void bscan_plt_b(int num_samp, double pos_samp[], double v_samp[], double b_samp[]) { /* Declare variables */ FILE* file_ptr; int i; /* Open the plt file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { bscan_message("Unable to open plt file"); return; } /* Write the values to the plt file */ fprintf(file_ptr, "%% pos (m), V (V), B (T)\n"); for (i = 0; i < num_samp; i++) fprintf(file_ptr, "%f %f %f\n", pos_samp[i], v_samp[i], b_samp[i]); /* Close the plt file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * bscan_exit * This function is used to exit the magnetic field * measurement system. * * Zachary Wolf * 11/21/02 */ void bscan_exit(void) { /* Exit the system */ /* nothing needs to be done */ /* Done */ return; } /* ************************************************************** */ /* INTERNAL FUNCTIONS */ /* ************************************************************** */ /* * bscan_error * This function handles errors for the BSCAN module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void bscan_error(char* message) { /* Declare variables */ char buf[BSCAN_MAX_NUM_CHAR]; /* Notify the operator of the error */ printf("\nBSCAN ERROR: %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, BSCAN_MAX_NUM_CHAR, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* * bscan_message * This function handles messages for the IMAG module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/12/98 */ void bscan_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * bscan_check_param * This function checks that all required parameters have been assigned * appropriate values. * * Output: * err, 0 = no error, non-zero = error * * Zachary Wolf * 11/21/02 */ int bscan_check_param() { /* log_file */ if (CompareStrings(log_file, 0, "", 0, 0) == 0) { bscan_error("Log file not defined."); return -1; } /* bscan_param.probe */ /* OK since enum */ /* probe_calib_file */ if (CompareStrings(bscan_param.probe_calib_file, 0, "", 0, 0) == 0) { bscan_error("Probe calibration file not defined."); return -1; } /* bscan_param.show_ui */ /* OK since enum */ /* If we made it this far, all parameters have values */ return 0; } /* ************************************************************** */ /* * bscan_log_get_b * This function logs the result of a field scan measurement. * * Input: * start_pos, starting position of the probe (m) * dist_move, distance the probe moves, sign gives the direction (m) * num_samp, the number of voltage samples to take * pos_samp[0 to n-1], positions of the samples (m) * v_samp[0 to n-1], voltage samples (V) * b_samp[0 to n-1], field samples (T) * * Zachary Wolf * 11/21/02 */ void bscan_log_get_b(double start_pos, double dist_move, int num_samp, double pos_samp[], double v_samp[], double b_samp[]) { /* Declare variables */ FILE* file_ptr; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { bscan_message("Unable to open log file"); return; } /* Write the values to the log file */ fprintf(file_ptr, "%s Magnetic Field Samples Measurement\n", TimeStr()); fprintf(file_ptr, " start_pos = %f (m), dist_move = %f (m), num_samp = %i\n", start_pos, dist_move, num_samp); /* Close the log file */ fclose(file_ptr); /* Done */ return; }