## toolFortran

toolFortran — introduces routines to read the binary Fortran data format.

## Synopsis

    enum        EndianId;
    gboolean    toolFortranRead_character       (char *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);
    gboolean    toolFortranRead_double          (double *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);
    gboolean    toolFortranRead_flag            (unsigned int *nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness);
    gboolean    toolFortranRead_integer         (unsigned int *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);
    gboolean    toolFortranRead_real            (float *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);
    gboolean    toolFortranTest_endianness      (unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId *endianness);

## Description

In Fortran binary data are written inside tags. These tags give the size to the data that are between. The routines in this module can read these tags and the data inside. One must know the endianness of the file and the kind of data to be read (integer, float, double...). If the first tag is known, one can test the endianness of the file calling `toolFortranTest_endianness()`.

The size of the tag (32 bits or 64 bits) is not modifiable for the moment and is fixed at 32 bits. This may be changed in the futur with the same kind of things that for endianness.

## Details

### enum EndianId

    typedef enum
      {
        KEEP_ENDIANNESS,
        CHANGE_ENDIANNESS
      } EndianId;

Thiese ids are used when reading a multi-bytes information from a binary file.

`KEEP_ENDIANNESS` | read a file without inverting records.
`CHANGE_ENDIANNESS` | read a file inverting records.

### toolFortranRead_character ()

    gboolean    toolFortranRead_character       (char *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);

Read an array of characters from a fortran record. The endianness is required to read the Fortran flag.

`var` : | an allocated array of char ;
`nb` : | the size of the array `var` ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | reverse or not the order of multi-bytes ;
`testFlag` : | if TRUE, read start and stop flags and test their values.
Returns : | TRUE if everything went right.

### toolFortranRead_double ()

    gboolean    toolFortranRead_double          (double *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);

Read an array of doubles from a fortran record.

`var` : | an allocated array of double ;
`nb` : | the size of the array `var` ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | reverse or not the order of multi-bytes ;
`testFlag` : | if TRUE, read start and stop flags and test their values.
Returns : | TRUE if everything went right.

### toolFortranRead_flag ()

    gboolean    toolFortranRead_flag            (unsigned int *nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness);

Read the flag of a record (a 32bits integer).

`nb` : | a location t store the value of the flag ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | reverse or not the order of multi-bytes.
Returns : | TRUE if everything went right.

### toolFortranRead_integer ()

    gboolean    toolFortranRead_integer         (unsigned int *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);

Read an array of integers from a fortran record.

`var` : | an allocated array of int ;
`nb` : | the size of the array `var` ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | reverse or not the order of multi-bytes ;
`testFlag` : | if TRUE, read start and stop flags and test their values.
Returns : | TRUE if everything went right.

### toolFortranRead_real ()

    gboolean    toolFortranRead_real            (float *var,
                                                 unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId endianness,
                                                 gboolean testFlag);

Read an array of reals from a fortran record.

`var` : | an allocated array of float ;
`nb` : | the size of the array `var` ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | reverse or not the order of multi-bytes ;
`testFlag` : | if TRUE, read start and stop flags and test their values.
Returns : | TRUE if everything went right.

### toolFortranTest_endianness ()

    gboolean    toolFortranTest_endianness      (unsigned int nb,
                                                 FILE *flux,
                                                 GError **error,
                                                 EndianId *endianness);

Read a flag and compare the value with `nb` for little and big endian. It return the value of endianness to be used after. The file is rewind after the call.

`nb` : | the value of the flag to read ;
`flux` : | a pointer on an opened file ;
`error` : | a pointer to an error location ;
`endianness` : | a location to store the endianness.
Returns : | TRUE if everything went right.