Skip to content

Commit de3c062

Browse files
Merge pull request #547 from jacobwilliams/546-example
added a new test
2 parents fff5372 + 1f01ab1 commit de3c062

File tree

4 files changed

+107
-6
lines changed

4 files changed

+107
-6
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ jobs:
2020

2121
- name: Set vars
2222
id: vars
23-
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
23+
# run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} # this is depreciated: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
24+
run: echo "name=tag::${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
2425

2526
- name: Checkout code
26-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4.1.6
2728
with:
2829
submodules: recursive
2930

3031
- name: Setup cmake
3132
if: contains( matrix.gcc_v, 9 )
32-
uses: jwlawson/actions-setup-cmake@v1.13
33+
uses: jwlawson/actions-setup-cmake@v2.0.2
3334
with:
3435
cmake-version: '3.19.x'
3536

3637
- name: Install Python
37-
uses: actions/setup-python@v4 # Use pip to install latest CMake, & FORD/Jin2For, etc.
38+
uses: actions/setup-python@v5.1.0 # Use pip to install latest CMake, & FORD/Jin2For, etc.
3839
with:
3940
python-version: ${{ matrix.python-version }}
4041

4142
- name: Setup Graphviz
42-
uses: ts-graphviz/setup-graphviz@v1
43+
uses: ts-graphviz/setup-graphviz@v2.0.2
4344

4445
- name: Install Python dependencies
4546
if: contains( matrix.os, 'ubuntu')

fpm.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,9 @@ main = "jf_test_48.F90"
256256
[[test]]
257257
name = "jf_test_49"
258258
source-dir = "src/tests"
259-
main = "jf_test_49.F90"
259+
main = "jf_test_49.F90"
260+
261+
[[test]]
262+
name = "jf_test_50"
263+
source-dir = "src/tests"
264+
main = "jf_test_50.F90"

src/tests/jf_test_50.F90

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+

visual_studio/jsonfortrantest/jsonfortrantest.vfproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@
9595
<File RelativePath="..\..\src\tests\jf_test_47.F90"/>
9696
<File RelativePath="..\..\src\tests\jf_test_48.F90"/>
9797
<File RelativePath="..\..\src\tests\jf_test_49.F90"/>
98+
<File RelativePath="..\..\src\tests\jf_test_50.F90"/>
9899
<File RelativePath=".\jsonfortrantest.f90"/></Filter></Files>
99100
<Globals/></VisualStudioProject>

0 commit comments

Comments
 (0)