Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mat_VarCreate states minimum rank is 2, but 1 seems to work. #259

Open
kargl opened this issue Oct 31, 2024 · 0 comments
Open

Mat_VarCreate states minimum rank is 2, but 1 seems to work. #259

kargl opened this issue Oct 31, 2024 · 0 comments

Comments

@kargl
Copy link

kargl commented Oct 31, 2024

The manual page contains

 The rank argument specifies how many dimensions the data has.  The minimum rank is 2.

The below program sets rank=1 and dims[1] = {1}. When compiled and run with

  % cc -o z b.c -I/usr/local/include -L/usr/local/lib -lmatio -lz
  % ./z z.mat

the file z.mat loaded into octave contains the right variable and value. Is the documentation wrong?

#include <err.h>
#include <stdlib.h>
#include <stdio.h>

#include "matio.h"

#define COMP MAT_COMPRESSION_NONE

void
write_float_scalar(mat_t *mfp, char *xnam, float *xval)
{
   matvar_t *mvar;
   int rank = 1;       // Should a run-time error occur because rank = 1?
   size_t dims[1] = {1};
   mvar = Mat_VarCreate(xnam, MAT_C_SINGLE, MAT_T_SINGLE, rank, dims, xval, 0);
   if (!mvar)
     errx(1, "creating variable: %s", xnam);
   Mat_VarWrite(mfp, mvar, COMP);
   Mat_VarFree(mvar);
}

int
main(int argc, char *argv[])
{
   mat_t *mfp;
   matvar_t *mvar;
   int i,j;
   float  a;
   size_t dims[2];

   if (argc != 2)
      errx(1,"Usage: a filename");

   mfp = Mat_CreateVer(*++argv, NULL, MAT_FT_MAT5);
   if (!mfp)
      errx(1, "cannot create %s", *argv);

   a = 42;
   write_float_scalar(mfp, "a", &a);

   Mat_Close(mfp);

   return 0;
}
@kargl kargl changed the title Mat_VarCreate states minim rank is 2, but 1 seems to work. Mat_VarCreate states minimum rank is 2, but 1 seems to work. Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant