The calc() method is the interface to the Spectra calc command. The Spectra manual gives the details.
In the following examples the constructor (SCAN->create()) is used. It is described in 7.4.1.
The $var->calc( expr => "someExpr") is implemented in the following way: Spectra executes the command calc $var->name = someExpr. The expression $var->name is the name of the GQE.
Here is the first example:
#!/usr/bin/env perl use strict; use Spectra; my $t1 = SCAN->create( name => "t1", start => 0, stop => 10, delta => 0.1); $t1->calc( expr => "sin( x(t1))"); $t1->display(); Spectra::wait(); # Spectra::gra_input(); # invokes the CLI
The symbol $t1 points to a SCAN GQE. The name happens to be T1. In the calc expression the GQE can be referred to by T1 or by $t1-> name.
In the following example two SCANs, sin and cos, are created and the y-values are set by the calc() method. A third SCAN, tan, is created by duplicating the first SCAN. tan could have been 'created' as well since the number of points and the limits are known. In genral this is not he case, that's why the copy() method is useful.
Finally the y-values of tan are set to the ratio of sin divided by cos. Figure 7.1 shows the graphical screen.
#!/usr/bin/env perl use strict; use Spectra; my $sin = SCAN->create( name => "sin", start => 0, stop => 10, delta => 0.1, title => "Sinus", at => "(2,2,1)", colour => 'red'); $sin->calc( expr => "sin( x(sin))"); my $cos = SCAN->create( name => "cos", start => 0, stop => 10, delta => 0.1, title => "Cosinus", at => "(2,2,2)", colour => 'green'); $cos->calc( expr => "cos( x(cos))"); my $tan = SCAN->copy( from => "sin", to => "tan", title => "Tangens", at => "(1,2,2)", colour => 'blue'); $tan->calc( expr => "sin/cos"); Spectra::display(); Spectra::wait();
In the next example was used as extra code for the after scan macro. The input from c5at means, the symbol $Spectra::SYM scan_name exists and the counters c1 and c5 have been selected for the measurement.
my $sname = $Spectra::SYM{ scan_name}; my $src = SCAN->locate( name => $sname); my $res = SCAN->copy( from => $src, to => $sname . "_res"); $res->calc( expr => "${sname}_c5/${sname}_c1"); $res->write( format => "asc", file_name => $sname); $res->delete();