0

#x #y #z

1 1 1
1 2 4
1 3 9
1 4 16

2 1 1
2 2 4
2 3 9
2 4 16

3 1 1
3 2 4
3 3 9
3 4 16
...

How to read this file to array x, y, z?

where x from first column, y from first column, z from first column of file

I'd tried something already but i had some problem with blank line.

2
  • 1
    If you tried something, you should show your code. You should also explain little bit more what the numbers in the file mean, your explanation is strange. Commented Nov 29, 2014 at 10:10
  • @VladimirF Sir, just use read function to read file in ordinary way to three array variables but problem is happened because of blank lines. and for the meaning is this is just 3d data that have x, y, z data Commented Nov 29, 2014 at 19:39

1 Answer 1

2

Your description is quite incomplete, but if I get your intention right, you can first read the line into a variable and test if it is empty or not

character(200) : line

i = 1
do
  read(unit, '(a)') line
  if (len_trim(line)>0) then
    read(line,*) x(i), y(i), z(i)
    i = i + 1
  end do
end do
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, this totally answer my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.