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

type convertion functions

jgte
Beginner
1,135 Views
I'm confused here. I understand that type conversions are dead easy using internal read and write, but hasn't anyone come up with a module for a bunch of functions that make type convertion to char automatic? Something like:
-----------
use magic_type_convertion_module

int a
real b
logical c
character d*96



write (*,*) trim(d)//' = '//any2str(a)//'; '//any2str(b)//'; '//any2str(c)
---------
Certainly makes building up strings from other types easier.

In the same way, a "any2int", "any2real", "any2complex", etc seem to be missing. I don't see any obvious difficulty in implementing this and it would make certain programming task much simpler (such as assigning/reading values to/from edit boxes in dialogs - even programming in one single type?)

My questions:
1) Does anyone disagree with the usefulness of this? If so, why?
2) Can anyone confirm that this sort of thing is not intrinsic? Main question: Can you figure out any reason why (if you agree with it's usefulness and ease of implementation)?
3) Is out there any module that has this implemented? Is it freely available?
0 Kudos
3 Replies
Jugoslav_Dujic
Valued Contributor II
1,135 Views
1) Does anyone disagree with the usefulness of this? If so, why?

This was discussed in comp.lang.fortran about a year ago; sorry, can't give you specific URL, because it wasn't so recent and I can't figure out any specific keyword to search. The answer, as I recall, was that, since READ/WRITE already do that, functional form will be redundant. In other words, Fortran has the equivalent of C sprintf/sscanf, but not of itoa/atoi/ftoa/atof. If you want the latter, you can roll your own...

2) Can anyone confirm that this sort of thing is not intrinsic? Main question: Can you figure out any reason why (if you agree with it's usefulness and ease of implementation)?

See above.

3) Is out there any module that has this implemented? Is it freely available?

...attached is a set of routines I wrote for personal use. Generic STRING takes integer, real or double argument and converts it to string of width iLen, with iPrec decimal places, and optionally right-adjusted if bRight is .TRUE. As you know, WRITE does that already, but functional form can be more succinct.



Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,135 Views

Does an URL trigger it?


Here's the attachment.
0 Kudos
jgte
Beginner
1,135 Views
Once more, thanks jugoslavdujic.

That's what I need for now, so you've saved me from writing it all over again.
0 Kudos
Reply