我已经在这里阅读了fortran format specifier for complex number
中复数的格式说明符但是我无法根据自己的意愿修改它。我有已知维度的双复矩阵,我希望它写成这样:
{1.000E+00, 0.000E+00} {2.123E+00, 6.545E+20} {5.456E+24, 5.562E+12} ....
{1.000E+00, 0.000E+00} {2.123E+00, 6.545E+20} {5.456E+24, 5.562E+12}
{1.000E+00, 0.000E+00} {2.123E+00, 6.545E+20} {5.456E+24, 5.562E+12}
...
因此,大括号中的第一部分应该是实部,第二部分是虚部。矩阵元素应各自用大括号括起来,并根据矩阵中的位置彼此相邻放置。
到目前为止,我可以使用以下格式正确地打印出一个元素或所有矩阵元素:("{",ES10.3, ",", 1X, ES10.3 ,"}")
编辑:
program test
implicit none
double complex :: zz
double complex, dimension(3,4) :: aa
character (len=32) :: fmtString
zz = cmplx(1.d0, -2.d0)
fmtString = '("{",ES10.3, ",", 1X ES10.3,"}")'
write(0,fmt = fmtString) zz !works
write(0,fmt = fmtString)aa !not formatted propperly
end program test
会产生类似的结果,因为aa未初始化:
{ 1.000E+00, -2.000E+00} <- zz works
{ 9.881-324, 9.387-323} <- aa doesn't since it is not displayed as a 3x4 matrix
{ 6.953-310, 0.000E+00}
{ 0.000E+00, 0.000E+00}
{ 1.812-314, 6.953-310}
{ 0.000E+00, 1.019-312}
{ 0.000E+00, 0.000E+00}
{ 4.496-322, 0.000E+00}
{ 0.000E+00, 2.631-312}
{ 0.000E+00, 2.631-312}
{ 0.000E+00, 1.210-316}
{ 1.210-316, 1.210-316}
{ 1.210-316, 3.953-323}
那我该怎么办?
答案 0 :(得分:1)
program test
implicit none
double complex :: zz
double complex, dimension(3,4) :: aa
character (50) :: fmtString
integer :: i
zz = cmplx(1.d0, -2.d0)
aa = zz ! aa needs to be initialized too
fmtString = '(9999("{",ES10.3,",",1X,ES10.3,"}",:,1X))'
write(*,fmt = fmtString) zz
do i=1,size(aa,1)
write(*,fmt = fmtString) aa(i,:)
enddo
end program test