|
| 1 | +program test_savetxt_qp |
| 2 | +use iso_fortran_env, only: qp=>real128 |
| 3 | +use stdlib_experimental_io, only: loadtxt, savetxt |
| 4 | +use stdlib_experimental_error, only: assert |
| 5 | +implicit none |
| 6 | + |
| 7 | +character(:), allocatable :: outpath |
| 8 | + |
| 9 | +outpath = get_outpath() // "/tmp_qp.dat" |
| 10 | + |
| 11 | +call test_qp(outpath) |
| 12 | + |
| 13 | +contains |
| 14 | + |
| 15 | + function get_outpath() result(outpath) |
| 16 | + integer :: ierr |
| 17 | + character(256) :: argv |
| 18 | + character(:), allocatable :: outpath |
| 19 | + |
| 20 | + call get_command_argument(1, argv, status=ierr) |
| 21 | + if (ierr==0) then |
| 22 | + outpath = trim(argv) |
| 23 | + else |
| 24 | + outpath = '.' |
| 25 | + endif |
| 26 | + end function get_outpath |
| 27 | + |
| 28 | + subroutine test_qp(outpath) |
| 29 | + character(*), intent(in) :: outpath |
| 30 | + real(qp) :: d(3, 2), e(2, 3) |
| 31 | + real(qp), allocatable :: d2(:, :) |
| 32 | + d = reshape([1, 2, 3, 4, 5, 6], [3, 2]) |
| 33 | + call savetxt(outpath, d) |
| 34 | + call loadtxt(outpath, d2) |
| 35 | + call assert(all(shape(d2) == [3, 2])) |
| 36 | + call assert(all(abs(d-d2) < epsilon(1._qp))) |
| 37 | + |
| 38 | + e = reshape([1, 2, 3, 4, 5, 6], [2, 3]) |
| 39 | + call savetxt(outpath, e) |
| 40 | + call loadtxt(outpath, d2) |
| 41 | + call assert(all(shape(d2) == [2, 3])) |
| 42 | + call assert(all(abs(e-d2) < epsilon(1._qp))) |
| 43 | + end subroutine |
| 44 | + |
| 45 | +end program |
0 commit comments