private int CalcNumOfBytesInHeader(EDFFile edf)
        {
            int totalFixedLength = 256;
            int ns = edf.Signals.Length;
            int totalVariableLength = ns * 16 + (ns * 80) * 2 + (ns * 8) * 6 + (ns * 32);

            return(totalFixedLength + totalVariableLength);
        }
        public void WriteEDF(EDFFile edf, string edfFilePath)
        {
            edf.Header.SizeInBytes.Value = CalcNumOfBytesInHeader(edf);

            //----------------- Fixed length header items -----------------
            WriteItem(edf.Header.Version);
            WriteItem(edf.Header.PatientID);
            WriteItem(edf.Header.RecordID);
            WriteItem(edf.Header.RecordingStartDate);
            WriteItem(edf.Header.RecordingStartTime);
            WriteItem(edf.Header.SizeInBytes);
            WriteItem(edf.Header.Reserved);
            WriteItem(edf.Header.RecordCount);
            WriteItem(edf.Header.RecordDurationInSeconds);
            WriteItem(edf.Header.SignalCount);

            //----------------- Variable length header items -----------------
            WriteItem(edf.Signals.Select(s => s.Label));
            WriteItem(edf.Signals.Select(s => s.TransducerType));
            WriteItem(edf.Signals.Select(s => s.PhysicalDimension));
            WriteItem(edf.Signals.Select(s => s.PhysicalMinimum));
            WriteItem(edf.Signals.Select(s => s.PhysicalMaximum));
            WriteItem(edf.Signals.Select(s => s.DigitalMinimum));
            WriteItem(edf.Signals.Select(s => s.DigitalMaximum));
            WriteItem(edf.Signals.Select(s => s.Prefiltering));
            WriteItem(edf.Signals.Select(s => s.SampleCountPerRecord));
            WriteItem(edf.Signals.Select(s => s.Reserved));

            Console.WriteLine("Writer position after header: " + BaseStream.Position);
            Console.WriteLine("Writing signals.");
            //TODO: Missing for each record loop, see fixed reading code
            foreach (var sig in edf.Signals)
            {
                WriteSignal(sig);
            }

            Close();
            Console.WriteLine("File size: " + System.IO.File.ReadAllBytes(edfFilePath).Length);
        }