Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

How to convert characters to integers

cldblau
Beginner
4,567 Views
I need to convert a character string to an integer. The string looks like:
112###### (where # ara blank spaces) and is defined as follows:
character crecy*13
Can anyone help me?
Thanks
0 Kudos
2 Replies
Steven_L_Intel1
Employee
4,567 Views
This is a common question to those new to Fortran. The Fortran way of doing this is not to call a routine, as in other languages, but to use a special form of I/O statements called "internal I/O". With internal I/O, you specify a character variable in place of the unit number. You can do formatted or list-directed internal I/O. (You can even use character arrays, in which eash array element is considered a "record".)

So in your case you would want something like:

READ (CRECY, '(BN,I13)') intvar

Some people would use list-directed (format *) here, but I recommend against it because list-directed is too permissive in what it will accept. If you know that the input is always a well-formed integer, you can use:

READ (CRECY, *) intvar

instead.
0 Kudos
cldblau
Beginner
4,567 Views
Thanks a lot Steve, it works!!!
0 Kudos
Reply