INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Fortran -> how to delete double lines?

Fortran -> how to delete double lines?

(OP)
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?

RE: Fortran -> how to delete double lines?

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: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

RE: Fortran -> how to delete double lines?

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 smile

RE: Fortran -> how to delete double lines?

drop it into excel, hit the delete multiples button...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close