|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Mar 10, 2013 10:44 pm Post subject: Unlimited repeat count on Format statement |
|
|
When you need to repeat a Format sequence a number of times, but don't know how many, it is traditional to use a large number, such as in the following example.
Code: |
write(*,'(9999(f7.3,:,1x))') a(1:number)
|
In such code, the repeat counter 9999 is chosen to be larger than any possible value of number. (The : is used to prevent a space being printed after the last value).
It would be nice to allow the following extension from Fortran 2008 for this case.
Code: |
write(*,'(*(f7.3,:,1x))') a(1:number)
|
Just a suggestion _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Last edited by davidb on Tue Apr 02, 2013 5:16 pm; edited 1 time in total |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7942 Location: Salford, UK
|
Posted: Mon Mar 11, 2013 7:59 am Post subject: |
|
|
Nice idea. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Mon Mar 11, 2013 8:30 pm Post subject: |
|
|
So you are trying to teach computer what infinity means
DEC Fortran had nice extension which still works in CVF/IVF which is even better
Code: | write(*,'(<number>(f7.3,:,1x))') a(1:number) |
where value in <> parentheses could be not a fixed number but a variable where you can put whatever you want because it like all variables of course could be changed dynamically |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Mar 16, 2013 12:15 am Post subject: |
|
|
The problem with the DEC/Intel extension is you need to include the count variable twice on the same line. The * method is just a bit more concise and is part of the Fortran standard. It has also been implemented in the Intel compilers as an alternative to the DEC extension. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Sun Mar 17, 2013 10:52 am Post subject: |
|
|
Depends of what you are doing. The <> is absolutely intuitive and is based on common sense that all must be changeable at run time, including super-conservative format statement. It perfectly succeeded to make nice and elegant code for run-time changeable formats, all it is done with absolute minimum of typing leading to very readable code
Code: |
Write(*,'(T<variable>, i10)') something
Write(*,'(E<variable1>.<variable2>)') something
Write(*,'(I<variable>)') something
Write(*,'(<variable>X, E10.3)') something
|
Possibilities of <> are infinite and all are extremely useful (versus this unlimited repeat format for which, sorry, i see just one). I miss <> in this compiler very much, i am doing similar things now in several lines using character variable as a format filled using internal write....yuck
Last edited by DanRRight on Sun Mar 17, 2013 12:06 pm; edited 2 times in total |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Mar 17, 2013 11:10 am Post subject: |
|
|
Yes, these are good examples.They are mostly not repeat counters though, which was the point of this suggestion.
If you really need to have this functionality, you can do it without using the DEC extensions in standard Fortran.
For example:
Code: |
character*1 :: num_size, num_decimals
num_size = "5"
num_decimals = "3"
write(*,'(F'//num_size//'.'//num_decimals//')') 2.59
end
|
Most of the time, you will need to use TRIM, which can be a bit messy. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2834 Location: South Pole, Antarctica
|
Posted: Sun Mar 17, 2013 11:17 am Post subject: |
|
|
LOL If i knew that 5 and 3 in advance i'd just write
Code: | write(*,'(F5.3)') 2.59 |
In practice your code will look
Code: | character*1 :: num_size, num_decimals
write(num_size,'(i1)') variable1
write(num_decimals,'(i1)') variable2
write(*,'(F'//num_size//'.'//num_decimals//')') 2.59
end |
versus
Code: |
write(*, '(F<variable1>.<variable2>')) 2.59
|
|
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Mar 17, 2013 2:09 pm Post subject: |
|
|
Obviously, it was just an example. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
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
|