Statistics
| Branch: | Revision:

root / src / scave / octaveexport.h @ e1750c09

History | View | Annotate | Download (2.46 KB)

1
//=========================================================================
2
//  OCTAVEEXPORT.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Tamas Borbely
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#ifndef _OCTAVEEXPORT_H_
18
#define _OCTAVEEXPORT_H_
19

    
20
#include <stdio.h>
21
#include <string>
22
#include <set>
23
#include "scavedefs.h"
24
#include "xyarray.h"
25
#include "exception.h"
26

    
27
NAMESPACE_BEGIN
28

    
29
/**
30
 * Exports data in Octave's "save -text" format. This format can be loaded
31
 * into R (r-project.org) as well.
32
 *
33
 * To see the an example, type the following commands in Octave:
34
 * <pre>
35
 *    a = [1 2; 3 4; 5 6]
36
 *    save -text - a
37
 * </pre>
38
 *
39
 * The output:
40
 * <pre>
41
 *  # Created by Octave 2.1.73 ...
42
 *  # name: a
43
 *  # type: matrix
44
 *  # rows: 3
45
 *  # columns: 2
46
 *   1 2
47
 *   3 4
48
 *   5 6
49
 * </pre>
50
 *
51
 * If several variables are saved, the above pattern repeats.
52
 * Floating-point numbers appear to be written with 14 digit precision.
53
 *
54
 * This class exports output vectors as two-column matrices.
55
 */
56
class SCAVE_API OctaveExport
57
{
58
    private:
59
        std::string fileName;
60
        FILE *f;
61
        int prec;
62
        std::set<std::string> savedVars;
63

    
64
//FIXME create separate OctaveFileWriter and OctaveExport (which builds upon the former)
65
    protected:
66
        void openFileIfNeeded();
67
        void writeMatrixHeader(const char *name, int rows, int columns);
68
        void writeDescription(const char *name, const char *description);
69
        void writeString(const char *name, const char *value);
70

    
71
    public:
72
        OctaveExport(const char *fileName);
73
        virtual ~OctaveExport();
74

    
75
        void setPrecision(int prec) {this->prec = prec;}
76
        std::string makeUniqueName(const char *nameHint);
77

    
78
        void saveVector(const char *name, const char *description, const XYArray *vec, int startIndex=0, int endIndex=-1);
79
        void saveVectorX(const char *name, const char *description, const XYArray *vec, int startIndex=0, int endIndex=-1);
80
        void saveVectorY(const char *name, const char *description, const XYArray *vec, int startIndex=0, int endIndex=-1);
81
        void close();
82
};
83

    
84
NAMESPACE_END
85

    
86

    
87
#endif
88

    
89