[med-svn] [SCM] aghermann branch, master, updated. 551e213a23b59b71cba6a9c3a282d1b60e21b854

Andrei Zavada johnhommer at gmail.com
Sun Apr 21 23:17:55 UTC 2013


The following commit has been merged in the master branch:
commit 2740814d17937df8aaebb488214b39fd1ccc3f61
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Tue Apr 9 02:22:14 2013 +0300

    introducing edf subtype

diff --git a/src/libsigfile/edf.cc b/src/libsigfile/edf.cc
index 14c660f..36389cb 100644
--- a/src/libsigfile/edf.cc
+++ b/src/libsigfile/edf.cc
@@ -75,6 +75,7 @@ int
 sigfile::CEDFFile::
 set_comment( const char *s)
 {
+	fprintf( stderr, "Writing to reserved EDF field: don't do that!\n");
 	memcpy( header.reserved, agh::str::pad( s, 44).c_str(), 44);
 	return strlen(s) > 44;
 }
@@ -219,13 +220,14 @@ CEDFFile (const char *fname_, int flags_)
 
 
 sigfile::CEDFFile::
-CEDFFile (const char *fname_, int flags_,
+CEDFFile (const char *fname_, TSubtype subtype_, int flags_,
 	  const list<pair<string, size_t>>& channels_,
 	  size_t data_record_size_,
 	  size_t n_data_records_)
       : CSource (fname_, flags_),
 	data_record_size (data_record_size_),
-	n_data_records (n_data_records_)
+	n_data_records (n_data_records_),
+	_subtype (subtype_)
 {
 	_fd = open( fname_, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP);
 	if ( _fd == -1 ) {
@@ -358,6 +360,7 @@ CEDFFile (CEDFFile&& rv)
 	n_data_records   = rv.n_data_records;
 	data_record_size = rv.data_record_size;
 
+	_subtype    = rv._subtype;
 	_start_time = rv._start_time;
 	_end_time   = rv._end_time;
 
@@ -508,6 +511,13 @@ _parse_header()
 		_get_next_field( header.data_record_size, 8);
 		_get_next_field( header.n_channels,       4);
 
+		_subtype =
+			(strncasecmp( header.reserved, "edf+c", 5) == 0)
+			? edfplus_c
+			: (strncasecmp( header.reserved, "edf+d", 5) == 0)
+			? edfplus_d
+			: edf;
+
 		if ( strncmp( header.version_number, version_string, 8) ) {
 			_status |= (bad_version | inoperable);
 			return -2;
@@ -759,6 +769,7 @@ sigfile::CEDFFile::details( bool channels_too) const
 		char *outp;
 		if ( asprintf( &outp,
 			       "File\t: %s\n"
+			       " subtype\t: %s\n"
 			       " PatientID\t: %s\n"
 			       " RecordingID\t: %s\n"
 			       " Date\t: %s\n"
@@ -767,6 +778,7 @@ sigfile::CEDFFile::details( bool channels_too) const
 			       " # of records\t: %zu\n"
 			       " Record length\t: %zu sec\n",
 			       filename(),
+			       subtype_s(),
 			       subject(),
 			       agh::str::trim( string (header.recording_id, 80)).c_str(),
 			       agh::str::trim( string (header.recording_date, 8)).c_str(),
diff --git a/src/libsigfile/edf.hh b/src/libsigfile/edf.hh
index fe61706..e70c1d2 100644
--- a/src/libsigfile/edf.hh
+++ b/src/libsigfile/edf.hh
@@ -4,7 +4,7 @@
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  * Initial version:  2008-07-01
  *
- *         Purpose:  EDF class
+ *         Purpose:  EDF class, also accommodating EDF+
  *
  *         License:  GPL
  */
@@ -46,13 +46,35 @@ class CEDFFile
 	CEDFFile() = delete;
 
     public:
+	// subtype
+	enum TSubtype {
+		edf,
+		edfplus_c,  // continuous
+		edfplus_d   // discontinuous
+	};
+	TSubtype subtype() const
+		{ return _subtype; }
+	static const char*
+	subtype_s( TSubtype t)
+		{
+			switch (t) {
+			case edf:       return "edf";
+			case edfplus_c: return "edf+c";
+			case edfplus_d: return "edf+d";
+			default:        return "(invalid)";
+			}
+		}
+	const char*
+	subtype_s() const
+		{ return subtype_s( _subtype); }
+
       // ctor
 	CEDFFile( const CEDFFile&)
 	      : CSource("")
 		{
 			throw invalid_argument("nono");
 		}
-	enum {
+	enum TFlags {
 		no_mmap				= 1<<3,
 		no_cache			= 1<<4, // just considering
 		no_field_consistency_check	= 1<<5,
@@ -60,7 +82,7 @@ class CEDFFile
 	// open existing
 	CEDFFile (const char *fname, int flags = 0);
 	// create new
-	CEDFFile (const char *fname, int flags,
+	CEDFFile (const char *fname, TSubtype subtype_, int flags,
 		  const list<pair<string, size_t>>& channels,
 		  size_t data_record_size = 1,
 		  size_t n_data_records = 0);
@@ -490,6 +512,8 @@ class CEDFFile
 	static string explain_edf_status( int);
 
     private:
+	TSubtype _subtype;
+
 	time_t	_start_time,
 		_end_time;
 
diff --git a/src/tools/edfcat.cc b/src/tools/edfcat.cc
index c22981f..62b814e 100644
--- a/src/tools/edfcat.cc
+++ b/src/tools/edfcat.cc
@@ -341,6 +341,7 @@ exec_convert( const SOperation::SObject& obj)
 		grand_min, grand_max);
 
 	sigfile::CEDFFile F ((obj + ".edf").c_str(),
+			     sigfile::CEDFFile::TSubtype::edf,
 			     sigfile::CTypedSource::no_ancillary_files,
 			     make_channel_headers_for_CEDFFile( Hh.size(), "channel%zu", obj.samplerate),
 			     obj.record_size,
@@ -383,6 +384,7 @@ exec_prune( const SOperation::SObject& obj)
 	printf( "Keeping %zu channel(s)\n", selected_channels.size());
 
 	sigfile::CEDFFile G ((agh::fs::make_fname_base( obj, ".edf", false) + "-mod.edf").c_str(),
+			     sigfile::CEDFFile::TSubtype::edf,
 			     sigfile::CTypedSource::no_ancillary_files,
 			     selected_channels,
 			     F.data_record_size,

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list