由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 如何在fortran中定义一个动态的数组?
相关主题
关于内存泄漏help!无法编译一个package
再请教两道QuantC++面试题这样一道面试题 (转载)-debug求助
几个问题Write In C
fortran 77 introduction book recommendation?problem about Fortran 77 in unix
vector的析构问题偶也问一fortran问题
问一个 Andrei A. 的 Modern c++ design 书里边的一个问题<>全书下载
现在iOS的内存管理是怎么样的?关于C和Fortran: 一点儿个人观点
又问几个c语言编程的题目visual fortran区别6位以上的变量名吗?
相关话题的讨论汇总
话题: p2i话题: fortran话题: stat话题: integer话题: alloc
进入Programming版参与讨论
1 (共1页)
f**********w
发帖数: 93
1
想在fortran中定义一个动态大小的数组,数组的大小从文件中读入,所以开始不知道。
我知道在C++中可以
int *p2i = new int[size];
//....
在fortran中怎么做?谢谢
O******e
发帖数: 734
2
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 的大作中提到】
: 想在fortran中定义一个动态大小的数组,数组的大小从文件中读入,所以开始不知道。
: 我知道在C++中可以
: int *p2i = new int[size];
: //....
: 在fortran中怎么做?谢谢

f**********w
发帖数: 93
3
Thank you. Although I still have a question,
what is the meaning of :: here?
I know it is scope operator in C++, does it have a similar meaning here?
Thanks.
O******e
发帖数: 734
4
The :: is just the new syntax for declarations in Fortran 90/95/2003.
In F77 you would write
INTEGER X
DIMENSION X(1:N)
or more compactly
INTGETER X(1:N)
and in F90+ you would write
integer,dimension(1:n)::x
The :: separates the type and properties from the list of variables.
It does not have the same meaning as :: in C++.
You can probably even omit the :: (at least in some cases you can).
I have gotten into the habit of always writing the :: where possible.

【在 f**********w 的大作中提到】
: Thank you. Although I still have a question,
: what is the meaning of :: here?
: I know it is scope operator in C++, does it have a similar meaning here?
: Thanks.

f**********w
发帖数: 93
5
thanks
1 (共1页)
进入Programming版参与讨论
相关主题
visual fortran区别6位以上的变量名吗?vector的析构问题
fortran搞计算还是简单多了问一个 Andrei A. 的 Modern c++ design 书里边的一个问题
请教Unix中怎么编译Fortun文件现在iOS的内存管理是怎么样的?
统计工作机会: Healthcare Economics Consultant --Cypress,CA又问几个c语言编程的题目
关于内存泄漏help!无法编译一个package
再请教两道QuantC++面试题这样一道面试题 (转载)-debug求助
几个问题Write In C
fortran 77 introduction book recommendation?problem about Fortran 77 in unix
相关话题的讨论汇总
话题: p2i话题: fortran话题: stat话题: integer话题: alloc