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

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
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!
RE: find value in external file and get
RE: find value in external file and get
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
> 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!