|
| 1 | +!***************************************************************************************** |
| 2 | +!> author: Jacob Williams |
| 3 | +! date: 10/20/2016 |
| 4 | +! |
| 5 | +! Module for the 21st unit test. |
| 6 | +! This one is testing the real format options. |
| 7 | + |
| 8 | +module jf_test_21_mod |
| 9 | + |
| 10 | + use json_module, RK => json_RK |
| 11 | + use, intrinsic :: iso_fortran_env , only: error_unit,output_unit |
| 12 | + |
| 13 | + implicit none |
| 14 | + |
| 15 | + character(len=*),parameter :: dir = '../files/' !! working directory |
| 16 | + |
| 17 | +contains |
| 18 | + |
| 19 | + subroutine test_21(error_cnt) |
| 20 | + |
| 21 | + !! Test some of the edge cases, and incorrect usages. |
| 22 | + |
| 23 | + implicit none |
| 24 | + |
| 25 | + integer,intent(out) :: error_cnt !! report number of errors to caller |
| 26 | + |
| 27 | + type(json_core) :: json |
| 28 | + type(json_file) :: jfile |
| 29 | + type(json_value),pointer :: ptr |
| 30 | + |
| 31 | + logical :: found |
| 32 | + real(kind=RK),dimension(:),allocatable :: array1,array2 |
| 33 | + |
| 34 | + write(error_unit,'(A)') '' |
| 35 | + write(error_unit,'(A)') '=================================' |
| 36 | + write(error_unit,'(A)') ' TEST 21' |
| 37 | + write(error_unit,'(A)') '=================================' |
| 38 | + write(error_unit,'(A)') '' |
| 39 | + |
| 40 | + error_cnt = 0 |
| 41 | + |
| 42 | + array1 = [sqrt(2.0_RK),sqrt(3.0_RK),sqrt(7.0_RK),& |
| 43 | + sqrt(2.0e4_RK),sqrt(3.0e5_RK),sqrt(7.0e6_RK),& |
| 44 | + huge(1.0_RK),tiny(1.0_RK),epsilon(1.0_RK)] |
| 45 | + |
| 46 | + ! write array1 into file |
| 47 | + call json % initialize(real_format='E') |
| 48 | + call json % create_object(ptr,'') |
| 49 | + call json % add(ptr,'value',array1) |
| 50 | + call json % print(ptr,dir//'test21.json') |
| 51 | + call json % destroy(ptr) |
| 52 | + |
| 53 | + ! read array2 from file |
| 54 | + call jfile % initialize(real_format='E') |
| 55 | + call jfile % load_file(dir//'test21.json') |
| 56 | + call jfile % get('value',array2,found) |
| 57 | + call jfile % destroy() |
| 58 | + |
| 59 | + ! Compare |
| 60 | + write(*,*) '' |
| 61 | + if (any(array1 /= array2)) then |
| 62 | + error_cnt = error_cnt + 1 |
| 63 | + write(*,*) 'Test failed' |
| 64 | + write(*,*) array1 == array2 |
| 65 | + else |
| 66 | + write(*,*) 'Test passed' |
| 67 | + end if |
| 68 | + write(*,'(A,1X,*(E30.18E3))') 'original array :',array1 |
| 69 | + write(*,'(A,1X,*(E30.18E3))') 'read from file :',array2 |
| 70 | + write(*,*) '' |
| 71 | + |
| 72 | + end subroutine test_21 |
| 73 | + |
| 74 | +end module jf_test_21_mod |
| 75 | +!***************************************************************************************** |
| 76 | + |
| 77 | +!***************************************************************************************** |
| 78 | +program jf_test_21 |
| 79 | + |
| 80 | + !! 21st unit test. |
| 81 | + |
| 82 | + use jf_test_21_mod, only: test_21 |
| 83 | + implicit none |
| 84 | + integer :: n_errors |
| 85 | + call test_21(n_errors) |
| 86 | + if ( n_errors /= 0) stop 1 |
| 87 | + |
| 88 | +end program jf_test_21 |
| 89 | +!***************************************************************************************** |
0 commit comments