|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Sat Mar 25, 2023 11:56 pm Post subject: A question re: format ( 4(2xI3) ) |
|
|
Re: format ( 4(2x,I3) )
I would like to know what the format ( 4(2x,I3) ) specifies.
Please only reply with a code example employing the format ( 4(2x,I3) ).
Please do not respond with a narrative or more obfuscation.
Thank you very much in advance, Zach.
Last edited by Zach on Sun Mar 26, 2023 11:45 am; edited 2 times in total |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 711 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Sun Mar 26, 2023 11:05 am Post subject: |
|
|
4 means repeat what is in the following brackets four times.
2x means two spaces.
Code: | program fmt
integer :: ia(4) = [123,234,345,456]
! / is new line.
write(6,'(a,/,a)') 'xx xx xx xx ',' 123 123 123 123'
! 2x is two spaces, i3 an integer occupying three spaces, all repeated four times.
write(6,'(/,"Case 1")')
write(6,'(4(2x,i3))') ia(1),ia(2),ia(3),ia(4)
! Equivalent to:
write(6,'(/,"Case 2")')
write(6,'(2x,i3,2x,i3,2x,i3,2x,i3)') ia(1),ia(2),ia(3),ia(4)
! Missing comma as per question- OK in this particular case - compiler can work it out.
write(6,'(/,"Case 3")')
write(6,'(4(2xi3))') ia(1),ia(2),ia(3),ia(4)
end program fmt
|
Returns:
Code: | xx xx xx xx
123 123 123 123
Case 1
123 234 345 456
Case 2
123 234 345 456
Case 3
123 234 345 456 |
|
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Sun Mar 26, 2023 12:51 pm Post subject: |
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. So from you I learn that:
4(2x,I3) pertains to four integers, each preceded by two spaces
Now re (6,'4(2x,I3)') what does the "6" stand for?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. You add another query:
write(6,'(a,/,a)') 'xx xx xx xx ',' 123 123 123 123'
a/a I would expect to signify two alphas below eo, but the code produces:
xx xx xx x
123 123 123 123
Now please explain the new magic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 711 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Sun Mar 26, 2023 2:30 pm Post subject: |
|
|
1. Standard output is to unit 6 (equivalent to *).
2. The output list for the write is two character strings, and the format code provides for two character strings to be printed, with the second character string printed after a "new line" instruction i.e. '/'.
Note that the width of the 'a' descriptor is optional and not necessary in this case. |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Sun Mar 26, 2023 2:58 pm Post subject: |
|
|
Thank you for the program you responded with and the explanation contained.
Last edited by Zach on Sun Mar 26, 2023 4:32 pm; edited 1 time in total |
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1226 Location: Morrison, CO, USA
|
Posted: Sun Mar 26, 2023 3:05 pm Post subject: |
|
|
Note that if any of the 4 integers are greater than 999, the display of that/those will be ***.
Unlike "C" and printf(), if the number exceeds the specified length of the supplied format, then the field is replaced by a series of asterisks for the length of the supplied format.
for example:
Code: | INTEGER I
I=100000
WRITE(6,'(I5,1X,I6)')I,I
|
Yields:
Same applied for floating point numbers.
Bill |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Sun Mar 26, 2023 3:39 pm Post subject: |
|
|
Thank you Bill for "If any of the 4 integers are greater than 999", etc ! |
|
Back to top |
|
|
Kenneth_Smith
Joined: 18 May 2012 Posts: 711 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Sun Mar 26, 2023 4:31 pm Post subject: |
|
|
Quote: | So in (*,(A,/,A)) : A signifies an array of type character? And the * stands for "move the result to the default standard output i.e. the display"? |
Yes, if you view a string of characters as an array. |
|
Back to top |
|
|
Zach
Joined: 13 Mar 2023 Posts: 85 Location: Groningen, Netherlands
|
Posted: Sun Mar 26, 2023 4:51 pm Post subject: |
|
|
I had already amended my response. Thank you again. I wasn't yet sensitised to seeing 'whatever' rather than whatever so I will pay better attention in future. Yes, they are character strings. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|