×
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!
  • Students Click Here

*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

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

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
OPEN(unit=19,file=filez, status='old', action='read')
DO
READ(19,*,END=10)
nlines = nlines + 1
END DO
10 CLOSE(19)

allocate(cs(nlines,2))
OPEN(unit=19,file=filez, status='old')
DO i=1,nlines
READ(19,*)cs(i,1), cs(i,2)
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.

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


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