@@ -48,6 +48,7 @@ module jf_test_9_mod
48
48
use , intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp = > real64
49
49
50
50
implicit none
51
+
51
52
! small file - 0.0 sec : http://www.json-generator.com
52
53
! character(len=*),parameter :: filename = 'random1.json'
53
54
@@ -57,9 +58,13 @@ module jf_test_9_mod
57
58
! 13 MB - 7.6 sec : http://mtgjson.com
58
59
! character(len=*),parameter :: filename = 'AllSets.json'
59
60
61
+ ! ....WARNING: this file is causing some error.... (bug in code?)
60
62
! 100 MB - takes forever... : https://github.com/seductiveapps/largeJSON
61
63
! character(len=*),parameter :: filename = '100mb.json'
62
64
65
+ ! small file that contains unicode characters:
66
+ ! character(len=*),parameter :: filename = 'hello-world-ucs4.json' !!!! test !!!!
67
+
63
68
character (len=* ),parameter :: dir = ' ../files/inputs/' ! working directory
64
69
65
70
contains
@@ -74,6 +79,7 @@ subroutine test_9(error_cnt)
74
79
75
80
type (json_file) :: f
76
81
real :: tstart, tend
82
+ character (len= :),allocatable :: str
77
83
78
84
error_cnt = 0
79
85
call json_initialize()
@@ -84,7 +90,7 @@ subroutine test_9(error_cnt)
84
90
85
91
write (error_unit,' (A)' ) ' '
86
92
write (error_unit,' (A)' ) ' ================================='
87
- write (error_unit,' (A)' ) ' EXAMPLE 9 '
93
+ write (error_unit,' (A)' ) ' EXAMPLE 9a '
88
94
write (error_unit,' (A)' ) ' ================================='
89
95
90
96
write (error_unit,' (A)' ) ' '
@@ -108,8 +114,75 @@ subroutine test_9(error_cnt)
108
114
! cleanup:
109
115
call f% destroy()
110
116
117
+ write (error_unit,' (A)' ) ' '
118
+ write (error_unit,' (A)' ) ' ================================='
119
+ write (error_unit,' (A)' ) ' EXAMPLE 9b '
120
+ write (error_unit,' (A)' ) ' ================================='
121
+
122
+ write (error_unit,' (A)' ) ' '
123
+ write (error_unit,' (A)' ) ' Load a file using json_file%load_from_string'
124
+ write (error_unit,' (A)' ) ' '
125
+ write (error_unit,' (A)' ) ' Loading file: ' // trim (filename)
126
+
127
+ call cpu_time(tstart)
128
+ call read_file(dir// filename, str)
129
+
130
+ if (allocated (str)) then
131
+ call f% load_from_string(str)
132
+ call cpu_time(tend)
133
+ write (error_unit,' (A,1X,F10.3,1X,A)' ) ' Elapsed time to parse: ' ,tend- tstart,' sec'
134
+ if (json_failed()) then
135
+ call json_print_error_message(error_unit)
136
+ error_cnt = error_cnt + 1
137
+ else
138
+ write (error_unit,' (A)' ) ' File successfully read'
139
+ end if
140
+ write (error_unit,' (A)' ) ' '
141
+ ! write(error_unit,'(A)') str !!!! test !!!!
142
+ ! write(error_unit,'(A)') '' !!!! test !!!!
143
+ else
144
+ write (error_unit,' (A)' ) ' Error loading file'
145
+ end if
146
+
147
+ ! cleanup:
148
+ call f% destroy()
149
+
111
150
end subroutine test_9
112
151
152
+ subroutine read_file (filename ,str )
153
+ !
154
+ ! Reads the contents of the file into the allocatable string str.
155
+ ! If there are any problems, str will be returned unallocated.
156
+ !
157
+
158
+ ! Will this routine work if the file contains unicode characters??
159
+
160
+ implicit none
161
+
162
+ character (len=* ),intent (in ) :: filename
163
+ character (len= :),allocatable ,intent (out ) :: str
164
+
165
+ integer :: iunit,istat,filesize
166
+
167
+ open ( newunit = iunit,&
168
+ file = filename,&
169
+ status = ' OLD' ,&
170
+ form = ' UNFORMATTED' ,&
171
+ access = ' STREAM' ,&
172
+ iostat = istat )
173
+
174
+ if (istat== 0 ) then
175
+ inquire (file= filename, size= filesize)
176
+ if (filesize> 0 ) then
177
+ allocate ( character (len= filesize) :: str )
178
+ read (iunit,pos= 1 ,iostat= istat) str
179
+ if (istat/= 0 ) deallocate (str)
180
+ close (iunit, iostat= istat)
181
+ end if
182
+ end if
183
+
184
+ end subroutine read_file
185
+
113
186
end module jf_test_9_mod
114
187
115
188
program jf_test_9
0 commit comments