在 Fortran 90 中编写动态数组 [英] Write dynamical arrays in Fortran 90
问题描述
我有具有动态维度的数组(dimx
、dim
),我需要一种方法通过 Write
在文件中写入此类数组指令,问题是直到现在我还不能以自动方式生成这样的文件,我的意思是直到现在我必须手动更改 Write
指令中数组的维数,然后我需要一种根据尺寸dimx
和dim
来改变尺寸的方法:
I have arrays with dynamical dimension (dimx
, dim
) and I need a way to write such arrays in a file through the Write
instruction, the problem is that until now I haven't been able to produce such files in a automatic way, I mean until now I have to change the dimension of the array in the Write
instruction by hand and I need a way in which the dimension change depending of the dimension dimx
and dim
in the way:
integer :: dimx, dim
complex, allocatable :: matA(:,:), vectB(:)
allocate(matA(dimx,dimx), vectB(dim))
write(1,'(**dimx** e16.6) matA
write(2,'(**dim** e16.6) vecB
有没有办法做到这一点?
Is there a way to do this?
推荐答案
补充另一个答案,以及评论中提到的几乎重复的内容中未涵盖的问题...
To supplement the other answer, and a matter not covered in the near-duplicate referred to in the comments ...
2008 语言标准引入了unlimited-format-item 的概念,这是一种语言标准机制,用于根据需要多次重复格式规范.在过去,人们可能会在格式规范之前使用非常大的数字(如@dave_thompson_085 提到的),现在可以使用 *
代替,例如
The 2008 language standard introduces the concept of the unlimited-format-item, that is a language-standard mechanism for repeating a format specification as many times as necessary. In the olden days one might precede a format specification with a very large number (as @dave_thompson_085 mentions), now one can use a *
instead, for example
write(1,'(*(e16.6))') matA
而不是
write(1,'(999(e16.6))') matA
许多常用的编译器已经实现了这个特性.
Many compilers in common use already implement this feature.
这篇关于在 Fortran 90 中编写动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!