Fortran equivalence statements

I am migrating an application from fortran to JAVA. I was wondering how to convert if equivalence between two different data types.

If I type cast, can I lose data or pass this as an array of bytes?

+2
source share
2 answers

You need to fully understand the old FORTRAN code. EQUIVALENCE uses memory without converting values ​​between different data types. Perhaps the programmer saved memory using overlapping arrays that were not used at the same time, and EQUIVALENCE can be ignored. Perhaps they were doing something very complex, based on the binary representation of a particular platform, and you would need to figure out what they were doing.

There is very little reason to use EQUIVALENCE in modern Fortran. In most cases, when a bit needs to be transferred from one type to another without conversion, the internal TRANSFER function should be used instead.

+3
source

From http://www.fortran.com/F77_std/rjcnf0001-sh-8.html#sh-8.2 :

The EQUIVALENCE statement is used to specify the sharing of storage units by two or more objects in a software module. This causes a union of objects that share storage units.

If equivalent objects have different data types, the EQUIVALENCE statement does not cause type conversion or implies mathematical equivalence. If the variable and the array are equivalent, the variable does not have the properties of the array and the array does not have the properties of the variable.

So, consider the reason it was EQUIVALENCE 'd in Fortran code, and decide from there how to proceed. There is not enough information in your question to evaluate the intention or the best way to transform it.

+2
source

Source: https://habr.com/ru/post/1387306/


All Articles