Latex Tables from Fortran II

There seems to be interest out there in the code for generating Latex tables from Fortran that I described in an earlier post, so I went back and took a look at it again. I realized, not unexpectedly, that I could make some improvements, so I did.

One improvement that I made is to make the call to writing out the table generic. That way, we don’t have to rememember the specific subroutine calls. I left the specific routines public, so old code does not need to be modified. Now, a table from an array of real, double precision or integers can be created with a generic call:

      TYPE(LatexTableMaker) :: TMaker
     REAL(KIND(1.0d0)) :: tableData(4,5) ! Stored as (rows,columns)

      CALL TMaker % writeTableAsLatex(tableData = tableData, &
                                                     headers   = [“first ”,”second”,…,”last  ”],   &
                                                     caption   = “Prize Winning Results",   &
                                                     label     = “tab:PWR",     &
                                                     fileUnit  = 6)

Similarly, you can use tableColumns the same way:

      CALL TMaker % writeTableAsLatex(                              &
                                                 tableColumnsArray = arrayOfColumns,    &
                                                 caption           = caption, &
                                                 label             = label, &
                                                 fileUnit          = 6)

On the other hand, I did make one change that requires changes to existing code. I changed newLatexTableColumn to be called constructLatexTableColumn because I think that name more accurately describes what the procedure does. See the example code for the new calls.

Finally, I added the ability to transpose the table by writing the columns as rows instead. This is how I’ll write non-homogeneous rows. Transposing is done by including the optional “transpose” argument in the call:

      CALL TMaker % writeTableAsLatex(                              &
                                                 tableColumnsArray = arrayOfColumns,    &
                                                 caption           = caption, &
                                                 label             = label, &
                                                 fileUnit          = 6, &
                                                 transpose   = .TRUE.)

As before, you can get the code from my “Free Fortran” page and the manual can be found here.

© Nocturnal Aviation Software 2011-2017. Mac and Mac OS are trademarks of Apple Inc., registered in the U.S. and other countries. iMac drawing by dinodigital. All other trademarks are the property of their respective owners. Privacy Policy. Press Releases.