Array declaration in Fortran

别来无恙 提交于 2019-11-26 21:53:38

问题


Consider

INTEGER,DIMENSION(3) :: NumberVector

and

INTEGER              :: NumberVector(3)

Is there any difference whatsoever between these two declarations or are they exactly the same? (I mean in ANY possible context and variation: for example, in the case that those two were identical, what if I am declaring an array with an implicit size as one of the input parameter of a subroutine? Would it still be irrelevant which one I used?)


回答1:


Yes, it is identical. Even for assumed, deferred and whatever possible shape.




回答2:


The DIMENSION attribute was added to Fortran 90 in order to improve code clarity and to enable code savings when declaring multiple arrays of the same type (not uncommon in scientific computing), e.g. instead of

REAL :: mat1(10,20), mat2(10,20), mat3(10,20), mat4(10,20), mat5(10,20)

one could write

REAL, DIMENSION(10,20) :: mat1, mat2, mat3, mat4, mat5

Besides reducing source code size and compilation time (less parsing; not that relevant nowadays), this reduces the possibility of making a mistake in any of the declarations. Otherwise both forms are equal and the variables declared behave exactly the same way everywhere in the program.



来源:https://stackoverflow.com/questions/10691401/array-declaration-in-fortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!