TUM-Logo

libRASCH

 

Home
 

General

About libRASCH/News
Design
Screen shots
Sample programs (with source code)
License
 

Download

libRASCH
Tools
 

Documentation

User
Developer
 

Resources

Mailing list
Supported Formats
Plugins
Status
Links
 
Contact
About this site
 
Last updated
Tue Mar 27 23:03:50 2007
Examples for all supported lanuages/systems

Appendix A. Examples for all supported lanuages/systems

This appendix shows the examples presented in Chapter 3 for all supported languages/systems.

A.1. Init libRASCH

A.1.1. C Version

//
#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() */

//

#plugins (): 30
measurements found in ./database:
   1: ./database/JesusOlivan2003-12-EMG2.edf
   2: ./database/100s.hea

A.1.2. Perl Version

#
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;
#

#plugins (): 30
measurements found in ./database:
1: ./database/JesusOlivan2003-12-EMG2.edf
2: ./database/100s.hea

A.1.3. Python Version

#
import sys
from RASCH import *

# initialize libRASCH
ra = RASCH()
if not ra:
    print "can't initialize libRASCH"
    sys.exit()
[err_num, err_text] = ra.get_error()
if err_num != 1:
    print "while initializing libRASCH, error #%d occured:\n "           "%s\n" % err_num, err_text
    sys.exit()
    
# get some infos
[value, name, desc] = ra.get_info(info='num_plugins')
if (value):
    print name, "("+desc+"):", value

# find all measurements in a directory
meas = ra.get_all_meas(sys.argv[1])
print "measurements found in " + sys.argv[1] + ":\n"
cnt = 1
for item in meas:
    print "%d: %s" % (cnt, item)
    cnt = cnt + 1

#

#plugins (): 30
measurements found in ./database:

1: ./database/JesusOlivan2003-12-EMG2.edf
2: ./database/100s.hea

A.1.4. Matlab/Octave Version

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>