Example #1
0
        internal static H5File OpenCore(string filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, bool deleteOnClose = false)
        {
            var absoluteFilePath = System.IO.Path.GetFullPath(filePath);
            var stream           = System.IO.File.Open(absoluteFilePath, fileMode, fileAccess, fileShare);

            return(H5File.OpenCore(stream, absoluteFilePath, deleteOnClose));
        }
        public static H5File GetH5File(Superblock superblock, string absoluteFilePath)
        {
            if (!Uri.TryCreate(absoluteFilePath, UriKind.Absolute, out var uri))
            {
                throw new Exception("The provided path is not absolute.");
            }

            if (!uri.IsFile && !uri.IsUnc)
            {
                throw new Exception("The provided path is not a file path or aN UNC path.");
            }

            if (!_fileMap.TryGetValue(superblock, out var pathToH5FileMap))
            {
                pathToH5FileMap      = new Dictionary <string, H5File>();
                _fileMap[superblock] = pathToH5FileMap;
            }

            if (!pathToH5FileMap.TryGetValue(uri.AbsoluteUri, out var h5File))
            {
#warning This does not correspond to https://support.hdfgroup.org/HDF5/doc/RM/H5L/H5Lcreate_external.htm
                h5File = H5File.Open(uri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                pathToH5FileMap[uri.AbsoluteUri] = h5File;
            }

            return(h5File);
        }
 internal H5NamedReference(string name, ulong value, H5File file)
 {
     this.Name       = name;
     this.Value      = value;
     this.File       = file;
     this.ScratchPad = null;
     this.Exception  = null;
 }
        internal static H5File Open(string filePath, FileMode mode, FileAccess fileAccess, FileShare fileShare, bool deleteOnClose)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new Exception("This library only works on little endian systems.");
            }

            var absoluteFilePath = System.IO.Path.GetFullPath(filePath);
            var reader           = new H5BinaryReader(System.IO.File.Open(absoluteFilePath, mode, fileAccess, fileShare));

            // superblock
            int stepSize  = 512;
            var signature = reader.ReadBytes(8);

            while (!H5File.ValidateSignature(signature, Superblock.FormatSignature))
            {
                reader.Seek(stepSize - 8, SeekOrigin.Current);

                if (reader.BaseStream.Position >= reader.BaseStream.Length)
                {
                    throw new Exception("The file is not a valid HDF 5 file.");
                }

                signature = reader.ReadBytes(8);
                stepSize *= 2;
            }

            var version = reader.ReadByte();

            var superblock = (Superblock)(version switch
            {
                0 => new Superblock01(reader, version),
                1 => new Superblock01(reader, version),
                2 => new Superblock23(reader, version),
                3 => new Superblock23(reader, version),
                _ => throw new NotSupportedException($"The superblock version '{version}' is not supported.")
            });
Example #5
0
 internal H5Group(H5File file, H5Context context, H5NamedReference reference, ObjectHeader header)
     : base(context, reference, header)
 {
     _file = file;
 }
Example #6
0
 internal H5Group(H5File file, H5Context context, H5NamedReference reference)
     : base(context, reference)
 {
     _file       = file;
     _scratchPad = reference.ScratchPad;
 }
Example #7
0
 internal static H5File OpenReadCore(string filePath, bool deleteOnClose = false)
 {
     return(H5File.OpenCore(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, deleteOnClose));
 }
 public static H5File Open(string filePath, FileMode mode, FileAccess fileAccess, FileShare fileShare)
 {
     return(H5File.Open(filePath, mode, fileAccess, fileShare, deleteOnClose: false));
 }
Example #9
0
        internal H5Dataset(H5File file, H5Context context, NamedReference reference, ObjectHeader header)
            : base(context, reference, header)
        {
            this.File = file;

            foreach (var message in this.Header.HeaderMessages)
            {
                var type = message.Data.GetType();

                if (typeof(DataLayoutMessage).IsAssignableFrom(type))
                {
                    this.InternalDataLayout = (DataLayoutMessage)message.Data;
                }

                else if (type == typeof(DataspaceMessage))
                {
                    this.InternalDataspace = (DataspaceMessage)message.Data;
                }

                else if (type == typeof(DatatypeMessage))
                {
                    this.InternalDataType = (DatatypeMessage)message.Data;
                }

                else if (type == typeof(FillValueMessage))
                {
                    this.InternalFillValue = (FillValueMessage)message.Data;
                }

                else if (type == typeof(FilterPipelineMessage))
                {
                    this.InternalFilterPipeline = (FilterPipelineMessage)message.Data;
                }

                else if (type == typeof(ObjectModificationMessage))
                {
                    this.InternalObjectModification = (ObjectModificationMessage)message.Data;
                }

                else if (type == typeof(ExternalFileListMessage))
                {
                    this.InternalExternalFileList = (ExternalFileListMessage)message.Data;
                }
            }

            // check that required fields are set
            if (this.InternalDataLayout is null)
            {
                throw new Exception("The data layout message is missing.");
            }

            if (this.InternalDataspace is null)
            {
                throw new Exception("The dataspace message is missing.");
            }

            if (this.InternalDataType is null)
            {
                throw new Exception("The data type message is missing.");
            }

            if (this.InternalFillValue is null)
            {
                throw new Exception("The fill value message is missing.");
            }
        }
Example #10
0
 public static H5File Open(Stream stream)
 {
     return(H5File.OpenCore(stream, string.Empty));
 }
Example #11
0
 public static H5File Open(string filePath, FileMode mode, FileAccess fileAccess, FileShare fileShare)
 {
     return(H5File.OpenCore(filePath, mode, fileAccess, fileShare));
 }
Example #12
0
 public static H5File OpenRead(string filePath)
 {
     return(H5File.OpenReadCore(filePath));
 }