3
3
implicit none
4
4
5
5
integer , parameter :: message_len = 128
6
- contains
7
6
8
- subroutine download_and_uncompress ()
9
- character (len=* ), parameter :: download_mechanism = ' curl -LO '
10
- character (len=* ), parameter :: base_url= ' https://github.com/modern-fortran/neural-fortran/files/8498876/'
11
- character (len=* ), parameter :: download_filename = ' mnist.tar.gz'
12
- character (len=* ), parameter :: download_command = download_mechanism // base_url // download_filename
13
- character (len=* ), parameter :: uncompress_file= ' tar xvzf ' // download_filename
14
- character (len= message_len) :: command_message
15
- character (len= :), allocatable :: error_message
16
- integer exit_status, command_status
17
- exit_status= 0
18
- call execute_command_line(command= download_command, &
19
- wait= .true. , exitstat= exit_status, cmdstat= command_status, cmdmsg= command_message)
20
- if (any ([exit_status, command_status]/= 0 )) then
21
- error_message = ' command "' // download_command // ' " failed'
22
- if (command_status/= 0 ) error_message = error_message // " with message " // trim (command_message)
23
- error stop error_message
24
- end if
25
- call execute_command_line(command= uncompress_file , &
26
- wait= .true. , exitstat= exit_status, cmdstat= command_status, cmdmsg= command_message)
27
- if (any ([exit_status, command_status]/= 0 )) then
28
- error_message = ' command "' // uncompress_file // ' " failed'
29
- if (command_status/= 0 ) error_message = error_message // " with message " // trim (command_message)
30
- error stop error_message
31
- end if
32
- end subroutine
7
+ contains
33
8
34
9
module subroutine read_binary_file_1d (filename , dtype , nrec , array )
35
10
character (len=* ), intent (in ) :: filename
36
11
integer (ik), intent (in ) :: dtype, nrec
37
12
real (rk), allocatable , intent (in out ) :: array(:)
38
13
integer (ik) :: fileunit
39
- character (len= message_len) io_message, command_message
40
- integer io_status
41
- io_status= 0
42
- open (newunit= fileunit, file= filename, access= ' direct' ,&
43
- action= ' read' , recl= dtype * nrec, status= ' old' , iostat= io_status)
44
- if (io_status/= 0 ) then
45
- call download_and_uncompress
46
- open (newunit= fileunit, file= filename, access= ' direct' ,&
47
- action= ' read' , recl= dtype * nrec, status= ' old' , iostat= io_status, iomsg= io_message)
48
- if (io_status/= 0 ) error stop trim (io_message)
49
- end if
14
+ character (len= message_len) :: io_message
15
+ integer :: io_status
16
+ io_status = 0
17
+ open (newunit= fileunit, file= filename, access= ' direct' , action= ' read' , &
18
+ recl= dtype * nrec, status= ' old' , iostat= io_status, iomsg= io_message)
19
+ if (io_status /= 0 ) error stop trim (io_message)
50
20
allocate (array(nrec))
51
21
read (fileunit, rec= 1 ) array
52
22
close (fileunit)
@@ -57,19 +27,13 @@ module subroutine read_binary_file_2d(filename, dtype, dsize, nrec, array)
57
27
integer (ik), intent (in ) :: dtype, dsize, nrec
58
28
real (rk), allocatable , intent (in out ) :: array(:,:)
59
29
integer (ik) :: fileunit, i
60
- character (len= message_len) io_message, command_message
61
- integer io_status
62
- open (newunit= fileunit, file= filename, access= ' direct' ,&
63
- action= ' read' , recl= dtype * nrec, status= ' old' , iostat= io_status)
64
- if (io_status/= 0 ) then
65
- call download_and_uncompress
66
- open (newunit= fileunit, file= filename, access= ' direct' ,&
67
- action= ' read' , recl= dtype * nrec, status= ' old' , iostat= io_status, iomsg= io_message)
68
- if (io_status/= 0 ) error stop trim (io_message)
69
- end if
30
+ character (len= message_len) :: io_message
31
+ integer :: io_status
32
+ io_status = 0
33
+ open (newunit= fileunit, file= filename, access= ' direct' , action= ' read' , &
34
+ recl= dtype * dsize, status= ' old' , iostat= io_status, iomsg= io_message)
35
+ if (io_status /= 0 ) error stop trim (io_message)
70
36
allocate (array(dsize, nrec))
71
- open (newunit= fileunit, file= filename, access= ' direct' ,&
72
- action= ' read' , recl= dtype * dsize, status= ' old' )
73
37
do i = 1 , nrec
74
38
read (fileunit, rec= i) array(:,i)
75
39
end do
0 commit comments