windows平台下fortran编程使用子程序subroutine

 时间:2026-02-17 02:38:00

1、关于codeblocks IDE的极速安装

请参考百度经验<<Windows下极速搭建fortran开发环境>>

windows平台下fortran编程使用子程序subroutine

2、子程序的一般形式:

subroutine xxxx(参数1,参数2.....)

      implicit none

      参数1类型

      参数2类型

      xxxxxx代码

end subroutine xxxx

3、编写子程序

传入2个参数

其中一个是字符串

另一个是整数

循环整数次,打印字符串

程序结束时改变传入的整数值

传入的参数有如下三种形式:

      intent(in):在子程序中不可改变值

      intent(out):可在子程序中改变

      intent(inout):可在子程序中改变

=====================================

    !子程序

    subroutine dy2003310(strFileName, times)

        implicit none

        character(*),intent(in)::strFileName

        integer,intent(inout)::times

        integer::i

        do i=1,times

            print *, strFileName

        end do

        times=times+times

    end subroutine dy2003310

windows平台下fortran编程使用子程序subroutine

4、使用fortran的关键字contains

contains是Fortran 90中新增的一个语法功能

在module或者subroutine中

可以用contains来包含其他的module或者subroutine

5、编写主程序

测试子程序是否能够改变传入的参数

    implicit none

    character(len=255)::str

    integer::n

    str="168"

    n=3

    print *, "*****************************************"

    print *, "子程序运行之前,n=",n

    call dy2003310(str,n)

    print *, "子程序运行之后,n=",n

    print *, "*****************************************"

windows平台下fortran编程使用子程序subroutine

6、在codeblocks中编译、链接:

windows平台下fortran编程使用子程序subroutine

7、运行、测试结果如下

可以看到:

子程序调用前参数2等于3

调用后变成了6

windows平台下fortran编程使用子程序subroutine

  • 后缀为py的文件怎么打开
  • pycharm如何新建py文件
  • VisualStudioCode创建工作区
  • Python编程:怎么使用cmath模块log10()方法
  • 在C语言中如何实现按任意键继续
  • 热门搜索
    怎么减肥最有效 邪恶漫画大全无意鸟 美甲图片大全 动漫电影大全 钢筋图纸怎么看 路由器怎么升级 我的世界设计图纸大全 汤的做法大全 三级钢筋符号大全 花边图片大全