Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
            }
        }