Thank you for your effort in the MATIO library and I have successfully compiled this library using ifort and gcc as well as a gfortran/gcc on ALMAlinux 9.3. I did not manage to compile it with icc and ifort (newest API version).
I have a test program for writing a MAT file but I can't get this to work and I guess my knowledge of c is reason for this but I have not found a solution for this (after extensive search).
The test program :
++++++++++++++++++++++++++++++++++++++++++
Thanks for your efforts and report. Unfortunately Fortran interface is not tested. I gave up on https://github.com/tbeu/matio/issues/51 as I failed. (That#s why it says "help wanted".) I would appreciate if we could set up a CI stage to build and run the Fortran interface.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
programtest_mat_fileuse,intrinsic::iso_c_bindingimplicitnonetype(c_ptr)::matfilecharacter(kind=c_char,len=*),parameter::filename='zzz.mat'//c_null_charcharacter(kind=c_char,len=*),parameter::header='HEADERSTRING'//c_null_charcharacter(kind=c_char,len=*),parameter::varname='reeks'//c_null_charreal(c_double),target,dimension(1000)::dinteger::itype(c_ptr)::matvarinteger(c_size_t),dimension(2)::dimsinteger,parameter::MAT_FT_MAT5=256integer,parameter::COMPRESSION_NONE=0integer,parameter::MAT_T_DOUBLE=9integer,parameter::MAT_C_DOUBLE=6interfacefunctionMat_CreateVer(filename,header,mat_file_ver)bind(c,name="Mat_CreateVer")import::c_int,c_ptr,c_chartype(c_ptr)::Mat_CreateVercharacter(kind=c_char),intent(in)::filename(*)character(kind=c_char),intent(in)::header(*)integer(c_int),value::mat_file_verendfunctionMat_CreateVerfunctionMat_VarCreate(name,class_type,data_type,rank,dims,data,opt)bind(c,name="Mat_VarCreate")import::c_int,c_ptr,c_char,c_size_ttype(c_ptr)::Mat_VarCreatecharacter(kind=c_char),intent(in)::name(*)integer(c_int),value::class_type,data_type,rankinteger(c_size_t),intent(in)::dims(*)type(c_ptr),value::datainteger(c_int),value::optendfunctionMat_VarCreatesubroutineMat_VarWrite(matfp,matvar,compression)bind(c,name="Mat_VarWrite")import::c_int,c_ptrtype(c_ptr),value::matfptype(c_ptr),value::matvarinteger(c_int),value::compressionendsubroutineMat_VarWritesubroutineMat_Close(mat)bind(c,name="Mat_Close")import::c_ptrtype(c_ptr),value::matendsubroutineMat_Closeendinterface!Initializedatadoi=1,1000d(i)=real(i,kind=c_double)enddo!CreateMATfilematfile=Mat_CreateVer(filename(1:1),header(1:1),MAT_FT_MAT5)if(.not.c_associated(matfile))thenprint*,"Error: Could not create MAT file."stopendif!Definedimensionsdims=[size(d,1,kind=c_size_t),1_c_size_t]!CreateMATvariablematvar=Mat_VarCreate(varname(1:1),MAT_C_DOUBLE,MAT_T_DOUBLE,2,dims,c_loc(d),0)if(.not.c_associated(matvar))thenprint*,"Error: Mat_VarCreate returned a null pointer."callMat_Close(matfile)stopendif!WriteMATvariabletofilecallMat_VarWrite(matfile,matvar,COMPRESSION_NONE)!CloseMATfilecallMat_Close(matfile)print*,"MAT file successfully written."endprogramtest_mat_file
Last edit: tbeu 2025-04-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for reporting. I notice that the test_mat_file.f90 does not used the provided fartran interface in ./matio/src/fortran at all and instead uses own binding interfaces.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your effort in the MATIO library and I have successfully compiled this library using ifort and gcc as well as a gfortran/gcc on ALMAlinux 9.3. I did not manage to compile it with icc and ifort (newest API version).
I have a test program for writing a MAT file but I can't get this to work and I guess my knowledge of c is reason for this but I have not found a solution for this (after extensive search).
The test program :
++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++
COMPILING & RUNNING :
$ gfortran -o xx ww.f90 -I/apps/MATIO/matio-1.5.26/include -L/apps/MATIO/matio-1.5.26/lib -lmatio
$ xx
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
0 0x2B66C14266D7
1 0x2B66C1426D1E
2 0x2B66C1EB93FF
3 0x2B66C1296FF1
4 0x400905 in MAIN__ at ww.f90:?
Segmentation fault
or with ifort
$ xx
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
xx 0000000000405AEA Unknown Unknown Unknown
libc.so.6 000014AE66E54DB0 Unknown Unknown Unknown
libc.so.6 000014AE66E94E06 ftello Unknown Unknown
libmatio.so.11.1. 000014AE6732320B Mat_GetDir Unknown Unknown
libmatio.so.11.1. 000014AE67323151 Mat_VarWrite Unknown Unknown
xx 0000000000404C3E MAIN__ 66 ww.f90
xx 0000000000404AE2 Unknown Unknown Unknown
libc.so.6 000014AE66E3FEB0 Unknown Unknown Unknown
libc.so.6 000014AE66E3FF60 __libc_start_main Unknown Unknown
xx 00000000004049E9 Unknown Unknown Unknown
My main question - is this an error in compiling or is there something wrong in the fortran code calling C-routines?
And excuse me for the typo in the title..
Last edit: tbeu 2025-04-07
Thanks for your efforts and report. Unfortunately Fortran interface is not tested. I gave up on https://github.com/tbeu/matio/issues/51 as I failed. (That#s why it says "help wanted".) I would appreciate if we could set up a CI stage to build and run the Fortran interface.
it is working now, see the correct code below:
Last edit: tbeu 2025-04-07
Thanks for reporting. I notice that the test_mat_file.f90 does not used the provided fartran interface in ./matio/src/fortran at all and instead uses own binding interfaces.