Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
CodeGeneration[Fortran] - Maple コードの Fortran コードへの変換
使い方
Fortran(x, cgopts)
パラメータ
x
-
式、リスト、rtable、プロシージャ、またはモジュール
cgopts
(オプション) 1 つまたは複数の CodeGeneration のオプション
説明
Fortran コマンドは Maple コードを Fortran 77 コードに変換します。
- パラメータ x が代数式の場合、その数式を変数に割り当てる Fortran 文が生成されます。
- x が代数式のリスト、rtable、または Maple 配列の場合、要素を Fortran 配列に割り当てる Fortran 文の式列が生成されます。rtable または Maple 配列の場合、初期化されている要素のみが変換されます。
- x が 形式の式のリスト ( は名前、 は代数式) である場合、x は代入文の式列を意味するものとして解釈されます。この場合、等価な意味を持つ Fortran の代入文の列が生成されます。
- x がプロシージャの場合、Fortran 関数またはサブルーチンが生成されます。
- x がモジュールの場合、Fortran プログラムが生成されます。詳細は FortranDetails ヘルプページを参照してください。
パラメータ cgopts には 1 つ以上の CodeGeneration オプションを指定できます。オプションの詳細は CodeGenerationOptions を参照してください。このコマンドでのみ使用可能な limitvariablelength=false オプションを指定すると、7 文字以上の名前を使用することができます。デフォルトでは、このような名前は Fortran 77 規格に適合しないため、自動的に置き換えられます。
CodeGeneration パッケージによる Maple コードから他の言語への変換についての詳細は、Translation Details を参照してください。Fortran への変換に特化した情報については、FortranDetails を参照してください。
例
以下の例で使用されているオプションの説明については、CodeGenerationOptions を参照してください。
with(CodeGeneration):
単純な数式を変換し、目的のコード内の名前 "w" に割り当てます。
Fortran(x+y*z-2*x*z, resultname="w");
w = x + y * z - 2 * x * z
リストを変換し、目的のコード内にある "w" という名前の配列に割り当てます。
Fortran([[x, 2*y], [5, z]], resultname="w");
w(1,1) = x w(1,2) = 2 * y w(2,1) = 5 w(2,2) = z
計算式の列を変換します。最初に入力を最適化します。
cs := [s=1.0+x, t=ln(s)*exp(-x), r=exp(-x)+x*t]:
Fortran(cs, optimize);
s = 0.10D1 + x t1 = log(s) t2 = exp(-x) t = t1 * t2 r = t2 + x * t
x が浮動小数点数、y が整数であることを宣言します。結果が文字列内に返されます。
s := Fortran(x+y+1, declare=[x::float, y::integer], output=string);
プロシージャを変換します。型が指定されていない変数はすべて integer であると仮定します。
f := proc(x, y, z) return x*y-y*z+x*z; end proc:
Fortran(f, defaulttype=integer);
integer function f (x, y, z) integer x integer y integer z f = x * y - y * z + x * z return end
間接的な戻り値を含むプロシージャを変換します。戻り値を格納するための新しい変数が作成されます。
f := proc(n) local x, i; x := 0.0; for i to n do x := x + i; end do; end proc:
Fortran(f);
doubleprecision function f (n) integer n doubleprecision x integer i doubleprecision cgret x = 0.0D0 do 100, i = 1, n, 1 x = x + dble(i) cgret = x 100 continue f = cgret return end
配列をパラメータとして受け入れているプロシージャを変換します。
f := proc(x::Array(numeric, 5..7)) return x[5]+x[6]+x[7]; end proc:
doubleprecision function f (x) doubleprecision x(5:7) f = x(5) + x(6) + x(7) return end
エクスポートされたプロシージャとローカルプロシージャを 1 つずつ持つモジュールを変換します。
m := module() export p; local q; p := proc(x,y) if y>0 then trunc(x); else ceil(x); end if; end proc: q := proc(x) sin(x)^2 end proc: end module:
Fortran(m, resultname=t0);
Warning, the function names {ceil} are not recognized in the target language doubleprecision function q (x) doubleprecision x q = sin(x) ** 2 return end integer function p (x, y) doubleprecision x integer y if (0 .lt. y) then p = int(aint(x)) return else p = int(ceil(x)) return end if end program m end
戻り値を持たない、出力文を含んだプロシージャを変換します。
f := proc(N) printf("%d is a Number.\n", N); end proc:
subroutine f (N) doubleprecision N print *, N, ' is a Number.' end
limitvariablelength オプションを使って 7 文字以上の名前を使用します。
p:=proc() local longvar: end proc;
CodeGeneration[Fortran](p);
Warning, The following variable name replacements were made: ["cg"] = ["longvar"]
subroutine p
doubleprecision cg
end
CodeGeneration[Fortran](p,limitvariablelength=false);
doubleprecision longvar
関連項目
CodeGeneration、CodeGenerationOptions、FortranDetails、Translation Details
Download Help Document