[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How can I declare an "uint8 RowVector"?
From: |
Roberto Vidmar |
Subject: |
How can I declare an "uint8 RowVector"? |
Date: |
Mon, 16 Jan 2006 09:09:17 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
Hi to all,
I need to read and process a binary file made of 553 byte records.
Every record contains many data and, among these, 3 arrays of uint8 values.
First I wrote an octave function to store every record in an octave
structure using fread and uint8 convertion funcion:
...
RpfRecord.ret2 = uint8(fread(rpfid, 220, 'uint8'));
...
...but this is far to slow for my purpouses so I tried to move the
reading part into a dynamic loadable function written in C++ (but I'm
NOT a C++ programmer, I know only non-object oriented languages).
My C++ function opens the file, reads it, and returns a structure, at
preset just a single record not yet a vector. The code follows:
#include <octave/oct.h>
#include <octave/ov-struct.h>
#include <rpf-a.h>
DEFUN_DLD (readrpf, args, ,
"Read RPF file into RPF structure.\n\
\n\
Reference:\n\
\n\
Roberto Vidmar Jannuary 2006.\n\
Last Update: 20060111.")
{
octave_value_list retval;
rpf_record_t rpf_record;
RowVector t0(40); # I know this declares an array of double,
but I'm not able to declare an uint8 array.....
FILE * rpf_fp;
int bytesread=0;
rpf_fp=fopen("outfile.rpf.recs", "r");
bytesread=fread(&rpf_record.gpstime, 1,
sizeof(rpf_record.gpstime), rpf_fp);
bytesread+=fread(&rpf_record.pulsecount, 1,
sizeof(rpf_record.pulsecount), rpf_fp);
bytesread+=fread(&rpf_record.range, 1,
sizeof(rpf_record.range), rpf_fp);
bytesread+=fread(&rpf_record.intensity, 1,
sizeof(rpf_record.intensity), rpf_fp);
bytesread+=fread(&rpf_record.scanangle, 1,
sizeof(rpf_record.scanangle), rpf_fp);
bytesread+=fread(&rpf_record.roll, 1,
sizeof(rpf_record.roll), rpf_fp);
bytesread+=fread(&rpf_record.pitch, 1,
sizeof(rpf_record.pitch), rpf_fp);
bytesread+=fread(&rpf_record.heading, 1,
sizeof(rpf_record.heading), rpf_fp);
bytesread+=fread(&rpf_record.aircraft_lat, 1,
sizeof(rpf_record.aircraft_lat), rpf_fp);
bytesread+=fread(&rpf_record.aircraft_lon, 1,
sizeof(rpf_record.aircraft_lon), rpf_fp);
bytesread+=fread(&rpf_record.aircraft_ele, 1,
sizeof(rpf_record.aircraft_ele), rpf_fp);
bytesread+=fread(&rpf_record.t1, 1,
sizeof(rpf_record.t1), rpf_fp);
bytesread+=fread(&rpf_record.t2, 1,
sizeof(rpf_record.t2), rpf_fp);
bytesread+=fread(&rpf_record.t0, 1,
sizeof(rpf_record.t0), rpf_fp);
bytesread+=fread(&rpf_record.ret1, 1,
sizeof(rpf_record.ret1), rpf_fp);
bytesread+=fread(&rpf_record.ret2, 1,
sizeof(rpf_record.ret2), rpf_fp);
printf("----- bytesread=%d -----\n\n", bytesread);
Octave_map stru( "Field1" , "Filed1_value"); stru.assign("gpstime",
rpf_record.gpstime);
stru.assign("pulsecount", rpf_record.pulsecount);
stru.assign("range", &rpf_record.range);
stru.assign("intensity", rpf_record.intensity);
stru.assign("scanangle", rpf_record.scanangle);
stru.assign("roll", rpf_record.roll);
stru.assign("pitch", rpf_record.pitch);
stru.assign("heading", rpf_record.heading);
stru.assign("aircraft_lat", rpf_record.aircraft_lat);
stru.assign("aircraft_lon", rpf_record.aircraft_lon);
stru.assign("aircraft_ele", rpf_record.aircraft_ele);
stru.assign("t1", rpf_record.t1);
stru.assign("t2", rpf_record.t2);
{
int i;
for (i=0; i<40; i++)
t0(i)=rpf_record.t0[i];
}
stru.assign("t0", t0);
retval.append(stru);
return retval;
}
This works and returns the first record of the file in a structure. The
problem is that t0 is a....
whos return_value.t0
*** local user variables:
Prot Name Size Bytes Class
==== ==== ==== ===== =====
rwd return_value.t0 1x40 320 matrix
Total is 40 elements using 320 bytes
How can I declare t0 in a way that my function will return a 40 byte
uint8 vector?
And is it possible to return directly an array of structures?
Any help will be appreciated
Roberto Vidmar
--
------------------------------------
Roberto Vidmar
___ __ __ OCEANOGRAFIA
/ / /__ /__ GEOFISICA
/__/ /__/ __/ SPERIMENTALE
Istituto Nazionale di Oceanografia e
di Geofisica Sperimentale
34010 Sgonico (TS) ITALY
Research Group: CARS
(Cartography And Remote Sensing)
CARS Group is certified ISO 9001:2000
Tel. +39 040 2140 336 direct
Tel. +39 040 2140 1 operator
E-mail: address@hidden
------------------------------------
rvidmar.vcf
Description: Vcard
- How can I declare an "uint8 RowVector"?,
Roberto Vidmar <=