Back: 9. Example EDL Scripts Forward: 9.2 GUI-fying the script   FastBack: 9. Example EDL Scripts Up: 9. Example EDL Scripts FastForward: 10. Command Line Options         Top: fsc2 Contents: Table of Contents Index: Index About: About This Document

9.1 An enhanced cw-EPR experiment

In the chapter describing the EDL language (see EDL) already a script for doing a very simple cw-EPR experiment was given. Here we will now enhance this script a bit to allow e.g. multiple runs over the field range:

 
 1 DEVICES:
 2   er035m_s;              // gaussmeter module
 3   aeg_x_band;            // magnet module
 4   sr530;                 // lock-in amplifier module
 5 
 6 VARIABLES:
 7   start_field    = 3360.0 G;
 8   end_field      = 3450.0 G;
 9   field_step     =    0.5 G;
10   Number_of_runs = 10;
11 
12   field = start_field;
13   Number_of_points = 1 + int( ( start_field - end_field ) 
14                               / field_step );
15   data;
16   mean_data[ Number_of_points ];
17   I, J;
18   File_1, File_2;
19   tc;
20 
21 PREPARATIONS:
22   magnet_setup( start_field, field_step );
23   init_1d( 2, Number_of_points, start_field, field_step,
24            "Magnetic field [G]", "Signal strength [uV]"  );
25 
26 EXPERIMENT:
27 
28   File_1 = get_file( "File for storing all runs:" );
29   File_2 = get_file( "File for storing end results:" );
30 
31   tc = lockin_time_constant( );
32 
33   FOR I = 1 : Number_of_runs
34   {
35     FOR J = 1 : Number_of_points
36     {
37       wait( tc );
38       data = lockin_get_data( );
39       mean_data[ J ] += data;
40       display_1d( J, data / 1 uV, 1,
41                   J, mean_data[ J ] / ( I * 1 uV ), 2 );
42       fsave( File_1, "# #\n", field, data );
43       field = magnet_sweep_up( );
44     }
45 
46     fsave( File_1, "\n" );
47     field = magnet_reset_field( );
48     clear_curve( 1 );
49   }
50 
51   fsave( File_2, "% Start field     = # G\n", start_field );
52   fsave( File_2, "% End field       = # G\n", end_field );
53   fsave( File_2, "% Field step      = # G\n", field_step );
54   fsave( File_2, "% Number of runs  = #\n", Number_of_runs );
55   fsave( File_2, "% Time constant   = # ms\n", tc / 1 ms );
56   save( File_2, mean_data / Number_of_runs );

The DEVICES section is identical to the original script, again we use the AEG X-band magnet (controlled via the Bruker ER 035 M gaussmeter) and the SR 530 lock-in amplifier.

Also the first lines of the VARIABLES section are identical, we need three variables for the start field, the end field and the field step size. But now also another variable for the number of runs we'll do during the experiment is needed, which we declare in line 10.

The following variables are all auxiliary variables. Number_of_points is automatically initialized to the number of points during one run (we got to add 1, otherwise we wouldn't get the last point of the field range). The next variables, data and mean_data are both for storing the results f the experiment. But since (as the name indicates) mean_data is going to be used to store the mean value of all data points it needs to be an array with enough space for all points of the spectrum.

The variables I and J are simple counters and File_1 and File_2 are integer variables that we will be used for file handles - we are going to use two files, one for storing intermediate results, i.e. all single run spectra, and a second one for saving the end results, i.e. the mean values of the data from all runs. Finally, tc is going to be used for the lock-in's time constant.

Also the first line of the PREPARATIONS section hasn't changed, again we set up the magnet using magnet_setup() to be started at a field as stored in the variable start_field and tell it, that sweeps will be done with step sizes of field_step.

But the graphics initialization using the function init_1d() in line 23 has been changed a bit. Instead of using the defaults, we now request 2 curves (one for the newly measured data points and one for the mean values of all runs don so far). Also, we indicate that the curves will be Number_of_points long. The next two values set up the scale of the x-axis: the x-axis should start with a value of start_field and the difference between two points in x-direction is field_step. Finally, we also set labels for the x- and y-axis: the values at the x-axis are the magnetic fields (in Gauss) and the y-axis will represent the measured signal intensity in microvolt.

The first thing done in the EXPERIMENT section is asking the user to supply two file names - what we get back from the functions are integer numbers that are going to be used later to indicate into which of the two files data are to be written to (should the user hit the Cancel button to indicate that (s)he doesn't want to write out the data to a file the number returned will tell fsc2 not to open a file and skip commands for writing data to this file).

The next step (line 31) is to determine the lock-in amplifiers time constant, we will have to wait for this time after a field sweep step to give the lock-in enough time to measure a new value.

The actual experiment now consists of two loops, a main loop for doing all the consecutive runs over the field range, and an embedded loop for acquiring, displaying and storing each data point in a run. Both loops are realized by FOR loops because for both we know exactly how many times each one has to be repeated.

Within the inner loop, i.e. for each data point we wait for the lock-in amplifiers time constant to measure a new data point at the current field, which we then fetch from the lock-in amplifier (line 38) and store it in the variable data. The new value now gets added to the appropriate element of the array of mean values.

In line 40/41 the new data value and the new mean value both are displayed on the screen. The first three arguments of the call of the function display_1d() are the x-coordinate, which is just the loop counter variable, the y-coordinate, the new data value but devided by 1 uV because the value returned by the lock-in amplifiers is always in Volts and we want to display the value in code micro-Volts, and the number of the curve, 1. The next three arguments are for the new mean value, we only have to take care to divide the mean_data array element by I, the number of runs done so far.

If you have trouble understanding why the x-coordinate is passed to display_1d() as an integer numbers but on the screen the scale is being shown in field units, here's an explanation: in the init_1d() function call during the PREPARATIONS section we told the program that the first x-axis value would be at a field of the value of start_field and that all following fields would be equally spaced by a field difference according to the value of the second variable, field_step. The program uses this information to convert a x-coordinate of 1 to make the data point appear at the field scale value of start_field, a x-coordinate of 2 at start_value + field_step etc.

The next instruction (line 42) stores the newly measured value, together with the current field, in the first file. In this case we use the function fsave() to write both the current field (as stored in the variable field) and the new data into the (first) file. According to the format string both values will appear on one line.

All now still to be done in the inner loop is to sweep to a new magnetic field (which, according to the our call of magnet_setup() in the PREPARATIONS section is supposed to be field_step higher than the current value). When the magnet has reached the new field the magnet_sweep_up() function returns the new field value which gets stored in the variable field.

When the inner loop has been repeated Number_of_points times we have reached the end field and now have to start a new scan. First we write an empty line into the file for the data of all runs in order to have a visual indication where the data of the new run start. Then we have to set the field back to the start field, which can be done by calling the function magnet_reset_field() (you actually also could also tell the magnet to go to a field of start_field by calling magnet_field() with start_field as its only argument). Finally, we have to remove the data of the last run from the screen but keeping the curve with the mean values. This is done by calling the function clear_curve() with the number of the curve to be removed (which is 1) as the parameter. Then we proceed with the inner loop.

When the experiment finally is done, i.e. when we're finished doing the Number_of_runs repetitions of the field sweep we end up at line 51 where we now can store the whole array of mean values, together with some information about the experimental parameters. Please note that using the function save() it is possible to write whole (one-dimensional) arrays with one call. You also see here an example of arithmetic done on arrays: all array elements of mean_data are automatically divided by Number_of_runs before being written to the file.


Back: 9. Example EDL Scripts Forward: 9.2 GUI-fying the script   FastBack: 9. Example EDL Scripts Up: 9. Example EDL Scripts FastForward: 10. Command Line Options

This document was generated by Jens Thoms Toerring on September 6, 2017 using texi2html 1.82.