- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - fortran_eli
Hi,
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
By the way, there are 2 common modes of include files in Fortran. There is the Fortran standard INCLUDE which doesn't take effect during pre-processing, and the cpp style #include which is expanded during pre-processing (a de facto standard, not a Fortran standard). So it is doubly important that you follow their examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is possible that they provide two different files named mat.h, one for Fortran and one for C. Would you please attach the mat.h you think is being used? If it mostly looks like Fortran but has lines starting with #, you need to enable the preprocessor in the Fortran project properties, Preprocessor property page.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - fortran_eli
Hi,
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
I'm a Fortran-newbie and need to include a file 'mat.h' in my Fortran code (ifort with Visual Studio). This file is provided by Mathworks to enable Fortran to commands for generating Matlab data-files (.mat).
'mat.h' ist expilcitly made to be included in C or Fortran code. I'm sure that in C it won't be to hard to do so. But with Fortran i get "bad precompiler" errors.
So my question is how to make ifort compile the mixed code properly?
Thank you very much and best regards,
Eli
mat.h is only for C or C++ programs - it contains C source code such as function and type declarations that a Fortran compiler would not understand.
The name of the file you #include for fortran sources is "fintrf.h". This file only contains preprocessor "instruction" lines, such as "#define MWPOINTER INTEGER*4". You will need to enable the preprocessor in Intel Fortran in order to compile source files that have the relevant #include "fintrf.h" line.
Your Matlab installation and documentation includes a number of fortran source code examples.
(Rant about the lack of a modern Fortran interface into Matlab (almost) suppressed).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - IanH
Thank you all for your quick and very professional answers to my question.
The inclusion of the right file for Fortran code fintr.h (instead of mat.h which is for C) and setting up the ifort preprocessor and the linker in MS Visual Studio (switch on preprocessor, add directories of additional MS and Matlab libraries, add addit. dependencies) finally solved it. Mathworks really should improve their Matlab documantation in that topic - it was no help at all but confusing.
Cheers
The inclusion of the right file for Fortran code fintr.h (instead of mat.h which is for C) and setting up the ifort preprocessor and the linker in MS Visual Studio (switch on preprocessor, add directories of additional MS and Matlab libraries, add addit. dependencies) finally solved it. Mathworks really should improve their Matlab documantation in that topic - it was no help at all but confusing.
Cheers

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page