/* ebscuttr Class definitions for ebstrans Copyright (C) 1993/94 C.Taegert-Kilger, Institut fuer Physiologie und Biokybernetik (IPB), Universitaet Erlangen, Deutschland Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and related publications and that both that copyright notice and this permission notice appear in supporting documentation. The authors make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. Send your comments, suggestions or bug reports to ftpebs@uni-erlangen.de Or mail to Institut fuer Physiologie und Biokybernetik Markus Prosch Universitaetsstrasse 17 D-91054 Erlangen Germany $Id: ebscuttr.h,v 1.1 1994/12/08 11:49:59 hospitan Exp $ */ /* Necessary files: parse1.h parse1.cc trace.h ebsclass.h ebsclass.cc ebshead.h ebshead.c ebs.h ebs.c */ // Commands #define CUTCOMM_E 1 #define CUTCOMM_A 3 #define CUTCOMM_MS 5 #define CUTCOMM_HELP 10 #define CUTCOMM_COPYRIGHT 11 // prevent multiple loading of this module #ifndef __ebscuttr_h #define __ebscuttr_h #include "ebsclass.h" // class library for ebs file handling #include "parse1.h" // Class library for the parsing stuff extern "C"{ #include "ebs.h" // basic ebs stuff #include "ebshead.h" // medium level access fns for ebs files #include #include #ifdef MSDOS #include #include #include #else #define coreleft() printf("No memory function\n") #endif } //#define TRACE #undef TRACE #include "trace.h" #define ALL (uint32) ~0 #define MAX_INFILES 15 #ifdef MSDOS #define MAX_ARRAYLEN 0x8000 #else #define MAX_ARRAYLEN 0x1000000 #endif #define TIME_BUF_LEN 32 #define TEMPNAME "_test.@@@" // Temporary name for writing ebs-files // to disk // Error strings #define ERR_INV_ARG "Invalid argument" #define ERR_INV_INFILE "Invalid input file" #define ERR_COMPRESSED_FORMAT "Input file in compressed format" #define ERR_INV_OUTFILE "Invalid output file" #define ERR_UNKNOWN "An error occured:" #define ERR_WARNING "" #define ERR_INCOMPATIBLE_DATA "Incompatible input data" #define ERR_INSUFFICIENT_MEMORY "Insufficient memory" // Copyright string etc. (is found in the main module) /*extern char copyrightstring[]; extern char helpstring[]; extern char version[]; extern char historystring[]; */ #define historystring \ "Created by EBS cut/append/merge program, V1.0, C.Taegert-Kilger, IPB" #define copyrightstring \ "Transform EBS files: Extract channels, samples; append them; merge them.\n"\ "Copyright (C) 1994 Christoph Taegert-Kilger,\n"\ "Institut fuer Physiologie und Biokybernetik (IPB),\n"\ "Universitaet Erlangen-Nuernberg, Deutschland\n\n"\ "Permission to use, copy, modify, distribute, and sell this software\n"\ "and its documentation for any purpose is hereby granted without fee,\n"\ "provided that the above copyright notice appear in all copies and\n"\ "related publications and that both that copyright notice and this\n"\ "permission notice appear in supporting documentation. The authors make\n"\ "no representations about the suitability of this software for any\n"\ "purpose. It is provided \"as is\" without express or implied warranty.\n\n"\ "Send your comments, suggestions or bug reports to\n"\ " ftpebs@uni-erlangen.de\n\n"\ "Or mail to\n"\ " Institut fuer Physiologie und Biokybernetik\n"\ " Markus Prosch\n"\ " Universitaetsstrasse 17\n"\ " D-91054 Erlangen\n"\ " Germany\n\n" #define version "EBS data extractor & merger, V0.9\n"\ "(C) 1994, Christoph Taegert-Kilger, IPB, Erlangen\n"\ "Type ebstrans -h for help\n\n" #define helpstring \ "Command line syntax:\n\n"\ " ebstrans [ -c | -h |\n"\ " [ -e | -a | -m ]\n"\ " -s [ss | st ][ds |dt
][c1[,cn...]]\n"\ " [ @ ]\n"\ " -t [ f [ CIB_16 | CIL_16 | TIB_16 | TIL_16 ]]\n"\ " -o [ s ] [ r , ]\n"\ " [ m ]\n\n"\ "EXAMPLE: ebstrans -a -s test1.ebs ss10 ds2000 c0,1,2,5 @\n"\ " test2.ebs st 00:00:05.13 dt00:01:10.2\n"\ " -t test.ebs fCIB_16 -o r-1024,1023 m0.5\n"\ "-> ppend in time:\n"\ " - from ource file test1.ebs:\n"\ " tart at sample 10, for a uration of 20000 amples,\n"\ " taking one empty hannel and hannels 1,2 and 5\n"\ " - from source file test2.ebs:\n"\ " tart at ime 5.13 sec from start of file,\n"\ " cover a uration in ime of 1 min 10.2 sec,\n"\ " take all channels\n"\ " to arget test.ebs in ormat CIB_16\n"\ " using an integer ange of -1024...1023 and \n"\ " ultiplying each value by 0.5\n\n"\ " For convenience you may use as well:\n"\ " ebstrans -a -stest1.ebs:ss10ds2000c0,1,2,5@\n"\ " test2.ebs:st00:00:05.13dt00:01:10.2\n"\ " -ttest.ebs:fCIB_16 -o r-1024,1023 m0.5\n\n"\ "Command -m would merge the channels, -e would extract from a single file.\n\n"\ "See ebstrans.doc for more help.\n\n" /* There are some possibilities of what to do with input files: - Append them regardless of time information - Merge them (i.e.: Put them in parallel) - Merge them with time info and translation table */ /* Parsing structure for EBS command lines */ class EBSParser { private: // Internal list parsing class class ParserInputList:public ParserList { protected: EBSParser *parent; public: ParserInputList(EBSParser *parent_); virtual int InputFn(); }; public: // Storage for command int command; // Storage for output parameters struct OutParams { char name[50]; char start[15]; char format[9]; } out_params; // List subtype for storing simple integers class IntList : public List { public: int value; IntList(int arg,List* next_=NULL): List(&value,next_) {value=arg;}; }; // Input file structure int n_infiles; struct InFile { char name[50]; uint32 ss,ds; EBSFile::EBSTm st,dt; int prior; IntList* channels; InFile(); ~InFile(); } infile_array[MAX_INFILES],infile_read,infile_default; // Storage for extra parameters struct SpecialOptions { double mul_val; // Multiply each value with this double sample_rate; // Set sample rate to... int32 int_range_min;// Set integer range to +-... int32 int_range_max; } special_options; public: // Some parser types Parser* ParserTime(EBSFile::EBSTm *tm); Parser* ParserCommand(); Parser* ParserInArgs(EBSParser*); Parser* ParserInParams(); Parser* ParserSingleInParams(); Parser* ParserOutParams(); Parser* ParserSpecialOptions(); public: // Parsing functions int ParseCommand(); // Extract command of command line int ParseParameters(int command_); // Parse suitable parameters // Constructor, destructor EBSParser(int argc, char** argv); ~EBSParser(); char *args, *args_orig, *program_name; }; // Try to evaluate a parsed command line as message command int EvaluateParserAsMessage(EBSParser* ebs_parser); // Forward declaration of EBSTrans class EBSTrans; /* The transfer object is created from opened EBS files, contained transferred in an array of input paramaters. %%%%%%%%%%%%%%%%%%%%%%%%% InputParams ::= %%%%%%%%%%%%%%%%%%%%%%%%% */ class EBSTransInParams : public EBSFile { // Allow translation relative time -> samples // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! friend class EBSTrans; private: int n_outchannels; // Number of output channels int tc; // Output channel displacement struct ChannelTranslator // Channel translator structure { int source; // Source channel double multiplier; // Multiplier } *channel_translator; uint32 ss; // First sample to transfer uint32 ts; // First sample in destination uint32 ds; // Number of samples to transfer uint32 ds_i; // Number of samples to transfer from // data (rest is: Default 0) int Priority; // Channels taken from files with // higher priority overwrite other channels protected: char* filename_; // Storage for filename public: // Default value int GetDefaultValue(); /* Access functions */ int GetNOutChannels(); // Compute number of relevant channels uint32 GetNOutSamples(); // Number of samples to write char *GetFilename(); int GetInChannel(int); // Get Origin for channel i int GetOutChannel(int); // Get target for channel i double GetMultiplier(int); // Get multiplier for output channel i void AddInChannel(int,int, // Add correspondence: double); // Args (in channel, out channel, // multiplier or default val) int GetTransformedValue( // Compute transformed value uint32,uint32); // for output channel i and output sample // j int GetChannelData( // Get data of a single channel uint32 i, uint32 n, uint32* target); int GetDataBlock( // Get data for k output channels: uint32 fch, // Output channel displacement uint32 nch, // Number of channels to write uint32 from, // From output sample no uint32 n, // get n samples int16* target); // and write to array[channels][time] // WARNING: GetSamples does only fill at the tail, not at the // beginning ( vvv000000, not 000vv000 ) /* Constructor */ EBSTransInParams(EBSParser::InFile *in_file); // Modifier void SetDataScheme( uint32 ss_=ALL, uint32 ds_=ALL, uint32 ts_=ALL, uint32 tc_=ALL); void SetMultiplierForChannel(int c_out,double mul); /* Destructor */ ~EBSTransInParams(); // Destruct (close EBS File, free memory, etc.) }; /* Other (general) parameters are collected in a struct of output params: %%%%%%%%%%%%%%%%%%%%%%% Params ::= %%%%%%%%%%%%%%%%%%%%%%% */ class EBSTrans : public EBSFile { // Some comparison operators int IsEqual(struct Filters*,struct Filters*); /* Data part --------- */ public: char* param_string; EBSParser* params_parser; protected: int n_channels; // Number of channels to write int n_infiles; // Number of input files to regard int n_eventlists; // Number of event lists created int32 ebs_format; // EBS format of output file uint32 n_samples; // Number of samples to write EBSTransInParams** in_files; // Array of input parameters /* Methods ------- */ // Constructing & modifying from the outside public: // Constructing from EBSParser object EBSTrans(EBSParser* ebs_parser); // Initializing input objects int CreateInputObjects(); // Compute ranges for channels & samples int ComputeRanges(int command); // Update input objects with command implications int UpdateInputObjects(int command); void ComputeStartingTime(int); // Determine file format, initialize data int InitializeData(); // Transfer data int TransferData(int command); // Create new events for limits of input files int CreateInputFileEventLists(); // Compute new units & range int DeriveUnitsAndRange(); // Compute new filters int DeriveFilters(); // Get & transform event lists of input files void GetInputEventLists(); // Create file events void AppendFileEvents(EBSTransInParams*,char* desc); // Transform header data void ComputeNewPatientsData(); void ComputeNewInstitution(); void ComputeNewDescriptions(); void ComputeNewProcessingHistory(); // Transform location diagram & info void TransferLocationDiagrams(); // Get channel descriptions void TransferChannelDescriptions(int command); // Get channel groups void TransferChannelGroups(); protected: /* The following methods must be called inside constructors */ void InitForNInfiles(int); // Alloc mem for n input files void InitForNChannels(int); // Alloc mem for n channels int GetMaxInChannels(); int GetSumInChannels(); int GetExactInChannels(); int GetExactInSamples(); uint32 GetMaxSamples(); uint32 GetSumSamples(); double GetExactSampleRate(); uint32 WriteDataBlock( uint32 start_,uint32 nsamples_, uint32 ch1_,uint32 nch_, int16* block); protected: // Internal: Calls SetEventList or AppEventList int AppendEventlist(char* name, char* description, uint32 nevents, Event* events); /* @c disposing the rubbish we've done */ private: /* The following methods are called inside the destructor */ void DeleteInFiles(); void DeleteChannels(); public: /* Destructor */ ~EBSTrans(); /* Access fns - Compute special details for the new file */ /* Structures for parameter parsing */ // Array of input files // Structure for output files struct OutFileStruct { char name[50]; } default_outfile,read_outfile; // @3 Structure for file header struct HeaderDataStruct { char name[50]; int sex; } default_header,read_header; } ; #endif