The handling of evaluations will be changed in the next version of
libRASCH. Because we are working already on it, the sections about
evaluations, event-sets and event-propertiey may not work with the
current version (0.7.0). If you have any questions about the changes,
please send them to the mailing list.
//
#include <stdio.h>
#include <ra.h>
int main(int argc, char *argv[])
{
ra_handle ra;
value_handle vh;
ra_find_handle f;
struct ra_find_struct fs;
/* initialize libRASCH */
ra = ra_lib_init();
/* check if init was successful */
if ((ra == NULL)
|| (ra_lib_get_error(ra, NULL, 0) != RA_ERR_NONE))
{
if (!ra)
printf("error initializing libRASCH\n");
else
{
char err_t[200];
long err_num;
err_num = ra_lib_get_error(ra, err_t, 200);
printf("while initializing libRASCH, error #%d "
"occured\n %s\n", err_num, err_t);
ra_lib_close(ra);
}
return -1;
}
/* get some infos */
vh = ra_value_malloc();
if (ra_info_get(ra, RA_INFO_NUM_PLUGINS_L, vh) == 0)
{
printf("%s (%s): %d\n", ra_value_get_name(vh),
ra_value_get_desc(vh), ra_value_get_long(vh));
}
ra_value_free(vh);
/* find all measurements in a directory */
f = ra_meas_find_first(ra, argv[1], &fs);
if (f)
{
int cnt = 1;
printf("measurements found in %s:\n", argv[1]);
do
{
printf(" %2d: %s\n", cnt, fs.name);
cnt++;
}
while (ra_meas_find_next(f, &fs));
ra_meas_close_find(f);
}
/* close libRASCH */
ra_lib_close(ra);
return 0;
} /* main() */
//
To use libRASCH, the header-file ra.h must be included. In this
example the include-directory of libRASCH is in the INCLUDE path of
the C compiler. In ra.h you will find all function prototypes of the
API of libRASCH. ra.h includes the header-file ra_defines.h, there you
will find all define's and structure's needed for the libRASCH API.
ra_lib_init() initialize libRASCH. The function returns
an ra_handle.
ra_lib_get_error() returns the last error occured in
libRASCH. To check if the initialization was successful, check that no
error occured. If an error occured, a short description of the error
can be retrieved with the function ra_lib_get_error().
ra_value_malloc() returns an value object. This object will be used in
libRASCH to handle data. To set/get the data and to get informations
about the stored data, API functions in libRASCH are available. The
functions start with 'ra_value_*'.
ra_info_get() returns information about libRASCH and all objects
handled by libRASCH. RA_INFO_NUM_PLUGINS_L asks libRASCH for the the
number of loaded plugins. The last character of the info-id ('L')
indicates that the returned value will be a long-value. Therefore the
number of plugins will be returned by using the function
ra_value_get_long(). (See the descriptions of the ra_value_* functions
in the reference manual what else can be done with an value object.)
ra_value_free() frees the memory associated with the value object
allocated above.
ra_meas_find_first() returns a valid handle (not
NULL) if at least one supported measurement (this means that at least
one measurement in the directory can be handled with one of the loaded
access-plugins). The information about the found measurement will be
set in the ra_find_struct (for definition of structure see
ra_defines.h).
ra_meas_find_next() returns true (!= 0) if another
measurement is available. Again, the info about the measurement will
be in the ra_find_struct. This function iterates over all found
measurements.
ra_meas_close_find() frees all memory allocated during
ra_meas_find_first() and ra_meas_find_next().
ra_lib_close() unloads all plugins and frees all
allocated memory.
Running the example in the examples directory with the command
init_lib ./database produced the following output.
#plugins (): 30
measurements found in ./database:
1: ./database/JesusOlivan2003-12-EMG2.edf
2: ./database/100s.hea
The Perl script shown below produces exactly the same
output as the C version, therefore the output is not shown.
#
use strict;
use RASCH;
# initialize libRASCH
my $ra = new RASCH or die "error initializing libRASCH\n";
my ($err_num, $err_text) = $ra->get_error ();
if ($err_num != 1)
{
print "while initializing libRASCH, error # $err_num " .
"occured:\n $err_text\n";
exit -1;
}
# get some infos
my $value = $ra->get_info (info =>'num_plugins');
if ($value->is_ok())
{
print $value->name() . ' (' . $value->desc() . '): ' . $value->value() . "\n";
}
# find all measurements in a directory
my $meas = $ra->find_meas($ARGV[0]);
print "measurements found in $ARGV[0]:\n";
my $cnt = 1;
for (@$meas)
{
print $cnt . ': ' . $_->filename() . "\n";
$cnt++;
}
# ra_close() will be called when $ra is being destroyed
exit 0;
#
After installing the Perl support for libRASCH, the package RASCH.pm
is available.
Create a new RASCH object.
The function get_info() returns an array including (1) the value, (2)
the name and (3) a short description of the wanted information.
get_all_meas() returns an array with all the measurements found.
Here an Octave session using the libRASCH support is shown. The same
tasks are performed as in the previous examples. Most of the functions
have in Matlab and Octave the same behaviour. Differences are listed
in the function reference section for Matlab and Octave.
rasch@rasch:~> octave
GNU Octave, version 2.1.50 (i686-pc-linux-gnu).
...
octave:1> ra=ra_lib_init
ra = 145016336
octave:2> [err_num, err_text]=ra_lib_get_error(ra)
err_num = 1
err_text = libRASCH: no error
octave:3> [value, name, desc]=ra_lib_get_info(ra, 'num_plugins')
value = 25
name = #plugins
desc =
octave:4> meas=ra_meas_find(ra, './database')
meas =
{
[1,1] = ./database/JesusOlivan2003-12-EMG2.edf
[2,1] = ./database/100s.hea
}
octave:5>
Initialize libRASCH. If function call is successfull, a value not 0
will be returned.
The function returns an array including (1) the value, (2)
the name and (3) a short description of the wanted information.
The function returns a cell-array with all the measurements found.