Not really an issue: Add a function Mat_GetFileMode to the library.
Closed this issue · 6 comments
Please add this simple function, because struct's elements are private to the library.
-> to mat.c; and its header to mat.h
int Mat_GetFileMode(mat_t *mat)
{
int rval=-1;
if ( NULL != mat )
rval = mat->mode;
return rval;
}
Another comment:
could you modify mat.c/L.481 to:
mat = Mat_CreateVer(matname, NULL, (enum mat_ft)((MAT_FT_DEFAULT|mode) & 0xfffffffe));
so that Mat_Open(filename,mode) does not fail if the file does not exist, and user requested RDWR access to it.
Along the same lines, can the file mode flags be expanded to:
- append mode (if file does not exist, create it; start writing at the end of it)
- write mode (if file exist, delete its previous content and start new one).
see https://stackoverflow.com/questions/21113919/difference-between-r-and-w-in-fopen: flag "r+" will not create a file for RDWR if it does not exist. - read mode (if file does not exist, report an error - already done with MAT_ACC_RDONLY)
write mode is needed for repeated execution of a script to create the same mat file with certain data in it.
Sure, can do. Feel free to send in a PR if you like.
Pardon my ignorance, but what is PR?
Never mind, PR is for pull request to propose changes.
I have a question for my rlab interface to matio: I crate mat file and put some variables in it, then close it. Can I append to that file and add more content, or not? Consider rlab example: matopen(fn=“myfile.mat”,”rw”); matwritem(fn,x=rand(3,8)); matclose(fn); If I repeat code above with another variable, say y, then only the last data will be in the file.
See #60.
Please add this simple function, because struct's elements are private to the library.
-> to mat.c; and its header to mat.h int Mat_GetFileMode(mat_t *mat) { int rval=-1; if ( NULL != mat ) rval = mat->mode;
return rval; }
Thinking once again I'd rather not expose the file open mode and keep it an internal flag. Even worse, it is used inconsistently within the library and seems to be broken:
Mat_Create4
sets mode toMAT_ACC_RDONLY
, whereasMat_Create5
andMat_Create73
set it toMAT_ACC_RDWR
.Mat_Close
does not reset the mode. HavingMAT_ACC_RDONLY
set to zero as default seems unfortunate.Mat_VarDelete
does not respect the mode, i.e. it is possible to delete a variable from a file that is opened asMAT_ACC_RDONLY
.Mat_VarDelete
seems to be the only location where mode is utilized at all, but only when copying the mode flag from the existing file to the new file.
Another comment:
could you modify mat.c/L.481 to:
mat = Mat_CreateVer(matname, NULL, (enum mat_ft)((MAT_FT_DEFAULT|mode) & 0xfffffffe));
so that Mat_Open(filename,mode) does not fail if the file does not exist, and user requested RDWR access to it.
Mat_Open
is documented to only work on existing files. I'd rather keep it as is.