~ubuntu-branches/ubuntu/utopic/adios/utopic

« back to all changes in this revision

Viewing changes to wrappers/matlab/adiosclosec.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-12-09 15:21:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131209152131-jtd4fpmdv3xnunnm
Tags: 1.5.0-1
* New upstream.
* Standards-Version: 3.9.5
* Include latest config.{sub,guess} 
* New watch file.
* Create libadios-bin for binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
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.
 
4
 *
 
5
 * Copyright (c) 2008 - 2009.  UT-BATTELLE, LLC. All rights reserved.
 
6
 */
 
7
 
 
8
/*=================================================================
 
9
 * adiosclosec.c - Close an ADIOS file
 
10
 *
 
11
 * Input: fh, ghs,  Verbose
 
12
 *    fh:       int64 adios file handler
 
13
 *    ghs:      array of int64 group handlers
 
14
 *    Verbose:  numeric (double)
 
15
 *
 
16
 * $Revision: 1.0 $  $Date: 2009/08/05 12:53:41 $
 
17
 * Author: Norbert Podhorszki <pnorbert@ornl.gov>
 
18
 *=================================================================*/
 
19
 
 
20
#include "mex.h"
 
21
#include "adios_read.h"
 
22
#include "adios_types.h"
 
23
 
 
24
static int verbose=0;
 
25
 
 
26
mxClassID adiostypeToMatlabClass(int type, mxComplexity *complexity );
 
27
void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]);
 
28
char* getString(const mxArray *mxstr);
 
29
 
 
30
 
 
31
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
 
32
    int status;
 
33
    char msg[512];                               /* error messages from function calls */
 
34
    mwSize ngroups;
 
35
    int64_t *ghs, *int64p;               /* file and group handlers and temp pointers */
 
36
    int i;
 
37
 
 
38
    errorCheck(nlhs, nrhs, prhs);
 
39
 
 
40
    /*mexPrintf("nrhs=%d  nlhs=%d\n", nrhs, nlhs);*/
 
41
    
 
42
    /***********************/
 
43
    /* 0. get verbose parameter first */
 
44
    verbose = (int)mxGetScalar(prhs[2]);
 
45
    if (verbose) mexPrintf("Verbosity level: %d\n", verbose);
 
46
 
 
47
    /* 1. get file handler */
 
48
    int64p = (int64_t *) mxGetData(prhs[0]);
 
49
    if (verbose) mexPrintf("File handler: \"%lld\"\n", *int64p);
 
50
 
 
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);
 
55
 
 
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]);
 
59
    }
 
60
    if (verbose) mexPrintf("Close file handler: \"%lld\"\n", *int64p);
 
61
    adios_fclose((ADIOS_FILE *) *int64p);
 
62
 
 
63
    if (verbose) mexPrintf("return from adiosclosec\n");
 
64
}
 
65
 
 
66
 
 
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. */
 
70
    
 
71
    if ( nrhs != 3 ) {
 
72
        mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","This function needs exactly 3 arguments: FileHandler, GroupHandlers, Verbose");
 
73
    }
 
74
    
 
75
    if ( !mxIsInt64(prhs[0]) ) {
 
76
        mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","First arg must be an int64 handler to an ADIOS file .");
 
77
    } 
 
78
    
 
79
    if ( !mxIsInt64(prhs[1]) ) {
 
80
        mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","Second arg must be an int64 adios group handler.");
 
81
    } 
 
82
 
 
83
    if ( !mxIsNumeric(prhs[2]) ) {
 
84
        mexErrMsgIdAndTxt("MATLAB:adiosclosec:rhs","Third arg must be a number.");
 
85
    } 
 
86
    
 
87
    if ( nlhs > 0 ) {
 
88
        mexErrMsgIdAndTxt("MATLAB:adiosclosec:lhs","This function does not have output arguments.");
 
89
    }
 
90
    
 
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);
 
96
    }
 
97
#endif
 
98
 }
 
99
 
 
100
 
 
101
/** Make a C char* string from a Matlab string */
 
102
char* getString(const mxArray *mxstr) 
 
103
{
 
104
    mwSize buflen;
 
105
    char   *str;
 
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.");
 
112
    return str;
 
113
}
 
114