導航:首頁 > 數據處理 > fortran怎麼添加數據

fortran怎麼添加數據

發布時間:2023-10-17 21:06:15

A. Fortran命令行啟動怎麼往主程序輸入參數

主要使用下面的三個函數實現:

第一個:

COMMAND_ARGUMENT_COUNT — Get number of command line arguments

Description:
COMMAND_ARGUMENT_COUNT returns the number of arguments passed on the command line when the containing program was invoked.
Standard:
Fortran 2003 and later
Class:
Inquiry function
Syntax:
RESULT = COMMAND_ARGUMENT_COUNT()
Arguments:
None

Return value:
The return value is an INTEGER of default kind.
Example:
program test_command_argument_count
integer :: count
count = command_argument_count()
print *, count
end program test_command_argument_count

COMMAND_ARGUMENT_COUNT — Get number of command line arguments

Description:
COMMAND_ARGUMENT_COUNT returns the number of arguments passed on the command line when the containing program was invoked.
Standard:
Fortran 2003 and later
Class:
Inquiry function
Syntax:
RESULT = COMMAND_ARGUMENT_COUNT()
Arguments:
None

Return value:
The return value is an INTEGER of default kind.
Example:
program test_command_argument_count
integer :: count
count = command_argument_count()
print *, count
end program test_command_argument_count

第二個:

GET_COMMAND_ARGUMENT — Get command line arguments

Description:
Retrieve the NUMBER-th argument that was passed on the command line when the containing program was invoked.
Standard:
Fortran 2003 and later
Class:
Subroutine
Syntax:
CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])
Arguments:
NUMBER Shall be a scalar of type INTEGER and of default kind, NUMBER \geq 0
VALUE (Optional) Shall be a scalar of type CHARACTER and of default kind.
LENGTH (Optional) Shall be a scalar of type INTEGER and of default kind.
STATUS (Optional) Shall be a scalar of type INTEGER and of default kind.

Return value:
After GET_COMMAND_ARGUMENT returns, the VALUE argument holds the
NUMBER-th command line argument. If VALUE can not hold the argument, it
is truncated to fit the length of VALUE. If there are less than NUMBER
arguments specified at the command line, VALUE will be filled with
blanks. If NUMBER = 0, VALUE is set to the name of the program (on
systems that support this feature). The LENGTH argument contains the
length of the NUMBER-th command line argument. If the argument retrieval
fails, STATUS is a positive number; if VALUE contains a truncated
command line argument, STATUS is -1; and otherwise the STATUS is zero.
Example:
PROGRAM test_get_command_argument
INTEGER :: i
CHARACTER(len=32) :: arg

i = 0
DO
CALL get_command_argument(i, arg)
IF (LEN_TRIM(arg) == 0) EXIT

WRITE (*,*) TRIM(arg)
i = i+1
END DO
END PROGRAM

GET_COMMAND_ARGUMENT — Get command line arguments

Description:
Retrieve the NUMBER-th argument that was passed on the command line when the containing program was invoked.
Standard:
Fortran 2003 and later
Class:
Subroutine
Syntax:
CALL GET_COMMAND_ARGUMENT(NUMBER [, VALUE, LENGTH, STATUS])
Arguments:
NUMBER Shall be a scalar of type INTEGER and of default kind, NUMBER \geq 0
VALUE (Optional) Shall be a scalar of type CHARACTER and of default kind.
LENGTH (Optional) Shall be a scalar of type INTEGER and of default kind.
STATUS (Optional) Shall be a scalar of type INTEGER and of default kind.

Return value:
After GET_COMMAND_ARGUMENT returns, the VALUE argument holds the
NUMBER-th command line argument. If VALUE can not hold the argument, it
is truncated to fit the length of VALUE. If there are less than NUMBER
arguments specified at the command line, VALUE will be filled with
blanks. If NUMBER = 0, VALUE is set to the name of the program (on
systems that support this feature). The LENGTH argument contains the
length of the NUMBER-th command line argument. If the argument retrieval
fails, STATUS is a positive number; if VALUE contains a truncated
command line argument, STATUS is -1; and otherwise the STATUS is zero.
Example:
PROGRAM test_get_command_argument
INTEGER :: i
CHARACTER(len=32) :: arg

i = 0
DO
CALL get_command_argument(i, arg)
IF (LEN_TRIM(arg) == 0) EXIT

WRITE (*,*) TRIM(arg)
i = i+1
END DO
END PROGRAM
第三個:

GET_COMMAND — Get the entire command line

Description:
Retrieve the entire command line that was used to invoke the program.
Standard:
Fortran 2003 and later
Class:
Subroutine
Syntax:
CALL GET_COMMAND([COMMAND, LENGTH, STATUS])
Arguments:
COMMAND (Optional) shall be of type CHARACTER and of default kind.
LENGTH (Optional) Shall be of type INTEGER and of default kind.
STATUS (Optional) Shall be of type INTEGER and of default kind.

Return value:
If COMMAND is present, stores the entire command line that was used to
invoke the program in COMMAND. If LENGTH is present, it is assigned the
length of the command line. If STATUS is present, it is assigned 0 upon
success of the command, -1 if COMMAND is too short to store the command
line, or a positive value in case of an error.
Example:
PROGRAM test_get_command
CHARACTER(len=255) :: cmd
CALL get_command(cmd)
WRITE (*,*) TRIM(cmd)
END PROGRAM

GET_COMMAND — Get the entire command line

Description:
Retrieve the entire command line that was used to invoke the program.
Standard:
Fortran 2003 and later
Class:
Subroutine
Syntax:
CALL GET_COMMAND([COMMAND, LENGTH, STATUS])
Arguments:
COMMAND (Optional) shall be of type CHARACTER and of default kind.
LENGTH (Optional) Shall be of type INTEGER and of default kind.
STATUS (Optional) Shall be of type INTEGER and of default kind.

Return value:
If COMMAND is present, stores the entire command line that was used to
invoke the program in COMMAND. If LENGTH is present, it is assigned the
length of the command line. If STATUS is present, it is assigned 0 upon
success of the command, -1 if COMMAND is too short to store the command
line, or a positive value in case of an error.
Example:
PROGRAM test_get_command
CHARACTER(len=255) :: cmd
CALL get_command(cmd)
WRITE (*,*) TRIM(cmd)
END PROGRAM

最近在Fortran的數據傳遞設計上碰到了問題。現在略歸納下子程序間參數傳遞的實現辦法。
首先,Fortran subroutine
獨立地擁有屬於自己的變數申明。有說:Fortran的變數作用域只有兩類:一是全局作用域,二是子程序作用域,並且子程序內部不存在嵌套作用域。最後一
點很重要喲。舉例:在一個子程序里申明的變數,不能在與之並列的另外一個子程序裡面使用。即兩個子程序不能有變數重疊。即使在這個兩個子程序里都使用了同
名的某個變數,本質上講,在這兩個子程序里的同名變數也是沒任何聯系的。
那麼,如果需要在子程序之間傳遞變數(參數),怎麼辦呢?還要細說一點:傳參的結構有兩類:第一類,諸如主程序-子程序、外層子程序-內層子程序(子程序嵌套)之間的參數傳遞,另外一類,就是並列的兩個子程序(即它們之間不需要有關系,僅僅由於需求相同的變數)之間的參數傳遞。
第一類傳參結構的實現常見傳址調用。
第二類傳參結構的實現常見申明公共內存塊,將需求的相同變數申明成全局變數,那麼各個子程序自然都可以用了。注意,仍然是地址,所以子程序可以修改這些全局變數的。
其中,FORTRAN77的公共塊(全局變數申明)使用COMMON;FORTRAN90以後使用MODULE來包裝公共塊。

來看幾個問題:
一、以數組A中滿足某一條件的元素的編號構成新的數組B
do bi=1,bn
do ai=1,an
if(A(ai).eq.a0) then
B(bi)=ai
endif
enddo
enddo

二、以數組A的元素為編號,取數組B的元素進行其他運算
do bi=1,bn
do ai=1,an
if (bi.eq.A(ai)) then
fun(i)=fun(i)+fun2(bi)
endif
enddo
enddo

閱讀全文

與fortran怎麼添加數據相關的資料

熱點內容
企業客戶信息如何做到保密 瀏覽:941
哪些國寶不能交易 瀏覽:734
縣級教體局招聘的人事代理是什麼 瀏覽:158
代理為什麼找下家 瀏覽:272
唐代大商人一般用什麼貨幣交易 瀏覽:950
蘭州職業技術學院怎麼報考 瀏覽:607
為什麼信息都不見了 瀏覽:405
做品牌代理需要哪些資料 瀏覽:808
什麼是整理庫存數據 瀏覽:508
心動省級代理怎麼弄 瀏覽:104
已讀信息怎麼標記 瀏覽:363
測試你適合什麼顏色的口紅小程序 瀏覽:463
安卓如何設置程序使用屏幕的比例 瀏覽:958
怎麼獲取知網資料庫 瀏覽:263
做市場投放需要注意什麼 瀏覽:742
濱州哪裡有鑒定交易 瀏覽:59
批發市場的雞蛋皮是怎麼知道的 瀏覽:269
麻友圈成為代理怎麼充卡 瀏覽:64
有什麼好的技術推廣 瀏覽:43
交易數據異常是什麼意思 瀏覽:327