How to copy a file in Fortran 90?
11,393
You can read/write the file through a stream in Fortran 2003, but in Fortran 90/95 I think this would work to copy an arbitrary file (extremely inefficient though!!)
OPEN(UNIT=ISRC, FILE='', ACCESS='DIRECT', STATUS='OLD', ACTION='READ', IOSTAT=IERR, RECL=1)
OPEN(UNIT=IDST, FILE='', ACCESS='DIRECT', STATUS='REPLACE', ACTION='WRITE', IOSTATE=IERR, RE)
IREC = 1
DO
READ(UNIT=ISRC, REC=IREC, IOSTAT=IERR) CHAR
IF (IERR.NE.0) EXIT
WRITE(UNIT=IDST, REC=I) CHAR
IREC = IREC + 1
END DO
Of course, if it was a fortran generated file, you could use that information to make it more efficient.
On a personal note: if you need invoke system calls from inside fortran, what are you doing? Isn't it better to use some other language that is better suited for the task?
Author by
Stefano Borini
Updated on June 23, 2022Comments
-
Stefano Borini almost 2 years
How can I copy a file in fortran 90 in a portable, cross plaform way ?