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
Access raw data

A.4. Access raw data

A.4.1. C Version

//
#include <stdlib.h>
#include <ra.h>

int main(int argc, char *argv[])
{
    ra_handle ra;
    value_handle vh;
    meas_handle meas;
    rec_handle rec;
    long l, num_ch;
    double *buf = NULL;

    /* initialize libRASCH */
    ra = ra_lib_init();
    if (ra == NULL)
    {
        printf("error initializing libRASCH\n");
        return -1;
    }

    /* open measurement */
    meas = ra_meas_open(ra, argv[1], 0);
    if (meas == NULL)
    {
        printf("can't open measurement %s\n", argv[1]);
        return -1;
    }

    /* get root recording */
    rec = ra_rec_get_first(meas, 0);
    if (rec == NULL)
    {
        printf("can't get recording-handle\n");
        return -1;
    }

    /* get first 10000 samples for each channel */
    vh = ra_value_malloc();
    if (ra_info_get(rec, RA_INFO_REC_GEN_NUM_CHANNEL_L, vh) == 0)
        num_ch = ra_value_get_long(vh);
    buf = malloc(sizeof(double) * 10000);
    for (l = 0; l < num_ch; l++)
    {
        long m, num_read;

        num_read = ra_raw_get_unit(rec, l, 0, 10000, buf);
        for (m = 0; m < num_read; m++)
            ;                   /* do something with every sample */
    }

    /* clean up */
    free(buf);
    ra_value_free(vh);
    ra_meas_close(meas);
    ra_lib_close(ra);

    return 0;
}                               /* main() */

//

A.4.2. Perl Version

#
use strict;
use RASCH;

# initialize libRASCH
my $ra = new RASCH or die "error initializing libRASCH\n";

# open measurement
my $meas = $ra->open_meas($ARGV[0], 0) or
    die "can't open measurement $ARGV[0]\n";

# get root recording
my $rec = $meas->get_first_session_rec(0) or
    die "can't get root recording\n";

# get first 10000 samples for each channel
my ($num_ch) = $rec->get_info(info => 'rec_num_channel');
for (my $i = 0; $i < $num_ch; $i++)
{
    my $data_ref = $rec->get_raw($i, 0, 10000);
    for (@$data_ref)
    {
	; # do something with every sample
    }
}

exit 0;
#

A.4.3. Python Version

#
import sys
from RASCH import *

# initialize libRASCH
ra = RASCH()
if not ra:
    print "can't initialize libRASCH"
    sys.exit()

# open measurement
meas = ra.open_meas(sys.argv[1], 0)
if not meas:
    print "can't open measurement", sys.argv[1]
    sys.exit()

# get root recording
rec = meas.get_first_session_rec(0)
if not rec:
    print "can't get root recording"
    sys.exit()

# get first 10000 samples for each channel
[num_ch, n, d] = rec.get_info(info='rec_num_channel')
if num_ch > 0:
    for i in range(num_ch):
        data = rec.get_raw(i, 0, 10000)
        for elem in data:
            elem # do something with every sample

#

A.4.4. Matlab/Octave Version

rasch@rasch:~> octave
GNU Octave, version 2.1.50 (i686-pc-linux-gnu).
...

octave:1> ra=ra_lib_init
ra = 145017272
octave:2> meas=ra_meas_open(ra, '/home/rasch/ecgs/AT011030_rdi.ART', 0)
meas = 145244336
octave:3> rec=ra_rec_get_first(meas, 0)
rec = 145421120
octave:4> num_ch=ra_rec_get_info(rec, 'rec_num_channel')
num_ch = 5
octave:5> ch_all=[];
octave:6> for i=0:(num_ch-1)
> ch=ra_raw_get(rec, i, 0, 10000);
> ch_all=[ch_all ch'];
> endfor
octave:7> whos ch_all

*** local user variables:

prot  type                       rows   cols  name
====  ====                       ====   ====  ====
 rwd  matrix                    10000      5  ch_all

octave:8> samplerate=ra_ch_get_info(rec, 0, 'ch_samplerate')
samplerate = 1600
octave:9> x=0:9999;
octave:10> x = x / samplerate;
octave:11> figure(0); plot(x, ch_all(:,1));
octave:12> figure(1); plot(x, ch_all(:,2));
octave:13> figure(2); plot(x, ch_all(:,3));
octave:14> figure(3); plot(x, ch_all(:,4));
octave:15> figure(4); plot(x, ch_all(:,5));
octave:16>