1) While experimenting I did notice that IFAUTO is not used in your code - is it actually necessary?
I guess not! It will be a left over from something else.
2) ...
But what did you mean by "Fortran-77 interfaces, required preprocessor, external build script, etc.? I didnt end up using any of these.. At least I dont think I did ...
I just compiled an adjusted version of the Matlab-provided sample .f file - they didnt have the IMPLICIT NONE (oh, mine!!!) and so some integer handles became real values for about 40mins while I was trying to figure out the cause of access violation... argghhh!!!!
Its just personal preference. Given the documentation directs you towards use of the eng* routines that's probably where you should go. But I dislike:
- the fact that the recommended way of building things requires use of the mex build script (previously I recall studying the script and appling the same settings within the VS IDE, but that's a nuisance)
- that all the procedure interfaces are implicit (hence "F77 style" - as opposed to INTERFACE blocks), so argument mismatches will slip though undiagnosed, as you experienced.
- that relevant variable definitions use a non-Fortran syntax (ie mwPointer p, versus something like INTEGER (pointer_kind) p, or TYPE(Pointer) p).
- Related to the above, that your code needs to use the C preprocessor (#include, #define and friends) to mutate variable types and procedure names. Mutated variable names then use nonstandard INTEGER*kind rather than INTEGER(kind) style declarations.
Since the advent of F90, and particularly since the advent of the C interoperability features of F2003, none of the above is required. Things could be so much easier out-of-the-box with a mathworks provided module. But, as you note, given their examples don't have IMPLICIT NONE and are written in fixed form source, it looks like the Mathworks are happy being two decades out of date with respect to Fortran.
But that said, I also hate all the mucking around that you have to do with COM. So I guess you can't win.
Either way wrapper modules are the way to go. I actually started to put something together a while back to use the C libraries that are provided with Matlab from Fortran (using F03's C-interop), but got distracted.