|
realloc 是 Sun 提供的函数,不是标准的。
不管是VB的 Redim Preserve,还是 C++ 容器类的 resize() 成员。其底层的实现本质,都是重新分配,然后复制原来的值。
Fortran需要自己去实现,而且由于Fortran没有模板类,所以每种类型都要写一遍,二维数组又要写一遍,三维还要写一遍。实际上,C++ 压根没有多维数组,VB Redim Preserve 也只能改变最后一维的大小,前面不能改变。
静态编程语言,改变大小都很难。想要自由编程,可以选 Python 或者 matlab 这种动态编程语言。想怎么加怎么加。
用预处理宏定义可以节省一点时间。
[Fortran] 纯文本查看 复制代码 02 | Integer , allocatable :: x ( : ) |
03 | Real , allocatable :: y ( : ) |
08 | call ReallocateInt ( x , 3 ) |
09 | call ReallocateReal ( y , 6 ) |
15 | Subroutine ReallocateInt ( x , n ) |
16 | TYPE_ , allocatable :: x ( : ) , t ( : ) |
23 | End Subroutine ReallocateInt |
25 | Subroutine ReallocateReal ( x , n ) |
26 | TYPE_ , allocatable :: x ( : ) , t ( : ) |
33 | End Subroutine ReallocateReal |
|
|