Re: Difficulty Reading in Constants
- From: "Jugoslav Dujic" <jdujic@xxxxxxxxx>
- Date: Thu, 20 Oct 2005 17:18:44 +0200
m wrote:
| Hi. I am trying to get some legacy f77 software automated by getting it
| to work with Matlab. The legacy code has parameters which are set in
| the .f file itself i.e. you modify the text file, compile and run. What
| I want is for the legacy code to be compiled as a .exe. Matlab then
| creates a parameter file, calls the legacy .exe, reads/displays the
| output, creates a new parameter file, etc.
|
| My problem is in modifying the legacy code to read the parameters in.
| The beginning of the original code, which is all I am/have, modified is:
|
| c
| integer mdim
....
| c
| c -------------------------------------------------------
| c CONTROL PARAMETERS
| c
| parameter(
| c DESCRIBE DATA
| 1 mdim=2
....
| My change is:
|
| c
| integer mdim
| open(97,file='param.txt',status='old')
| read(97,*)mdim
....
| The part of the errors are:
|
| Matlab_rf.f:20:
| integer mdim,ntrain,nclass,maxcat,ntest,
| 1
| Matlab_rf.f:78: (continued):
| real x(mdim,nsample),xts(mdim,ntest0),v5(mdim),v95(mdim),
| 2
| Invalid declaration of or reference to symbol `mdim' at (2) [initially
|
| As I read it, the program is having a problem with the 'open' statement.
| But I am very new to FORTAN and really have no idea. Any guidance
| would be appreciated.
No, the problem is not (exactly) the "open" statement. The problem is
much more fundamental.
The original code had PARAMETER declaration for mdim et al. That means
that mdim is a constant (PARAMETER in Fortranspeak) and its value cannot
be changed in the program.
Now, you tried to read it from a file instead, and thus had to remove
PARAMETER declaration. However, guess what?
*IN FORTRAN 77, ALL ARRAY DIMENSIONS HAVE TO BE CONSTANT AND KNOWN IN
ADVANCE* (i.e. to be either PARAMETERs or literal constants)
Thus, in F77, you cannot size an array that way (there are some
extensions which will allow it, but not using that particular syntax
anyway).
I'm not sure how your system is exactly set up. You have several options:
1) Use a F90 compiler, add allocatable attribute to the arrays and
ALLOCATE them. There are free fortran compilers at www.g95.org and
gcc.gnu.org (gfortran).
2) The "old" (F77) way was to declare the arrays to be of "maximal
possible" size, and use only a smaller part of it. Thus, you can
use open statement and read the variables, but you still have to
size the arrays with PARAMETERs (i.e. read variables of other
names and use these as real do-loop boundaries & counters).
3) ...<maybe someone has a better idea>
HTH
--
Jugoslav
___________
www.xeffort.com
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
.
- References:
- Difficulty Reading in Constants
- From: m
- Difficulty Reading in Constants
- Prev by Date: Re: Difficulty Reading in Constants
- Next by Date: Re: Difficulty Reading in Constants
- Previous by thread: Re: Difficulty Reading in Constants
- Next by thread: Re: Difficulty Reading in Constants
- Index(es):
Relevant Pages
|
|