[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: structures in oct files
From: |
Andy Buckle |
Subject: |
Re: structures in oct files |
Date: |
Fri, 21 Jan 2011 14:21:28 +0000 |
On Fri, Jan 21, 2011 at 8:28 AM, jacques.beilin <address@hidden> wrote:
> Hi,
>
> I want to write a package based on oct files in order to manage GPS time
> (GPS week number, day of week, day of year, second of day, second of week,
> mjd...). I have already written such a package but it was based on m-files.
>
> In the package, I have several initialization functions. For example mjd_t
> takes a modified julian date as input and gives back a structure with all
> the date fields. I also wrote a add_s function. It takes a structure and a
> number of second to add. The function gives back the structure with the new
> date.
>
> I have a problem when I write yyyyddds_t2.oct function. It take year, day of
> year and second of day as arguments. I want to initialize first a structure
> for yyyy, january 1st and then add 86400 seconds per day plus the seconds of
> day.
>
>
> Here is the code :
>
> #include <octave/oct.h>
> #include <octave/ov-struct.h>
> #include <octave/parse.h>
>
>
> DEFUN_DLD (yyyyddds_t2, args, , "Struct demo.")
> {
> int nargin = args.length ();
> octave_value retval;
> octave_map ymdhms0;
> octave_value_list rr;
>
> if (nargin <2)
> print_usage ();
> else
> {
> Octave_map tgps;
> double yyyy = args(0).double_value();
>
> // 2 or 4 digits year management
> if (yyyy<80) {
> yyyy=yyyy+2000;
> } else if (yyyy<100) {
> yyyy=yyyy+1900;
> }
>
> const double ddd = args(1).double_value(); // ddd : Day of year
>
> double s = 0.0;
> if (nargin==2) {
> s=0.0000;
> } else {
> s = args(2).double_value(); // s : seconds of day
> }
>
>
> // calculating gpstime structure for yyyy, january, 1st,, 0h:00
> std::string fcn = "ymdhms_t";
> int nargout;
> octave_value_list newargs;
> newargs(0) = yyyy;
> newargs(1) = 1;
> newargs(2) = 1;
> newargs(3) = 0;
> newargs(4) = 0;
> newargs(5) = 0;
> rr = feval (fcn, newargs, nargout);
> retval=rr(0);
>
> // adding (ddd-1.0)*86400+s seconds to gpstime structure
> std::string fcn2 = "add_s";
> int nargout2;
> octave_value_list newargs2;
> newargs2(0) = retval;
> newargs2(1) = s;
> rr = feval (fcn2, newargs2, nargout2);
> retval=rr(0);
>
> }
>
> return retval;
> }
>
> This code is successfully compiled but it crashes (octave terminal closed)
> on the line " rr = feval (fcn2, newargs2, nargout2);". I suppose that the
> problem comes from retval which is an octave_value whereas add_s takes an
> octave_map for the first argument.
>
> I do not understand how (and when) to use octave_value and/or octave_map.
>
> Best regards,
>
> Jacques
>
>
>
> Le 20/01/2011 18:42, Andy Buckle a écrit :
>>
>> On Thu, Jan 20, 2011 at 3:25 PM, jacques.beilin<address@hidden>
>> wrote:
>>>
>>> Hi,
>>>
>>> I do not know whether this question has already been sent to the list. In
>>> this case I am sorry to ask again.
>>>
>>> I would like to know if there is somewhere a tutorial and/or examples
>>> about
>>> oct files.
>>>
>>> I found this :
>>>
>>> http://www.gnu.org/software/octave/doc/interpreter/Oct_002dFiles.html#Oct_002dFiles
>>>
>>> I wrote some sample programs but I have parameter problems when I try to
>>> call other oct files from an oct file. I try to send structures as input
>>> and
>>> output.
>>
>> When I have done similar, I have made a c++ function that actually
>> does the job I want. To make this available from Octave I have then
>> written a DEFUN_DLD that does extra parameter checking and then calls
>> the actual function. If I want to call the function from other c++,
>> then I call it directly. I pass by reference, to keep things quick.
>>
>> If you want more helpful comments, you may have to provide the list
>> with more details of your approach, and the problems you had.
>>
>
> --
> ___________________________________________
>
> Beilin Jacques
>
> Département Positionnement Terrestre et Spatial
> Ecole Nationale des Sciences Géographiques
> Institut Géographique National
>
> Cité Descartes
> 6,8 avenue Blaise Pascal - Champs Sur Marne
> 77455 Marne La Vallée Cedex
>
> tel : 01 64 15 31 09
>
> http://www.ensg.ign.fr/Positionnement-Terrestre-et-Spatial-geodesie
>
>
>
I don't have the time it would take me to look at this properly ATM. A
quick note that might help: octave_value has a constructor that can
take a map.
octave_value::octave_value ( const Octave_map & m )
Hopefully someone else on the list can provide a more expert comment.
--
/* andy buckle */