forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Grab parameters from external file

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
LouisT



Joined: 29 Feb 2008
Posts: 4

PostPosted: Sat Mar 01, 2008 12:58 am    Post subject: Grab parameters from external file Reply with quote

Hi,

I'm new to Fortran and programming in general. I'm interested in running simulations in FORTRAN. One of the things is that I need to run the code multiple times using different starting parameters. Is there any way I can automate this? For example, grabbing parameters from an external file.

Thanks! All suggestions would be greatly appreciated.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Sat Mar 01, 2008 9:16 am    Post subject: Reply with quote

You can read data from a file using stanard Fortran READ statements.
Then you can change the contents of the data file for each run.

As a refinement you could supply the name of the data file as a parameter on the command line for the executable and then read from the corresponding file. Then you could have separate files for each data set.

See the FTN95.chm under READ, GET_COMMAND and GET_COMMAND_ARGUMENT.
Back to top
View user's profile Send private message AIM Address
LouisT



Joined: 29 Feb 2008
Posts: 4

PostPosted: Sun Mar 16, 2008 8:00 pm    Post subject: Reply with quote

Thanks Paul! That was really helpful. The next question I have is, how can I compile the project/program given that I have not specified the character buffer beforehand?

E.g., CALL getarg(1,buffer)
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Mon Mar 17, 2008 8:47 am    Post subject: Reply with quote

You will need to define a CHARACTER variable for "buffer" and give it a length that is sufficient for the maximum size (say 256).
Back to top
View user's profile Send private message AIM Address
LouisT



Joined: 29 Feb 2008
Posts: 4

PostPosted: Mon Mar 17, 2008 7:19 pm    Post subject: Reply with quote

Hi, Paul, thanks. I did declare the buffer as a character variable beforehand. The issue is, when I compile the program, the error message appears:

C:\FORTRAN\CAT.F90(28) : error 573 - Missing expression

Although I have declared the variable, I did not input any arguments because the arguments are to be read in from the terminal/console. How can I specify this so it can compile?

Thanks!
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Mon Mar 17, 2008 7:21 pm    Post subject: Reply with quote

Can you post some code to look at?
Back to top
View user's profile Send private message AIM Address
LouisT



Joined: 29 Feb 2008
Posts: 4

PostPosted: Fri Mar 21, 2008 5:46 pm    Post subject: Reply with quote

Hi Paul,
Here is a sample code. So when I run the executable, I can append the parameters to the execute command and the program will use those parameters. Thanks for your help!

~~~~~~~~
PROGRAM X
IMPLICIT NONE
INTEGER a1, a2
CHARACTER *20 buffer

CALL getarg(1,buffer)
READ(buffer,*), a1
CALL getarg(2,buffer)
READ(buffer,*), a2

END PROGRAM X
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Sat Mar 22, 2008 9:14 am    Post subject: Reply with quote

Louis

All you need to do is take out a couple of commas...

Code:
PROGRAM X
IMPLICIT NONE
INTEGER a1, a2
CHARACTER *20 buffer

CALL getarg(1,buffer)
READ(buffer,*) a1
CALL getarg(2,buffer)
READ(buffer,*) a2

END PROGRAM X
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group