I'm in the process of translating some C code to Fortran & I have run across some instances which have me scratching my head as to how to properly convert the C to Fortran.
Example #1-
typedef struct fileheadtype
{
char version[128];
char notes[256];
} FileHeadType;
typedef struct linetype
{
LineInfo info;
float latlon[50];
} LineType;
typedef struct vg_dbstruct
{
VG_HdrStruct hdr;
union
{
FileHeadType fhed;
LineType lin;
} elem;
} VG_DBStruct;
I understand the 'fileheadtype' and 'linetype' structures but I don't understand what the vg_dbstruct is doing, how it relates to the other two structures and how to properly translate to Fortran.
Example #2-
typedef struct breakpt_t { /* break point structure */
float lat;
float lon;
char breakPtName[ 100 ];
} Breakpt_T;
enum tca_adv_t {
WATCH = 0,
WARNING = 1
};
typedef struct tcaww_t {
enum tca_adv_t advisoryType;
int numBreakPts;
struct breakpt_t *breakPnt;
} TcaWw_T;
Here, i don't understand what the enumeration operation is doing in the tcaww_t struct nor the "breakpt_t" struct is doing and...how to translate to Fortran.
Any help is greatly appreciated Jeff
Typedef is something Fortran doesn't have. It enables you to call some type or structure by a different name. You can even do
typedef int myint;
and use myint as name of a type
myint i;
With the example one you can then use
FileHeadType fh;
instead of
struct fileheadtype fh;
which will translate to type(fileheadtype).
In Fortran you always need to use the original type, whether it is integer or type(typename).
The enumerations exist in Fortran for C interoperability, but if you don't want to call C, but you just do a translation in Fortran spirit, you can just use integers:
integer, parameter :: WATCH = 0, WARNING = 1
Unions are not part of Fortran, you must study the intention of the code and either use two separate components, or use transfer() or equivalence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With