"Fossies" - the Fresh Open Source Software Archive 
Member "pfstools-2.2.0/src/octave/pfsread.cpp" (12 Aug 2021, 3441 Bytes) of package /linux/privat/pfstools-2.2.0.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /**
2 * @brief GNU Octave wrapper - read selected channels from the PFS stream
3 *
4 * This file is a part of PFSTOOLS package.
5 * ----------------------------------------------------------------------
6 * Copyright (C) 2003,2004 Rafal Mantiuk and Grzegorz Krawczyk
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * ----------------------------------------------------------------------
22 *
23 * @author Rafal Mantiuk, <mantiuk@mpi-sb.mpg.de>
24 *
25 * $Id: pfsread.cpp,v 1.1 2005/06/15 13:36:54 rafm Exp $
26 */
27
28 #include <octave/oct.h>
29 #include <octave/oct-stream.h>
30
31 //#include <config.h> // conflicts with config.h from octave distribution
32
33 #include <string>
34
35 #include <pfs.h>
36
37 #define SCRIPT_NAME "pfsread"
38
39 static const char *helpString =
40 #include "pfsread_help.h"
41
42 DEFUN_DLD( pfsread, args, , helpString)
43 {
44 octave_value_list retval;
45
46 int nargin = args.length();
47
48 if( nargin < 1 )
49 {
50 error( SCRIPT_NAME ": Improper usage!");
51 return retval;
52 }
53
54 if( !args(0).is_string() ) {
55 error( SCRIPT_NAME ": expected file name as the first argument!");
56 return retval;
57 }
58
59 FILE *fh;
60 const char *fileName = args(0).string_value().c_str();
61 if( !strcasecmp( "stdin", fileName ) )
62 fh = stdin;
63 else {
64 fh = fopen( fileName, "rb" );
65 if( fh == NULL ) {
66 error( SCRIPT_NAME ": cannot open file for reading!");
67 return retval;
68 }
69 }
70
71 try {
72
73 pfs::DOMIO ctx;
74 pfs::Frame *frame = ctx.readFrame( fh );
75 if( frame == NULL ) { // No more frames
76 for( int i = 0; i < nargin; i++ )
77 retval(i) = std::string( "EOF" );
78 return retval;
79 }
80
81 for( int i = 1; i < nargin; i++ ) {
82 if( !args(i).is_string() ) {
83 error( SCRIPT_NAME ": expected string argument!");
84 break;
85 }
86 const char *channelName = args(i).string_value().c_str();
87 pfs::Channel *channel = frame->getChannel( channelName );
88
89 if( channel == NULL ) {
90 error( SCRIPT_NAME ": channel not found!");
91 break;
92 }
93
94 Matrix mat( channel->getRows(), channel->getCols() );
95 int index = 0;
96 for( int r = 0; r < channel->getRows(); r++ ) // Copy channel data to Octave matrix
97 for( int c = 0; c < channel->getCols(); c++ ) {
98 mat(r,c) = (*channel)(index++);
99 }
100 retval(i-1) = mat;
101 }
102
103 ctx.freeFrame( frame );
104
105 }
106 catch( pfs::Exception ex )
107 {
108 error( "%s: %s", SCRIPT_NAME, ex.getMessage() );
109 }
110
111 if( fh != stdin ) fclose( fh );
112
113 return retval;
114 }