Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put a while loop in a g77 fortran .f file

Status
Not open for further replies.

stellarowl12

Programmer
Feb 3, 2010
1
US
So I'm a beginning programmer and Fortran pretty much blows my mind. I am trying to edit the dualfoil5.1.f and the dualfoil5.in files from
Basically, in the dualfoil5.in file these lines (line 60):
1 ! lcurs, number of current changes
20.0d0 60.0d0 1 2.0d0 4.70d0 !Discharge at 10A/m2 for 60min, low/high cutoff 2.0/4.7 V

If I wanted 2 current changes I would have to do:
2 ! lcurs
20.0d0 60.0d0 1 2.0d0 4.70d0
0.0d0 60.0d0 1 2.0d0 4.70d0

For 6 current changes, I would have to copy and past those bottom two lines 3 times. In the end, I want to have maybe a 1000 current changes (for short time intervals) so I was thinking I would have to write a while loop into the .in file. However, I think the .f file does not allow me to write a while loop after the lcurs line since it is expecting something else. Can anyone help me with where to put the while loop (should it be inside the .f file? and where exactly should it go so that it can read data from the .in file and compute based on that)

Thanks so much in advance,
Kevin
 
stellarowl12 said:
I was thinking I would have to write a while loop into the .in file
You cannot, because the dualfoil5.in is a data file, not a program source

stellarowl12 said:
I think the .f file does not allow me to write a while loop after the lcurs line since it is expecting something else. Can anyone help me with where to put the while loop (should it be inside the .f file? and where exactly should it go so that it can read data from the .in file and compute based on that)
I thing, that the program does what you want.
Look:
It reads first from the data file dualfoil5.in the value of lcurs here on line 349 in dualfoil5.1.f
Code:
      [COLOR=#804040][b]read[/b][/color] ([COLOR=#ff00ff]1[/color],[COLOR=#804040][b]*[/b][/color]) lcurs [COLOR=#0000ff]! number of current changes[/color]
and after that on the lines 375-377 it reads in a loop the lines which follows after the lcurs line (in dualfoil5.in)
Code:
[COLOR=#0000ff]c[/color]
      [COLOR=#804040][b]do[/b][/color] [COLOR=#ff00ff]555[/color] i [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color], lcurs
      [COLOR=#804040][b]read[/b][/color] ([COLOR=#ff00ff]1[/color],[COLOR=#804040][b]*[/b][/color]) cu(i),tt(i),mc(i),vcutlo(i),vcuthi(i)
  [COLOR=#6a5acd]555[/color] [COLOR=#804040][b]continue[/b][/color]
[COLOR=#0000ff]c     cu(i)      operating current density (A/m2) or cell potential (V)[/color]
[COLOR=#0000ff]c     tt(i)      time (min) or cutoff potential (V)[/color]
[COLOR=#0000ff]c     mc(i) The mode of discharge[/color]
[COLOR=#0000ff]c           0 for potentiostatic[/color]
[COLOR=#0000ff]c           1 for galvanostatic for a given time[/color]
[COLOR=#0000ff]c           2 for galvanostatic to a cutoff potential[/color]
[COLOR=#0000ff]c          -1 for galvanostatic for a given time with tapered[/color]
[COLOR=#0000ff]c             charge/discharge upon reaching cutoff potential[/color]
[COLOR=#0000ff]c          -2 for specified power (in W/m2)[/color]
[COLOR=#0000ff]c          -3 for specified load (in ohm-m2)[/color]
[COLOR=#0000ff]c     vcutlo(i)  lower cutoff potential[/color]
[COLOR=#0000ff]c     vcuthi(i)  upper cutoff potential[/color]
The arrays cu, tt, mc,vcutlo,vcuthi are declared on the lines 179-180 with dimension 200:
Code:
      [COLOR=#2e8b57][b]dimension[/b][/color] terms([COLOR=#ff00ff]221[/color]),tt([COLOR=#ff00ff]200[/color]),cu([COLOR=#ff00ff]200[/color]),tot([COLOR=#ff00ff]200[/color]),mc([COLOR=#ff00ff]200[/color]),taper([COLOR=#ff00ff]200[/color])
      [COLOR=#2e8b57][b]dimension[/b][/color] vcutlo([COLOR=#ff00ff]200[/color]),vcuthi([COLOR=#ff00ff]200[/color])
So the value of lcurs should be maximal 200 and the program (due to above arrays definition) could read up to 200 lines following after the lcur line (in the data file dualfoil5.in)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top