Variable format

后端 未结 1 1800
借酒劲吻你
借酒劲吻你 2020-12-11 13:38

I wrote a program to calculate a square finite difference matrix, where you can enter the number of rows (equals the number of columns) -> this is stored in the variable mat

1条回答
  •  情深已故
    2020-12-11 13:55

    The syntax you are trying to use is non-standard, it works only in some compilers and I discourage using it.

    Also, forget the FORMAT() statements for good, they are obsolete.

    You can get your own number inside the format string when you construct it yourself from several parts

    character(80) :: form
    form = '(          (i10,1x))'
    write(form(2:11),'(i10)') matrix
    
    write(*,form) A
    

    You can also write your matrix in a loop per row and then you can use an arbitrarily large count number or a * in Fortran 2008.

    do i = 1, matrix
      write(*,'(999(i10,1x))') A(:,i)
    end do
    
    do i = 1, matrix
      write(*,'(*(i10,1x))') A
    end do
    

    Just check if I did not transpose the matrix inadvertently.

    0 讨论(0)
提交回复
热议问题