Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran -> how to delete double lines?

Status
Not open for further replies.

JulerS89

Materials
Aug 1, 2014
5
Hello everyone! I have trouble to deal with a text file like this:

1.21781250000000 47 0
1.21781250000000 48 0
1.21781250000000 49 0
1.21781250000000 50 0
1.21781250000000 51 0
1.21781250000000 52 0
1.21781250000000 53 0
1.21781250000000 54 0
1.21781250000000 47 0
1.21781250000000 48 0
1.21781250000000 49 0
1.21781250000000 50 0
1.21781250000000 51 0
1.21781250000000 52 0
1.21781250000000 53 0
1.21781250000000 54 0
1.21781250000000 47 0
1.21781250000000 48 0
1.21781250000000 49 0
1.21781250000000 50 0
1.21781250000000 51 0
1.21781250000000 52 0
1.21781250000000 53 0
1.21781250000000 54 0

I'd like to delete the double lines automatically. Can someone give me a tip or code how to erase them with fortran?

 
Replies continue below

Recommended for you

In Fortran I'd do it by brute force, working down the list. It would be more robust to mark lines for deletion rather than actually deleting them.

You could do a sort instead, but you still need to check whether adjacent lines are identical.



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Do you mean to delete "Duplicate" lines?

It should be very simple to do in fortran (any version from 77 to 2008). Here's a simple pseudo-code-logic:

Allocate a character string array, a:)), at lease big enough to store all lines of the file.
Read each and every line into a character string array, a(1:???)
Now... look through each line (stored in a:)) looking for duplicate lines)

Do i = 1 to the total # of lines
Do j = i+1 to the total # of lines
If( a(i) == a(j) )Then
! you will be wanting to eliminate the jth line
End If
End Do
End Do

Now... write all of the non-eliminated lines back out to your file and re-save it.

The above is not the most efficient way to do it. However, if you don't have many thousands of lines and you don't have to do the operation over and over again... it's very simple and will execute very quickly.

Dan :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor