Re: how to "translate" dynamic array in FORTRAN 90 to Java code?



Shawn wrote:
Hi,

I am translating a Fortran program to Java code. Starting FORTRAN 90, an
array size can be un-specified, for example:

DIMENSION PS(*)

is an array with size unspecified. On the run-time, its size can be
increased automatically if needed.

Previously, I use Object array in Java to translate FORTRAN array. But
now, array in Java have to be fixed size.

If I use collections in Java, like Vector or ArrayList, the problem is,
as stated in my posting previously and copied to below:


Vector vec = new Vector();
vec.add(0, new Integer(4));
vec.add(1, new Double(4.4));
vec.add(2, "How are you?");
vec.add(5, "morning");

The last one is one error and the program cannot run. I purposely
skipped a couple positions.
There is a reason that I need skipping: I am "translating" Fortran code
to Java. In the original Fortran code, it takes an array several item
positions to hold a long string, like "How are you?". In Java, it only
needs one item position to hold it. I hope to keep index in Fortran and
Java correspondent, so I need skipping to let several item positions
unused. But the program will not run now.

Maybe I need:
vec.add(3, null);
vec.add(4, null);

?

Thank you again for your help.

Hi Shawn,

I think both you and some of the posters responding may have a
misunderstanding about
the meaning of the Fortran specification.

There are two kinds Fortran array specifications where the size is not
given.

The notation

real array(*)

is normally used when the array is a parameter of a subroutine, and the
real dimension will be specified in the argument...

E.g.,

program main
real myArray(100)
call sub(myArray)
end

subroutine sub(array)
real array(*)
...
end

This is exactly analagous to

void method() {
float[] myArray = new float[100];
sub(myArray);
}
void sub(float[] array) {
...
}

Fortran also has dynamically allocated arrays where the
size is determined at run time and the array
can be reallocated. I'm a bit rusty on the syntax here but it's
something like.

real, allocatable :: myArray(:)
...
allocate(myArray(2*n))
...
deallocate(myArray)
....
allocate(myArray(3*n))
...

This corresponds in Java to something like:

float[] myArray;
...
myArray = new float[2*n];
...
...
myArray = new float[3*n];
...



I'm pretty sure that anything like:

program main
real myArray(*)
myArray(3) = 3.14
end
or
real myArray(3)
myArray(5) = 25
end


are illegal in all versions of the Fortran standard. Neither Fortran
nor Java provides for automatic extensions of arrays when
a user asks for an element beyond the end of the allocated array.

So your job in translating from Fortran to Java may be a bit easier
than you have been led to believe...

Regards,
Tom McGlynn

.



Relevant Pages

  • Re: A simple Vector and generics question
    ... There is a reason that I need skipping: I am "translating" Fortran code to Java. ... Isn't a Java Objectarray a better match for a Fortran array. ... this one element shift problem using Vector. ...
    (comp.lang.java.programmer)
  • Re: how to "translate" dynamic array in FORTRAN 90 to Java code?
    ... I am translating a Fortran program to Java code. ... Starting FORTRAN 90, an array size can be un-specified, for example: ... I use Object array in Java to translate FORTRAN array. ... There is a reason that I need skipping: I am "translating" Fortran code to Java. ...
    (comp.lang.java.programmer)
  • Re: why cannot assign to function call
    ... You are mistaken (except perhaps in the Fortran case, which is an oddball by modern standards, and I don't know Perl well enough to judge). ... Java would also have the same semantics, though my Java is too rusty to get the syntax right without actually trying it. ... If you can find a language where an array variable is NOT a reference, then that language is either a dinosaur or some weird academic oddity. ...
    (comp.lang.python)
  • how to "translate" dynamic array in FORTRAN 90 to Java code?
    ... I am translating a Fortran program to Java code. ... Starting FORTRAN 90, an array size can be un-specified, for example: ... I use Object array in Java to translate FORTRAN array. ... There is a reason that I need skipping: I am "translating" Fortran code to Java. ...
    (comp.lang.java.programmer)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (comp.lang.fortran)