forums.silverfrost.com
Welcome to the Silverfrost forums

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
Kenneth_Smith

Joined: 18 May 2012
Posts: 682
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
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kenneth_Smith

Joined: 18 May 2012
Posts: 682
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.
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
wahorger

Joined: 13 Oct 2014
Posts: 1153
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:
 Quote: ***** 100000

Same applied for floating point numbers.

Bill
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 !
Kenneth_Smith

Joined: 18 May 2012
Posts: 682
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.
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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1