Beispiel #1
0
 public bool compatible(BDFHeader header)
 {
     if (!(LocalSubject.Equals(header.LocalSubject)))
     {
         return(false);
     }
     if (!(LocalRecording.Equals(header.LocalRecording)))
     {
         return(false);
     }
     if (!(DataFormat.Equals(header.DataFormat)))
     {
         return(false);
     }
     if (ChannelCount != header.ChannelCount)
     {
         return(false);
     }
     for (int i = 0; i < ChannelCount; i++)
     {
         if (!(ChannelHeaders[i].Equals(header.ChannelHeaders[i])))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
        private void generateFromFiles(List <BDFFile> files)
        {
            try
            {
                try
                {
                    checkAreCompatible(files);
                }
                catch (Exception e)
                {
                    throw new BDFIncompatibleFilesException("Files are not compatible", e);
                }

                files.Sort((x, y) => DateTime.Compare(x.header.StartDateTime, y.header.StartDateTime));
                header                      = new BDFHeader();
                header.DataFormat           = files.First().header.DataFormat;
                header.ChannelCount         = files.First().header.ChannelCount;
                header.SecondsPerDataRecord = files.First().header.SecondsPerDataRecord;
                header.LocalSubject         = string.Copy(files.First().header.LocalSubject);
                header.LocalRecording       = string.Copy(files.First().header.LocalRecording);
                header.HeaderByteCount      = 256 * (header.ChannelCount + 1);
                header.StartDateTime        = files.First().header.StartDateTime;
                header.RecordCount          = files.Last().header.RecordCount + (int)((files.Last().header.StartDateTime - files.First().header.StartDateTime).TotalSeconds);


                channels = new BDFChannel[header.ChannelCount];
                for (int i = 0; i < channels.Length; i++)
                {
                    channels[i] = new BDFChannel();

                    channels[i].Header                      = new BDFChannelHeader();
                    channels[i].Header.Label                = String.Copy(files.First().channels[i].Header.Label);
                    channels[i].Header.TransuderType        = String.Copy(files.First().channels[i].Header.TransuderType);
                    channels[i].Header.Dimension            = String.Copy(files.First().channels[i].Header.Dimension);
                    channels[i].Header.MinValue             = files.First().channels[i].Header.MinValue;
                    channels[i].Header.MaxValue             = files.First().channels[i].Header.MaxValue;
                    channels[i].Header.DigitalMin           = files.First().channels[i].Header.DigitalMin;
                    channels[i].Header.DigitalMax           = files.First().channels[i].Header.DigitalMax;
                    channels[i].Header.Prefiltered          = String.Copy(files.First().channels[i].Header.Prefiltered);
                    channels[i].Header.SamplesPerDataRecord = files.First().channels[i].Header.SamplesPerDataRecord;


                    channels[i].Data = new int[channels[i].Header.SamplesPerDataRecord * header.RecordCount];

                    foreach (BDFFile file in files)
                    {
                        Array.Copy(file.channels[i].Data, 0, channels[i].Data, (int)((file.header.StartDateTime - header.StartDateTime).TotalSeconds) * channels[i].Header.SamplesPerDataRecord, file.channels[i].Data.Length);
                    }
                }
            }
            catch (Exception e)
            {
                throw new BDFPatchException("Cannot patch files!", e);
            }
        }
Beispiel #3
0
 public bool compatible(BDFHeader header)
 {
     if (!(LocalSubject.Equals(header.LocalSubject)))
         return false;
     if (!(LocalRecording.Equals(header.LocalRecording)))
         return false;
     if (!(DataFormat.Equals(header.DataFormat)))
         return false;
     if (ChannelCount != header.ChannelCount)
         return false;
     for (int i = 0; i < ChannelCount; i++)
     {
         if (!(ChannelHeaders[i].Equals(header.ChannelHeaders[i])))
             return false;
     }
     return true;
 }
Beispiel #4
0
 public static BDFHeader Copy(BDFHeader header)
 {
     BDFHeader res = new BDFHeader();
     res.LocalSubject = String.Copy(header.LocalSubject);
     res.LocalRecording = String.Copy(header.LocalRecording);
     res.StartDateTime = header.StartDateTime;
     res.HeaderByteCount = header.HeaderByteCount;
     res.DataFormat = String.Copy(header.DataFormat);
     res.RecordCount = header.RecordCount;
     res.SecondsPerDataRecord = header.SecondsPerDataRecord;
     res.ChannelCount = header.ChannelCount;
     res.ChannelHeaders = new BDFChannelHeader[res.ChannelCount];
     for (int i = 0; i < res.ChannelCount; i++)
     {
         res.ChannelHeaders[i] = BDFChannelHeader.Copy(header.ChannelHeaders[i]);
     }
     return res;
 }
Beispiel #5
0
        public static BDFHeader Copy(BDFHeader header)
        {
            BDFHeader res = new BDFHeader();

            res.LocalSubject         = String.Copy(header.LocalSubject);
            res.LocalRecording       = String.Copy(header.LocalRecording);
            res.StartDateTime        = header.StartDateTime;
            res.HeaderByteCount      = header.HeaderByteCount;
            res.DataFormat           = String.Copy(header.DataFormat);
            res.RecordCount          = header.RecordCount;
            res.SecondsPerDataRecord = header.SecondsPerDataRecord;
            res.ChannelCount         = header.ChannelCount;
            res.ChannelHeaders       = new BDFChannelHeader[res.ChannelCount];
            for (int i = 0; i < res.ChannelCount; i++)
            {
                res.ChannelHeaders[i] = BDFChannelHeader.Copy(header.ChannelHeaders[i]);
            }
            return(res);
        }
Beispiel #6
0
        public BDFHeader readHeader()
        {
            BDFFile   file   = new BDFFile(fileName);
            BDFHeader header = null;

            try
            {
                header = file.Header;
            }
            catch (BDFHeaderReadException e)
            {
                Exception ex = e as Exception;
                Console.WriteLine();
                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }
                Console.WriteLine();
                return(null);
            }
            return(BDFHeader.Copy(header));
        }
Beispiel #7
0
        private void readHeader()
        {
            try
            {
                header = new BDFHeader();
                byte[] bytes = readBytes(8);
                if (bytes.Length != 8 || bytes[0] != 255 || !Encoding.ASCII.GetString(bytes.Skip(1).ToArray()).Equals("BIOSEMI"))
                    throw new Exception(String.Format("{0} not BDFFile!", fileName));
                header.LocalSubject = readStr(80);
                header.LocalRecording = readStr(80);
                header.StartDateTime = readDateTime();
                header.HeaderByteCount = readStrInt(8);
                header.DataFormat = readStr(44);
                if (!header.DataFormat.Equals("24BIT"))
                    throw new Exception("Incorrect data format!");
                header.RecordCount = readStrInt(8);
                header.SecondsPerDataRecord = readStrInt(8);
                header.ChannelCount = readStrInt(4);

                channels = new BDFChannel[header.ChannelCount];

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i] = new BDFChannel();
                    channels[i].Header = new BDFChannelHeader();
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Label = readStr(16);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.TransuderType = readStr(80);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Dimension = readStr(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.MinValue = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.MaxValue = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.DigitalMin = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.DigitalMax = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Prefiltered = readStr(80);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.SamplesPerDataRecord = readStrInt(8);
                }


                header.ChannelHeaders = new BDFChannelHeader[header.ChannelCount];

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    header.ChannelHeaders[i] = channels[i].Header;
                }

                reader.ReadBytes(32 * header.ChannelCount);

                if (header.RecordCount == -1)
                {
                    int bytesPerDataRecord = 0;
                    for (int i = 0; i < header.ChannelCount; i++)
                    {
                        bytesPerDataRecord += (channels[i].Header.SamplesPerDataRecord * 3);
                    }

                    header.RecordCount = ((int)(new FileInfo(fileName)).Length - header.HeaderByteCount) / bytesPerDataRecord;
                }
                
                Size = header.RecordCount;

            }
            catch (Exception e)
            {
                throw new BDFHeaderReadException("Cannot read header from file " + fileName, e);
            }
        }
Beispiel #8
0
        private void generateFromFiles(List<BDFFile> files)
        {
            try
            {
                try
                {
                    checkAreCompatible(files);
                }
                catch (Exception e)
                {
                    throw new BDFIncompatibleFilesException("Files are not compatible", e);    
                }

                files.Sort((x, y) => DateTime.Compare(x.header.StartDateTime, y.header.StartDateTime));
                header = new BDFHeader();
                header.DataFormat = files.First().header.DataFormat;
                header.ChannelCount = files.First().header.ChannelCount;
                header.SecondsPerDataRecord = files.First().header.SecondsPerDataRecord;
                header.LocalSubject = string.Copy(files.First().header.LocalSubject);
                header.LocalRecording = string.Copy(files.First().header.LocalRecording);
                header.HeaderByteCount = 256 * (header.ChannelCount + 1);
                header.StartDateTime = files.First().header.StartDateTime;
                header.RecordCount = files.Last().header.RecordCount + (int)((files.Last().header.StartDateTime - files.First().header.StartDateTime).TotalSeconds);


                channels = new BDFChannel[header.ChannelCount];
                for (int i = 0; i < channels.Length; i++)
                {
                    channels[i] = new BDFChannel();

                    channels[i].Header = new BDFChannelHeader();
                    channels[i].Header.Label = String.Copy(files.First().channels[i].Header.Label);
                    channels[i].Header.TransuderType = String.Copy(files.First().channels[i].Header.TransuderType);
                    channels[i].Header.Dimension = String.Copy(files.First().channels[i].Header.Dimension);
                    channels[i].Header.MinValue = files.First().channels[i].Header.MinValue;
                    channels[i].Header.MaxValue = files.First().channels[i].Header.MaxValue;
                    channels[i].Header.DigitalMin = files.First().channels[i].Header.DigitalMin;
                    channels[i].Header.DigitalMax = files.First().channels[i].Header.DigitalMax;
                    channels[i].Header.Prefiltered = String.Copy(files.First().channels[i].Header.Prefiltered);
                    channels[i].Header.SamplesPerDataRecord = files.First().channels[i].Header.SamplesPerDataRecord;


                    channels[i].Data = new int[channels[i].Header.SamplesPerDataRecord * header.RecordCount];
                    
                    foreach (BDFFile file in files)
                    {
                        Array.Copy(file.channels[i].Data, 0, channels[i].Data, (int)((file.header.StartDateTime - header.StartDateTime).TotalSeconds) * channels[i].Header.SamplesPerDataRecord, file.channels[i].Data.Length);
                    }
                }
                
            }
            catch (Exception e)
            {
                throw new BDFPatchException("Cannot patch files!", e);
            }
        }
Beispiel #9
0
        private void readHeader()
        {
            try
            {
                header = new BDFHeader();
                byte[] bytes = readBytes(8);
                if (bytes.Length != 8 || bytes[0] != 255 || !Encoding.ASCII.GetString(bytes.Skip(1).ToArray()).Equals("BIOSEMI"))
                {
                    throw new Exception(String.Format("{0} not BDFFile!", fileName));
                }
                header.LocalSubject    = readStr(80);
                header.LocalRecording  = readStr(80);
                header.StartDateTime   = readDateTime();
                header.HeaderByteCount = readStrInt(8);
                header.DataFormat      = readStr(44);
                if (!header.DataFormat.Equals("24BIT"))
                {
                    throw new Exception("Incorrect data format!");
                }
                header.RecordCount          = readStrInt(8);
                header.SecondsPerDataRecord = readStrInt(8);
                header.ChannelCount         = readStrInt(4);

                channels = new BDFChannel[header.ChannelCount];

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i]        = new BDFChannel();
                    channels[i].Header = new BDFChannelHeader();
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Label = readStr(16);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.TransuderType = readStr(80);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Dimension = readStr(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.MinValue = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.MaxValue = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.DigitalMin = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.DigitalMax = readStrInt(8);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.Prefiltered = readStr(80);
                }

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    channels[i].Header.SamplesPerDataRecord = readStrInt(8);
                }


                header.ChannelHeaders = new BDFChannelHeader[header.ChannelCount];

                for (int i = 0; i < header.ChannelCount; i++)
                {
                    header.ChannelHeaders[i] = channels[i].Header;
                }

                reader.ReadBytes(32 * header.ChannelCount);

                if (header.RecordCount == -1)
                {
                    int bytesPerDataRecord = 0;
                    for (int i = 0; i < header.ChannelCount; i++)
                    {
                        bytesPerDataRecord += (channels[i].Header.SamplesPerDataRecord * 3);
                    }

                    header.RecordCount = ((int)(new FileInfo(fileName)).Length - header.HeaderByteCount) / bytesPerDataRecord;
                }

                Size = header.RecordCount;
            }
            catch (Exception e)
            {
                throw new BDFHeaderReadException("Cannot read header from file " + fileName, e);
            }
        }
        private void patchHeader(BDFHeader header)
        {
            this.header = BDFHeader.Copy(header);
            this.header.StartDateTime = beginTime;
            this.header.RecordCount   = -1;
            samplesPerDataRecord      = 0;
            for (int i = 0; i < header.ChannelCount; i++)
            {
                samplesPerDataRecord += header.ChannelHeaders[i].SamplesPerDataRecord;
            }

            patchBytes(new byte[1] {
                255
            });
            patchStr("BIOSEMI", 7);
            patchStr(this.header.LocalSubject, 80);
            patchStr(this.header.LocalRecording, 80);
            patchDateTime(this.header.StartDateTime);
            patchStrInt(this.header.HeaderByteCount, 8);
            patchStr(this.header.DataFormat, 44);
            patchStrInt(this.header.RecordCount, 8);
            patchStrInt(this.header.SecondsPerDataRecord, 8);
            patchStrInt(this.header.ChannelCount, 4);
            int channelCount = this.header.ChannelCount;

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Label, 16);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].TransuderType, 80);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Dimension, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].MinValue, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].MaxValue, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].DigitalMin, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].DigitalMax, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Prefiltered, 80);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].SamplesPerDataRecord, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr("reserved", 32);
            }
        }
        private void patchHeader(BDFHeader header)
        {
            this.header = BDFHeader.Copy(header);
            this.header.StartDateTime = beginTime;
            this.header.RecordCount = -1;
            samplesPerDataRecord = 0;
            for (int i = 0; i < header.ChannelCount; i++)
            {
                samplesPerDataRecord += header.ChannelHeaders[i].SamplesPerDataRecord;
            }

            patchBytes(new byte[1] { 255 });
            patchStr("BIOSEMI", 7);
            patchStr(this.header.LocalSubject, 80);
            patchStr(this.header.LocalRecording, 80);
            patchDateTime(this.header.StartDateTime);
            patchStrInt(this.header.HeaderByteCount, 8);
            patchStr(this.header.DataFormat, 44);
            patchStrInt(this.header.RecordCount, 8);
            patchStrInt(this.header.SecondsPerDataRecord, 8);
            patchStrInt(this.header.ChannelCount, 4);
            int channelCount = this.header.ChannelCount;

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Label, 16);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].TransuderType, 80);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Dimension, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].MinValue, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].MaxValue, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].DigitalMin, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].DigitalMax, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr(this.header.ChannelHeaders[i].Prefiltered, 80);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStrInt(this.header.ChannelHeaders[i].SamplesPerDataRecord, 8);
            }

            for (int i = 0; i < channelCount; i++)
            {
                patchStr("reserved", 32);
            }
        }