Writing dynamic arrays to Fortran 90

I have arrays with dynamic dimension ( dimx, dim), and I need a way to write such arrays to a file using the instruction Write, the problem is that so far I have not been able to create such files automatically, I mean, so far I have I need to resize the array in the instructions Writemanually, and I need a way to resize depending on the size dimxand dimin the method:

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 any way to do this?

+4
source share
2 answers

- - . , :

 write(unit,'(3f5.1)') x,y,z

, :

 real::a(3)
 write(unit,'(f5.1,f10.2,f5.1)') a

( / -do), , , , . , ( , F66) ( ) - "" , , - .

complex, , .

F77 , ( ) "" WRITE, . 2- () .

, :

program SO43482939
integer,parameter::dimx=2,dimy=3,dim=4
complex,allocatable::mata(:,:),vecb(:)
character(len=80)::fmt
integer i,j
allocate (mata(dimx,dimy),vecb(dim))
do i=1,dimx
  do j=1,dimy
    mata(i,j)=complex(i*10+j,i*10+j)
  end do
end do
do i=1,dim
  vecb(i)=complex(i*10+j,i*10+j)
end do
write(*,'(999f5.1)') vecb
write(fmt,'(a,i5,a)') '(',2*dimx,'f5.1)'
write(*,'(a)') fmt
write(*,fmt) mata
end program

OUTPUT

 14.0 14.0 24.0 24.0 34.0 34.0 44.0 44.0
(    4f5.1)
 11.0 11.0 21.0 21.0
 12.0 12.0 22.0 22.0
 13.0 13.0 23.0 23.0
+3

, , , ...

2008 , , . ( @dave_thompson_085), *,

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

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

.

+3

Source: https://habr.com/ru/post/1675095/


All Articles