|
| 1 | +!***************************************************************************************** |
| 2 | +!> |
| 3 | +! Module for the 50th unit test. See Issue #546. |
| 4 | + |
| 5 | +module jf_test_50_mod |
| 6 | + |
| 7 | + use json_module, wp => json_RK, IK => json_IK, LK => json_LK, CK => json_CK |
| 8 | + use, intrinsic :: iso_fortran_env , only: error_unit, output_unit |
| 9 | + |
| 10 | + implicit none |
| 11 | + |
| 12 | + private |
| 13 | + public :: test_50 |
| 14 | + |
| 15 | +contains |
| 16 | + |
| 17 | + subroutine test_50(error_cnt) |
| 18 | + |
| 19 | + !! 50th unit test. see Issue #546 |
| 20 | + |
| 21 | + integer,intent(out) :: error_cnt |
| 22 | + |
| 23 | + real(wp),dimension(6,6),parameter :: pcir = reshape(& |
| 24 | + [0.00_wp, 0.35_wp, 0.15_wp, 0.00_wp, 0.50_wp, 0.00_wp, & ! these are the columns |
| 25 | + 1.00_wp, 0.00_wp, 0.00_wp, 0.25_wp, 0.00_wp, 0.00_wp, & |
| 26 | + 0.00_wp, 0.00_wp, 0.00_wp, 1.00_wp, 0.00_wp, 0.00_wp, & |
| 27 | + 0.00_wp, 0.90_wp, 0.55_wp, 0.00_wp, 0.00_wp, 0.90_wp, & |
| 28 | + 0.00_wp, 0.00_wp, 0.30_wp, 0.00_wp, 0.00_wp, 0.70_wp, & |
| 29 | + 0.00_wp, 0.00_wp, 0.00_wp, 1.10_wp, 0.50_wp, 0.00_wp], [6,6]) |
| 30 | + |
| 31 | + type(json_core) :: json |
| 32 | + type(json_value),pointer :: p |
| 33 | + |
| 34 | + call json%initialize(compress_vectors = .true.) ! so it will print each col on one line |
| 35 | + |
| 36 | + call json%create_object(p,'') !create the root |
| 37 | + call json_value_add_real_vec_2d(json, p, CK_'Pcir', pcir, by_col=.true.) |
| 38 | + call json%print(p) |
| 39 | + |
| 40 | + error_cnt = 0 |
| 41 | + |
| 42 | + end subroutine test_50 |
| 43 | + |
| 44 | + subroutine json_value_add_real_vec_2d(json, p, name, val, by_col) |
| 45 | + |
| 46 | + implicit none |
| 47 | + |
| 48 | + class(json_core),intent(inout) :: json |
| 49 | + type(json_value),pointer :: p |
| 50 | + character(kind=CK,len=*),intent(in) :: name !! name of the variable |
| 51 | + real(wp),dimension(:,:),intent(in) :: val !! value |
| 52 | + logical,intent(in) :: by_col !! if true, write by column. if false, write by row |
| 53 | + |
| 54 | + type(json_value),pointer :: var |
| 55 | + integer(IK) :: i !! counter |
| 56 | + |
| 57 | + !create a variable as an array: |
| 58 | + call json%create_array(var,name) |
| 59 | + |
| 60 | + !populate as an array of arrays: |
| 61 | + if (by_col) then |
| 62 | + do i=1,size(val,2) |
| 63 | + call json%add(var, CK_'', val(:,i)) |
| 64 | + end do |
| 65 | + else |
| 66 | + do i=1,size(val,1) |
| 67 | + call json%add(var, CK_'', val(i,:)) |
| 68 | + end do |
| 69 | + end if |
| 70 | + |
| 71 | + !add it: |
| 72 | + call json%add(p, var) |
| 73 | + |
| 74 | + end subroutine json_value_add_real_vec_2d |
| 75 | + |
| 76 | +end module jf_test_50_mod |
| 77 | +!***************************************************************************************** |
| 78 | + |
| 79 | +!***************************************************************************************** |
| 80 | +#ifndef INTEGRATED_TESTS |
| 81 | +program jf_test_50 |
| 82 | + |
| 83 | + use jf_test_50_mod , only: test_50 |
| 84 | + |
| 85 | + implicit none |
| 86 | + integer :: n_errors |
| 87 | + |
| 88 | + call test_50(n_errors) |
| 89 | + if (n_errors /= 0) stop 1 |
| 90 | + |
| 91 | +end program jf_test_50 |
| 92 | +#endif |
| 93 | +!***************************************************************************************** |
| 94 | + |
0 commit comments