由买买提看人间百态

topics

全部话题 - 话题: p2i
(共0页)
O******e
发帖数: 734
1
Dynamic allocation in heap memory using Fortran 90/95:
integer,dimension(:),allocatable::p2i
integer::size
integer::alloc_stat
read(some_file,some_format)size
allocate(p2i(1:size),stat=alloc_stat)
if(alloc_stat.ne.0)stop"error allocating p2i"
...
deallocate(p2i,stat=alloc_stat)
if(alloc_stat.ne.0)stop"error deallocating p2i"
If you want to call a subroutine to allocate p2i, return from that
subroutine, use p2i elsewhere, then call another subroutine to deallocate
p2i, you will need to declare p2
f**********w
发帖数: 93
2
想在fortran中定义一个动态大小的数组,数组的大小从文件中读入,所以开始不知道。
我知道在C++中可以
int *p2i = new int[size];
//....
在fortran中怎么做?谢谢
(共0页)