Contact US

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.

Students Click Here

find value in external file and get

find value in external file and get

find value in external file and get

Hello all of you smile
I've got a problem with a fortran code.
I'd like to find a value in the first row of an external file and get the highest value next to it (i.e. 134 -> 4):

130 2 1 CRACK
131 1 1 CRACK
131 2 1 CRACK
132 1 1 CRACK
132 2 1 CRACK
133 1 1 CRACK
133 2 1 CRACK
134 1 1 CRACK
134 2 1 CRACK
134 3 1 CRACK
134 4 1 CRACK
135 1 1 CRACK
135 2 1 CRACK
135 3 1 CRACK
135 4 1 CRACK
Do you have any idea how to solve the problem? It's for a simulation and I'm desperate for finding the solution sad.

Best regards


RE: find value in external file and get

What have you done so far?

RE: find value in external file and get

Hi xwb and IRstuff
So far I open the external file, count the amount of lines in the file and store the first two rows in an Array:

OPEN(unit=19,file=filez, status='old', action='read')
nlines = nlines + 1
10 CLOSE(19)

OPEN(unit=19,file=filez, status='old')
DO i=1,nlines
READ(19,*)cs(i,1), cs(i,2)
In the next step I set the value of a statevariable equal to the value of the second row.
DO i = 1, nlines
IF(cs(i,1).EQ.NOEL) THEN
STATEV(18) = cs(i,2)

So far it's working fine, but the value of the statevariable is just equal to the last point.
If the file would look like this, and I'd like to search for 135:

134 1 1 CRACK
134 2 1 CRACK
134 3 1 CRACK
134 4 1 CRACK
135 1 1 CRACK
135 3 1 CRACK
135 4 1 CRACK
135 2 1 CRACK

I would get the value 2, and not the highest one (4)...
Do you have any idea how to solve the Problem?

Thanks a lot for your help!

RE: find value in external file and get

Please note that student posting is not allowed.

> I think you are calling your columns "rows," which would be confusing to most people.
> Opening the file twice will probably get you a lower grade. A more typical construct is to read lines until EOF, and use a counter to keep track of the number of lines.
> I don't see that you've done anything to test for a maximum value, nor is there anything for keeping track of which "4" to want or should get.

FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

Of course I can. I can do anything. I can do absolutely anything. I'm an expert!

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! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

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