36 SUBROUTINE move_file(file_source, file_dest, error)
37 #if defined(__INTEL_COMPILER)
44 CHARACTER (len=*),
INTENT(in) :: file_source
45 CHARACTER (len=*),
INTENT(in) :: file_dest
46 INTEGER,
INTENT(out) :: error
52 CHARACTER (len=*),
PARAMETER :: cmd =
'move /y '
54 CHARACTER (len=*),
PARAMETER :: cmd =
'mv -f '
59 #if defined(__GFORTRAN__) || defined(__INTEL_COMPILER)
60 error = rename(trim(file_source), trim(file_dest))
62 CALL system(cmd // trim(file_source) //
' ' // file_dest,
77 SUBROUTINE copy_file(file_source, file_dest, error)
79 #if defined(FAST_COPY)
80 use,
INTRINSIC :: iso_c_binding
86 CHARACTER (len=*),
INTENT(in) :: file_source
87 CHARACTER (len=*),
INTENT(in) :: file_dest
88 INTEGER,
INTENT(out) :: error
94 INTEGER :: max_block_size
99 CHARACTER (len=1),
ALLOCATABLE,
DIMENSION(:) :: buffer
102 INTEGER,
PARAMETER :: block_size = 1024
104 #if defined(fast_copy)
107 use,
INTRINSIC :: iso_c_binding
111 INTEGER,
PARAMETER :: length = 300
112 INTEGER (c_int) :: copy_file_c
113 CHARACTER (kind=c_char,len=1),
DIMENSION(length),
INTENT(in) ::
115 CHARACTER (kind=c_char,len=1),
DIMENSION(length),
INTENT(in) ::
122 #if defined(FAST_COPY)
123 error =
copy_file_c(trim(file_source) // c_null_char,
124 & trim(file_dest) // c_null_char)
128 INQUIRE (file=file_source, exist=l_exists, opened=l_opened)
129 CALL getfilesize(file_source, file_size)
131 IF (.not.l_exists)
THEN
132 WRITE (*,1001) trim(file_source)
135 ELSE IF (l_opened)
THEN
136 WRITE (*,1000) trim(file_source)
142 INQUIRE (file=file_dest, exist=l_exists, opened=l_opened)
144 WRITE (*,1000) trim(file_dest)
154 max_block_size = min(block_size, file_size)
156 CALL safe_open(io_source, error, file_source,
'old',
157 &
'unformatted', record_in=max_block_size,
158 & access_in=
'direct')
159 IF (error .ne. 0)
WRITE (*,1002) trim(file_source)
161 CALL safe_open(io_dest, error, file_dest,
'new',
'unformatted',
162 & record_in=max_block_size, access_in=
'direct')
163 IF (error .ne. 0)
WRITE (*,1003) trim(file_dest)
165 ALLOCATE (buffer(max_block_size), stat=error)
166 IF (error .ne. 0)
WRITE (*,1004)
169 n_rec = max(1, file_size/max_block_size)
171 READ (io_source, rec=i_rec) buffer
172 WRITE (io_dest, rec=i_rec) buffer
180 IF (file_size - (i_rec - 1)*max_block_size .gt. 0)
THEN
181 OPEN (unit=io_source, file=file_source, status=
'old',
182 & access=
'direct', recl=1)
183 OPEN (unit=io_dest, file=file_dest, status=
'old',
184 & access=
'direct', recl=1)
186 DO i_rec = i_rec, file_size
187 READ (io_source, rec=i_rec) buffer(1)
188 WRITE (io_dest, rec=i_rec) buffer(1)
197 1000
FORMAT(
'ERROR: File ',a,
' is already opened.')
198 1001
FORMAT(
'ERROR: File ',a,
' does not exist.')
199 1002
FORMAT(
'ERROR: Fail to open ',a,
'.')
200 1003
FORMAT(
'ERROR: Fail to create ',a,
'.')
201 1004
FORMAT(
'ERROR: Fail to allocate copy buffer.')
215 #if defined(__INTEL_COMPILER)
223 CHARACTER (len=*),
INTENT(in) :: file_source
224 INTEGER,
INTENT(out) :: error
230 #if defined(__GFORTRAN__) || defined(__INTEL_COMPILER)
231 error = unlink(file_source)
234 CALL safe_open(io_unit, error, file_source,
'old',
'formatted')
235 CLOSE (io_unit, iostat=error, status=
'delete')
253 CHARACTER (len=*),
INTENT(in) :: directory_source
254 INTEGER,
INTENT(out) :: error
258 CHARACTER (len=*),
PARAMETER :: cmd =
'mkdir '
260 CHARACTER (len=*),
PARAMETER :: cmd =
'mkdir -p '
265 CALL system(cmd // trim(directory_source), error)
282 CHARACTER (len=*),
INTENT(in) :: directory_source
283 INTEGER,
INTENT(out) :: error
287 CHARACTER (len=*),
PARAMETER :: cmd =
'rmdir /Q /S '
289 CHARACTER (len=*),
PARAMETER :: cmd =
'rm -rf '
294 CALL system(cmd // trim(directory_source), error)
314 CHARACTER (len=*),
INTENT(in) :: path
318 IF (path .eq.
'')
THEN
335 & (index(path,
':\') .eq. 0) .or.
336 & (path(1:1) .eq.
'\')
340 & (path(1:1) .eq.
'~')
359 CHARACTER (len=*),
INTENT(in) :: file
364 & file(1:(index(trim(file),
'\', back = .true.) - 1))
367 & file(1:(index(trim(file),
'/', back = .true.) - 1))
387 CHARACTER (len=*),
INTENT(in) :: path
388 CHARACTER (len=*),
INTENT(in) :: name
391 IF (trim(path) .eq.
'')
THEN
414 #if defined(__INTEL_COMPILER)
421 CHARACTER (len=*),
INTENT(in) :: path
422 INTEGER,
INTENT(out) :: error
425 error =
chdir(trim(path))