#include #include #include //============================================================================== // // Title: Utilities.c // Purpose: A short description of the implementation. // // Created on: 5/7/2014 at 10:29:17 AM by Steve Marks. // Copyright: LBNL. All Rights Reserved. // //============================================================================== //============================================================================== // Include files #include "Utilities.h" #include "Hp3458.h" //============================================================================== // Constants #define LINE 80 //============================================================================== // Types //============================================================================== // Static global variables //============================================================================== // Static functions //============================================================================== // Global variables //============================================================================== // Global functions /// HIFN What does your function do? /// HIPAR x/What inputs does your function expect? /// HIRET What does your function return? // ****************************************************************************** // // RdParamFile Reads scan parameter file. Order of paramaters is fixed, // but any number of comment lines, deliniated by '#', // may be used // int RdParamFile (char *fname) { int i; int nDVM = 2; char buffer[80]; FILE *fpi; if ((fpi = fopen (fname, "r")) == NULL) { FileSelectPopup ("c:\\Users\\smarks\\Documents\\National Instruments\\CVI", "*.prm", "*.prm", "Find Parameter File", VAL_LOAD_BUTTON, 0, 0, 1, 0, fname); fpi = fopen (fname, "r"); } // Read DVM GPIB addresses for (i = 0; i < nDVM; i++) { fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%d", &GPIBDVM[i]); } // Read DVM Voltage scales for (i = 0; i < nDVM; i++) { fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &DCV[i]); } // Read integration time fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &int_tm); // specified in NPLC // Read scan velocity fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &Sc_V); // Read scan starting location fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &Sc_strt); // Read scan stop location fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &Sc_stp); // Read scan trigger spacing fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf", &trig_spc); // Read x, y, z probe location for reference measurement #1 fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf%lf%lf", &HP_x[0], &HP_y[0], &HP_z[0]); // Read x, y, z probe location for reference measurement #2 fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); sscanf (buffer, "%lf%lf%lf", &HP_x[1], &HP_y[1], &HP_z[1]); // Read Hall probe name or designator fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); for (i = 0; buffer[i] != '#'; i++) HP_name[i] = buffer[i]; HP_name[i] = '\0'; // Read Hall probe calibration file fgets (buffer, LINE, fpi); while (buffer[0] == '#') fgets (buffer, LINE, fpi); for (i = 0; buffer[i] != '#'; i++) HP_cal_file[i] = buffer[i]; HP_cal_file[i-1] = '\0'; return 0; } // ************************************************************************************* // // RdCalFile Reads Hall probe calibration file. A fixed format is assumed // int RdCalFile (char *cal_file) { int i; char buffer[80]; FILE *fpi; fpi = fopen (cal_file, "r"); for (i = 0; i < 12; i++) fgets (buffer, LINE, fpi); for (i = 0; i < NCAL; i++) { fgets (buffer, LINE, fpi); sscanf (buffer, "%lf%lf", &HP_cal_Vx[i], &HP_cal_Bx[i]); } for (i = 0; i < 2; i++) fgets (buffer, LINE, fpi); for (i = 0; i < NCAL; i++) { fgets (buffer, LINE, fpi); sscanf (buffer, "%lf%lf", &HP_cal_Vy[i], &HP_cal_By[i]); // printf ("%d %lf %lf\n", i, HP_cal_Vy[i], HP_cal_By[i]); } for (i = 0; i < 2; i++) fgets (buffer, LINE, fpi); for (i = 0; i < NCAL; i++) { fgets (buffer, LINE, fpi); sscanf (buffer, "%lf%lf", &HP_cal_Vz[i], &HP_cal_Bz[i]); // printf ("%d %lf %lf\n", i, HP_cal_Vz[i], HP_cal_Bz[i]); } fclose (fpi); return 1; } // ***************************************************************************** // // ProbeInterpolat Interpolate from calibration data. // Linear interpolation is sufficient since // Hall probes are very nearly linear // int ProbeInterpolate (double Vint, double *pBint, double *V, double *B, int nint) { int i; double Bint; if (Vint < V[0] || Vint > V[nint-1]) return 1; for (i = 0; i < nint; i++) { if (V[i] > Vint) break; } Bint = B[i-1] + (B[i] - B[i-1])*(Vint - V[i-1])/(V[i] - V[i-1]); *pBint = Bint; return 0; } // ***************************************************************************** // // LogRecord Record a text line (from UI) to log. // int LogRecord (char *IDname, FILE *fpl) { char *buffer; buffer = DateStr (); fprintf (fpl, "%s\n", buffer); buffer = TimeStr (); fprintf (fpl, "%s\n", buffer); fprintf (fpl, "%s\n", und_name); return 0; } // ***************************************************************************** // // WriteDataFile After completion of scan, write data to specified file. // int WriteDataFile (char *fname) { int i; FILE *fpo; FileSelectPopup (und_dir, und_file, "", "Data File", VAL_OK_BUTTON, 0, 0, 1, 0, und_file); // Add some header information // Write data fpo = fopen (und_file, "w"); fprintf (fpo, " n z[mm] Vx Vy Bx[T] By[T]\n"); for (i = 0; i < num_pnts; i++) fprintf (fpo, "%6d %10.2lf %12.4lf %12.4lf %12.4lf %12.4lf\n", i, z[i], Vx[i], Vy[i], Bx[i], By[i]); fclose (fpo); return 0; } // ***************************************************************************** // // RefMeas Take reference Hall probe measurement // index = 0 or 1, indicating the first or second reference measurement int RefMeas (int index) { // Move to specified x, y, z location // Measure votages hp3458_get_voltage(hp3458_ID[0], &Vx_ref[index]); hp3458_get_voltage(hp3458_ID[1], &Vy_ref[index]); // Convert to B ProbeInterpolate (Vx_ref[index], &Bx_ref[index], HP_cal_Vx, HP_cal_Bx, NCAL); ProbeInterpolate (Vy_ref[index], &By_ref[index], HP_cal_Vy, HP_cal_By, NCAL); return 0; } double GetTemp (int channel) { return 0; } int MoveProbe (double x, double y, double z) { return 0; }