×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# find value in external file and get

## find value in external file and get

(OP)
Hello all of you
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 .

Best regards

JulerS

### RE: find value in external file and get

What have you done so far?

### RE: find value in external file and get

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

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DO
nlines = nlines + 1
END DO
10 CLOSE(19)

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

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.

TTFN
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.

#### Resources

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
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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!