-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C-style formatting #19
Comments
We can start with using C, and later we can perhaps reimplement in Fortran if we decide it is valuable to stay in pure Fortran (see #20). |
A bit more thought makes me wonder if it would in fact be better to do this in Fortran, as converting between Fortran and C strings is quite a painful really. Furthermore, some of the behaviour of |
Perhaps using the Python 3 formatting syntax would work for Fortran: https://docs.python.org/3.1/library/string.html#format-specification-mini-language (see examples). |
@certik Yes, that's what I was thinking of, although I don't think it would be practical to allow named-arguments in the format string, given Fortran doesn't have features like that. |
Python 3 formatting is becoming quite widespread; I know that C# and Rust use them. It would be great to reach this point, but I agree with @cmacmackin that it might not be practical with Fortran syntax. Those languages also offer C-style formatting, so I see no harm in pursuing both. |
We can start without named arguments. Then go from there, perhaps there is a way to specify the names somehow, that is quite reasonable syntax-wise. |
Note that the Fortran 202X proposal list includes intrinsic functions for converting Fortran characters to C strings and vice versa. |
I agree C-style formatting is already considered obsolete in Python. I would prefer just improving the currect capabilities of Fortran i/o. On a side note, there has been recently a whole discussion whether "things easy to implement should be implemented or left for the programmer". My stand on this is "they should be implemented if they are the recommended way of doing things". Using C stdlib in Fortran is certainly not the purest way of doing things (and might possibly bring portability issues) so I would leave this burden and responsibility to the programmer. What do you think? |
I agree with @gronki and I think this whole issue should migrate to a "string style formatting" type of discussion (For instance: #69 ) closing this one. We could implement some facility to convert a easier to write and read syntax to the standard way. "My name is (A) and I want a readable spec, so I can show pi = (G0) and fruits = (I0) to my friends." and convert to the weird and sometimes infuriating standard I/O '("My name is ",A," and I want a readable spec, so I can show pi = ",G0," and fruits = ",I0," to my friends.")' Then, finally using it as a sane format write(f, sane_fmt) 'Ian', PI, my_fruits Such facility would fit into a string module (like Python did, actually). IDK, what you all think @certik @gronki @cmacmackin ? |
In #14 @milancurcic indicated he'd like to have something along the lines of a
printf
function, like in C. I suggested a way to do this:I went on to comment:
My suggestion of calls to C was specifically for a
printf
function. This would avoid the combinatorial explosion becauseprintf
works onvoid*
data types. These can be passed in from Fortran using a "deferred-type" argument,type(*)
. The interface would look something like this:The main complication with this is how to convert between Fortran and C strings. It wouldn't be hard to provide wrapper routines which do this for the Format string, but string arguments to
printf
could be more of a challenge.The text was updated successfully, but these errors were encountered: