`
chemingliang
  • 浏览: 136619 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Fortran中使用Module、Type和Pointer示例

阅读更多

程序代码如下:

-----------------------------------------------------------------------------------------------------------------

!define a module
module college
implicit none
type,public:: information
        integer, pointer::numclg    !number of colleges
        integer, pointer::nummjr    !number of majors
end type information

type(information),public,target::info

end module college

 

!initializing the module
module college_init
use college
contains
subroutine init ()
        print *,"initatilizing..."
        allocate(info%numclg)
        allocate(info%nummjr)
end subroutine init

subroutine release ()
        print *,"releasing..."
        deallocate(info.numclg)
        deallocate(info.nummjr)
end subroutine release
end module college_init

 

!the main program
program main
use college
use college_init, only: init

integer,pointer::a,b
integer,pointer::c,d

call init()

a=>info.numclg
b=>info.numclg
c=>info.nummjr
d=>info.nummjr

a=5
c=20

print *,"a=",a,",b=",b,",c=",c,",d=",d

end program main
-----------------------------------------------------------------------------------------------------------------

打印结果如下:

 initatilizing...
 a=           5 ,b=           5 ,c=          20 ,d=          20

 

分享到:
评论

相关推荐

    json-fortran-8.1.0

    type(json_value), pointer :: jv character(len=:), allocatable :: json_text ! 读取JSON文件 call json_file%open('data.json', action='read') call json_file%get('root', jv) call json_file%close() ...

    Fortran90 新特性

    - **模块(Module):** 模块是Fortran90中的一项重要特性,它允许开发者将数据类型、常量、变量声明、子程序等封装在一起,从而实现代码的重用和更好的组织结构。 - **自由格式源代码(Free-form Source Code):** 这...

    Fortran面试题.pdf

    3. **指针(Pointer)工作原理与使用示例:** - 指针指向其他变量的位置。 - 示例: ```fortran real, pointer :: p real :: x = 10.0 p => x print *, p ``` 4. **派生类型(Derived Type)的创建与使用:** ...

    fortran90读书杂记

    - 使用`USE module1, ONLY: v1, v2, v3 => v4`引入模块中的变量和重命名。 7. I/O操作: - OPEN语句打开文件,如`OPEN(UNIT=1, FILE='file.dat', IOSTAT=status)`。 - NAMELIST用于结构化输入输出,如`NAMELIST ...

    Fortran90 手册

    2. **示例**:使用DO循环计算1到10的和。 ```fortran program SumNumbers implicit none integer :: i, sum sum = 0 do i = 1, 10 sum = sum + i end do write(*,*) "Sum is:", sum end program ...

    西交大代码,西南交大代码,Fortran源码.zip

    7. **现代Fortran**:自Fortran 90以来,语言进行了重大更新,增加了模块(MODULE)、类型(TYPE)、指针(POINTER)、内联函数(INTRINSIC)等特性,提高了可读性和可维护性。 8. **在科学计算中的应用**:Fortran...

    Visual Fortran调用Win32 API函数 (2008年)

    在 CVF 中使用 QuickWin 应用程序类型时,可能会遇到与 Win32 API 图形函数重名的问题。为了解决这一冲突,CVF 对部分图形例程进行了重命名。例如,来自 GDI32 的函数会将设备环境 DC 参数转换为焦点窗口的单元号,...

    interface功能详解

    总结来说,`interface` 在 Fortran 中是一个强大的工具,它帮助我们确保函数调用的正确性,支持函数重载和操作符重载,使得代码更易于理解和维护。在编写涉及复杂函数接口或需要特殊行为的程序时,`interface` 是不...

    程序科学

    在“Prog_cientifica-master”这个压缩包中,可能包含了关于程序科学的示例代码、教程或项目,涵盖了上述的Fortran知识点。学习者可以通过分析这些文件,了解如何在实际项目中应用Fortran进行科学计算,同时也可以...

Global site tag (gtag.js) - Google Analytics