Fortran 作为科学计算常用语言,自然免不了各种文件读写的操作,以下是一个简单的模板
参见 gist bdb32fffcd08b9ab21ea
:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program gaugeselect | |
implicit none | |
character(len=80):: filename | |
character(len=80):: arg1 ,arg2 | |
character(len=80):: buff | |
logical:: flag=.false. | |
!================================================================! | |
call getarg(1,arg1) | |
call getarg(2,arg2) | |
if ( len_trim(arg1)==0 )then | |
print *,"please specify the argument of running file!!" | |
print *," usage: ./gaugeselect filename " | |
stop | |
else | |
filename=trim(arg1) | |
inquire(file=trim(filename),exist=flag) | |
if(flag)then | |
open(5,file=trim(filename)) | |
do while(.true.) | |
read(5,*,end=100)buff | |
enddo | |
100 close(5) | |
print *,'file: ',trim(filename), " processed" | |
else | |
print *,"oops........" | |
print *,'can NOT open file: ',trim(filename) | |
print *," " | |
endif | |
endif | |
end program gaugeselect |
或者,直接参见下面:
|
|