@@ -1146,6 +1146,9 @@ end subroutine array_callback_func
1146
1146
integer (IK),parameter :: chunk_size = 100 ! allocate chunks of this size
1147
1147
integer (IK) :: ipos = 1 ! next character to read
1148
1148
1149
+ ! unit number to cause stuff to be output to strings rather than files
1150
+ ! See 9.5.6.12 in the F2003/08 standard
1151
+ integer (IK),parameter :: unit2str = - 1
1149
1152
contains
1150
1153
! *****************************************************************************************
1151
1154
@@ -1386,15 +1389,15 @@ subroutine json_file_print_1(me, iunit)
1386
1389
implicit none
1387
1390
1388
1391
class(json_file),intent (inout ) :: me
1389
- integer (IK),intent (in ) :: iunit ! must be non-zero
1392
+ integer (IK),intent (in ) :: iunit ! must not be -1
1390
1393
1391
1394
integer (IK) :: i
1392
1395
character (kind= CK,len= :),allocatable :: dummy
1393
1396
1394
- if (iunit/= 0 ) then
1397
+ if (iunit/= unit2str ) then
1395
1398
i = iunit
1396
1399
else
1397
- call throw_exception(' Error in json_file_print_1: iunit must be nonzero .' )
1400
+ call throw_exception(' Error in json_file_print_1: iunit must not be -1 .' )
1398
1401
return
1399
1402
end if
1400
1403
@@ -4217,7 +4220,7 @@ subroutine json_value_to_string(me,str)
4217
4220
character (kind= CK,len= :),intent (out ),allocatable :: str
4218
4221
4219
4222
str = ' '
4220
- call json_value_print(me, iunit= 0 , str= str, indent= 1 , colon= .true. )
4223
+ call json_value_print(me, iunit= unit2str , str= str, indent= 1 , colon= .true. )
4221
4224
4222
4225
end subroutine json_value_to_string
4223
4226
! *****************************************************************************************
@@ -4232,7 +4235,7 @@ end subroutine json_value_to_string
4232
4235
! Print the JSON structure to a file.
4233
4236
!
4234
4237
! INPUT
4235
- ! * iunit is the nonzero file unit (the file must already have been opened).
4238
+ ! * iunit is the file unit (the file must already have been opened, can't be -1 ).
4236
4239
!
4237
4240
! AUTHOR
4238
4241
! Jacob Williams, 6/20/2014
@@ -4244,13 +4247,13 @@ subroutine json_print_1(me,iunit)
4244
4247
implicit none
4245
4248
4246
4249
type (json_value),pointer ,intent (in ) :: me
4247
- integer (IK),intent (in ) :: iunit ! must be non-zero
4250
+ integer (IK),intent (in ) :: iunit ! must not be -1
4248
4251
character (kind= CK,len= :),allocatable :: dummy
4249
4252
4250
- if (iunit/= 0 ) then
4253
+ if (iunit/= unit2str ) then
4251
4254
call json_value_print(me,iunit,str= dummy, indent= 1 , colon= .true. )
4252
4255
else
4253
- call throw_exception(' Error in json_print: iunit must be nonzero .' )
4256
+ call throw_exception(' Error in json_print: iunit must not be -1 .' )
4254
4257
end if
4255
4258
4256
4259
end subroutine json_print_1
@@ -4321,7 +4324,7 @@ recursive subroutine json_value_print(me,iunit,str,indent,need_comma,colon,is_ar
4321
4324
logical (LK),intent (in ),optional :: need_comma ! if it needs a comma after it
4322
4325
logical (LK),intent (in ),optional :: colon ! if the colon was just written
4323
4326
character (kind= CK,len= :),intent (inout ),allocatable :: str
4324
- ! if iunit==0, then the structure is
4327
+ ! if iunit==unit2str (-1) then the structure is
4325
4328
! printed to this string rather than
4326
4329
! a file. This mode is used by
4327
4330
! json_value_to_string.
@@ -4337,7 +4340,7 @@ recursive subroutine json_value_print(me,iunit,str,indent,need_comma,colon,is_ar
4337
4340
if (.not. exception_thrown) then
4338
4341
4339
4342
! whether to write a string or a file (one or the other):
4340
- write_string = (iunit== 0 )
4343
+ write_string = (iunit== unit2str )
4341
4344
write_file = .not. write_string
4342
4345
4343
4346
! if the comma will be printed after the value
0 commit comments