GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MAT_VARCREATESTRUCT(3) FreeBSD Library Functions Manual MAT_VARCREATESTRUCT(3)

Mat_VarCreateStruct
Creates a structure variable.

#include <matio.h>

matvar_t *
Mat_VarCreateStruct(const char *name, int rank, size_t *dims, const char **fields, unsigned nfields);

The Mat_VarCreateStruct() function creates a structure variable named name that can be written to a MAT file.

If the structure variable was successfully created, a pointer to the variable is returned. Otherwise NULL is returned. The structure variable pointer should be free'd when no longer needed using Mat_VarFree(). The names of the fields are copied in the function, and thus should be released after calling the function if necessary.

This example program opens a MAT file named by the first argument to the program, and writes a structure named a to the file.
#include "matio.h"

int
main(int argc, char **argv)
{
    mat_t    *matfp;
    matvar_t *matvar;
    matvar_t *field;
    const char *fields[2] = {"field1", "field2"};
    double       data1 = 1, data2 = 2;
    size_t       dims[2] = {1, 1};

    matfp = Mat_Open(argv[1], MAT_ACC_RDWR);
    if ( NULL == matfp ) {
        fprintf(stderr, "Error opening MAT file %s0, argv[1]);
        return EXIT_FAILURE;
    }

    dims[0] = 1; dims[1] = 1;
    matvar = Mat_VarCreateStruct("a", 2, dims, fields, 2);
    if ( NULL == matvar ) {
        Mat_Close(matfp);
        return EXIT_FAILURE;
    }

    field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data1,
                MAT_F_DONT_COPY_DATA);
    Mat_VarSetStructFieldByName(matvar, "field1", 0, field);

    field = Mat_VarCreate(NULL, MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, &data2,
                MAT_F_DONT_COPY_DATA);
    Mat_VarSetStructFieldByName(matvar, "field2", 0, field);

    Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_NONE);
    Mat_VarFree(matvar);

    Mat_Close(matfp);
    return EXIT_SUCCESS;
}

Mat_VarCreate(3), Mat_VarSetStructFieldByName(3)
September 12, 2019 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.