[med-svn] [SCM] aghermann branch, master, updated. 99b1d5a023eee9df74b0e0d6f894516fc79435ad
Andrei Zavada
johnhommer at gmail.com
Sun Jul 7 23:04:06 UTC 2013
The following commit has been merged in the master branch:
commit 34181470e48e01c3b5945d8b257da36e0997d2fe
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Mon Jul 1 01:41:02 2013 +0300
WIP
diff --git a/src/libsigfile/edf.cc b/src/libsigfile/edf.cc
index e237229..5d188a5 100644
--- a/src/libsigfile/edf.cc
+++ b/src/libsigfile/edf.cc
@@ -515,41 +515,11 @@ _parse_header()
}
// deal with episode and session
- {
- // (a) parsed from RecordingID_raw
- char int_session[81], int_episode[81];
- string rec_id_isolated (trim( string (header.recording_id, 80)));
-#define T "%80[-a-zA-Z0-9 _]"
- if ( sscanf( rec_id_isolated.c_str(), T ", " T, int_episode, int_session) == 2 ||
- sscanf( rec_id_isolated.c_str(), T ": " T, int_session, int_episode) == 2 ||
- sscanf( rec_id_isolated.c_str(), T "/" T, int_session, int_episode) == 2 ||
- sscanf( rec_id_isolated.c_str(), T " (" T ")", int_session, int_episode) == 2 )
- ;
- else
- _status |= (nosession | noepisode);
-#undef T
- // (b) identified from file name
- string fn_episode;
- size_t basename_start = _filename.rfind( '/');
- fn_episode =
- _filename.substr(
- basename_start + 1,
- _filename.size() - basename_start - 4 /* strlen(".edf") */ - 1);
- // chip away '-1' if present
- if ( fn_episode.size() >= 3 /* strlen("a-1") */ ) {
- size_t sz = fn_episode.size();
- if ( fn_episode[sz-2] == '-' && isdigit(fn_episode[sz-1]) )
- fn_episode.erase( sz-2, 2);
- }
-
- if ( _status & noepisode ) { // (a) failed
- _episode.assign( fn_episode); // use RecordingID_raw as Session
- _session.assign( rec_id_isolated);
- } else {
- _episode.assign( int_episode);
- _session.assign( int_session);
- }
- }
+ int parsed_status;
+ tie (_session, _episode, parsed_status) =
+ figure_session_and_episode();
+ if ( parsed_status )
+ _status |= (nosession | noepisode);
// parse times
{
diff --git a/src/libsigfile/source-base.cc b/src/libsigfile/source-base.cc
index 01772c9..59dc3aa 100644
--- a/src/libsigfile/source-base.cc
+++ b/src/libsigfile/source-base.cc
@@ -273,6 +273,62 @@ CSource (CSource&& rv)
}
+
+
+
+
+
+
+tuple<string, string, int>
+sigfile::CSource::
+figure_session_and_episode()
+{
+ int status = 0;
+ string session, episode;
+
+ // (a) parsed from RecordingID_raw
+ char int_session[81], int_episode[81];
+ string rec_id_isolated (agh::str::trim( recording_id()));
+#define T "%80[-a-zA-Z0-9 _]"
+ if ( sscanf( rec_id_isolated.c_str(), T "," T, int_episode, int_session) == 2 ||
+ sscanf( rec_id_isolated.c_str(), T ":" T, int_session, int_episode) == 2 ||
+ sscanf( rec_id_isolated.c_str(), T "/" T, int_session, int_episode) == 2 ||
+ sscanf( rec_id_isolated.c_str(), T " (" T ")", int_session, int_episode) == 2 )
+ ;
+ else
+ status = 1;
+#undef T
+
+ // (b) identified from file name
+ ///// if ( sscanf( agh::fs::path_elements( filename).back().c_str(), "%*s-%d.%s", ) == 3 )
+ size_t basename_start = _filename.rfind( '/'),
+ dot = _filename.rfind('.');
+ string fn_episode =
+ _filename.substr(
+ basename_start + 1,
+ dot - basename_start - 1);
+ // chip away '-1' if present
+ if ( fn_episode.size() >= 3 /* strlen("a-1") */ ) {
+ size_t sz = fn_episode.size();
+ if ( fn_episode[sz-2] == '-' && isdigit(fn_episode[sz-1]) )
+ fn_episode.erase( sz-2, 2);
+ }
+
+ if ( status ) { // (a) failed
+ episode.assign( fn_episode); // use RecordingID_raw as Session
+ session.assign( rec_id_isolated);
+ } else {
+ episode.assign( int_episode);
+ session.assign( int_session);
+ }
+
+ return make_tuple( session, episode, status);
+}
+
+
+
+
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: 8
diff --git a/src/libsigfile/source-base.hh b/src/libsigfile/source-base.hh
index 72437b2..8a8acdf 100644
--- a/src/libsigfile/source-base.hh
+++ b/src/libsigfile/source-base.hh
@@ -12,6 +12,8 @@
#ifndef _SIGFILE_SOURCE_BASE_H
#define _SIGFILE_SOURCE_BASE_H
+#include <tuple>
+
#include "common/fs.hh"
#include "common/alg.hh"
#include "common/subject_id.hh"
@@ -407,6 +409,10 @@ class CSource {
{
return sigfile::make_fname_annotations( filename(), channel);
}
+
+ // supporting functions
+ tuple<string, string, int>
+ figure_session_and_episode();
};
diff --git a/src/libsigfile/tsv.cc b/src/libsigfile/tsv.cc
index c770a01..733869d 100644
--- a/src/libsigfile/tsv.cc
+++ b/src/libsigfile/tsv.cc
@@ -164,44 +164,19 @@ CTSVFile::
_parse_header()
{
size_t n_channels;
- _subtype = TSubtype::tsv;
- // deal with episode and session
- {
- // (a) parsed from RecordingID_raw
- char int_session[81], int_episode[81];
- string rec_id_isolated (trim( _recording_id));
-#define T "%80[-a-zA-Z0-9 _]"
- if ( sscanf( rec_id_isolated.c_str(), T ", " T, int_episode, int_session) == 2 ||
- sscanf( rec_id_isolated.c_str(), T ": " T, int_session, int_episode) == 2 ||
- sscanf( rec_id_isolated.c_str(), T "/" T, int_session, int_episode) == 2 ||
- sscanf( rec_id_isolated.c_str(), T " (" T ")", int_session, int_episode) == 2 )
- ;
- else
- _status |= (nosession | noepisode);
-#undef T
- // (b) identified from file name
- string fn_episode;
- size_t basename_start = _filename.rfind( '/');
- fn_episode =
- _filename.substr(
- basename_start + 1,
- _filename.size() - basename_start - 4 /* strlen(".edf") */ - 1);
- // chip away '-1' if present
- if ( fn_episode.size() >= 3 /* strlen("a-1") */ ) {
- size_t sz = fn_episode.size();
- if ( fn_episode[sz-2] == '-' && isdigit(fn_episode[sz-1]) )
- fn_episode.erase( sz-2, 2);
- }
+ // 1. read metadata
+ do {
+
+ } while ();
- if ( _status & noepisode ) { // (a) failed
- _episode.assign( fn_episode); // use RecordingID_raw as Session
- _session.assign( rec_id_isolated);
- } else {
- _episode.assign( int_episode);
- _session.assign( int_session);
- }
- }
+ // 2. pick essential bits
+
+
+ // 3. deal with episode and session
+
+ tie( _session, _episode, parsed_successfully) =
+ figure_session_and_episode( _recording_id, _filename);
// are channels unique?
@@ -214,6 +189,9 @@ _parse_header()
}
outer_break:
+ // 4. read one line of channel data, figure subtype and number of channels
+
+
return 0;
}
--
Sleep experiment manager
More information about the debian-med-commit
mailing list