The Spectra-Perl interface is developed following the aim to make the Spectra features available to Perl programmers in an elegant way. Since only a part of the work has been done so far, Spectra programmers may be interested to learn about the low level interface to be able to do the things themselves.
The module Spectra.pm exports several functions. Their usage is demonstrated in the following example.
#!/usr/bin/perl use Spectra; # # Spectra::gra_command returns 1 to indicate a successful completion, 0 otherwise # $ret = Spectra::gra_command( "delete *.*"); $ret = Spectra::gra_command( "create test 0 10 100"); $ret = Spectra::gra_command( "display"); if( !$ret) { print " An error occurred ... \n"; prtc(); return; } # # Gra_decode_... return a number, a string or "undef" to indicate an error # $x_min = Spectra::gra_decode_double( "attr(test, x_min)"); $colour = Spectra::gra_decode_int( "attr(test, colour)"); $date = Spectra::gra_decode_text( "date()"); if( ! defined $date ) { print " An error occured ... \n"; prtc(); return; } print " x_min: $x_min \n"; print " colour: $colour \n"; print " date: $date \n"; prtc(); # # enter Spectra # Spectra::gra_input();
Notice that Spectra::gra_command()
always returns a numerical value: 0 or 1.
In contrast, the Spectra::gra_decode_...
functions return undef
to indicate an error. In Perl a variable can have the value undef.
This feature allows us to handle the data transfer from Spectra to
Perl in a compact form. Otherwise one had to pass a data structure
consisting of a return status and a value.
Notice also that double-quoted strings are subject of variable interpolation of scalar and list values:
#!/usr/bin/perl use Spectra; $var = "test"; $start = 0; $stop = 10; $np = 100; $ret = Spectra::gra_command( "create $var $start $stop $np");
1