JSON/jf_test_9 [ Unittest ]

[ Top ] [ Unittest ]

NAME

jf_test_9

DESCRIPTION

Ninth unit test.

AUTHOR

Jacob Williams : 3/2/3015

LICENSE

JSON-FORTRAN: A Fortran 2008 JSON API

https://github.com/jacobwilliams/json-fortran

Copyright (c) 2014, Jacob Williams

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

SOURCE

 45 module jf_test_9_mod
 46 
 47     use json_module
 48     use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
 49 
 50     implicit none
 51     !small file - 0.0 sec : http://www.json-generator.com
 52     !character(len=*),parameter :: filename = 'random1.json'
 53 
 54     !7 MB - 5.4 sec : http://www.json-generator.com
 55     character(len=*),parameter :: filename = 'big.json'
 56 
 57     !13 MB - 7.6 sec : http://mtgjson.com
 58     !character(len=*),parameter :: filename = 'AllSets.json'
 59 
 60     !100 MB - takes forever... : https://github.com/seductiveapps/largeJSON
 61     !character(len=*),parameter :: filename = '100mb.json'
 62 
 63     character(len=*),parameter :: dir = '../files/inputs/' !working directory
 64 
 65 contains
 66 
 67     subroutine test_9(error_cnt)
 68 
 69 !   Open a random JSON file generated by http://www.json-generator.com
 70 
 71     implicit none
 72 
 73     integer,intent(out) :: error_cnt
 74 
 75     type(json_file) :: f
 76     real :: tstart, tend
 77 
 78     error_cnt = 0
 79     call json_initialize()
 80     if (json_failed()) then
 81         call json_print_error_message(error_unit)
 82         error_cnt = error_cnt + 1
 83     end if
 84 
 85     write(error_unit,'(A)') ''
 86     write(error_unit,'(A)') '================================='
 87     write(error_unit,'(A)') '   EXAMPLE 9 '
 88     write(error_unit,'(A)') '================================='
 89 
 90     write(error_unit,'(A)') ''
 91     write(error_unit,'(A)') '  Load a file using json_file%load_file'
 92     write(error_unit,'(A)') ''
 93     write(error_unit,'(A)') 'Loading file: '//trim(filename)
 94 
 95     call cpu_time(tstart)
 96     call f%load_file(dir//filename)
 97     call cpu_time(tend)
 98     write(error_unit,'(A,1X,F10.3,1X,A)') 'Elapsed time: ',tend-tstart,' sec'
 99 
100     if (json_failed()) then
101         call json_print_error_message(error_unit)
102         error_cnt = error_cnt + 1
103     else
104         write(error_unit,'(A)') 'File successfully read'
105     end if
106     write(error_unit,'(A)') ''
107 
108     !cleanup:
109     call f%destroy()
110 
111     end subroutine test_9
112 
113 end module jf_test_9_mod
114 
115 program jf_test_9
116     use jf_test_9_mod , only: test_9
117     implicit none
118     integer :: n_errors
119     n_errors = 0
120     call test_9(n_errors)
121     if (n_errors /= 0) stop 1
122 end program jf_test_9