source: trunk/src/octave/rpLibPutFile.cc @ 827

Last change on this file since 827 was 605, checked in by dkearney, 17 years ago

fixed function name for octave put file function
added more error checking in rappture library core for put file functions
adjusted argument list for perl's put file function
added error checking to rapptue buffer

File size: 3.8 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [err] = rpLibPutFile(libHandle,path,fileName,compress,append)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2005-2007
10 *  Purdue Research Foundation, West Lafayette, IN
11 * ======================================================================
12 */
13
14#include "RpOctaveInterface.h"
15
16/**********************************************************************/
17// METHOD: [err] = rpLibPutFile (libHandle,path,fileName,fileType,append)
18/// Set the value of a node.
19/**
20 * Clients use this to set the value of a node.  If the path
21 * is not specified, it sets the value for the root node.
22 * Otherwise, it sets the value for the element specified
23 * by the path.  The value is treated as the text within the
24 * tag at the tail of the path.
25 *
26 * FileName is the name of the file to import into the rappture object
27 * Compress is an integer telling if the provided data should be compressed
28 * (use 1) or left uncompressed (use 0).
29 * Append is an integer telling if this new data should overwrite
30 * (use 0) or be appended (use 1) to previous data in this node.
31 *
32 */
33
34DEFUN_DLD (rpLibPutFile, args, ,
35"-*- texinfo -*-\n\
36[err] = rpLibPutFile(@var{libHandle},@var{path},@var{fileName},@var{compress},@var{append})\n\
37\n\
38Clients use this to set the value of a node.  If the @var{path}\n\
39is not specified (ie. empty string ""), it sets the value for the\n\
40root node.  Otherwise, it sets the value for the element specified\n\
41by the path.  The added data is treated as the text within the \n\
42tag at the tail of the @var{path}.\n\
43\n\
44@var{fileName} is the name of the file to import into the rappture object\n\
45@var{compress} is an integer telling if the provided data should be compressed\n\
46(use 1) or left uncompressed (use 0).\n\
47@var{append} is an integer telling if this new data should overwrite\n\
48(use 0) or be appended (use 1) to previous data in this node.\n\
49\n\
50Error Codes: err = 0 is success, anything else is failure.")
51{
52    static std::string who = "rpLibPutFile";
53
54    // The list of values to return.
55    octave_value_list retval;
56    int err               = 1;
57    int nargin            = args.length ();
58    int libHandle         = 0;
59    std::string path      = "";
60    std::string fileName  = "";
61    unsigned int compress = 0;
62    unsigned int append   = 0;
63    RpLibrary* lib        = NULL;
64
65    if (nargin == 5) {
66
67        if ( args(0).is_real_scalar() &&
68             args(1).is_string()      &&
69             args(2).is_string()      &&
70             args(3).is_real_scalar() &&
71             args(4).is_real_scalar()   ) {
72
73            libHandle = args(0).int_value ();
74            path      = args(1).string_value ();
75            fileName  = args(2).string_value ();
76            compress  = (unsigned int) args(3).int_value ();
77            append    = (unsigned int) args(4).int_value ();
78
79            /* Call the C subroutine. */
80            // the only input that has restrictions is libHandle
81            // all other inputs may be empty strings or any integer value
82            if ( (libHandle >= 0) ) {
83
84                lib = getObject_Lib(libHandle);
85                if (lib) {
86                    lib->putFile(path,fileName,compress,append);
87                    err = 0;
88                }
89                else {
90                    // lib is NULL, not found in dictionary
91                }
92            }
93            else {
94                // libHandle is negative
95                print_usage (who.c_str());
96            }
97        }
98        else {
99            // wrong argument types
100            print_usage (who.c_str());
101        }
102    }
103    else {
104        // wrong number of arguments
105        print_usage (who.c_str());
106    }
107
108    retval(0) = err;
109    return retval;
110}
Note: See TracBrowser for help on using the repository browser.