fortran matlab python函數(shù)和讀寫文件
函數(shù)
fortran里的函數(shù)是輸入,輸出都在一個(gè)括號(hào)里,比如:
subroutine f(x_in,y_in,x_out,y_out)
?end
調(diào)用時(shí)直接寫:
call f(x_in,y_in,x_out,y_out)
matlab里函數(shù)是:
function [x_out,y_out] = f(x_in,y_in)
end
調(diào)用時(shí)是:
[x_out,y_out] = f(x_in,y_in);
Python里函數(shù)是:
def printfun( str ):
? ?"打印任何傳入的字符串"
? ?print str
? ?return [str]
?
調(diào)用函數(shù)
printfun("我要調(diào)用用戶自定義函數(shù)!")
讀寫文件
fortran
open(1,file='in/input.dat',status='old')
read(1,'(a)')? letter
read(1,*)? m,n,o,p,q
open(1,file='out/output.dat',status='old')
write(1,'(a)')? letter
write(1,*)? m,n,o,p,q
matlab
fid=fopen('./input.dat');
str = fgetl(fid);?
fclose(fid);
?python
f = open("input.txt")
lines = f.readline()
f.close()
標(biāo)簽: