2
* ADIOS is freely available under the terms of the BSD license described
3
* in the COPYING file in the top level directory of this source distribution.
5
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
8
/*=================================================================
9
* adiosclosec.c - Close an ADIOS file
11
* Input: fh, ghs, Verbose
12
* fh: int64 adios file handler
13
* ghs: array of int64 group handlers
14
* Verbose: numeric (double)
16
* $Revision: 1.0 $ $Date: 2009/08/05 12:53:41 $
17
* Author: Norbert Podhorszki <pnorbert@ornl.gov>
18
*=================================================================*/
21
#include "adios_read.h"
22
#include "adios_types.h"
26
mxClassID adiostypeToMatlabClass(int type, mxComplexity *complexity );
27
void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]);
28
char* getString(const mxArray *mxstr);
31
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
33
char msg[512]; /* error messages from function calls */
35
int64_t *ghs, *int64p; /* file and group handlers and temp pointers */
38
errorCheck(nlhs, nrhs, prhs);
40
/*mexPrintf("nrhs=%d nlhs=%d\n", nrhs, nlhs);*/
42
/***********************/
43
/* 0. get verbose parameter first */
44
verbose = (int)mxGetScalar(prhs[2]);
45
if (verbose) mexPrintf("Verbosity level: %d\n", verbose);
47
/* 1. get file handler */
48
int64p = (int64_t *) mxGetData(prhs[0]);
49
if (verbose) mexPrintf("File handler: \"%lld\"\n", *int64p);
51
/* 2. get group handlers */
52
ghs = (int64_t *) mxGetData(prhs[1]);
53
ngroups=mxGetNumberOfElements(prhs[1]);
54
if (verbose) mexPrintf("Number of group handlers: \"%d\"\n", ngroups);
56
for (i=0; i<ngroups; i++) {
57
if (verbose) mexPrintf("Close group handler: \"%lld\"\n", ghs[i]);
58
adios_gclose((ADIOS_GROUP *)ghs[i]);
60
if (verbose) mexPrintf("Close file handler: \"%lld\"\n", *int64p);
61
adios_fclose((ADIOS_FILE *) *int64p);
63
if (verbose) mexPrintf("return from adiosclosec\n");
67
void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]){
68
/* Assume that we are called from adiosread.m which checks the arguments already */
69
/* Check for proper number of arguments. */
72
mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","This function needs exactly 3 arguments: FileHandler, GroupHandlers, Verbose");
75
if ( !mxIsInt64(prhs[0]) ) {
76
mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","First arg must be an int64 handler to an ADIOS file .");
79
if ( !mxIsInt64(prhs[1]) ) {
80
mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","Second arg must be an int64 adios group handler.");
83
if ( !mxIsNumeric(prhs[2]) ) {
84
mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","Third arg must be a number.");
88
mexErrMsgIdAndTxt("MATLAB:adiosclosec:lhs","This function does not have output arguments.");
91
#if !defined(MX_COMPAT_32)
92
/* Make sure that it is safe to cast dim to mwSize when using largeArrayDims.*/
93
if ( dim > MWSIZE_MAX ) {
94
mexErrMsgIdAndTxt("MATLAB:adiosclosec:dimensionTooLarge",
95
"The input dimension, %.0f, is larger than the maximum value of mwSize, %u, when built with largeArrayDims.", dim, MWSIZE_MAX);
101
/** Make a C char* string from a Matlab string */
102
char* getString(const mxArray *mxstr)
106
/* Allocate enough memory to hold the converted string. */
107
buflen = mxGetNumberOfElements(mxstr) + 1;
108
str = mxCalloc(buflen, sizeof(char));
109
/* Copy the string data from string_array_ptr and place it into buf. */
110
if (mxGetString(mxstr, str, buflen) != 0)
111
mexErrMsgTxt("Could not convert string data from the file name.");