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

Format anomoly

JohnNichols
Valued Contributor III
989 Views

    !  Known Errors
4373 Write(*,8126)NJL,NM1
    Write(12,8126)

8126 FORMAT("    STOP  as " :: ,2I10)

The double colon does not cause an error, I mistyped, it should be inside the " "

Is this standard Fortran, what does it do?  

This is from the McMaster Uni program, I am down to a few minor errors and this traps two of them. 

0 Kudos
6 Replies
Steve_Lionel
Honored Contributor III
983 Views

Yes, it is standard conforming. Colon is a standard control edit descriptor that says to not process more of the format unless there are unused items in the I/O list. You have two of them, and the standard allows there to be no comma between them. I don't think it behaves any different than a single colon.

0 Kudos
jimdempseyatthecove
Honored Contributor III
941 Views

Steve,

Can the FORTMAT have more than one : at different positions in the FORMAT statement? e.g.

    !  Known Errors
4373 Write(*,8126)NJL,NM1 ! two items
    Write(12,8126)NJL ! one item
    Write(1,8126) ! no items

8126 FORMAT("    STOP  as :" : ,I10 :, I10)

Jim Dempsey

0 Kudos
Steve_Lionel
Honored Contributor III
912 Views

@jimdempseyatthecove wrote:

Steve,

Can the FORMAT have more than one : at different positions in the FORMAT statement?


Sure, no problem. But your example doesn't show the effect because the I10 would stop processing. The primary use of the colon edit descriptor is when you have non-data transferring descriptors you want to skip if there are no more items. The most common example of this is a comma-list.

 

program test
implicit none
integer :: a(5) = [1,2,3,4,5]
integer :: i

do i=1,5
  write (*,'(*(I2,:,","))') a(1:i)
  end do
end program test
D:\Projects>t.exe
 1
 1, 2
 1, 2, 3
 1, 2, 3, 4
 1, 2, 3, 4, 5

Without the colon, you'd see this:

 1,
 1, 2,
 1, 2, 3,
 1, 2, 3, 4,
 1, 2, 3, 4, 5,

 

 

jimdempseyatthecove
Honored Contributor III
943 Views

>>The double colon does not cause an error, I mistyped, it should be inside the " "

From your code snip, I think one of the :'s should have been inside the ""'s and the other outside the ""'s.

Jim Dempsey

0 Kudos
JohnNichols
Valued Contributor III
925 Views

 

Screenshot 2023-04-08 095111.png

They are both inside the quotations.  I use it as simple device to line up numbers so it is quick to read. 

No idea why I use ::  always have, lost in the mists of time. 

 

This is from the McMaster Program, I have the code running, sorted out the last of the lost goto's, now to make sense of the thesis and the code, both are a little cryptic and the lack of a meaningful output is annoying.  

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
906 Views

Great example!

I've had many occasions to want to do just that.

Jim Dempsey

0 Kudos
Reply