Re: Difficulty Reading in Constants



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.
.



Relevant Pages

  • Re: Array of objects as array of POD
    ... Convert the class into a typedef. ... Convert all instances of point as an array to type Point. ... A typedef may be safer for legacy code, ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.cpp)
  • Re: Ada.Containers.Vectors - querying multiple elements
    ... >> efficiency reasons and simple implementation of certain classes of algorithms. ... element copy into a buffer, ... legacy code around that takes an array as a parameter. ...
    (comp.lang.ada)
  • Re: Ada.Containers.Vectors - querying multiple elements
    ... > Recursive algorithms on arrays that change their ... > Or are array parameters used for the side effect of passing ... That's why I've been mentioning legacy code: ... level abstraction built on low level building blocks, ...
    (comp.lang.ada)
  • Array of objects as array of POD
    ... While maintaining some legacy code I came across such a class ... This class doesn't have any virtual functions and is aligned by ... Also huge arrays of Points are passed as 3 * array of doubles to ... Any reference to the standard would be greatly appreciated. ...
    (comp.lang.cpp)
  • Re: Difficulty Reading in Constants
    ... The legacy code has parameters which are set in the .f file itself i.e. you modify the text file, ... and since you're reading those values in, they're no longer parameters and, thus, they can no longer be used to dimension the arrays. ... It's not a big problem, but my approach would be to compile the code with g95 after modifying the code to make the arrays in question declared with the attribute ALLOCATABLE, e.g. ... Invalid declaration of or reference to symbol `mdim' at [initially ...
    (comp.lang.fortran)