Merge branch 'vtr-as-input-prerequisites' into 'development'
prerequisites for using VTR as input format for spectral solver See merge request damask/DAMASK!214
This commit is contained in:
commit
d7932aeacb
|
@ -184,7 +184,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
|||
endif ()
|
||||
|
||||
set (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}} ${PETSC_INCLUDES} ${BUILDCMD_POST}")
|
||||
set (CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${PETSC_EXTERNAL_LIB} ${BUILDCMD_POST}")
|
||||
set (CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${PETSC_EXTERNAL_LIB} -lz ${BUILDCMD_POST}")
|
||||
|
||||
message ("Fortran Compiler Flags:\n${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}\n")
|
||||
message ("C Compiler Flags:\n${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}\n")
|
||||
|
|
|
@ -14,6 +14,7 @@ module CPFEM2
|
|||
use material
|
||||
use lattice
|
||||
use IO
|
||||
use base64
|
||||
use DAMASK_interface
|
||||
use results
|
||||
use discretization
|
||||
|
@ -42,6 +43,7 @@ subroutine CPFEM_initAll
|
|||
call DAMASK_interface_init ! Spectral and FEM interface to commandline
|
||||
call prec_init
|
||||
call IO_init
|
||||
call base64_init
|
||||
#ifdef Mesh
|
||||
call FEM_quadrature_init
|
||||
#endif
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "zlib.h"
|
||||
|
||||
/* http://stackoverflow.com/questions/30279228/is-there-an-alternative-to-getcwd-in-fortran-2003-2008 */
|
||||
|
||||
|
@ -57,3 +58,17 @@ void signalusr1_c(void (*handler)(int)){
|
|||
void signalusr2_c(void (*handler)(int)){
|
||||
signal(SIGUSR2, handler);
|
||||
}
|
||||
|
||||
void inflate_c(const uLong *s_deflated, const uLong *s_inflated, const Byte deflated[], Byte inflated[]){
|
||||
/* make writable copy, uncompress will write to it */
|
||||
uLong s_inflated_;
|
||||
s_inflated_ = *s_inflated;
|
||||
|
||||
if(uncompress((Bytef *)inflated, &s_inflated_, (Bytef *)deflated, *s_deflated) == Z_OK)
|
||||
return;
|
||||
else{
|
||||
for(uLong i=0;i<*s_inflated;i++){
|
||||
inflated[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ module IO
|
|||
|
||||
implicit none
|
||||
private
|
||||
|
||||
character(len=*), parameter, public :: &
|
||||
IO_WHITESPACE = achar(44)//achar(32)//achar(9)//achar(10)//achar(13) !< whitespace characters
|
||||
character, parameter, public :: &
|
||||
|
@ -50,7 +51,7 @@ contains
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief does nothing.
|
||||
!> @brief do self test
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine IO_init
|
||||
|
||||
|
@ -447,6 +448,9 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg)
|
|||
msg = 'invalid character for float:'
|
||||
case (113)
|
||||
msg = 'invalid character for logical:'
|
||||
case (114)
|
||||
msg = 'cannot decode base64 string:'
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
! lattice error messages
|
||||
case (130)
|
||||
|
|
|
@ -0,0 +1,226 @@
|
|||
!--------------------------------------------------------------------------------------------------
|
||||
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
||||
!> @brief Decode Base64 strings.
|
||||
!> @details See https://en.wikipedia.org/wiki/Base64.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
module base64
|
||||
use prec
|
||||
use IO
|
||||
|
||||
implicit none
|
||||
private
|
||||
|
||||
character(len=*), parameter :: &
|
||||
base64_encoding='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
|
||||
public :: &
|
||||
base64_init, &
|
||||
base64_to_bytes, &
|
||||
base64_nBase64, &
|
||||
base64_nByte
|
||||
|
||||
contains
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Do self test.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine base64_init
|
||||
|
||||
write(6,'(/,a)') ' <<<+- base64 init -+>>>'; flush(6)
|
||||
|
||||
call selfTest
|
||||
|
||||
end subroutine base64_init
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Calculate number of Base64 characters required for storage of N bytes.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function base64_nBase64(nByte)
|
||||
|
||||
integer(pLongInt), intent(in) :: nByte
|
||||
integer(pLongInt) :: base64_nBase64
|
||||
|
||||
base64_nBase64 = 4_pLongInt * (nByte/3_pLongInt + merge(1_pLongInt,0_pLongInt,mod(nByte,3_pLongInt) /= 0_pLongInt))
|
||||
|
||||
end function base64_nBase64
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Calculate number of bytes required for storage of N Base64 characters.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function base64_nByte(nBase64)
|
||||
|
||||
integer(pLongInt), intent(in) :: nBase64
|
||||
integer(pLongInt) :: base64_nByte
|
||||
|
||||
base64_nByte = 3_pLongInt * (nBase64/4_pLongInt)
|
||||
|
||||
end function base64_nByte
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Decode Base64 ASCII string into byte-wise binary representation.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
function base64_to_bytes(base64_str,s,e) result(bytes)
|
||||
|
||||
character(len=*), intent(in) :: base64_str !< Base64 string representation
|
||||
integer(pLongInt), intent(in), optional :: &
|
||||
s, & !< start (in bytes)
|
||||
e !< end (in bytes)
|
||||
|
||||
integer(pLongInt) :: s_bytes, e_bytes, s_str, e_str
|
||||
integer(C_SIGNED_CHAR), dimension(:), allocatable :: bytes
|
||||
|
||||
if(.not. valid_base64(base64_str)) call IO_error(114,ext_msg='invalid character')
|
||||
|
||||
if(present(s)) then
|
||||
if(s<1_pLongInt) call IO_error(114, ext_msg='s out of range')
|
||||
s_str = ((s-1_pLongInt)/3_pLongInt)*4_pLongInt + 1_pLongInt
|
||||
s_bytes = mod(s-1_pLongInt,3_pLongInt) + 1_pLongInt
|
||||
else
|
||||
s_str = 1_pLongInt
|
||||
s_bytes = 1_pLongInt
|
||||
endif
|
||||
|
||||
if(present(e)) then
|
||||
if(e>base64_nByte(len(base64_str,kind=pLongInt))) call IO_error(114, ext_msg='e out of range')
|
||||
e_str = ((e-1_pLongInt)/3_pLongInt)*4_pLongInt + 4_pLongInt
|
||||
e_bytes = e - base64_nByte(s_str)
|
||||
else
|
||||
e_str = len(base64_str,kind=pLongInt)
|
||||
e_bytes = base64_nByte(len(base64_str,kind=pLongInt)) - base64_nByte(s_str)
|
||||
if(base64_str(e_str-0_pLongInt:e_str-0_pLongInt) == '=') e_bytes = e_bytes - 1_pLongInt
|
||||
if(base64_str(e_str-1_pLongInt:e_str-1_pLongInt) == '=') e_bytes = e_bytes - 1_pLongInt
|
||||
endif
|
||||
|
||||
bytes = decode_base64(base64_str(s_str:e_str))
|
||||
bytes = bytes(s_bytes:e_bytes)
|
||||
|
||||
end function base64_to_bytes
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Convert a Base64 ASCII string into its byte-wise binary representation.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function decode_base64(base64_str) result(bytes)
|
||||
|
||||
character(len=*), intent(in) :: base64_str !< Base64 string representation
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(base64_nByte(len(base64_str,pLongInt))) :: bytes
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(0:3) :: charPos
|
||||
integer(pLongInt) :: c, b, p
|
||||
|
||||
c = 1_pLongInt
|
||||
b = 1_pLongInt
|
||||
|
||||
do while(c < len(base64_str,kind=pLongInt))
|
||||
do p=0_pLongInt,3_pLongInt
|
||||
if(c+p<=len(base64_str,kind=pLongInt)) then
|
||||
charPos(p) = int(index(base64_encoding,base64_str(c+p:c+p))-1,C_SIGNED_CHAR)
|
||||
else
|
||||
charPos(p) = 0_C_SIGNED_CHAR
|
||||
endif
|
||||
enddo
|
||||
|
||||
call mvbits(charPos(0),0,6,bytes(b+0),2)
|
||||
call mvbits(charPos(1),4,2,bytes(b+0),0)
|
||||
call mvbits(charPos(1),0,4,bytes(b+1),4)
|
||||
call mvbits(charPos(2),2,4,bytes(b+1),0)
|
||||
call mvbits(charPos(2),0,2,bytes(b+2),6)
|
||||
call mvbits(charPos(3),0,6,bytes(b+2),0)
|
||||
b = b+3_pLongInt
|
||||
c = c+4_pLongInt
|
||||
enddo
|
||||
|
||||
end function decode_base64
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Test for valid Base64 encoded string.
|
||||
!> @details Input string must be properly padded.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure logical function valid_base64(base64_str)
|
||||
|
||||
character(len=*), intent(in) :: base64_str !< Base64 string representation
|
||||
|
||||
integer(pLongInt) :: l
|
||||
|
||||
l = len(base64_str,pLongInt)
|
||||
valid_base64 = .true.
|
||||
|
||||
if(mod(l,4_pLongInt)/=0_pLongInt .or. l < 4_pInt) valid_base64 = .false.
|
||||
if(verify(base64_str(:l-2_pLongInt),base64_encoding, kind=pLongInt) /= 0_pLongInt) valid_base64 = .false.
|
||||
if(verify(base64_str(l-1_pLongInt:),base64_encoding//'=',kind=pLongInt) /= 0_pLongInt) valid_base64 = .false.
|
||||
|
||||
end function valid_base64
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Check correctness of base64 functions.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine selfTest
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), allocatable :: bytes
|
||||
character(len=*), parameter :: zero_to_three = 'AAECAw=='
|
||||
|
||||
! https://en.wikipedia.org/wiki/Base64#Output_padding
|
||||
if(base64_nBase64(20_pLongInt) /= 28_pLongInt) call IO_error(0,ext_msg='base64_nBase64/20/28')
|
||||
if(base64_nBase64(19_pLongInt) /= 28_pLongInt) call IO_error(0,ext_msg='base64_nBase64/19/28')
|
||||
if(base64_nBase64(18_pLongInt) /= 24_pLongInt) call IO_error(0,ext_msg='base64_nBase64/18/24')
|
||||
if(base64_nBase64(17_pLongInt) /= 24_pLongInt) call IO_error(0,ext_msg='base64_nBase64/17/24')
|
||||
if(base64_nBase64(16_pLongInt) /= 24_pLongInt) call IO_error(0,ext_msg='base64_nBase64/16/24')
|
||||
|
||||
if(base64_nByte(4_pLongInt) /= 3_pLongInt) call IO_error(0,ext_msg='base64_nByte/4/3')
|
||||
if(base64_nByte(8_pLongInt) /= 6_pLongInt) call IO_error(0,ext_msg='base64_nByte/8/6')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three)
|
||||
if(any(bytes /= int([0,1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 4) call IO_error(0,ext_msg='base64_to_bytes//')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,e=1_pLongInt)
|
||||
if(any(bytes /= int([0],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes//1')
|
||||
bytes = base64_to_bytes(zero_to_three,e=2_pLongInt)
|
||||
if(any(bytes /= int([0,1],C_SIGNED_CHAR)) .or. size(bytes) /= 2) call IO_error(0,ext_msg='base64_to_bytes//2')
|
||||
bytes = base64_to_bytes(zero_to_three,e=3_pLongInt)
|
||||
if(any(bytes /= int([0,1,2],C_SIGNED_CHAR)) .or. size(bytes) /= 3) call IO_error(0,ext_msg='base64_to_bytes//3')
|
||||
bytes = base64_to_bytes(zero_to_three,e=4_pLongInt)
|
||||
if(any(bytes /= int([0,1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 4) call IO_error(0,ext_msg='base64_to_bytes//4')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,s=1_pLongInt)
|
||||
if(any(bytes /= int([0,1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 4) call IO_error(0,ext_msg='base64_to_bytes/1/')
|
||||
bytes = base64_to_bytes(zero_to_three,s=2_pLongInt)
|
||||
if(any(bytes /= int([1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 3) call IO_error(0,ext_msg='base64_to_bytes/2/')
|
||||
bytes = base64_to_bytes(zero_to_three,s=3_pLongInt)
|
||||
if(any(bytes /= int([2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 2) call IO_error(0,ext_msg='base64_to_bytes/3/')
|
||||
bytes = base64_to_bytes(zero_to_three,s=4_pLongInt)
|
||||
if(any(bytes /= int([3],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes/4/')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,s=1_pLongInt,e=1_pLongInt)
|
||||
if(any(bytes /= int([0],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes/1/1')
|
||||
bytes = base64_to_bytes(zero_to_three,s=2_pLongInt,e=2_pLongInt)
|
||||
if(any(bytes /= int([1],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes/2/2')
|
||||
bytes = base64_to_bytes(zero_to_three,s=3_pLongInt,e=3_pLongInt)
|
||||
if(any(bytes /= int([2],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes/3/3')
|
||||
bytes = base64_to_bytes(zero_to_three,s=4_pLongInt,e=4_pLongInt)
|
||||
if(any(bytes /= int([3],C_SIGNED_CHAR)) .or. size(bytes) /= 1) call IO_error(0,ext_msg='base64_to_bytes/4/4')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,s=1_pLongInt,e=2_pLongInt)
|
||||
if(any(bytes /= int([0,1],C_SIGNED_CHAR)) .or. size(bytes) /= 2) call IO_error(0,ext_msg='base64_to_bytes/1/2')
|
||||
bytes = base64_to_bytes(zero_to_three,s=2_pLongInt,e=3_pLongInt)
|
||||
if(any(bytes /= int([1,2],C_SIGNED_CHAR)) .or. size(bytes) /= 2) call IO_error(0,ext_msg='base64_to_bytes/2/3')
|
||||
bytes = base64_to_bytes(zero_to_three,s=3_pLongInt,e=4_pLongInt)
|
||||
if(any(bytes /= int([2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 2) call IO_error(0,ext_msg='base64_to_bytes/3/4')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,s=1_pLongInt,e=3_pLongInt)
|
||||
if(any(bytes /= int([0,1,2],C_SIGNED_CHAR)) .or. size(bytes) /= 3) call IO_error(0,ext_msg='base64_to_bytes/1/3')
|
||||
bytes = base64_to_bytes(zero_to_three,s=2_pLongInt,e=4_pLongInt)
|
||||
if(any(bytes /= int([1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 3) call IO_error(0,ext_msg='base64_to_bytes/2/4')
|
||||
|
||||
bytes = base64_to_bytes(zero_to_three,s=1_pLongInt,e=4_pLongInt)
|
||||
if(any(bytes /= int([0,1,2,3],C_SIGNED_CHAR)) .or. size(bytes) /= 4) call IO_error(0,ext_msg='base64_to_bytes/1/4')
|
||||
|
||||
end subroutine selfTest
|
||||
|
||||
end module base64
|
95
src/prec.f90
95
src/prec.f90
|
@ -8,6 +8,7 @@
|
|||
!--------------------------------------------------------------------------------------------------
|
||||
module prec
|
||||
use, intrinsic :: IEEE_arithmetic
|
||||
use, intrinsic :: ISO_C_Binding
|
||||
|
||||
implicit none
|
||||
public
|
||||
|
@ -81,7 +82,7 @@ contains
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief reporting precision
|
||||
!> @brief report precision and do self test
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine prec_init
|
||||
|
||||
|
@ -100,7 +101,7 @@ end subroutine prec_init
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief equality comparison for float with double precision
|
||||
!> @brief Test floating point numbers with double precision for equality.
|
||||
! replaces "==" but for certain (relative) tolerance. Counterpart to dNeq
|
||||
! https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
! AlmostEqualRelative
|
||||
|
@ -123,7 +124,7 @@ end function dEq
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief inequality comparison for float with double precision
|
||||
!> @brief Test floating point numbers with double precision for inequality.
|
||||
! replaces "!=" but for certain (relative) tolerance. Counterpart to dEq
|
||||
! https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
! AlmostEqualRelative NOT
|
||||
|
@ -143,7 +144,7 @@ end function dNeq
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief equality to 0 comparison for float with double precision
|
||||
!> @brief Test floating point number with double precision for equality to 0.
|
||||
! replaces "==0" but everything not representable as a normal number is treated as 0. Counterpart to dNeq0
|
||||
! https://de.mathworks.com/help/matlab/ref/realmin.html
|
||||
! https://docs.oracle.com/cd/E19957-01/806-3568/ncg_math.html
|
||||
|
@ -166,7 +167,7 @@ end function dEq0
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief inequality to 0 comparison for float with double precision
|
||||
!> @brief Test floating point number with double precision for inequality to 0.
|
||||
! replaces "!=0" but everything not representable as a normal number is treated as 0. Counterpart to dEq0
|
||||
! https://de.mathworks.com/help/matlab/ref/realmin.html
|
||||
! https://docs.oracle.com/cd/E19957-01/806-3568/ncg_math.html
|
||||
|
@ -186,7 +187,7 @@ end function dNeq0
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief equality comparison for complex with double precision
|
||||
!> @brief Test complex floating point numbers with double precision for equality.
|
||||
! replaces "==" but for certain (relative) tolerance. Counterpart to cNeq
|
||||
! https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
! probably a component wise comparison would be more accurate than the comparsion of the absolute
|
||||
|
@ -210,7 +211,7 @@ end function cEq
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief inequality comparison for complex with double precision
|
||||
!> @brief Test complex floating point numbers with double precision for inequality.
|
||||
! replaces "!=" but for certain (relative) tolerance. Counterpart to cEq
|
||||
! https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||
! probably a component wise comparison would be more accurate than the comparsion of the absolute
|
||||
|
@ -231,23 +232,95 @@ end function cNeq
|
|||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief check correctness of some prec functions
|
||||
!> @brief Decode byte array (C_SIGNED_CHAR) as C_FLOAT array (4 byte float).
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function bytes_to_C_FLOAT(bytes)
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), intent(in) :: bytes !< byte-wise representation of a C_FLOAT array
|
||||
real(C_FLOAT), dimension(size(bytes,kind=pLongInt)/(storage_size(0._C_FLOAT,pLongInt)/8_pLongInt)) :: &
|
||||
bytes_to_C_FLOAT
|
||||
|
||||
bytes_to_C_FLOAT = transfer(bytes,bytes_to_C_FLOAT,size(bytes_to_C_FLOAT))
|
||||
|
||||
end function bytes_to_C_FLOAT
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Decode byte array (C_SIGNED_CHAR) as C_DOUBLE array (8 byte float).
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function bytes_to_C_DOUBLE(bytes)
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), intent(in) :: bytes !< byte-wise representation of a C_DOUBLE array
|
||||
real(C_DOUBLE), dimension(size(bytes,kind=pLongInt)/(storage_size(0._C_DOUBLE,pLongInt)/8_pLongInt)) :: &
|
||||
bytes_to_C_DOUBLE
|
||||
|
||||
bytes_to_C_DOUBLE = transfer(bytes,bytes_to_C_DOUBLE,size(bytes_to_C_DOUBLE))
|
||||
|
||||
end function bytes_to_C_DOUBLE
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Decode byte array (C_SIGNED_CHAR) as C_INT32_T array (4 byte signed integer).
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function bytes_to_C_INT32_T(bytes)
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), intent(in) :: bytes !< byte-wise representation of a C_INT32_T array
|
||||
integer(C_INT32_T), dimension(size(bytes,kind=pLongInt)/(storage_size(0_C_INT32_T,pLongInt)/8_pLongInt)) :: &
|
||||
bytes_to_C_INT32_T
|
||||
|
||||
bytes_to_C_INT32_T = transfer(bytes,bytes_to_C_INT32_T,size(bytes_to_C_INT32_T))
|
||||
|
||||
end function bytes_to_C_INT32_T
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Decode byte array (C_SIGNED_CHAR) as C_INT64_T array (8 byte signed integer).
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
pure function bytes_to_C_INT64_T(bytes)
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), intent(in) :: bytes !< byte-wise representation of a C_INT64_T array
|
||||
integer(C_INT64_T), dimension(size(bytes,kind=pLongInt)/(storage_size(0_C_INT64_T,pLongInt)/8_pLongInt)) :: &
|
||||
bytes_to_C_INT64_T
|
||||
|
||||
bytes_to_C_INT64_T = transfer(bytes,bytes_to_C_INT64_T,size(bytes_to_C_INT64_T))
|
||||
|
||||
end function bytes_to_C_INT64_T
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Check correctness of some prec functions.
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine selfTest
|
||||
|
||||
integer, allocatable, dimension(:) :: realloc_lhs_test
|
||||
real(pReal), dimension(2) :: r
|
||||
real(pReal), dimension(1) :: f
|
||||
integer(pInt), dimension(1) :: i
|
||||
real(pReal), dimension(2) :: r
|
||||
external :: &
|
||||
quit
|
||||
|
||||
realloc_lhs_test = [1,2]
|
||||
if (any(realloc_lhs_test/=[1,2])) call quit(9000)
|
||||
|
||||
call random_number(r)
|
||||
r = r/minval(r)
|
||||
if(.not. all(dEq(r,r+PREAL_EPSILON))) call quit(9000)
|
||||
if(dEq(r(1),r(2)) .and. dNeq(r(1),r(2))) call quit(9000)
|
||||
if(.not. all(dEq0(r-(r+PREAL_MIN)))) call quit(9000)
|
||||
|
||||
realloc_lhs_test = [1,2]
|
||||
if (any(realloc_lhs_test/=[1,2])) call quit(9000)
|
||||
! https://www.binaryconvert.com
|
||||
! https://www.rapidtables.com/convert/number/binary-to-decimal.html
|
||||
f = real(bytes_to_C_FLOAT(int([-65,+11,-102,+75],C_SIGNED_CHAR)),pReal)
|
||||
if(dNeq(f(1),20191102.0_pReal,0.0_pReal)) call quit(9000)
|
||||
|
||||
f = real(bytes_to_C_DOUBLE(int([0,0,0,-32,+119,+65,+115,65],C_SIGNED_CHAR)),pReal)
|
||||
if(dNeq(f(1),20191102.0_pReal,0.0_pReal)) call quit(9000)
|
||||
|
||||
i = int(bytes_to_C_INT32_T(int([+126,+23,+52,+1],C_SIGNED_CHAR)),pInt)
|
||||
if(i(1) /= 20191102_pInt) call quit(9000)
|
||||
|
||||
i = int(bytes_to_C_INT64_T(int([+126,+23,+52,+1,0,0,0,0],C_SIGNED_CHAR)),pInt)
|
||||
if(i(1) /= 20191102_pInt) call quit(9000)
|
||||
|
||||
end subroutine selfTest
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ module rotations
|
|||
contains
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief doing self test
|
||||
!> @brief do self test
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
subroutine rotations_init
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
!--------------------------------------------------------------------------------------------------
|
||||
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
||||
!> @brief Inflate zlib compressed data
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
module zlib
|
||||
use prec
|
||||
|
||||
implicit none
|
||||
private
|
||||
|
||||
public :: &
|
||||
zlib_inflate
|
||||
|
||||
interface
|
||||
|
||||
subroutine inflate_C(s_deflated,s_inflated,deflated,inflated) bind(C)
|
||||
use, intrinsic :: ISO_C_Binding, only: &
|
||||
C_SIGNED_CHAR, C_INT64_T
|
||||
|
||||
integer(C_INT64_T), intent(in) :: s_deflated,s_inflated
|
||||
integer(C_SIGNED_CHAR), dimension(s_deflated), intent(in) :: deflated
|
||||
integer(C_SIGNED_CHAR), dimension(s_inflated), intent(out) :: inflated
|
||||
|
||||
end subroutine inflate_C
|
||||
|
||||
end interface
|
||||
|
||||
contains
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Inflate byte-wise representation
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
function zlib_inflate(deflated,size_inflated)
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(:), intent(in) :: deflated
|
||||
integer(pLongInt), intent(in) :: size_inflated
|
||||
|
||||
integer(C_SIGNED_CHAR), dimension(size_inflated) :: zlib_inflate
|
||||
|
||||
call inflate_C(size(deflated,kind=C_INT64_T),int(size_inflated,C_INT64_T),deflated,zlib_inflate)
|
||||
|
||||
end function zlib_inflate
|
||||
|
||||
end module zlib
|
Loading…
Reference in New Issue