Skip to content

Commit

Permalink
preliminary update of .ebsp file reader to include version 5
Browse files Browse the repository at this point in the history
needs to be tested
  • Loading branch information
marcdegraef committed Mar 21, 2024
1 parent 9180fe7 commit f10e608
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Source/EMsoftOOLib/mod_vendors.f90
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ recursive function openExpPatternFile_(self, EMsoft, npat, L, recsize, HDFstring
end if
! get the first byte to check if this file is version 1-3 or 4
! version 4 has an extra byte in the header...
! now there is also a version 5 file with some differences ...
read(unit=self%funit, pos=1, iostat=ios) header
ebspversion = 256-iachar(header)
io_int(1) = ebspversion
Expand Down Expand Up @@ -844,11 +845,12 @@ recursive subroutine getExpPatternRow_(self, iii, wd, patsz, L, dims3, offset3,
case(5) ! "OxfordBinary"

! read position of patterns in file for a single row from the header
if (ebspversion.eq.4) then
if (ebspversion.gt.3) then
read(unit=self%funit, pos=(liii-1)*lwd*8+10, iostat=ios) patoffsets
else
read(unit=self%funit, pos=(liii-1)*lwd*8+9, iostat=ios) patoffsets
end if
if (ebspversion.eq.5) patoffsets = patoffsets + 25_8

! generate a buffer to load individual patterns into
buffersize = lL
Expand All @@ -859,8 +861,13 @@ recursive subroutine getExpPatternRow_(self, iii, wd, patsz, L, dims3, offset3,
allocate(pairs(buffersize))

do ii=1,lwd
! read each pattern into buffer with the 16 bytes of metadata skipped
read(unit=self%funit, pos=patoffsets(ii)+17_8, iostat=ios) buffer
! read each pattern into buffer with the 16 bytes of metadata skipped (42 for version 5)
if (ebspversion.eq.5) then
! read(unit=self%funit, pos=patoffsets(ii)+43_8, iostat=ios) buffer
read(unit=self%funit, pos=patoffsets(ii), iostat=ios) buffer
else
read(unit=self%funit, pos=patoffsets(ii)+17_8, iostat=ios) buffer
end if

! loop over pixels and convert the byte values into single byte integers
do jj=1_ill,lL
Expand Down Expand Up @@ -1133,18 +1140,24 @@ recursive subroutine getSingleExpPattern_(self, iii, wd, patsz, L, dims3, offset
l1 = mod(offset3(3),wd)
lL = L
lwd = wd
if (ebspversion.eq.4) then
if (ebspversion.gt.3) then
read(unit=self%funit, pos=(liii-1)*lwd*8+10, iostat=ios) patoffsets
else
read(unit=self%funit, pos=(liii-1)*lwd*8+9, iostat=ios) patoffsets
end if
if (ebspversion.eq.5) patoffsets = patoffsets + 25_8

! generate buffers to load individual pattern into
buffersize = lL
allocate(buffer(buffersize), pairs(buffersize))

! read single pattern into buffer with the 16 bytes of metadata skipped
read(unit=self%funit, pos=patoffsets(l1)+17_8, iostat=ios) buffer
if (ebspversion.eq.5) then
! read(unit=self%funit, pos=patoffsets(l1)+43_8, iostat=ios) buffer
read(unit=self%funit, pos=patoffsets(l1), iostat=ios) buffer
else
read(unit=self%funit, pos=patoffsets(l1)+17_8, iostat=ios) buffer
end if

! convert the byte values into single byte integers
pairs = ichar(buffer)
Expand Down

0 comments on commit f10e608

Please sign in to comment.