Error is compiling mex file in MATLAB with intel compiler "Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2010"

I am using a code written for mex interface Fortran/Matlab:
File newstrs_mex written in Fortran (fixed format) is attached.
while compiling viz. mex newstrs_mex.F I am getting following errors and it is aborted:
Building with 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2010'.
Error using mex
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(744): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
call newstrs_mex(nelem, mnode, ndime, nnods, ntotv, max_gpts,
------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(745): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ nstrc, bkflg, ichoic, stress_integration, mat_frame,
---------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(746): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ damage, temp_option, strain_rate_option, temp_rate_option,
-------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(747): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ stiff_option, pce, yes, no, false, true, el, pl, lo, dt,
-------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(748): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ dprod_zero, elcon, edge_face_number, no_mat_prop, no_mat,
-------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(749): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ mtype_array, mcons, lmat1, lmat2, c1, c2, t, delta_Temp,
-----------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(750): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ Temp, darray, privious_dtsnbf_in, Thermal_strain, coord,
------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(751): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ indis,
---------------------------------------------------------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(752): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ tsrbf_in_mex, tsnbf_in, state_in, sigyd_in, dtsnbf_in,
---------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(753): error #5276: Unbalanced parentheses
+ tsrbf_out_mex, tsnbf_out, state_out, sigyd_out, dtsnbf_out)
---------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(769): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: *
<IDENTIFIER>
subroutine newstrs_mex(nelem, mnode, ndime, nnods, ntotv,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(770): error #5082: Syntax error, found '+' when expecting one of: <LABEL>
<END-OF-STATEMENT> ; BLOCK BLOCKDATA PROGRAM MODULE TYPE INTEGER REAL ...
+ max_gpts, nstrc, bkflg1, ichoic1, stress_integration1,
---------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(770): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ max_gpts, nstrc, bkflg1, ichoic1, stress_integration1,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(771): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ mat_frame1, damage1, temp_option1, strain_rate_option1,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(772): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ temp_rate_option1, stiff_option1, pce1, yes1, no1, false1,
------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(773): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ true1, el1, pl1, lo1, dt, dprod_zero, elcon1,
----------------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(774): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ edge_face_number1, no_mat_prop, no_mat, mtype_array1,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(775): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ mcons, lmat1, lmat2, c1, c2, t, delta_Temp, Temp, darray,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(776): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ privious_dtsnbf_in, Thermal_strain, coord, indis,
----------------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(777): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: (
<IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
+ tsrbf_in_mex, tsnbf_in, state_in1, sigyd_in, dtsnbf_in,
--------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(778): error #5276: Unbalanced parentheses
+ tsrbf_out_mex, tsnbf_out, state_out1, sigyd_out, dtsnbf_out)
----------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(778): error #5082: Syntax error, found ')' when expecting one of: ,
<END-OF-STATEMENT> ;
+ tsrbf_out_mex, tsnbf_out, state_out1, sigyd_out, dtsnbf_out)
----------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(804): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 lmat1(nstrc,nstrc), lmat2(nstrc,nstrc),
----------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(806): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 delta_Temp(nelem,max_gpts), Temp(nelem,max_gpts),
--------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(808): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 privious_dtsnbf_in(nelem,max_gpts),
------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(813): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 tsrbf_in_mex(nelem*max_gpts,nstrc),
------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(820): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 tsrbf_out_mex(nelem*max_gpts,nstrc),
-------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(826): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of:
%FILL <IDENTIFIER>
real*8 tsrbf_in(nelem,max_gpts,nstrc),
--------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(871): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
call newstrs1_mex(nelem, mnode, ndime, nnods, ntotv, max_gpts,
------------------------------------------------------------------------------^
D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F(872): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( *
) :: , <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
+ nstrc, bkflg, ichoic, stress_integration, mat_frame, damage,
-----------------------------------------------------------------------------^
C:\Users\rks\AppData\Local\Temp\27123.i(1085): catastrophic error: Too many errors, exiting
compilation aborted for D:\My Work\work\Mech_Therm-2017-05-01\mex_files\newstrs_mex.F (code 1)
Please look into and any help in this regard for compiling the file and further execution will be appreciated from the core of heart!

Answers (1)

For a fixed format source file, the continuation line must have the continuation character in column 6. You have several lines that violate this. It appears that your text file uses tabs to indent the source code and that you expect that '+' character to be in column 6, but this is obviously not happening because of the error you are getting. E.g.,
call newstrs_mex(nelem, mnode, ndime, nnods, ntotv, max_gpts,
+ nstrc, bkflg, ichoic, stress_integration, mat_frame,
+ damage, temp_option, strain_rate_option, temp_rate_option,
+ stiff_option, pce, yes, no, false, true, el, pl, lo, dt,
+ dprod_zero, elcon, edge_face_number, no_mat_prop, no_mat,
+ mtype_array, mcons, lmat1, lmat2, c1, c2, t, delta_Temp,
+ Temp, darray, privious_dtsnbf_in, Thermal_strain, coord,
+ indis,
+ tsrbf_in_mex, tsnbf_in, state_in, sigyd_in, dtsnbf_in,
+ tsrbf_out_mex, tsnbf_out, state_out, sigyd_out, dtsnbf_out)
There are tabs in the above lines, and the '+' characters are not in column 6 as a result. Likely a mismatch between the editor used to create the file (how it interprets a tab) and how the Fortran compiler is interpreting the tab. I never use tabs personally because this can happen. The fix is simply to replace those tabs with hard spaces so that the continuation characters '+' are in column 6. E.g.,
call newstrs_mex(nelem, mnode, ndime, nnods, ntotv, max_gpts,
+ nstrc, bkflg, ichoic, stress_integration, mat_frame,
+ damage, temp_option, strain_rate_option, temp_rate_option,
+ stiff_option, pce, yes, no, false, true, el, pl, lo, dt,
+ dprod_zero, elcon, edge_face_number, no_mat_prop, no_mat,
+ mtype_array, mcons, lmat1, lmat2, c1, c2, t, delta_Temp,
+ Temp, darray, privious_dtsnbf_in, Thermal_strain, coord,
+ indis,
+ tsrbf_in_mex, tsnbf_in, state_in, sigyd_in, dtsnbf_in,
+ tsrbf_out_mex, tsnbf_out, state_out, sigyd_out, dtsnbf_out)
SIDE OBSERVATIONS:
You've got several lines that use literal constants with API calls, like this:
call mxCopyPtrToReal8(x_pr, nelem1, 1) ! Load the data into Fortran arrays
That last argument is a literal 1 integer. Depending on the compiler and settings this could either be an integer*4 (likely) or possibly an integer*8. This may mismatch the actual type that is expected here from the function signature, e.g.,
subroutine mxCopyPtrToReal8(px, y, n)
mwPointer px
real*8 y(n)
mwSize n
That last argument is typed as an mwSize, which could either be an integer*4 or an integer*8 depending on the system you are on and the settings that are being used for the mex compile. It is best to write code that ensures these always match up since you don't get automatic type promotion in Fortran like you do in C/C++. E.g., the following is a better way to code this:
mwSize :: one = 1
:
call mxCopyPtrToReal8(x_pr, nelem1, one) ! Load the data into Fortran arrays
That way the third argument is guaranteed to match the function signature type.
Also, you are not checking the input variables completely. E.g., take this section of code:
msize = 1
m = mxGetM(prhs(msize))
n = mxGetN(prhs(msize))
if(n .ne. 1 .or. m .ne. 1) then ! Check that input # 1 is a scalar
call mexErrMsgIdAndTxt ('MATLAB:newstrs_mex:NonScalar',
+ 'Input # 1 nelem is not a scalar.')
endif
if (mxIsNumeric(prhs(msize)) .ne. 1) then ! Check to see inputs are numeric
call mexErrMsgIdAndTxt ('MATLAB:newstrs_mex:NonNumeric1',
+ 'Input # 1 nelem is not a numeric.')
endif
x_pr = mxGetPr(prhs(msize)) ! Get the Pointers for Input arguments
call mxCopyPtrToReal8(x_pr, nelem1, 1) ! Load the data into Fortran arrays
nelem = int(nelem1)
The above code checks to see that the input variable is numeric, but then jumps to the conclusion that it is a full double when you make the mxCopyPtrToReal8 call. The above code will crash MATLAB if the input happens to be single or int8 or a sparse 0 for instance. I.e., it will pass your numeric test but then crash with invalid memory access on the subsequent mxCopyPtrToReal8 call. You could change your mxIsNumeric check to mxIsDouble and then add in code to see if it is sparse (and handle that case differently). But if the input is simply a scalar I would advise you to just change the way you copy the data to mxGetScalar so that it will work for any numeric type input. You might also check to see that the input is not complex if that matters to you. E.g., simply change these line:
x_pr = mxGetPr(prhs(msize)) ! Get the Pointers for Input arguments
call mxCopyPtrToReal8(x_pr, nelem1, 1) ! Load the data into Fortran arrays
to this:
nelem1 = mxGetScalar(prhs(msize))

Categories

Asked:

on 3 May 2017

Edited:

on 3 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!