Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

problem in format statment

dousti_a_
Beginner
888 Views

i define a subroutine

but it no work

subroutine printrmat(matrix,row,column)
    implicit none
    integer row,column,,i,j
    real(8) matrix(row,column)
    do i=1,row
        write(*,10) (matrix(i,j),j=1,column)
10 format(column(f))        
    end do
    end subroutine

 

 
 
0 Kudos
5 Replies
Johannes_Rieke
New Contributor III
888 Views

Hi dousti,

try this (it works with Intel compilers but is not standard Fortran):

subroutine printrmat(matrix,row,column)
    implicit none
    integer, intent(in) :: row, column
    real(8), intent(in) :: matrix(row,column)
    integer :: i,j
    do i=1,row
        write(*,'(<column>ES16.8)') matrix(i,1:column)
    end do
    return   
end subroutine

Regards, Johannes

0 Kudos
IanH
Honored Contributor III
888 Views

The standard language offers an unlimited repeat count in format specifications, that can come in handy for these cases.

subroutine printrmat(matrix,row,column)
    implicit none
    integer, intent(in) :: row, column
    real(8), intent(in) :: matrix(row,column)
    integer :: i
    do i=1,row
        write(*,'(*(ES16.8))') matrix(i,:)
    end do
end subroutine


 

0 Kudos
Johannes_Rieke
New Contributor III
888 Views

Hi IanH,

didn't know of that standard feature 'unlimited format repeat count' before. I've googled it and it was introduced with F08. It is implemented since Composer XE2011 in the Intel compilers.

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/270542

Hopefully other compilers (e.g. gfortran, ...)  support it also in the stable releases.

0 Kudos
dousti_a_
Beginner
888 Views

hi friends

tanks very much

i found a solution for problem

 write(*,10) (matrix(i,j),j=1,column)
10 format(100(f))   

or

  write(*,10) (matrix(i,j),j=1,column)
10 format(1000(f))

or

...

0 Kudos
Johannes_Rieke
New Contributor III
888 Views

Hi dousti,

good that you found a solution. But in my opinion it would be better to use 'unlimited format repeat count', '*', instead of the fixed number. In case you plan to use this print routine in future, you could avoid trouble later on...

0 Kudos
Reply