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.
29281 Discussions

determining the number of readed values

dnoack
Beginner
665 Views

Hello,

in a text file each line contains an arbitrary number of values. I would like to read this file line by line and determining the number ofvalues in every line.

Does anyone know a simple method for this problem.

Thanx in advance.

dnoack

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
665 Views

Look in the documentation regarding nonadvancing I/O (ADVANCE='NO')and use of EOR=nnn or IOSTAT=iStatus.

Or, depending on your data, you could preload your input arraywith a value that will never be in your input. After reading a record check for your preload value.

Jim Dempsey

0 Kudos
greldak
Beginner
665 Views

Assuming your lines are of a reasonable length I'd read the line into a string long enough to hold your longest expected line

If you have no seperators the number of values is simply obtained from the length of the string trimmed to remove white space at the end divided by the size of your value.

If you have seperators - commas, spaces whatever count them, the number of values will be the same as your count if there is a seperator after the final value or 1 more if not

You can then use internal IO to convert obtain the values from the string

0 Kudos
Reply