[med-svn] [SCM] aghermann branch, master, updated. 99b1d5a023eee9df74b0e0d6f894516fc79435ad

Andrei Zavada johnhommer at gmail.com
Sun Jul 7 23:04:07 UTC 2013


The following commit has been merged in the master branch:
commit 99b1d5a023eee9df74b0e0d6f894516fc79435ad
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Mon Jul 8 02:03:18 2013 +0300

    WIP (<regex> not worky)

diff --git a/src/aghermann/expdesign/primaries.cc b/src/aghermann/expdesign/primaries.cc
index e5245d4..13692fb 100644
--- a/src/aghermann/expdesign/primaries.cc
+++ b/src/aghermann/expdesign/primaries.cc
@@ -569,7 +569,7 @@ sync()
 			for ( auto &D : J.measurements )
 				for ( auto &E : D.second.episodes )
 					for ( auto &F : E.sources )
-						F().write_ancillary_files();
+						F().save_ancillary_files();
 }
 
 
diff --git a/src/aghermann/expdesign/tree-scanner.cc b/src/aghermann/expdesign/tree-scanner.cc
index 9b98ab5..d581371 100644
--- a/src/aghermann/expdesign/tree-scanner.cc
+++ b/src/aghermann/expdesign/tree-scanner.cc
@@ -15,6 +15,7 @@
 #include <string>
 
 #include "common/alg.hh"
+#include "libsigfile/all.hh"
 #include "primaries.hh"
 
 
@@ -246,11 +247,19 @@ agh::CExpDesign::
 is_supported_source( sigfile::CTypedSource& F)
 {
 	using namespace sigfile;
-	CEDFFile::TSubtype subtype;
-	return F.type() == CTypedSource::TType::edf and
-		(subtype = static_cast<CEDFFile*>(&F()) -> subtype(),
-		 (subtype == CEDFFile::TSubtype::edf ||
-		  subtype == CEDFFile::TSubtype::edfplus_c));
+	union {
+		CEDFFile::TSubtype e;
+		CTSVFile::TSubtype t;
+	} u;
+	return (F.type() == CTypedSource::TType::edf and
+		(u.e = static_cast<CEDFFile*>(&F()) -> subtype(),
+		 (u.e == CEDFFile::TSubtype::edf ||
+		  u.e == CEDFFile::TSubtype::edfplus_c)))
+		or
+		(F.type() == CTypedSource::TType::ascii and
+		 (u.t = static_cast<CTSVFile*>(&F()) -> subtype(),
+		  (u.t == CTSVFile::TSubtype::csv ||
+		   u.t == CTSVFile::TSubtype::tsv)));
 }
 
 namespace {
diff --git a/src/aghermann/model/ultradian-cycle.cc b/src/aghermann/model/ultradian-cycle.cc
index 6f67194..106387b 100644
--- a/src/aghermann/model/ultradian-cycle.cc
+++ b/src/aghermann/model/ultradian-cycle.cc
@@ -15,6 +15,7 @@
 
 #include "aghermann/globals.hh"
 #include "aghermann/expdesign/recording.hh"
+#include "libsigproc/sigproc.hh"
 #include "beersma.hh"
 
 using namespace std;
diff --git a/src/aghermann/ui/mw/measurements_cb.cc b/src/aghermann/ui/mw/measurements_cb.cc
index eeb3f8b..c2b2de1 100644
--- a/src/aghermann/ui/mw/measurements_cb.cc
+++ b/src/aghermann/ui/mw/measurements_cb.cc
@@ -9,6 +9,7 @@
  *         License:  GPL
  */
 
+#include "libsigfile/source-base.hh"
 #include "aghermann/ui/misc.hh"
 #include "aghermann/ui/sf/sf.hh"
 #include "mw.hh"
@@ -197,7 +198,7 @@ iSubjectTimelineEDFInfo_activate_cb(
 	const auto& F = J->using_episode->sources.front();
 	gtk_text_buffer_set_text(
 		ED.tEDFFileDetailsReport,
-		F().details( 0|sigfile::CEDFFile::with_channels).c_str(), -1);
+		F().details( 0|sigfile::CSource::TDetails::with_channels).c_str(), -1);
 	gtk_window_set_title(
 		(GtkWindow*)ED.wEDFFileDetails,
 		snprintf_buf( "%s header", F().filename()));
diff --git a/src/libmetrics/psd.cc b/src/libmetrics/psd.cc
index b23cd55..9a1399a 100644
--- a/src/libmetrics/psd.cc
+++ b/src/libmetrics/psd.cc
@@ -13,6 +13,7 @@
  */
 
 
+#include <map>
 #include <cassert>
 #include <unistd.h>
 
diff --git a/src/libsigfile/Makefile.am b/src/libsigfile/Makefile.am
index 9fad844..b861ba6 100644
--- a/src/libsigfile/Makefile.am
+++ b/src/libsigfile/Makefile.am
@@ -19,7 +19,8 @@ libsigfile_la_SOURCES := \
 	tsv.cc \
 	tsv.hh \
 	page.cc \
-	page.hh
+	page.hh \
+	all.hh
 
 libsigfile_la_LDFLAGS := \
 	-avoid-version \
diff --git a/src/libmetrics/all.hh b/src/libsigfile/all.hh
similarity index 56%
copy from src/libmetrics/all.hh
copy to src/libsigfile/all.hh
index 2645064..d24074c 100644
--- a/src/libmetrics/all.hh
+++ b/src/libsigfile/all.hh
@@ -1,21 +1,20 @@
 /*
- *       File name:  libmetrics/all.hh
+ *       File name:  libsigfile/all.hh
  *         Project:  Aghermann
  *          Author:  Andrei Zavada <johnhommer at gmail.com>
  *
- * Initial version:  2013-05-23
+ * Initial version:  2013-07-07
  *
  *         Purpose:  
  *
  *         License:  GPL
  */
 
-#ifndef AGH_LIBMETRICS_ALL_H_
-#define AGH_LIBMETRICS_ALL_H_
+#ifndef AGH_LIBSIGFILE_ALL_H_
+#define AGH_LIBSIGFILE_ALL_H_
 
-#include "psd.hh"
-#include "mc.hh"
-#include "swu.hh"
+#include "edf.hh"
+#include "tsv.hh"
 
 #endif
 
diff --git a/src/libsigfile/edf-io.cc b/src/libsigfile/edf-io.cc
index ee4fce5..d88f239 100644
--- a/src/libsigfile/edf-io.cc
+++ b/src/libsigfile/edf-io.cc
@@ -63,99 +63,6 @@ get_region_original_smpl( const int h,
 
 
 
-valarray<TFloat>
-CEDFFile::
-get_region_filtered_smpl( const int h,
-			  const size_t smpla, const size_t smplz) const
-{
-	valarray<TFloat> recp =
-		get_region_original_smpl( h, smpla, smplz);
-	if ( recp.size() == 0 )
-		return valarray<TFloat> (0);
-	// and zeromean
-       	recp -= (recp.sum() / recp.size());
-
-	const SSignal& H = operator[](h);
-
-      // artifacts
-	size_t this_samplerate = H.samples_per_record / data_record_size;
-	for ( auto &A : H.artifacts() ) {
-		size_t	Aa = A.a * this_samplerate,
-			Az = A.z * this_samplerate;
-		if ( unlikely (Aa >= smplz) )
-			break;
-		size_t	run = (Az - Aa),
-			window = min( run, this_samplerate),
-			t;
-		if ( unlikely (Az > smplz) )
-			run = smplz - Aa;
-		valarray<TFloat>
-			W (run);
-
-		if ( run > window ) {
-			// construct a vector of multipliers using an INVERTED windowing function on the
-			// first and last windows of the run
-			size_t	t0;
-			for ( t = 0; t < window/2; ++t )
-				W[t] = (1 - sigproc::winf[(size_t)H.artifacts.dampen_window_type]( t, window));
-			t0 = run-window;  // start of the last window but one
-			for ( t = window/2; t < window; ++t )
-				W[t0 + t] = (1 - sigproc::winf[(size_t)H.artifacts.dampen_window_type]( t, window));
-			// AND, connect mid-first to mid-last windows (at lowest value of the window)
-			TFloat minimum = sigproc::winf[(size_t)H.artifacts.dampen_window_type]( window/2, window);
-			W[ slice(window/2, run-window, 1) ] =
-				(1. - minimum);
-		} else  // run is shorter than samplerate (1 sec)
-			for ( t = 0; t < window; ++t )
-				W[t] = (1 - sigproc::winf[(size_t)H.artifacts.dampen_window_type]( t, window));
-
-		// now gently apply the multiplier vector onto the artifacts
-		recp[ slice(Aa, run, 1) ] *= (W * (TFloat)H.artifacts.factor);
-	}
-
-      // filters
-	if ( H.filters.low_pass_cutoff > 0. && H.filters.high_pass_cutoff > 0. &&
-	     H.filters.low_pass_order > 0 && H.filters.high_pass_order > 0 ) {
-		auto tmp (exstrom::band_pass(
-				  recp, this_samplerate,
-				  H.filters.high_pass_cutoff, H.filters.low_pass_cutoff,
-				  H.filters.low_pass_order, true));
-		recp = tmp;
-	} else {
-		if ( H.filters.low_pass_cutoff > 0. && H.filters.low_pass_order > 0 ) {
-			auto tmp (exstrom::low_pass(
-					  recp, this_samplerate,
-					  H.filters.low_pass_cutoff, H.filters.low_pass_order, true));
-			recp = tmp;
-		}
-		if ( H.filters.high_pass_cutoff > 0. && H.filters.high_pass_order > 0 ) {
-			auto tmp (exstrom::high_pass(
-					  recp, this_samplerate,
-					  H.filters.high_pass_cutoff, H.filters.high_pass_order, true));
-			recp = tmp;
-		}
-	}
-
-	switch ( H.filters.notch_filter ) {
-	case SFilterPack::TNotchFilter::at50Hz:
-		recp = exstrom::band_stop( recp, this_samplerate,
-					   48, 52, 1, true);
-	    break;
-	case SFilterPack::TNotchFilter::at60Hz:
-		recp = exstrom::band_stop( recp, this_samplerate,
-					   58, 62, 1, true);
-	    break;
-	case SFilterPack::TNotchFilter::none:
-	default:
-	    break;
-	}
-
-	// filters happen to append samples, so
-	return move(recp[ slice (0, smplz-smpla, 1)]);
-}
-
-
-
 
 
 int
diff --git a/src/libsigfile/edf.cc b/src/libsigfile/edf.cc
index 5d188a5..281cb3e 100644
--- a/src/libsigfile/edf.cc
+++ b/src/libsigfile/edf.cc
@@ -176,10 +176,7 @@ CEDFFile (const string& fname_, const int flags_)
 
 	_extract_embedded_annotations();
 
-      // ancillary files:
-	if ( flags_ & sigfile::CSource::no_ancillary_files )
-		;
-	else
+	if ( not (flags_ & CSource::no_ancillary_files) )
 		load_ancillary_files();
 }
 
diff --git a/src/libsigfile/edf.hh b/src/libsigfile/edf.hh
index b376675..589bd72 100644
--- a/src/libsigfile/edf.hh
+++ b/src/libsigfile/edf.hh
@@ -22,7 +22,6 @@
 #include <map>
 #include <stdexcept>
 
-#include "libsigproc/sigproc.hh"
 #include "channel.hh"
 #include "source-base.hh"
 
@@ -199,9 +198,6 @@ class CEDFFile
 				h, 0, n_data_records * operator[](h).samples_per_record); }
 
 	valarray<TFloat>
-	get_region_filtered_smpl( int, size_t, size_t) const;
-
-	valarray<TFloat>
 	get_signal_filtered( const int h) const
 		{ return get_region_filtered_smpl(
 				h, 0, n_data_records * operator[](h).samples_per_record); }
@@ -258,9 +254,6 @@ class CEDFFile
 
 
       // reporting & misc
-	void write_ancillary_files();
-
-	enum TEdfDetails { with_channels = 1, with_annotations = 2 };
 	string details( int which) const;
 
 	sigproc::TWinType af_dampen_window_type; // master copy
diff --git a/src/libsigfile/source-base.cc b/src/libsigfile/source-base.cc
index 59dc3aa..b826290 100644
--- a/src/libsigfile/source-base.cc
+++ b/src/libsigfile/source-base.cc
@@ -12,12 +12,14 @@
 
 #include <fstream>
 #include "common/string.hh"
+#include "libsigproc/sigproc.hh"
 #include "source-base.hh"
 
 using namespace std;
+using namespace sigfile;
 
 void
-sigfile::SArtifacts::
+SArtifacts::
 mark_artifact( const double aa, const double az)
 {
 	if ( aa >= az )
@@ -38,7 +40,7 @@ mark_artifact( const double aa, const double az)
 
 
 void
-sigfile::SArtifacts::
+SArtifacts::
 clear_artifact( const double aa, const double az)
 {
 	auto A = obj.begin();
@@ -66,7 +68,7 @@ clear_artifact( const double aa, const double az)
 
 float
 __attribute__ ((pure))
-sigfile::SArtifacts::
+SArtifacts::
 region_dirty_fraction( const double ra, const double rz) const
 {
 	size_t	dirty = 0;
@@ -95,7 +97,7 @@ region_dirty_fraction( const double ra, const double rz) const
 
 
 unsigned long
-sigfile::SArtifacts::
+SArtifacts::
 dirty_signature() const
 {
 	string sig ("a");
@@ -107,10 +109,9 @@ dirty_signature() const
 
 
 unsigned long
-sigfile::SFilterPack::
+SFilterPack::
 dirty_signature() const
 {
-//	DEF_UNIQUE_CHARP (tmp);
 	char *tmp;
 	ASPRINTF( &tmp, "%g%d%g%d%d",
 		  low_pass_cutoff, low_pass_order, high_pass_cutoff, high_pass_order, (int)notch_filter);
@@ -124,7 +125,7 @@ dirty_signature() const
 
 
 int
-sigfile::CSource::
+CSource::
 load_ancillary_files()
 {
 	int retval = 0;
@@ -207,7 +208,7 @@ load_ancillary_files()
 
 
 int
-sigfile::CSource::
+CSource::
 save_ancillary_files()
 {
 	int retval = 0;
@@ -280,7 +281,7 @@ CSource (CSource&& rv)
 
 
 tuple<string, string, int>
-sigfile::CSource::
+CSource::
 figure_session_and_episode()
 {
 	int status = 0;
@@ -329,6 +330,105 @@ figure_session_and_episode()
 
 
 
+
+
+
+
+valarray<TFloat>
+CSource::
+get_region_filtered_smpl( const int h,
+			  const size_t smpla, const size_t smplz) const
+{
+	valarray<TFloat> recp =
+		get_region_original_smpl( h, smpla, smplz);
+	if ( recp.size() == 0 )
+		return valarray<TFloat> (0);
+	// and zeromean
+       	recp -= (recp.sum() / recp.size());
+
+	size_t this_samplerate = samplerate(h);
+
+      // artifacts
+	const auto& AA = artifacts(h);
+	for ( const auto& A : AA() ) {
+		size_t	Aa = A.a * this_samplerate,
+			Az = A.z * this_samplerate;
+		if ( unlikely (Aa >= smplz) )
+			break;
+		size_t	run = (Az - Aa),
+			window = min( run, this_samplerate),
+			t;
+		if ( unlikely (Az > smplz) )
+			run = smplz - Aa;
+		valarray<TFloat>
+			W (run);
+
+		if ( run > window ) {
+			// construct a vector of multipliers using an INVERTED windowing function on the
+			// first and last windows of the run
+			size_t	t0;
+			for ( t = 0; t < window/2; ++t )
+				W[t] = (1 - sigproc::winf[(size_t)AA.dampen_window_type]( t, window));
+			t0 = run-window;  // start of the last window but one
+			for ( t = window/2; t < window; ++t )
+				W[t0 + t] = (1 - sigproc::winf[(size_t)AA.dampen_window_type]( t, window));
+			// AND, connect mid-first to mid-last windows (at lowest value of the window)
+			TFloat minimum = sigproc::winf[(size_t)AA.dampen_window_type]( window/2, window);
+			W[ slice(window/2, run-window, 1) ] =
+				(1. - minimum);
+		} else  // run is shorter than samplerate (1 sec)
+			for ( t = 0; t < window; ++t )
+				W[t] = (1 - sigproc::winf[(size_t)AA.dampen_window_type]( t, window));
+
+		// now gently apply the multiplier vector onto the artifacts
+		recp[ slice(Aa, run, 1) ] *= (W * (TFloat)AA.factor);
+	}
+
+      // filters
+	const auto& ff = filters(h);
+	if ( ff.low_pass_cutoff > 0. && ff.high_pass_cutoff > 0. &&
+	     ff.low_pass_order  > 0  && ff.high_pass_order  > 0 ) {
+		auto tmp (exstrom::band_pass(
+				  recp, this_samplerate,
+				  ff.high_pass_cutoff, ff.low_pass_cutoff,
+				  ff.low_pass_order, true));
+		recp = tmp;
+	} else {
+		if ( ff.low_pass_cutoff > 0. && ff.low_pass_order > 0 ) {
+			auto tmp (exstrom::low_pass(
+					  recp, this_samplerate,
+					  ff.low_pass_cutoff, ff.low_pass_order, true));
+			recp = tmp;
+		}
+		if ( ff.high_pass_cutoff > 0. && ff.high_pass_order > 0 ) {
+			auto tmp (exstrom::high_pass(
+					  recp, this_samplerate,
+					  ff.high_pass_cutoff, ff.high_pass_order, true));
+			recp = tmp;
+		}
+	}
+
+	switch ( ff.notch_filter ) {
+	case SFilterPack::TNotchFilter::at50Hz:
+		recp = exstrom::band_stop( recp, this_samplerate,
+					   48, 52, 1, true);  // hardcoded numerals spotted!
+	    break;
+	case SFilterPack::TNotchFilter::at60Hz:
+		recp = exstrom::band_stop( recp, this_samplerate,
+					   58, 62, 1, true);
+	    break;
+	case SFilterPack::TNotchFilter::none:
+	default:
+	    break;
+	}
+
+	// filters happen to append samples, so
+	return move(recp[ slice (0, smplz-smpla, 1)]);
+}
+
+
+
+
 // Local Variables:
 // Mode: c++
 // indent-tabs-mode: 8
diff --git a/src/libsigfile/source-base.hh b/src/libsigfile/source-base.hh
index 8a8acdf..1141059 100644
--- a/src/libsigfile/source-base.hh
+++ b/src/libsigfile/source-base.hh
@@ -238,7 +238,11 @@ class CSource {
 	      : _filename (fname_),
 		_status (0),
 		_flags (flags_)
-		{}
+		{
+			// if ( not (_flags & no_ancillary_files) )
+			// 	load_ancillary_files();
+			/// defer until, at least, n_channels is known
+		}
 	CSource( CSource&&);
 	virtual ~CSource()
 		{
@@ -250,6 +254,7 @@ class CSource {
 	int flags()	const { return _flags; }
 
 	virtual string explain_status()			const = 0;
+	enum TDetails { with_channels = 1, with_annotations = 2 };
 	virtual string details( int which_details)	const = 0;
 
       // identification
@@ -355,7 +360,7 @@ class CSource {
 
 	// filtered
 	virtual valarray<TFloat>
-	get_region_filtered_smpl( int, size_t, size_t) const = 0;
+	get_region_filtered_smpl( int, size_t, size_t) const;
 
 	valarray<TFloat>
 	get_region_filtered_sec( const int h,
diff --git a/src/libsigfile/tsv.cc b/src/libsigfile/tsv.cc
index 733869d..0f125e4 100644
--- a/src/libsigfile/tsv.cc
+++ b/src/libsigfile/tsv.cc
@@ -13,7 +13,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <fstream>
+#include <regex.h>
 #include <sstream>
 #include <list>
 #include <stdexcept>
@@ -59,15 +59,13 @@ CTSVFile (const string& fname_, const int flags_)
 		if ( stst == -1 )
 			throw invalid_argument (explain_status(_status |= TStatus::sysfail));
 	}
-	_fd = open( fname_.c_str(), O_RDWR);
-	if ( _fd == -1 )
+	_f = fopen( fname_.c_str(), "r");
+	if ( !_f )
 		throw invalid_argument (explain_status(_status |= TStatus::sysfail));
 
       // parse header
 	if ( _parse_header() ) {  // creates channels list
 		if ( not (flags_ & sigfile::CSource::no_field_consistency_check) ) {
-			close( _fd);
-			_fd = -1;
 			throw invalid_argument (explain_status(_status)); // _status set in _parse_header()
 		} else
 			fprintf( stderr, "CTSVFile::CTSVFile(\"%s\") Warning: parse header failed, but proceeding anyway\n", fname_.c_str());
@@ -76,8 +74,7 @@ CTSVFile (const string& fname_, const int flags_)
 
 	_read_data();
 
-      // ancillary files:
-	if ( not (flags_ & sigfile::CSource::no_ancillary_files) )
+	if ( not (flags_ & CSource::no_ancillary_files) )
 		load_ancillary_files();
 }
 
@@ -93,8 +90,8 @@ CTSVFile (const string& fname_, const TSubtype subtype_, const int flags_,
 	_subtype (subtype_),
 	_samplerate (samplerate_)
 {
-	_fd = open( fname_.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP);
-	if ( _fd == -1 ) {
+	_f = fopen( fname_.c_str(), "r");
+	if ( !_f ) {
 		fprintf( stderr, "CTSVFile::CTSVFile(\"%s\"): Failed to open file for writing\n", fname_.c_str());
 		throw invalid_argument (explain_status(_status |= TStatus::sysfail));
 	}
@@ -139,20 +136,16 @@ CTSVFile (CTSVFile&& rv)
 	swap( channels, rv.channels);
 	swap( common_annotations, rv.common_annotations);
 
-	_fd = rv._fd;
-	rv._fd = -1;
+	_f = rv._f;
+	rv._f = nullptr;
 }
 
 
 CTSVFile::
 ~CTSVFile ()
 {
-	if ( _fd != -1 ) {
-		close( _fd);
-
-		if ( not (flags() & sigfile::CSource::no_ancillary_files) )
-			write_ancillary_files();
-	}
+	if ( not (flags() & sigfile::CSource::no_ancillary_files) )
+		save_ancillary_files();
 }
 
 
@@ -166,18 +159,33 @@ _parse_header()
 	size_t	n_channels;
 
       // 1. read metadata
-	do {
-		
-	} while ();
+
+	regex_t RE;
+	assert (0 == regcomp( &RE, "^#\\W*(\\w+)\\W*(:|=)\\", REG_EXTENDED));
+	regmatch_t M[1+2];
+
+	size_t n = 4096;
+	char *line = (char*)malloc( n);
+	while ( getline( &line, &n, _f) > 0 ) {
+		if ( regexec( &RE, line, 1+2, M, 0) == 0 ) {
+			metadata[string (line, M[1].rm_so, M[1].rm_eo)] =
+				string (line, M[2].rm_so, M[2].rm_eo);
+			printf( "matched metadata [%s] = %s\n", string (line, M[1].rm_so, M[1].rm_eo).c_str(), string (line, M[2].rm_so, M[2].rm_eo).c_str());
+		} else
+			if ( line[0] != '#' )
+				break; // end of header
+	}
+	free( (void*)line);
 
       // 2. pick essential bits
 	
 
       // 3. deal with episode and session
-	
-	tie( _session, _episode, parsed_successfully) =
-		figure_session_and_episode( _recording_id, _filename);
-
+	int parsed_with_issues;
+	tie( _session, _episode, parsed_with_issues) =
+		figure_session_and_episode();
+	if ( parsed_with_issues )
+		_status |= (nosession | noepisode);
 
 	// are channels unique?
 	for ( auto &H : channels )
@@ -209,6 +217,13 @@ _read_data()
 
 
 
+int
+CTSVFile::
+put_region_smpl( int, const valarray<TFloat>&, size_t) const
+{
+	
+	return 0;
+}
 
 
 string
@@ -219,81 +234,33 @@ details( const int which) const
 	if ( _status & bad_header )
 		recv << "Bad header, or no file\n";
 	else {
-		size_t	n_dicontinuities = 0;
-		double	prev_offset = NAN, cur_offset;
-		for ( size_t r = 1; r < _record_offsets.size(); ++r ) {
-			cur_offset = _record_offsets[r] - _record_offsets[r-1];
-			if ( isfinite(prev_offset) and cur_offset != prev_offset )
-				++n_dicontinuities;
-			prev_offset = cur_offset;
-		}
-		char *outp;
-		ASPRINTF( &outp,
-			  "File\t: %s\n"
-			  " subtype\t: %s\n"
-			  " PatientID\t: %s\n"
-			  " RecordingID\t: %s\n"
-			  " Date\t: %s\n"
-			  " Time\t: %s\n"
-			  " # of channels\t: %zu\n"
-			  " # of records\t: %zu\n"
-			  " Record size\t: %g sec\n"
-			  " # of discontinuities\t: %zu\n"
-			  " # of embedded annotations\t: %zu\n",
-			  filename(),
-			  subtype_s(),
-			  patient_id(),
-			  recording_id.c_str(),
-			  recording_date, 8)).c_str(),
-			  trim( string (header.recording_time, 8)).c_str(),
-			  channels.size(),
-			  n_data_records,
-			  data_record_size,
-			  n_dicontinuities,
-			  common_annotations.size());
-		recv << outp;
-		free( outp);
+		char b[20];
+		recv << agh::str::sasprintf(
+			"File\t: %s\n"
+			" subtype\t: %s\n"
+			" PatientID\t: %s\n"
+			" RecordingID\t: %s\n"
+			" Start time\t: %s\n"
+			" Duration\t: %s\n"
+			" # of channels\t: %zu\n"
+			" Sample rate\t: %zu\n",
+			filename(),
+			subtype_s(),
+			patient_id(),
+			recording_id(),
+			(strftime( b, 20, "%F %T", localtime(&_start_time)), b),
+			agh::str::dhms( recording_time()).c_str(),
+			channels.size(),
+			_samplerate);
 
 		if ( which & with_channels ) {
 			size_t i = 0;
-			for ( auto &H : channels ) {
-				ASPRINTF( &outp,
-					  " Channel %zu:\n"
-					  "  Label\t: %s\n"
-					  "  Transducer type\t: %s\n"
-					  "  Physical dimension\t: %s\n"
-					  "  Physical min\t: % g\n"
-					  "  Physical max\t: % g\n"
-					  "  Digital min\t: % d\n"
-					  "  Digital max\t: % d\n"
-					  "  Filtering info\t: %s\n"
-					  "  Samples/rec\t: %zu\n"
-					  "  Scale\t: %g\n"
-					  "  (reserved)\t: %s\n",
-					  ++i,
-					  trim( string (H.header.label, 16)).c_str(),
-					  H.transducer_type.c_str(),
-					  H.physical_dim.c_str(),
-					  H.physical_min,
-					  H.physical_max,
-					  H.digital_min,
-					  H.digital_max,
-					  H.filtering_info.c_str(),
-					  H.samples_per_record,
-					  H.scale,
-					  H.reserved.c_str());
-				recv << outp;
-				free( outp);
-			}
-		}
-
-		if ( which & with_annotations ) {
-			recv << "Embedded annotations (" << common_annotations.size() << "):\n";
-			for ( auto &A : common_annotations )
-				recv << ' '
-				     << A.span.a << '\t'
-				     << A.span.z << '\t'
-				     << A.label << endl;
+			for ( auto &H : channels )
+				recv << agh::str::sasprintf(
+					" Channel %zu:\n"
+					"  Label\t: %s\n",
+					++i,
+					H.ucd.name());
 		}
 	}
 
@@ -308,15 +275,13 @@ details( const int which) const
 
 string
 CTSVFile::
-explain_edf_status( const int status)
+explain_status( const int status)
 {
 	list<string> recv;
 	if ( status & sysfail )
 		recv.emplace_back( "* stat or fopen error");
 	if ( status & bad_header )
 		recv.emplace_back( "* Ill-formed header");
-	if ( status & bad_version )
-		recv.emplace_back( "* Bad Version signature (i.e., not an EDF file)");
 	if ( status & missing_patient_id )
 		recv.emplace_back( "* Missing PatientId");
 	if ( status & bad_numfld )
@@ -337,18 +302,10 @@ explain_edf_status( const int status)
 		recv.emplace_back( "* Signal type not listed in Kemp et al");
 	if ( status & dup_channels )
 		recv.emplace_back( "* Duplicate channel names");
-	if ( status & nogain )
-		recv.emplace_back( "* Physical or Digital Min value greater than Max");
 	if ( status & too_many_channels )
 		recv.emplace_back( string("* Number of channels grearter than ") + to_string(max_channels));
-	if ( status & file_truncated )
-		recv.emplace_back( "* File truncated");
-	if ( status & trailing_junk )
-		recv.emplace_back( "* File has trailing junk");
 	if ( status & extra_patientid_subfields )
 		recv.emplace_back( "* Extra subfields in PatientId");
-	if ( status & recognised_channel_conflicting_type )
-		recv.emplace_back( "* Explicitly specified signal type does not match type of known channel name");
 	return join(recv, "\n");
 }
 
diff --git a/src/libsigfile/tsv.hh b/src/libsigfile/tsv.hh
index 3812e3d..991f2c7 100644
--- a/src/libsigfile/tsv.hh
+++ b/src/libsigfile/tsv.hh
@@ -21,6 +21,7 @@
 #include <list>
 #include <map>
 #include <stdexcept>
+#include <fstream>
 
 #include "libsigproc/sigproc.hh"
 #include "channel.hh"
@@ -204,16 +205,14 @@ class CTSVFile
 
       // signal data extractors
 	valarray<TFloat>
-	get_region_original_smpl( int, size_t, size_t) const;
+	get_region_original_smpl( const int h, const size_t sa, const size_t sz) const
+		{ return operator[](h).data[ slice (sa, sz-sa, 1) ];}
 
 	valarray<TFloat>
 	get_signal_original( const int h) const // there is a CSource::get_signal_original already, but this one is a little better
 		{ return get_region_original_smpl( h, 0, channels.front().data.size()); }
 
 	valarray<TFloat>
-	get_region_filtered_smpl( int, size_t, size_t) const;
-
-	valarray<TFloat>
 	get_signal_filtered( const int h) const
 		{ return get_region_filtered_smpl( h, 0, channels.front().data.size()); }
 
@@ -260,10 +259,7 @@ class CTSVFile
 
 
       // reporting & misc
-	void write_ancillary_files();
-
-	enum TTsvDetails { with_channels = 1, with_annotations = 2 };
-	string details( int which) const;
+	string details( int which_details) const;
 
 	sigproc::TWinType af_dampen_window_type; // master copy
 
@@ -376,7 +372,7 @@ class CTSVFile
 	time_t	_start_time,
 		_end_time;
 
-	int	_fd;
+	FILE	*_f;
 
 	int _parse_header();
 	int _read_data();

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list