Fortran如何调用模块中子程序

Fortran如何调用模块中子程序,第1张

把你写的function放在另一个.f文件里面,或者放在主程序语句外面(即子程序形式)再来调用。主程序可调用function 和subroutine,所以,不用把子程序function写在主程序里。如此则subroutine和主程序都可以随意调用function,注意调用时的实参(subroutine里面的参数)和虚参(function里面的参数)要变量类型一致,而且实参数目不少于虚参(这个很重要)。

大致思路就是只要不把他们放在一个主程序内就OK了,放在同一个文件或者不同.f文件都是一样的。对于第二个问题,回答也是可以的

比如说这样的程序调用:

PROGRAM MAIN

CALL SUB1

END

SUBROUTINE S

CALL SUB2

END

SUBROUTINE SUB2()

CALL SUB3

END

SUBROUTINE SUB3()

下面有些路径是根据我自己的程序安装路径。1)set environment variables for Fluent, C++, Fortran//设置FLUENT,c++,Fortran的环境变量;2)put sorce code file into ..\src folder, put compiled fortran .obj files into ..\ntx86\2d folder, copy sed.exe, user_nt.udf and makefile_nt.udf to the same folder as compiled fortran .obj files(this two folders are created by yourself, you can put them under your case folder).将源文件代码放入\src文件夹下,将编译之后的fortran的.obj文件放在路径为···\ntx86\2d的文件夹下,复制文件sed.exe,user_nt.udf和makefile_nt.udf文件到路径为···\ntx86\2d的文件夹下(这两个是自己创建的,你可以放它们在你的case文件夹下)。3)modify user_nt.udf file {follow the instructions. e.g. USER_OBJECTS = test.obj this obj file is the complied fortran .obj file ,SOURCES = &#36(SRC)test_use.c(c source file that is in the \src fold), VERSION = 2d(your model dimension), PARALLEL_NODE = none按下面的方法修改user_nt.udf文件:USER_OBJECTS = test.obj // test是你编译之后的fortran程序文件名;SOURCES = &#36(SRC)test_use.c(text_use.c是你放入\src文件下的c程序的源码文件) ;VERSION = 2d //为你模型的维数。PARALLEL_NODE = none//是否并行计算,一般选择不并行计算。4)change the name of file makefile_nt.udf tomakefile, modify makefile, (add this line "FLUENT_INC= D:\Fluent.Inc" below "UDFDATA = udf_names.c"改变makefile_nt.udf的文件名为:makefile;并且添加在UDFDATA = udf_names.c这行后面添加FLUENT_INC= D:\Fluent.Inc;* 5)You might need to copy all the .lib files under Fortran\lib fold to folder D:\Fluent.Inc\fluent6.3.26\ntx86\Fortran_lib (this folder is created by myself) change this line "LIBS = /Libpath:&#36(FLUENT_INC)\fluent&#36(RELEASE)\&#36(FLUENT_ARCH)\&#36(VERSION)" in the makefile file to "LIBS = /Libpath:&#36(FLUENT_INC)\fluent&#36(RELEASE)\&#36(FLUENT_ARCH)\&#36(VERSION)D:\Fluent.Inc\fluent6.3.26\ntx86\Fortran_lib\*.lib"你需要复制fortran的库文件到fluent的安装文件D:\Fluent.Inc\fluent6.3.26\ntx86\Fortran_lib(其中Fortran_lib为自己创建的文件名);并且改变makefile文件中的行LIBS = /Libpath:&#36(FLUENT_INC)\fluent&#36(RELEASE)\&#36(FLUENT_ARCH)\&#36(VERSION)为LIBS = /Libpath:&#36(FLUENT_INC)\fluent&#36(RELEASE)\&#36(FLUENT_ARCH)\&#36(VERSION)6)Type "nmake" in the command line console, make sure the console is displaying the right path that is including your files such as: "makefile",".obj","sed.exe".在编译之后,确保在fluent的界面中出现,文件"makefile",".obj","sed.exe".的正确路径。7)Put the generated .dll file with your .cas and .data files together.连接你的dll文件和你的case文件和date文件一起。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7788333.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存