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 Measurements

3.2. Access Measurements

The example will show how to open a measurement and how to get some information from a measurement. We will perform the following steps:

  • open a measurement

  • get the number of sessions and the maximum samplerate

  • print all available infos about the measurement object (in this example it is a patient)

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

int main(int argc, char *argv[])
{
    ra_handle ra;
    value_handle vh;
    meas_handle meas;

    /* initialize libRASCH */
    ra = ra_lib_init();
    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;
    }

    /* open measurement */
    meas = ra_meas_open(ra, argv[1], 0); (1)
    if (meas == NULL)
    {
        char err_t[200];
        long err_num;

        err_num = ra_lib_get_error(ra, err_t, 200);
        printf("can't open measurement %s\nerror #%d: %s\n",
               argv[1], err_num, err_t);
        ra_lib_close(ra);
        return -1;
    }

    /* get some infos */
    vh = ra_value_malloc();
    if (ra_info_get(meas, RA_INFO_NUM_SESSIONS_L, vh) == 0)
        printf("%s (%s): %d\n", ra_value_get_name(vh),
               ra_value_get_desc(vh), ra_value_get_long(vh));
    if (ra_info_get(meas, RA_INFO_MAX_SAMPLERATE_D, vh) == 0)
        printf("%s (%s): %f\n", ra_value_get_name(vh),
               ra_value_get_desc(vh), ra_value_get_double(vh));

    /* get all measurement-object infos */
    if (ra_info_get(meas, RA_INFO_NUM_OBJ_INFOS_L, vh) == 0) (2)
    {
        long l;
        long n = ra_value_get_long(vh);

        for (l = 0; l < n; l++)
        {
            ra_info_get_by_idx(meas, RA_INFO_OBJECT, l, vh); (3)
            printf("%s (%s): ", ra_value_get_name(vh),
                   ra_value_get_desc(vh));
            switch (ra_value_get_type(vh)) (4)
            {
            case RA_VALUE_TYPE_LONG:
                printf("%d\n", ra_value_get_long(vh));
                break;
            case RA_VALUE_TYPE_DOUBLE:
                printf("%f\n", ra_value_get_double(vh));
                break;
            case RA_VALUE_TYPE_CHAR:
                printf("%s\n", ra_value_get_string(vh));
                break;
            default:
                printf("not supported type\n");
                break;
            }
        }
    }

    /* close */
    ra_value_free(vh);
    ra_meas_close(meas);
    ra_lib_close(ra);

    return 0;
}                               /* main() */

//
(1)
ra_open_meas() opens a measurement. The user do not need to specify the format in which the measurement was saved, libRASCH selects the access plugin which can handle the format. If no access plugin can handle the measurement, the function fails. The third parameter (here it is set to '0') controls if a fast-open should be done (set to '1'). When a fast-open is selected, some "time-consuming" initialization is skipped and only the object informations and some basic recording informations (e.g. recording date) are available. [1]
(2)
With this call, the number of available measurement objects is returned. In the following loop, we will get all available informations about the measurement object.
(3)
With the function ra_info_get_by_idx() we select the information we want by a number. Because we do not know which number is which information, this function is only useful to display all available data in a list.
(4)
Because we do not know which information is returned, we do not know the type of the information. Therefore we have to get the type of the information so we use the correct way to display the information.

The output of the above example for the measurement '100s' is shown here:

#sessions (): 1
max. samplerate (maximum samplrate used in measurement):
360.000000
ID (Patient-ID): 100s

Notes

[1]

Some access plugins do not differ between fast and normal open. But it is recommended, when writing access plugins, to skip time consuming tasks when fast-open was selected. This decreases the time needed to list all measurements in a directory.