Skip to content

Commit 38174d0

Browse files
committed
adds support for reading patterns from the Oxford HDF5 format (.h5oina)
Note that this requires an update of the EMsoft_SDK to include building the HDF5 plugins!!!
1 parent 367830d commit 38174d0

1 file changed

Lines changed: 64 additions & 16 deletions

File tree

Source/EMsoftHDFLib/patternmod.f90

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ recursive function get_input_type(inputtype) result(itype)
111111
if (trim(inputtype).eq."TSLup2") itype = 3
112112
if (trim(inputtype).eq."TSLHDF") itype = 4
113113
if (trim(inputtype).eq."OxfordBinary") itype = 5
114-
if (trim(inputtype).eq."OxfordHDF") itype = 6 ! to be implemented
114+
if (trim(inputtype).eq."OxfordHDF") itype = 6
115115
if (trim(inputtype).eq."EMEBSD") itype = 7
116116
if (trim(inputtype).eq."BrukerHDF") itype = 8
117117
if (trim(inputtype).eq."NORDIF") itype = 9
@@ -220,6 +220,7 @@ end subroutine invert_ordering_arrays
220220
!> @date 05/01/19 MA 1.7 add support for Oxford Instruments binary pattern files
221221
!> @date 10/09/19 HWÅ 1.8 support for NORDIF binary pattern files
222222
!> @date 04/06/20 MDG 1.9 adds support for 32-bit integer and float HDF files generated by EMEBSD
223+
!> @date 11/10/22 MDG 2.0 adds support for Oxford HDF file format
223224
!--------------------------------------------------------------------------
224225
recursive function openExpPatternFile(filename, npat, L, inputtype, recsize, funit, HDFstrings, verbose) result(istat)
225226
!DEC$ ATTRIBUTES DLLEXPORT :: openExpPatternFile
@@ -319,9 +320,38 @@ recursive function openExpPatternFile(filename, npat, L, inputtype, recsize, fun
319320
end if
320321

321322
case(6) ! "OxfordHDF"
322-
call FatalError("openExpPatternFile","OxfordHDF input format not yet implemented")
323-
! at this point in time (Feb. 2018) it does not appear that the Oxford HDF5 format has the
324-
! patterns stored in it... Hence this option is currently non-existent.
323+
! Fall 2022, Oxford has an HDF5 file with extension .h5oina; some of the patterns in the
324+
! "Processed Patterns" dataset may have been compressed using the lzf compression scheme.
325+
! Reading them does not require anything special when the most recent version of the
326+
! EMsoft_SDK is used. It does require that the HDF5_PLUGIN_PATH environment variable is
327+
! set to the location of the plugin dynamical libraries; in a development environment, this
328+
! would be done with the following shell command (csh):
329+
! setenv HDF5_PLUGIN_PATH /full/path/to/EMsoft_SDK/hdf5-1.12.2-Release/lib/plugin
330+
! We remind the user here that this parameter needs to be set in order for the uncompression
331+
! dynamically loaded library to be found... The actual reading of the data set is identical
332+
! to that of the TSLHDF format, but some or all patterns may be in compressed form.
333+
! [MDG, 11/09/22]
334+
call Message(" ================================================================ ")
335+
call Message("The Oxford HDF5 format uses the lzf compression algorithm to ")
336+
call Message("compress patterns; to properly read those patterns and uncompress ")
337+
call Message("them, the HDF5_PLUGIN_PATH environmental parameter must be set. ")
338+
call Message("Please make sure that this parameter points to the correct folder;")
339+
call Message("for instance, EMsoftOO_SDK/hdf5-1.12.2-Release/lib/plugin or ")
340+
call Message("similar; the folder should contain a liblzf.so or similar library.")
341+
call Message(" ================================================================ ")
342+
343+
nullify(pmHDF_head%next)
344+
! open the file
345+
hdferr = HDF_openFile(ename, pmHDF_head, readonly=.TRUE.)
346+
if (hdferr.ne.0) call HDF_handleError(hdferr,'HDF_openFile ')
347+
! open all the groups to the correct level of the data set
348+
do i=1,hdfnumg
349+
groupname = trim(HDFstrings(i))
350+
hdferr = HDF_openGroup(groupname, pmHDF_head)
351+
if (hdferr.ne.0) call HDF_handleError(hdferr,'HDF_openGroup: group name issue, check for typos ...')
352+
end do
353+
! and here we leave this file open so that we can read data blocks using the hyperslab mechanism;
354+
! we can do this because the pmHDF_head pointer is private and has SAVE status for this entire module
325355

326356
case(4, 7, 10, 11, 12) ! "TSLHDF", "EMEBSD" , "EMEBSD32i" , "EMEBSD32f" , "EMEBSDdefect"
327357
nullify(pmHDF_head%next)
@@ -419,6 +449,7 @@ end function openExpPatternFile
419449
!> @date 09/26/19 MDG 1.6 add option for vertical flip of patterns
420450
!> @date 10/09/19 HWÅ 1.7 support for NORDIF binary pattern files
421451
!> @date 02/02/21 CZ 1.8 support for reading EMEBSDdefect generated file
452+
!> @date 11/10/22 MDG 2.0 adds support for Oxford HDF file format
422453
!--------------------------------------------------------------------------
423454
recursive subroutine getExpPatternRow(iii, wd, patsz, L, dims3, offset3, funit, inputtype, HDFstrings, &
424455
exppatarray, ROI, flipy)
@@ -598,8 +629,21 @@ recursive subroutine getExpPatternRow(iii, wd, patsz, L, dims3, offset3, funit,
598629
where(exppatarray.lt.0.0) exppatarray = exppatarray + 256.0
599630

600631
case(6) ! "OxfordHDF"
601-
! at this point in time (Feb. 2018) it does not appear that the Oxford HDF5 format has the
602-
! patterns stored in it... Hence this option is currently non-existent.
632+
! read a hyperslab section from the HDF5 input file; note that these patterns may be
633+
! in lzf compressed form; the HDF read routine will transparently take care of the
634+
! uncompressing, but only if the proper library can be found; make sure the HDF5_PLUGIN_PATH
635+
! environmental parameter has been set correctly. [MDG, 11/09/22]
636+
EBSDpatint = HDF_readHyperslabIntegerArray3D(dataset, offset3, dims3, pmHDF_head)
637+
exppatarray = 0.0
638+
do kk=kkstart,kkend
639+
do jj=1,dims3(2)
640+
do ii=1,dims3(1)
641+
z = float(EBSDpatint(ii,jj,kk))
642+
if (z.lt.0.0) z = z+2.0**16
643+
exppatarray((kk-kkstart)*patsz+(jj-1)*dims3(1)+ii) = z
644+
end do
645+
end do
646+
end do
603647

604648
case(4) ! "TSLHDF" passed tests on 2/14/18 by MDG
605649
! read a hyperslab section from the HDF5 input file
@@ -893,12 +937,19 @@ recursive subroutine getSingleExpPattern(iii, wd, patsz, L, dims3, offset3, funi
893937
where(exppat.lt.0.0) exppat = exppat + 256.0
894938

895939
case(6) ! "OxfordHDF"
896-
! at this point in time (Feb. 2018) it does not appear that the Oxford HDF5 format has the
897-
! patterns stored in it... Hence this option is currently non-existent.
898-
899-
! Update 07/13/19: after talking with Phillipe Pinard (Oxford) at the EMAS 2019 conference
900-
! in Trondheim, it is clear that Oxford is working on including the patterns into their
901-
! current HDF5 file version. This might become available sometime by the end of 2019.
940+
! read a hyperslab section from the HDF5 input file; note that these patterns may be
941+
! in lzf compressed form; the HDF read routine will transparently take care of the
942+
! uncompressing, but only if the proper library can be found; make sure the HDF5_PLUGIN_PATH
943+
! environmental parameter has been set correctly. [MDG, 11/09/22]
944+
EBSDpatint = HDF_readHyperslabIntegerArray3D(dataset, offset3, dims3, pmHDF_head)
945+
exppat = 0.0
946+
do jj=1,dims3(2)
947+
do ii=1,dims3(1)
948+
z = float(EBSDpatint(ii,jj,1))
949+
if (z.lt.0.0) z = z+2.0**16
950+
exppat((jj-1)*dims3(1)+ii) = z
951+
end do
952+
end do
902953

903954
case(4) ! "TSLHDF" passed tests on 2/20/18 by MDG
904955
! read a hyperslab single pattern section from the HDF5 input file
@@ -1968,16 +2019,13 @@ recursive subroutine closeExpPatternFile(inputtype, funit)
19682019
case(2,3) ! "TSLup2"
19692020
close(unit=funit,status='keep')
19702021

1971-
case(4, 7, 10, 11, 12) ! "TSLHDF" "EMEBSD" "EMEBSD32i" "EMEBSD32f" "EMEBSDdefect"
2022+
case(4, 6, 7, 10, 11, 12) ! "TSLHDF" "EMEBSD" "EMEBSD32i" "EMEBSD32f" "EMEBSDdefect"
19722023
call HDF_pop(pmHDF_head,.TRUE.)
19732024
nullify(pmHDF_head%next)
19742025

19752026
case(5) ! "OxfordBinary"
19762027
close(unit=funit,status='keep')
19772028

1978-
case(6) ! "OxfordHDF"
1979-
call FatalError("closeExpPatternFile","input format not yet implemented")
1980-
19812029
case(8) ! "BrukerHDF"
19822030
call HDF_pop(pmHDF_head,.TRUE.)
19832031
nullify(pmHDF_head%next)

0 commit comments

Comments
 (0)