在Fortran 90中编写动态数组 [英] Write dynamical arrays in Fortran 90

查看:261
本文介绍了在Fortran 90中编写动态数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数组动态维( dimx dim ),我需要一种方法来写这样的数组一个文件通过 Write 指令,问题是直到现在我还没有能够自动生成这样的文件,我的意思是直到现在我不得不改变在$ 写入指令中手动修改数组的维数,我需要一个维度根据维度 dimx dim 的方式:

  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

有没有办法做到这一点?

解决方案

另一个答案,以及在评论中提到的近乎重复中没有涉及的事情...

2008年的语言标准简要介绍了 unlimited-format-item 的概念,这是一种语言标准机制,用于根据需要多次重复格式规范。在过去的一段时间里,人们可能会在格式规范之前加上一个很大的数字(如@ dave_thompson_085所提到的),现在可以使用 * 来替代,比如

  write(1,'(*(e16.6))')matA 

而不是

  write(1,'(999(e16。 6))')matA 

常用的许多编译器已经实现了这个功能。 b $ b

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 ...

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

rather than

write(1,'(999(e16.6))') matA

Many compilers in common use already implement this feature.

这篇关于在Fortran 90中编写动态数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆