From: <car...@us...> - 2012-04-17 12:03:52
|
Revision: 10262 http://octave.svn.sourceforge.net/octave/?rev=10262&view=rev Author: carandraug Date: 2012-04-17 12:03:41 +0000 (Tue, 17 Apr 2012) Log Message: ----------- time/financial: moving functions from time to financial package since they belong to Matlab's financial toolbox and time package has no maintainer Added Paths: ----------- trunk/octave-forge/main/financial/inst/busdate.m trunk/octave-forge/main/financial/inst/busdays.m trunk/octave-forge/main/financial/inst/datefind.m trunk/octave-forge/main/financial/inst/day.m trunk/octave-forge/main/financial/inst/daysact.m trunk/octave-forge/main/financial/inst/eomdate.m trunk/octave-forge/main/financial/inst/fbusdate.m trunk/octave-forge/main/financial/inst/holidays.m trunk/octave-forge/main/financial/inst/hour.m trunk/octave-forge/main/financial/inst/isbusday.m trunk/octave-forge/main/financial/inst/lbusdate.m trunk/octave-forge/main/financial/inst/lweekdate.m trunk/octave-forge/main/financial/inst/m2xdate.m trunk/octave-forge/main/financial/inst/minute.m trunk/octave-forge/main/financial/inst/month.m trunk/octave-forge/main/financial/inst/months.m trunk/octave-forge/main/financial/inst/nweekdate.m trunk/octave-forge/main/financial/inst/second.m trunk/octave-forge/main/financial/inst/thirdwednesday.m trunk/octave-forge/main/financial/inst/today.m trunk/octave-forge/main/financial/inst/x2mdate.m trunk/octave-forge/main/financial/inst/year.m trunk/octave-forge/main/financial/inst/yeardays.m Removed Paths: ------------- trunk/octave-forge/main/time/inst/busdate.m trunk/octave-forge/main/time/inst/busdays.m trunk/octave-forge/main/time/inst/datefind.m trunk/octave-forge/main/time/inst/day.m trunk/octave-forge/main/time/inst/daysact.m trunk/octave-forge/main/time/inst/eomdate.m trunk/octave-forge/main/time/inst/fbusdate.m trunk/octave-forge/main/time/inst/holidays.m trunk/octave-forge/main/time/inst/hour.m trunk/octave-forge/main/time/inst/isbusday.m trunk/octave-forge/main/time/inst/lbusdate.m trunk/octave-forge/main/time/inst/lweekdate.m trunk/octave-forge/main/time/inst/m2xdate.m trunk/octave-forge/main/time/inst/minute.m trunk/octave-forge/main/time/inst/month.m trunk/octave-forge/main/time/inst/months.m trunk/octave-forge/main/time/inst/nweekdate.m trunk/octave-forge/main/time/inst/second.m trunk/octave-forge/main/time/inst/thirdwednesday.m trunk/octave-forge/main/time/inst/today.m trunk/octave-forge/main/time/inst/x2mdate.m trunk/octave-forge/main/time/inst/year.m trunk/octave-forge/main/time/inst/yeardays.m Copied: trunk/octave-forge/main/financial/inst/busdate.m (from rev 10260, trunk/octave-forge/main/time/inst/busdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/busdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/busdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,97 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {b =} busdate (refdate) +## @deftypefnx {Function File} {b =} busdate (refdate, direction) +## @deftypefnx {Function File} {b =} busdate (refdate, direction, holiday) +## @deftypefnx {Function File} {b =} busdate (refdate, direction, holiday, weekend) +## +## Return the datenum of the next or previous business day from +## @var{refdate}. @var{direction} indicates the next day (default) if 1 +## and the previous day if -1. @var{holiday} is a vector of datenums +## that defines the holidays observed (the holidays function is used if +## not given). @var{weekend} defines the days of the week that should +## be considered weekends; [1 0 0 0 0 0 1] (default) indicates that +## Sunday and Saturday are holidays. +## +## If any of the optional inputs (@var{direction}, @var{holiday}, +## @var{weekend}) are empty, then the default is used. +## +## @seealso{holidays, lbusdate, isbusday, fbusdate} +## @end deftypefn + +function rd = busdate (rd, d, hol, wkend) + + if ~isnumeric (rd) + rd = datenum ( rd); + endif + if nargin < 2 || isempty (d) + d = 1; + elseif ~ all (abs (d) == 1) + ## People could use other numbers to skip days, but that is not + ## supported. + error ("directions must all be either 1 or -1.") + endif + if nargin < 3 + hol = []; + end + if nargin < 4 + wkend = []; + elseif nargin > 4 + print_usage (); + endif + + rd += d; + mask = ~isbusday (rd, hol, wkend); + while any (mask) + ## Only recompute for the days that are not yet business days + if isscalar (d) + rd(mask) += d; + else + rd(mask) += d(mask); + endif + mask(mask) = ~isbusday (rd(mask), hol, wkend); + endwhile + +endfunction + +## Tests +## A normal day +%!assert(busdate(datenum(2008,1,2)), datenum(2008,1,3)) +## A holiday +%!assert(busdate(datenum(2007,12,31)), datenum(2008,1,2)) +## Go over a weekend and start in a weekend +%!assert(busdate(datenum(2007,1,5)), datenum(2007,1,8)) +%!assert(busdate(datenum(2007,1,6)), datenum(2007,1,8)) +## Backward +%!assert(busdate(datenum(2008,1,3), -1), datenum(2008,1,2)) +## Backward holiday +%!assert(busdate(datenum(2008,1,2), -1), datenum(2007,12,31)) +## Backward with alternate holidays +%!assert(busdate(datenum(2008,1,2), -1, datenum(2007,1,1):datenum(2008,1,1)), datenum(2006,12,29)) +## Multiple dates in both orientations +%!assert(busdate([datenum(2008,1,2) datenum(2007,1,1)]), [datenum(2008,1,3) datenum(2007,1,2)]) +%!assert(busdate([datenum(2008,1,2) datenum(2007,1,1)], [1 1]), [datenum(2008,1,3) datenum(2007,1,2)]) +%!assert(busdate([datenum(2008,1,2) datenum(2007,1,1)], 1), [datenum(2008,1,3) datenum(2007,1,2)]) +%!assert(busdate([datenum(2008,1,2);datenum(2007,1,1)], [1;1]), [datenum(2008,1,3);datenum(2007,1,2)]) +## Multiple dates with opposite directions holidays and weekends +%!assert(busdate([datenum(2008,1,2);datenum(2007,1,2)], [1;-1]), [datenum(2008,1,3);datenum(2006,12,29)]) +## Alternate weekends +%!assert(busdate(datenum(2008,1,2), 1, holidays(datenum(2008,1,1), datenum(2008,1,31)), [1 0 0 0 0 0 0]), datenum(2008,1,3)) +%!assert(busdate(datenum(2008,1,4), 1, holidays(datenum(2008,1,1), datenum(2008,1,31)), [1 0 0 0 0 0 0]), datenum(2008,1,5)) +%!assert(busdate(datenum(2008,1,5), 1, holidays(datenum(2008,1,1), datenum(2008,1,31)), [1 0 0 0 0 0 0]), datenum(2008,1,7)) +%!assert(busdate(datenum(2008,1,6), 1, holidays(datenum(2008,1,1), datenum(2008,1,31)), [1 0 0 0 0 0 0]), datenum(2008,1,7)) +%!assert(busdate(datenum(2008,1,1), 1, holidays(datenum(2008,1,1), datenum(2008,1,31)), [1 1 1 1 1 1 0]), datenum(2008,1,5)) Copied: trunk/octave-forge/main/financial/inst/busdays.m (from rev 10260, trunk/octave-forge/main/time/inst/busdays.m) =================================================================== --- trunk/octave-forge/main/financial/inst/busdays.m (rev 0) +++ trunk/octave-forge/main/financial/inst/busdays.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,127 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{bdates} =} busdays (@var{sdate}, @var{edate}) +## @deftypefnx {Function File} {@var{bdates} =} busdays (@var{sdate}, @var{edate}, @var{bdmode}) +## @deftypefnx {Function File} {@var{bdates} =} busdays (@var{sdate}, @var{edate}, @var{bdmode}, @var{holvec}) +## Generate a list of business dates at the end of the periods defined +## between (including) @var{sdate} and @var{edate}. +## +## @var{sdate} is the starting date, @var{edate} is the ending date, +## both are in serial date format (see datenum). @var{bdmode} is the +## business day frequency ("daily", "weekly", "monthly", "quarterly", +## "semiannual", or "annual"); these can be abbreviated by the first +## letter and they may also use an integer corresponding to the order in +## the above list (i.e. "daily" = 1). @var{holvec} is an optional list +## of holidays. If the holidays are not given, then the holidays +## function is used. +## @seealso{holidays, busdate, lbusdate, isbusday, fbusdate, datenum} +## @end deftypefn + +function bd = busdays (sd, ed, mode=1, hol=[]) + + if nargin < 2 || nargin > 4 + print_usage (); + endif + if ~isnumeric (sd) + sd = datenum (sd); + endif + if ~isnumeric (ed) + ed = datenum (ed); + endif + if ed < sd + error ("busdays: the start date must be less than the end date") + endif + if isempty (hol) + ## make the holidays take into account the whole ending year because + ## the day may extend beyond the actual ending date + edtmp = datevec (ed); + edtmp(2:3) = [12 31]; + hol = holidays (sd, datenum (edtmp)); + endif + ## Convert the mode to the numeric + modestr = "dwmqsa"; + if ischar (mode) + mode = find (lower (mode(1)) == modestr); + if isempty (mode) + error ("busdays: mode must be one of '%s'", modestr) + endif + elseif isnumeric (mode) + if mode < 1 || mode > length (modestr) + error ("busdays: mode must be between 1 and %d", length (modestr)) + endif + else + error ("busdays: mode must be a number or string") + endif + + ## do the computation + if mode == 1 + ## daily + bd = (sd:ed)'(isbusday (sd:ed, hol)); + elseif mode < 6 + if mode == 2 + ## weekly make the start and end dates Fridays and then move back + ## from there + wd = weekday ([sd;ed]); + d = [sd;ed] - wd + 7; + ## there are generally not more than one week of holidays at a + ## time, but the call to unique will make certain of that. + bd = unique (busdate ([d(1):7:d(2)]', -1, hol)); + else + d = datevec ([sd:ed]); + ## unique year and month list within the date range + ym = unique (d(:,1:2), "rows"); + if mode == 3 + ## monthly, do nothing to the ym list + elseif mode == 4 + ## quarterly + if mod (ym(end), 3) != 0 + ## make the last month an end of quarter month + ym(end) = ym(end) + 3 - mod (ym(end), 3); + endif + ym(mod (ym(:,2), 3) != 0, :) = []; + elseif mode == 5 + ## semi-annually + if mod (ym(end), 6) != 0 + ## make the last month an end of semi-annual month (6, 12) + ym(end) = ym(end) + 6 - mod (ym(end), 6); + endif + ym(mod (ym(:,2), 6) != 0, :) = []; + endif + bd = lbusdate (ym(:,1), ym(:,2), hol); + endif + elseif mode == 6 + ## annual + d = datevec ([sd;ed]); + bd = lbusdate ((d(1,1):d(2,1))', 12, hol); + else + ## this should have been caught before now + error ("busdays: invalid mode") + endif + +endfunction + +## Tests +%!assert (busdays (datenum (2008, 1, 1), datenum (2008, 1, 12)), datenum (2008, 1, [2;3;4;7;8;9;10;11])) +%!assert (busdays (datenum (2008, 1, 1), datenum (2008, 1, 12), "d"), datenum (2008, 1, [2;3;4;7;8;9;10;11])) +%!assert (busdays (datenum (2001, 1, 2), datenum (2001, 1, 9), "w"), datenum (2001, 1, [5;12])) +%!assert (busdays (datenum (2008, 1, 1), datenum (2008, 1, 2), "m"), datenum (2008, 1, 31)) +%!assert (busdays (datenum (2008, 1, 1), datenum (2010, 5, 2), "m"), lbusdate ([2008*ones(12,1);2009*ones(12,1);2010*ones(5,1)], [1:12 1:12 1:5]')) +%!assert (busdays (datenum (2008, 1, 1), datenum (2008, 1, 2), "q"), datenum (2008, 3, 31)) +%!assert (busdays (datenum (2008, 1, 1), datenum (2010, 5, 2), "q"), lbusdate ([2008*ones(4,1);2009*ones(4,1);2010*ones(2,1)], [3:3:12 3:3:12 3 6]')) +%!assert (busdays (datenum (2008, 1, 1), datenum (2008, 1, 2), "s"), datenum (2008, 6, 30)) +%!assert (busdays (datenum (2008, 1, 1), datenum (2010, 5, 2), "s"), lbusdate ([2008;2008;2009;2009;2010], [6 12 6 12 6]')) +%!assert (busdays (datenum (2008, 1, 1), datenum (2011, 1, 2), "a"), datenum ([2008;2009;2010;2011], [12;12;12;12], [31;31;30;30])) Copied: trunk/octave-forge/main/financial/inst/datefind.m (from rev 10260, trunk/octave-forge/main/time/inst/datefind.m) =================================================================== --- trunk/octave-forge/main/financial/inst/datefind.m (rev 0) +++ trunk/octave-forge/main/financial/inst/datefind.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,44 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {indices =} datefind (subset, superset, tol) +## +## Find any instances of the @code{subset} in the @code{superset} with +## the @code{tol}erance. @code{tol} is 0 by default. +## +## @seealso{date, datenum} +## @end deftypefn + +function idx = datefind (subset, superset, tol=0) + + if (nargin < 2 || nargin > 3) + print_usage (); + elseif ! isscalar (tol) + error ("datefind: tol must be a scalar") + endif + + idx = []; + for i = 1:numel (superset) + if any (subset(:) - tol <= superset(i) & superset(i) <= subset(:) + tol) + idx(end+1, 1) = i; + endif + endfor + +endfunction + +## Tests +%!assert (datefind (datenum (1999, 7, [10;20]), datenum (1999, 7, 1:31)), [10;20]) +%!assert (datefind (datenum (1999, 7, [10;20]), datenum (1999, 7, 1:31), 1), [9;10;11;19;20;21]) Copied: trunk/octave-forge/main/financial/inst/day.m (from rev 10260, trunk/octave-forge/main/time/inst/day.m) =================================================================== --- trunk/octave-forge/main/financial/inst/day.m (rev 0) +++ trunk/octave-forge/main/financial/inst/day.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,31 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {dom =} day (Date) +## +## Returns the day of the month from a serial date number or a date +## string. +## +## @seealso{date, datevec, now, month, year} +## @end deftypefn + +function t = day (dates) + + t = datevec (dates); + t = t (:,3); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/daysact.m (from rev 10260, trunk/octave-forge/main/time/inst/daysact.m) =================================================================== --- trunk/octave-forge/main/financial/inst/daysact.m (rev 0) +++ trunk/octave-forge/main/financial/inst/daysact.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,76 @@ +## Copyright (C) 2007 David Bateman +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} daysact (@var{d1}) +## @deftypefnx {Function File} {} daysact (@var{d1}, @var{d2}) +## Calculates the number of days between two dates. If the second date is not +## given, calculate the number of days since 1-Jan-0000. The variables @var{d1} +## and @var{d2} can either be strings or an @var{n}-row string matrix. If both +## @var{d1} and @var{d2} are string matrices, then the number of rows must +## match. An example of the use of @code{daysact} is +## +## @example +## @group +## daysact ("01-Jan-2007", ["10-Jan-2007"; "23-Feb-2007"; "23-Jul-2007"]) +## @result{} 9 +## 53 +## 203 +## @end group +## @end example +## @seealso{datenum} +## @end deftypefn + +function days = daysact (d1, d2) + if (nargin == 1) + nr = size (d1, 1); + if (nr != 1) + days = zeros (nr,1); + for i = 1 : nr + days (i) = datenum (d1 (i,:)); + endfor + else + days = datenum(d1); + endif + elseif (nargin == 2) + nr1 = size (d1, 1); + nr2 = size (d2, 1); + if (nr1 != nr2 && nr1 != 1 && nr2 != 1) + error ("daysact: size mismatch"); + endif + if (nr1 == 1 && nr2 == 1) + days = datenum (d2) - datenum(d1); + elseif (nr1 == 1) + days = zeros (nr2, 1); + for i = 1 : nr2 + days(i) = datenum (d2 (i,:)) - datenum (d1); + endfor + elseif (nr2 == 1) + days = zeros (nr1, 1); + for i = 1 : nr1 + days(i) = datenum (d2) - datenum (d1 (i,:)); + endfor + else + days = zeros (nr1, 1); + for i = 1 : nr1 + days(i) = datenum (d2 (i, :)) - datenum (d1 (i,:)); + endfor + endif + else + print_usage(); + endif +endfunction + +%!assert (daysact ("01-Jan-2007", ["10-Jan-2007"; "23-Feb-2007"; "23-Jul-2007"]),[9;53;203]) Copied: trunk/octave-forge/main/financial/inst/eomdate.m (from rev 10260, trunk/octave-forge/main/time/inst/eomdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/eomdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/eomdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,40 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{e} =} eomdate (@var{y}, @var{m}) +## Return the last day of the month @var{m} for the year @var{y} in +## datenum format. +## @seealso{datenum, datevec, weekday, eomday} +## @end deftypefn + +function e = eomdate (y, m) + + if (nargin != 2) + print_usage (); + endif + + d = eomday (y, m); + e = datenum (y, m, d); + +endfunction + +## Tests +## Leap years +%!assert(eomdate(2008, 2), datenum(2008, 2, 29)) +%!assert(eomdate(2007, 2), datenum(2007, 2, 28)) +## Vectors +%!assert(eomdate([2008 2007], [3 4]), [datenum(2008, 3, 31) datenum(2007, 4, 30)]) +%!assert(eomdate([2008;2007], [3;4]), [datenum(2008, 3, 31);datenum(2007, 4, 30)]) Copied: trunk/octave-forge/main/financial/inst/fbusdate.m (from rev 10260, trunk/octave-forge/main/time/inst/fbusdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/fbusdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/fbusdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,58 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {b =} fbusdate (year, month) +## @deftypefnx {Function File} {b =} fbusdate (year, month, holiday) +## @deftypefnx {Function File} {b =} fbusdate (year, month, holiday, weekend) +## +## Return the datenum of the first business day of the @var{year} and +## @var{month}. @var{holiday} is a vector of datenums that defines the +## holidays observed (the holidays function is used if not given). +## @var{weekend} defines the days of the week that should be considered +## weekends; [1 0 0 0 0 0 1] (default) indicates that Sunday and +## Saturday are holidays. +## +## If any of the optional inputs (@var{holiday}, @var{weekend}) are +## empty, then the default is used. +## +## @seealso{holidays, lbusdate, isbusday, busdate} +## @end deftypefn + +function rd = fbusdate (y, m, hol, wkend) + + rd = datenum (y, m, 1); + if nargin < 3 + hol = []; + end + if nargin < 4 + wkend = []; + elseif nargin < 3 || nargin > 4 + print_usage (); + endif + + ## Test from the day before the beginning of the month so that the + ## first day of the month is captured. + rd = busdate (rd-1, 1, hol, wkend); + +endfunction + +## Tests +## A normal day +%!assert(fbusdate(2008,2), datenum(2008,2,1)) +## A holiday +%!assert(fbusdate(2008,1), datenum(2008,1,2)) +## A weekend +%!assert(fbusdate(2008,3), datenum(2008,3,3)) Copied: trunk/octave-forge/main/financial/inst/holidays.m (from rev 10260, trunk/octave-forge/main/time/inst/holidays.m) =================================================================== --- trunk/octave-forge/main/financial/inst/holidays.m (rev 0) +++ trunk/octave-forge/main/financial/inst/holidays.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,91 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {h =} holidays (startdate, enddate) +## +## Return a vector of datenums that were holidays between +## @var{startdate} and @var{enddate}, inclusive. These holidays are +## trading holidays observed by the NYSE according to its rule 51.10. It +## does not take into account the exceptions for "unusual business +## conditions" or for additional days that have been called as holidays +## for one-time purposes. +## +## The complete list can be found at +## http://www.chronos-st.org/NYSE_Observed_Holidays-1885-Present.html +## +## @seealso{busdate, lbusdate, isbusday, fbusdate} +## @end deftypefn + +function hol = holidays (sd, ed) + + sd = datenum (datevec (sd)); + ed = datenum (datevec (ed)); + + ## just get the start and end years and generate all holidays in that range + yrs = year(sd):year(ed); + + hol = []; + ## New Year's Day + tmphol = datenum (yrs, 1, 1); + hol = [hol; tmphol(:)]; + ## Martin Luther King Day, the third Monday in January + tmphol = nweekdate (3, 2, yrs, 1); + hol = [hol; tmphol(:)]; + ## Washington's Birthday, the third Monday in February + tmphol = nweekdate (3, 2, yrs, 2); + hol = [hol; tmphol(:)]; + ## Good Friday + tmphol = easter (yrs) - 2; + hol = [hol; tmphol(:)]; + ## Memorial Day, the last Monday in May + tmphol = lweekdate (2, yrs, 5); + hol = [hol; tmphol(:)]; + ## Independence Day, July 4 + tmphol = datenum (yrs, 7, 4); + hol = [hol; tmphol(:)]; + ## Labor Day, the first Monday in September + tmphol = nweekdate (1, 2, yrs, 9); + hol = [hol; tmphol(:)]; + ## Thanksgiving Day, the fourth Thursday in November + tmphol = nweekdate (4, 5, yrs, 11); + hol = [hol; tmphol(:)]; + ## Christmas Day + tmphol = datenum (yrs, 12, 25); + hol = [hol; tmphol(:)]; + + ## Adjust for Saturdays and Sundays + wd = weekday (hol); + if any (wd == 1) + hol(wd == 1) = hol(wd == 1) + 1; + endif + if any (wd == 7) + hol(wd == 7) = hol(wd == 7) - 1; + endif + + ## Trim out the days that are not in the date range + hol(hol > ed | hol < sd) = []; + hol = sort (hol); + +endfunction + +## Tests +%!assert(holidays(datenum(2008,1,1), datenum(2008,12,31)), datenum(2008*ones(9,1), [1;1;2;3;5;7;9;11;12], [1;21;18;21;26;4;1;27;25])) +## Test Independence day observing on a Monday (July 5) and Christmas +## observing on a Friday (Dec 24) +%!assert(holidays(datenum(2004,1,1), datenum(2004,12,31)), datenum(2004*ones(9,1), [1;1;2;4;5;7;9;11;12], [1;19;16;9;31;5;6;25;24])) +%!assert(holidays(datenum(2008,3,5), datenum(2008,3,8)), zeros(0,1)) +%!assert(holidays(datenum(2008,3,5), datenum(2008,3,5)), zeros(0,1)) +%!assert(holidays(datenum(2008,1,1), datenum(2008,1,1)), datenum(2008,1,1)) Copied: trunk/octave-forge/main/financial/inst/hour.m (from rev 10260, trunk/octave-forge/main/time/inst/hour.m) =================================================================== --- trunk/octave-forge/main/financial/inst/hour.m (rev 0) +++ trunk/octave-forge/main/financial/inst/hour.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,30 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {h =} hour (Date) +## +## Returns the hour from a serial date number or a date string. +## +## @seealso{date, datevec, now, minute, second} +## @end deftypefn + +function t = hour (dates) + + t = datevec (dates); + t = t (:,4); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/isbusday.m (from rev 10260, trunk/octave-forge/main/time/inst/isbusday.m) =================================================================== --- trunk/octave-forge/main/financial/inst/isbusday.m (rev 0) +++ trunk/octave-forge/main/financial/inst/isbusday.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,72 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {r =} isbusday (refdate) +## @deftypefnx {Function File} {r =} isbusday (refdate, holiday) +## @deftypefnx {Function File} {r =} isbusday (refdate, holiday, weekend) +## +## Return true if the @var{refdate} is a business date @var{refdate}. +## @var{holiday} is a vector of datenums that defines the holidays +## observed (the holidays function is used if not given). @var{weekend} +## defines the days of the week that should be considered weekends; +## [1 0 0 0 0 0 1] (default) indicates that Sunday and Saturday are +## weekends. +## +## @seealso{holidays, lbusdate, busdate, fbusdate} +## @end deftypefn + +function mask = isbusday (rd, hol=[], wkend=[]) + + if ~ isnumeric (rd) + rd = datenum (rd); + endif + if isempty (hol) + ## Get all possible holidays that could affect the output. + hol = holidays (min(rd), max(rd)); + end + if isempty (wkend) + wkend = [1 0 0 0 0 0 1]; + elseif numel (wkend) ~= 7 + error ("wkend must have 7 elements") + elseif nargin > 3 + print_usage (); + endif + + mask = reshape (wkend (weekday (rd)), size (rd)); + if ~ isempty (hol) + ## Is it a holiday? + mask = mask | ismember(rd, hol); + endif + mask = ~mask; +endfunction + +## Tests +## A normal day +%!assert(isbusday(datenum(2008,1,2)), true()) +## A holiday +%!assert(isbusday(datenum(2008,1,1)), false()) +%!assert(isbusday(datenum(2008,1,1), []), false()) +## A weekend +%!assert(isbusday(datenum(2008,2,2)), false()) +## An alternate holiday +%!assert(isbusday(datenum(2008,1,2), datenum(2008,1,2)), false()) +## An alternate weekend +%!assert(isbusday(datenum(2008,1,2), [], zeros(1,7)), true()) +%!assert(isbusday(datenum(2008,1,2), [], ones(1,7)), false()) +## A vector +%!assert(isbusday([datenum(2008,1,2) datenum(2008,2,2)]), [true() false()]) +## A vector in the other direction +%!assert(isbusday([datenum(2008,1,2);datenum(2008,2,2)]), [true();false()]) Copied: trunk/octave-forge/main/financial/inst/lbusdate.m (from rev 10260, trunk/octave-forge/main/time/inst/lbusdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/lbusdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/lbusdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,56 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {b =} lbusdate (year, month) +## @deftypefnx {Function File} {b =} lbusdate (year, month, holiday) +## @deftypefnx {Function File} {b =} lbusdate (year, month, holiday, weekend) +## +## Return the datenum of the last business day of the @var{year} and +## @var{month}. @var{holiday} is a vector of datenums that defines the +## holidays observed (the holidays function is used if not given). +## @var{weekend} defines the days of the week that should be considered +## weekends; [1 0 0 0 0 0 1] (default) indicates that Sunday and +## Saturday are holidays. +## +## If any of the optional inputs (@var{holiday}, @var{weekend}) are +## empty, then the default is used. +## +## @seealso{holidays, fbusdate, isbusday, busdate} +## @end deftypefn + +function rd = lbusdate (y, m, hol, wkend) + + rd = eomdate (y, m); + if nargin < 3 + hol = []; + end + if nargin < 4 + wkend = []; + elseif nargin < 3 || nargin > 4 + print_usage (); + endif + + ## Test from the day after the end of the month so that the + ## last day of the month is captured. + rd = busdate (rd+1, -1, hol, wkend); + +endfunction + +## Tests +## A normal day +%!assert(lbusdate(2008,4), datenum(2008,4,30)) +## A weekend +%!assert(lbusdate(2008,5), datenum(2008,5,30)) Copied: trunk/octave-forge/main/financial/inst/lweekdate.m (from rev 10260, trunk/octave-forge/main/time/inst/lweekdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/lweekdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/lweekdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,37 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {last =} lweekdate (weekday, year, month, nextday) +## +## Returns the last occurrence of @var{weekday} from the @var{month} and +## @var{year}. If the optional @var{nextday} argument is given, then +## the week must also contain @var{nextday}. +## +## @seealso{eomdate, nweekdate, weekday} +## @end deftypefn + +function t = lweekdate (varargin) + if nargin < 3 || nargin > 4 + error ("3 or 4 input arguments are required") + elseif nargin == 3 + varargin{4} = 0; + endif + + t = nweekdate ("lweekdate", varargin{:}); + +endfunction + +## Tests are in nweekdate Copied: trunk/octave-forge/main/financial/inst/m2xdate.m (from rev 10260, trunk/octave-forge/main/time/inst/m2xdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/m2xdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/m2xdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,74 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {exceldatenums =} m2xdate (datenums) +## @deftypefnx {Function File} {exceldatenums =} m2xdate (datenums, convention) +## @deftypefnx {Function File} {exceldatenums =} m2xdate (datenums, convention, "ExcelBug") +## +## Convert @var{datenums} from the internal date format to the format +## used by Microsoft Excel. If set to 0 (default, Excel for Windows), +## @var{convention} specifies to use the Excel 1900 convention where Jan +## 1, 1900 corresponds to Excel serial date number 1. If set to 1 +## (Excel for Mac), @var{convention} specifies to use the Excel 1904 +## convention where Jan 1, 1904 corresponds to Excel serial date number +## 0. +## +## Note that this does not take into account the Excel bug where 1900 is +## considered to be a leap year unless you give the "ExcelBug" option. +## +## Excel does not represent dates prior to 1 January 1900 using this +## format, so a warning will be issued if any dates preceed this date. +## +## @seealso{datenum, x2mdate} +## @end deftypefn + +function dates = m2xdate (dates, convention, excelbug) + + if nargin == 1 + convention = 0; + excelbug = false(); + elseif nargin == 2 + excelbug = false(); + elseif nargin == 3 + excelbug = strcmpi(excelbug, "ExcelBug"); + else + print_usage (); + endif + + if convention == 0 + adj = datenum(1900, 1, 1) - 2; + elseif convention == 1 + adj = datenum(1904, 1, 1); + endif + + if excelbug + datemask = (dates < datenum(1900, 3, 1)); + dates(datemask) = dates(datemask) - 1; + endif + dates = dates - adj; + if any (dates < 0) + warning ("Negative date found, this will not work within MS Excel.") + endif + +endfunction + +## Tests +%!assert(m2xdate(datenum(2008, 1, 1)), 39448) +%!assert(m2xdate(datenum(2007:2008, 1, 1)), [39083 39448]) +%!assert(m2xdate(datenum(1900, 1, 1)), 2) +%!assert(m2xdate(datenum(1900, 1, 1), 0, "ExcelBug"), 1) +%!assert(m2xdate(datenum(1904, 1, 1), 1), 0) + Copied: trunk/octave-forge/main/financial/inst/minute.m (from rev 10260, trunk/octave-forge/main/time/inst/minute.m) =================================================================== --- trunk/octave-forge/main/financial/inst/minute.m (rev 0) +++ trunk/octave-forge/main/financial/inst/minute.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,30 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {m =} minute (Date) +## +## Returns the minute from a serial date number or a date string. +## +## @seealso{date, datevec, now, hour, second} +## @end deftypefn + +function t = minute (dates) + + t = datevec (dates); + t = t (:,6); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/month.m (from rev 10260, trunk/octave-forge/main/time/inst/month.m) =================================================================== --- trunk/octave-forge/main/financial/inst/month.m (rev 0) +++ trunk/octave-forge/main/financial/inst/month.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,31 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {mon =} month (Date) +## +## Returns the day of the month from a serial date number or a date +## string. +## +## @seealso{date, datevec, now, day, year} +## @end deftypefn + +function t = month (dates) + + t = datevec (dates); + t = t (:,2); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/months.m (from rev 10260, trunk/octave-forge/main/time/inst/months.m) =================================================================== --- trunk/octave-forge/main/financial/inst/months.m (rev 0) +++ trunk/octave-forge/main/financial/inst/months.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,60 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {mos =} months (startdate, enddate) +## @deftypefnx {Function File} {mos =} months (startdate, enddate, endmonthflag) +## +## Return the number of whole months between @var{startdate} and +## @var{enddate}. @var{endmonthflag} defaults to 1. +## +## If @var{endmonthflag} is true, then if both the @var{startdate} and +## the @var{enddate} are end of month dates and @var{enddate} has fewer +## days in the month than @var{startdate}, @var{endmonthflag} = 1 treats +## @var{enddate} as the end of a month, but @var{endmonthflag} = 0 does +## not. +## +## @seealso{yeardays, yearfrac} +## @end deftypefn + +function mos = months (startdate, enddate, endmonthflag) + + if nargin == 2 + endmonthflag = 1; + elseif nargin != 3 + print_usage (); + endif + + s = datevec (startdate); + e = datevec (enddate); + s_eom = (s(:,3) == eomday(s(:,1), s(:,2))); + e_eom = (e(:,3) == eomday(e(:,1), e(:,2))); + + ## Handle the end of the month correctly + dayadj = ((s(:,3) > e(:,3)) & endmonthflag & s_eom & e_eom); + + mos = 12*(e(:,1) - s(:,1)) + (e(:,2) - s(:,2)) - (s(:,3) > e(:,3)) + dayadj; + +endfunction + +## Tests +%!assert(months('may 31 2004', 'jun 30 2004'), 1) +%!assert(months({'may 31 2004' 'may 30 2004'}, 'jun 30 2004'), [1;1]) +%!assert(months('may 31 2004', 'jun 30 2004', 1), 1) +%!assert(months({'may 31 2004' 'may 30 2004'}, 'jun 30 2004', 1), [1;1]) +%!assert(months('may 31 2004', 'jun 30 2004', 0), 0) +%!assert(months({'may 31 2004' 'may 30 2004'}, 'jun 30 2004', 0), [0;1]) +%!assert(months('jun 30 2005', 'june 30 2006'), 12) +%!assert(months('jun 30 2005', 'june 29 2006'), 11) Copied: trunk/octave-forge/main/financial/inst/nweekdate.m (from rev 10260, trunk/octave-forge/main/time/inst/nweekdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/nweekdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/nweekdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,152 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {last =} nweekdate (n, weekday, year, month, nextday) +## +## Returns the @var{n}th occurrence of @var{weekday} from the +## @var{month} and @var{year}. If the optional @var{nextday} argument +## is given, then the week must also contain @var{nextday}. If @var{n} +## is greater than the number of occurrences of that day in the month, 0 +## is returned. +## +## @seealso{eomdate, lweekdate, weekday} +## @end deftypefn + +function t = nweekdate (varargin) + if nargin < 4 || nargin > 5 + error ("4 or 5 input arguments are required") + elseif nargin == 4 + varargin{5} = 0; + endif + + ## special handling so that most of this code will not need to be + ## duplicated in lweekdate + do_lweekdate = is_lweekdate(varargin{1}); + if do_lweekdate + varargin{1} = 1; + endif + + scale = cellfun (@numel, varargin); + if ~ all (scale == 1 | scale == max(scale)); + error("All inputs must be either scalars or have the same number of elements"); + else + ## make sure that the sizes are the same for any non-scalar inputs + ind = find (scale > 1); + if length(ind) > 1 + for i = 2:length (ind) + if ndims (varargin{ind(1)}) ~= ndims (varargin{ind(i)}) + error("Mismatching dimensions on inputs %d and %d", ind(1), ind(i)); + elseif ~ all (size (varargin{ind(1)}) == size (varargin{ind(i)})) + error("The sizes of inputs %d and %d do not match", ind(1), ind(i)); + endif + endfor + endif + endif + + if max(scale) > 1 + t = zeros (size (varargin{ind(1)})); + for i = 1:numel (varargin{ind(1)}) + args = cell(5,1); + for j = 1:5 + if isscalar (varargin{j}) + args{j} = varargin{j}; + else + args{j} = varargin{j}(i); + endif + endfor + if do_lweekdate + args{1} = "lweekdate"; + end + t(i) = nweekdate (args{:}); + endfor + else + ## Do the real work. + n = varargin{1}; + wd = varargin{2}; + y = varargin{3}; + mon = varargin{4}; + nextday = varargin{5}; + + ## Find the day of the week for the last day of the mon. + doml = eomday (y, mon); + dowl = weekday (datenum (y, mon, doml)); + ## Make sure that the day is in the weeks for the last then the + ## first week. + if (wd < nextday) || (dowl < wd) + ## adjust the last day + adjust = 7; + else + adjust = 0; + endif + dom = sort((doml - dowl + wd - adjust):-7:1); + if nextday && (dom(1) <= wd - nextday) + # adjust the first day + dom(1) = []; + endif + if do_lweekdate + t = datenum (y, mon, dom(end)); + elseif n > length(dom) + t = 0; + else + t = datenum (y, mon, dom(n)); + end + endif + +endfunction + +function v = is_lweekdate(v) + if ischar(v) + if strcmp (v, "lweekdate") + v = true(); + else + error("Invalid input for n") + endif + else + v = false(); + endif +endfunction + +# Tests for all calling options +# Find the first Wednesday in Jan 2008 +%!assert(nweekdate(1, 4, 2008, 1), datenum(2008, 1, 2)) +# Find the second Wednesday in Jan 2008 +%!assert(nweekdate(2, 4, 2008, 1), datenum(2008, 1, 9)) +# Find the third Wednesday in Jan 2008 +%!assert(nweekdate(3, 4, 2008, 1), datenum(2008, 1, 16)) +# Find the fourth Wednesday in Jan 2008 +%!assert(nweekdate(4, 4, 2008, 1), datenum(2008, 1, 23)) +# Find the fifth Wednesday in Jan 2008 +%!assert(nweekdate(5, 4, 2008, 1), datenum(2008, 1, 30)) +# Find the sixth Wednesday in Jan 2008, it doesn't exist, so return 0 +%!assert(nweekdate(6, 4, 2008, 1), 0) +# Find the fifth Friday in Jan 2008, it doesn't exist, so return 0 +%!assert(nweekdate(5, 6, 2008, 1), 0) +# Find the first Wednesday in Jan 2008 in the same week as a Monday +# WARNING: it is unclear from the Matlab docs if this should work or if +# this should be called the second Wednesday in Jan 2008. +%!assert(nweekdate(1, 4, 2008, 1, 2), datenum(2008, 1, 9)) +# Find the fifth Wednesday in Jan 2008 in the same week as a Friday. +# It doesn't exist, so return 0 +%!assert(nweekdate(5, 4, 2008, 1, 6), 0) +# Try vector arguments +%!assert(nweekdate(1:6, 4, 2008, 1, 6), [datenum(2008, 1, 2:7:23), 0, 0]) + +# Try the lweekdate operation of this function: +# Find the last Wednesday in Jan 2008 +%!assert(nweekdate('lweekdate', 4, 2008, 1), datenum(2008, 1, 30)) +# Find the last Wednesday in Jan 2008 with a Friday +%!assert(nweekdate('lweekdate', 4, 2008, 1, 6), datenum(2008, 1, 23)) + Copied: trunk/octave-forge/main/financial/inst/second.m (from rev 10260, trunk/octave-forge/main/time/inst/second.m) =================================================================== --- trunk/octave-forge/main/financial/inst/second.m (rev 0) +++ trunk/octave-forge/main/financial/inst/second.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,30 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {s =} second (Date) +## +## Returns the second from a serial date number or a date string. +## +## @seealso{date, datevec, now, hour, minute} +## @end deftypefn + +function t = second (dates) + + t = datevec (dates); + t = t (:,6); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/thirdwednesday.m (from rev 10260, trunk/octave-forge/main/time/inst/thirdwednesday.m) =================================================================== --- trunk/octave-forge/main/financial/inst/thirdwednesday.m (rev 0) +++ trunk/octave-forge/main/financial/inst/thirdwednesday.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,68 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[begindate, enddate]} = thirdwednesday (month, year) +## +## Find the third Wednesday of the month specified by the @var{month} +## and @var{year}. The @var{begindate} is the third Wednesday of the +## month, and the @var{enddate} is three months after that. Outputs are +## in the form of datenums. +## +## The third Wednesday is used for Eurodollar futures. +## +## @seealso{nweekdate, datenum} +## @end deftypefn + +function [wednesdays, enddate] = thirdwednesday (month, year) + + if nargin ~= 2 + print_usage (); + elseif ~ ((numel(year) == 1) || + (numel(month) == 1) || + ~isequal (size (month), size (year))) + error("month and year must have the same size or one of them must be a scalar") + endif + + if numel (year) == 1 + sz = size (month); + else + sz = size (year); + endif + + wednesdays = nweekdate (3, 4, year, month); + dates = datevec (wednesdays); + ## adjust the year when the date will wrap + dates(:,1) += dates (:,2) > 9; + ## adjust the month by three + dates(:,2) = mod (dates(:,2) + 2, 12) + 1; + enddate = reshape (datenum (dates), sz); + +endfunction + +## Tests +%!shared m, y, bt, et +%! m = (1:12)'; +%! y = 2008; +%! bt = datenum(2008, m, [16;20;19;16;21;18;16;20;17;15;19;17]); +%! et = datenum([2008*ones(9,1);2009*ones(3,1)], [4:12 1:3]', [16;20;19;16;21;18;16;20;17;15;19;17]); +%!test +%! [b e] = thirdwednesday (m, y); +%! assert(b, bt) +%! assert(e, et) +%!test +%! [b e] = thirdwednesday (m', y); +%! assert(b, bt') +%! assert(e, et') Copied: trunk/octave-forge/main/financial/inst/today.m (from rev 10260, trunk/octave-forge/main/time/inst/today.m) =================================================================== --- trunk/octave-forge/main/financial/inst/today.m (rev 0) +++ trunk/octave-forge/main/financial/inst/today.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,32 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {datenum =} today () +## Returns the current local date as the number of days since Jan 1, 0000. +## By this reckoning, Jan 1, 1970 is day number 719529. +## +## The returned number corresponds to 00:00:00 today. +## +## The returned value is also called a "serial date number" +## (see @code{datenum}). +## @seealso{clock, date, datenum, now} +## @end deftypefn + +function t = today () + + t = floor (now ()); + +endfunction Copied: trunk/octave-forge/main/financial/inst/x2mdate.m (from rev 10260, trunk/octave-forge/main/time/inst/x2mdate.m) =================================================================== --- trunk/octave-forge/main/financial/inst/x2mdate.m (rev 0) +++ trunk/octave-forge/main/financial/inst/x2mdate.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,75 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {datenums =} x2mdate (exceldatenums) +## @deftypefnx {Function File} {datenums =} x2mdate (exceldatenums, convention) +## @deftypefnx {Function File} {datenums =} x2mdate (exceldatenums, convention, "ExcelBug") +## +## Convert @var{datenums} from the Microsoft Excel date format to the +## format used by @code{datenum}. If set to 0 (default, Excel for +## Windows), @var{convention} specifies to use the Excel 1900 convention +## where Jan 1, 1900 corresponds to Excel serial date number 1. If set +## to 1 (Excel for Mac), @var{convention} specifies to use the Excel +## 1904 convention where Jan 1, 1904 corresponds to Excel serial date +## number 0. +## +## Note that this does not take into account the Excel bug where 1900 is +## considered to be a leap year unless you give the "ExcelBug" option. +## +## Excel does not represent dates prior to 1 January 1900 using this +## format, so a warning will be issued if any dates preceed this date. +## +## @seealso{datenum, x2mdate} +## @end deftypefn + +function dates = x2mdate (dates, convention, excelbug) + + if nargin == 1 + convention = 0; + excelbug = false(); + elseif nargin == 2 + excelbug = false(); + elseif nargin == 3 + excelbug = strcmpi(excelbug, "ExcelBug"); + else + print_usage (); + endif + + if any (dates < 0) + warning ("Negative date found, this will not work within MS Excel.") + endif + + if convention == 0 + adj = datenum(1900, 1, 1) - 2; + elseif convention == 1 + adj = datenum(1904, 1, 1); + endif + + if excelbug + datemask = (dates < 61); + dates(datemask) = dates(datemask) + 1; + endif + dates = dates + adj; + +endfunction + +## Tests +%!assert(x2mdate(39448), datenum(2008, 1, 1)) +%!assert(x2mdate([39083 39448]), datenum(2007:2008, 1, 1)) +%!assert(x2mdate(2), datenum(1900, 1, 1)) +%!assert(x2mdate(1, 0, "ExcelBug"), datenum(1900, 1, 1)) +%!assert(x2mdate(0, 1), datenum(1904, 1, 1)) + Copied: trunk/octave-forge/main/financial/inst/year.m (from rev 10260, trunk/octave-forge/main/time/inst/year.m) =================================================================== --- trunk/octave-forge/main/financial/inst/year.m (rev 0) +++ trunk/octave-forge/main/financial/inst/year.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,30 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {y =} year (Date) +## +## Returns the year from a serial date number or a date string. +## +## @seealso{date, datevec, now, day, month} +## @end deftypefn + +function t = year (dates) + + t = datevec (dates); + t = t (:,1); + +endfunction + Copied: trunk/octave-forge/main/financial/inst/yeardays.m (from rev 10260, trunk/octave-forge/main/time/inst/yeardays.m) =================================================================== --- trunk/octave-forge/main/financial/inst/yeardays.m (rev 0) +++ trunk/octave-forge/main/financial/inst/yeardays.m 2012-04-17 12:03:41 UTC (rev 10262) @@ -0,0 +1,111 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) an... [truncated message content] |
From: <car...@us...> - 2012-04-17 14:04:40
|
Revision: 10264 http://octave.svn.sourceforge.net/octave/?rev=10264&view=rev Author: carandraug Date: 2012-04-17 14:04:28 +0000 (Tue, 17 Apr 2012) Log Message: ----------- financial/time: moved the rest of time package into financial. Time package is now a dummy package, transitional, only listing the financial package as dependency. Updated NEWS file of both packages and deprecated datesplit. Modified Paths: -------------- trunk/octave-forge/main/financial/DESCRIPTION trunk/octave-forge/main/time/DESCRIPTION trunk/octave-forge/main/time/NEWS Added Paths: ----------- trunk/octave-forge/main/financial/INDEX trunk/octave-forge/main/financial/NEWS trunk/octave-forge/main/financial/inst/datesplit.m trunk/octave-forge/main/financial/inst/easter.m Removed Paths: ------------- trunk/octave-forge/main/time/inst/datesplit.m trunk/octave-forge/main/time/inst/easter.m Modified: trunk/octave-forge/main/financial/DESCRIPTION =================================================================== --- trunk/octave-forge/main/financial/DESCRIPTION 2012-04-17 13:33:51 UTC (rev 10263) +++ trunk/octave-forge/main/financial/DESCRIPTION 2012-04-17 14:04:28 UTC (rev 10264) @@ -2,11 +2,11 @@ Version: 0.3.2 Date: 2008-08-17 Author: Bill Denney <bi...@de...>, Kurt Hornik <Kur...@wu...> -Maintainer: Octave Community +Maintainer: Octave-Forge community <oct...@li...> Title: Financial -Description: Financial manipulation and plotting functions -Categories: Financial -Depends: octave (>= 3.0.0), time (>= 1.0.5), miscellaneous (>= 1.0.6) -Autoload: yes +Description: Financial manipulation, plotting functions and additional + date manipulation tools. +Depends: octave (>= 3.0.1), miscellaneous (>= 1.0.6) +Autoload: no License: GPL version 3 and GPL version 2 or later Url: http://octave.sf.net Added: trunk/octave-forge/main/financial/INDEX =================================================================== --- trunk/octave-forge/main/financial/INDEX (rev 0) +++ trunk/octave-forge/main/financial/INDEX 2012-04-17 14:04:28 UTC (rev 10264) @@ -0,0 +1,61 @@ +financial >> Financial +Financial + cfconv + cfdur + corr2cov + cov2corr + effrr + fetch + fvl + fv + google + hhigh + irr + llow + mirr + movavg + negvolidx + nomrr + nper + npv + onbalvol + pmt + posvolidx + pvl + pv + rate + rsindex + taxedrr + vol + yahoo +Plot + bolling + dateaxis + highlow + pointfig +Time + busdate + busdays + datefind + datesplit + day + daysact + easter + eomdate + fbusdate + holidays + hour + isbusday + lbusdate + lweekdate + m2xdate + minute + month + months + nweekdate + second + thirdwednesday + today + x2mdate + yeardays + year Added: trunk/octave-forge/main/financial/NEWS =================================================================== --- trunk/octave-forge/main/financial/NEWS (rev 0) +++ trunk/octave-forge/main/financial/NEWS 2012-04-17 14:04:28 UTC (rev 10264) @@ -0,0 +1,37 @@ +Summary of important user-visible changes for financial 0.4.0: +------------------------------------------------------------------- + + ** The following functions are new at financial 0.4.0: + + cfconv cfdur corr2cov cov2corr + + ** The following functions have been imported from the time package + which has been removed (it is now simply a dummy package that + lists the financial package as its single dependency): + + busdate busdays datefind datesplit + day daysact easter eomdate + fbusdate holidays hour isbusday + lbusdate lweekdate m2xdate minute + month months nweekdate second + thirdwednesday today x2mdate year + yeardays + + ** The following functions were made private (`fetch' should be used + directly instead): + + __fetch_google__ __fetch_yahoo__ + + ** The function `datesplit' (just imported from the time package) has + been deprecated in favour of `datevec' from Octave-core. + + ** The functions `rate' and `irr' should now be compatible with new + releases of octave. + + ** The function `fetch' should now work properly when using google + finnance to adapt to the UTF-8 file received. + + ** The function `dateaxis' should no longer enter in debug mode at the + end of its call. + + ** Package is no longer automatically loaded. Copied: trunk/octave-forge/main/financial/inst/datesplit.m (from rev 10262, trunk/octave-forge/main/time/inst/datesplit.m) =================================================================== --- trunk/octave-forge/main/financial/inst/datesplit.m (rev 0) +++ trunk/octave-forge/main/financial/inst/datesplit.m 2012-04-17 14:04:28 UTC (rev 10264) @@ -0,0 +1,492 @@ +## Copyright (C) 2001 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {Y =} datesplit(date, P) +## @deftypefnx {Function File} {[Y,M,D,h,m,s] =} datesplit(date, P) +## Split a date string into the Year, Month, Day, hour, minute, and +## second. This routine tries to be as forgiving as possible to the +## date input while requiring that the date is not ambiguous. +## +## Anywhere possible where it would not be ambiguous, efforts were made +## to make times possible with seconds and AM/PM as optional. Also, +## along the same lines, where possible, commas were allowed with +## spaces, and the year/month/day separators were allowed as period (.), +## slash (/), and dash (-). Not all format possibilities are shown in +## the following table, but a date like @code{dd-mmm-yyyy HH:MM:SS} is +## parsed just as well as @code{d/mmm.yyyy, ,H:MM, AM}. +## +## Supported @code{date} formats include (the same as datestr): +## @multitable @columnfractions 0.1 0.45 0.45 +## @item @strong{Code} @tab @strong{Format} @tab @strong{Example} +## @item 0 @tab dd-mmm-yyyy HH:MM:SS @tab 07-Sep-2000 15:38:09 +## @item 1 @tab dd-mmm-yyyy @tab 07-Sep-2000 +## @item 2 @tab mm/dd/yy @tab 09/07/00 +## @item 3 @tab mmm @tab Sep +## @item 6 @tab mm/dd @tab 09/13 +## @item 10 @tab yyyy @tab 2000 +## @item 12 @tab mmmyy @tab Sep00 +## @item 13 @tab HH:MM:SS @tab 15:38:09 +## @item 14 @tab HH:MM:SS PM @tab 03:38:09 PM +## @item 15 @tab HH:MM @tab 15:38 +## @item 16 @tab HH:MM PM @tab 03:38 PM +## @item 17 @tab QQ-YY @tab Q3-00 +## @item 19 @tab dd/mm @tab 13/03 +## @item 20 @tab dd/mm/yy @tab 13/03/95 +## @item 21 @tab mmm.dd.yyyy HH:MM:SS @tab Mar.03.1962 13:53:06 +## @item 22 @tab mmm.dd.yyyy @tab Mar.03.1962 +## @item 23 @tab mm/dd/yyyy @tab 03/13/1962 +## @item 24 @tab dd/mm/yyyy @tab 12/03/1962 +## @item 25 @tab yy/mm/dd @tab 95/03/13 +## @item 26 @tab yyyy/mm/dd @tab 1995/03/13 +## @item 27 @tab QQ-YYYY @tab Q4-2132 +## @item 28 @tab mmmyyyy @tab Mar2047 +## @item 29 @tab yyyymmdd @tab 20470313 +## @item 30 @tab yyyymmddTHHMMSS @tab 20470313T132603 +## @item 31 @tab yyyy-mm-dd HH:MM:SS @tab 1047-03-13 13:26:03 +## @end multitable +## +## The parameter @code{P} is needed to convert date strings with 2 digit +## years into dates with 4 digit years. 2 digit years are assumed to be +## between @code{P} and @code{P+99}. If @code{P} is not given then the +## current year - 50 is used, so that dates are centered on the present. +## For birthdates, you would want @code{P} to be current year - 99. For +## appointments, you would want @code{P} to be current year. +## +## This function makes no strong attempt to verify the accuracy of the +## numbers that it returns in that it doesn't (currently) check to see +## that you're not trying to use the date Feb 30. When applicable, it +## tries to make your input work, though. It will try to determine if +## you're using the date "03/13/95" that the date is "March 13, 1995", +## but if there is doubt, datesplit will return an error instead of +## trying to guess the wrong value. +## +## @seealso{date,clock,now,datestr,datenum,calendar,weekday} +## @end deftypefn + +## TODO: +## * Some formats are ambiguous. Allow the user to specify the format +## to remove ambiguity. +## * Validate the dates. +## * Possible bug (after dates are validated): There are times where +## the year is assumed, Feb 29 may be a valid date, but with the +## assumed year, it may become invalid. +## * Internationalize. Not all months use the English system. +## * Vectorize. That requires vectorization of regexp though... + +function [y, m, d, h, mi, s] = datesplit(ds, P) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "`datesplit' has been deprecated in favor of `datevec' from Octave core. This function will be removed from future versions of the `financial' package"); + endif + + if nargin < 2 + P = []; + endif + + today = datevec(now); + + if (isempty(P)) + P = today(1)-50; + endif + + global __month_names = ["Jan";"Feb";"Mar";"Apr";"May";"Jun";... + "Jul";"Aug";"Sep";"Oct";"Nov";"Dec"]; + global __day_names = ["Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"]; + global __time_names = ["AM";"PM"]; + + if (iscellstr(ds)) + ds = ds{1}; + endif + ds = tolower(deblank(ds)); + + if (nargin < 1) + error("datesplit: no input arguments"); + elseif (nargin == 1) + fmt = []; + endif + %% we have to determine the format, this could be error prone + + ## format 0 dd-mmm-yyyy HH:MM:SS e.g. 07-Sep-2000 15:38:09 + [match, d, m, y, h, mi, s, ap] = \ + of_regexp("^(3[01]|[0-2]?[0-9])[-./]([a-z]{3})[-./]([0-9]{4})[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); + + ## format 21 mmm.dd.yyyy HH:MM:SS e.g. Mar.03.1962 13:53:06 + if (isempty(match)) + [match, m, d, y, h, mi, s, ap] = \ + of_regexp("^([a-z]{3})[-./](3[01]|[0-2]?[0-9])[-./]([0-9]{4})[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); + endif + + ## format 31 yyyy-mm-dd HH:MM:SS e.g. 2004-03-13 13:26:03 + if (isempty(match)) + [match, y, m, d, h, mi, s, ap] = \ + of_regexp("^([0-9]{4})[-./](1[012]|0?[0-9])[-./](3[01]|[0-2]?[0-9])[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); + endif + + ## format 30 yyyymmddTHHMMSS e.g. 20470313T132603 + if (isempty(match)) + [match, y, m, d, h, mi, s] = \ + of_regexp("^([0-9]{4})(1[012]|0[0-9])(3[01]|[012][0-9])t(2[0-3]|[01][0-9])([0-5][0-9])([0-5][0-9])$", ds); + ap = "NA"; + endif + + ## format 13 HH:MM:SS e.g. 15:38:09 + ## format 14 HH:MM:SS PM e.g. 03:38:09 PM + ## format 15 HH:MM e.g. 15:38 + ## format 16 HH:MM PM e.g. 03:38 PM + if (isempty(match)) + [match, h, mi, s, ap] = \ + of_regexp("^(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); + + if (! isempty(match)) + %% assume that it is as of today + y = today(1); + m = today(2); + d = today(3); + endif + endif + + ## format 1 dd-mmm-yyyy e.g. 07-Sep-2000 + if (isempty(match)) + [match, d, m, y] = \ + of_regexp("^(3[01]|[012]?[0-9])[-./]([a-z]{3})[-./]([0-9]{4})$", ds); + + if (! isempty(match)) + %% assume the beginning of the day + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 22 mmm.dd.yyyy e.g. Mar.03.1962 + if (isempty(match)) + [match, m, d, y] = \ + of_regexp("^([a-z]{3})[-./](3[01]|[012]?[0-9])[-./]([0-9]{4})$", ds); + + if (! isempty(match)) + %% assume the beginning of the day + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 2 mm/dd/yy e.g. 09/07/00 + ## format 23 mm/dd/yyyy e.g. 03/13/1962 + ## format 20 dd/mm/yy e.g. 13/03/95 + ## format 24 dd/mm/yyyy e.g. 12/03/1962 + ## format 25 yy/mm/dd e.g. 95/03/13 + ## format 26 yyyy/mm/dd e.g. 1995/03/13 + if (isempty(match)) + [match, d, m, y] = \ + of_regexp("^([0-9]{1,2}|[0-9]{4})[-./](3[01]|[012]?[0-9])[-./]([0-9]{1,2}|[0-9]{4})$", ds); + + if (! isempty(match)) + %% we have to determine if the date is unambiguous + d = str2num(d); + m = str2num(m); + y = str2num(y); + + if ((y == 0) || (y > 31)) + %% we've got the year correct + if ((m > 12) && (d < 13)) + %% we're operating on mm/dd/yyyy + tmp = m; + m = d; + d = tmp; + elseif ((m < 13) && (d > 12)) + %% it's fine + else + %% it's ambiguous + error(["datesplit: ambiguous date " ds]); + endif + elseif ((d == 0) || (d > 31)) + %% the day and the year need to be switched + tmp = y; + y = d; + d = tmp; + else + %% it's ambiguous + error(["datesplit: ambiguous date " ds]); + endif + + %% assume the beginning of the day + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + + endif + + ## format 29 yyyymmdd e.g. 20470313 + if (isempty(match)) + [match, y, m, d] = \ + of_regexp("^([0-9]{4})(1[012]|0?[0-9])(3[01]|[012][0-9])$", ds); + %% I've never seen a date that has the year first that was not + %% yyyy/mm/dd, so I'm going to assume that it's unambiguous. + + if (! isempty(match)) + %% assume the beginning of the day + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 17 QQ-YY e.g. Q3-00 + ## format 27 QQ-YYYY e.g. Q4-2132 + if (isempty(match)) + [match, q, y] = \ + of_regexp("^q([1-4])[-./]([0-9]{2}|[0-9]{4})$", ds); + if (! isempty(match)) + %% Assume that it's the end of the quarter + q = str2num(q); + m = 3*q; + dayopts = [31 30 30 31]; + d = dayopts(q); + + %% assume the end of the day + h = 23; + mi = 59; + s = 59; + ap = "NA"; + endif + endif + + ## format 28 mmmyyyy e.g. Mar2047 + ## format 12 mmmyy e.g. Sep00 + if (isempty(match)) + [match, m, y] = \ + of_regexp("^([a-z]{3})([0-9]{2}|[0-9]{4})$", ds); + if (! isempty(match)) + %% assume the beginning of the month + d = 1; + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 6 mm/dd e.g. 09/07 + ## format 19 dd/mm e.g. 13/03 + if (isempty(match)) + [match, m, d] = \ + of_regexp("^(3[01]|[012]?[0-9])[-./](3[01]|[012][0-9])$", ds); + + if (! isempty(match)) + m = str2num(m); + d = str2num(d); + + %% we have to determine if the date is unambiguous + if ((m > 12) && (d < 13)) + %% we're operating on mm/dd/yyyy + tmp = m; + m = d; + d = tmp; + elseif ((m < 13) && (d > 12)) + %% it's fine + else + %% it's ambiguous + error(["datesplit: ambiguous date " ds]); + endif + %% assume this year and the beginning of the day + y = today(1); + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 10 yyyy e.g. 2000 + if (isempty(match)) + [match, y] = of_regexp("^([0-9]{4})$", ds); + + if (! isempty(match)) + %% assume the beginning of the year + m = 1; + d = 1; + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 3 mmm e.g. Sep + if (isempty(match)) + m = strmatch(ds, tolower(__month_names)); + + if (! isempty(m)) + match = 1; + %% assuming the beginning of the month, this year + y = today(1); + d = 1; + h = 0; + mi = 0; + s = 0; + ap = "NA"; + endif + endif + + ## format 8 ddd e.g. Thu + %% People shouldn't use this function for something like this + + if (isempty(match)) + %% you mean I did all that work, and you still didn't use a valid + %% date? Darn you! + error(["datesplit: Unknown date format " ds]); + endif + + if (! isempty(match)) + if isempty(s) + s = 0; + elseif (ischar(s) && (1 == findstr(s,":"))) + s = s(2:3); + endif + if isempty(ap) + ap = "NA"; + endif + endif + + %% start converting the date from characters to numbers + if (ischar(y)) + y = str2num(y); + if (isempty(y)) + error(["datesplit: Invalid year specification " y]); + endif + endif + %% Handle Y2K issues... + if (y < 100) + y = y + 1900; + if (y < P) + y = y + 100; + endif + endif + + if (ischar(m)) + m_num = str2num(m); + if (isempty(m_num)) + m = strmatch(m, tolower(__month_names)); + else + m = m_num; + endif + if (isempty(m)) + error(["datesplit: Invalid month specification"]); + endif + endif + + if (ischar(d)) + d = str2num(d); + if (isempty(d)) + error(["datesplit: Invalid day specification " d]); + endif + endif + + if (ischar(h)) + h = str2num(h); + if (isempty(h)) + error(["datesplit: Invalid hour specification " h]); + elseif ((ap(2) == "M") && (h > 12)) + error(["datesplit: Invalid hour specification, AM or PM specified but" + "hour is greater than 12."]); + endif + + if (strcmpi(ap, "PM") && (h < 12)) + h = h + 12; + elseif (strcmpi(ap, "AM") && (h == 12)) + h = 0; + endif + endif + + if (ischar(mi)) + mi = str2num(mi); + if (isempty(mi) || (mi > 59)) + error(["datesplit: Invalid minute specification " mi]); + endif + endif + + if (ischar(s)) + s = str2num(s); + if (isempty(s) || (s > 59)) + error(["datesplit: Invalid second specification " s]); + endif + endif + + if (nargout <= 1) + y = [y, m, d, h, mi, s]; + endif + +endfunction + +# wrapper around Octave's regexp +# compatible with octave-forge's regexp + +function varargout = of_regexp(pattern,string) + [S, E, TE, M, T, NM] = regexp(string,pattern); + varargout{1} = S; + + # return sub-strings if match + if (S) + for i=2:nargout + varargout{i} = T{1}{i-1}; + end + else + for i=2:nargout + varargout{i} = []; + end + end +endfunction + + +%!shared nowvec +%! nowvec=datevec(now); % Some tests could fail around midnight! +%!assert (datevec("07-Sep-2000 15:38:09"),[2000,9,7,15,38,9]); +%!assert (datevec("07-Sep-2000"),[2000,9,7,0,0,0]); +%!assert (datevec("1 Jan 2000"),[2000,1,1,0,0,0]); +%!assert (datevec("Sep00"),[2000,9,1,0,0,0]); +%!assert (datevec("15:38:09"),[nowvec(1:3),15,38,9]); +%!assert (datevec("03:38:09 PM"),[nowvec(1:3),15,38,9]); +%!assert (datevec("15:38"),[nowvec(1:3),15,38,0]); +%!assert (datevec("3:38 PM"),[nowvec(1:3),15,38,0]); +%!assert (datevec("03/13/1962"),[1962,3,13,0,0,0]); + +## Ambiguous +%!#assert (datevec("09/07/00"),[2000,9,7,0,0,0]); +%!#assert (datevec("09/13"),[nowvec(1),9,13,0,0,0]); + +## Not supported in octave version of datevec +%!#assert (datevec("Sep"),[nowvec(1),9,1,0,0,0]); +%!#assert (datevec("Q3-00"),[2000,9,30,23,59,59]); +%!#assert (datevec("Q4-2132"),[2132,12,31,23,59,59]); + +## This should be a standard string (without or without the time) +%!assert (datevec("Mar.03.1962 13:53:06","mmm.dd.yyyy HH:MM:SS"),[1962,3,3,13,53,6]); + +## No longer a predefined string to parse the date in octave version +%!assert (datevec("1995/03/13","yyyy/mm/dd"),[1995,3,13,0,0,0]); +%!assert (datevec("Mar2047","mmmyyyy"),[2047,3,1,0,0,0]); +%!assert (datevec("20470313","yyyymmdd"),[2047,3,13,0,0,0]); +%!assert (datevec("20470313T132603","yyyymmddTHHMMSS"),[2047,3,13,13,26,3]); +%!assert (datevec("1047-03-13 13:26:03","yyyy-mm-dd HH:MM:SS"),[1047,3,13,13,26,3]); Copied: trunk/octave-forge/main/financial/inst/easter.m (from rev 10262, trunk/octave-forge/main/time/inst/easter.m) =================================================================== --- trunk/octave-forge/main/financial/inst/easter.m (rev 0) +++ trunk/octave-forge/main/financial/inst/easter.m 2012-04-17 14:04:28 UTC (rev 10264) @@ -0,0 +1,69 @@ +## Copyright (C) 2008 Bill Denney <bi...@de...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[m, d] =} easter (y) +## @deftypefnx {Function File} {datenum =} easter (y) +## +## Return the month (@var{m}) and day (@var{d}) of Easter in the +## Gregorial calendar on a given year or years. +## +## @seealso{holidays} +## @end deftypefn + +function varargout = easter (y) + + ## This uses the Meesus/Jones/Butcher Gregorian algorithm as described + ## on http://en.wikipedia.org/wiki/Computus#Algorithms + a = mod (y, 19); + b = floor (y/100); + c = mod (y, 100); + d = floor (b/4); + e = mod (b, 4); + f = floor ((b + 8)/25); + g = floor ((b - f + 1)/3); + h = mod ((19*a+b-d-g+15), 30); + i = floor (c/4); + k = mod (c, 4); + L = mod ((32 + 2*e + 2*i - h - k), 7); + m = floor ((a + 11*h + 22*L)/451); + mon = floor ((h + L - 7*m + 114)/31); + day = 1 + mod ((h + L - 7*m + 114), 31); + + if nargout == 2 + varargout = {mon(:), day(:)}; + else + varargout{1} = reshape (datenum (y(:), mon(:), day(:)), size (y)); + end + +endfunction + +## Tests +## Validate that it calculates the correct date for a decade +%!assert(easter(1990), datenum(1990, 4, 15)) +%!assert(easter(1991), datenum(1991, 3, 31)) +%!assert(easter(1992), datenum(1992, 4, 19)) +%!assert(easter(1993), datenum(1993, 4, 11)) +%!assert(easter(1994), datenum(1994, 4, 3)) +%!assert(easter(1995), datenum(1995, 4, 16)) +%!assert(easter(1996), datenum(1996, 4, 7)) +%!assert(easter(1997), datenum(1997, 3, 30)) +%!assert(easter(1998), datenum(1998, 4, 12)) +%!assert(easter(1999), datenum(1999, 4, 4)) +## Validate vector and matrix inputs +%!assert(easter([2000 2001]), [datenum(2000, 4, 23) datenum(2001, 4, 15)]) +%!assert(easter([2002;2003]), [datenum(2002, 3, 31);datenum(2003, 4, 20)]) +%!assert(easter([2004 2005;2006 2007;2008 2009]), [datenum(2004, 4, 11) datenum(2005, 3, 27);datenum(2006, 4, 16) datenum(2007, 4, 8);datenum(2008, 3, 23) datenum(2009, 4, 12)]) +%!assert(easter([2002;2003]), [datenum(2002, 3, 31);datenum(2003, 4, 20)]) Modified: trunk/octave-forge/main/time/DESCRIPTION =================================================================== --- trunk/octave-forge/main/time/DESCRIPTION 2012-04-17 13:33:51 UTC (rev 10263) +++ trunk/octave-forge/main/time/DESCRIPTION 2012-04-17 14:04:28 UTC (rev 10264) @@ -4,9 +4,10 @@ Author: Bill Denney <bi...@de...> Maintainer: Octave-Forge community <oct...@li...> Title: Time and Dates -Description: Additional date manipulation tools. +Description: Additional date manipulation tools. This a dummy package + as transition for the financial package. Categories: Time -Depends: octave (>= 3.0.1) +Depends: financial (>= 0.4.0) Autoload: no License: GPLv3+ Url: http://octave.sf.net Modified: trunk/octave-forge/main/time/NEWS =================================================================== --- trunk/octave-forge/main/time/NEWS 2012-04-17 13:33:51 UTC (rev 10263) +++ trunk/octave-forge/main/time/NEWS 2012-04-17 14:04:28 UTC (rev 10264) @@ -1,5 +1,13 @@ Summary of important user-visible changes for time 2.0.0: ------------------------------------------------------------------- + ** VERY IMPORTANT: the time package has been removed. All its functions + have been moved to the financial package (23 of its 25 functions are + part of Matlab's financial toolbox). To avoid transition problems, this + new release is merely a dummy package with no functions, and dependent + on the new version of the financial package. + + ** The function `datesplit' (now part of the financial package) has been + deprecated in favour of `datevec' from Octave-core. + ** Package is no longer automatically loaded. - Deleted: trunk/octave-forge/main/time/inst/datesplit.m =================================================================== --- trunk/octave-forge/main/time/inst/datesplit.m 2012-04-17 13:33:51 UTC (rev 10263) +++ trunk/octave-forge/main/time/inst/datesplit.m 2012-04-17 14:04:28 UTC (rev 10264) @@ -1,485 +0,0 @@ -## Copyright (C) 2001 Bill Denney <bi...@de...> -## -## This program is free software; you can redistribute it and/or modify it under -## the terms of the GNU General Public License as published by the Free Software -## Foundation; either version 3 of the License, or (at your option) any later -## version. -## -## This program is distributed in the hope that it will be useful, but WITHOUT -## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -## details. -## -## You should have received a copy of the GNU General Public License along with -## this program; if not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {Y =} datesplit(date, P) -## @deftypefnx {Function File} {[Y,M,D,h,m,s] =} datesplit(date, P) -## Split a date string into the Year, Month, Day, hour, minute, and -## second. This routine tries to be as forgiving as possible to the -## date input while requiring that the date is not ambiguous. -## -## Anywhere possible where it would not be ambiguous, efforts were made -## to make times possible with seconds and AM/PM as optional. Also, -## along the same lines, where possible, commas were allowed with -## spaces, and the year/month/day separators were allowed as period (.), -## slash (/), and dash (-). Not all format possibilities are shown in -## the following table, but a date like @code{dd-mmm-yyyy HH:MM:SS} is -## parsed just as well as @code{d/mmm.yyyy, ,H:MM, AM}. -## -## Supported @code{date} formats include (the same as datestr): -## @multitable @columnfractions 0.1 0.45 0.45 -## @item @strong{Code} @tab @strong{Format} @tab @strong{Example} -## @item 0 @tab dd-mmm-yyyy HH:MM:SS @tab 07-Sep-2000 15:38:09 -## @item 1 @tab dd-mmm-yyyy @tab 07-Sep-2000 -## @item 2 @tab mm/dd/yy @tab 09/07/00 -## @item 3 @tab mmm @tab Sep -## @item 6 @tab mm/dd @tab 09/13 -## @item 10 @tab yyyy @tab 2000 -## @item 12 @tab mmmyy @tab Sep00 -## @item 13 @tab HH:MM:SS @tab 15:38:09 -## @item 14 @tab HH:MM:SS PM @tab 03:38:09 PM -## @item 15 @tab HH:MM @tab 15:38 -## @item 16 @tab HH:MM PM @tab 03:38 PM -## @item 17 @tab QQ-YY @tab Q3-00 -## @item 19 @tab dd/mm @tab 13/03 -## @item 20 @tab dd/mm/yy @tab 13/03/95 -## @item 21 @tab mmm.dd.yyyy HH:MM:SS @tab Mar.03.1962 13:53:06 -## @item 22 @tab mmm.dd.yyyy @tab Mar.03.1962 -## @item 23 @tab mm/dd/yyyy @tab 03/13/1962 -## @item 24 @tab dd/mm/yyyy @tab 12/03/1962 -## @item 25 @tab yy/mm/dd @tab 95/03/13 -## @item 26 @tab yyyy/mm/dd @tab 1995/03/13 -## @item 27 @tab QQ-YYYY @tab Q4-2132 -## @item 28 @tab mmmyyyy @tab Mar2047 -## @item 29 @tab yyyymmdd @tab 20470313 -## @item 30 @tab yyyymmddTHHMMSS @tab 20470313T132603 -## @item 31 @tab yyyy-mm-dd HH:MM:SS @tab 1047-03-13 13:26:03 -## @end multitable -## -## The parameter @code{P} is needed to convert date strings with 2 digit -## years into dates with 4 digit years. 2 digit years are assumed to be -## between @code{P} and @code{P+99}. If @code{P} is not given then the -## current year - 50 is used, so that dates are centered on the present. -## For birthdates, you would want @code{P} to be current year - 99. For -## appointments, you would want @code{P} to be current year. -## -## This function makes no strong attempt to verify the accuracy of the -## numbers that it returns in that it doesn't (currently) check to see -## that you're not trying to use the date Feb 30. When applicable, it -## tries to make your input work, though. It will try to determine if -## you're using the date "03/13/95" that the date is "March 13, 1995", -## but if there is doubt, datesplit will return an error instead of -## trying to guess the wrong value. -## -## @seealso{date,clock,now,datestr,datenum,calendar,weekday} -## @end deftypefn - -## TODO: -## * Some formats are ambiguous. Allow the user to specify the format -## to remove ambiguity. -## * Validate the dates. -## * Possible bug (after dates are validated): There are times where -## the year is assumed, Feb 29 may be a valid date, but with the -## assumed year, it may become invalid. -## * Internationalize. Not all months use the English system. -## * Vectorize. That requires vectorization of regexp though... - -function [y, m, d, h, mi, s] = datesplit(ds, P) - - if nargin < 2 - P = []; - endif - - today = datevec(now); - - if (isempty(P)) - P = today(1)-50; - endif - - global __month_names = ["Jan";"Feb";"Mar";"Apr";"May";"Jun";... - "Jul";"Aug";"Sep";"Oct";"Nov";"Dec"]; - global __day_names = ["Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"]; - global __time_names = ["AM";"PM"]; - - if (iscellstr(ds)) - ds = ds{1}; - endif - ds = tolower(deblank(ds)); - - if (nargin < 1) - error("datesplit: no input arguments"); - elseif (nargin == 1) - fmt = []; - endif - %% we have to determine the format, this could be error prone - - ## format 0 dd-mmm-yyyy HH:MM:SS e.g. 07-Sep-2000 15:38:09 - [match, d, m, y, h, mi, s, ap] = \ - of_regexp("^(3[01]|[0-2]?[0-9])[-./]([a-z]{3})[-./]([0-9]{4})[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); - - ## format 21 mmm.dd.yyyy HH:MM:SS e.g. Mar.03.1962 13:53:06 - if (isempty(match)) - [match, m, d, y, h, mi, s, ap] = \ - of_regexp("^([a-z]{3})[-./](3[01]|[0-2]?[0-9])[-./]([0-9]{4})[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); - endif - - ## format 31 yyyy-mm-dd HH:MM:SS e.g. 2004-03-13 13:26:03 - if (isempty(match)) - [match, y, m, d, h, mi, s, ap] = \ - of_regexp("^([0-9]{4})[-./](1[012]|0?[0-9])[-./](3[01]|[0-2]?[0-9])[, ]+(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); - endif - - ## format 30 yyyymmddTHHMMSS e.g. 20470313T132603 - if (isempty(match)) - [match, y, m, d, h, mi, s] = \ - of_regexp("^([0-9]{4})(1[012]|0[0-9])(3[01]|[012][0-9])t(2[0-3]|[01][0-9])([0-5][0-9])([0-5][0-9])$", ds); - ap = "NA"; - endif - - ## format 13 HH:MM:SS e.g. 15:38:09 - ## format 14 HH:MM:SS PM e.g. 03:38:09 PM - ## format 15 HH:MM e.g. 15:38 - ## format 16 HH:MM PM e.g. 03:38 PM - if (isempty(match)) - [match, h, mi, s, ap] = \ - of_regexp("^(2[0-3]|[01]?[0-9]):([0-5][0-9])(:[0-5][0-9]|)[, ]*([ap]m|)$", ds); - - if (! isempty(match)) - %% assume that it is as of today - y = today(1); - m = today(2); - d = today(3); - endif - endif - - ## format 1 dd-mmm-yyyy e.g. 07-Sep-2000 - if (isempty(match)) - [match, d, m, y] = \ - of_regexp("^(3[01]|[012]?[0-9])[-./]([a-z]{3})[-./]([0-9]{4})$", ds); - - if (! isempty(match)) - %% assume the beginning of the day - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 22 mmm.dd.yyyy e.g. Mar.03.1962 - if (isempty(match)) - [match, m, d, y] = \ - of_regexp("^([a-z]{3})[-./](3[01]|[012]?[0-9])[-./]([0-9]{4})$", ds); - - if (! isempty(match)) - %% assume the beginning of the day - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 2 mm/dd/yy e.g. 09/07/00 - ## format 23 mm/dd/yyyy e.g. 03/13/1962 - ## format 20 dd/mm/yy e.g. 13/03/95 - ## format 24 dd/mm/yyyy e.g. 12/03/1962 - ## format 25 yy/mm/dd e.g. 95/03/13 - ## format 26 yyyy/mm/dd e.g. 1995/03/13 - if (isempty(match)) - [match, d, m, y] = \ - of_regexp("^([0-9]{1,2}|[0-9]{4})[-./](3[01]|[012]?[0-9])[-./]([0-9]{1,2}|[0-9]{4})$", ds); - - if (! isempty(match)) - %% we have to determine if the date is unambiguous - d = str2num(d); - m = str2num(m); - y = str2num(y); - - if ((y == 0) || (y > 31)) - %% we've got the year correct - if ((m > 12) && (d < 13)) - %% we're operating on mm/dd/yyyy - tmp = m; - m = d; - d = tmp; - elseif ((m < 13) && (d > 12)) - %% it's fine - else - %% it's ambiguous - error(["datesplit: ambiguous date " ds]); - endif - elseif ((d == 0) || (d > 31)) - %% the day and the year need to be switched - tmp = y; - y = d; - d = tmp; - else - %% it's ambiguous - error(["datesplit: ambiguous date " ds]); - endif - - %% assume the beginning of the day - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - - endif - - ## format 29 yyyymmdd e.g. 20470313 - if (isempty(match)) - [match, y, m, d] = \ - of_regexp("^([0-9]{4})(1[012]|0?[0-9])(3[01]|[012][0-9])$", ds); - %% I've never seen a date that has the year first that was not - %% yyyy/mm/dd, so I'm going to assume that it's unambiguous. - - if (! isempty(match)) - %% assume the beginning of the day - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 17 QQ-YY e.g. Q3-00 - ## format 27 QQ-YYYY e.g. Q4-2132 - if (isempty(match)) - [match, q, y] = \ - of_regexp("^q([1-4])[-./]([0-9]{2}|[0-9]{4})$", ds); - if (! isempty(match)) - %% Assume that it's the end of the quarter - q = str2num(q); - m = 3*q; - dayopts = [31 30 30 31]; - d = dayopts(q); - - %% assume the end of the day - h = 23; - mi = 59; - s = 59; - ap = "NA"; - endif - endif - - ## format 28 mmmyyyy e.g. Mar2047 - ## format 12 mmmyy e.g. Sep00 - if (isempty(match)) - [match, m, y] = \ - of_regexp("^([a-z]{3})([0-9]{2}|[0-9]{4})$", ds); - if (! isempty(match)) - %% assume the beginning of the month - d = 1; - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 6 mm/dd e.g. 09/07 - ## format 19 dd/mm e.g. 13/03 - if (isempty(match)) - [match, m, d] = \ - of_regexp("^(3[01]|[012]?[0-9])[-./](3[01]|[012][0-9])$", ds); - - if (! isempty(match)) - m = str2num(m); - d = str2num(d); - - %% we have to determine if the date is unambiguous - if ((m > 12) && (d < 13)) - %% we're operating on mm/dd/yyyy - tmp = m; - m = d; - d = tmp; - elseif ((m < 13) && (d > 12)) - %% it's fine - else - %% it's ambiguous - error(["datesplit: ambiguous date " ds]); - endif - %% assume this year and the beginning of the day - y = today(1); - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 10 yyyy e.g. 2000 - if (isempty(match)) - [match, y] = of_regexp("^([0-9]{4})$", ds); - - if (! isempty(match)) - %% assume the beginning of the year - m = 1; - d = 1; - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 3 mmm e.g. Sep - if (isempty(match)) - m = strmatch(ds, tolower(__month_names)); - - if (! isempty(m)) - match = 1; - %% assuming the beginning of the month, this year - y = today(1); - d = 1; - h = 0; - mi = 0; - s = 0; - ap = "NA"; - endif - endif - - ## format 8 ddd e.g. Thu - %% People shouldn't use this function for something like this - - if (isempty(match)) - %% you mean I did all that work, and you still didn't use a valid - %% date? Darn you! - error(["datesplit: Unknown date format " ds]); - endif - - if (! isempty(match)) - if isempty(s) - s = 0; - elseif (ischar(s) && (1 == findstr(s,":"))) - s = s(2:3); - endif - if isempty(ap) - ap = "NA"; - endif - endif - - %% start converting the date from characters to numbers - if (ischar(y)) - y = str2num(y); - if (isempty(y)) - error(["datesplit: Invalid year specification " y]); - endif - endif - %% Handle Y2K issues... - if (y < 100) - y = y + 1900; - if (y < P) - y = y + 100; - endif - endif - - if (ischar(m)) - m_num = str2num(m); - if (isempty(m_num)) - m = strmatch(m, tolower(__month_names)); - else - m = m_num; - endif - if (isempty(m)) - error(["datesplit: Invalid month specification"]); - endif - endif - - if (ischar(d)) - d = str2num(d); - if (isempty(d)) - error(["datesplit: Invalid day specification " d]); - endif - endif - - if (ischar(h)) - h = str2num(h); - if (isempty(h)) - error(["datesplit: Invalid hour specification " h]); - elseif ((ap(2) == "M") && (h > 12)) - error(["datesplit: Invalid hour specification, AM or PM specified but" - "hour is greater than 12."]); - endif - - if (strcmpi(ap, "PM") && (h < 12)) - h = h + 12; - elseif (strcmpi(ap, "AM") && (h == 12)) - h = 0; - endif - endif - - if (ischar(mi)) - mi = str2num(mi); - if (isempty(mi) || (mi > 59)) - error(["datesplit: Invalid minute specification " mi]); - endif - endif - - if (ischar(s)) - s = str2num(s); - if (isempty(s) || (s > 59)) - error(["datesplit: Invalid second specification " s]); - endif - endif - - if (nargout <= 1) - y = [y, m, d, h, mi, s]; - endif - -endfunction - -# wrapper around Octave's regexp -# compatible with octave-forge's regexp - -function varargout = of_regexp(pattern,string) - [S, E, TE, M, T, NM] = regexp(string,pattern); - varargout{1} = S; - - # return sub-strings if match - if (S) - for i=2:nargout - varargout{i} = T{1}{i-1}; - end - else - for i=2:nargout - varargout{i} = []; - end - end -endfunction - - -%!shared nowvec -%! nowvec=datevec(now); % Some tests could fail around midnight! -%!assert (datevec("07-Sep-2000 15:38:09"),[2000,9,7,15,38,9]); -%!assert (datevec("07-Sep-2000"),[2000,9,7,0,0,0]); -%!assert (datevec("1 Jan 2000"),[2000,1,1,0,0,0]); -%!assert (datevec("Sep00"),[2000,9,1,0,0,0]); -%!assert (datevec("15:38:09"),[nowvec(1:3),15,38,9]); -%!assert (datevec("03:38:09 PM"),[nowvec(1:3),15,38,9]); -%!assert (datevec("15:38"),[nowvec(1:3),15,38,0]); -%!assert (datevec("3:38 PM"),[nowvec(1:3),15,38,0]); -%!assert (datevec("03/13/1962"),[1962,3,13,0,0,0]); - -## Ambiguous -%!#assert (datevec("09/07/00"),[2000,9,7,0,0,0]); -%!#assert (datevec("09/13"),[nowvec(1),9,13,0,0,0]); - -## Not supported in octave version of datevec -%!#assert (datevec("Sep"),[nowvec(1),9,1,0,0,0]); -%!#assert (datevec("Q3-00"),[2000,9,30,23,59,59]); -%!#assert (datevec("Q4-2132"),[2132,12,31,23,59,59]); - -## This should be a standard string (without or without the time) -%!assert (datevec("Mar.03.1962 13:53:06","mmm.dd.yyyy HH:MM:SS"),[1962,3,3,13,53,6]); - -## No longer a predefined string to parse the date in octave version -%!assert (datevec("1995/03/13","yyyy/mm/dd"),[1995,3,13,0,0,0]); -%!assert (datevec("Mar2047","mmmyyyy"),[2047,3,1,0,0,0]); -%!assert (datevec("20470313","yyyymmdd"),[2047,3,13,0,0,0]); -%!assert (datevec("20470313T132603","yyyymmddTHHMMSS"),[2047,3,13,13,26,3]); -%!assert (datevec("1047-03-13 13:26:03","yyyy-mm-dd HH:MM:SS"),[1047,3,13,13,26,3]); Deleted: trunk/octave-forge/main/time/inst/easter.m =================================================================== --- trunk/octave-forge/main/time/inst/easter.m 2012-04-17 13:33:51 UTC (rev 10263) +++ trunk/octave-forge/main/time/inst/easter.m 2012-04-17 14:04:28 UTC (rev 10264) @@ -1,69 +0,0 @@ -## Copyright (C) 2008 Bill Denney <bi...@de...> -## -## This program is free software; you can redistribute it and/or modify it under -## the terms of the GNU General Public License as published by the Free Software -## Foundation; either version 3 of the License, or (at your option) any later -## version. -## -## This program is distributed in the hope that it will be useful, but WITHOUT -## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -## details. -## -## You should have received a copy of the GNU General Public License along with -## this program; if not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[m, d] =} easter (y) -## @deftypefnx {Function File} {datenum =} easter (y) -## -## Return the month (@var{m}) and day (@var{d}) of Easter in the -## Gregorial calendar on a given year or years. -## -## @seealso{holidays} -## @end deftypefn - -function varargout = easter (y) - - ## This uses the Meesus/Jones/Butcher Gregorian algorithm as described - ## on http://en.wikipedia.org/wiki/Computus#Algorithms - a = mod (y, 19); - b = floor (y/100); - c = mod (y, 100); - d = floor (b/4); - e = mod (b, 4); - f = floor ((b + 8)/25); - g = floor ((b - f + 1)/3); - h = mod ((19*a+b-d-g+15), 30); - i = floor (c/4); - k = mod (c, 4); - L = mod ((32 + 2*e + 2*i - h - k), 7); - m = floor ((a + 11*h + 22*L)/451); - mon = floor ((h + L - 7*m + 114)/31); - day = 1 + mod ((h + L - 7*m + 114), 31); - - if nargout == 2 - varargout = {mon(:), day(:)}; - else - varargout{1} = reshape (datenum (y(:), mon(:), day(:)), size (y)); - end - -endfunction - -## Tests -## Validate that it calculates the correct date for a decade -%!assert(easter(1990), datenum(1990, 4, 15)) -%!assert(easter(1991), datenum(1991, 3, 31)) -%!assert(easter(1992), datenum(1992, 4, 19)) -%!assert(easter(1993), datenum(1993, 4, 11)) -%!assert(easter(1994), datenum(1994, 4, 3)) -%!assert(easter(1995), datenum(1995, 4, 16)) -%!assert(easter(1996), datenum(1996, 4, 7)) -%!assert(easter(1997), datenum(1997, 3, 30)) -%!assert(easter(1998), datenum(1998, 4, 12)) -%!assert(easter(1999), datenum(1999, 4, 4)) -## Validate vector and matrix inputs -%!assert(easter([2000 2001]), [datenum(2000, 4, 23) datenum(2001, 4, 15)]) -%!assert(easter([2002;2003]), [datenum(2002, 3, 31);datenum(2003, 4, 20)]) -%!assert(easter([2004 2005;2006 2007;2008 2009]), [datenum(2004, 4, 11) datenum(2005, 3, 27);datenum(2006, 4, 16) datenum(2007, 4, 8);datenum(2008, 3, 23) datenum(2009, 4, 12)]) -%!assert(easter([2002;2003]), [datenum(2002, 3, 31);datenum(2003, 4, 20)]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-23 21:14:41
|
Revision: 10317 http://octave.svn.sourceforge.net/octave/?rev=10317&view=rev Author: carandraug Date: 2012-04-23 20:22:00 +0000 (Mon, 23 Apr 2012) Log Message: ----------- combinatorics: removing package * combs() moved to specfun and deprecated * partcnt and partint moved to miscellaneous package * NEWS/INDEX/Makefile files updated Modified Paths: -------------- trunk/octave-forge/main/combinatorics/DESCRIPTION trunk/octave-forge/main/combinatorics/NEWS trunk/octave-forge/main/miscellaneous/INDEX trunk/octave-forge/main/miscellaneous/NEWS trunk/octave-forge/main/miscellaneous/src/Makefile trunk/octave-forge/main/specfun/NEWS Added Paths: ----------- trunk/octave-forge/main/combinatorics/inst/dummy trunk/octave-forge/main/miscellaneous/PKG_ADD trunk/octave-forge/main/miscellaneous/src/partint.cc trunk/octave-forge/main/miscellaneous/src/partint.h trunk/octave-forge/main/specfun/inst/combs.m Removed Paths: ------------- trunk/octave-forge/main/combinatorics/INDEX trunk/octave-forge/main/combinatorics/PKG_ADD trunk/octave-forge/main/combinatorics/inst/combs.m trunk/octave-forge/main/combinatorics/src/ Modified: trunk/octave-forge/main/combinatorics/DESCRIPTION =================================================================== --- trunk/octave-forge/main/combinatorics/DESCRIPTION 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/combinatorics/DESCRIPTION 2012-04-23 20:22:00 UTC (rev 10317) @@ -1,11 +1,11 @@ Name: Combinatorics Version: 1.0.9 Date: 2009-05-18 -Author: Torsten Finke <fi...@ig...> -Maintainer: Torsten Finke <fi...@ig...> +Author: various authors +Maintainer: Octave-Forge community <oct...@li...> Title: Combinatorics. Description: Combinatorics functions, incuding partitioning. -Depends: octave (>= 2.9.7) +Depends: specfun (>= 1.2.0), miscellaneous (>= 1.2.0) Autoload: no License: GPLv3+ Url: http://octave.sf.net Deleted: trunk/octave-forge/main/combinatorics/INDEX =================================================================== --- trunk/octave-forge/main/combinatorics/INDEX 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/combinatorics/INDEX 2012-04-23 20:22:00 UTC (rev 10317) @@ -1,5 +0,0 @@ -combinatorics >> Combinatorics -Partitions - partint - partcnt - combs Modified: trunk/octave-forge/main/combinatorics/NEWS =================================================================== --- trunk/octave-forge/main/combinatorics/NEWS 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/combinatorics/NEWS 2012-04-23 20:22:00 UTC (rev 10317) @@ -1,4 +1,20 @@ Summary of important user-visible changes for combinatorics 2.0.0: ------------------------------------------------------------------- + ** VERY IMPORTANT: the combinatorics package has been removed. Its + integer partition functions have moved to miscellaneous while + `combs' has been moved to the specfun package. To avoid transition + problems, this new release is merely a dummy package with no functions, + and dependent on the new version of the miscellaneous and specfun + packages. + + ** The function `combs' (now part of the specfun package) has been + deprecated in favour of `nchoosek' from Octave-core which should + perform faster. The only difference is that it does accept string + arrays (which does not make a lot of sense in the first place). To + workaround this, the following can be used: + + char (nchoosek (double (n_string), k)) + ** Package is no longer automatically loaded. + Deleted: trunk/octave-forge/main/combinatorics/PKG_ADD =================================================================== --- trunk/octave-forge/main/combinatorics/PKG_ADD 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/combinatorics/PKG_ADD 2012-04-23 20:22:00 UTC (rev 10317) @@ -1 +0,0 @@ -autoload ("partcnt", fullfile (fileparts (mfilename ("fullpath")), "partint.oct")); Deleted: trunk/octave-forge/main/combinatorics/inst/combs.m =================================================================== --- trunk/octave-forge/main/combinatorics/inst/combs.m 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/combinatorics/inst/combs.m 2012-04-23 20:22:00 UTC (rev 10317) @@ -1,98 +0,0 @@ -## Copyright (C) 2007 Muthiah Annamalai <mut...@ut...> -## -## This program is free software; you can redistribute it and/or modify it under -## the terms of the GNU General Public License as published by the Free Software -## Foundation; either version 3 of the License, or (at your option) any later -## version. -## -## This program is distributed in the hope that it will be useful, but WITHOUT -## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -## details. -## -## You should have received a copy of the GNU General Public License along with -## this program; if not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} @var{rval}= {} combs(@var{sym_set},@var{k}) -## Function generates the nchoosek(N,K) combinations, and returns it. -## compute the combinations nchoosek(length(@var{sym_set}), @var{k}) -## nchoosek() is a much faster variant of this function. -## @example -## @group -## -## combs([1,2,3],2) -## ##returns value [1 2; 1 3; 2 3] -## -## combs(['a','e','i','o','u'],2) -## ##returns value [['a', 'e']; ['a', 'i']; ['a','o']; ['a','u']; ['e', 'i']; -## ##['e','o']; ['e','u']; ['i','o']; ['i','u']; ['o', 'u'];] -## -## @end group -## @end example -## @end deftypefn -## @seealso {perms, nchoosek} - -## -## Code modified from answer by 'leapinglizard-ga' on -## Google Answers, posted on 01 Sep 2004 09:13 PDT, -## - -function L=combs(Set,K) - if ( nargin < 2 ) - print_usage() - end - - N=length(Set); - %%printf("# of combinations = %g\n",nchoosek(N,K)) - L=comb_worker(K,1,Set,[],true); - return -end - -## -## sub-function -## -function L=comb_worker(K,P,Set,combo,is_first) - persistent N - persistent Result - persistent count - - L={}; - - if isempty(N) - N=length(Set); - end - - if isempty(Result) - Result=[]; - end - - if (K == 0) - count=count+1; - Result=[Result; combo]; - %%combo; - return - else - for idx=P:N - C=Set(idx); - combo=[combo C]; - comb_worker(K-1,idx+1,Set,combo,false); - combo=combo(1:end-1); - end - - if ( is_first > 0 ) - L=Result; - - %reset - N=[]; - Result=[]; - count=[]; - - return - end - - return - end -end - -%!assert(combs([1,2,3],2),[1 2; 1 3; 2 3]) Added: trunk/octave-forge/main/combinatorics/inst/dummy =================================================================== --- trunk/octave-forge/main/combinatorics/inst/dummy (rev 0) +++ trunk/octave-forge/main/combinatorics/inst/dummy 2012-04-23 20:22:00 UTC (rev 10317) @@ -0,0 +1,2 @@ +## pkg install does not allow dummy packages (without files). This ensures +## that the package is installed without polluting the user's namespace Modified: trunk/octave-forge/main/miscellaneous/INDEX =================================================================== --- trunk/octave-forge/main/miscellaneous/INDEX 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/miscellaneous/INDEX 2012-04-23 20:22:00 UTC (rev 10317) @@ -19,6 +19,8 @@ normr nze partarray + partcnt + partint peano_curve publish read_options Modified: trunk/octave-forge/main/miscellaneous/NEWS =================================================================== --- trunk/octave-forge/main/miscellaneous/NEWS 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/miscellaneous/NEWS 2012-04-23 20:22:00 UTC (rev 10317) @@ -6,6 +6,12 @@ ** New functions: truncate.m : truncates a number to a given precision. + ** The following functions have been imported from the combinatorics + package which has been removed: + + partcnt partint + + =============================================================================== miscellaneous-1.1.0 Release Date: 2012-03-24 Release Manager: =============================================================================== Copied: trunk/octave-forge/main/miscellaneous/PKG_ADD (from rev 10314, trunk/octave-forge/main/combinatorics/PKG_ADD) =================================================================== --- trunk/octave-forge/main/miscellaneous/PKG_ADD (rev 0) +++ trunk/octave-forge/main/miscellaneous/PKG_ADD 2012-04-23 20:22:00 UTC (rev 10317) @@ -0,0 +1 @@ +autoload ("partcnt", fullfile (fileparts (mfilename ("fullpath")), "partint.oct")); Modified: trunk/octave-forge/main/miscellaneous/src/Makefile =================================================================== --- trunk/octave-forge/main/miscellaneous/src/Makefile 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/miscellaneous/src/Makefile 2012-04-23 20:22:00 UTC (rev 10317) @@ -1,7 +1,9 @@ -all: cell2cell.oct partarray.oct sample.oct text_waitbar.oct - MKOCTFILE = mkoctfile -Wall +PROGS = $(patsubst %.cc,%.oct,$(wildcard *.cc)) + +all: $(PROGS) + %.oct: %.cc $(MKOCTFILE) $< Copied: trunk/octave-forge/main/miscellaneous/src/partint.cc (from rev 10315, trunk/octave-forge/main/combinatorics/src/partint.cc) =================================================================== --- trunk/octave-forge/main/miscellaneous/src/partint.cc (rev 0) +++ trunk/octave-forge/main/miscellaneous/src/partint.cc 2012-04-23 20:22:00 UTC (rev 10317) @@ -0,0 +1,225 @@ +// Copyright (C) 2006 Torsten Finke <fi...@ig...> +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 3 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/lo-ieee.h> + +#include "partint.h" + +unsigned long * pcnt(unsigned long n) +{ + unsigned long *s = new unsigned long[n]; + unsigned long *x = new unsigned long[n*n]; + unsigned long **p = new unsigned long*[n]; + for (unsigned long k=0; k<n; ++k) { + p[k] = x + (k*n); + s[k] = 0; + } + for (unsigned long k=0; k<n*n; ++k) x[k] = 0; + p[0][0] = 1; + for (unsigned long k=1; k<n; ++k) + { + // p[N][j] == numpart of N with max summand j + for (unsigned long j=1; j<=k; ++j) { + p[k][j] = p[k-1][j-1] + p[k-j][j]; + } + for (unsigned long j=1; j<=k; ++j) { + s[k] += p[k][j]; // S(k) = numpart(n) + } + } + return s; +} + +DEFUN_DLD (partcnt, args, , +"-*- texinfo -*-\n\ +@deftypefn{Loadable Function} {@var{p} =} partcnt(@var{n})\n\ +\n\ +@cindex partition count\n\ +\n\ +Calculate integer partition count. Argument @var{n} be scalar, vector\n\ +or matrix of non-negative numbers. A partition is the sum decomposition \n\ +of integers. \n\ +\n\ +Example:\n\ +@example \n\ +partcnt([1, 5; 17 -3])\n\ +@end example\n\ +@noindent\n\ +returns\n\ +@example\n\ +ans =\n\ + 1 7\n\ + 297 NaN\n\ +@end example\n\ +\n\ +Reference:\n\ +Joerg Arndt: Algorithms for programmers (http://www.jjj.de), 2006.\n\n\ +@end deftypefn\n\ +@seealso{partint}\n\ +") +{ + octave_value r; + + int nargin = args.length (); + if (nargin != 1) { + error("partcnt accepts exactly one argument"); + return r; + } + if ( ! args(0).is_numeric_type()) { + error("partcnt only accepts a numeric argument"); + return r; + } + + NDArray f(args(0).matrix_value()); + RowVector m(f.max()); + double mmax = m.max(); + if ( mmax < 1 ) { + error("partcnt is only defined for non-negative arguments"); + return r; + } + + unsigned long n = (unsigned long) mmax + 1; + unsigned long *s = pcnt(n); + unsigned long fr = (unsigned long) f.rows(); + unsigned long fc = (unsigned long) f.columns(); + for (unsigned long i=0; i<fr; i++) { + for (unsigned long k=0; k<fc; k++) { + unsigned long idx = (unsigned long) f(i, k); + if (0 < idx && idx < n) { + f(i, k) = s[idx]; + } else { + f(i, k) = lo_ieee_nan_value(); + } + } + } + r = f; + return r; +} + +/* + +%!assert(partcnt(1), 1); +%!assert(partcnt(17), 297); +%!fail("partcnt()", "partcnt"); +%!fail("partcnt(1,2)", "partcnt"); +%!fail("partcnt('xyz')", "partcnt"); +%!demo +%! p = partcnt([1, 5; 17 -5]) + +*/ + +DEFUN_DLD (partint, args, , +"-*- texinfo -*-\n\ +@deftypefn{Loadable Function} {@var{p} =} partint(@var{n})\n\ +\n\ +@cindex partition\n\ +\n\ +Calculate all integer partitions. Argument @var{n} be \n\ +a positive number. A partition is the sum decomposition \n\ +of integers. \n\ +\n\ +Example:\n\ +@example \n\ +partint(4)\n\ +@end example\n\ +@noindent\n\ +returns\n\ +@example\n\ +ans =\n\ + 4 0 0 0\n\ + 2 1 0 0\n\ + 0 2 0 0\n\ + 1 0 1 0\n\ + 0 0 0 1\n\ +@end example\n\ +\n\ +This means\n\n\ +@iftex\n\ +@tex\n\ +$$\eqalign{4 & = 4 \\cdot 1 \\cr\n\ + & = 2 \\cdot 1 + 1 \\cdot 2 \\cr\n\ + & = 2 \\cdot 2 \\cr\n\ + & = 1 \\cdot 1 + 1 \\cdot 3 \\cr\n\ + & = 1 \\cdot 1 \\cr\n\ +\\cr}$$\n\ +@end tex\n\ +@end iftex\n\ +@ifinfo\n\ +@example\n\ +4 = 4 * 1\n\ + = 2 * 1 + 1 * 2\n\ + = 2 * 2\n\ + = 1 * 1 + 1 * 3\n\ + = 1 * 4\n\ +@end example\n\ +@end ifinfo\n\ +\n\ +Note:\n\ +\n\ +partint(n) * [1:n]' == n\n\ +\n\ +Reference:\n\ +Joerg Arndt: Algorithms for programmers (http://www.jjj.de), 2006.\n\n\ +@end deftypefn\n\ +@seealso{partcnt}\n\ +") +{ + octave_value r; + + int nargin = args.length (); + if (nargin != 1 || + ! args(0).is_scalar_type() || + ! args(0).is_numeric_type() + ) { + error("partint only accepts one scalar positive integer argument"); + return r; + } + double arg0 = args(0).double_value(); + if ( arg0 < 1 ) { + error("partint is only defined for positive integer arguments"); + return r; + } + + unsigned long n = (unsigned long) arg0; + unsigned long *s = pcnt(n+1); + unsigned long k = s[n]; + Matrix pa(k, n, 0); + int_partition p(n); + unsigned long i = 0; + do { + const unsigned long *d = p.data(); + for (unsigned long j=0; j<n; j++) { + pa(i, j) = (unsigned long)d[j+1]; + } + i ++; + } while (p.next()); + r = pa; + return r; +} + +/* + +%!assert(partint(1), 1); +%!assert(all(partint(n=17) * [1:n]' == n) - 1, 0); +%!test +%! expected = [4,0,0,0; 2,1,0,0; 0,2,0,0; 1,0,1,0; 0,0,0,1]; +%! assert(partint(4), expected); +%!fail("partint()", "partint"); +%!fail("partint(1,2)", "partint"); +%!fail("partint('xyz')", "partint"); +%!demo +%! p = partint(4) + +*/ Copied: trunk/octave-forge/main/miscellaneous/src/partint.h (from rev 10315, trunk/octave-forge/main/combinatorics/src/partint.h) =================================================================== --- trunk/octave-forge/main/miscellaneous/src/partint.h (rev 0) +++ trunk/octave-forge/main/miscellaneous/src/partint.h 2012-04-23 20:22:00 UTC (rev 10317) @@ -0,0 +1,78 @@ +// Copyright (C) 2006 Torsten Finke <fi...@ig...> +// +// This program is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 3 of the License, or (at your option) any later +// version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, see <http://www.gnu.org/licenses/>. + +class int_partition +// Integer partitions +// Reference: +// Joerg Arndt: Algorithms for programmers +// (http://www.jjj.de), 2006. +{ +private: + unsigned long *c_; // partition: c[1]* 1 + c[2]* 2 + ... + c[n]* n == n + unsigned long *s_; // cumulative sums: s[j+1] = c[1]* 1 + c[2]* 2 + ... + c[j]* j + unsigned long n_; // partitions of n + +public: + int_partition(unsigned long n) + { + n_ = n; + c_ = new unsigned long[n+1]; + s_ = new unsigned long[n+1]; + s_[0] = 0; // unused + c_[0] = 0; // unused + first(); + } + + ~int_partition() + { + delete [] c_; + delete [] s_; + } + + void first() + { + c_[1] = n_; + for (unsigned long i=2; i<=n_; i++) { c_[i] = 0; } + s_[1] = 0; + for (unsigned long i=2; i<=n_; i++) { s_[i] = n_; } + } + + const unsigned long *data() const { return c_; } // one-based! + + bool next() + { + // This algorithm was given by Torsten Finke + if ( c_[n_]!=0 ) return false; // last == 1* n (c[n]==1) + + // Find first coefficient c[i], i>=2 that can be increased: + unsigned long i = 2; + while ( s_[i]<i ) ++i; + + ++c_[i]; + s_[i] -= i; + unsigned long z = s_[i]; + // Now set c[1], c[2], ..., c[i-1] to the first partition + // of z into i-1 parts, i.e. set to z, 0, 0, ..., 0: + while ( --i > 1 ) + { + s_[i] = z; + c_[i] = 0; + } + c_[1] = z; // z* 1 == z + // s_[1] unused + + return true; + } +}; Modified: trunk/octave-forge/main/specfun/NEWS =================================================================== --- trunk/octave-forge/main/specfun/NEWS 2012-04-23 19:55:13 UTC (rev 10316) +++ trunk/octave-forge/main/specfun/NEWS 2012-04-23 20:22:00 UTC (rev 10317) @@ -5,6 +5,13 @@ big_factorial lfactorial + ** The function `combs' (just imported from the combinatorics package) + has been deprecated in favour of `nchoosek' from Octave-core which + should perform faster. The only difference is that it does accept + string arrays (which does not make a lot of sense in the first place). + To workaround this, the following can be used: + + char (nchoosek (double (n_string), k)) Summary of important user-visible changes for specfun 1.1.0: ------------------------------------------------------------------- Copied: trunk/octave-forge/main/specfun/inst/combs.m (from rev 10315, trunk/octave-forge/main/combinatorics/inst/combs.m) =================================================================== --- trunk/octave-forge/main/specfun/inst/combs.m (rev 0) +++ trunk/octave-forge/main/specfun/inst/combs.m 2012-04-23 20:22:00 UTC (rev 10317) @@ -0,0 +1,105 @@ +## Copyright (C) 2007 Muthiah Annamalai <mut...@ut...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{rval}= {} combs(@var{sym_set},@var{k}) +## Function generates the nchoosek(N,K) combinations, and returns it. +## compute the combinations nchoosek(length(@var{sym_set}), @var{k}) +## nchoosek() is a much faster variant of this function. +## @example +## @group +## +## combs([1,2,3],2) +## ##returns value [1 2; 1 3; 2 3] +## +## combs(['a','e','i','o','u'],2) +## ##returns value [['a', 'e']; ['a', 'i']; ['a','o']; ['a','u']; ['e', 'i']; +## ##['e','o']; ['e','u']; ['i','o']; ['i','u']; ['o', 'u'];] +## +## @end group +## @end example +## @end deftypefn +## @seealso {perms, nchoosek} + +## +## Code modified from answer by 'leapinglizard-ga' on +## Google Answers, posted on 01 Sep 2004 09:13 PDT, +## + +function L=combs(Set,K) + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "`combs' has been deprecated in favor of `nchoosek'. This function will be removed from future versions of the `specfun' package"); + endif + + if ( nargin < 2 ) + print_usage() + end + + N=length(Set); + %%printf("# of combinations = %g\n",nchoosek(N,K)) + L=comb_worker(K,1,Set,[],true); + return +end + +## +## sub-function +## +function L=comb_worker(K,P,Set,combo,is_first) + persistent N + persistent Result + persistent count + + L={}; + + if isempty(N) + N=length(Set); + end + + if isempty(Result) + Result=[]; + end + + if (K == 0) + count=count+1; + Result=[Result; combo]; + %%combo; + return + else + for idx=P:N + C=Set(idx); + combo=[combo C]; + comb_worker(K-1,idx+1,Set,combo,false); + combo=combo(1:end-1); + end + + if ( is_first > 0 ) + L=Result; + + %reset + N=[]; + Result=[]; + count=[]; + + return + end + + return + end +end + +%!assert(combs([1,2,3],2),[1 2; 1 3; 2 3]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-25 21:44:17
|
Revision: 10328 http://octave.svn.sourceforge.net/octave/?rev=10328&view=rev Author: carandraug Date: 2012-04-25 21:44:08 +0000 (Wed, 25 Apr 2012) Log Message: ----------- physical_constant: move function into miscellaneous package Modified Paths: -------------- trunk/octave-forge/main/miscellaneous/NEWS trunk/octave-forge/main/physical-constants/DESCRIPTION Added Paths: ----------- trunk/octave-forge/main/miscellaneous/inst/physical_constant.m trunk/octave-forge/main/miscellaneous/inst/physical_constant.py trunk/octave-forge/main/physical-constants/inst/dummy Removed Paths: ------------- trunk/octave-forge/main/physical-constants/inst/physical_constant.m trunk/octave-forge/main/physical-constants/inst/physical_constant.py Modified: trunk/octave-forge/main/miscellaneous/NEWS =================================================================== --- trunk/octave-forge/main/miscellaneous/NEWS 2012-04-25 21:29:49 UTC (rev 10327) +++ trunk/octave-forge/main/miscellaneous/NEWS 2012-04-25 21:44:08 UTC (rev 10328) @@ -12,7 +12,15 @@ partcnt partint + ** The function `physical_constant' has been imported from the + physicalconstants package. + ** The values returned by `physical_constant' have been adjusted to the + latest (2010) recommended values by CODATA. + + ** The function `physical_constant' has a new API and should also + perform faster. + =============================================================================== miscellaneous-1.1.0 Release Date: 2012-03-24 Release Manager: =============================================================================== Copied: trunk/octave-forge/main/miscellaneous/inst/physical_constant.m (from rev 10326, trunk/octave-forge/main/physical-constants/inst/physical_constant.m) =================================================================== --- trunk/octave-forge/main/miscellaneous/inst/physical_constant.m (rev 0) +++ trunk/octave-forge/main/miscellaneous/inst/physical_constant.m 2012-04-25 21:44:08 UTC (rev 10328) @@ -0,0 +1,2078 @@ +## Copyright (C) 2007 Muthiah Annamalai <mut...@ut...> +## Copyright (C) 2012 Carnë Draug <car...@gm...> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{names}] =} physical_constant +## @deftypefnx {Function File} {[@var{val}, @var{uncertainty}, @var{unit}] =} physical_constant (@var{name}) +## @deftypefnx {Function File} {[@var{constants}] =} physical_constant ("all") +## Get physical constant @var{arg}. +## +## If no arguments are given, returns a cell array with all possible @var{name}s. +## Alternatively, @var{name} can be `all' in which case @var{val} is a structure +## array with 4 fields (name, value, uncertainty, units). +## +## Since the long list of values needs to be parsed on each call to this function +## it is much more efficient to store the values in a variable rather make multiple +## calls to this function with the same argument +## +## The values are the ones recommended by CODATA. This function was autogenerated +## on Wed Apr 25 22:17:07 2012 from NIST database at @uref{http://physics.nist.gov/constants} +## @end deftypefn + +## DO NOT EDIT THIS FILE +## This function file is generated automatically by physical_constant.py + +function [rval, uncert, unit] = physical_constant (arg) + + persistent unit_data; + if (isempty(unit_data)) + unit_data = get_data; + endif + + if (nargin > 1 || (nargin == 1 && !ischar (arg))) + print_usage; + elseif (nargin == 0) + rval = reshape ({unit_data(:).name}, size (unit_data)); + return + elseif (nargin == 1 && strcmpi (arg, "all")) + rval = unit_data; + return + endif + + val = reshape ({unit_data(:).name}, size (unit_data)); + map = strcmpi (val, arg); + if (any (map)) + val = unit_data(map); + rval = val.value; + uncert = val.uncertainty; + unit = val.units; + else + error ("No constant with name '%s' found", arg) + endif +endfunction + +function unit_data = get_data + unit_data(1).name = "Angstrom star"; + unit_data(1).value = 1.00001495e-10; + unit_data(1).uncertainty = 0.00000090e-10; + unit_data(1).units = "m"; + + unit_data(2).name = "Avogadro constant"; + unit_data(2).value = 6.02214129e23; + unit_data(2).uncertainty = 0.00000027e23; + unit_data(2).units = "mol^-1"; + + unit_data(3).name = "Bohr magneton"; + unit_data(3).value = 927.400968e-26; + unit_data(3).uncertainty = 0.000020e-26; + unit_data(3).units = "J T^-1"; + + unit_data(4).name = "Bohr magneton in Hz/T"; + unit_data(4).value = 13.99624555e9; + unit_data(4).uncertainty = 0.00000031e9; + unit_data(4).units = "Hz T^-1"; + + unit_data(5).name = "Bohr magneton in K/T"; + unit_data(5).value = 0.67171388; + unit_data(5).uncertainty = 0.00000061; + unit_data(5).units = "K T^-1"; + + unit_data(6).name = "Bohr magneton in eV/T"; + unit_data(6).value = 5.7883818066e-5; + unit_data(6).uncertainty = 0.0000000038e-5; + unit_data(6).units = "eV T^-1"; + + unit_data(7).name = "Bohr magneton in inverse meters per tesla"; + unit_data(7).value = 46.6864498; + unit_data(7).uncertainty = 0.0000010; + unit_data(7).units = "m^-1 T^-1"; + + unit_data(8).name = "Bohr radius"; + unit_data(8).value = 0.52917721092e-10; + unit_data(8).uncertainty = 0.00000000017e-10; + unit_data(8).units = "m"; + + unit_data(9).name = "Boltzmann constant"; + unit_data(9).value = 1.3806488e-23; + unit_data(9).uncertainty = 0.0000013e-23; + unit_data(9).units = "J K^-1"; + + unit_data(10).name = "Boltzmann constant in Hz/K"; + unit_data(10).value = 2.0836618e10; + unit_data(10).uncertainty = 0.0000019e10; + unit_data(10).units = "Hz K^-1"; + + unit_data(11).name = "Boltzmann constant in eV/K"; + unit_data(11).value = 8.6173324e-5; + unit_data(11).uncertainty = 0.0000078e-5; + unit_data(11).units = "eV K^-1"; + + unit_data(12).name = "Boltzmann constant in inverse meters per kelvin"; + unit_data(12).value = 69.503476; + unit_data(12).uncertainty = 0.000063; + unit_data(12).units = "m^-1 K^-1"; + + unit_data(13).name = "Compton wavelength"; + unit_data(13).value = 2.4263102389e-12; + unit_data(13).uncertainty = 0.0000000016e-12; + unit_data(13).units = "m"; + + unit_data(14).name = "Compton wavelength over 2 pi"; + unit_data(14).value = 386.15926800e-15; + unit_data(14).uncertainty = 0.00000025e-15; + unit_data(14).units = "m"; + + unit_data(15).name = "Cu x unit"; + unit_data(15).value = 1.00207697e-13; + unit_data(15).uncertainty = 0.00000028e-13; + unit_data(15).units = "m"; + + unit_data(16).name = "Faraday constant"; + unit_data(16).value = 96485.3365; + unit_data(16).uncertainty = 0.0021; + unit_data(16).units = "C mol^-1"; + + unit_data(17).name = "Faraday constant for conventional electric current"; + unit_data(17).value = 96485.3321; + unit_data(17).uncertainty = 0.0043; + unit_data(17).units = "C_90 mol^-1"; + + unit_data(18).name = "Fermi coupling constant"; + unit_data(18).value = 1.166364e-5; + unit_data(18).uncertainty = 0.000005e-5; + unit_data(18).units = "GeV^-2"; + + unit_data(19).name = "Hartree energy"; + unit_data(19).value = 4.35974434e-18; + unit_data(19).uncertainty = 0.00000019e-18; + unit_data(19).units = "J"; + + unit_data(20).name = "Hartree energy in eV"; + unit_data(20).value = 27.21138505; + unit_data(20).uncertainty = 0.00000060; + unit_data(20).units = "eV"; + + unit_data(21).name = "Josephson constant"; + unit_data(21).value = 483597.870e9; + unit_data(21).uncertainty = 0.011e9; + unit_data(21).units = "Hz V^-1"; + + unit_data(22).name = "Loschmidt constant (273.15 K, 100 kPa)"; + unit_data(22).value = 2.6516462e25; + unit_data(22).uncertainty = 0.0000024e25; + unit_data(22).units = "m^-3"; + + unit_data(23).name = "Loschmidt constant (273.15 K, 101.325 kPa)"; + unit_data(23).value = 2.6867805e25; + unit_data(23).uncertainty = 0.0000024e25; + unit_data(23).units = "m^-3"; + + unit_data(24).name = "Mo x unit"; + unit_data(24).value = 1.00209952e-13; + unit_data(24).uncertainty = 0.00000053e-13; + unit_data(24).units = "m"; + + unit_data(25).name = "Newtonian constant of gravitation"; + unit_data(25).value = 6.67384e-11; + unit_data(25).uncertainty = 0.00080e-11; + unit_data(25).units = "m^3 kg^-1 s^-2"; + + unit_data(26).name = "Newtonian constant of gravitation over h-bar c"; + unit_data(26).value = 6.70837e-39; + unit_data(26).uncertainty = 0.00080e-39; + unit_data(26).units = "(GeV/c^2)^-2"; + + unit_data(27).name = "Planck constant"; + unit_data(27).value = 6.62606957e-34; + unit_data(27).uncertainty = 0.00000029e-34; + unit_data(27).units = "J s"; + + unit_data(28).name = "Planck constant in eV s"; + unit_data(28).value = 4.135667516e-15; + unit_data(28).uncertainty = 0.000000091e-15; + unit_data(28).units = "eV s"; + + unit_data(29).name = "Planck constant over 2 pi"; + unit_data(29).value = 1.054571726e-34; + unit_data(29).uncertainty = 0.000000047e-34; + unit_data(29).units = "J s"; + + unit_data(30).name = "Planck constant over 2 pi in eV s"; + unit_data(30).value = 6.58211928e-16; + unit_data(30).uncertainty = 0.00000015e-16; + unit_data(30).units = "eV s"; + + unit_data(31).name = "Planck constant over 2 pi times c in MeV fm"; + unit_data(31).value = 197.3269718; + unit_data(31).uncertainty = 0.0000044; + unit_data(31).units = "MeV fm"; + + unit_data(32).name = "Planck length"; + unit_data(32).value = 1.616199e-35; + unit_data(32).uncertainty = 0.000097e-35; + unit_data(32).units = "m"; + + unit_data(33).name = "Planck mass"; + unit_data(33).value = 2.17651e-8; + unit_data(33).uncertainty = 0.00013e-8; + unit_data(33).units = "kg"; + + unit_data(34).name = "Planck mass energy equivalent in GeV"; + unit_data(34).value = 1.220932e19; + unit_data(34).uncertainty = 0.000073e19; + unit_data(34).units = "GeV"; + + unit_data(35).name = "Planck temperature"; + unit_data(35).value = 1.416833e32; + unit_data(35).uncertainty = 0.000085e32; + unit_data(35).units = "K"; + + unit_data(36).name = "Planck time"; + unit_data(36).value = 5.39106e-44; + unit_data(36).uncertainty = 0.00032e-44; + unit_data(36).units = "s"; + + unit_data(37).name = "Rydberg constant"; + unit_data(37).value = 10973731.568539; + unit_data(37).uncertainty = 0.000055; + unit_data(37).units = "m^-1"; + + unit_data(38).name = "Rydberg constant times c in Hz"; + unit_data(38).value = 3.289841960364e15; + unit_data(38).uncertainty = 0.000000000017e15; + unit_data(38).units = "Hz"; + + unit_data(39).name = "Rydberg constant times hc in J"; + unit_data(39).value = 2.179872171e-18; + unit_data(39).uncertainty = 0.000000096e-18; + unit_data(39).units = "J"; + + unit_data(40).name = "Rydberg constant times hc in eV"; + unit_data(40).value = 13.60569253; + unit_data(40).uncertainty = 0.00000030; + unit_data(40).units = "eV"; + + unit_data(41).name = "Sackur-Tetrode constant (1 K, 100 kPa)"; + unit_data(41).value = -1.1517078; + unit_data(41).uncertainty = 0.0000023; + unit_data(41).units = ""; + + unit_data(42).name = "Sackur-Tetrode constant (1 K, 101.325 kPa)"; + unit_data(42).value = -1.1648708; + unit_data(42).uncertainty = 0.0000023; + unit_data(42).units = ""; + + unit_data(43).name = "Stefan-Boltzmann constant"; + unit_data(43).value = 5.670373e-8; + unit_data(43).uncertainty = 0.000021e-8; + unit_data(43).units = "W m^-2 K^-4"; + + unit_data(44).name = "Thomson cross section"; + unit_data(44).value = 0.6652458734e-28; + unit_data(44).uncertainty = 0.0000000013e-28; + unit_data(44).units = "m^2"; + + unit_data(45).name = "Wien frequency displacement law constant"; + unit_data(45).value = 5.8789254e10; + unit_data(45).uncertainty = 0.0000053e10; + unit_data(45).units = "Hz K^-1"; + + unit_data(46).name = "Wien wavelength displacement law constant"; + unit_data(46).value = 2.8977721e-3; + unit_data(46).uncertainty = 0.0000026e-3; + unit_data(46).units = "m K"; + + unit_data(47).name = "alpha particle mass"; + unit_data(47).value = 6.64465675e-27; + unit_data(47).uncertainty = 0.00000029e-27; + unit_data(47).units = "kg"; + + unit_data(48).name = "alpha particle mass energy equivalent"; + unit_data(48).value = 5.97191967e-10; + unit_data(48).uncertainty = 0.00000026e-10; + unit_data(48).units = "J"; + + unit_data(49).name = "alpha particle mass energy equivalent in MeV"; + unit_data(49).value = 3727.379240; + unit_data(49).uncertainty = 0.000082; + unit_data(49).units = "MeV"; + + unit_data(50).name = "alpha particle mass in u"; + unit_data(50).value = 4.001506179125; + unit_data(50).uncertainty = 0.000000000062; + unit_data(50).units = "u"; + + unit_data(51).name = "alpha particle molar mass"; + unit_data(51).value = 4.001506179125e-3; + unit_data(51).uncertainty = 0.000000000062e-3; + unit_data(51).units = "kg mol^-1"; + + unit_data(52).name = "alpha particle-electron mass ratio"; + unit_data(52).value = 7294.2995361; + unit_data(52).uncertainty = 0.0000029; + unit_data(52).units = ""; + + unit_data(53).name = "alpha particle-proton mass ratio"; + unit_data(53).value = 3.97259968933; + unit_data(53).uncertainty = 0.00000000036; + unit_data(53).units = ""; + + unit_data(54).name = "atomic mass constant"; + unit_data(54).value = 1.660538921e-27; + unit_data(54).uncertainty = 0.000000073e-27; + unit_data(54).units = "kg"; + + unit_data(55).name = "atomic mass constant energy equivalent"; + unit_data(55).value = 1.492417954e-10; + unit_data(55).uncertainty = 0.000000066e-10; + unit_data(55).units = "J"; + + unit_data(56).name = "atomic mass constant energy equivalent in MeV"; + unit_data(56).value = 931.494061; + unit_data(56).uncertainty = 0.000021; + unit_data(56).units = "MeV"; + + unit_data(57).name = "atomic mass unit-electron volt relationship"; + unit_data(57).value = 931.494061e6; + unit_data(57).uncertainty = 0.000021e6; + unit_data(57).units = "eV"; + + unit_data(58).name = "atomic mass unit-hartree relationship"; + unit_data(58).value = 3.4231776845e7; + unit_data(58).uncertainty = 0.0000000024e7; + unit_data(58).units = "E_h"; + + unit_data(59).name = "atomic mass unit-hertz relationship"; + unit_data(59).value = 2.2523427168e23; + unit_data(59).uncertainty = 0.0000000016e23; + unit_data(59).units = "Hz"; + + unit_data(60).name = "atomic mass unit-inverse meter relationship"; + unit_data(60).value = 7.5130066042e14; + unit_data(60).uncertainty = 0.0000000053e14; + unit_data(60).units = "m^-1"; + + unit_data(61).name = "atomic mass unit-joule relationship"; + unit_data(61).value = 1.492417954e-10; + unit_data(61).uncertainty = 0.000000066e-10; + unit_data(61).units = "J"; + + unit_data(62).name = "atomic mass unit-kelvin relationship"; + unit_data(62).value = 1.08095408e13; + unit_data(62).uncertainty = 0.00000098e13; + unit_data(62).units = "K"; + + unit_data(63).name = "atomic mass unit-kilogram relationship"; + unit_data(63).value = 1.660538921e-27; + unit_data(63).uncertainty = 0.000000073e-27; + unit_data(63).units = "kg"; + + unit_data(64).name = "atomic unit of 1st hyperpolarizability"; + unit_data(64).value = 3.206361449e-53; + unit_data(64).uncertainty = 0.000000071e-53; + unit_data(64).units = "C^3 m^3 J^-2"; + + unit_data(65).name = "atomic unit of 2nd hyperpolarizability"; + unit_data(65).value = 6.23538054e-65; + unit_data(65).uncertainty = 0.00000028e-65; + unit_data(65).units = "C^4 m^4 J^-3"; + + unit_data(66).name = "atomic unit of action"; + unit_data(66).value = 1.054571726e-34; + unit_data(66).uncertainty = 0.000000047e-34; + unit_data(66).units = "J s"; + + unit_data(67).name = "atomic unit of charge"; + unit_data(67).value = 1.602176565e-19; + unit_data(67).uncertainty = 0.000000035e-19; + unit_data(67).units = "C"; + + unit_data(68).name = "atomic unit of charge density"; + unit_data(68).value = 1.081202338e12; + unit_data(68).uncertainty = 0.000000024e12; + unit_data(68).units = "C m^-3"; + + unit_data(69).name = "atomic unit of current"; + unit_data(69).value = 6.62361795e-3; + unit_data(69).uncertainty = 0.00000015e-3; + unit_data(69).units = "A"; + + unit_data(70).name = "atomic unit of electric dipole mom."; + unit_data(70).value = 8.47835326e-30; + unit_data(70).uncertainty = 0.00000019e-30; + unit_data(70).units = "C m"; + + unit_data(71).name = "atomic unit of electric field"; + unit_data(71).value = 5.14220652e11; + unit_data(71).uncertainty = 0.00000011e11; + unit_data(71).units = "V m^-1"; + + unit_data(72).name = "atomic unit of electric field gradient"; + unit_data(72).value = 9.71736200e21; + unit_data(72).uncertainty = 0.00000021e21; + unit_data(72).units = "V m^-2"; + + unit_data(73).name = "atomic unit of electric polarizability"; + unit_data(73).value = 1.6487772754e-41; + unit_data(73).uncertainty = 0.0000000016e-41; + unit_data(73).units = "C^2 m^2 J^-1"; + + unit_data(74).name = "atomic unit of electric potential"; + unit_data(74).value = 27.21138505; + unit_data(74).uncertainty = 0.00000060; + unit_data(74).units = "V"; + + unit_data(75).name = "atomic unit of electric quadrupole mom."; + unit_data(75).value = 4.486551331e-40; + unit_data(75).uncertainty = 0.000000099e-40; + unit_data(75).units = "C m^2"; + + unit_data(76).name = "atomic unit of energy"; + unit_data(76).value = 4.35974434e-18; + unit_data(76).uncertainty = 0.00000019e-18; + unit_data(76).units = "J"; + + unit_data(77).name = "atomic unit of force"; + unit_data(77).value = 8.23872278e-8; + unit_data(77).uncertainty = 0.00000036e-8; + unit_data(77).units = "N"; + + unit_data(78).name = "atomic unit of length"; + unit_data(78).value = 0.52917721092e-10; + unit_data(78).uncertainty = 0.00000000017e-10; + unit_data(78).units = "m"; + + unit_data(79).name = "atomic unit of mag. dipole mom."; + unit_data(79).value = 1.854801936e-23; + unit_data(79).uncertainty = 0.000000041e-23; + unit_data(79).units = "J T^-1"; + + unit_data(80).name = "atomic unit of mag. flux density"; + unit_data(80).value = 2.350517464e5; + unit_data(80).uncertainty = 0.000000052e5; + unit_data(80).units = "T"; + + unit_data(81).name = "atomic unit of magnetizability"; + unit_data(81).value = 7.891036607e-29; + unit_data(81).uncertainty = 0.000000013e-29; + unit_data(81).units = "J T^-2"; + + unit_data(82).name = "atomic unit of mass"; + unit_data(82).value = 9.10938291e-31; + unit_data(82).uncertainty = 0.00000040e-31; + unit_data(82).units = "kg"; + + unit_data(83).name = "atomic unit of mom.um"; + unit_data(83).value = 1.992851740e-24; + unit_data(83).uncertainty = 0.000000088e-24; + unit_data(83).units = "kg m s^-1"; + + unit_data(84).name = "atomic unit of permittivity"; + unit_data(84).value = 1.112650056e-10; + unit_data(84).uncertainty = 0.0; + unit_data(84).units = "F m^-1"; + + unit_data(85).name = "atomic unit of time"; + unit_data(85).value = 2.418884326502e-17; + unit_data(85).uncertainty = 0.000000000012e-17; + unit_data(85).units = "s"; + + unit_data(86).name = "atomic unit of velocity"; + unit_data(86).value = 2.18769126379e6; + unit_data(86).uncertainty = 0.00000000071e6; + unit_data(86).units = "m s^-1"; + + unit_data(87).name = "characteristic impedance of vacuum"; + unit_data(87).value = 376.730313461; + unit_data(87).uncertainty = 0.0; + unit_data(87).units = "ohm"; + + unit_data(88).name = "classical electron radius"; + unit_data(88).value = 2.8179403267e-15; + unit_data(88).uncertainty = 0.0000000027e-15; + unit_data(88).units = "m"; + + unit_data(89).name = "conductance quantum"; + unit_data(89).value = 7.7480917346e-5; + unit_data(89).uncertainty = 0.0000000025e-5; + unit_data(89).units = "S"; + + unit_data(90).name = "conventional value of Josephson constant"; + unit_data(90).value = 483597.9e9; + unit_data(90).uncertainty = 0.0; + unit_data(90).units = "Hz V^-1"; + + unit_data(91).name = "conventional value of von Klitzing constant"; + unit_data(91).value = 25812.807; + unit_data(91).uncertainty = 0.0; + unit_data(91).units = "ohm"; + + unit_data(92).name = "deuteron g factor"; + unit_data(92).value = 0.8574382308; + unit_data(92).uncertainty = 0.0000000072; + unit_data(92).units = ""; + + unit_data(93).name = "deuteron mag. mom."; + unit_data(93).value = 0.433073489e-26; + unit_data(93).uncertainty = 0.000000010e-26; + unit_data(93).units = "J T^-1"; + + unit_data(94).name = "deuteron mag. mom. to Bohr magneton ratio"; + unit_data(94).value = 0.4669754556e-3; + unit_data(94).uncertainty = 0.0000000039e-3; + unit_data(94).units = ""; + + unit_data(95).name = "deuteron mag. mom. to nuclear magneton ratio"; + unit_data(95).value = 0.8574382308; + unit_data(95).uncertainty = 0.0000000072; + unit_data(95).units = ""; + + unit_data(96).name = "deuteron mass"; + unit_data(96).value = 3.34358348e-27; + unit_data(96).uncertainty = 0.00000015e-27; + unit_data(96).units = "kg"; + + unit_data(97).name = "deuteron mass energy equivalent"; + unit_data(97).value = 3.00506297e-10; + unit_data(97).uncertainty = 0.00000013e-10; + unit_data(97).units = "J"; + + unit_data(98).name = "deuteron mass energy equivalent in MeV"; + unit_data(98).value = 1875.612859; + unit_data(98).uncertainty = 0.000041; + unit_data(98).units = "MeV"; + + unit_data(99).name = "deuteron mass in u"; + unit_data(99).value = 2.013553212712; + unit_data(99).uncertainty = 0.000000000077; + unit_data(99).units = "u"; + + unit_data(100).name = "deuteron molar mass"; + unit_data(100).value = 2.013553212712e-3; + unit_data(100).uncertainty = 0.000000000077e-3; + unit_data(100).units = "kg mol^-1"; + + unit_data(101).name = "deuteron rms charge radius"; + unit_data(101).value = 2.1424e-15; + unit_data(101).uncertainty = 0.0021e-15; + unit_data(101).units = "m"; + + unit_data(102).name = "deuteron-electron mag. mom. ratio"; + unit_data(102).value = -4.664345537e-4; + unit_data(102).uncertainty = 0.000000039e-4; + unit_data(102).units = ""; + + unit_data(103).name = "deuteron-electron mass ratio"; + unit_data(103).value = 3670.4829652; + unit_data(103).uncertainty = 0.0000015; + unit_data(103).units = ""; + + unit_data(104).name = "deuteron-neutron mag. mom. ratio"; + unit_data(104).value = -0.44820652; + unit_data(104).uncertainty = 0.00000011; + unit_data(104).units = ""; + + unit_data(105).name = "deuteron-proton mag. mom. ratio"; + unit_data(105).value = 0.3070122070; + unit_data(105).uncertainty = 0.0000000024; + unit_data(105).units = ""; + + unit_data(106).name = "deuteron-proton mass ratio"; + unit_data(106).value = 1.99900750097; + unit_data(106).uncertainty = 0.00000000018; + unit_data(106).units = ""; + + unit_data(107).name = "electric constant"; + unit_data(107).value = 8.854187817e-12; + unit_data(107).uncertainty = 0.0; + unit_data(107).units = "F m^-1"; + + unit_data(108).name = "electron charge to mass quotient"; + unit_data(108).value = -1.758820088e11; + unit_data(108).uncertainty = 0.000000039e11; + unit_data(108).units = "C kg^-1"; + + unit_data(109).name = "electron g factor"; + unit_data(109).value = -2.00231930436153; + unit_data(109).uncertainty = 0.00000000000053; + unit_data(109).units = ""; + + unit_data(110).name = "electron gyromag. ratio"; + unit_data(110).value = 1.760859708e11; + unit_data(110).uncertainty = 0.000000039e11; + unit_data(110).units = "s^-1 T^-1"; + + unit_data(111).name = "electron gyromag. ratio over 2 pi"; + unit_data(111).value = 28024.95266; + unit_data(111).uncertainty = 0.00062; + unit_data(111).units = "MHz T^-1"; + + unit_data(112).name = "electron mag. mom."; + unit_data(112).value = -928.476430e-26; + unit_data(112).uncertainty = 0.000021e-26; + unit_data(112).units = "J T^-1"; + + unit_data(113).name = "electron mag. mom. anomaly"; + unit_data(113).value = 1.15965218076e-3; + unit_data(113).uncertainty = 0.00000000027e-3; + unit_data(113).units = ""; + + unit_data(114).name = "electron mag. mom. to Bohr magneton ratio"; + unit_data(114).value = -1.00115965218076; + unit_data(114).uncertainty = 0.00000000000027; + unit_data(114).units = ""; + + unit_data(115).name = "electron mag. mom. to nuclear magneton ratio"; + unit_data(115).value = -1838.28197090; + unit_data(115).uncertainty = 0.00000075; + unit_data(115).units = ""; + + unit_data(116).name = "electron mass"; + unit_data(116).value = 9.10938291e-31; + unit_data(116).uncertainty = 0.00000040e-31; + unit_data(116).units = "kg"; + + unit_data(117).name = "electron mass energy equivalent"; + unit_data(117).value = 8.18710506e-14; + unit_data(117).uncertainty = 0.00000036e-14; + unit_data(117).units = "J"; + + unit_data(118).name = "electron mass energy equivalent in MeV"; + unit_data(118).value = 0.510998928; + unit_data(118).uncertainty = 0.000000011; + unit_data(118).units = "MeV"; + + unit_data(119).name = "electron mass in u"; + unit_data(119).value = 5.4857990946e-4; + unit_data(119).uncertainty = 0.0000000022e-4; + unit_data(119).units = "u"; + + unit_data(120).name = "electron molar mass"; + unit_data(120).value = 5.4857990946e-7; + unit_data(120).uncertainty = 0.0000000022e-7; + unit_data(120).units = "kg mol^-1"; + + unit_data(121).name = "electron to alpha particle mass ratio"; + unit_data(121).value = 1.37093355578e-4; + unit_data(121).uncertainty = 0.00000000055e-4; + unit_data(121).units = ""; + + unit_data(122).name = "electron to shielded helion mag. mom. ratio"; + unit_data(122).value = 864.058257; + unit_data(122).uncertainty = 0.000010; + unit_data(122).units = ""; + + unit_data(123).name = "electron to shielded proton mag. mom. ratio"; + unit_data(123).value = -658.2275971; + unit_data(123).uncertainty = 0.0000072; + unit_data(123).units = ""; + + unit_data(124).name = "electron volt"; + unit_data(124).value = 1.602176565e-19; + unit_data(124).uncertainty = 0.000000035e-19; + unit_data(124).units = "J"; + + unit_data(125).name = "electron volt-atomic mass unit relationship"; + unit_data(125).value = 1.073544150e-9; + unit_data(125).uncertainty = 0.000000024e-9; + unit_data(125).units = "u"; + + unit_data(126).name = "electron volt-hartree relationship"; + unit_data(126).value = 3.674932379e-2; + unit_data(126).uncertainty = 0.000000081e-2; + unit_data(126).units = "E_h"; + + unit_data(127).name = "electron volt-hertz relationship"; + unit_data(127).value = 2.417989348e14; + unit_data(127).uncertainty = 0.000000053e14; + unit_data(127).units = "Hz"; + + unit_data(128).name = "electron volt-inverse meter relationship"; + unit_data(128).value = 8.06554429e5; + unit_data(128).uncertainty = 0.00000018e5; + unit_data(128).units = "m^-1"; + + unit_data(129).name = "electron volt-joule relationship"; + unit_data(129).value = 1.602176565e-19; + unit_data(129).uncertainty = 0.000000035e-19; + unit_data(129).units = "J"; + + unit_data(130).name = "electron volt-kelvin relationship"; + unit_data(130).value = 1.1604519e4; + unit_data(130).uncertainty = 0.0000011e4; + unit_data(130).units = "K"; + + unit_data(131).name = "electron volt-kilogram relationship"; + unit_data(131).value = 1.782661845e-36; + unit_data(131).uncertainty = 0.000000039e-36; + unit_data(131).units = "kg"; + + unit_data(132).name = "electron-deuteron mag. mom. ratio"; + unit_data(132).value = -2143.923498; + unit_data(132).uncertainty = 0.000018; + unit_data(132).units = ""; + + unit_data(133).name = "electron-deuteron mass ratio"; + unit_data(133).value = 2.7244371095e-4; + unit_data(133).uncertainty = 0.0000000011e-4; + unit_data(133).units = ""; + + unit_data(134).name = "electron-helion mass ratio"; + unit_data(134).value = 1.8195430761e-4; + unit_data(134).uncertainty = 0.0000000017e-4; + unit_data(134).units = ""; + + unit_data(135).name = "electron-muon mag. mom. ratio"; + unit_data(135).value = 206.7669896; + unit_data(135).uncertainty = 0.0000052; + unit_data(135).units = ""; + + unit_data(136).name = "electron-muon mass ratio"; + unit_data(136).value = 4.83633166e-3; + unit_data(136).uncertainty = 0.00000012e-3; + unit_data(136).units = ""; + + unit_data(137).name = "electron-neutron mag. mom. ratio"; + unit_data(137).value = 960.92050; + unit_data(137).uncertainty = 0.00023; + unit_data(137).units = ""; + + unit_data(138).name = "electron-neutron mass ratio"; + unit_data(138).value = 5.4386734461e-4; + unit_data(138).uncertainty = 0.0000000032e-4; + unit_data(138).units = ""; + + unit_data(139).name = "electron-proton mag. mom. ratio"; + unit_data(139).value = -658.2106848; + unit_data(139).uncertainty = 0.0000054; + unit_data(139).units = ""; + + unit_data(140).name = "electron-proton mass ratio"; + unit_data(140).value = 5.4461702178e-4; + unit_data(140).uncertainty = 0.0000000022e-4; + unit_data(140).units = ""; + + unit_data(141).name = "electron-tau mass ratio"; + unit_data(141).value = 2.87592e-4; + unit_data(141).uncertainty = 0.00026e-4; + unit_data(141).units = ""; + + unit_data(142).name = "electron-triton mass ratio"; + unit_data(142).value = 1.8192000653e-4; + unit_data(142).uncertainty = 0.0000000017e-4; + unit_data(142).units = ""; + + unit_data(143).name = "elementary charge"; + unit_data(143).value = 1.602176565e-19; + unit_data(143).uncertainty = 0.000000035e-19; + unit_data(143).units = "C"; + + unit_data(144).name = "elementary charge over h"; + unit_data(144).value = 2.417989348e14; + unit_data(144).uncertainty = 0.000000053e14; + unit_data(144).units = "A J^-1"; + + unit_data(145).name = "fine-structure constant"; + unit_data(145).value = 7.2973525698e-3; + unit_data(145).uncertainty = 0.0000000024e-3; + unit_data(145).units = ""; + + unit_data(146).name = "first radiation constant"; + unit_data(146).value = 3.74177153e-16; + unit_data(146).uncertainty = 0.00000017e-16; + unit_data(146).units = "W m^2"; + + unit_data(147).name = "first radiation constant for spectral radiance"; + unit_data(147).value = 1.191042869e-16; + unit_data(147).uncertainty = 0.000000053e-16; + unit_data(147).units = "W m^2 sr^-1"; + + unit_data(148).name = "hartree-atomic mass unit relationship"; + unit_data(148).value = 2.9212623246e-8; + unit_data(148).uncertainty = 0.0000000021e-8; + unit_data(148).units = "u"; + + unit_data(149).name = "hartree-electron volt relationship"; + unit_data(149).value = 27.21138505; + unit_data(149).uncertainty = 0.00000060; + unit_data(149).units = "eV"; + + unit_data(150).name = "hartree-hertz relationship"; + unit_data(150).value = 6.579683920729e15; + unit_data(150).uncertainty = 0.000000000033e15; + unit_data(150).units = "Hz"; + + unit_data(151).name = "hartree-inverse meter relationship"; + unit_data(151).value = 2.194746313708e7; + unit_data(151).uncertainty = 0.000000000011e7; + unit_data(151).units = "m^-1"; + + unit_data(152).name = "hartree-joule relationship"; + unit_data(152).value = 4.35974434e-18; + unit_data(152).uncertainty = 0.00000019e-18; + unit_data(152).units = "J"; + + unit_data(153).name = "hartree-kelvin relationship"; + unit_data(153).value = 3.1577504e5; + unit_data(153).uncertainty = 0.0000029e5; + unit_data(153).units = "K"; + + unit_data(154).name = "hartree-kilogram relationship"; + unit_data(154).value = 4.85086979e-35; + unit_data(154).uncertainty = 0.00000021e-35; + unit_data(154).units = "kg"; + + unit_data(155).name = "helion g factor"; + unit_data(155).value = -4.255250613; + unit_data(155).uncertainty = 0.000000050; + unit_data(155).units = ""; + + unit_data(156).name = "helion mag. mom."; + unit_data(156).value = -1.074617486e-26; + unit_data(156).uncertainty = 0.000000027e-26; + unit_data(156).units = "J T^-1"; + + unit_data(157).name = "helion mag. mom. to Bohr magneton ratio"; + unit_data(157).value = -1.158740958e-3; + unit_data(157).uncertainty = 0.000000014e-3; + unit_data(157).units = ""; + + unit_data(158).name = "helion mag. mom. to nuclear magneton ratio"; + unit_data(158).value = -2.127625306; + unit_data(158).uncertainty = 0.000000025; + unit_data(158).units = ""; + + unit_data(159).name = "helion mass"; + unit_data(159).value = 5.00641234e-27; + unit_data(159).uncertainty = 0.00000022e-27; + unit_data(159).units = "kg"; + + unit_data(160).name = "helion mass energy equivalent"; + unit_data(160).value = 4.49953902e-10; + unit_data(160).uncertainty = 0.00000020e-10; + unit_data(160).units = "J"; + + unit_data(161).name = "helion mass energy equivalent in MeV"; + unit_data(161).value = 2808.391482; + unit_data(161).uncertainty = 0.000062; + unit_data(161).units = "MeV"; + + unit_data(162).name = "helion mass in u"; + unit_data(162).value = 3.0149322468; + unit_data(162).uncertainty = 0.0000000025; + unit_data(162).units = "u"; + + unit_data(163).name = "helion molar mass"; + unit_data(163).value = 3.0149322468e-3; + unit_data(163).uncertainty = 0.0000000025e-3; + unit_data(163).units = "kg mol^-1"; + + unit_data(164).name = "helion-electron mass ratio"; + unit_data(164).value = 5495.8852754; + unit_data(164).uncertainty = 0.0000050; + unit_data(164).units = ""; + + unit_data(165).name = "helion-proton mass ratio"; + unit_data(165).value = 2.9931526707; + unit_data(165).uncertainty = 0.0000000025; + unit_data(165).units = ""; + + unit_data(166).name = "hertz-atomic mass unit relationship"; + unit_data(166).value = 4.4398216689e-24; + unit_data(166).uncertainty = 0.0000000031e-24; + unit_data(166).units = "u"; + + unit_data(167).name = "hertz-electron volt relationship"; + unit_data(167).value = 4.135667516e-15; + unit_data(167).uncertainty = 0.000000091e-15; + unit_data(167).units = "eV"; + + unit_data(168).name = "hertz-hartree relationship"; + unit_data(168).value = 1.5198298460045e-16; + unit_data(168).uncertainty = 0.0000000000076e-16; + unit_data(168).units = "E_h"; + + unit_data(169).name = "hertz-inverse meter relationship"; + unit_data(169).value = 3.335640951e-9; + unit_data(169).uncertainty = 0.0; + unit_data(169).units = "m^-1"; + + unit_data(170).name = "hertz-joule relationship"; + unit_data(170).value = 6.62606957e-34; + unit_data(170).uncertainty = 0.00000029e-34; + unit_data(170).units = "J"; + + unit_data(171).name = "hertz-kelvin relationship"; + unit_data(171).value = 4.7992434e-11; + unit_data(171).uncertainty = 0.0000044e-11; + unit_data(171).units = "K"; + + unit_data(172).name = "hertz-kilogram relationship"; + unit_data(172).value = 7.37249668e-51; + unit_data(172).uncertainty = 0.00000033e-51; + unit_data(172).units = "kg"; + + unit_data(173).name = "inverse fine-structure constant"; + unit_data(173).value = 137.035999074; + unit_data(173).uncertainty = 0.000000044; + unit_data(173).units = ""; + + unit_data(174).name = "inverse meter-atomic mass unit relationship"; + unit_data(174).value = 1.33102505120e-15; + unit_data(174).uncertainty = 0.00000000094e-15; + unit_data(174).units = "u"; + + unit_data(175).name = "inverse meter-electron volt relationship"; + unit_data(175).value = 1.239841930e-6; + unit_data(175).uncertainty = 0.000000027e-6; + unit_data(175).units = "eV"; + + unit_data(176).name = "inverse meter-hartree relationship"; + unit_data(176).value = 4.556335252755e-8; + unit_data(176).uncertainty = 0.000000000023e-8; + unit_data(176).units = "E_h"; + + unit_data(177).name = "inverse meter-hertz relationship"; + unit_data(177).value = 299792458; + unit_data(177).uncertainty = 0.0; + unit_data(177).units = "Hz"; + + unit_data(178).name = "inverse meter-joule relationship"; + unit_data(178).value = 1.986445684e-25; + unit_data(178).uncertainty = 0.000000088e-25; + unit_data(178).units = "J"; + + unit_data(179).name = "inverse meter-kelvin relationship"; + unit_data(179).value = 1.4387770e-2; + unit_data(179).uncertainty = 0.0000013e-2; + unit_data(179).units = "K"; + + unit_data(180).name = "inverse meter-kilogram relationship"; + unit_data(180).value = 2.210218902e-42; + unit_data(180).uncertainty = 0.000000098e-42; + unit_data(180).units = "kg"; + + unit_data(181).name = "inverse of conductance quantum"; + unit_data(181).value = 12906.4037217; + unit_data(181).uncertainty = 0.0000042; + unit_data(181).units = "ohm"; + + unit_data(182).name = "joule-atomic mass unit relationship"; + unit_data(182).value = 6.70053585e9; + unit_data(182).uncertainty = 0.00000030e9; + unit_data(182).units = "u"; + + unit_data(183).name = "joule-electron volt relationship"; + unit_data(183).value = 6.24150934e18; + unit_data(183).uncertainty = 0.00000014e18; + unit_data(183).units = "eV"; + + unit_data(184).name = "joule-hartree relationship"; + unit_data(184).value = 2.29371248e17; + unit_data(184).uncertainty = 0.00000010e17; + unit_data(184).units = "E_h"; + + unit_data(185).name = "joule-hertz relationship"; + unit_data(185).value = 1.509190311e33; + unit_data(185).uncertainty = 0.000000067e33; + unit_data(185).units = "Hz"; + + unit_data(186).name = "joule-inverse meter relationship"; + unit_data(186).value = 5.03411701e24; + unit_data(186).uncertainty = 0.00000022e24; + unit_data(186).units = "m^-1"; + + unit_data(187).name = "joule-kelvin relationship"; + unit_data(187).value = 7.2429716e22; + unit_data(187).uncertainty = 0.0000066e22; + unit_data(187).units = "K"; + + unit_data(188).name = "joule-kilogram relationship"; + unit_data(188).value = 1.112650056e-17; + unit_data(188).uncertainty = 0.0; + unit_data(188).units = "kg"; + + unit_data(189).name = "kelvin-atomic mass unit relationship"; + unit_data(189).value = 9.2510868e-14; + unit_data(189).uncertainty = 0.0000084e-14; + unit_data(189).units = "u"; + + unit_data(190).name = "kelvin-electron volt relationship"; + unit_data(190).value = 8.6173324e-5; + unit_data(190).uncertainty = 0.0000078e-5; + unit_data(190).units = "eV"; + + unit_data(191).name = "kelvin-hartree relationship"; + unit_data(191).value = 3.1668114e-6; + unit_data(191).uncertainty = 0.0000029e-6; + unit_data(191).units = "E_h"; + + unit_data(192).name = "kelvin-hertz relationship"; + unit_data(192).value = 2.0836618e10; + unit_data(192).uncertainty = 0.0000019e10; + unit_data(192).units = "Hz"; + + unit_data(193).name = "kelvin-inverse meter relationship"; + unit_data(193).value = 69.503476; + unit_data(193).uncertainty = 0.000063; + unit_data(193).units = "m^-1"; + + unit_data(194).name = "kelvin-joule relationship"; + unit_data(194).value = 1.3806488e-23; + unit_data(194).uncertainty = 0.0000013e-23; + unit_data(194).units = "J"; + + unit_data(195).name = "kelvin-kilogram relationship"; + unit_data(195).value = 1.5361790e-40; + unit_data(195).uncertainty = 0.0000014e-40; + unit_data(195).units = "kg"; + + unit_data(196).name = "kilogram-atomic mass unit relationship"; + unit_data(196).value = 6.02214129e26; + unit_data(196).uncertainty = 0.00000027e26; + unit_data(196).units = "u"; + + unit_data(197).name = "kilogram-electron volt relationship"; + unit_data(197).value = 5.60958885e35; + unit_data(197).uncertainty = 0.00000012e35; + unit_data(197).units = "eV"; + + unit_data(198).name = "kilogram-hartree relationship"; + unit_data(198).value = 2.061485968e34; + unit_data(198).uncertainty = 0.000000091e34; + unit_data(198).units = "E_h"; + + unit_data(199).name = "kilogram-hertz relationship"; + unit_data(199).value = 1.356392608e50; + unit_data(199).uncertainty = 0.000000060e50; + unit_data(199).units = "Hz"; + + unit_data(200).name = "kilogram-inverse meter relationship"; + unit_data(200).value = 4.52443873e41; + unit_data(200).uncertainty = 0.00000020e41; + unit_data(200).units = "m^-1"; + + unit_data(201).name = "kilogram-joule relationship"; + unit_data(201).value = 8.987551787e16; + unit_data(201).uncertainty = 0.0; + unit_data(201).units = "J"; + + unit_data(202).name = "kilogram-kelvin relationship"; + unit_data(202).value = 6.5096582e39; + unit_data(202).uncertainty = 0.0000059e39; + unit_data(202).units = "K"; + + unit_data(203).name = "lattice parameter of silicon"; + unit_data(203).value = 543.1020504e-12; + unit_data(203).uncertainty = 0.0000089e-12; + unit_data(203).units = "m"; + + unit_data(204).name = "mag. constant"; + unit_data(204).value = 12.566370614e-7; + unit_data(204).uncertainty = 0.0; + unit_data(204).units = "N A^-2"; + + unit_data(205).name = "mag. flux quantum"; + unit_data(205).value = 2.067833758e-15; + unit_data(205).uncertainty = 0.000000046e-15; + unit_data(205).units = "Wb"; + + unit_data(206).name = "molar Planck constant"; + unit_data(206).value = 3.9903127176e-10; + unit_data(206).uncertainty = 0.0000000028e-10; + unit_data(206).units = "J s mol^-1"; + + unit_data(207).name = "molar Planck constant times c"; + unit_data(207).value = 0.119626565779; + unit_data(207).uncertainty = 0.000000000084; + unit_data(207).units = "J m mol^-1"; + + unit_data(208).name = "molar gas constant"; + unit_data(208).value = 8.3144621; + unit_data(208).uncertainty = 0.0000075; + unit_data(208).units = "J mol^-1 K^-1"; + + unit_data(209).name = "molar mass constant"; + unit_data(209).value = 1e-3; + unit_data(209).uncertainty = 0.0; + unit_data(209).units = "kg mol^-1"; + + unit_data(210).name = "molar mass of carbon-12"; + unit_data(210).value = 12e-3; + unit_data(210).uncertainty = 0.0; + unit_data(210).units = "kg mol^-1"; + + unit_data(211).name = "molar volume of ideal gas (273.15 K, 100 kPa)"; + unit_data(211).value = 22.710953e-3; + unit_data(211).uncertainty = 0.000021e-3; + unit_data(211).units = "m^3 mol^-1"; + + unit_data(212).name = "molar volume of ideal gas (273.15 K, 101.325 kPa)"; + unit_data(212).value = 22.413968e-3; + unit_data(212).uncertainty = 0.000020e-3; + unit_data(212).units = "m^3 mol^-1"; + + unit_data(213).name = "molar volume of silicon"; + unit_data(213).value = 12.05883301e-6; + unit_data(213).uncertainty = 0.00000080e-6; + unit_data(213).units = "m^3 mol^-1"; + + unit_data(214).name = "muon Compton wavelength"; + unit_data(214).value = 11.73444103e-15; + unit_data(214).uncertainty = 0.00000030e-15; + unit_data(214).units = "m"; + + unit_data(215).name = "muon Compton wavelength over 2 pi"; + unit_data(215).value = 1.867594294e-15; + unit_data(215).uncertainty = 0.000000047e-15; + unit_data(215).units = "m"; + + unit_data(216).name = "muon g factor"; + unit_data(216).value = -2.0023318418; + unit_data(216).uncertainty = 0.0000000013; + unit_data(216).units = ""; + + unit_data(217).name = "muon mag. mom."; + unit_data(217).value = -4.49044807e-26; + unit_data(217).uncertainty = 0.00000015e-26; + unit_data(217).units = "J T^-1"; + + unit_data(218).name = "muon mag. mom. anomaly"; + unit_data(218).value = 1.16592091e-3; + unit_data(218).uncertainty = 0.00000063e-3; + unit_data(218).units = ""; + + unit_data(219).name = "muon mag. mom. to Bohr magneton ratio"; + unit_data(219).value = -4.84197044e-3; + unit_data(219).uncertainty = 0.00000012e-3; + unit_data(219).units = ""; + + unit_data(220).name = "muon mag. mom. to nuclear magneton ratio"; + unit_data(220).value = -8.89059697; + unit_data(220).uncertainty = 0.00000022; + unit_data(220).units = ""; + + unit_data(221).name = "muon mass"; + unit_data(221).value = 1.883531475e-28; + unit_data(221).uncertainty = 0.000000096e-28; + unit_data(221).units = "kg"; + + unit_data(222).name = "muon mass energy equivalent"; + unit_data(222).value = 1.692833667e-11; + unit_data(222).uncertainty = 0.000000086e-11; + unit_data(222).units = "J"; + + unit_data(223).name = "muon mass energy equivalent in MeV"; + unit_data(223).value = 105.6583715; + unit_data(223).uncertainty = 0.0000035; + unit_data(223).units = "MeV"; + + unit_data(224).name = "muon mass in u"; + unit_data(224).value = 0.1134289267; + unit_data(224).uncertainty = 0.0000000029; + unit_data(224).units = "u"; + + unit_data(225).name = "muon molar mass"; + unit_data(225).value = 0.1134289267e-3; + unit_data(225).uncertainty = 0.0000000029e-3; + unit_data(225).units = "kg mol^-1"; + + unit_data(226).name = "muon-electron mass ratio"; + unit_data(226).value = 206.7682843; + unit_data(226).uncertainty = 0.0000052; + unit_data(226).units = ""; + + unit_data(227).name = "muon-neutron mass ratio"; + unit_data(227).value = 0.1124545177; + unit_data(227).uncertainty = 0.0000000028; + unit_data(227).units = ""; + + unit_data(228).name = "muon-proton mag. mom. ratio"; + unit_data(228).value = -3.183345107; + unit_data(228).uncertainty = 0.000000084; + unit_data(228).units = ""; + + unit_data(229).name = "muon-proton mass ratio"; + unit_data(229).value = 0.1126095272; + unit_data(229).uncertainty = 0.0000000028; + unit_data(229).units = ""; + + unit_data(230).name = "muon-tau mass ratio"; + unit_data(230).value = 5.94649e-2; + unit_data(230).uncertainty = 0.00054e-2; + unit_data(230).units = ""; + + unit_data(231).name = "natural unit of action"; + unit_data(231).value = 1.054571726e-34; + unit_data(231).uncertainty = 0.000000047e-34; + unit_data(231).units = "J s"; + + unit_data(232).name = "natural unit of action in eV s"; + unit_data(232).value = 6.58211928e-16; + unit_data(232).uncertainty = 0.00000015e-16; + unit_data(232).units = "eV s"; + + unit_data(233).name = "natural unit of energy"; + unit_data(233).value = 8.18710506e-14; + unit_data(233).uncertainty = 0.00000036e-14; + unit_data(233).units = "J"; + + unit_data(234).name = "natural unit of energy in MeV"; + unit_data(234).value = 0.510998928; + unit_data(234).uncertainty = 0.000000011; + unit_data(234).units = "MeV"; + + unit_data(235).name = "natural unit of length"; + unit_data(235).value = 386.15926800e-15; + unit_data(235).uncertainty = 0.00000025e-15; + unit_data(235).units = "m"; + + unit_data(236).name = "natural unit of mass"; + unit_data(236).value = 9.10938291e-31; + unit_data(236).uncertainty = 0.00000040e-31; + unit_data(236).units = "kg"; + + unit_data(237).name = "natural unit of mom.um"; + unit_data(237).value = 2.73092429e-22; + unit_data(237).uncertainty = 0.00000012e-22; + unit_data(237).units = "kg m s^-1"; + + unit_data(238).name = "natural unit of mom.um in MeV/c"; + unit_data(238).value = 0.510998928; + unit_data(238).uncertainty = 0.000000011; + unit_data(238).units = "MeV/c"; + + unit_data(239).name = "natural unit of time"; + unit_data(239).value = 1.28808866833e-21; + unit_data(239).uncertainty = 0.00000000083e-21; + unit_data(239).units = "s"; + + unit_data(240).name = "natural unit of velocity"; + unit_data(240).value = 299792458; + unit_data(240).uncertainty = 0.0; + unit_data(240).units = "m s^-1"; + + unit_data(241).name = "neutron Compton wavelength"; + unit_data(241).value = 1.3195909068e-15; + unit_data(241).uncertainty = 0.0000000011e-15; + unit_data(241).units = "m"; + + unit_data(242).name = "neutron Compton wavelength over 2 pi"; + unit_data(242).value = 0.21001941568e-15; + unit_data(242).uncertainty = 0.00000000017e-15; + unit_data(242).units = "m"; + + unit_data(243).name = "neutron g factor"; + unit_data(243).value = -3.82608545; + unit_data(243).uncertainty = 0.00000090; + unit_data(243).units = ""; + + unit_data(244).name = "neutron gyromag. ratio"; + unit_data(244).value = 1.83247179e8; + unit_data(244).uncertainty = 0.00000043e8; + unit_data(244).units = "s^-1 T^-1"; + + unit_data(245).name = "neutron gyromag. ratio over 2 pi"; + unit_data(245).value = 29.1646943; + unit_data(245).uncertainty = 0.0000069; + unit_data(245).units = "MHz T^-1"; + + unit_data(246).name = "neutron mag. mom."; + unit_data(246).value = -0.96623647e-26; + unit_data(246).uncertainty = 0.00000023e-26; + unit_data(246).units = "J T^-1"; + + unit_data(247).name = "neutron mag. mom. to Bohr magneton ratio"; + unit_data(247).value = -1.04187563e-3; + unit_data(247).uncertainty = 0.00000025e-3; + unit_data(247).units = ""; + + unit_data(248).name = "neutron mag. mom. to nuclear magneton ratio"; + unit_data(248).value = -1.91304272; + unit_data(248).uncertainty = 0.00000045; + unit_data(248).units = ""; + + unit_data(249).name = "neutron mass"; + unit_data(249).value = 1.674927351e-27; + unit_data(249).uncertainty = 0.000000074e-27; + unit_data(249).units = "kg"; + + unit_data(250).name = "neutron mass energy equivalent"; + unit_data(250).value = 1.505349631e-10; + unit_data(250).uncertainty = 0.000000066e-10; + unit_data(250).units = "J"; + + unit_data(251).name = "neutron mass energy equivalent in MeV"; + unit_data(251).value = 939.565379; + unit_data(251).uncertainty = 0.000021; + unit_data(251).units = "MeV"; + + unit_data(252).name = "neutron mass in u"; + unit_data(252).value = 1.00866491600; + unit_data(252).uncertainty = 0.00000000043; + unit_data(252).units = "u"; + + unit_data(253).name = "neutron molar mass"; + unit_data(253).value = 1.00866491600e-3; + unit_data(253).uncertainty = 0.00000000043e-3; + unit_data(253).units = "kg mol^-1"; + + unit_data(254).name = "neutron to shielded proton mag. mom. ratio"; + unit_data(254).value = -0.68499694; + unit_data(254).uncertainty = 0.00000016; + unit_data(254).units = ""; + + unit_data(255).name = "neutron-electron mag. mom. ratio"; + unit_data(255).value = 1.04066882e-3; + unit_data(255).uncertainty = 0.00000025e-3; + unit_data(255).units = ""; + + unit_data(256).name = "neutron-electron mass ratio"; + unit_data(256).value = 1838.6836605; + unit_data(256).uncertainty = 0.0000011; + unit_data(256).units = ""; + + unit_data(257).name = "neutron-muon mass ratio"; + unit_data(257).value = 8.89248400; + unit_data(257).uncertainty = 0.00000022; + unit_data(257).units = ""; + + unit_data(258).name = "neutron-proton mag. mom. ratio"; + unit_data(258).value = -0.68497934; + unit_data(258).uncertainty = 0.00000016; + unit_data(258).units = ""; + + unit_data(259).name = "neutron-proton mass difference"; + unit_data(259).value = 2.30557392e-30; + unit_data(259).uncertainty = 0.00000076e-30; + unit_data(259).units = ""; + + unit_data(260).name = "neutron-proton mass difference energy equivalent"; + unit_data(260).value = 2.07214650e-13; + unit_data(260).uncertainty = 0.00000068e-13; + unit_data(260).units = ""; + + unit_data(261).name = "neutron-proton mass difference energy equivalent in MeV"; + unit_data(261).value = 1.29333217; + unit_data(261).uncertainty = 0.00000042; + unit_data(261).units = ""; + + unit_data(262).name = "neutron-proton mass difference in u"; + unit_data(262).value = 0.00138844919; + unit_data(262).uncertainty = 0.00000000045; + unit_data(262).units = ""; + + unit_data(263).name = "neutron-proton mass ratio"; + unit_data(263).value = 1.00137841917; + unit_data(263).uncertainty = 0.00000000045; + unit_data(263).units = ""; + + unit_data(264).name = "neutron-tau mass ratio"; + unit_data(264).value = 0.528790; + unit_data(264).uncertainty = 0.000048; + unit_data(264).units = ""; + + unit_data(265).name = "nuclear magneton"; + unit_data(265).value = 5.05078353e-27; + unit_data(265).uncertainty = 0.00000011e-27; + unit_data(265).units = "J T^-1"; + + unit_data(266).name = "nuclear magneton in K/T"; + unit_data(266).value = 3.6582682e-4; + unit_data(266).uncertainty = 0.0000033e-4; + unit_data(266).units = "K T^-1"; + + unit_data(267).name = "nuclear magneton in MHz/T"; + unit_data(267).value = 7.62259357; + unit_data(267).uncertainty = 0.00000017; + unit_data(267).units = "MHz T^-1"; + + unit_data(268).name = "nuclear magneton in eV/T"; + unit_data(268).value = 3.1524512605e-8; + unit_data(268).uncertainty = 0.0000000022e-8; + unit_data(268).units = "eV T^-1"; + + unit_data(269).name = "nuclear magneton in inverse meters per tesla"; + unit_data(269).value = 2.542623527e-2; + unit_data(269).uncertainty = 0.000000056e-2; + unit_data(269).units = "m^-1 T^-1"; + + unit_data(270).name = "proton Compton wavelength"; + unit_data(270).value = 1.32140985623e-15; + unit_data(270).uncertainty = 0.00000000094e-15; + unit_data(270).units = "m"; + + unit_data(271).name = "proton Compton wavelength over 2 pi"; + unit_data(271).value = 0.21030891047e-15; + unit_data(271).uncertainty = 0.00000000015e-15; + unit_data(271).units = "m"; + + unit_data(272).name = "proton charge to mass quotient"; + unit_data(272).value = 9.57883358e7; + unit_data(272).uncertainty = 0.00000021e7; + unit_data(272).units = "C kg^-1"; + + unit_data(273).name = "proton g factor"; + unit_data(273).value = 5.585694713; + unit_data(273).uncertainty = 0.000000046; + unit_data(273).units = ""; + + unit_data(274).name = "proton gyromag. ratio"; + unit_data(274).value = 2.675222005e8; + unit_data(274).uncertainty = 0.000000063e8; + unit_data(274).units = "s^-1 T^-1"; + + unit_data(275).name = "proton gyromag. ratio over 2 pi"; + unit_data(275).value = 42.5774806; + unit_data(275).uncertainty = 0.0000010; + unit_data(275).units = "MHz T^-1"; + + unit_data(276).name = "proton mag. mom."; + unit_data(276).value = 1.410606743e-26; + unit_data(276).uncertainty = 0.000000033e-26; + unit_data(276).units = "J T^-1"; + + unit_data(277).name = "proton mag. mom. to Bohr magneton ratio"; + unit_data(277).value = 1.521032210e-3; + unit_data(277).uncertainty = 0.000000012e-3; + unit_data(277).units = ""; + + unit_data(278).name = "proton mag. mom. to nuclear magneton ratio"; + unit_data(278).value = 2.792847356; + unit_data(278).uncertainty = 0.000000023; + unit_data(278).units = ""; + + unit_data(279).name = "proton mag. shielding correction"; + unit_data(279).value = 25.694e-6; + unit_data(279).uncertainty = 0.014e-6; + unit_data(279).units = ""; + + unit_data(280).name = "proton mass"; + unit_data(280).value = 1.672621777e-27; + unit_data(280).uncertainty = 0.000000074e-27; + unit_data(280).units = "kg"; + + unit_data(281).name = "proton mass energy equivalent"; + unit_data(281).value = 1.503277484e-10; + unit_data(281).uncertainty = 0.000000066e-10; + unit_data(281).units = "J"; + + unit_data(282).name = "proton mass energy equivalent in MeV"; + unit_data(282).value = 938.272046; + unit_data(282).uncertainty = 0.000021; + unit_data(282).units = "MeV"; + + unit_data(283).name = "proton mass in u"; + unit_data(283).value = 1.007276466812; + unit_data(283).uncertainty = 0.000000000090; + unit_data(283).units = "u"; + + unit_data(284).name = "proton molar mass"; + unit_data(284).value = 1.007276466812e-3; + unit_data(284).uncertainty = 0.000000000090e-3; + unit_data(284).units ... [truncated message content] |
From: <jpi...@us...> - 2012-05-30 08:15:19
|
Revision: 10538 http://octave.svn.sourceforge.net/octave/?rev=10538&view=rev Author: jpicarbajal Date: 2012-05-30 08:15:08 +0000 (Wed, 30 May 2012) Log Message: ----------- linear-algebra: fixing text_waitbar use in nmf_pg Modified Paths: -------------- trunk/octave-forge/main/geometry/inst/geom2d/closed_path.m trunk/octave-forge/main/linear-algebra/inst/nmf_pg.m Modified: trunk/octave-forge/main/geometry/inst/geom2d/closed_path.m =================================================================== --- trunk/octave-forge/main/geometry/inst/geom2d/closed_path.m 2012-05-30 08:00:59 UTC (rev 10537) +++ trunk/octave-forge/main/geometry/inst/geom2d/closed_path.m 2012-05-30 08:15:08 UTC (rev 10538) @@ -13,7 +13,6 @@ %% You should have received a copy of the GNU General Public License %% along with this program. If not, see <http://www.gnu.org/licenses/>. - %% -*- texinfo -*- %% @deftypefn {Function File} {@var{y} =} polygon (@var{x}) %% Returns a simple closed path that passes through all the points in @var{x}. Modified: trunk/octave-forge/main/linear-algebra/inst/nmf_pg.m =================================================================== --- trunk/octave-forge/main/linear-algebra/inst/nmf_pg.m 2012-05-30 08:00:59 UTC (rev 10537) +++ trunk/octave-forge/main/linear-algebra/inst/nmf_pg.m 2012-05-30 08:15:08 UTC (rev 10538) @@ -85,6 +85,12 @@ maxsubiter = parser.Results.MaxSubIter; verbose = parser.Results.Verbose; + # Check if text_waitbar is loaded + __txtwb__ = true; + if !exist ('text_waitbar') + __txtwb__ = false; + end + clear parser # ------ # @@ -141,7 +147,13 @@ r,c,Wr,Wc,Hr,Hc); fprintf ("Initial gradient norm = %f\n", initgrad); fflush (stdout); - text_waitbar(0,'Please wait ...'); + + if __txtwb__ + text_waitbar(0,'Please wait ...'); + else + printf ('Running main loop, this may take a while.\n'); + fflush (stdout); + end end for iter = 1:maxiter @@ -177,9 +189,10 @@ break end - if verbose + if verbose && __txtwb__ text_waitbar (iter/maxiter); - end + end + end if iter == maxiter This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2012-06-12 14:29:08
|
Revision: 10624 http://octave.svn.sourceforge.net/octave/?rev=10624&view=rev Author: i7tiol Date: 2012-06-12 14:28:58 +0000 (Tue, 12 Jun 2012) Log Message: ----------- More compatible passing of linker flags to mkoctfile. Modified Paths: -------------- trunk/octave-forge/main/linear-algebra/src/Makefile trunk/octave-forge/main/octgpr/src/Makefile.in trunk/octave-forge/main/odepkg/src/Makefile trunk/octave-forge/main/optiminterp/src/Makefile Property Changed: ---------------- trunk/octave-forge/main/miscellaneous/inst/hermitepoly.m trunk/octave-forge/main/miscellaneous/inst/hilbert_curve.m trunk/octave-forge/main/miscellaneous/inst/peano_curve.m trunk/octave-forge/main/miscellaneous/inst/z_curve.m Modified: trunk/octave-forge/main/linear-algebra/src/Makefile =================================================================== --- trunk/octave-forge/main/linear-algebra/src/Makefile 2012-06-12 14:11:58 UTC (rev 10623) +++ trunk/octave-forge/main/linear-algebra/src/Makefile 2012-06-12 14:28:58 UTC (rev 10624) @@ -4,7 +4,14 @@ MKOCTFILE = mkoctfile endif -LAPACK_LIBS := $(shell mkoctfile -p LAPACK_LIBS) +ifndef LAPACK_LIBS +LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) +endif +ifndef BLAS_LIBS +BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) +endif +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) +export LFLAGS DEFINES = -DHAVE_CONFIG_H -Wall GSVD_OBJECTS = gsvd.o dbleGSVD.o CmplxGSVD.o Modified: trunk/octave-forge/main/octgpr/src/Makefile.in =================================================================== --- trunk/octave-forge/main/octgpr/src/Makefile.in 2012-06-12 14:11:58 UTC (rev 10623) +++ trunk/octave-forge/main/octgpr/src/Makefile.in 2012-06-12 14:28:58 UTC (rev 10624) @@ -24,7 +24,8 @@ FFLAGS=@FFLAGS@ @FPICFLAG@ CC=@CC@ @CPICFLAG@ CFLAGS=@CFLAGS@ -I. -LIBS=@LIBS@ +LFLAGS=@LIBS@ +export LFLAGS OBJS_GPR_TRAIN=dsdacc.o dwdis2.o dtr2tp.o corrf.o stheta.o \ nllgpr.o nldgpr.o nl0gpr.o pakgpr.o \ @@ -55,14 +56,14 @@ $(MKOCTFILE) -c $< gpr_train.oct: gpr_train.o $(OBJS_GPR_TRAIN) - $(MKOCTFILE) -o $@ gpr_train.o $(OBJS_GPR_TRAIN) $(LIBS) + $(MKOCTFILE) -o $@ gpr_train.o $(OBJS_GPR_TRAIN) gpr_predict.oct: gpr_predict.o $(OBJS_GPR_PRED) - $(MKOCTFILE) -o $@ gpr_predict.o $(OBJS_GPR_PRED) $(LIBS) + $(MKOCTFILE) -o $@ gpr_predict.o $(OBJS_GPR_PRED) pgp_train.oct: pgp_train.o $(OBJS_GPR_TRAIN) - $(MKOCTFILE) -o $@ pgp_train.o $(OBJS_GPR_TRAIN) $(LIBS) + $(MKOCTFILE) -o $@ pgp_train.o $(OBJS_GPR_TRAIN) pgp_predict.oct: pgp_predict.o $(OBJS_GPR_PRED) - $(MKOCTFILE) -o $@ pgp_predict.o $(OBJS_GPR_PRED) $(LIBS) + $(MKOCTFILE) -o $@ pgp_predict.o $(OBJS_GPR_PRED) pdist2_mw.oct: pdist2_mw.cc $(MKOCTFILE) -o $@ $< Modified: trunk/octave-forge/main/odepkg/src/Makefile =================================================================== --- trunk/octave-forge/main/odepkg/src/Makefile 2012-06-12 14:11:58 UTC (rev 10623) +++ trunk/octave-forge/main/odepkg/src/Makefile 2012-06-12 14:28:58 UTC (rev 10624) @@ -22,8 +22,13 @@ MKF77FILE = FFLAGS="$(FFLAGS)" $(MKOCTFILE) endif +ifndef LAPACK_LIBS LAPACK_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) $(shell $(MKOCTFILE) -p LAPACK_LIBS) +endif +ifndef FLIBS FLIBS := $(shell $(MKOCTFILE) -p FLIBS) +endif +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(FLIBS) EXTERNALDIRS = hairer cash daskr EXTERNALPACKS = $(patsubst %, %.tgz, $(EXTERNALDIRS)) @@ -49,7 +54,7 @@ all : $(EXTERNALDIRS) $(SOLVEROCTFILE) $(SOLVEROCTFILE) : $(EXTERNALDIRS) $(SOLVEROBJECTS) - $(MKOCTFILE) $(SOLVEROBJECTS) -o $(SOLVEROCTFILE) \ + LFLAGS="$(LFLAGS)" $(MKOCTFILE) $(SOLVEROBJECTS) -o $(SOLVEROCTFILE) \ $(LAPACK_LIBS) $(FLIBS) install : Modified: trunk/octave-forge/main/optiminterp/src/Makefile =================================================================== --- trunk/octave-forge/main/optiminterp/src/Makefile 2012-06-12 14:11:58 UTC (rev 10623) +++ trunk/octave-forge/main/optiminterp/src/Makefile 2012-06-12 14:28:58 UTC (rev 10624) @@ -7,8 +7,16 @@ TARGETS=optiminterp.oct -LAPACK_LIBS := $(shell mkoctfile -p LAPACK_LIBS) -FLIBS := $(shell mkoctfile -p FLIBS) +ifndef LAPACK_LIBS +LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) +endif +ifndef BLAS_LIBS +BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) +endif +ifndef FLIBS +FLIBS := $(shell $(MKOCTFILE) -p FLIBS) +endif +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) # Rule for compiling Fortran 90 programs @@ -24,7 +32,8 @@ optiminterp.oct: $(OBJECTS) - $(MKOCTFILE) -o $@ $(OBJECTS) $(LIBS) $(LAPACK_LIBS) $(FLIBS) + LFLAGS="$(LFLAGS)" \ + $(MKOCTFILE) -o $@ $(OBJECTS) $(LIBS) $(LAPACK_LIBS) $(FLIBS) check: octave --silent --norc --eval test_optiminterp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2012-06-12 14:38:45
|
Revision: 10625 http://octave.svn.sourceforge.net/octave/?rev=10625&view=rev Author: i7tiol Date: 2012-06-12 14:38:35 +0000 (Tue, 12 Jun 2012) Log Message: ----------- Add missing NEWS entrys for fixing Makefiles for more compatible passing of linker flags. Modified Paths: -------------- trunk/octave-forge/main/control/NEWS trunk/octave-forge/main/linear-algebra/DESCRIPTION trunk/octave-forge/main/linear-algebra/NEWS trunk/octave-forge/main/octgpr/DESCRIPTION trunk/octave-forge/main/odepkg/DESCRIPTION Added Paths: ----------- trunk/octave-forge/main/octgpr/NEWS trunk/octave-forge/main/odepkg/NEWS trunk/octave-forge/main/optiminterp/NEWS Modified: trunk/octave-forge/main/control/NEWS =================================================================== --- trunk/octave-forge/main/control/NEWS 2012-06-12 14:28:58 UTC (rev 10624) +++ trunk/octave-forge/main/control/NEWS 2012-06-12 14:38:35 UTC (rev 10625) @@ -27,7 +27,10 @@ ** test_control Add a few remarks to the help text regarding the severity of failing tests. +** Makefile fixed to work with non-standard linker options e.g on + Apple. + =============================================================================== control-2.3.50 Release Date: 2012-03-06 Release Manager: Lukas Reichlin =============================================================================== Modified: trunk/octave-forge/main/linear-algebra/DESCRIPTION =================================================================== --- trunk/octave-forge/main/linear-algebra/DESCRIPTION 2012-06-12 14:28:58 UTC (rev 10624) +++ trunk/octave-forge/main/linear-algebra/DESCRIPTION 2012-06-12 14:38:35 UTC (rev 10625) @@ -1,6 +1,6 @@ Name: Linear-algebra Version: 2.2.0 -Date: 2012-21-05 +Date: 2012-06-12 Author: various authors Maintainer: Octave-Forge community <oct...@li...> Title: Linear algebra. Modified: trunk/octave-forge/main/linear-algebra/NEWS =================================================================== --- trunk/octave-forge/main/linear-algebra/NEWS 2012-06-12 14:28:58 UTC (rev 10624) +++ trunk/octave-forge/main/linear-algebra/NEWS 2012-06-12 14:38:35 UTC (rev 10625) @@ -5,6 +5,9 @@ nmf_pg doesn't use text_waitbar by default. Miscellanoues package is not required. + ** Makefile fixed to work with non-standard linker options e.g on + Apple. + Summary of important user-visible changes for linear-algebra 2.2.0: ------------------------------------------------------------------- Modified: trunk/octave-forge/main/octgpr/DESCRIPTION =================================================================== --- trunk/octave-forge/main/octgpr/DESCRIPTION 2012-06-12 14:28:58 UTC (rev 10624) +++ trunk/octave-forge/main/octgpr/DESCRIPTION 2012-06-12 14:38:35 UTC (rev 10625) @@ -1,6 +1,6 @@ Name: OctGPR -Version: 1.2.0 -Date: 2009-08-06 +Version: 1.2.1 +Date: 2012-06-12 Author: Jaroslav Hajek <hi...@gm...> Title: Package for full dense Gaussian Process Regression Maintainer: Jaroslav Hajek <hi...@gm...> Added: trunk/octave-forge/main/octgpr/NEWS =================================================================== --- trunk/octave-forge/main/octgpr/NEWS (rev 0) +++ trunk/octave-forge/main/octgpr/NEWS 2012-06-12 14:38:35 UTC (rev 10625) @@ -0,0 +1,5 @@ +Summary of important user-visible changes for octgpr 1.2.1: +------------------------------------------------------------------- + + ** Makefile fixed to work with non-standard linker options e.g on + Apple. Modified: trunk/octave-forge/main/odepkg/DESCRIPTION =================================================================== --- trunk/octave-forge/main/odepkg/DESCRIPTION 2012-06-12 14:28:58 UTC (rev 10624) +++ trunk/octave-forge/main/odepkg/DESCRIPTION 2012-06-12 14:38:35 UTC (rev 10625) @@ -1,6 +1,6 @@ Name: OdePkg -Version: 0.8.2 -Date: 2012-04-15 +Version: 0.8.3 +Date: 2012-06-12 Author: Thomas Treichl <tr...@us...> Maintainer: Thomas Treichl <tr...@us...> Title: OdePkg Added: trunk/octave-forge/main/odepkg/NEWS =================================================================== --- trunk/octave-forge/main/odepkg/NEWS (rev 0) +++ trunk/octave-forge/main/odepkg/NEWS 2012-06-12 14:38:35 UTC (rev 10625) @@ -0,0 +1,5 @@ +Summary of important user-visible changes for odepkg 0.8.3: +------------------------------------------------------------------- + + ** Makefile fixed to work with non-standard linker options e.g on + Apple. Added: trunk/octave-forge/main/optiminterp/NEWS =================================================================== --- trunk/octave-forge/main/optiminterp/NEWS (rev 0) +++ trunk/octave-forge/main/optiminterp/NEWS 2012-06-12 14:38:35 UTC (rev 10625) @@ -0,0 +1,5 @@ +Summary of important user-visible changes for optiminterp 0.3.4: +------------------------------------------------------------------- + + ** Makefile fixed to work with non-standard linker options e.g on + Apple. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ean...@us...> - 2012-08-07 19:48:38
|
Revision: 10840 http://octave.svn.sourceforge.net/octave/?rev=10840&view=rev Author: eandrius Date: 2012-08-07 19:48:30 +0000 (Tue, 07 Aug 2012) Log Message: ----------- serial: initial release Added Paths: ----------- trunk/octave-forge/main/serial/ trunk/octave-forge/main/serial/COPYING trunk/octave-forge/main/serial/DESCRIPTION trunk/octave-forge/main/serial/INDEX trunk/octave-forge/main/serial/NEWS trunk/octave-forge/main/serial/src/ trunk/octave-forge/main/serial/src/Makefile trunk/octave-forge/main/serial/src/serial.cc trunk/octave-forge/main/serial/src/serial.h trunk/octave-forge/main/serial/src/srl_baudrate.cc trunk/octave-forge/main/serial/src/srl_bytesize.cc trunk/octave-forge/main/serial/src/srl_close.cc trunk/octave-forge/main/serial/src/srl_flush.cc trunk/octave-forge/main/serial/src/srl_parity.cc trunk/octave-forge/main/serial/src/srl_read.cc trunk/octave-forge/main/serial/src/srl_stopbits.cc trunk/octave-forge/main/serial/src/srl_write.cc Added: trunk/octave-forge/main/serial/COPYING =================================================================== --- trunk/octave-forge/main/serial/COPYING (rev 0) +++ trunk/octave-forge/main/serial/COPYING 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Added: trunk/octave-forge/main/serial/DESCRIPTION =================================================================== --- trunk/octave-forge/main/serial/DESCRIPTION (rev 0) +++ trunk/octave-forge/main/serial/DESCRIPTION 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,11 @@ +Name: serial +Version: 0.1.0 +Date: 2012-08-02 +Author: Andrius Sutas <and...@gm...> +Maintainer: Andrius Sutas <and...@gm...> +Title: Serial +Description: Serial functions for communicating from within octave. +Categories: Serial +Depends: octave (>= 3.6.2) +Autoload: no +License: GPLv3+ Added: trunk/octave-forge/main/serial/INDEX =================================================================== --- trunk/octave-forge/main/serial/INDEX (rev 0) +++ trunk/octave-forge/main/serial/INDEX 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,11 @@ +serial >> Serial +Serial + serial + srl_write + srl_baudrate + srl_bytesize + srl_flush + srl_parity + srl_stopbits + srl_close + srl_read \ No newline at end of file Added: trunk/octave-forge/main/serial/NEWS =================================================================== --- trunk/octave-forge/main/serial/NEWS (rev 0) +++ trunk/octave-forge/main/serial/NEWS 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,15 @@ +Summary of important user-visible changes for serial 0.1.0: +------------------------------------------------------------------- + + ** Initial release + + ** The following functions are new: + serial + srl_write + srl_baudrate + srl_bytesize + srl_flush + srl_parity + srl_stopbits + srl_close + srl_read Added: trunk/octave-forge/main/serial/src/Makefile =================================================================== --- trunk/octave-forge/main/serial/src/Makefile (rev 0) +++ trunk/octave-forge/main/serial/src/Makefile 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,17 @@ +OCT = serial.oct +OBJ := serial.o srl_baudrate.o srl_bytesize.o srl_flush.o srl_parity.o srl_stopbits.o srl_write.o srl_close.o srl_read.o + +MKOCTFILE ?= mkoctfile + +all: $(OCT) + +%.oct: $(OBJ) + $(MKOCTFILE) $^ + +%.o: %.cc + $(MKOCTFILE) -c -s $< + +clean: + rm -f *.oct *.o + +.PHONY: all clean Added: trunk/octave-forge/main/serial/src/serial.cc =================================================================== --- trunk/octave-forge/main/serial/src/serial.cc (rev 0) +++ trunk/octave-forge/main/serial/src/serial.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,170 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +// TODO: Include more detailed error messages +// TODO: Implement Flow Control +// TODO: Implement read timeout + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +DEFINE_OCTAVE_ALLOCATOR (octave_serial); +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_serial, "octave_serial", "octave_serial"); + +static bool type_loaded = false; + +octave_serial::octave_serial() +{ + this->fd = -1; +} + +octave_serial::octave_serial(string path, int flags) +{ + this->fd = open(path.c_str(), flags, 0); + tcgetattr(this->fd, &this->config); +} + +octave_serial::~octave_serial() +{ + this->srl_close(); +} + +int octave_serial::srl_get_fd() +{ + return this->fd; +} + +void octave_serial::print (std::ostream& os, bool pr_as_read_syntax ) const +{ + print_raw (os, pr_as_read_syntax); + newline (os); +} + +void octave_serial::print_raw (std::ostream& os, bool pr_as_read_syntax) const +{ + os << this->fd; +} + +// PKG_ADD: autoload ("serial", "serial.oct"); +DEFUN_DLD (serial, args, nargout, "Hello World Help String") +{ + int nargin = args.length(); + + // Do not open interface if return value is not assigned + if (nargout != 1) + { + error("serial: serial() function has one mandatory output argument"); + return octave_value(); + } + + +#ifdef __WIN32__ + error("serial: Windows platform support is not yet implemented, go away..."); + return octave_value(); +#endif + + // Default values + string path("/dev/ttyUSB0"); + unsigned int baud_rate = 115200; + unsigned short bytesize = 8; + string parity("N"); + unsigned short stopbits = 1; + int oflags = O_RDWR | O_NOCTTY | O_SYNC; + // O_SYNC - All writes immediately effective, no buffering + + if (!type_loaded) + { + octave_serial::register_type(); + type_loaded = true; + } + + // Parse the function arguments + if (args.length() > 0) + { + if (args(0).is_string()) + { + path = args(0).string_value(); + } + else + { + error("serial: 1st argument must be an interface path of type string..."); + return octave_value(); + } + + } + + // is_float_type() is or'ed to allow expression like ("", 123), without user + // having to use ("", int32(123)), as we still only take "int_value" + if (args.length() > 1) + { + if (args(1).is_integer_type() || args(1).is_float_type()) + { + baud_rate = args(1).int_value(); + } + else + { + error("serial: 2nd argument must be an interface baud rate of type integer..."); + return octave_value(); + } + } + + if (args.length() > 2) + { + if (args(2).is_integer_type() || args(2).is_float_type()) + { + oflags = args(2).int_value(); + } + else + { + error("serial: 3rd argument must be an interface flags of type integer..."); + return octave_value(); + } + } + + // Open the interface + octave_serial* retval = new octave_serial(path, oflags); + + if (retval->srl_get_fd() < 0) + { + error("serial: Error opening the interface..."); + return octave_value(); + } + + retval->srl_baudrate(baud_rate); + retval->srl_parity(parity); + retval->srl_bytesize(bytesize); + retval->srl_stopbits(stopbits); + + return octave_value(retval); +} Added: trunk/octave-forge/main/serial/src/serial.h =================================================================== --- trunk/octave-forge/main/serial/src/serial.h (rev 0) +++ trunk/octave-forge/main/serial/src/serial.h 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,86 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#ifndef SERIAL_H +#define SERIAL_H + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <string> + +/* a=target variable, b=bit number to act upon 0-n */ +#define BIT_SET(a,b) ((a) |= (1<<(b))) +#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b))) +#define BIT_FLIP(a,b) ((a) ^= (1<<(b))) +#define BIT_CHECK(a,b) ((a) & (1<<(b))) + +#define BITMASK_SET(x,y) ((x) |= (y)) +#define BITMASK_CLEAR(x,y) ((x) &= (~(y))) +#define BITMASK_TOGGLE(x,y) ((x) ^= (y)) +#define BITMASK_CHECK(x,y) ((x) & (y)) + +class octave_serial : public octave_base_value +{ +public: + octave_serial(); + octave_serial(string, int); + ~octave_serial(); + + int srl_get_fd(); + + int srl_write(string); + int srl_read(char *, unsigned int); + int srl_close(); + + int srl_flush(unsigned short); + + int srl_baudrate(unsigned int); + int srl_bytesize(unsigned short); + int srl_parity(string); + int srl_stopbits(unsigned short); + + + // Overloaded base functions + double serial_value() const + { + return (double)this->fd; + } + + virtual double scalar_value (bool frc_str_conv = false) const + { + return (double)this->fd; + } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax) const; + + // Properties + bool is_constant (void) const { return true;} + bool is_defined (void) const { return true;} + bool print_as_scalar (void) const { return true;} + +private: + int fd; + struct termios config; + + DECLARE_OCTAVE_ALLOCATOR + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + + +#endif Added: trunk/octave-forge/main/serial/src/srl_baudrate.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_baudrate.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_baudrate.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,137 @@ +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_baudrate", "serial.oct"); +DEFUN_DLD (srl_baudrate, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_baudrate: expecting one or two arguments..."); + return octave_value(-1); + } + + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_baudrate: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + // Setting new baudrate + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_baudrate: expecting second argument of type integer..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_baudrate(args(1).int_value()); + + return octave_value(); + } + + // Returning current baud rate + // TODO: return current baudrate + + return octave_value(-115200); +} + +int octave_serial::srl_baudrate(unsigned int baud) +{ + speed_t baud_rate = 0; + + switch (baud) + { + case 0: + baud_rate = B0; break; + case 50: + baud_rate = B50; break; + case 75: + baud_rate = B75; break; + case 110: + baud_rate = B110; break; + case 134: + baud_rate = B134; break; + case 150: + baud_rate = B150; break; + case 200: + baud_rate = B200; break; + case 300: + baud_rate = B300; break; + case 600: + baud_rate = B600; break; + case 1200: + baud_rate = B1200; break; + case 1800: + baud_rate = B1800; break; + case 2400: + baud_rate = B2400; break; + case 4800: + baud_rate = B4800; break; + case 9600: + baud_rate = B9600; break; + case 19200: + baud_rate = B19200; break; + case 38400: + baud_rate = B38400; break; + case 57600: + baud_rate = B57600; break; + case 115200: + baud_rate = B115200; break; + case 230400: + baud_rate = B230400; break; + default: + error("srl_baudrate: currently only standard baud rates are supported..."); + return false; + } + + cfsetispeed(&this->config, baud_rate); + cfsetospeed(&this->config, baud_rate); + + if (tcsetattr(this->srl_get_fd(), TCSANOW, &this->config) < 0) { + error("srl_baudrate: error setting baud rate..."); + return false; + } + + return true; +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_bytesize.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_bytesize.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_bytesize.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,114 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_bytesize", "serial.oct"); +DEFUN_DLD (srl_bytesize, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_bytesize: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_bytesize: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + // Setting new byte size + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_bytesize: expecting second argument of type integer..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_bytesize(args(1).int_value()); + + return octave_value(); + } + + // Returning current byte size + // TODO: return current byte size + + return octave_value(-8); +} + +int octave_serial::srl_bytesize(unsigned short bytesize) +{ + tcflag_t c_bytesize = 0; + + switch (bytesize) + { + case 5: c_bytesize = CS5; break; + case 6: c_bytesize = CS6; break; + case 7: c_bytesize = CS7; break; + case 8: c_bytesize = CS8; break; + + default: + error("srl_bytesize: expecting value between [5..8]..."); + return false; + } + + // Clear previous config flags + /* + BITMASK_CLEAR(this->config.c_cflag, CS5); + BITMASK_CLEAR(this->config.c_cflag, CS6); + BITMASK_CLEAR(this->config.c_cflag, CS7); + BITMASK_CLEAR(this->config.c_cflag, CS8); + */ + + // Clear bitmask CSIZE + BITMASK_CLEAR(this->config.c_cflag, CSIZE); + + // Apply new + this->config.c_cflag |= c_bytesize; + + if (tcsetattr(this->srl_get_fd(), TCSANOW, &this->config) < 0) { + error("srl_bytesize: error setting byte size..."); + return false; + } + + return true; +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_close.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_close.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_close.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,66 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_close", "serial.oct"); +DEFUN_DLD (srl_close, args, nargout, "Hello World Help String") +{ + if (args.length() != 1) + { + error("srl_close: expecting one argument..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_close: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_close(); + + return octave_value(); +} + +int octave_serial::srl_close() +{ + return ::close(this->srl_get_fd()); +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_flush.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_flush.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_flush.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,99 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_flush", "serial.oct"); +int octave_serial::srl_flush(unsigned short queue_selector) +{ + + // TCIFLUSH Flush pending input. + // TCIOFLUSH Flush both pending input and untransmitted output. + // TCOFLUSH Flush untransmitted output. + + + int flag; + + switch (queue_selector) + { + case 0: flag = TCIFLUSH; break; + case 1: flag = TCIOFLUSH; break; + case 2: flag = TCOFLUSH; break; + default: + error("srl_flush: only [0..2] values are accepted..."); + return false; + } + + return ::tcflush(this->srl_get_fd(), flag); +} + +// PKG_ADD: autoload ("srl_flush", "serial.oct"); +DEFUN_DLD (srl_flush, args, nargout, "Hello World Help String") +{ + int queue_selector = 1; + + if (args.length() < 1 || args.length() > 2) + { + error("srl_write: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_write: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + + if (args.length() > 1) + { + if (!(args(1).is_integer_type() || args(1).is_float_type())) + { + error("srl_write: expecting second argument of type integer..."); + return octave_value(-1); + } + + queue_selector = args(1).int_value(); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_flush(queue_selector); + + return octave_value(); +} Added: trunk/octave-forge/main/serial/src/srl_parity.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_parity.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_parity.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,123 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_parity", "serial.oct"); +DEFUN_DLD (srl_parity, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_parity: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_parity: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + // Setting new parity + if (args.length() > 1) + { + if ( !(args(1).is_string()) ) + { + error("srl_parity: expecting second argument of type string..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_parity(args(1).string_value()); + + return octave_value(); + } + + // Returning current parity + // TODO: return current parity + + return octave_value("-N"); +} + +int octave_serial::srl_parity(string parity) +{ + // Convert string to lowercase + std::transform(parity.begin(), parity.end(), parity.begin(), ::tolower); + + /* + * PARENB Enable parity generation on output and parity checking for input. + * PARODD If set, then parity for input and output is odd; otherwise even parity is used. + */ + + if (parity == "n" || parity == "none") + { + // Disable parity generation/checking + BITMASK_CLEAR(this->config.c_cflag, PARENB); + } + else if (parity == "e" || parity == "even") + { + // Enable parity generation/checking + BITMASK_SET(this->config.c_cflag, PARENB); + + // Set to Even + BITMASK_CLEAR(this->config.c_cflag, PARODD); + + } + else if (parity == "o" || parity == "odd") + { + // Enable parity generation/checking + BITMASK_SET(this->config.c_cflag, PARENB); + + // Set to Odd + BITMASK_SET(this->config.c_cflag, PARODD); + + } + else + { + error("srl_parity: Only [N]one, [E]ven or [O]dd parities are supported..."); + return false; + } + + if (tcsetattr(this->srl_get_fd(), TCSANOW, &this->config) < 0) { + error("srl_parity: error setting parity..."); + return false; + } + + return true; +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_read.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_read.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,111 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +#include <octave/ov-uint8.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_read", "serial.oct"); +DEFUN_DLD (srl_read, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_read: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_read: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + char *buffer = NULL; + unsigned int buffer_len = 1; + + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_read: expecting second argument of type integer..."); + return octave_value(-1); + } + + buffer_len = args(1).int_value(); + } + + buffer = new char[buffer_len+1]; + + if (buffer == NULL) + { + error("srl_read: cannot allocate requested memory..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + int retval = 0; + + while (retval < buffer_len) + { + retval += serial->srl_read(buffer + retval, buffer_len - retval); + } + + //buffer[retval] = '\0'; + + octave_value_list return_list; + uint8NDArray data; + data.resize(retval); + + // TODO: clean this up + for (int i = 0; i < retval; i++) + { + data(i) = buffer[i]; + } + + return_list(1) = retval; + return_list(0) = data; + + delete[] buffer; + + return return_list; +} + +int octave_serial::srl_read(char *buf, unsigned int len) +{ + return ::read(srl_get_fd(), buf, len); +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_stopbits.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_stopbits.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_stopbits.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,107 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_stopbits", "serial.oct"); +DEFUN_DLD (srl_stopbits, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_stopbits: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_stopbits: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + // Setting new stop bits + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_stopbits: expecting second argument of type integer..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_stopbits(args(1).int_value()); + + return octave_value(); + } + + // Returning current stop bits + + // TODO: return current stop bits + + return octave_value(-1); +} + +int octave_serial::srl_stopbits(unsigned short stopbits) +{ + /* + * CSTOPB Send two stop bits, else one. + */ + + if (stopbits == 1) + { + // Set to one stop bit + BITMASK_CLEAR(this->config.c_cflag, CSTOPB); + } + else if (stopbits == 2) + { + // Set to two stop bits + BITMASK_SET(this->config.c_cflag, CSTOPB); + } + else + { + error("srl_stopbits: Only 1 or 2 stop bits are supported..."); + return false; + } + + if (tcsetattr(this->srl_get_fd(), TCSANOW, &this->config) < 0) { + error("srl_stopbits: error setting stop bits..."); + return false; + } + + return true; +} \ No newline at end of file Added: trunk/octave-forge/main/serial/src/srl_write.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_write.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_write.cc 2012-08-07 19:48:30 UTC (rev 10840) @@ -0,0 +1,73 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// TODO: implement uint8 array as input type +// PKG_ADD: autoload ("srl_write", "serial.oct"); +DEFUN_DLD (srl_write, args, nargout, "Hello World Help String") +{ + if (args.length() != 2) + { + error("srl_write: expecting two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_write: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + if (!args(1).is_string()) + { + error("srl_write: expecting second argument of type string..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_write(args(1).string_value()); + + return octave_value(); +} + +int octave_serial::srl_write(string str) +{ + return ::write(srl_get_fd(), str.c_str(), str.length()); +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ean...@us...> - 2012-08-19 22:33:06
|
Revision: 10887 http://octave.svn.sourceforge.net/octave/?rev=10887&view=rev Author: eandrius Date: 2012-08-19 22:32:59 +0000 (Sun, 19 Aug 2012) Log Message: ----------- i2c: initial commit \nserial: small changes to error reporting Modified Paths: -------------- trunk/octave-forge/main/serial/DESCRIPTION trunk/octave-forge/main/serial/src/serial.h trunk/octave-forge/main/serial/src/srl_baudrate.cc trunk/octave-forge/main/serial/src/srl_read.cc trunk/octave-forge/main/serial/src/srl_write.cc Added Paths: ----------- trunk/octave-forge/main/i2c/ trunk/octave-forge/main/i2c/COPYING trunk/octave-forge/main/i2c/DESCRIPTION trunk/octave-forge/main/i2c/INDEX trunk/octave-forge/main/i2c/NEWS trunk/octave-forge/main/i2c/src/ trunk/octave-forge/main/i2c/src/Makefile trunk/octave-forge/main/i2c/src/i2c.cc trunk/octave-forge/main/i2c/src/i2c.h trunk/octave-forge/main/i2c/src/i2c_addr.cc trunk/octave-forge/main/i2c/src/i2c_close.cc trunk/octave-forge/main/i2c/src/i2c_read.cc trunk/octave-forge/main/i2c/src/i2c_write.cc Added: trunk/octave-forge/main/i2c/COPYING =================================================================== --- trunk/octave-forge/main/i2c/COPYING (rev 0) +++ trunk/octave-forge/main/i2c/COPYING 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Added: trunk/octave-forge/main/i2c/DESCRIPTION =================================================================== --- trunk/octave-forge/main/i2c/DESCRIPTION (rev 0) +++ trunk/octave-forge/main/i2c/DESCRIPTION 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,11 @@ +Name: i2c +Version: 0.1.0 +Date: 2012-08-19 +Author: Andrius Sutas <and...@gm...> +Maintainer: Andrius Sutas <and...@gm...> +Title: i2c +Description: i2c functions for communicating from within octave. +Categories: i2c +Depends: octave (>= 3.4.0) +Autoload: no +License: LGPLv3+ Added: trunk/octave-forge/main/i2c/INDEX =================================================================== --- trunk/octave-forge/main/i2c/INDEX (rev 0) +++ trunk/octave-forge/main/i2c/INDEX 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,8 @@ +i2c >> i2c +i2c + i2c + i2c_addr + i2c_read + i2c_write + i2c_close + Added: trunk/octave-forge/main/i2c/NEWS =================================================================== --- trunk/octave-forge/main/i2c/NEWS (rev 0) +++ trunk/octave-forge/main/i2c/NEWS 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,12 @@ +Summary of important user-visible changes for i2c 0.1.0: +------------------------------------------------------------------- + + ** Initial release + + ** The following functions are new: + i2c + i2c_addr + i2c_read + i2c_write + i2c_close + Added: trunk/octave-forge/main/i2c/src/Makefile =================================================================== --- trunk/octave-forge/main/i2c/src/Makefile (rev 0) +++ trunk/octave-forge/main/i2c/src/Makefile 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,19 @@ +OCT = i2c.oct +OBJ := i2c.o i2c_close.o i2c_addr.o i2c_write.o i2c_read.o + + +MKOCTFILE ?= mkoctfile + +all: $(OCT) + +%.oct: $(OBJ) + $(MKOCTFILE) $^ + +%.o: %.cc + $(MKOCTFILE) -c -s $< + +clean: + rm -f *.oct *.o + + +.PHONY: all clean Added: trunk/octave-forge/main/i2c/src/i2c.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,109 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +DEFINE_OCTAVE_ALLOCATOR (octave_i2c); +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_i2c, "octave_i2c", "octave_i2c"); + +static bool type_loaded = false; + +octave_i2c::octave_i2c() +{ + this->fd = -1; +} + +octave_i2c::octave_i2c(string path, int flags) +{ + this->fd = open(path.c_str(), flags, 0); +} + +octave_i2c::~octave_i2c() +{ + this->i2c_close(); +} + +int octave_i2c::i2c_get_fd() +{ + return this->fd; +} + +void octave_i2c::print (std::ostream& os, bool pr_as_read_syntax ) const +{ + print_raw(os, pr_as_read_syntax); + newline(os); +} + +void octave_i2c::print_raw (std::ostream& os, bool pr_as_read_syntax) const +{ + os << this->fd; +} + +// PKG_ADD: autoload ("i2c", "i2c.oct"); +DEFUN_DLD (i2c, args, nargout, "i2c() function has one mandatory output argument") +{ +#ifdef __WIN32__ + error("i2c: Windows platform support is not yet implemented, go away..."); + return octave_value(); +#endif + + int nargin = args.length(); + + // Default values + int oflags = O_RDWR; + string path("/dev/i2c-0"); + + // Do not open interface if return value is not assigned + if (nargout != 1) + { + print_usage(); + return octave_value(); + } + + // Open the interface + octave_i2c* retval = new octave_i2c(path, oflags); + + if (retval->i2c_get_fd() < 0) + { + error("i2c: Error opening the interface: %s\n", strerror(errno)); + return octave_value(); + } + + return octave_value(retval); +} Added: trunk/octave-forge/main/i2c/src/i2c.h =================================================================== --- trunk/octave-forge/main/i2c/src/i2c.h (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c.h 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,72 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#ifndef i2c_H +#define i2c_H + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <string> + +using std::string; + +class octave_i2c : public octave_base_value +{ +public: + octave_i2c(); + octave_i2c(string, int); + ~octave_i2c(); + + int i2c_get_fd(); + int i2c_close(); + + int i2c_set_addr(int); + int i2c_get_addr(); + + // Simple i2c commands + int i2c_write(unsigned char*, int); + int i2c_read(char*, unsigned int); + + + // Overloaded base functions + double i2c_value() const + { + return (double)this->fd; + } + + virtual double scalar_value (bool frc_str_conv = false) const + { + return (double)this->fd; + } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax) const; + + // Properties + bool is_constant (void) const { return true;} + bool is_defined (void) const { return true;} + bool print_as_scalar (void) const { return true;} + +private: + int fd; + int addr; + + DECLARE_OCTAVE_ALLOCATOR + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + + +#endif Added: trunk/octave-forge/main/i2c/src/i2c_addr.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_addr.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_addr.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,89 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_addr", "i2c.oct"); +DEFUN_DLD (i2c_addr, args, nargout, "Hello World Help String") +{ + if (args.length() > 2 || + args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + + // Setting new slave address + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + i2c->i2c_set_addr(args(1).int_value()); + + return octave_value(); + } + + // Returning current slave address + return octave_value(i2c->i2c_get_addr()); +} + +int octave_i2c::i2c_set_addr(int addr) +{ + + if (::ioctl(i2c_get_fd(), I2C_SLAVE, addr) < 0) + { + error("i2c: Error setting slave address: %s\n", strerror(errno)); + return false; + } + + return true; +} + +int octave_i2c::i2c_get_addr() +{ + return this->addr; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_close.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_close.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_close.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,66 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_close", "i2c.oct"); +DEFUN_DLD (i2c_close, args, nargout, "Hello World Help String") +{ + if (args.length() != 1 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + i2c->i2c_close(); + + return octave_value(); +} + +int octave_i2c::i2c_close() +{ + int retval = ::close(this->i2c_get_fd()); + this->fd = -1; + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_read.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_read.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_read.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,101 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_read", "i2c.oct"); +DEFUN_DLD (i2c_read, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + char *buffer = NULL; + unsigned int buffer_len = 1; + + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + buffer_len = args(1).int_value(); + } + + buffer = new char [buffer_len + 1]; + + if (buffer == NULL) + { + error("i2c_read: cannot allocate requested memory..."); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + int retval; + + retval = i2c->i2c_read(buffer, buffer_len); + + octave_value_list return_list; + uint8NDArray data(retval); + + for (int i = 0; i < retval; i++) + data(i) = buffer[i]; + + return_list(1) = retval; + return_list(0) = data; + + delete[] buffer; + + return return_list; +} + +int octave_i2c::i2c_read(char *buf, unsigned int len) +{ + int retval = ::read(i2c_get_fd(), buf, len); + + if (retval != len) + error("i2c: Failed to read from the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/i2c/src/i2c_write.cc =================================================================== --- trunk/octave-forge/main/i2c/src/i2c_write.cc (rev 0) +++ trunk/octave-forge/main/i2c/src/i2c_write.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -0,0 +1,90 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_write", "i2c.oct"); +DEFUN_DLD (i2c_write, args, nargout, "Hello World Help String") +{ + if (args.length() != 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + const octave_base_value& data = args(1).get_rep(); + int retval; + + if (data.is_string()) + { + string buf = data.string_value(); + retval = i2c->i2c_write((unsigned char*)buf.c_str(), buf.length()); + } + else if (data.byte_size() == data.numel()) + { + NDArray dtmp = data.array_value(); + unsigned char* buf = new unsigned char [dtmp.length()]; + + for (int i = 0; i < dtmp.length(); i++) + buf[i] = (unsigned char)dtmp(i); + + retval = i2c->i2c_write(buf, data.byte_size()); + + delete[] buf; + } + else + { + print_usage(); + return octave_value(-1); + } + + return octave_value(retval); +} + +int octave_i2c::i2c_write(unsigned char *buf, int len) +{ + int retval = ::write(i2c_get_fd(), buf, len); + + if (retval < 0) + error("i2c: Failed to write to the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Modified: trunk/octave-forge/main/serial/DESCRIPTION =================================================================== --- trunk/octave-forge/main/serial/DESCRIPTION 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/DESCRIPTION 2012-08-19 22:32:59 UTC (rev 10887) @@ -6,6 +6,6 @@ Title: Serial Description: Serial functions for communicating from within octave. Categories: Serial -Depends: octave (>= 3.6.2) +Depends: octave (>= 3.2.0) Autoload: no License: LGPLv3+ Modified: trunk/octave-forge/main/serial/src/serial.h =================================================================== --- trunk/octave-forge/main/serial/src/serial.h 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/serial.h 2012-08-19 22:32:59 UTC (rev 10887) @@ -23,12 +23,6 @@ #include <string> -/* a=target variable, b=bit number to act upon 0-n */ -#define BIT_SET(a,b) ((a) |= (1<<(b))) -#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b))) -#define BIT_FLIP(a,b) ((a) ^= (1<<(b))) -#define BIT_CHECK(a,b) ((a) & (1<<(b))) - #define BITMASK_SET(x,y) ((x) |= (y)) #define BITMASK_CLEAR(x,y) ((x) &= (~(y))) #define BITMASK_TOGGLE(x,y) ((x) ^= (y)) Modified: trunk/octave-forge/main/serial/src/srl_baudrate.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_baudrate.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_baudrate.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -38,19 +38,13 @@ // PKG_ADD: autoload ("srl_baudrate", "serial.oct"); DEFUN_DLD (srl_baudrate, args, nargout, "Hello World Help String") { - if (args.length() < 1 || args.length() > 2) + if (args.length() < 1 || args.length() > 2 || + args(0).type_id() != octave_serial::static_type_id()) { - error("srl_baudrate: expecting one or two arguments..."); + print_usage(); return octave_value(-1); } - - if (args(0).type_id() != octave_serial::static_type_id()) - { - error("srl_baudrate: expecting first argument of type octave_serial..."); - return octave_value(-1); - } - // Setting new baudrate if (args.length() > 1) { Modified: trunk/octave-forge/main/serial/src/srl_read.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -88,9 +88,8 @@ } octave_value_list return_list; - uint8NDArray data; - data.resize(buffer_read); - + uint8NDArray data(buffer_read); + // TODO: clean this up for (int i = 0; i < buffer_read; i++) { Modified: trunk/octave-forge/main/serial/src/srl_write.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_write.cc 2012-08-19 04:30:38 UTC (rev 10886) +++ trunk/octave-forge/main/serial/src/srl_write.cc 2012-08-19 22:32:59 UTC (rev 10887) @@ -39,24 +39,14 @@ // PKG_ADD: autoload ("srl_write", "serial.oct"); DEFUN_DLD (srl_write, args, nargout, "Hello World Help String") { - if (args.length() != 2) + if (args.length() != 2) || + args(0).type_id() != octave_serial::static_type_id() || + !args(1).is_string()) { - error("srl_write: expecting two arguments..."); + print_usage(); return octave_value(-1); } - - if (args(0).type_id() != octave_serial::static_type_id()) - { - error("srl_write: expecting first argument of type octave_serial..."); - return octave_value(-1); - } - - if (!args(1).is_string()) - { - error("srl_write: expecting second argument of type string..."); - return octave_value(-1); - } - + octave_serial* serial = NULL; const octave_base_value& rep = args(0).get_rep(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ean...@us...> - 2012-09-02 22:39:49
|
Revision: 10954 http://octave.svn.sourceforge.net/octave/?rev=10954&view=rev Author: eandrius Date: 2012-09-02 22:39:41 +0000 (Sun, 02 Sep 2012) Log Message: ----------- instrument-control: merged serial and i2c packages Added Paths: ----------- trunk/octave-forge/main/instrument-control/ trunk/octave-forge/main/instrument-control/COPYING trunk/octave-forge/main/instrument-control/DESCRIPTION trunk/octave-forge/main/instrument-control/INDEX trunk/octave-forge/main/instrument-control/NEWS trunk/octave-forge/main/instrument-control/PKG_ADD trunk/octave-forge/main/instrument-control/src/ trunk/octave-forge/main/instrument-control/src/Makefile trunk/octave-forge/main/instrument-control/src/i2c/ trunk/octave-forge/main/instrument-control/src/i2c/Makefile trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c.h trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc trunk/octave-forge/main/instrument-control/src/serial/ trunk/octave-forge/main/instrument-control/src/serial/Makefile trunk/octave-forge/main/instrument-control/src/serial/serial.cc trunk/octave-forge/main/instrument-control/src/serial/serial.h trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc trunk/octave-forge/main/instrument-control/src/serial/srl_stopbits.cc trunk/octave-forge/main/instrument-control/src/serial/srl_timeout.cc trunk/octave-forge/main/instrument-control/src/serial/srl_write.cc Removed Paths: ------------- trunk/octave-forge/main/i2c/ trunk/octave-forge/main/serial/ Added: trunk/octave-forge/main/instrument-control/COPYING =================================================================== --- trunk/octave-forge/main/instrument-control/COPYING (rev 0) +++ trunk/octave-forge/main/instrument-control/COPYING 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Added: trunk/octave-forge/main/instrument-control/DESCRIPTION =================================================================== --- trunk/octave-forge/main/instrument-control/DESCRIPTION (rev 0) +++ trunk/octave-forge/main/instrument-control/DESCRIPTION 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,11 @@ +Name: instrument-control +Version: 0.1.0 +Date: 2012-09-02 +Author: Andrius Sutas <and...@gm...> +Maintainer: Andrius Sutas <and...@gm...> +Title: Instrument Control Toolbox +Description: Low level I/O functions for serial, i2c and parallel interfaces. +Categories: instrument-control +Depends: octave (>= 3.2.0) +Autoload: no +License: LGPLv3+ Added: trunk/octave-forge/main/instrument-control/INDEX =================================================================== --- trunk/octave-forge/main/instrument-control/INDEX (rev 0) +++ trunk/octave-forge/main/instrument-control/INDEX 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,12 @@ +instrument-control >> Low level I/O functions + +Serial + serial + srl_read + srl_write + srl_close + +I2C + i2c + i2c_read + i2c_write Added: trunk/octave-forge/main/instrument-control/NEWS =================================================================== --- trunk/octave-forge/main/instrument-control/NEWS (rev 0) +++ trunk/octave-forge/main/instrument-control/NEWS 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,9 @@ +Summary of important user-visible changes for instrument-control 0.1.0: +------------------------------------------------------------------- + + ** Initial release + + ** Support for parallel port I/O + + ** The following functions are new: + parport Added: trunk/octave-forge/main/instrument-control/PKG_ADD =================================================================== --- trunk/octave-forge/main/instrument-control/PKG_ADD (rev 0) +++ trunk/octave-forge/main/instrument-control/PKG_ADD 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,18 @@ +# Serial +autoload ("srl_timeout", "instrument-control.oct"); +autoload ("serial", "instrument-control.oct"); +autoload ("srl_stopbits", "instrument-control.oct"); +autoload ("srl_read", "instrument-control.oct"); +autoload ("srl_parity", "instrument-control.oct"); +autoload ("srl_close", "instrument-control.oct"); +autoload ("srl_bytesize", "instrument-control.oct"); +autoload ("srl_write", "instrument-control.oct"); +autoload ("srl_flush", "instrument-control.oct"); +autoload ("srl_baudrate", "instrument-control.oct"); + +# I2C +autoload ("i2c_addr", "instrument-control.oct"); +autoload ("i2c", "instrument-control.oct"); +autoload ("i2c_read", "instrument-control.oct"); +autoload ("i2c_close", "instrument-control.oct"); +autoload ("i2c_write", "instrument-control.oct"); Added: trunk/octave-forge/main/instrument-control/src/Makefile =================================================================== --- trunk/octave-forge/main/instrument-control/src/Makefile (rev 0) +++ trunk/octave-forge/main/instrument-control/src/Makefile 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,12 @@ +OCT = instrument-control +SUBDIRS = i2c serial + +MKOCTFILE ?= mkoctfile + +all: + @for dir in $(SUBDIRS); do $(MAKE) -C $$dir; done + $(MKOCTFILE) i2c/*.o serial/*.o -o $(OCT) + +clean: + @for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done + rm -f *.oct Added: trunk/octave-forge/main/instrument-control/src/i2c/Makefile =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/Makefile (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/Makefile 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,21 @@ +OCT := i2c.oct +OBJ := i2c.o i2c_close.o i2c_addr.o i2c_write.o i2c_read.o + +MKOCTFILE ?= mkoctfile + +all: $(OBJ) + +oct: $(OCT) + +%.oct: $(OBJ) + $(MKOCTFILE) $^ + +%.o: %.cc + $(MKOCTFILE) -c -s $< + + +clean: + rm -f *.oct *.o + + +.PHONY: all clean Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,122 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +DEFINE_OCTAVE_ALLOCATOR (octave_i2c); +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_i2c, "octave_i2c", "octave_i2c"); + +static bool type_loaded = false; + + + +DEFUN_DLD (helloworld, args, nargout, + "Hello World Help String") + { + int nargin = args.length (); + octave_stdout << "Hello World has " << nargin + << " input arguments and " + << nargout << " output arguments.\n"; + return octave_value_list (); + } + + +octave_i2c::octave_i2c() +{ + this->fd = -1; +} + +octave_i2c::octave_i2c(string path, int flags) +{ + this->fd = open(path.c_str(), flags, 0); +} + +octave_i2c::~octave_i2c() +{ + this->i2c_close(); +} + +int octave_i2c::i2c_get_fd() +{ + return this->fd; +} + +void octave_i2c::print (std::ostream& os, bool pr_as_read_syntax ) const +{ + print_raw(os, pr_as_read_syntax); + newline(os); +} + +void octave_i2c::print_raw (std::ostream& os, bool pr_as_read_syntax) const +{ + os << this->fd; +} + +// PKG_ADD: autoload ("i2c", "instrument-control.oct"); +DEFUN_DLD (i2c, args, nargout, "i2c() function has one mandatory output argument") +{ +#ifdef __WIN32__ + error("i2c: Windows platform support is not yet implemented, go away..."); + return octave_value(); +#endif + + int nargin = args.length(); + + // Default values + int oflags = O_RDWR; + string path("/dev/i2c-0"); + + // Do not open interface if return value is not assigned + if (nargout != 1) + { + print_usage(); + return octave_value(); + } + + // Open the interface + octave_i2c* retval = new octave_i2c(path, oflags); + + if (retval->i2c_get_fd() < 0) + { + error("i2c: Error opening the interface: %s\n", strerror(errno)); + return octave_value(); + } + + return octave_value(retval); +} Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c.h =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c.h (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c.h 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,72 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#ifndef i2c_H +#define i2c_H + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <string> + +using std::string; + +class octave_i2c : public octave_base_value +{ +public: + octave_i2c(); + octave_i2c(string, int); + ~octave_i2c(); + + int i2c_get_fd(); + int i2c_close(); + + int i2c_set_addr(int); + int i2c_get_addr(); + + // Simple i2c commands + int i2c_write(unsigned char*, int); + int i2c_read(char*, unsigned int); + + + // Overloaded base functions + double i2c_value() const + { + return (double)this->fd; + } + + virtual double scalar_value (bool frc_str_conv = false) const + { + return (double)this->fd; + } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax) const; + + // Properties + bool is_constant (void) const { return true;} + bool is_defined (void) const { return true;} + bool print_as_scalar (void) const { return true;} + +private: + int fd; + int addr; + + DECLARE_OCTAVE_ALLOCATOR + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + + +#endif Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,89 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_addr", "instrument-control.oct"); +DEFUN_DLD (i2c_addr, args, nargout, "Hello World Help String") +{ + if (args.length() > 2 || + args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + + // Setting new slave address + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + i2c->i2c_set_addr(args(1).int_value()); + + return octave_value(); + } + + // Returning current slave address + return octave_value(i2c->i2c_get_addr()); +} + +int octave_i2c::i2c_set_addr(int addr) +{ + + if (::ioctl(i2c_get_fd(), I2C_SLAVE, addr) < 0) + { + error("i2c: Error setting slave address: %s\n", strerror(errno)); + return false; + } + + return true; +} + +int octave_i2c::i2c_get_addr() +{ + return this->addr; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,66 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + +using std::string; + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_close", "instrument-control.oct"); +DEFUN_DLD (i2c_close, args, nargout, "Hello World Help String") +{ + if (args.length() != 1 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + i2c->i2c_close(); + + return octave_value(); +} + +int octave_i2c::i2c_close() +{ + int retval = ::close(this->i2c_get_fd()); + this->fd = -1; + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,101 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_read", "instrument-control.oct"); +DEFUN_DLD (i2c_read, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + char *buffer = NULL; + unsigned int buffer_len = 1; + + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + buffer_len = args(1).int_value(); + } + + buffer = new char [buffer_len + 1]; + + if (buffer == NULL) + { + error("i2c_read: cannot allocate requested memory..."); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + int retval; + + retval = i2c->i2c_read(buffer, buffer_len); + + octave_value_list return_list; + uint8NDArray data(retval); + + for (int i = 0; i < retval; i++) + data(i) = buffer[i]; + + return_list(1) = retval; + return_list(0) = data; + + delete[] buffer; + + return return_list; +} + +int octave_i2c::i2c_read(char *buf, unsigned int len) +{ + int retval = ::read(i2c_get_fd(), buf, len); + + if (retval != len) + error("i2c: Failed to read from the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,90 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/i2c-dev.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + + +#include "i2c.h" + +// PKG_ADD: autoload ("i2c_write", "instrument-control.oct"); +DEFUN_DLD (i2c_write, args, nargout, "Hello World Help String") +{ + if (args.length() != 2 || args(0).type_id() != octave_i2c::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_i2c* i2c = NULL; + + const octave_base_value& rep = args(0).get_rep(); + i2c = &((octave_i2c &)rep); + + const octave_base_value& data = args(1).get_rep(); + int retval; + + if (data.is_string()) + { + string buf = data.string_value(); + retval = i2c->i2c_write((unsigned char*)buf.c_str(), buf.length()); + } + else if (data.byte_size() == data.numel()) + { + NDArray dtmp = data.array_value(); + unsigned char* buf = new unsigned char [dtmp.length()]; + + for (int i = 0; i < dtmp.length(); i++) + buf[i] = (unsigned char)dtmp(i); + + retval = i2c->i2c_write(buf, data.byte_size()); + + delete[] buf; + } + else + { + print_usage(); + return octave_value(-1); + } + + return octave_value(retval); +} + +int octave_i2c::i2c_write(unsigned char *buf, int len) +{ + int retval = ::write(i2c_get_fd(), buf, len); + + if (retval < 0) + error("i2c: Failed to write to the i2c bus: %s\n", strerror(errno)); + + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/Makefile =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/Makefile (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/Makefile 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,21 @@ +OCT := serial.oct +OBJ := serial.o srl_baudrate.o srl_timeout.o srl_bytesize.o srl_flush.o \ + srl_parity.o srl_stopbits.o srl_write.o srl_close.o srl_read.o + +MKOCTFILE ?= mkoctfile + +all: $(OBJ) + +oct: $(OCT) + +%.oct: $(OBJ) + $(MKOCTFILE) $^ + +%.o: %.cc + $(MKOCTFILE) -c -s $< + +clean: + rm -f *.oct *.o + + +.PHONY: all clean Added: trunk/octave-forge/main/instrument-control/src/serial/serial.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/serial.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/serial.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,187 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +// TODO: Implement Flow Control +// TODO: Implement H/W handshaking +// TODO: Check if interface is opened first + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +DEFINE_OCTAVE_ALLOCATOR (octave_serial); +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_serial, "octave_serial", "octave_serial"); + +static bool type_loaded = false; + +octave_serial::octave_serial() +{ + this->fd = -1; +} + +octave_serial::octave_serial(string path, int flags) +{ + this->fd = open(path.c_str(), flags, 0); + + if (this->fd > 0) + { + tcgetattr(this->fd, &this->config); + this->blocking_read = true; + } +} + +octave_serial::~octave_serial() +{ + this->close(); +} + +void octave_serial::print (std::ostream& os, bool pr_as_read_syntax ) const +{ + print_raw(os, pr_as_read_syntax); + newline(os); +} + +void octave_serial::print_raw (std::ostream& os, bool pr_as_read_syntax) const +{ + os << this->fd; +} + +// PKG_ADD: autoload ("serial", "instrument-control.oct"); +DEFUN_DLD (serial, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {@var{serial} = } serial ([@var{path}], [@var{baudrate}], [@var{timeout}])\n \ +\n\ +Open serial interface.\n \ +\n\ +@var{path} - the interface path of type String. If omitted defaults to '/dev/ttyUSB0'. @*\ +@var{baudrate} - the baudrate of interface. If omitted defaults to 115200. @*\ +@var{timeout} - the interface timeout value. If omitted defaults to blocking call.\n \ +\n\ +The serial() shall return instance of @var{octave_serial} class as the result @var{serial}.\n \ +@end deftypefn") +{ +#ifdef __WIN32__ + error("serial: Windows platform support is not yet implemented, go away..."); + return octave_value(); +#endif + + int nargin = args.length(); + + // Do not open interface if return value is not assigned + if (nargout != 1) + { + print_usage(); + return octave_value(); + } + + // Default values + string path("/dev/ttyUSB0"); + unsigned int baud_rate = 115200; + short timeout = -1; + + unsigned short bytesize = 8; + string parity("N"); + unsigned short stopbits = 1; + int oflags = O_RDWR | O_NOCTTY | O_SYNC; + // O_SYNC - All writes immediately effective, no buffering + + if (!type_loaded) + { + octave_serial::register_type(); + type_loaded = true; + } + + // Parse the function arguments + if (args.length() > 0) + { + if (args(0).is_string()) + { + path = args(0).string_value(); + } + else + { + print_usage(); + return octave_value(); + } + + } + + // is_float_type() is or'ed to allow expression like ("", 123), without user + // having to use ("", int32(123)), as we still only take "int_value" + if (args.length() > 1) + { + if (args(1).is_integer_type() || args(1).is_float_type()) + { + baud_rate = args(1).int_value(); + } + else + { + print_usage(); + return octave_value(); + } + } + + if (args.length() > 2) + { + if (args(2).is_integer_type() || args(2).is_float_type()) + { + timeout = args(2).int_value(); + } + else + { + print_usage(); + return octave_value(); + } + } + + // Open the interface + octave_serial* retval = new octave_serial(path, oflags); + + if (retval->get_fd() < 0) + { + error("serial: Error opening the interface: %s\n", strerror(errno)); + return octave_value(); + } + + retval->set_baudrate(baud_rate); + + if (timeout >= 0) { + retval->set_timeout(timeout); + } + + retval->set_parity(parity); + retval->set_bytesize(bytesize); + retval->set_stopbits(stopbits); + + //retval->flush(2); + + return octave_value(retval); +} Added: trunk/octave-forge/main/instrument-control/src/serial/serial.h =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/serial.h (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/serial.h 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,89 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#ifndef SERIAL_H +#define SERIAL_H + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <string> + +#define BITMASK_SET(x,y) ((x) |= (y)) +#define BITMASK_CLEAR(x,y) ((x) &= (~(y))) +#define BITMASK_TOGGLE(x,y) ((x) ^= (y)) +#define BITMASK_CHECK(x,y) ((x) & (y)) + +class octave_serial : public octave_base_value +{ +public: + octave_serial(); + octave_serial(string, int); + ~octave_serial(); + + int write(string); + int write(unsigned char*, int); + + int read(char *, unsigned int); + + int close(); + + int flush(unsigned short); + + int set_timeout(short); + int get_timeout(); + + int set_baudrate(unsigned int); + int get_baudrate(); + + int set_bytesize(unsigned short); + int get_bytesize(); + + int set_parity(string); + string get_parity(); + + int set_stopbits(unsigned short); + int get_stopbits(); + + int get_fd() { return this->fd; } + + // Overloaded base functions + double serial_value() const { return (double)this->fd; } + + virtual double scalar_value (bool frc_str_conv = false) const + { + return (double)this->fd; + } + + void print (std::ostream& os, bool pr_as_read_syntax = false) const; + void print_raw (std::ostream& os, bool pr_as_read_syntax) const; + + // Properties + bool is_constant (void) const { return true;} + bool is_defined (void) const { return true;} + bool print_as_scalar (void) const { return true;} + +private: + int fd; + struct termios config; + + bool blocking_read; + + DECLARE_OCTAVE_ALLOCATOR + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + + +#endif Added: trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,193 @@ +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_baudrate", "instrument-control.oct"); +DEFUN_DLD (srl_baudrate, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} srl_baudrate (@var{serial}, @var{baudrate})\n \ +@deftypefnx {Loadable Function} {@var{br} = } srl_baudrate (@var{serial})\n \ +\n\ +Set new or get existing serial interface baudrate parameter. Only standard values are supported.\n \ +\n\ +@var{serial} - instance of @var{octave_serial} class.@*\ +@var{baudrate} - the baudrate value used. Supported values: 0, 50, 75, 110, \ +134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600 19200, 38400, 57600, \ +115200 and 230400.\n \ +\n\ +If @var{baudrate} parameter is omitted, the srl_baudrate() shall return current baudrate value as the result @var{br}.\n \ +@end deftypefn") +{ + if (args.length() < 1 || args.length() > 2 || + args(0).type_id() != octave_serial::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + // Setting new baudrate + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_baudrate: expecting second argument of type integer..."); + return octave_value(-1); + } + + serial->set_baudrate(args(1).int_value()); + + return octave_value(); + } + + // Returning current baud rate + return octave_value(serial->get_baudrate()); +} + +int octave_serial::set_baudrate(unsigned int baud) +{ + speed_t baud_rate = 0; + + switch (baud) + { + case 0: + baud_rate = B0; break; + case 50: + baud_rate = B50; break; + case 75: + baud_rate = B75; break; + case 110: + baud_rate = B110; break; + case 134: + baud_rate = B134; break; + case 150: + baud_rate = B150; break; + case 200: + baud_rate = B200; break; + case 300: + baud_rate = B300; break; + case 600: + baud_rate = B600; break; + case 1200: + baud_rate = B1200; break; + case 1800: + baud_rate = B1800; break; + case 2400: + baud_rate = B2400; break; + case 4800: + baud_rate = B4800; break; + case 9600: + baud_rate = B9600; break; + case 19200: + baud_rate = B19200; break; + case 38400: + baud_rate = B38400; break; + case 57600: + baud_rate = B57600; break; + case 115200: + baud_rate = B115200; break; + case 230400: + baud_rate = B230400; break; + default: + error("srl_baudrate: currently only 0, 50, 75, 110, \ + 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, \ + 9600 19200, 38400, 57600, 115200 and 230400 baud rates are supported..."); + return false; + } + + cfsetispeed(&this->config, baud_rate); + cfsetospeed(&this->config, baud_rate); + + if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { + error("srl_baudrate: error setting baud rate: %s\n", strerror(errno)); + return false; + } + + return true; +} + +int octave_serial::get_baudrate() +{ + int retval = -1; + + speed_t baudrate = cfgetispeed(&this->config); + + if (baudrate == B0) + retval = 0; + else if (baudrate == B50) + retval = 50; + else if (baudrate == B75) + retval = 75; + else if (baudrate == B110) + retval = 110; + else if (baudrate == B134) + retval = 134; + else if (baudrate == B150) + retval = 150; + else if (baudrate == B200) + retval = 200; + else if (baudrate == B300) + retval = 300; + else if (baudrate == B600) + retval = 600; + else if (baudrate == B1200) + retval = 1200; + else if (baudrate == B1800) + retval = 1800; + else if (baudrate == B2400) + retval = 2400; + else if (baudrate == B4800) + retval = 4800; + else if (baudrate == B9600) + retval = 9600; + else if (baudrate == B19200) + retval = 19200; + else if (baudrate == B38400) + retval = 38400; + else if (baudrate == B57600) + retval = 57600; + else if (baudrate == B115200) + retval = 115200; + else if (baudrate == B230400) + retval = 230400; + + return retval; + +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,125 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_bytesize", "instrument-control.oct"); +DEFUN_DLD (srl_bytesize, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} srl_bytesize (@var{serial}, @var{bsize})\n \ +@deftypefnx {Loadable Function} {@var{bs} = } srl_bytesize (@var{serial})\n \ +\n\ +Set new or get existing serial interface byte size parameter.\n \ +\n\ +@var{serial} - instance of @var{octave_serial} class.@*\ +@var{bsize} - byte size of type Integer. Supported values: 5/6/7/8.\n \ +\n\ +If @var{bsize} parameter is omitted, the srl_bytesize() shall return current byte size value or in case of unsupported setting -1, as the result @var{bs}.\n \ +@end deftypefn") +{ + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + // Setting new byte size + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + print_usage(); + return octave_value(-1); + } + + serial->set_bytesize(args(1).int_value()); + + return octave_value(); + } + + // Returning current byte size + return octave_value(serial->get_bytesize()); +} + +int octave_serial::set_bytesize(unsigned short bytesize) +{ + tcflag_t c_bytesize = 0; + + switch (bytesize) + { + case 5: c_bytesize = CS5; break; + case 6: c_bytesize = CS6; break; + case 7: c_bytesize = CS7; break; + case 8: c_bytesize = CS8; break; + + default: + error("srl_bytesize: expecting value between [5..8]..."); + return false; + } + + // Clear bitmask CSIZE + BITMASK_CLEAR(this->config.c_cflag, CSIZE); + + // Apply new + BITMASK_SET(this->config.c_cflag, c_bytesize); + + if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { + error("srl_bytesize: error setting byte size: %s\n", strerror(errno)); + return false; + } + + return true; +} + +int octave_serial::get_bytesize() +{ + int retval = -1; + + if (BITMASK_CHECK(this->config.c_cflag, CS5)) + retval = 5; + else if (BITMASK_CHECK(this->config.c_cflag, CS6)) + retval = 6; + else if (BITMASK_CHECK(this->config.c_cflag, CS7)) + retval = 7; + else if (BITMASK_CHECK(this->config.c_cflag, CS8)) + retval = 8; + + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,67 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_close", "instrument-control.oct"); +DEFUN_DLD (srl_close, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} srl_close (@var{serial})\n \ +\n\ +Close the interface and release a file descriptor.\n \ +\n\ +@var{serial} - instance of @var{octave_serial} class.@*\ +@end deftypefn") +{ + if (args.length() != 1 || args(0).type_id() != octave_serial::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->close(); + + return octave_value(); +} + +int octave_serial::close() +{ + int retval = ::close(this->get_fd()); + this->fd = -1; + return retval; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,100 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_flush", "instrument-control.oct"); +DEFUN_DLD (srl_flush, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} srl_flush (@var{serial}, [@var{q}])\n \ +\n\ +Flush the pending input/output.\n \ +\n\ +@var{serial} - instance of @var{octave_serial} class.@*\ +@var{q} - queue selector of type Integer. Supported values: 0 - flush untransmitted output, \ +1 - flush pending input, 2 - flush both pending input and untransmitted output.\n \ +\n\ +If @var{q} parameter is omitted, the srl_flush() shall flush both, input and output buffers.\n \ +@end deftypefn") +{ + int queue_selector = 2; // Input and Output + + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + if (args.length() > 1) + { + if (!(args(1).is_integer_type() || args(1).is_float_type())) + { + print_usage(); + return octave_value(-1); + } + + queue_selector = args(1).int_value(); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->flush(queue_selector); + + return octave_value(); +} + +int octave_serial::flush(unsigned short queue_selector) +{ + /* + * TCIOFLUSH Flush both pending input and untransmitted output. + * TCOFLUSH Flush untransmitted output. + * TCIFLUSH Flush pending input. + */ + + int flag; + + switch (queue_selector) + { + case 0: flag = TCOFLUSH; break; + case 1: flag = TCIFLUSH; break; + case 2: flag = TCIOFLUSH; break; + default: + error("srl_flush: only [0..2] values are accepted..."); + return false; + } + + return ::tcflush(this->get_fd(), flag); +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,136 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, see <http://www.gnu.org/licenses/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_parity", "instrument-control.oct"); +DEFUN_DLD (srl_parity, args, nargout, +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} srl_parity (@var{serial}, @var{parity})\n \ +@deftypefnx {Loadable Function} {@var{p} = } srl_parity (@var{serial})\n \ +\n\ +Set new or get existing serial interface parity parameter. Even/Odd/None values are supported.\n \ +\n\ +@var{serial} - instance of @var{octave_serial} class.@*\ +@var{parity} - parity value of type String. Supported values: Even/Odd/None (case insensitive, can be abbreviated to the first letter only).\n \ +\n\ +If @var{parity} parameter is omitted, the srl_parity() shall return current parity value as the result @var{p}.\n \ +@end deftypefn") +{ + if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) + { + print_usage(); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + // Setting new parity + if (args.length() > 1) + { + if ( !(args(1).is_string()) ) + { + print_usage(); + return octave_value(-1); + } + + serial->set_parity(args(1).string_value()); + + return octave_value(); + } + + // Returning current parity + return octave_value(serial->get_parity()); +} + +int octave_serial::set_parity(string parity) +{ + // Convert string to lowercase + std::transform(parity.begin(), parity.end(), parity.begin(), ::tolower); + + /* + * PARENB Enable parity generation on output and parity checking for input. + * PARODD If set, then parity for input and output is odd; otherwise even parity is used. + */ + + if (parity == "n" || parity == "none") + { + // Disable parity generation/checking + BITMASK_CLEAR(this->config.c_cflag, PARENB); + } + else if (parity == "e" || parity == "even") + { + // Enable parity generation/checking + BITMASK_SET(this->config.c_cflag, PARENB); + + // Set to Even + BITMASK_CLEAR(this->config.c_cflag, PARODD); + + } + else if (parity == "o" || parity == "odd") + { + // Enable parity generation/checking + BITMASK_SET(this->config.c_cflag, PARENB); + + // Set to Odd + BITMASK_SET(this->config.c_cflag, PARODD); + + } + else + { + error("srl_parity: Only [N]one, [E]ven or [O]dd parities are supported..."); + return false; + } + + if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { + error("srl_parity: error setting parity: %s\n", strerror(errno)); + return false; + } + + return true; +} + +string octave_serial::get_parity() +{ + if (!BITMASK_CHECK(this->config.c_cflag, PARENB)) + return "None"; + else if (BITMASK_CHECK(this->config.c_cflag, PARODD)) + return "Odd"; + else + return "Even"; +} \ No newline at end of file Added: trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc (rev 0) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc 2012-09-02 22:39:41 UTC (rev 10954) @@ -0,0 +1,110 @@ +// Copyright (C) 2012 Andrius Sutas <and...@gm...> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this progra... [truncated message content] |
From: <jpi...@us...> - 2012-09-18 15:23:32
|
Revision: 11047 http://octave.svn.sourceforge.net/octave/?rev=11047&view=rev Author: jpicarbajal Date: 2012-09-18 15:23:21 +0000 (Tue, 18 Sep 2012) Log Message: ----------- statistics: fixing notation in docstring of linkage. Still improvements needed. Modified Paths: -------------- trunk/octave-forge/main/mechanics/DESCRIPTION trunk/octave-forge/main/mechanics/inst/core/forcematrix.m trunk/octave-forge/main/statistics/inst/linkage.m Modified: trunk/octave-forge/main/mechanics/DESCRIPTION =================================================================== --- trunk/octave-forge/main/mechanics/DESCRIPTION 2012-09-18 06:25:30 UTC (rev 11046) +++ trunk/octave-forge/main/mechanics/DESCRIPTION 2012-09-18 15:23:21 UTC (rev 11047) @@ -1,6 +1,6 @@ Name: Mechanics -Version: 1.3.0 -Date: 2012-24-08 +Version: 1.3.1 +Date: 2012-29-08 Author: Juan Pablo Carbajal <car...@if...>, Johan Beke <joh...@ho...> Maintainer: Juan Pablo Carbajal <car...@if...>, Johan Beke <joh...@ho...> Title: Classical Mechanics & Structural Analysis Modified: trunk/octave-forge/main/mechanics/inst/core/forcematrix.m =================================================================== --- trunk/octave-forge/main/mechanics/inst/core/forcematrix.m 2012-09-18 06:25:30 UTC (rev 11046) +++ trunk/octave-forge/main/mechanics/inst/core/forcematrix.m 2012-09-18 15:23:21 UTC (rev 11047) @@ -51,12 +51,13 @@ %% distances between the points. %% @end itemize %% -%% @html -%% @include doc/matrixforce.svg -%% @end html %% @seealso{pointmassmesh, polyval, vech, sub2ind} %% @end deftypefn +%% @html +%% @include ../doc/matrixforce.svg +%% @end html + function [F D dr] = forcematrix (pos, A, funcs) %% Argument parsing Modified: trunk/octave-forge/main/statistics/inst/linkage.m =================================================================== --- trunk/octave-forge/main/statistics/inst/linkage.m 2012-09-18 06:25:30 UTC (rev 11046) +++ trunk/octave-forge/main/statistics/inst/linkage.m 2012-09-18 15:23:21 UTC (rev 11047) @@ -23,7 +23,7 @@ ## ## Produce a hierarchical clustering dendrogram ## -## @var{d} is the dissimilarity matrix relative to @var{n} observations, +## @var{d} is the dissimilarity matrix relative to n observations, ## formatted as a @math{(n-1)*n/2}x1 vector as produced by @code{pdist}. ## Alternatively, @var{x} contains data formatted for input to ## @code{pdist}, @var{metric} is a metric for @code{pdist} and @@ -31,11 +31,11 @@ ## @code{pdist}. ## ## @code{linkage} starts by putting each observation into a singleton -## cluster and numbering those from 1 to @var{n}. Then it merges two +## cluster and numbering those from 1 to n. Then it merges two ## clusters, chosen according to @var{method}, to create a new cluster -## numbered @var{n+1}, and so on until all observations are grouped into -## a single cluster numbered @var{2*n-1}. Row @var{m} of the -## @math{m-1}x3 output matrix relates to cluster @math{n+m}: the first +## numbered n+1, and so on until all observations are grouped into +## a single cluster numbered 2*n-1. Row m of the +## (m-1)x3 output matrix relates to cluster n+m: the first ## two columns are the numbers of the two component clusters and column ## 3 contains their distance. ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jgp...@us...> - 2012-10-01 09:15:30
|
Revision: 11093 http://octave.svn.sourceforge.net/octave/?rev=11093&view=rev Author: jgpallero Date: 2012-10-01 09:15:16 +0000 (Mon, 01 Oct 2012) Log Message: ----------- Update OctCLIP to version 1.0.2 and OctPROJ to version 1.1.1 Modified Paths: -------------- trunk/octave-forge/main/octclip/ChangeLog trunk/octave-forge/main/octclip/DESCRIPTION trunk/octave-forge/main/octclip/doc/octclip.pdf trunk/octave-forge/main/octclip/doc/octclip.tex trunk/octave-forge/main/octclip/inst/oc_polybool.m trunk/octave-forge/main/octclip/src/Makefile trunk/octave-forge/main/octclip/src/_oc_polybool.cc trunk/octave-forge/main/octclip/src/compilador.c trunk/octave-forge/main/octclip/src/errores.c trunk/octave-forge/main/octclip/src/eucli.c trunk/octave-forge/main/octclip/src/fgeneral.c trunk/octave-forge/main/octclip/src/greiner.c trunk/octave-forge/main/octclip/src/libgeoc/compilador.h trunk/octave-forge/main/octclip/src/libgeoc/constantes.h trunk/octave-forge/main/octclip/src/libgeoc/errores.h trunk/octave-forge/main/octclip/src/libgeoc/eucli.h trunk/octave-forge/main/octclip/src/libgeoc/fgeneral.h trunk/octave-forge/main/octclip/src/libgeoc/general.h trunk/octave-forge/main/octclip/src/libgeoc/geom.h trunk/octave-forge/main/octclip/src/libgeoc/greiner.h trunk/octave-forge/main/octclip/src/libgeoc/polig.h trunk/octave-forge/main/octclip/src/libgeoc/ptopol.h trunk/octave-forge/main/octclip/src/libgeoc/segmento.h trunk/octave-forge/main/octclip/src/libgeoc/ventorno.h trunk/octave-forge/main/octclip/src/polig.c trunk/octave-forge/main/octclip/src/ptopol.c trunk/octave-forge/main/octclip/src/segmento.c trunk/octave-forge/main/octclip/src/ventorno.c trunk/octave-forge/main/octproj/ChangeLog trunk/octave-forge/main/octproj/DESCRIPTION trunk/octave-forge/main/octproj/doc/octproj.pdf trunk/octave-forge/main/octproj/doc/octproj.tex trunk/octave-forge/main/octproj/src/Makefile Added Paths: ----------- trunk/octave-forge/main/octclip/src/calctopo.c trunk/octave-forge/main/octclip/src/dpeucker.c trunk/octave-forge/main/octclip/src/geocnan.c trunk/octave-forge/main/octclip/src/geocomp.c trunk/octave-forge/main/octclip/src/libgeoc/calctopo.h trunk/octave-forge/main/octclip/src/libgeoc/dpeucker.h trunk/octave-forge/main/octclip/src/libgeoc/geocnan.h trunk/octave-forge/main/octclip/src/libgeoc/geocomp.h trunk/octave-forge/main/octclip/src/libgeoc/polil.h trunk/octave-forge/main/octclip/src/libgeoc/recpolil.h trunk/octave-forge/main/octclip/src/polil.c trunk/octave-forge/main/octclip/src/recpolil.c Modified: trunk/octave-forge/main/octclip/ChangeLog =================================================================== --- trunk/octave-forge/main/octclip/ChangeLog 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/ChangeLog 2012-10-01 09:15:16 UTC (rev 11093) @@ -1,8 +1,93 @@ +2012-10-01 José Luis García Pallero <jgp...@gm...> + + * DESCRIPTION: + Update version number and date in DESCRIPTION file + [f06e99c0b026] [tip] + + * .hgtags: + Version 1.0.2 + [a38b95e66500] + + * doc/octclip.pdf, doc/octclip.tex: + Update documentation + [2310bc775bea] [OctCLIP-1.0.2] + +2012-09-30 José Luis García Pallero <jgp...@gm...> + + * inst/oc_polybool.m, src/_oc_polybool.cc: + Fix function help text + [ca8c9ba38288] + + * src/Makefile: + Supression of compiler flag not common to all archs + [e5d734f4c6d0] + +2012-04-17 José Luis García Pallero <jgp...@gm...> + + * src/Makefile: + Changes in src/Makefile in ordert to pass warning and optimisation + flags to mkoctfile + [ec407713d9ac] + + * .hgignore: + Update .hgignore file in mercurial repo + [e493dfb8efb7] + +2012-04-13 José Luis García Pallero <jgp...@gm...> + + * doc/octclip.pdf, doc/octclip.tex: + Change author's affiliation and dates in the reference manual + [6292fc806330] + +2011-11-21 José Luis García Pallero <jgp...@gm...> + + * .hgtags: + Version 1.0.1 + [c77ff2bf09d4] + + * DESCRIPTION: + Change version number and date + [406c40e732a5] [OctCLIP-1.0.1] + + * src/_oc_polybool.cc: + Minor changes due to changes in the Greiner-Hormann API + [ecd2084e9cea] + + * src/Makefile: + Update Makefile with the new files + [9c07e48ee665] + + * src/calctopo.c, src/compilador.c, src/dpeucker.c, src/errores.c, + src/eucli.c, src/fgeneral.c, src/geocnan.c, src/geocomp.c, + src/greiner.c, src/libgeoc/calctopo.h, src/libgeoc/compilador.h, + src/libgeoc/constantes.h, src/libgeoc/dpeucker.h, + src/libgeoc/errores.h, src/libgeoc/eucli.h, src/libgeoc/fgeneral.h, + src/libgeoc/general.h, src/libgeoc/geocnan.h, src/libgeoc/geocomp.h, + src/libgeoc/geom.h, src/libgeoc/greiner.h, src/libgeoc/polig.h, + src/libgeoc/polil.h, src/libgeoc/ptopol.h, src/libgeoc/recpolil.h, + src/libgeoc/segmento.h, src/libgeoc/ventorno.h, src/polig.c, + src/polil.c, src/ptopol.c, src/recpolil.c, src/segmento.c, + src/ventorno.c: + Add changes and new files fron the original source of my Greiner- + Hormann implementation. OctCLIP code comes from a personal library + not yet published + [fccf93621aa8] + +2011-06-12 José Luis García Pallero <jgp...@gm...> + + * doc/octclip.pdf, doc/octclip.tex: + LaTeX documentation update + [9c92a3d8fd20] + 2011-06-07 José Luis García Pallero <jgp...@gm...> + * inst/oc_polybool.m: + Fix documentation + [f970d69207fd] + * INDEX: Remove test_octclip from 'INDEX' file - [5e2dd1fd23fc] [tip] + [5e2dd1fd23fc] * inst/oc_polybool.m: Add the content of old 'test_octclip.m' program into 'oc_polybool.m' Modified: trunk/octave-forge/main/octclip/DESCRIPTION =================================================================== --- trunk/octave-forge/main/octclip/DESCRIPTION 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/DESCRIPTION 2012-10-01 09:15:16 UTC (rev 11093) @@ -1,8 +1,8 @@ Name: OctCLIP -Version: 1.0.0 -Date: 2011-03-01 -Author: José Luis García Pallero <jgp...@gm...> -Maintainer: José Luis García Pallero <jgp...@gm...> +Version: 1.0.2 +Date: 2012-10-01 +Author: José Luis García Pallero, <jgp...@gm...> +Maintainer: José Luis García Pallero, <jgp...@gm...> Title: GNU Octave clipping polygons tool Description: This package allows to do boolean operations with polygons using the Greiner-Hormann algorithm. Modified: trunk/octave-forge/main/octclip/doc/octclip.pdf =================================================================== (Binary files differ) Modified: trunk/octave-forge/main/octclip/doc/octclip.tex =================================================================== --- trunk/octave-forge/main/octclip/doc/octclip.tex 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/doc/octclip.tex 2012-10-01 09:15:16 UTC (rev 11093) @@ -9,10 +9,12 @@ \title{Clipping polygons from \octave\footnote{This document is distributed under the terms of the GNU Free Documentation License. Please, see \url{http://www.gnu.org/licenses/}}} -\author{Jos\'e Luis Garc\'ia Pallero\footnote{Instituto de Astronom\'ia y - Geodesia, Fac. de CC Matem\'aticas, Universidad Complutense de Madrid. - \texttt{jlg...@pd...}, \texttt{jgp...@gm...}}} -\date{\today} +\author{Jos\'e Luis Garc\'ia Pallero\footnote{ETSI en Topograf\'ia, Geodesia y + Cartograf\'ia, Universidad Polit\'ecnica de Madrid. + \texttt{jlg...@up...}, \texttt{jgp...@gm...}}} +\date{October 1, 2012 (version 1.0.2)\\ + November 21, 2011 (version 1.0.1)\\ + May 24, 2011 (version 1.0.0)} \begin{document} \maketitle @@ -32,22 +34,22 @@ \section{Overview} The \octclip{} package allows you to perform boolean operations (intersection, -union and difference) between two polygons in \octave{} using the +union, difference and exclusive or) between two polygons in \octave{} using the Greiner-Hormann algorithm\footnote{\cite{greiner1998} and \url{http://davis.wpi.edu/~matt/courses/clipping/}}. Greiner-Hormann is an efficient algorithm for clipping arbitrary 2D polygons. -The algorithm can handle arbitrary closed polygons, specifically where the +The algorithm can handle arbitrary closed polygons, specifically where the subject and clip polygons may self-intersect. \section{Installation} -As several \octave{} packages, \octclip{} installation consists in compiling the +As most of \octave{} packages, \octclip{} installation consists in compiling the C++ kernel sources, link them against \octave{} library to generate \texttt{*.oct} functions and copy this \texttt{*.oct} executables and other \texttt{*.m} functions into a working directory. -The automatic procedure can be easily done by running the command: +The automagic procedure can be easily done by running the command: \begin{verbatim} octave:1> pkg install octclip-x.x.x.tar.gz @@ -71,7 +73,7 @@ The function is: \begin{itemize} -\item \texttt{\_oc\_polybool}: boolean operation between two polygons. +\item \texttt{\_oc\_polybool}: Performs boolean operation between two polygons. \end{itemize} \subsection{\texttt{*.m} function} @@ -83,21 +85,21 @@ The function is the same as in section \ref{op-of} (without the \texttt{\_} at the beginning of the name): \begin{itemize} -\item \texttt{oc\_polybool}: calls \texttt{\_oc\_polybool}. +\item \texttt{oc\_polybool}: Performs boolean operation between two polygons + by calling the \texttt{\_oc\_polybool}. \end{itemize} -A test script for the package exists too: +\texttt{oc\_polybool} includes too some demonstration code in order to test the +functionality of the functions. The demo code can be executed as: +\begin{verbatim} +octave:1> demo oc_polybool +\end{verbatim} -\begin{itemize} -\item \texttt{test\_octclip}: plots an example of the \texttt{oc\_polybool} - usage. -\end{itemize} - \subsection{Error handling} -\texttt{*.oct} and \texttt{*.m} functions can emit errors, some due to errors in -input arguments and other due to errors in functions from the C\footnote{The -algorithm is internally implemented in C (C99 standard).} code. +\texttt{*.oct} and \texttt{*.m} functions can emit errors, some due to errors +with input arguments and other due to errors in functions from the +C\footnote{The algorithm is internally implemented in C (C99 standard).} code. Errors due to wrong input arguments (data types, dimensions, etc.) can be only given for \texttt{*.m} function and this is the reason because the use of this @@ -108,7 +110,7 @@ arguments, wrong value of the operation identifier and internal errors of memory allocation. -\section{Caveats} +\section{Caveats of Greiner-Hormann algorithm} To do. @@ -116,6 +118,12 @@ To do. +\section{Notes} + +Apart from \url{http://octave.sourceforge.net/octclip/index.html}, an up to date +version of \octclip{} can be downloaded from +\url{https://bitbucket.org/jgpallero/octclip/}. + % \subsection{Geodetic to geocentric and vice versa} % % \begin{verbatim} Modified: trunk/octave-forge/main/octclip/inst/oc_polybool.m =================================================================== --- trunk/octave-forge/main/octclip/inst/oc_polybool.m 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/inst/oc_polybool.m 2012-10-01 09:15:16 UTC (rev 11093) @@ -17,8 +17,8 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}_oc_polybool(@var{sub},@var{clip},@var{op}) -## @deftypefnx{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}_oc_polybool(@var{sub},@var{clip}) +## @deftypefn{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}oc_polybool(@var{sub},@var{clip},@var{op}) +## @deftypefnx{Function File}{[@var{X},@var{Y},@var{nPol},@var{nInt},@var{nPert}] =}oc_polybool(@var{sub},@var{clip}) ## ## This function performs boolean operations between two polygons using the ## Greiner-Hormann algorithm (http://davis.wpi.edu/~matt/courses/clipping/). @@ -47,11 +47,11 @@ ## be repeated at the end (but is permitted). Pairs of (NaN,NaN) coordinates in ## @var{sub} and/or @var{clip} are ommitted. ## -## @var{X} is a column vector containing the X coordinates of the vertices for. -## resultant polygon(s). +## @var{X} is a column vector containing the X coordinates of the vertices of +## the resultant polygon(s). ## -## @var{Y} is a column vector containing the Y coordinates of the vertices for. -## resultant polygon(s). +## @var{Y} is a column vector containing the Y coordinates of the vertices of +## the resultant polygon(s). ## ## @var{nPol} is the number of output polygons. ## Modified: trunk/octave-forge/main/octclip/src/Makefile =================================================================== --- trunk/octave-forge/main/octclip/src/Makefile 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/Makefile 2012-10-01 09:15:16 UTC (rev 11093) @@ -1,22 +1,44 @@ # -*- coding: utf-8 -*- +#Compiler CC=mkoctfile +#Common warning flags for C and C++ +FLAGSCOMW=-Wall -Wextra -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings +#Common optimization flags for C and C++ +FLAGSCOMO=-O2 -funroll-loops -fno-common -fshort-enums +#Flags for C +CFLAGS=-std=c99 -pedantic $(FLAGSCOMW) -Wconversion -Wmissing-prototypes +CFLAGS+=-Wstrict-prototypes -Wnested-externs $(FLAGSCOMO) +#Flags for C++ +CXXFLAGS=$(FLAGSCOMW) $(FLAGSCOMO) +#Export flags for compilers and linker +export CFLAGS CXXFLAGS .PHONY: all all: compile clean .PHONY: compile compile: - $(CC) -c -Wall -Wextra -I. compilador.c -o compilador.o - $(CC) -c -Wall -Wextra -I. errores.c -o errores.o - $(CC) -c -Wall -Wextra -I. eucli.c -o eucli.o - $(CC) -c -Wall -Wextra -I. fgeneral.c -o fgeneral.o - $(CC) -c -Wall -Wextra -I. greiner.c -o greiner.o - $(CC) -c -Wall -Wextra -I. polig.c -o polig.o - $(CC) -c -Wall -Wextra -I. ptopol.c -o ptopol.o - $(CC) -c -Wall -Wextra -I. segmento.c -o segmento.o - $(CC) -c -Wall -Wextra -I. ventorno.c -o ventorno.o - $(CC) -s -Wall -Wextra -I. _oc_polybool.cc *.o + $(CC) -c -I. calctopo.c -o calctopo.o + $(CC) -c -I. compilador.c -o compilador.o + $(CC) -c -I. dpeucker.c -o dpeucker.o + $(CC) -c -I. errores.c -o errores.o + $(CC) -c -I. eucli.c -o eucli.o + $(CC) -c -I. fgeneral.c -o fgeneral.o + $(CC) -c -I. geocnan.c -o geocnan.o + $(CC) -c -I. geocomp.c -o geocomp.o + $(CC) -c -I. greiner.c -o greiner.o + $(CC) -c -I. polig.c -o polig.o + $(CC) -c -I. polil.c -o polil.o + $(CC) -c -I. ptopol.c -o ptopol.o + $(CC) -c -I. recpolil.c -o recpolil.o + $(CC) -c -I. segmento.c -o segmento.o + $(CC) -c -I. ventorno.c -o ventorno.o + $(CC) -s -I. _oc_polybool.cc *.o .PHONY: clean clean: rm -rf *.o *~ + +.PHONY: cleanall +cleanall: + rm -rf *~ *.o *.oct Modified: trunk/octave-forge/main/octclip/src/_oc_polybool.cc =================================================================== --- trunk/octave-forge/main/octclip/src/_oc_polybool.cc 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/_oc_polybool.cc 2012-10-01 09:15:16 UTC (rev 11093) @@ -51,10 +51,10 @@ be repeated at the end (but is permitted). Pairs of (NaN,NaN) coordinates in\n\ @var{sub} and/or @var{clip} are ommitted.\n\ \n\ -@var{X} is a column vector containing the X coordinates of the vertices for.\n\ -resultant polygon(s).\n\n\ -@var{Y} is a column vector containing the Y coordinates of the vertices for.\n\ -resultant polygon(s).\n\n\ +@var{X} is a column vector containing the X coordinates of the vertices of\n\ +the resultant polygon(s).\n\n\ +@var{Y} is a column vector containing the Y coordinates of the vertices of\n\ +the resultant polygon(s).\n\n\ @var{nPol} is the number of output polygons.\n\n\ @var{nInt} is the number of intersections between @var{sub} and @var{clip}.\n\n\ @var{nPert} is the number of perturbed points of the @var{clip} polygon in\n\ @@ -117,7 +117,7 @@ //operation identifier enum GEOC_OP_BOOL_POLIG op=GeocOpBoolInter; //output struct - poligGreiner* result=NULL; + polig* result=NULL; //number of polygons, intersections and perturbations size_t nPol=0,nInter=0,nPert=0; //number of elements for the output vectors @@ -231,7 +231,7 @@ //free memory LibMemPoliClip(polA); LibMemPoliClip(polB); - LibMemPoligGreiner(result); + LibMemPolig(result); } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// Added: trunk/octave-forge/main/octclip/src/calctopo.c =================================================================== --- trunk/octave-forge/main/octclip/src/calctopo.c (rev 0) +++ trunk/octave-forge/main/octclip/src/calctopo.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -0,0 +1,71 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup geodesia geom +@{ +\file calctopo.c +\brief Definición de funciones para cálculos de topografía. +\author José Luis García Pallero, jgp...@gm... +\date 05 de julio de 2011 +\section Licencia Licencia +Copyright (c) 2011, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/calctopo.h" +/******************************************************************************/ +/******************************************************************************/ +double AcimutTopografico(const double x1, + const double y1, + const double x2, + const double y2) +{ + //acimut calculado + double acimut=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos el acimut en el dominio [-pi pi] + acimut = atan2(x2-x1,y2-y1); + //comprobamos si ha salido un valor negativo + if(acimut<0.0) + { + //metemos el valor en dominio + acimut += 2.0*GEOC_CONST_PI; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return acimut; +} +/******************************************************************************/ +/******************************************************************************/ +/** @} */ +/******************************************************************************/ +/******************************************************************************/ +/* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */ +/* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */ +/* kate: line-numbers on; folding-markers on; remove-trailing-space on; */ +/* kate: backspace-indents on; show-tabs on; */ +/* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */ Modified: trunk/octave-forge/main/octclip/src/compilador.c =================================================================== --- trunk/octave-forge/main/octclip/src/compilador.c 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/compilador.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -73,3 +73,10 @@ /******************************************************************************/ /******************************************************************************/ /** @} */ +/******************************************************************************/ +/******************************************************************************/ +/* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */ +/* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */ +/* kate: line-numbers on; folding-markers on; remove-trailing-space on; */ +/* kate: backspace-indents on; show-tabs on; */ +/* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */ Added: trunk/octave-forge/main/octclip/src/dpeucker.c =================================================================== --- trunk/octave-forge/main/octclip/src/dpeucker.c (rev 0) +++ trunk/octave-forge/main/octclip/src/dpeucker.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -0,0 +1,472 @@ +/* -*- coding: utf-8 -*- */ +/** +\ingroup geom +@{ +\file dpeucker.c +\brief Definición de funciones para el aligerado de polilíneas basadas en el + algoritmo de Douglas-Peucker. +\author José Luis García Pallero, jgp...@gm... +\date 04 de julio de 2011 +\section Licencia Licencia +Copyright (c) 2011, José Luis García Pallero. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name of the copyright holders nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/******************************************************************************/ +/******************************************************************************/ +#include"libgeoc/dpeucker.h" +/******************************************************************************/ +/******************************************************************************/ +size_t* AligeraPolilinea(const double* x, + const double* y, + const size_t nPtos, + const size_t incX, + const size_t incY, + const double tol, + const enum GEOC_DPEUCKER_ROBUSTO robusto, + const size_t nPtosRobusto, + const size_t nSegRobusto, + size_t* nPtosSal) +{ + //índice para recorrer bucles + size_t p=0; + //índice de los puntos de trabajo + size_t i=0,j=0,k=0; + //coordenadas de trabajo + double xIni=0.0,yIni=0.0,xFin=0.0,yFin=0.0,xTrab=0.0,yTrab=0.0; + //altura del triángulo de trabajo + double h=0.0; + //variable indicadora de punto a mantener + int usado=0; + //número de elementos de trabajo internos del vector de salida + size_t nElem=0; + //vector de salida + size_t* sal=NULL; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //iniciamos la variable de salida de número de puntos a 0 + *nPtosSal = 0; + //comprobamos casos especiales de nPtos + if(nPtos==0) + { + //salimos de la función con NULL + return NULL; + } + else if(nPtos<=2) + { + //asignamos el número de puntos usados + *nPtosSal = nPtos; + //asignamos memoria para el vector de salida + sal = (size_t*)malloc((*nPtosSal)*sizeof(size_t)); + //comprobamos los posibles errores + if(sal==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + //asignamos valores al vector de salida + for(i=0;i<(*nPtosSal);i++) + { + //asignamos el índice de trabajo + sal[i] = i; + } + //salimos de la función + return sal; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //inicializamos el indicador interno de tamaño del vector + nElem = GEOC_DPEUCKER_BUFFER_PTOS; + //asignamos memoria para el vector de salida + sal = (size_t*)malloc(nElem*sizeof(size_t)); + //comprobamos los posibles errores + if(sal==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + //indicamos que el primer punto siempre se usa + *nPtosSal = 1; + sal[0] = 0; + //puntos de trabajo para iniciar los cálculos + i = 0; + j = 1; + k = 2; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //entramos en un bucle infinito + while(1) + { + //comprobamos si hay que salir del bucle + if(k>(nPtos-1)) + { + //salimos del bucle + break; + } + //coordenadas de la base del triángulo + xIni = x[i*incX]; + yIni = y[i*incY]; + xFin = x[k*incX]; + yFin = y[k*incY]; + //inicializamos a 0 la variable de punto usado + usado = 0; + //recorremos los puntos a testear + for(p=j;p<k;p++) + { + //coordenadas del vértice del triángulo + xTrab = x[p*incX]; + yTrab = y[p*incY]; + //calculamos la altura del triángulo + h = AlturaTriangulo(xTrab,yTrab,xIni,yIni,xFin,yFin); + //comprobamos si la altura supera a la tolerancia + if(h>tol) + { + //indicamos que el punto ha sido usado + usado = 1; + //comprobamos si se utiliza el algoritmo robusto + if(robusto!=GeocDPeuckerRobNo) + { + //comprobamos si hay que aplicar el algoritmo de + //intersección con puntos originales + if((robusto==GeocDPeuckerRobSi)|| + (robusto==GeocDPeuckerRobOrig)) + { + //aplicamos el algoritmo + AligPolilRobIntersecOrig(x,y,nPtos,incX,incY, + nPtosRobusto,i,&p); + } + //comprobamos si hay que aplicar el algoritmo de auto + //intersección + if((robusto==GeocDPeuckerRobSi)|| + (robusto==GeocDPeuckerRobAuto)) + { + //indicamos un número de puntos para el vector de salida + //una unidad menor que el número realmente almacenado + //para evitar el segmento inmediatamente anterior al que + //vamos a crear + AligPolilRobAutoIntersec(x,y,incX,incY,sal, + (*nPtosSal)-1,nSegRobusto,i, + &p); + } + } + //añadimos al contador este nuevo punto + (*nPtosSal)++; + //comprobamos si hay que reasignar memoria + if((*nPtosSal)>nElem) + { + //añadimos otro grupo de puntos + nElem += GEOC_DPEUCKER_BUFFER_PTOS; + //asignamos memoria para el vector de salida + sal = (size_t*)realloc(sal,nElem*sizeof(size_t)); + //comprobamos los posibles errores + if(sal==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + } + //añadimos el nuevo punto usado + sal[(*nPtosSal)-1] = p; + //actualizamos los índices de los puntos de trabajo + i = p; + j = i+1; + k = j+1; + //salimos del bucle + break; + } + } + //comprobamos si no se ha utilizado ninguno de los vértices candidatos + if(!usado) + { + //pasamos al siguiente punto como extremo del segmento + k++; + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //comprobamos si el último punto se ha añadido + if(sal[(*nPtosSal)-1]!=(nPtos-1)) + { + //añadimos al contador el último punto + (*nPtosSal)++; + //comprobamos si hay que reasignar memoria + if((*nPtosSal)>nElem) + { + //añadimos otro grupo de puntos + nElem += GEOC_DPEUCKER_BUFFER_PTOS; + //asignamos memoria para el vector de salida + sal = (size_t*)realloc(sal,nElem*sizeof(size_t)); + //comprobamos los posibles errores + if(sal==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + } + //asignamos el último punto + sal[(*nPtosSal)-1] = nPtos-1; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //comprobamos si el vector de salida tiene demasiada memoria asignada + if(nElem>(*nPtosSal)) + { + //ajustamos el tamaño del vector de salida + sal = (size_t*)realloc(sal,(*nPtosSal)*sizeof(size_t)); + //comprobamos los posibles errores + if(sal==NULL) + { + //mensaje de error + GEOC_ERROR("Error de asignación de memoria"); + //salimos de la función + return NULL; + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return sal; +} +/******************************************************************************/ +/******************************************************************************/ +void AligPolilRobIntersecOrig(const double* x, + const double* y, + const size_t nPtos, + const size_t incX, + const size_t incY, + const size_t ptosAUsar, + const size_t posIni, + size_t* posFin) +{ + //índices para recorrer bucles + size_t i=0,j=0; + //coordenadas de trabajo + double xA=0.0,yA=0.0,xB=0.0,yB=0.0,xC=0.0,yC=0.0,xD=0.0,yD=0.0; + //punto de parada para comprobar la intersección de segmentos + size_t parada=0; + //identificador de intersección + int inter=0; + //variables auxiliares + size_t aux=0; + double xAux=0.0,yAux=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //contemplamos una posible salida rápida + if((*posFin)<=(posIni+1)) + { + //salimos de la función + return; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos el número de puntos que quedan hasta el final de los vectores + //de coordenadas desde la posición de fin de segmento (contándola) + aux = nPtos-(*posFin); + //calculamos el punto de parada para la intersección de segmentos + if((aux>ptosAUsar)&&(ptosAUsar!=0)) + { + //paramos en un pnto tal que usemos ptosAUsar puntos + parada = *posFin+ptosAUsar-1; + } + else + { + //paramos en el penúltimo punto + parada = nPtos-2; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //las coordenadas del punto inicial del segmento base no cambian nunca + xA = x[posIni*incX]; + yA = y[posIni*incY]; + //recorremos los puntos candidatos hasta el anterior al punto base + for(i=(*posFin);i>posIni;i--) + { + //comprobamos si estamos ante el punto posterior al inicial + if(i==(posIni+1)) + { + //terminamos, porque este punto es el siguiente al punto base en el + //listado original + *posFin = i; + //salimos del bucle + break; + } + else + { + //coordenadas de los puntos inicial y final del segmento base + xB = x[i*incX]; + yB = y[i*incY]; + //recorremos los puntos posteriores hasta el de parada + for(j=i;j<=parada;j++) + { + //coordenadas de los puntos inicial y final del siguiente + //segmento + xC = x[j*incX]; + yC = y[j*incY]; + xD = x[(j+1)*incX]; + yD = y[(j+1)*incY]; + //calculamos la intersección entre los segmentos + inter = IntersecSegmentos2D(xA,yA,xB,yB,xC,yC,xD,yD,&xAux, + &yAux); + //comprobamos si hay intersección entre los segmentos + if(inter!=GEOC_SEG_NO_INTERSEC) + { + //salimos del bucle + break; + } + } + //comprobamos si no ha habido ninguna intersección + if(inter==GEOC_SEG_NO_INTERSEC) + { + //indicamos el índice del vértice final + *posFin = i; + //salimos del bucle + break; + } + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +void AligPolilRobAutoIntersec(const double* x, + const double* y, + const size_t incX, + const size_t incY, + const size_t* posAlig, + const size_t nPosAlig, + const size_t segAUsar, + const size_t posIni, + size_t* posFin) +{ + //índices para recorrer bucles + size_t i=0,j=0; + //variables de posición + size_t k=0,l=0,pos=0; + //coordenadas de trabajo + double xA=0.0,yA=0.0,xB=0.0,yB=0.0,xC=0.0,yC=0.0,xD=0.0,yD=0.0; + //número de segmentos calculados hasta ahora, excepto el último + size_t nSeg=0; + //identificador de intersección + int inter=0; + //variables auxiliares + double xAux=0.0,yAux=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //contemplamos una posible salida rápida + if(((*posFin)<=(posIni+1))||(nPosAlig<2)) + { + //salimos de la función + return; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos el número de segmentos calculados hasta ahora, excepto el + //anterior al de trabajo + nSeg = nPosAlig-1; + //comprobamos si se usan todos los segmentos o sólo parte + if(segAUsar!=0) + { + //asignamos el número de segmentos a utilizar + nSeg = (nSeg>segAUsar) ? segAUsar : nSeg; + } + //las coordenadas del punto inicial del segmento base no cambian nunca + xA = x[posIni*incX]; + yA = y[posIni*incY]; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //recorremos los puntos candidatos hasta el anterior al punto base + for(i=(*posFin);i>posIni;i--) + { + //comprobamos si estamos ante el punto posterior al inicial + if(i==(posIni+1)) + { + //terminamos, porque este punto es el siguiente al punto inicial + *posFin = i; + //salimos del bucle + break; + } + else + { + //coordenadas del punto final del segmento base + xB = x[i*incX]; + yB = y[i*incY]; + //recorremos el número de segmentos de trabajo + for(j=0;j<nSeg;j++) + { + //posición del punto inicial del siguiente segmento anterior + pos = nPosAlig-1-j; + //índices inicial y final del siguiente segmento anterior + k = posAlig[pos]; + l = posAlig[pos-1]; + //puntos inicial y final del siguiente segmento + xC = x[k*incX]; + yC = y[k*incY]; + xD = x[l*incX]; + yD = y[l*incY]; + //calculamos la intersección entre los segmentos + inter = IntersecSegmentos2D(xA,yA,xB,yB,xC,yC,xD,yD,&xAux, + &yAux); + //comprobamos si hay intersección entre los segmentos + if(inter!=GEOC_SEG_NO_INTERSEC) + { + //salimos del bucle + break; + } + } + //comprobamos si no ha habido ninguna intersección + if(inter==GEOC_SEG_NO_INTERSEC) + { + //indicamos el índice del vértice final + *posFin = i; + //salimos del bucle + break; + } + } + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return; +} +/******************************************************************************/ +/******************************************************************************/ +/** @} */ +/******************************************************************************/ +/******************************************************************************/ +/* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */ +/* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */ +/* kate: line-numbers on; folding-markers on; remove-trailing-space on; */ +/* kate: backspace-indents on; show-tabs on; */ +/* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */ Modified: trunk/octave-forge/main/octclip/src/errores.c =================================================================== --- trunk/octave-forge/main/octclip/src/errores.c 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/errores.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -110,3 +110,10 @@ /******************************************************************************/ /******************************************************************************/ /** @} */ +/******************************************************************************/ +/******************************************************************************/ +/* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */ +/* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */ +/* kate: line-numbers on; folding-markers on; remove-trailing-space on; */ +/* kate: backspace-indents on; show-tabs on; */ +/* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */ Modified: trunk/octave-forge/main/octclip/src/eucli.c =================================================================== --- trunk/octave-forge/main/octclip/src/eucli.c 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/eucli.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -8,7 +8,7 @@ \author José Luis García Pallero, jgp...@gm... \date 27 de octubre de 2009 \section Licencia Licencia -Copyright (c) 2009-2010, José Luis García Pallero. All rights reserved. +Copyright (c) 2009-2011, José Luis García Pallero. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -157,4 +157,82 @@ } /******************************************************************************/ /******************************************************************************/ +double AnguloVecPlano(const double x1, + const double y1, + const double x2, + const double y2) +{ + //variables auxiliares + double num=0.0,den=0.0; + //variable de salida + double alfa=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos el numerador de la fórmula que da el coseno del ángulo + num = x1*x2+y1*y2; + //calculamos el denominador de la fórmula que da el coseno del ángulo + den = sqrt((x1*x1+y1*y1)*(x2*x2+y2*y2)); + //calculamos el coseno del ángulo, teniendo en cuenta casos singulares + if(den==0.0) + { + //si el denominador es 0.0, el ángulo es 0.0 y su coseno 1.0 + alfa = 1.0; + } + else + { + //no hay singularidad + alfa = num/den; + } + //calculamos el ángulo + alfa = acos(alfa); + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return alfa; +} +/******************************************************************************/ +/******************************************************************************/ +double AlturaTriangulo(const double xVert, + const double yVert, + const double xBase1, + const double yBase1, + const double xBase2, + const double yBase2) +{ + //ángulo entra la base en el punto 1 y el vértice + double alfa=0.0; + //longitud del punto 1 de la base al vértice + double lon=0.0; + //variables auxiliares + double dxv=0.0,dyv=0.0,dxb=0.0,dyb=0.0; + //variable de salida + double h=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //calculamos los incrementos de coordenadas auxiliares + dxv = xVert-xBase1; + dyv = yVert-yBase1; + dxb = xBase2-xBase1; + dyb = yBase2-yBase1; + //calculamos el ángulo entre la base y el segmento que une el punto inicial + //de ésta con el vértice + alfa = AnguloVecPlano(dxv,dyv,dxb,dyb); + //longitud del lado que une la base con el vértice 1 de la base + lon = sqrt(dxv*dxv+dyv*dyv); + //calculamos la altura + h = fabs(lon*sin(alfa)); + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return h; +} +/******************************************************************************/ +/******************************************************************************/ /** @} */ +/******************************************************************************/ +/******************************************************************************/ +/* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */ +/* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */ +/* kate: line-numbers on; folding-markers on; remove-trailing-space on; */ +/* kate: backspace-indents on; show-tabs on; */ +/* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */ Modified: trunk/octave-forge/main/octclip/src/fgeneral.c =================================================================== --- trunk/octave-forge/main/octclip/src/fgeneral.c 2012-09-24 12:24:31 UTC (rev 11092) +++ trunk/octave-forge/main/octclip/src/fgeneral.c 2012-10-01 09:15:16 UTC (rev 11093) @@ -5,6 +5,7 @@ \file fgeneral.c \brief Definición de funciones de utilidad general. \author José Luis García Pallero, jgp...@gm... +\note Este fichero contiene funciones paralelizadas con OpenMP. \date 10 de octubre de 2009 \version 1.0 \section Licencia Licencia @@ -38,6 +39,65 @@ #include"libgeoc/fgeneral.h" /******************************************************************************/ /******************************************************************************/ +int GeocParOmpFgeneral(char version[]) +{ + //comprobamos si hay paralelización +#if defined(_OPENMP) + //comprobamos si hay que extraer versión + if(version!=NULL) + { + //calculamos la versión + VersionOpenMP(_OPENMP,version); + } + //salimos de la función + return 1; +#else + if(version!=NULL) + { + //utilizamos la variable version para que no dé warming al compilar + strcpy(version,""); + } + //salimos de la función + return 0; +#endif +} +/******************************************************************************/ +/******************************************************************************/ +double PonAnguloDominio(const double angulo) +{ + //signo del ángulo de trabajo + double signo=0.0; + //2.0*pi + double dosPi=2.0*GEOC_CONST_PI; + //variable auxiliar + double aux=angulo; + //variable de salida + double sal=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //sólo trabajamos si el valor de entrada está fuera de los límites + if((angulo<=-dosPi)||(angulo>=dosPi)) + { + //extraemos el signo del ángulo pasado + signo = GEOC_SIGNO(angulo); + //valor absoluto del ángulo pasado + aux = fabs(angulo); + //metemos el ángulo en dominio eliminando la cantidad que se pase de + //2.0*pi + sal = signo*(aux-floor(aux/dosPi)*dosPi); + } + else + { + //el valor de entrada no cambia + sal = angulo; + } + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return sal; +} +/******************************************************************************/ +/******************************************************************************/ void BuscaSegmento1DInc(const double valor, const double* lista, const size_t nDatos, @@ -171,7 +231,7 @@ //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //calculamos la fila y comprobamos si es el extremo S - *fil = f-1-(size_t)((yPto-yMin)/pasoY); + *fil = (size_t)(fabs(yPto-yMax)/pasoY); if(*fil==(f-1)) { //retrasamos una fila @@ -191,13 +251,250 @@ } /******************************************************************************/ /******************************************************************************/ +double Minimo(const double* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como el máximo valor para un double + double salida=DBL_MAX; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(min:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(min:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es menor que el considerado menor + if(lista[pos]<salida) + { + //asignamos el nuevo valor menor + salida = lista[pos]; + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +double Maximo(const double* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como el mínimo valor para un double + double salida=DBL_MIN; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(max:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(max:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es mayor que el considerado mayor + if(lista[pos]>salida) + { + //asignamos el nuevo valor menor + salida = lista[pos]; + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +double MinimoAbs(const double* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como el máximo valor para un double + double salida=DBL_MAX; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(min:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(min:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es menor que el considerado menor + if(fabs(lista[pos])<salida) + { + //asignamos el nuevo valor menor + salida = fabs(lista[pos]); + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +double MaximoAbs(const double* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como 0.0 (trabajamos en valor absoluto) + double salida=0.0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(max:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(max:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es mayor que el considerado mayor + if(fabs(lista[pos])>salida) + { + //asignamos el nuevo valor menor + salida = fabs(lista[pos]); + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +size_t MinimoSizeT(const size_t* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como el máximo valor para un size_t + size_t salida=SIZE_MAX; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(min:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(min:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es menor que el considerado menor + if(lista[pos]<salida) + { + //asignamos el nuevo valor menor + salida = lista[pos]; + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ +size_t MaximoSizeT(const size_t* lista, + const size_t nDatos, + const size_t incDatos) +{ + //índice para recorrer bucles + size_t i=0; + //variable de posición + size_t pos=0; + //variable de salida, inicializada como 0 (size_t es sólo positivo) + size_t salida=0; + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //paralelización con OpenMP, sólo si la versión es superior a la 3.0 + //en versiones anteriores no existe la posibilidad de usar reduction(max:) +#if defined(_OPENMP)&&(_OPENMP>=GEOC_OMP_F_3_1) +#pragma omp parallel for default(none) \ + shared(lista) \ + private(i,pos) \ + reduction(max:salida) +#endif + //recorremos el resto de elementos de la lista + for(i=0;i<nDatos;i++) + { + //posición del elemento a comprobar + pos = i*incDatos; + //comprobamos si el elemento actual es mayor que el considerado mayor + if(lista[pos]>salida) + { + //asignamos el nuevo valor menor + salida = lista[pos]; + } + } // --> fin del #pragma omp parallel for + //////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + //salimos de la función + return salida; +} +/******************************************************************************/ +/******************************************************************************/ void MinMax(const double* lista, const size_t nDatos, + const size_t incDatos, size_t* posMin, size_t* posMax) { //índice para recorrer bucles size_t i=0; + //variable de posición + size_t pos=0; //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //consideramos que el primer elemento es el mayor y el menor @@ -2... [truncated message content] |