fortran F90动态数组的基本使用示范
2011-03-15 21:28
92 查看
program sample parameter (row = 5) integer err_mesg integer ary1(:), ary11(:, :, :) allocatable ary1, ary11 !第一种声明动态数组的方式 integer, allocatable:: ary2(:), ary22(:) !第二种声明动态数组的方式 integer, dimension(:), allocatable:: ary3, ary33 !第三种声明动态数组的方式 !下面是测试部分 allocate(ary1(1:5), ary11(3, 3, 3), stat = err_mesg) if(0 .eq. err_mesg) then print *, "ary1 initialize successed!" else if(0 .ne. err_mesg) then print *, "ary1 initialize failed", err_mesg end if !以上测试正常分配的情况,分配成功stat = 0 !查看动态数组是否分配空间 if(.not. allocated(ary2)) print *, 'not allocated ary2' if(.false. .eq. allocated(ary22)) print *, 'not allocated ary22' if(.true. .eq. allocated(ary1)) print *, 'allocated ary1' !已被分配空间的数组不可重复分配 allocate(ary11(2, 2, 2), stat = err_mesg) if(0 .ne. err_mesg) print *, 'Ooops, ary11 has been allocated' !内存的释放,只有被allocate的内存才能用deallocate释放,否则报错 deallocate(ary1, stat = err_mesg) if(0 .ne. err_mesg) then print *, 'ary1 is not allocated' else if(0 .eq. err_mesg) then print *, 'ary1 del successfully' end if deallocate(ary3, stat = err_mesg) if(0 .ne. err_mesg) then print *, 'ary3 is not allocated' else if(0 .eq. err_mesg) then print *, 'ary3 del successfully' end if end subroutine disp(ary) parameter (row = 5) !integer row integer:: ary(1:row) do i = 1, row print *, ary(i) end do end 上述程序的输出: ary1 initialize successed! not allocated ary2 not allocated ary22 allocated ary1 Ooops, ary11 has been allocated ary1 del successfully ary3 is not allocated 请按任意键继续. . .
相关文章推荐
- 动态数组的使用
- java中数组的基本使用方法
- Java基本语法--数据类型、运算符表达式、基本控制语句、数组使用以及练习
- VB.NET 数组的定义 动态使用 多维数组
- 数组字符串系列之:判断一个输入字符串中的每个字符唯一,只能使用基本的数据结构
- [RTT例程练习] 2.2 信号量之基本使用(动态/静态信号量)
- 数组的基本概念,定义及使用方法
- java中动态数组Vector的使用实例
- MFC中动态数组CArray的使用
- linux shell 动态生成数组系列 seq使用技巧
- C语言基础之函数、虚拟键盘的使用、数组、指针、动态申请内存、内存泄漏
- MFC的CByteArray、CString类用做动态字节数组使用
- asp中使用redim、preserve创建动态数组实例
- 动态数组的使用
- 动态注册广播基本使用
- 数组的基本使用
- ArrayList动态数组的使用和遍历
- 在Delphi下,使用线程向窗体发送动态数组数据的解决方法~
- Fortran使用隐形DO循环和reshape给一维和多维数组赋初值
- c语言动态调整数组大小如何使用realloc