This list is closed, nobody may subscribe to it.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(10) |
Aug
(5) |
Sep
(3) |
Oct
(41) |
Nov
(41) |
Dec
(33) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(75) |
Feb
(10) |
Mar
(170) |
Apr
(174) |
May
(66) |
Jun
(11) |
Jul
(10) |
Aug
(44) |
Sep
(73) |
Oct
(28) |
Nov
(139) |
Dec
(52) |
2003 |
Jan
(35) |
Feb
(93) |
Mar
(62) |
Apr
(10) |
May
(55) |
Jun
(70) |
Jul
(37) |
Aug
(16) |
Sep
(56) |
Oct
(31) |
Nov
(57) |
Dec
(83) |
2004 |
Jan
(85) |
Feb
(67) |
Mar
(27) |
Apr
(37) |
May
(75) |
Jun
(85) |
Jul
(160) |
Aug
(68) |
Sep
(104) |
Oct
(25) |
Nov
(39) |
Dec
(23) |
2005 |
Jan
(10) |
Feb
(45) |
Mar
(43) |
Apr
(19) |
May
(108) |
Jun
(31) |
Jul
(41) |
Aug
(23) |
Sep
(65) |
Oct
(58) |
Nov
(44) |
Dec
(54) |
2006 |
Jan
(96) |
Feb
(27) |
Mar
(69) |
Apr
(59) |
May
(67) |
Jun
(35) |
Jul
(13) |
Aug
(461) |
Sep
(160) |
Oct
(399) |
Nov
(32) |
Dec
(72) |
2007 |
Jan
(316) |
Feb
(305) |
Mar
(318) |
Apr
(54) |
May
(194) |
Jun
(173) |
Jul
(282) |
Aug
(91) |
Sep
(227) |
Oct
(365) |
Nov
(168) |
Dec
(18) |
2008 |
Jan
(71) |
Feb
(111) |
Mar
(155) |
Apr
(173) |
May
(70) |
Jun
(67) |
Jul
(55) |
Aug
(83) |
Sep
(32) |
Oct
(68) |
Nov
(80) |
Dec
(29) |
2009 |
Jan
(46) |
Feb
(18) |
Mar
(95) |
Apr
(76) |
May
(140) |
Jun
(98) |
Jul
(84) |
Aug
(123) |
Sep
(94) |
Oct
(131) |
Nov
(142) |
Dec
(125) |
2010 |
Jan
(128) |
Feb
(158) |
Mar
(172) |
Apr
(134) |
May
(94) |
Jun
(84) |
Jul
(32) |
Aug
(127) |
Sep
(167) |
Oct
(109) |
Nov
(69) |
Dec
(78) |
2011 |
Jan
(39) |
Feb
(58) |
Mar
(52) |
Apr
(47) |
May
(56) |
Jun
(76) |
Jul
(55) |
Aug
(54) |
Sep
(165) |
Oct
(255) |
Nov
(328) |
Dec
(263) |
2012 |
Jan
(82) |
Feb
(147) |
Mar
(400) |
Apr
(216) |
May
(209) |
Jun
(160) |
Jul
(86) |
Aug
(141) |
Sep
(156) |
Oct
(6) |
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(2) |
2016 |
Jan
|
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
(4) |
Jun
(8) |
Jul
(2) |
Aug
(5) |
Sep
(9) |
Oct
|
Nov
|
Dec
|
From: <prn...@us...> - 2012-06-08 16:39:20
|
Revision: 10598 http://octave.svn.sourceforge.net/octave/?rev=10598&view=rev Author: prnienhuis Date: 2012-06-08 16:39:09 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Texinfo header (odfdom version) Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odsread.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2012-06-08 16:33:58 UTC (rev 10597) +++ trunk/octave-forge/main/io/inst/odsopen.m 2012-06-08 16:39:09 UTC (rev 10598) @@ -24,7 +24,7 @@ ## Calling odsopen without specifying a return argument is fairly useless! ## ## To make this function work at all, you need the Java package >= 1.2.5 plus -## ODFtoolkit (version 0.7.5 or 0.8.6) & xercesImpl, and/or jOpenDocument, and/or +## ODFtoolkit (version 0.7.5 or 0.8.6+) & xercesImpl, and/or jOpenDocument, and/or ## OpenOffice.org (or clones) installed on your computer + proper javaclasspath ## set. These interfaces are referred to as OTK, JOD, and UNO resp., and are ## preferred in that order by default (depending on their presence). @@ -59,7 +59,7 @@ ## the jOpenDocument interface is requested) ## @end example ## -## @seealso {odsclose, odsread, ods2oct, odsfinfo, chk_spreadsheet_support} +## @seealso {odsclose, odsread, oct2ods, ods2oct, odsfinfo, chk_spreadsheet_support} ## ## @end deftypefn Modified: trunk/octave-forge/main/io/inst/odsread.m =================================================================== --- trunk/octave-forge/main/io/inst/odsread.m 2012-06-08 16:33:58 UTC (rev 10597) +++ trunk/octave-forge/main/io/inst/odsread.m 2012-06-08 16:39:09 UTC (rev 10598) @@ -24,7 +24,7 @@ ## ## You need the octave-forge java package (> 1.2.6) and one or both of ## jopendocument-<version>.jar or preferrably: (odfdom.jar (versions -## 0.7.5, 0.8.6 or 0.8.7) & xercesImpl.jar v. 2.9.1) in your javaclasspath. +## 0.7.5 or 0.8.6+) & xercesImpl.jar v. 2.9.1) in your javaclasspath. ## There is also experimental support invoking OpenOffice.org or clones ## through Java/UNO bridge. ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-08 16:34:04
|
Revision: 10597 http://octave.svn.sourceforge.net/octave/?rev=10597&view=rev Author: prnienhuis Date: 2012-06-08 16:33:58 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Texinfo help text updated (COM intf now also supports formulas_as_text) Modified Paths: -------------- trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2012-06-08 16:14:00 UTC (rev 10596) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2012-06-08 16:33:58 UTC (rev 10597) @@ -36,7 +36,7 @@ ## or "" (empty string, indicating all data in a worksheet). ## If no range is specified the occupied cell range will have to be ## determined behind the scenes first; this can take some time for the -## Java-based interfaces. Be aware that in Excel/ActiveX interface the +## Java-based interfaces. Be aware that in COM/ActiveX interface the ## used range can be outdated. The Java-based interfaces are more ## reliable in this respect albeit much slower. ## @@ -48,8 +48,7 @@ ## @item "formulas_as_text" ## If set to TRUE or 1, spreadsheet formulas (if at all present) ## are read as formula strings rather than the evaluated formula -## result values. This only works for the Java based interfaces -## POI, JXL and UNO. The default value is 0 (FALSE). +## result values. The default value is 0 (FALSE). ## ## @item 'strip_array' ## Set the value of this field set to TRUE or 1 to strip the returned This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-08 16:14:07
|
Revision: 10596 http://octave.svn.sourceforge.net/octave/?rev=10596&view=rev Author: prnienhuis Date: 2012-06-08 16:14:00 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Copyright date in UNO section adapted Modified Paths: -------------- trunk/octave-forge/main/io/inst/ods2oct.m Modified: trunk/octave-forge/main/io/inst/ods2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/ods2oct.m 2012-06-08 15:44:35 UTC (rev 10595) +++ trunk/octave-forge/main/io/inst/ods2oct.m 2012-06-08 16:14:00 UTC (rev 10596) @@ -777,7 +777,7 @@ endfunction -## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## Copyright (C) 2011,2012 Philip Nienhuis <prn...@us...> ## ## 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-08 15:44:41
|
Revision: 10595 http://octave.svn.sourceforge.net/octave/?rev=10595&view=rev Author: prnienhuis Date: 2012-06-08 15:44:35 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Updated Modified Paths: -------------- trunk/octave-forge/main/io/NEWS Modified: trunk/octave-forge/main/io/NEWS =================================================================== --- trunk/octave-forge/main/io/NEWS 2012-06-08 15:42:23 UTC (rev 10594) +++ trunk/octave-forge/main/io/NEWS 2012-06-08 15:44:35 UTC (rev 10595) @@ -8,11 +8,15 @@ with jopendocument v 1.3b1 --- oct2xls, oct2ods: cast all numeric types in input array to double as spreadsheets have only double, boolean or character string type. This bug - has been there from the very beginning of the spreadsheet functions 8-O + has been there from the very beginning of the spreadsheet functions >8-O +--- Support for reading back formulas from .xls spreadsheets using ActiveX/COM + ** Compatible with jOpenDocument version 1.3b1 getUsedRange() method added (MUCH faster than the old hack) +** Compatible with odfdom-java-0.8.8-incubator.jar (ODF Toolkit 0.5-incubating) + ** Compatible with Apache POI 3.8 final =============================================================================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-08 15:42:34
|
Revision: 10594 http://octave.svn.sourceforge.net/octave/?rev=10594&view=rev Author: prnienhuis Date: 2012-06-08 15:42:23 +0000 (Fri, 08 Jun 2012) Log Message: ----------- odfdom-0.8.8 mentioned + adapted URL for odfdom; spell check Modified Paths: -------------- trunk/octave-forge/main/io/doc/READ-ODS.html Modified: trunk/octave-forge/main/io/doc/READ-ODS.html =================================================================== --- trunk/octave-forge/main/io/doc/READ-ODS.html 2012-06-08 15:28:56 UTC (rev 10593) +++ trunk/octave-forge/main/io/doc/READ-ODS.html 2012-06-08 15:42:23 UTC (rev 10594) @@ -18,7 +18,7 @@ Copyright \xA9 2009 - 2012 Philip Nienhuis <prnienhuis at users.sf.net></font></font> </p> <p align="center"><font face="Arial, sans-serif"><font size="2"> - This version June 07, 2012</font></font> + This version June 08, 2012</font></font> </p> <p><font face="Arial, sans-serif"><font size="2"> <i>(ODS = Open Document Format spreadsheet data format, used by e.g., OpenOffice.org.)</i></font></font> @@ -89,12 +89,12 @@ <li> <p align="left"><font face="Arial, sans-serif"><font size="2"> (currently the preferred option) <b>odfdom.jar</b> (<u>only</u> versions <b>0.7.5</b>, - <b>0.8.6</b>, and <b>0.8.7</b> work OK!) & <b>xercesImpl.jar</b> (watch out here too! only version 2.9.1 (2007-sep-14) works OK with odfdom). Get them here: + <b>0.8.6</b>, <b>0.8.7</b> and <b>0.8.8</b>(-incubator) work OK!) & <b>xercesImpl.jar</b> (watch out here too! only version 2.9.1 (2007-sep-14) works OK with odfdom). Get them here: </font></font></p> </li><li><p align="left"> - <a href="http://odftoolkit.org/projects/odfdom/pages/Home "><font face="Arial, sans-serif"><font size="2">http://odftoolkit.org/projects/odfdom/pages/Home </font></font></a></p></li> + <a href="http://odftoolkit.org/projects/odfdom/pages/Home"><font face="Arial, sans-serif"><font size="2">http://odftoolkit.org/projects/odfdom/pages/Home</font></font></a></p></li> <li><p align="left" lang="zxx"> - <font color="#000080"><font face="Arial, sans-serif"><font size="2"><u>http://odftoolkit.org/projects/odfdom/downloads/directory/current-version</u></font></font></font></p></li><li><p align="left"> + <font color="#000080"><font face="Arial, sans-serif"><font size="2"><a href="http://incubator.apache.org/odftoolkit/downloads.html"><font face="Arial, sans-serif"><font size="2">http://incubator.apache.org/odftoolkit/downloads.html</font></font></a></font></font></font></p></li><li><p align="left"> <a href="http://www.google.com/search?ie=UTF-8&oe=utf-8&q=xerces-2.9.1+download"><font face="Arial, sans-serif"><font size="2">Google for xerces-2.9.1 download </font></font></a></p></li> </ul> <dl><dt><p> @@ -347,7 +347,10 @@ primarily driven by requests from customers who pay for support. I do sympathize with this business model but for octave needs this may hamper progress for a while.<br> - In addition, jOpenDocument 1.2 has bugs here and there. For one, it doesn't write appropriate OfficeValueType attributes to the cells, so there's no way to reliably read and distinguish boolean, string amnd integer values.</font></font></p></dt> + In addition, jOpenDocument 1.2 and 1.3b1 still have bugs here and there. For + one, it doesn't write appropriate OfficeValueType attributes to the cells, so + there's no way to reliably read and distinguish boolean, string and integer + values.</font></font></p></dt> <dt><p><font face="Arial, sans-serif"><font size="2">The (still experimental) <b>UNO interface</b>, based on a Java/UNO bridge linking a hidden OpenOffice.org invocation to Octave, is the most promising: @@ -540,10 +543,10 @@ too - this needed a few adjustments; clearly the odfdom API (currently at main version 0) is not stable yet.</font></font></dt><dt> <font face="Arial, sans-serif"><font size="2">So at the moment - (May 2011 = last I looked) only odfdom versions <b>0.7.5</b>, - <b>0.8.6</b> and <b>0.8.7</b> are supported.</font></font></dt><dt> - <br> - </dt><dt><font face="Arial, sans-serif"><font size="2">If you want to + (June 2012 = last I looked) only odfdom versions <b>0.7.5</b>, + <b>0.8.6</b>, <b>0.8.7</b> and <b>0.8.8</b>(-incubator) are supported. + </font></font></dt><dt><br></dt> + <dt><font face="Arial, sans-serif"><font size="2">If you want to experiment with odfdom 0.8 & 0.8.5, you can try:</font></font></dt></dl> <ul> <li> @@ -554,7 +557,7 @@ <font face="Arial, sans-serif"><font size="2">oct2ods.m (revision 7159)</font></font></li></ul> <p><font face="Arial, sans-serif"><font size="2">Enjoy!</font></font></p><p align="center"><font face="Arial, sans-serif"><font size="2">Philip - Nienhuis, June 07, 2012</font></font></p><dl><dd><p align="center"> + Nienhuis, June 08, 2012</font></font></p><dl><dd><p align="center"> <br> </p></dd></dl> </body></html> \ 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: <prn...@us...> - 2012-06-08 15:29:07
|
Revision: 10593 http://octave.svn.sourceforge.net/octave/?rev=10593&view=rev Author: prnienhuis Date: 2012-06-08 15:28:56 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Stray debug stmts removed Modified Paths: -------------- trunk/octave-forge/main/io/inst/io_xls_testscript.m Modified: trunk/octave-forge/main/io/inst/io_xls_testscript.m =================================================================== --- trunk/octave-forge/main/io/inst/io_xls_testscript.m 2012-06-08 15:28:27 UTC (rev 10592) +++ trunk/octave-forge/main/io/inst/io_xls_testscript.m 2012-06-08 15:28:56 UTC (rev 10593) @@ -113,7 +113,7 @@ if (isnumeric (raw{3, 3})) printf (" (equals %f, should be a string like '=c2+d2')\n", raw{3, 3}); else - printf ("\n"); keyboard + printf ("\n"); endif end_try_catch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-08 15:28:36
|
Revision: 10592 http://octave.svn.sourceforge.net/octave/?rev=10592&view=rev Author: prnienhuis Date: 2012-06-08 15:28:27 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Support for odfdom-0.8.8-incubator; tabs replaced by double space Modified Paths: -------------- trunk/octave-forge/main/io/inst/getusedrange.m trunk/octave-forge/main/io/inst/oct2ods.m trunk/octave-forge/main/io/inst/ods2oct.m trunk/octave-forge/main/io/inst/odsclose.m trunk/octave-forge/main/io/inst/odsfinfo.m trunk/octave-forge/main/io/inst/odsopen.m trunk/octave-forge/main/io/inst/odsread.m trunk/octave-forge/main/io/inst/odswrite.m Modified: trunk/octave-forge/main/io/inst/getusedrange.m =================================================================== --- trunk/octave-forge/main/io/inst/getusedrange.m 2012-06-08 14:11:42 UTC (rev 10591) +++ trunk/octave-forge/main/io/inst/getusedrange.m 2012-06-08 15:28:27 UTC (rev 10592) @@ -66,8 +66,10 @@ ## 2011-06-13 OpenXLS support added ## 2011-09-08 Style & layout updates ## 2012-01-26 Fixed "seealso" help string +## 2012-06-08 Replaced tabs by double space +## '' Added COM and OXS to message about supported interfaces ## -## Last subfunc update: 2012-04-18 (JOD) +## Last subfunc update: 2012-06-08 (OTK) function [ trow, lrow, lcol, rcol ] = getusedrange (spptr, ii) @@ -89,7 +91,7 @@ elseif (strcmp (spptr.xtype, 'OXS')) [ trow, lrow, lcol, rcol ] = getusedrange_oxs (spptr, ii); else - error ('Only OTK, JOD, POI and JXL interface implemented'); + error ("Only OTK, JOD, COM, POI, JXL and OXS interface implemented"); endif endfunction @@ -124,10 +126,11 @@ ## Currently this fix is just commented. ## 2011-06-06 Fixed wrong if clause for finding last filler cells (L.160 & L.176) ## 2011-09-12 Support for odfdom-0.8.7 added (API change for XPATH) +## 2012-06-08 Support for odsfdom-0.8.8-incubator function [ trow, lrow, lcol, rcol ] = getusedrange_otk (ods, ii) - odfcont = ods.workbook; # Local copy just in case + odfcont = ods.workbook; # Local copy just in case if (isfield (ods, 'odfvsn')) if (strcmp (ods.odfvsn, '0.8.6') || strcmp (ods.odfvsn, '0.7.5')) @@ -166,11 +169,11 @@ reprows = 0; endif - # Get leftmost cell column number + # Get leftmost cell column number lcell = row.getFirstChild (); cl_char = char (lcell); - # Swap the following lines into comment to catch a jOpenDocument bug which foobars OTK - # (JOD doesn't set <office:value-type='string'> attribute when writing strings + # Swap the following lines into comment to catch a jOpenDocument bug which foobars OTK + # (JOD doesn't set <office:value-type='string'> attribute when writing strings #if (isempty (findstr ('office:value-type', cl_char)) || isempty (findstr ('<text:', cl_char))) if (isempty (findstr ('office:value-type', cl_char))) lcol = min (lcol, lcell.getTableNumberColumnsRepeatedAttribute () + 1); @@ -232,7 +235,7 @@ ## Created: 2010-05-25 ## Last updates: ## 2010-05-31 Fixed ignoring table-covered-cells; fixed count of sheets comprising just A1:A1 -## '' Added option for wsh being a string argument +## Added option for wsh being a string argument ## 2010-08-12 Little textual adaptations ## 2010-11-13 Catched jOpenDocument bug (1.2bx) where string cells have no office:value-type ## '' attrb set (by JOD). Somehow OTK is more robust as it catches these cells @@ -241,15 +244,15 @@ function [ trow, brow, lcol, rcol ] = getusedrange_jod (ods, wsh) - # This function works by virtue of sheets in JOD actually being a Java string. - # It works outside of the Java memory/heap space which is an added benefit... - # (Read: this is one big dirty hack...... prone to crash Java on BIG spreadsheets) + # This function works by virtue of sheets in JOD actually being a Java string. + # It works outside of the Java memory/heap space which is an added benefit... + # (Read: this is one big dirty hack...... prone to crash Java on BIG spreadsheets) - if (isnumeric (wsh)) - sh = ods.workbook.getSheet (wsh - 1); - else - sh = ods.workbook.getSheet (wsh); - endif + if (isnumeric (wsh)) + sh = char (ods.workbook.getSheet (wsh - 1)); + else + sh = char (ods.workbook.getSheet (wsh)); + endif try # Let's see if we have JOD v. 1.3x. If not, next call fails & we'll fall back to the old hack @@ -266,16 +269,12 @@ brow = trow + nr - 1; rcol = lcol + nc - 1; endif - return catch - # This function works by virtue of sheets in JOD actually being a Java string. - # It works outside of the Java memory/heap space which is an added benefit... - # (Read: this is one big dirty hack...... prone to crash Java on BIG spreadsheets) - + # Fall back to the old hack :-( sh = char (sh); - # Get table-row pointers + # 1. Get table-row pointers id_trow = strfind (sh, '<table:table-row'); id = strfind (sh, '</table:table>') - 1; id_trow = [id_trow id]; @@ -283,96 +282,96 @@ trow = rcol = 0; lcol = 1024; brow = 0; if (~isempty (id)) - # Loop over all table-rows - rowrepcnt = 0; - for irow = 1:length (id_trow)-1 - # Isolate single table-row - tablerow = sh(id_trow(irow):id_trow(irow+1)-1); - # Search table-cells. table-c covers both table-cell & table-covered-cell - id_tcell = strfind (tablerow, '<table:table-c'); - id_tcell = [id_tcell id]; - rowl = length (tablerow); - if (isempty (id_tcell(1:end-1))) - rowend = rowl; - else - rowend = id_tcell(1); - endif - # Add in table-number-rows-repeated attribute values - rowrept = strfind (tablerow(1:rowend), 'number-rows-repeated'); - if (~isempty (rowrept)) - [st, en] = regexp (tablerow(rowrept:min (rowend, rowrept+30)), '\d+'); - rowrepcnt += str2num (tablerow(rowrept+st-1:min (rowend, rowrept+en-1))) - 1; - endif + # 2. Loop over all table-rows + rowrepcnt = 0; + for irow = 1:length (id_trow)-1 + # Isolate single table-row + tablerow = sh(id_trow(irow):id_trow(irow+1)-1); + # Search table-cells. table-c covers both table-cell & table-covered-cell + id_tcell = strfind (tablerow, '<table:table-c'); + id_tcell = [id_tcell id]; + rowl = length (tablerow); + if (isempty (id_tcell(1:end-1))) + rowend = rowl; + else + rowend = id_tcell(1); + endif + # Add in table-number-rows-repeated attribute values + rowrept = strfind (tablerow(1:rowend), 'number-rows-repeated'); + if (~isempty (rowrept)) + [st, en] = regexp (tablerow(rowrept:min (rowend, rowrept+30)), '\d+'); + rowrepcnt += str2num (tablerow(rowrept+st-1:min (rowend, rowrept+en-1))) - 1; + endif - # Search table-cells. table-c is a table-covered-cell that is considered empty - id_tcell = strfind (tablerow, '<table:table-c'); - if (~isempty (id_tcell)) - # OK, this row has a value cell. Now table-covered-cells must be included. - id_tcell2 = strfind (tablerow, '<table:covered-t'); - if (~isempty (id_tcell2)) id_tcell = sort ([id_tcell id_tcell2]); endif - id_tcell = [id_tcell rowl]; - # Search for non-empty cells (i.e., with an office:value-type attribute). But: - # jOpenDocument 1.2b3 has a bug: it often doesn't set this attr for string cells - id_valtcell = strfind (tablerow, 'office:value-type='); - id_textonlycell = strfind (tablerow, '<text:'); - id_valtcell = sort ([id_valtcell id_textonlycell]); - id_valtcell = [id_valtcell rowl]; - if (~isempty (id_valtcell(1:end-1))) - brow = irow + rowrepcnt; - # First set trow if it hadn't already been found - if (~trow) trow = irow; endif - # Search for repeated table-cells - id_reptcell = strfind (tablerow, 'number-columns-repeated'); - id_reptcell = [id_reptcell rowl]; - # Search for leftmost non-empty table-cell. llcol = counter for this table-row - llcol = 1; - while (id_tcell (llcol) < id_valtcell(1) && llcol <= length (id_tcell) - 1) - ++llcol; - endwhile - --llcol; - # Compensate for repeated cells. First count all repeats left of llcol - ii = 1; - repcnt = 0; - if (~isempty (id_reptcell(1:end-1))) - # First try lcol - while (ii <= length (id_reptcell) - 1 && id_reptcell(ii) < id_valtcell(1)) - # Add all repeat counts left of leftmost data tcell minus 1 for each - [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); - repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; - ++ii; - endwhile - # Next, add current repcnt value to llcol and update lcol - lcol = min (lcol, llcol + repcnt); - # Get last value table-cell in table-cell idx - jj = 1; - while (id_tcell (jj) < id_valtcell(length (id_valtcell)-1)) - ++jj; - endwhile + # 3. Search table-cells. table-c is a table-covered-cell that is considered empty + id_tcell = strfind (tablerow, '<table:table-c'); + if (~isempty (id_tcell)) + # OK, this row has a value cell. Now table-covered-cells must be included. + id_tcell2 = strfind (tablerow, '<table:covered-t'); + if (~isempty (id_tcell2)) id_tcell = sort ([id_tcell id_tcell2]); endif + id_tcell = [id_tcell rowl]; + # Search for non-empty cells (i.e., with an office:value-type attribute). But: + # jOpenDocument 1.2b3 has a bug: it often doesn't set this attr for string cells + id_valtcell = strfind (tablerow, 'office:value-type='); + id_textonlycell = strfind (tablerow, '<text:'); + id_valtcell = sort ([id_valtcell id_textonlycell]); + id_valtcell = [id_valtcell rowl]; + if (~isempty (id_valtcell(1:end-1))) + brow = irow + rowrepcnt; + # First set trow if it hadn't already been found + if (~trow) trow = irow; endif + # Search for repeated table-cells + id_reptcell = strfind (tablerow, 'number-columns-repeated'); + id_reptcell = [id_reptcell rowl]; + # Search for leftmost non-empty table-cell. llcol = counter for this table-row + llcol = 1; + while (id_tcell (llcol) < id_valtcell(1) && llcol <= length (id_tcell) - 1) + ++llcol; + endwhile + --llcol; + # Compensate for repeated cells. First count all repeats left of llcol + ii = 1; + repcnt = 0; + if (~isempty (id_reptcell(1:end-1))) + # First try lcol + while (ii <= length (id_reptcell) - 1 && id_reptcell(ii) < id_valtcell(1)) + # Add all repeat counts left of leftmost data tcell minus 1 for each + [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); + repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; + ++ii; + endwhile + # Next, add current repcnt value to llcol and update lcol + lcol = min (lcol, llcol + repcnt); + # Get last value table-cell in table-cell idx + jj = 1; + while (id_tcell (jj) < id_valtcell(length (id_valtcell)-1)) + ++jj; + endwhile - # Get rest of column repeat counts in value table-cell range - while (ii < length (id_reptcell) && id_reptcell(ii) < id_tcell(jj)) - # Add all repeat counts minus 1 for each tcell in value tcell range - [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); - repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; - ++ii; - endwhile - else - # In case left column = A - lcol = min (lcol, llcol); - endif - # Count all table-cells in value table-cell-range - ii = 1; # Indexes cannot be negative - while (ii < length (id_tcell) && id_tcell(ii) < id_valtcell(length (id_valtcell) - 1)) - ++ii; - endwhile - --ii; - rcol = max (rcol, ii + repcnt); - endif - endif - endfor + # Get rest of column repeat counts in value table-cell range + while (ii < length (id_reptcell) && id_reptcell(ii) < id_tcell(jj)) + # Add all repeat counts minus 1 for each tcell in value tcell range + [st, en] = regexp (tablerow(id_reptcell(ii):id_reptcell(ii)+30), '\d+'); + repcnt += str2num (tablerow(id_reptcell(ii)+st-1:id_reptcell(ii)+en-1)) - 1; + ++ii; + endwhile + else + # In case left column = A + lcol = min (lcol, llcol); + endif + # Count all table-cells in value table-cell-range + ii = 1; # Indexes cannot be negative + while (ii < length (id_tcell) && id_tcell(ii) < id_valtcell(length (id_valtcell) - 1)) + ++ii; + endwhile + --ii; + rcol = max (rcol, ii + repcnt); + endif + endif + endfor else - # No data found, empty sheet - lcol = rcol = brow = trow = 0; + # No data found, empty sheet + lcol = rcol = brow = trow = 0; endif end_try_catch @@ -482,30 +481,30 @@ function [ trow, brow, lcol, rcol ] = getusedrange_com (xls, ii) - sh = xls.workbook.Worksheets (ii); - - # Decipher used range. Beware, UsedRange() returns *cached* rectangle of - # all spreadsheet cells containing *anything*, including just formatting - # (i.e., empty cells are included too). ==> This is an approximation only - allcells = sh.UsedRange; - - # Get top left cell as a Range object - toplftcl = allcells.Columns(1).Rows(1); - - # Count number of rows & cols in virtual range from A1 to top left cell - lcol = sh.Range ("A1", toplftcl).columns.Count; - trow = sh.Range ("A1", toplftcl).rows.Count; - - # Add real occupied rows & cols to obtain end row & col - brow = trow + allcells.rows.Count() - 1; - rcol = lcol + allcells.columns.Count() - 1; - - # Check if there are real data - if ((lcol == rcol) && (trow = brow)) - if (isempty (toplftcl.Value)) - trow = brow = lcol = rcol = 0; - endif + sh = xls.workbook.Worksheets (ii); + + # Decipher used range. Beware, UsedRange() returns *cached* rectangle of + # all spreadsheet cells containing *anything*, including just formatting + # (i.e., empty cells are included too). ==> This is an approximation only + allcells = sh.UsedRange; + + # Get top left cell as a Range object + toplftcl = allcells.Columns(1).Rows(1); + + # Count number of rows & cols in virtual range from A1 to top left cell + lcol = sh.Range ("A1", toplftcl).columns.Count; + trow = sh.Range ("A1", toplftcl).rows.Count; + + # Add real occupied rows & cols to obtain end row & col + brow = trow + allcells.rows.Count() - 1; + rcol = lcol + allcells.columns.Count() - 1; + + # Check if there are real data + if ((lcol == rcol) && (trow = brow)) + if (isempty (toplftcl.Value)) + trow = brow = lcol = rcol = 0; endif + endif endfunction @@ -532,35 +531,35 @@ function [ trow, brow, lcol, rcol ] = getusedrange_poi (xls, ii) - persistent cblnk; cblnk = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); + persistent cblnk; cblnk = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); - sh = xls.workbook.getSheetAt (ii-1); # Java POI starts counting at 0 + sh = xls.workbook.getSheetAt (ii-1); # Java POI starts counting at 0 - trow = sh.getFirstRowNum (); # 0-based - brow = sh.getLastRowNum (); # 0-based - # Get column range - lcol = 1048577; # OOXML (xlsx) max. + 1 - rcol = 0; - botrow = brow; - for jj=trow:brow - irow = sh.getRow (jj); - if (~isempty (irow)) - scol = (irow.getFirstCellNum).intValue (); - lcol = min (lcol, scol); - ecol = (irow.getLastCellNum).intValue () - 1; - rcol = max (rcol, ecol); - # Keep track of lowermost non-empty row as getLastRowNum() is unreliable - if ~(irow.getCell(scol).getCellType () == cblnk && irow.getCell(ecol).getCellType () == cblnk) - botrow = jj; - endif - endif - endfor - if (lcol > 1048576) - # Empty sheet - trow = 0; brow = 0; lcol = 0; rcol = 0; - else - brow = min (brow, botrow) + 1; ++trow; ++lcol; ++rcol; # 1-based return values + trow = sh.getFirstRowNum (); # 0-based + brow = sh.getLastRowNum (); # 0-based + # Get column range + lcol = 1048577; # OOXML (xlsx) max. + 1 + rcol = 0; + botrow = brow; + for jj=trow:brow + irow = sh.getRow (jj); + if (~isempty (irow)) + scol = (irow.getFirstCellNum).intValue (); + lcol = min (lcol, scol); + ecol = (irow.getLastCellNum).intValue () - 1; + rcol = max (rcol, ecol); + # Keep track of lowermost non-empty row as getLastRowNum() is unreliable + if ~(irow.getCell(scol).getCellType () == cblnk && irow.getCell(ecol).getCellType () == cblnk) + botrow = jj; + endif endif + endfor + if (lcol > 1048576) + # Empty sheet + trow = 0; brow = 0; lcol = 0; rcol = 0; + else + brow = min (brow, botrow) + 1; ++trow; ++lcol; ++rcol; # 1-based return values + endif endfunction @@ -588,33 +587,33 @@ function [ trow, brow, lcol, rcol ] = getusedrange_jxl (xls, wsh) - persistent emptycell = (java_get ('jxl.CellType', 'EMPTY')).toString (); + persistent emptycell = (java_get ('jxl.CellType', 'EMPTY')).toString (); - sh = xls.workbook.getSheet (wsh - 1); # JXL sheet count 0-based + sh = xls.workbook.getSheet (wsh - 1); # JXL sheet count 0-based - brow = sh.getRows (); - rcol = sh.getColumns (); - - if (brow == 0 || rcol == 0) - # Empty sheet - trow = 0; lcol = 0; brow = 0; rcol = 0; - else - trow = brow + 1; - lcol = rcol + 1; - for ii=0:brow-1 # For loop coz we must check ALL rows for leftmost column - emptyrow = 1; - jj = 0; - while (jj < rcol && emptyrow) # While loop => only til first non-empty cell - cell = sh.getCell (jj, ii); - if ~(strcmp (char (cell.getType ()), emptycell)) - lcol = min (lcol, jj + 1); - emptyrow = 0; - endif - ++jj; - endwhile - if ~(emptyrow) trow = min (trow, ii + 1); endif - endfor - endif + brow = sh.getRows (); + rcol = sh.getColumns (); + + if (brow == 0 || rcol == 0) + # Empty sheet + trow = 0; lcol = 0; brow = 0; rcol = 0; + else + trow = brow + 1; + lcol = rcol + 1; + for ii=0:brow-1 # For loop coz we must check ALL rows for leftmost column + emptyrow = 1; + jj = 0; + while (jj < rcol && emptyrow) # While loop => only til first non-empty cell + cell = sh.getCell (jj, ii); + if ~(strcmp (char (cell.getType ()), emptycell)) + lcol = min (lcol, jj + 1); + emptyrow = 0; + endif + ++jj; + endwhile + if ~(emptyrow) trow = min (trow, ii + 1); endif + endfor + endif endfunction @@ -643,18 +642,18 @@ function [ trow, brow, lcol, rcol ] = getusedrange_oxs (xls, wsh) - sh = xls.workbook.getWorkSheet (wsh - 1); - try - # Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z - trow = sh.getFirstRow () + 1; - brow = sh.getLastRow (); - lcol = sh.getFirstCol () + 1; - rcol = sh.getLastCol (); - catch - # Might be an empty sheet - trow = brow = lcol = rcol = 0; - end_try_catch - # Check for empty sheet - if ((trow > brow) || (lcol > rcol)), trow = brow = lcol = rcol = 0; endif + sh = xls.workbook.getWorkSheet (wsh - 1); + try + # Intriguing: sh.getFirst<> is off by one, sh.getLast<> = OK.... 8-Z + trow = sh.getFirstRow () + 1; + brow = sh.getLastRow (); + lcol = sh.getFirstCol () + 1; + rcol = sh.getLastCol (); + catch + # Might be an empty sheet + trow = brow = lcol = rcol = 0; + end_try_catch + # Check for empty sheet + if ((trow > brow) || (lcol > rcol)), trow = brow = lcol = rcol = 0; endif endfunction Modified: trunk/octave-forge/main/io/inst/oct2ods.m =================================================================== --- trunk/octave-forge/main/io/inst/oct2ods.m 2012-06-08 14:11:42 UTC (rev 10591) +++ trunk/octave-forge/main/io/inst/oct2ods.m 2012-06-08 15:28:27 UTC (rev 10592) @@ -115,98 +115,96 @@ ## 2012-02-20 Fixed range parameter to be default empty string rather than empty numeral ## 2012-02-27 More range arg fixes ## 2012-03-07 Updated texinfo help text -## 2012-05-22 Cast all numeric data in input array to double +## 2012-06-08 Support for odfdom-incubator-0.8.8 +## '' Tabs replaced by double space ## -## Last update of subfunctions below: 2012-02-26 +## Last update of subfunctions below: 2012-06-08 function [ ods, rstatus ] = oct2ods (c_arr, ods, wsh=1, crange='', spsh_opts=[]) - if (nargin < 2) error ("oct2xls needs a minimum of 2 arguments."); endif + if (nargin < 2) error ("oct2xls needs a minimum of 2 arguments."); endif - # Check if input array is cell - if (isempty (c_arr)) - warning ("Request to write empty matrix - ignored."); - rstatus = 1; - return; - elseif (isnumeric (c_arr)) - c_arr = num2cell (c_arr); - elseif (ischar(c_arr)) - c_arr = {c_arr}; - printf ("(oct2ods: input character array converted to 1x1 cell)\n"); - elseif (~iscell (c_arr)) - error ("oct2ods: input array neither cell nor numeric array"); - endif - if (ndims (c_arr) > 2), error ("Only 2-dimensional arrays can be written to spreadsheet"); endif - # Cast all numerical values to double as spreadsheets only have double/boolean/text type - idx = cellfun (@isnumeric, obj, "UniformOutput", true); - obj(idx) = cellfun (@double, obj(idx), "UniformOutput", false); + # Check if input array is cell + if (isempty (c_arr)) + warning ("Request to write empty matrix - ignored."); + rstatus = 1; + return; + elseif (isnumeric (c_arr)) + c_arr = num2cell (c_arr); + elseif (ischar(c_arr)) + c_arr = {c_arr}; + printf ("(oct2ods: input character array converted to 1x1 cell)\n"); + elseif (~iscell (c_arr)) + error ("oct2ods: input array neither cell nor numeric array"); + endif + if (ndims (c_arr) > 2), error ("Only 2-dimensional arrays can be written to spreadsheet"); endif # Check ods file pointer struct - test1 = ~isfield (ods, "xtype"); - test1 = test1 || ~isfield (ods, "workbook"); - test1 = test1 || isempty (ods.workbook); - test1 = test1 || isempty (ods.app); - if test1 - error ("Arg #2: Invalid ods file pointer struct"); - endif + test1 = ~isfield (ods, "xtype"); + test1 = test1 || ~isfield (ods, "workbook"); + test1 = test1 || isempty (ods.workbook); + test1 = test1 || isempty (ods.app); + if test1 + error ("Arg #2: Invalid ods file pointer struct"); + endif - # Check worksheet ptr - if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif + # Check worksheet ptr + if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 3"); endif - # Check range - if (~isempty (crange) && ~ischar (crange)) + # Check range + if (~isempty (crange) && ~ischar (crange)) error ("Character string (range) expected for arg # 4"); elseif (isempty (crange)) crange = ''; endif - # Various options - if (isempty (spsh_opts)) - spsh_opts.formulas_as_text = 0; - # other options to be implemented here - elseif (isstruct (spsh_opts)) - if (~isfield (spsh_opts, 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - # other options to be implemented here - else - error ("Structure expected for arg # 5"); - endif - - if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified.\n"); endif + # Various options + if (isempty (spsh_opts)) + spsh_opts.formulas_as_text = 0; + # other options to be implemented here + elseif (isstruct (spsh_opts)) + if (~isfield (spsh_opts, 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif + # other options to be implemented here + else + error ("Structure expected for arg # 5"); + endif + + if (nargout < 1) printf ("Warning: no output spreadsheet file pointer specified.\n"); endif - if (strcmp (ods.xtype, 'OTK')) - # Write ods file tru Java & ODF toolkit. - switch ods.odfvsn - case "0.7.5" - [ ods, rstatus ] = oct2jotk2ods (c_arr, ods, wsh, crange, spsh_opts); - case {"0.8.6", "0.8.7"} - [ ods, rstatus ] = oct3jotk2ods (c_arr, ods, wsh, crange, spsh_opts); - otherwise - error ("Unsupported odfdom version"); - endswitch + if (strcmp (ods.xtype, 'OTK')) + # Write ods file tru Java & ODF toolkit. + switch ods.odfvsn + case "0.7.5" + [ ods, rstatus ] = oct2jotk2ods (c_arr, ods, wsh, crange, spsh_opts); + case {"0.8.6", "0.8.7", "0.8.8"} + [ ods, rstatus ] = oct3jotk2ods (c_arr, ods, wsh, crange, spsh_opts); + otherwise + error ("Unsupported odfdom version"); + endswitch - elseif (strcmp (ods.xtype, 'JOD')) - # Write ods file tru Java & jOpenDocument. API still leaves lots to be wished... - [ ods, rstatus ] = oct2jod2ods (c_arr, ods, wsh, crange); + elseif (strcmp (ods.xtype, 'JOD')) + # Write ods file tru Java & jOpenDocument. API still leaves lots to be wished... + [ ods, rstatus ] = oct2jod2ods (c_arr, ods, wsh, crange); - elseif (strcmp (ods.xtype, 'UNO')) - # Write ods file tru Java & UNO bridge (OpenOffice.org & clones) - [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts); + elseif (strcmp (ods.xtype, 'UNO')) + # Write ods file tru Java & UNO bridge (OpenOffice.org & clones) + [ ods, rstatus ] = oct2uno2ods (c_arr, ods, wsh, crange, spsh_opts); -# elseif - # ---- < Other interfaces here > +# elseif + # ---- < Other interfaces here > - else - error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); - endif + else + error (sprintf ("ods2oct: unknown OpenOffice.org .ods interface - %s.", ods.xtype)); + endif - if (rstatus), ods.limits = []; endif + if (rstatus), ods.limits = []; endif endfunction #============================================================================= -## Copyright (C) 2010,2011 Philip Nienhuis <prn...@us...> +## Copyright (C) 2010,2011,2012 Philip Nienhuis <prn...@us...> ## ## 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 @@ -253,401 +251,401 @@ function [ ods, rstatus ] = oct2jotk2ods (c_arr, ods, wsh, crange, spsh_opts) - persistent ctype; - if (isempty (ctype)) - # Number, Boolean, String, Formula, Empty, Date, Time (last 2 are ignored) - ctype = [1, 2, 3, 4, 5, 6, 7]; - endif + persistent ctype; + if (isempty (ctype)) + # Number, Boolean, String, Formula, Empty, Date, Time (last 2 are ignored) + ctype = [1, 2, 3, 4, 5, 6, 7]; + endif - rstatus = 0; f_errs = 0; + rstatus = 0; f_errs = 0; - # Get some basic spreadsheet data from the pointer using ODFtoolkit - odfcont = ods.workbook; - xpath = ods.app.getXPath (); - offsprdsh = ods.app.getContentRoot(); - autostyles = odfcont.getOrCreateAutomaticStyles(); - officestyles = ods.app.getOrCreateDocumentStyles(); + # Get some basic spreadsheet data from the pointer using ODFtoolkit + odfcont = ods.workbook; + xpath = ods.app.getXPath (); + offsprdsh = ods.app.getContentRoot(); + autostyles = odfcont.getOrCreateAutomaticStyles(); + officestyles = ods.app.getOrCreateDocumentStyles(); - # Create an instance of type NODESET for use in subsequent statements - NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); + # Create an instance of type NODESET for use in subsequent statements + NODESET = java_get ('javax.xml.xpath.XPathConstants', 'NODESET'); - # Parse sheets ("tables") from ODS file - sheets = xpath.evaluate ("//table:table", odfcont, NODESET); - nr_of_sheets = sheets.getLength (); - newsh = 0; # Assume existing sheet - if isempty (wsh) wsh = 1; endif - if (~isnumeric (wsh)) # Sheet name specified - # Search in sheet names, match sheet name to sheet number. - # Beware, 0-based index, 1-based count! - ii = 0; - while (++ii <= nr_of_sheets && ischar (wsh)) - # Look in first part of the sheet nodeset - sh_name = sheets.item(ii-1).getTableNameAttribute (); - if (strcmp (sh_name, wsh)) - # Convert local copy of wsh into a number (pointer) - wsh = ii - 1; - endif - endwhile - if (ischar (wsh) && nr_of_sheets < 256) newsh = 1; endif - else # Sheet index specified - if ((ods.changed > 2) || (wsh > nr_of_sheets && wsh < 256)) # Max nr of sheets = 256 - # Create a new sheet - newsh = 1; - elseif (wsh <=nr_of_sheets && wsh > 0) - # Existing sheet. Count = 1-based, index = 0-based - --wsh; sh = sheets.item(wsh); - printf ("Writing to sheet %s\n", sh.getTableNameAttribute()); - else - error ("oct2ods: illegal sheet number."); - endif - endif + # Parse sheets ("tables") from ODS file + sheets = xpath.evaluate ("//table:table", odfcont, NODESET); + nr_of_sheets = sheets.getLength (); + newsh = 0; # Assume existing sheet + if isempty (wsh) wsh = 1; endif + if (~isnumeric (wsh)) # Sheet name specified + # Search in sheet names, match sheet name to sheet number. + # Beware, 0-based index, 1-based count! + ii = 0; + while (++ii <= nr_of_sheets && ischar (wsh)) + # Look in first part of the sheet nodeset + sh_name = sheets.item(ii-1).getTableNameAttribute (); + if (strcmp (sh_name, wsh)) + # Convert local copy of wsh into a number (pointer) + wsh = ii - 1; + endif + endwhile + if (ischar (wsh) && nr_of_sheets < 256) newsh = 1; endif + else # Sheet index specified + if ((ods.changed > 2) || (wsh > nr_of_sheets && wsh < 256)) # Max nr of sheets = 256 + # Create a new sheet + newsh = 1; + elseif (wsh <=nr_of_sheets && wsh > 0) + # Existing sheet. Count = 1-based, index = 0-based + --wsh; sh = sheets.item(wsh); + printf ("Writing to sheet %s\n", sh.getTableNameAttribute()); + else + error ("oct2ods: illegal sheet number."); + endif + endif # Check size of data array & range / capacity of worksheet & prepare vars - [nr, nc] = size (c_arr); - [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); - --trow; --lcol; # Zero-based row # & col # - if (nrows < nr || ncols < nc) - warning ("Array truncated to fit in range"); - c_arr = c_arr(1:nrows, 1:ncols); - endif - + [nr, nc] = size (c_arr); + [topleft, nrows, ncols, trow, lcol] = spsh_chkrange (crange, nr, nc, ods.xtype, ods.filename); + --trow; --lcol; # Zero-based row # & col # + if (nrows < nr || ncols < nc) + warning ("Array truncated to fit in range"); + c_arr = c_arr(1:nrows, 1:ncols); + endif + # Parse data array, setup typarr and throw out NaNs to speed up writing; - typearr = spsh_prstype (c_arr, nrows, ncols, ctype, spsh_opts, 0); - if ~(spsh_opts.formulas_as_text) - # Find formulas (designated by a string starting with "=" and ending in ")") - fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), c_arr); - typearr(fptr) = ctype(4); # FORMULA - endif + typearr = spsh_prstype (c_arr, nrows, ncols, ctype, spsh_opts, 0); + if ~(spsh_opts.formulas_as_text) + # Find formulas (designated by a string starting with "=" and ending in ")") + fptr = cellfun (@(x) ischar (x) && strncmp (x, "=", 1) && strncmp (x(end:end), ")", 1), c_arr); + typearr(fptr) = ctype(4); # FORMULA + endif # Prepare worksheet for writing. If needed create new sheet - if (newsh) - if (ods.changed > 2) - # New spreadsheet. Prepare to use the default 1x1 first sheet. - sh = sheets.item(0); - else - # Other sheets exist, create a new sheet. First the basics - sh = java_new ('org.odftoolkit.odfdom.doc.table.OdfTable', odfcont); - # Append sheet to spreadsheet ( contentRoot) - offsprdsh.appendChild (sh); - # Rebuild sheets nodes - sheets = xpath.evaluate ("//table:table", odfcont, NODESET); - endif + if (newsh) + if (ods.changed > 2) + # New spreadsheet. Prepare to use the default 1x1 first sheet. + sh = sheets.item(0); + else + # Other sheets exist, create a new sheet. First the basics + sh = java_new ('org.odftoolkit.odfdom.doc.table.OdfTable', odfcont); + # Append sheet to spreadsheet ( contentRoot) + offsprdsh.appendChild (sh); + # Rebuild sheets nodes + sheets = xpath.evaluate ("//table:table", odfcont, NODESET); + endif - # Sheet name - if (isnumeric (wsh)) - # Give sheet a name - str = sprintf ("Sheet%d", wsh); - sh.setTableNameAttribute (str); - else - # Assign name to sheet and change wsh into numeric pointer - sh.setTableNameAttribute (wsh); - wsh = sheets.getLength () - 1; - endif - # Fixup wsh pointer in case of new spreadsheet - if (ods.changed > 2) wsh = 0; endif + # Sheet name + if (isnumeric (wsh)) + # Give sheet a name + str = sprintf ("Sheet%d", wsh); + sh.setTableNameAttribute (str); + else + # Assign name to sheet and change wsh into numeric pointer + sh.setTableNameAttribute (wsh); + wsh = sheets.getLength () - 1; + endif + # Fixup wsh pointer in case of new spreadsheet + if (ods.changed > 2) wsh = 0; endif - # Add table-column entry for style etc - col = sh.addTableColumn (); - col.setTableDefaultCellStyleNameAttribute ("Default"); - col.setTableNumberColumnsRepeatedAttribute (lcol + ncols + 1); - col.setTableStyleNameAttribute ("co1"); + # Add table-column entry for style etc + col = sh.addTableColumn (); + col.setTableDefaultCellStyleNameAttribute ("Default"); + col.setTableNumberColumnsRepeatedAttribute (lcol + ncols + 1); + col.setTableStyleNameAttribute ("co1"); - # Build up the complete row & cell structure to cover the data array. - # This will speed up processing later + # Build up the complete row & cell structure to cover the data array. + # This will speed up processing later - # 1. Build empty table row template - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - # Create an empty tablecell & append it to the row - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - scell = row.appendCell (scell); - scell.setTableNumberColumnsRepeatedAttribute (1024); - # 2. If needed add empty filler row above the data rows & if needed add repeat count - if (trow > 0) - sh.appendRow (row); - if (trow > 1) row.setTableNumberRowsRepeatedAttribute (trow); endif - endif - # 3. Add data rows; first one serves as a template - drow = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - if (lcol > 0) - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - drow.appendCell (scell); - if (lcol > 1) scell.setTableNumberColumnsRepeatedAttribute (lcol); endif - endif - # 4. Add data cell placeholders - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - drow.appendCell (scell); - for jj=2:ncols - dcell = scell.cloneNode (1); # Deep copy - drow.appendCell (dcell); - endfor - # 5. Last cell is remaining column counter - rest = max (1024 - lcol - ncols); - if (rest) - dcell = scell.cloneNode (1); # Deep copy - drow.appendCell (dcell); - if (rest > 1) dcell.setTableNumberColumnsRepeatedAttribute (rest); endif - endif - # Only now add drow as otherwise for each cell an empty table-column is - # inserted above the rows (odftoolkit bug?) - sh.appendRow (drow); - if (ods.changed > 2) - # In case of a completely new spreadsheet, delete the first initial 1-cell row - # But check if it *is* a row... - try - sh.removeChild (drow.getPreviousRow ()); - catch - # Nothing. Apparently there was only the just appended row. - end_try_catch - endif - # 6. Row template ready. Copy row template down to cover future array - for ii=2:nrows - nrow = drow.cloneNode (1); # Deep copy - sh.appendRow (nrow); - endfor - ods.changed = min (ods.changed, 2); # Keep 2 for new spshsht, 1 for existing + changed + # 1. Build empty table row template + row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); + # Create an empty tablecell & append it to the row + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + scell = row.appendCell (scell); + scell.setTableNumberColumnsRepeatedAttribute (1024); + # 2. If needed add empty filler row above the data rows & if needed add repeat count + if (trow > 0) + sh.appendRow (row); + if (trow > 1) row.setTableNumberRowsRepeatedAttribute (trow); endif + endif + # 3. Add data rows; first one serves as a template + drow = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); + if (lcol > 0) + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + drow.appendCell (scell); + if (lcol > 1) scell.setTableNumberColumnsRepeatedAttribute (lcol); endif + endif + # 4. Add data cell placeholders + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + drow.appendCell (scell); + for jj=2:ncols + dcell = scell.cloneNode (1); # Deep copy + drow.appendCell (dcell); + endfor + # 5. Last cell is remaining column counter + rest = max (1024 - lcol - ncols); + if (rest) + dcell = scell.cloneNode (1); # Deep copy + drow.appendCell (dcell); + if (rest > 1) dcell.setTableNumberColumnsRepeatedAttribute (rest); endif + endif + # Only now add drow as otherwise for each cell an empty table-column is + # inserted above the rows (odftoolkit bug?) + sh.appendRow (drow); + if (ods.changed > 2) + # In case of a completely new spreadsheet, delete the first initial 1-cell row + # But check if it *is* a row... + try + sh.removeChild (drow.getPreviousRow ()); + catch + # Nothing. Apparently there was only the just appended row. + end_try_catch + endif + # 6. Row template ready. Copy row template down to cover future array + for ii=2:nrows + nrow = drow.cloneNode (1); # Deep copy + sh.appendRow (nrow); + endfor + ods.changed = min (ods.changed, 2); # Keep 2 for new spshsht, 1 for existing + changed - else - # Existing sheet. We must be prepared for all situations, incomplete rows, - # number-rows/columns-repeated, merged (spanning) cells, you name it. - # First explore row buildup of existing sheet using an XPath - sh = sheets.item(wsh); # 0 - based - str = sprintf ("//table:table[%d]/table:table-row", wsh + 1); # 1 - based - trows = xpath.evaluate (str, odfcont, NODESET); - nr_of_trows = trows.getLength(); # Nr. of existing table-rows, not data rows! + else + # Existing sheet. We must be prepared for all situations, incomplete rows, + # number-rows/columns-repeated, merged (spanning) cells, you name it. + # First explore row buildup of existing sheet using an XPath + sh = sheets.item(wsh); # 0 - based + str = sprintf ("//table:table[%d]/table:table-row", wsh + 1); # 1 - based + trows = xpath.evaluate (str, odfcont, NODESET); + nr_of_trows = trows.getLength(); # Nr. of existing table-rows, not data rows! - # For the first rows we do some preprocessing here. Similar stuff for cells - # i.e. table-cells (columns) is done in the loops below. - # Make sure the upper data array row doesn't end up in a nr-rows-repeated row + # For the first rows we do some preprocessing here. Similar stuff for cells + # i.e. table-cells (columns) is done in the loops below. + # Make sure the upper data array row doesn't end up in a nr-rows-repeated row - # Provisionally! set start table-row in case "while" & "if" (split) are skipped - drow = trows.item(0); - rowcnt = 0; trowcnt = 0; # Spreadsheet/ table-rows, resp; - while (rowcnt < trow && trowcnt < nr_of_trows) - # Count rows & table-rows UNTIL we reach trow - ++trowcnt; # Nr of table-rows - row = drow; - drow = row.getNextSibling (); - repcnt = row.getTableNumberRowsRepeatedAttribute(); - rowcnt = rowcnt + repcnt; # Nr of spreadsheet rows - endwhile - rsplit = rowcnt - trow; - if (rsplit > 0) - # Apparently a nr-rows-repeated top table-row must be split, as the - # first data row seems to be projected in it (1st while condition above!) - row.removeAttribute ('table:number-rows-repeated'); - row.getCellAt (0).removeAttribute ('table:number-columns-repeated'); - nrow = row.cloneNode (1); - drow = nrow; # Future upper data array row - if (repcnt > 1) - row.setTableNumberRowsRepeatedAttribute (repcnt - rsplit); - else - row.removeAttribute ('table:number-rows-repeated'); - endif - rrow = row.getNextSibling (); - sh.insertBefore (nrow, rrow); - for jj=2:rsplit - nrow = nrow.cloneNode (1); - sh.insertBefore (nrow, rrow); - endfor - elseif (rsplit < 0) - # New data rows to be added below existing data & table(!) rows, i.e. - # beyond lower end of the current sheet. Add filler row and 1st data row - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - drow = row.cloneNode (1); # First data row - row.setTableNumberRowsRepeatedAttribute (-rsplit); # Filler row - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - dcell = scell.cloneNode (1); - scell.setTableNumberColumnsRepeatedAttribute (COL_CAP); # Filler cell - row.appendCell (scell); - sh.appendRow (row); - drow.appendCell (dcell); - sh.appendRow (drow); - endif - endif + # Provisionally! set start table-row in case "while" & "if" (split) are skipped + drow = trows.item(0); + rowcnt = 0; trowcnt = 0; # Spreadsheet/ table-rows, resp; + while (rowcnt < trow && trowcnt < nr_of_trows) + # Count rows & table-rows UNTIL we reach trow + ++trowcnt; # Nr of table-rows + row = drow; + drow = row.getNextSibling (); + repcnt = row.getTableNumberRowsRepeatedAttribute(); + rowcnt = rowcnt + repcnt; # Nr of spreadsheet rows + endwhile + rsplit = rowcnt - trow; + if (rsplit > 0) + # Apparently a nr-rows-repeated top table-row must be split, as the + # first data row seems to be projected in it (1st while condition above!) + row.removeAttribute ('table:number-rows-repeated'); + row.getCellAt (0).removeAttribute ('table:number-columns-repeated'); + nrow = row.cloneNode (1); + drow = nrow; # Future upper data array row + if (repcnt > 1) + row.setTableNumberRowsRepeatedAttribute (repcnt - rsplit); + else + row.removeAttribute ('table:number-rows-repeated'); + endif + rrow = row.getNextSibling (); + sh.insertBefore (nrow, rrow); + for jj=2:rsplit + nrow = nrow.cloneNode (1); + sh.insertBefore (nrow, rrow); + endfor + elseif (rsplit < 0) + # New data rows to be added below existing data & table(!) rows, i.e. + # beyond lower end of the current sheet. Add filler row and 1st data row + row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); + drow = row.cloneNode (1); # First data row + row.setTableNumberRowsRepeatedAttribute (-rsplit); # Filler row + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + dcell = scell.cloneNode (1); + scell.setTableNumberColumnsRepeatedAttribute (COL_CAP); # Filler cell + row.appendCell (scell); + sh.appendRow (row); + drow.appendCell (dcell); + sh.appendRow (drow); + endif + endif # For each row, for each cell, add the data. Expand row/column-repeated nodes - row = drow; # Start row; pointer still exists from above stanzas - for ii=1:nrows - if (~newsh) # Only for existing sheets the next checks should be made - # While processing next data rows, fix table-rows if needed - if (isempty (row) || (row.getLength () < 1)) - # Append an empty row with just one empty cell - row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - scell.setTableNumberColumnsRepeatedAttribute (lcol + 1); - row.appendCell (scell); - sh.appendRow (row); - else - # If needed expand nr-rows-repeated - repcnt = row.getTableNumberRowsRepeatedAttribute (); - if (repcnt > 1) - row.removeAttribute ('table:number-rows-repeated'); - # Insert new table-rows above row until our new data space is complete. - # Keep handle of upper new table-row as that's where data are added 1st - drow = row.cloneNode (1); - sh.insertBefore (drow, row); - for kk=1:min (repcnt, nrows-ii) - nrow = row.cloneNode (1); - sh.insertBefore (nrow, row); - endfor - if (repcnt > nrows-ii+1) - row.setTableNumberRowsRepeatedAttribute (repcnt - nrows +ii - 1); - endif - row = drow; - endif - endif + row = drow; # Start row; pointer still exists from above stanzas + for ii=1:nrows + if (~newsh) # Only for existing sheets the next checks should be made + # While processing next data rows, fix table-rows if needed + if (isempty (row) || (row.getLength () < 1)) + # Append an empty row with just one empty cell + row = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableRow', odfcont); + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + scell.setTableNumberColumnsRepeatedAttribute (lcol + 1); + row.appendCell (scell); + sh.appendRow (row); + else + # If needed expand nr-rows-repeated + repcnt = row.getTableNumberRowsRepeatedAttribute (); + if (repcnt > 1) + row.removeAttribute ('table:number-rows-repeated'); + # Insert new table-rows above row until our new data space is complete. + # Keep handle of upper new table-row as that's where data are added 1st + drow = row.cloneNode (1); + sh.insertBefore (drow, row); + for kk=1:min (repcnt, nrows-ii) + nrow = row.cloneNode (1); + sh.insertBefore (nrow, row); + endfor + if (repcnt > nrows-ii+1) + row.setTableNumberRowsRepeatedAttribute (repcnt - nrows +ii - 1); + endif + row = drow; + endif + endif - # Check if leftmost cell ends up in nr-cols-repeated cell - colcnt = 0; tcellcnt = 0; rcellcnt = row.getLength(); - dcell = row.getCellAt (0); - while (colcnt < lcol && tcellcnt < rcellcnt) - # Count columns UNTIL we hit lcol - ++tcellcnt; # Nr of table-cells counted - scell = dcell; - dcell = scell.getNextSibling (); - repcnt = scell.getTableNumberColumnsRepeatedAttribute (); - colcnt = colcnt + repcnt; # Nr of spreadsheet cell counted - endwhile - csplit = colcnt - lcol; - if (csplit > 0) - # Apparently a nr-columns-repeated cell must be split - scell.removeAttribute ('table:number-columns-repeated'); - ncell = scell.cloneNode (1); - if (repcnt > 1) - scell.setTableNumberColumnsRepeatedAttribute (repcnt - csplit); - else - scell.removeAttribute ('table:number-columns-repeated'); - endif - rcell = scell.getNextSibling (); - row.insertBefore (ncell, rcell); - for jj=2:csplit - ncell = ncell.cloneNode (1); - row.insertBefore (ncell, rcell); - endfor - elseif (csplit < 0) - # New cells to be added beyond current last cell & table-cell in row - dcell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - scell = dcell.cloneNode (1); - dcell.setTableNumberColumnsRepeatedAttribute (-csplit); - row.appendCell (dcell); - row.appendCell (scell); - endif - endif + # Check if leftmost cell ends up in nr-cols-repeated cell + colcnt = 0; tcellcnt = 0; rcellcnt = row.getLength(); + dcell = row.getCellAt (0); + while (colcnt < lcol && tcellcnt < rcellcnt) + # Count columns UNTIL we hit lcol + ++tcellcnt; # Nr of table-cells counted + scell = dcell; + dcell = scell.getNextSibling (); + repcnt = scell.getTableNumberColumnsRepeatedAttribute (); + colcnt = colcnt + repcnt; # Nr of spreadsheet cell counted + endwhile + csplit = colcnt - lcol; + if (csplit > 0) + # Apparently a nr-columns-repeated cell must be split + scell.removeAttribute ('table:number-columns-repeated'); + ncell = scell.cloneNode (1); + if (repcnt > 1) + scell.setTableNumberColumnsRepeatedAttribute (repcnt - csplit); + else + scell.removeAttribute ('table:number-columns-repeated'); + endif + rcell = scell.getNextSibling (); + row.insertBefore (ncell, rcell); + for jj=2:csplit + ncell = ncell.cloneNode (1); + row.insertBefore (ncell, rcell); + endfor + elseif (csplit < 0) + # New cells to be added beyond current last cell & table-cell in row + dcell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + scell = dcell.cloneNode (1); + dcell.setTableNumberColumnsRepeatedAttribute (-csplit); + row.appendCell (dcell); + row.appendCell (scell); + endif + endif - # Write a row of data from data array, column by column - - for jj=1:ncols - scell = row.getCellAt (lcol + jj - 1); - if (~newsh) - if (isempty (scell)) - # Apparently end of row encountered. Add cell - scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); - scell = row.appendCell (scell); - else - # If needed expand nr-cols-repeated - repcnt = scell.getTableNumberColumnsRepeatedAttribute (); - if (repcnt > 1) - scell.removeAttribute ('table:number-columns-repeated'); - for kk=2:repcnt - ncell = scell.cloneNode (1); - row.insertBefore (ncell, scell.getNextSibling ()); - endfor - endif - endif - # Clear text contents - while (scell.hasChildNodes ()) - tmp = scell.getFirstChild (); - scell.removeChild (tmp); - endwhile - scell.removeAttribute ('table:formula'); - endif + # Write a row of data from data array, column by column + + for jj=1:ncols + scell = row.getCellAt (lcol + jj - 1); + if (~newsh) + if (isempty (scell)) + # Apparently end of row encountered. Add cell + scell = java_new ('org.odftoolkit.odfdom.doc.table.OdfTableCell', odfcont); + scell = row.appendCell (scell); + else + # If needed expand nr-cols-repeated + repcnt = scell.getTableNumberColumnsRepeatedAttribute (); + if (repcnt > 1) + scell.removeAttribute ('table:number-columns-repeated'); + for kk=2:repcnt + ncell = scell.cloneNode (1); + row.insertBefore (ncell, scell.getNextSibling ()); + endfor + endif + endif + # Clear text contents + while (scell.hasChildNodes ()) + tmp = scell.getFirstChild (); + scell.removeChild (tmp); + endwhile + scell.removeAttribute ('table:formula'); + endif - # Empty cell count stuff done. At last we can add the data - switch (typearr (ii, jj)) - case 1 # float - scell.setOfficeValueTypeAttribute ('float'); - scell.setOfficeValueAttribute (c_arr{ii, jj}); - case 2 # boolean - # Beware, for unpatched-for-booleans java-1.2.7- we must resort to floats - try - # First try the preferred java-boolean way - scell.setOfficeValueTypeAttribute ('boolean'); - scell.removeAttribute ('office:value'); - if (c_arr{ii, jj}) - scell.setOfficeBooleanValueAttribute (1); - else - scell.setOfficeBooleanValueAttribute (0); - endif - catch - # Unpatched java package. Fall back to transferring a float - scell.setOfficeValueTypeAttribute ('float'); - if (c_arr{ii, jj}) - scell.setOfficeValueAttribute (1); - else - scell.setOfficeValueAttribute (0); - endif - end_try_catch - case 3 # string - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); - scell.appendChild (pe); - case 4 # Formula. - # As we don't know the result type, simply remove previous type info. - # Once OOo Calc reads it, it'll add the missing attributes - scell.removeAttribute ('office:value'); - scell.removeAttribute ('office:value-type'); - # Try-catch not strictly needed, there's no formula validator yet - try - scell.setTableFormulaAttribute (c_arr{ii, jj}); - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', '#Recalc Formula#'); - scell.appendChild (pe); - catch - ++f_errs; - scell.setOfficeValueTypeAttribute ('string'); - pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); - scell.appendChild (pe); - end_try_catch - case {0 5} # Empty. Clear value attributes - if (~newsh) - scell.removeAttribute ('office:value-type'); - scell.removeAttribute ('office:value'); - endif - case 6 # Date (implemented but Octave has no "date" data type - yet?) - scell.setOfficeValueTypeAttribute ('date'); - [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); - str = sprintf ("%4d-%2d-%2dT%2d:%2d:%2d", yy, mo, dd, hh, mi, ss); - scell.setOfficeDateValueAttribute (str); - case 7 # Time (implemented but Octave has no "time" data type) - scell.setOfficeValueTypeAttribute ('time'); - [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); - str = sprintf ("PT%2d:%2d:%2d", hh, mi, ss); - scell.setOfficeTimeValuettribute (str); - otherwise - # Nothing - endswitch + # Empty cell count stuff done. At last we can add the data + switch (typearr (ii, jj)) + case 1 # float + scell.setOfficeValueTypeAttribute ('float'); + scell.setOfficeValueAttribute (c_arr{ii, jj}); + case 2 # boolean + # Beware, for unpatched-for-booleans java-1.2.7- we must resort to floats + try + # First try the preferred java-boolean way + scell.setOfficeValueTypeAttribute ('boolean'); + scell.removeAttribute ('office:value'); + if (c_arr{ii, jj}) + scell.setOfficeBooleanValueAttribute (1); + else + scell.setOfficeBooleanValueAttribute (0); + endif + catch + # Unpatched java package. Fall back to transferring a float + scell.setOfficeValueTypeAttribute ('float'); + if (c_arr{ii, jj}) + scell.setOfficeValueAttribute (1); + else + scell.setOfficeValueAttribute (0); + endif + end_try_catch + case 3 # string + scell.setOfficeValueTypeAttribute ('string'); + pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); + scell.appendChild (pe); + case 4 # Formula. + # As we don't know the result type, simply remove previous type info. + # Once OOo Calc reads it, it'll add the missing attributes + scell.removeAttribute ('office:value'); + scell.removeAttribute ('office:value-type'); + # Try-catch not strictly needed, there's no formula validator yet + try + scell.setTableFormulaAttribute (c_arr{ii, jj}); + scell.setOfficeValueTypeAttribute ('string'); + pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', '#Recalc Formula#'); + scell.appendChild (pe); + catch + ++f_errs; + scell.setOfficeValueTypeAttribute ('string'); + pe = java_new ('org.odftoolkit.odfdom.doc.text.OdfTextParagraph', odfcont,'', c_arr{ii, jj}); + scell.appendChild (pe); + end_try_catch + case {0 5} # Empty. Clear value attributes + if (~newsh) + scell.removeAttribute ('office:value-type'); + scell.removeAttribute ('office:value'); + endif + case 6 # Date (implemented but Octave has no "date" data type - yet?) + scell.setOfficeValueTypeAttribute ('date'); + [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); + str = sprintf ("%4d-%2d-%2dT%2d:%2d:%2d", yy, mo, dd, hh, mi, ss); + scell.setOfficeDateValueAttribute (str); + case 7 # Time (implemented but Octave has no "time" data type) + scell.setOfficeValueTypeAttribute ('time'); + [hh mo dd hh mi ss] = datevec (c_arr{ii,jj}); + str = sprintf ("PT%2d:%2d:%2d", hh, mi, ss); + scell.setOfficeTimeValuettribute (str); + otherwise + # Nothing + endswitch - scell = scell.getNextSibling (); + scell = scell.getNextSibling (); - endfor + endfor - row = row.getNextSibling (); + row = row.getNextSibling (); - endfor + endfor - if (f_errs) - printf ("%d formula errors encountered - please check input array\n", f_errs); - endif - ods.changed = max (min (ods.changed, 2), changed); # Preserve 2 (new file), 1 (existing) - rstatus = 1; - + if (f_errs) + printf ("%d formula errors encountered - please check input array\n", f_errs); + endif + ods.changed = max (min (ods.changed, 2), changed); # Preserve 2 (new file), 1 (existing) + rstatus = 1; + endfunction #============================================================================= -## Copyright (C) 2010,2011 Philip Nienhuis <prnienhuis _at- users.sf.net> +## Copyright (C) 2010,2011,2012 Philip Nienhuis <prnienhuis _at- users.sf.net> ## ## 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 @@ -662,9 +660,9 @@ ## You should have received a copy of the GNU General Public License along with ## this program; if not, see <http://www.gnu.org/licenses/>. -## odf3jotk2oct - read ODS spreadsheet data using Java & odftoolkit v 0.8.6. -## You need proper java-for-octave & odfdom.jar 0.8.6 + xercesImpl.jar -## in your javaclasspath. For reliable writing odfdom-0.8.6 is still +## odf3jotk2oct - read ODS spreadsheet data using Java & odftoolkit v 0.8.6+. +## You need proper java-for-octave & odfdom.jar 0.8.6+ & xercesImpl.jar 2.9.1 +## in your javaclasspath. For reliable writing odfdom-0.8.6+ is still ## experimental :-( v. 0.7.5 has been tested much more ## ## Author: Philip Nenhuis <pr.nienhuis at users.sf.net> @@ -684,167 +682,168 @@ ## 2010-11-12 Improved file change tracking tru ods.changed ## 2010-12-08 Bugfixes (obj -> arg L.715; removed stray arg in call to spsh_prstype L.719) ## 2011-03-23 First try of odfdom 0.8.7 +## 2012-06-08 Support for odfdom-incubator-0.8.8 function [ ods, rstatus ] = oct3jotk2ods (c_arr, ods, wsh, crange, spsh_opts) - persistent ctype; - if (isempty (ctype)) - # Number, Boolean, String, Formula, Empty; Date, Time - last two aren't used - ctype = [1, 2, 3, 4, 5, 6, 7]; - endif + persistent ctype; + if (isempty (ctype)) + # Number, Boolean, String, Formula, Empty; Date, Time - last two aren't used + ctype = [1, 2, 3, 4, 5, 6, 7]; + endif - rstatus = 0; changed = 0; newsh = 0; + rstatus = 0; changed = 0; newsh = 0; - # Get... [truncated message content] |
From: <be...@us...> - 2012-06-08 14:11:52
|
Revision: 10591 http://octave.svn.sourceforge.net/octave/?rev=10591&view=rev Author: benjf5 Date: 2012-06-08 14:11:42 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Fastlscomplex.cc runs, returns correct results. It isn't very fast, though. Modified Paths: -------------- trunk/octave-forge/extra/lssa/fastlscomplex.cc Modified: trunk/octave-forge/extra/lssa/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/fastlscomplex.cc 2012-06-07 22:11:08 UTC (rev 10590) +++ trunk/octave-forge/extra/lssa/fastlscomplex.cc 2012-06-08 14:11:42 UTC (rev 10591) @@ -1,10 +1,15 @@ +/* Copyright (C) 2012 Benjamin Lewis <be...@gm...> + * GNU GPLv2 + */ + #include <octave/oct.h> #include <octave/unwind-prot.h> #include <complex> #include <string> #include <math.h> #include <iostream> +#include <exception> ComplexRowVector flscomplex( RowVector tvec , ComplexRowVector xvec , int coefficients, int octaves, double maxfreq ); @@ -18,7 +23,6 @@ double omegamax = args(4).double_value(); octave_value_list retval; if ( !error_state) { - std::cout << "All values loaded safely! Your problem is in flscomplex." << std::endl; ComplexRowVector results = flscomplex(tvals,xvals,ncoeff,noctaves,omegamax); retval(0) = octave_value(results); } @@ -47,7 +51,6 @@ for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { temp_array[array_iter] = std::complex<double> ( 0 , 0 ); } - std::cout << "temp_array built." << std::endl; //errcheckline n_inv = 1.0 / n; mu = (0.5 * M_PI)/length; // Per the article; this is in place to improve numerical accuracy if desired. /* Viz. the paper, in which Dtau = c / omega_max, and c is stated as pi/2 for floating point processors, @@ -73,14 +76,14 @@ record_tail->next = 0; /* A test needs to be included for if there was a failure, but since * precomp_subset_count is of type size_t, it should be okay. */ - - for( ; record_current ; record_current = record_current->next ) { + for( ; record_current != 0 ; record_current = record_current->next ) { for ( int j = 0 ; j < 12 ; j++ ) { record_current->power_series[j] = std::complex<double> ( 0 , 0 ); } // To avoid any trouble down the line, although it is an annoyance. - while ( ( k < n ) && ( ( - delta_tau ) <= ( tvec(k) - tau_h ) ) && ( ( tvec(k) - tau_h ) < delta_tau ) ) { + // Error is traced this far. Time to see if it's in this loop. + while ( (k < n) && (abs(tvec(k)-tau_h) <= delta_tau) ) { double p; - alpha = std::complex<double> ( 0 , 0 ); + // alpha = std::complex<double> ( 0 , 0 ); for ( int j = 0 ; j < 12 ; j++ ) { alpha.real() = xvec(k).real(); alpha.imag() = xvec(k).imag(); @@ -117,7 +120,6 @@ } tau_h += ( 2 * delta_tau ); } - std::cout << "all records computed." << std::endl; // At this point all precomputation records have been exhausted; short-circuit is abused to avoid overflow errors. /* Summation of coefficients for each frequency. As we have ncoeffs * noctaves elements, @@ -138,19 +140,17 @@ for ( octave_iter = octaves ; ; omega_oct *= 0.5 , octavemax *= 0.5 , loop_tau_0 += loop_delta_tau , loop_delta_tau *= 2 ) { omega_working = omega_oct; + exp_term = std::complex<double> ( cos( - omega_working * loop_tau_0 ) , + sin ( - omega_working * loop_tau_0 ) ); + exp_multiplier = std::complex<double> ( cos ( - 2 * omega_working * loop_delta_tau ) , + sin ( - 2 * omega_working * loop_delta_tau ) ); for ( coeff_iter = 0 ; coeff_iter < coefficients ; coeff_iter++, omega_working *= omega_multiplier){ - exp_term = std::complex<double> ( cos( - omega_working * loop_tau_0 ) , - sin ( - omega_working * loop_tau_0 ) ); - exp_multiplier = std::complex<double> ( cos ( - 2 * omega_working * loop_delta_tau ) , - sin ( - 2 * omega_working * loop_delta_tau ) ); - // zeta = std::complex<double> (0,0); real_part_accumulator = 0; imag_part_accumulator = 0; real_part = 0; imag_part = 0; for ( record_current = precomp_records_head ; record_current ; record_current = record_current->next, exp_term *= exp_multiplier ) { - // z_accumulator = std::complex<double> ( 0 , 0 ); for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { z_accumulator = ( pow(omega_working,array_iter) * record_current->power_series[array_iter] ); real_part_accumulator += z_accumulator.real(); @@ -158,47 +158,23 @@ } real_part = real_part + ( exp_term.real() * real_part_accumulator - ( exp_term.imag() * imag_part_accumulator ) ); imag_part = imag_part + ( exp_term.imag() * real_part_accumulator + exp_term.real() * imag_part_accumulator ); - // zeta += ( exp_term * z_accumulator ); } results(iter) = std::complex<double> ( n_inv * real_part , n_inv * imag_part ); - std::cout << iter << std::endl; iter++; } if ( !(--octave_iter) ) break; /* If we've already reached the lowest value, stop. * Otherwise, merge with the next computation range. */ - std::cout << "100 terms precomputed" << std::endl; double exp_power_series_elements[12]; for ( int r_iter = 0 ; r_iter < 12 ; r_iter++ ) { exp_power_series_elements[r_iter] = ( r_iter == 0 ) ? 1 : exp_power_series_elements[r_iter-1] * ( mu * loop_delta_tau) * ( 1.0 / ( (double) r_iter ) ); } - std::cout << "Exponential series computed" << std::endl; - for ( record_current = precomp_records_head ; record_current ; - record_current = record_current->next ) { - if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { - if ( record_current->stored_data ) { - std::complex<double> temp[12]; - for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } - for( int p = 0 ; p < 12 ; p ++ ) { - double step_floor_r = floor( ( (double) p ) / 2.0 ); - double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); - for( int q = 0 ; q < step_floor_r ; q++ ) { - temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q )]; - } - for( int q = 0 ; q <= step_floor_i ; q++ ) { - temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q ) - 1]; - } - } - for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { - record_current->power_series[array_iter].real() = temp[array_iter].real(); - record_current->power_series[array_iter].imag() = temp[array_iter].imag(); - } - if ( ! record_ref ) break; // Last record was reached - } - else { - record_next = record_ref; + try{ + for ( record_current = precomp_records_head ; record_current ; + record_current = record_current->next ) { + if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { if ( record_current->stored_data ) { std::complex<double> temp[12]; for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } @@ -206,40 +182,67 @@ double step_floor_r = floor( ( (double) p ) / 2.0 ); double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); for( int q = 0 ; q < step_floor_r ; q++ ) { - temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q )] - record_next->power_series[p - (2*q)] ); + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q )]; } for( int q = 0 ; q <= step_floor_i ; q++ ) { - temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q ) - 1] - record_next->power_series[p - ( 2 * q ) - 1 ] ); + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q ) - 1]; } } for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { record_current->power_series[array_iter].real() = temp[array_iter].real(); record_current->power_series[array_iter].imag() = temp[array_iter].imag(); } - } else { - std::complex<double> temp[12]; - for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } - for( int p = 0 ; p < 12 ; p ++ ) { - double step_floor_r = floor( ( (double) p ) / 2.0 ); - double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); - for( int q = 0 ; q < step_floor_r ; q++ ) { - temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_next->power_series[p - ( 2 * q )]; + if ( ! record_ref ) break; // Last record was reached + } + else { + record_next = record_ref; + if ( record_current->stored_data ) { + std::complex<double> temp[12]; + for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } + for( int p = 0 ; p < 12 ; p ++ ) { + double step_floor_r = floor( ( (double) p ) / 2.0 ); + double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); + for( int q = 0 ; q < step_floor_r ; q++ ) { + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q )] - record_next->power_series[p - (2*q)] ); + } + for( int q = 0 ; q <= step_floor_i ; q++ ) { + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q ) - 1] - record_next->power_series[p - ( 2 * q ) - 1 ] ); + } } - for( int q = 0 ; q <= step_floor_i ; q++ ) { - temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,(q+1)) * record_next->power_series[p - ( 2 * q ) - 1]; + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + record_current->power_series[array_iter].real() = temp[array_iter].real(); + record_current->power_series[array_iter].imag() = temp[array_iter].imag(); } + } else { + std::complex<double> temp[12]; + for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } + for( int p = 0 ; p < 12 ; p ++ ) { + double step_floor_r = floor( ( (double) p ) / 2.0 ); + double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); + for( int q = 0 ; q < step_floor_r ; q++ ) { + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_next->power_series[p - ( 2 * q )]; + } + for( int q = 0 ; q <= step_floor_i ; q++ ) { + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,(q+1)) * record_next->power_series[p - ( 2 * q ) - 1]; + } + } + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + record_current->power_series[array_iter].real() = temp[array_iter].real(); + record_current->power_series[array_iter].imag() = temp[array_iter].imag(); + } } - for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { - record_current->power_series[array_iter].real() = temp[array_iter].real(); - record_current->power_series[array_iter].imag() = temp[array_iter].imag(); - } + record_current->stored_data = true; + record_ref = record_next; + record_current->next = record_ref->next; + delete record_ref; } - record_current->stored_data = true; - record_ref = record_next; - record_current->next = record_ref->next; - delete record_ref; } } + } catch (std::exception& e) { //This section was part of my debugging, and may be removed. + std::cout << "Exception thrown: " << e.what() << std::endl; + ComplexRowVector exception_result (1); + exception_result(0) = std::complex<double> ( 0,0); + return exception_result; } } return results; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-07 22:11:14
|
Revision: 10590 http://octave.svn.sourceforge.net/octave/?rev=10590&view=rev Author: prnienhuis Date: 2012-06-07 22:11:08 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Stricter formula recovery check & adapted to COM formula support Modified Paths: -------------- trunk/octave-forge/main/io/inst/io_xls_testscript.m Modified: trunk/octave-forge/main/io/inst/io_xls_testscript.m =================================================================== --- trunk/octave-forge/main/io/inst/io_xls_testscript.m 2012-06-07 22:10:30 UTC (rev 10589) +++ trunk/octave-forge/main/io/inst/io_xls_testscript.m 2012-06-07 22:11:08 UTC (rev 10590) @@ -106,7 +106,7 @@ try # Just check if it contains any string - assert ( (ischar (raw{3, 3}) && ~isempty (raw(3, 3))), true); + assert ( (ischar (raw{3, 3}) && ~isempty (raw(3, 3)) && raw{3, 3}(1) == "="), true); printf (" ...OK, formula recovered ('%s').\n", raw{3, 3}); catch printf ("Hmmm.... error, see 'raw(3, 3)'"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-07 22:10:37
|
Revision: 10589 http://octave.svn.sourceforge.net/octave/?rev=10589&view=rev Author: prnienhuis Date: 2012-06-07 22:10:30 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Replaced tabs by double space Modified Paths: -------------- trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m trunk/octave-forge/main/io/inst/xlswrite.m Modified: trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m =================================================================== --- trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m 2012-06-07 22:09:56 UTC (rev 10588) +++ trunk/octave-forge/main/io/inst/chk_spreadsheet_support.m 2012-06-07 22:10:30 UTC (rev 10589) @@ -83,350 +83,351 @@ % 2011-09-03 Small fix to better detect Basis* subdir when searching unoil.jar % 2011-09-18 Fixed 'Matlab style short circuit' warning in L. 152 % 2012-12-24 Amended code stanze to find unoil.jar; now works in LibreOffice 3.5b2 as well +% 2012-06-07 Replaced all tabs by double space - jcp = []; retval = 0; - if (nargin < 3); path_to_ooo= ''; end %if + jcp = []; retval = 0; + if (nargin < 3); path_to_ooo= ''; end %if if (nargin < 2); dbug = 0; end %if - isOctave = exist ('OCTAVE_VERSION', 'builtin') ~= 0; + isOctave = exist ('OCTAVE_VERSION', 'builtin') ~= 0; if (dbug); fprintf ('\n'); end %if - % interfaces = {'COM', 'POI', 'POI+OOXML', 'JXL', 'OXS', 'OTK', 'JOD', 'UNO'}; % Order = vital + % interfaces = {'COM', 'POI', 'POI+OOXML', 'JXL', 'OXS', 'OTK', 'JOD', 'UNO'}; % Order = vital - % Check if MS-Excel COM ActiveX server runs - if (dbug), fprintf ('Checking Excel/ActiveX/COM... '); end %if - try - app = actxserver ('Excel.application'); - % If we get here, the call succeeded & COM works. - xlsinterfaces.COM = 1; - % Close Excel to avoid zombie Excel invocation - app.Quit(); - delete(app); - if (dbug), fprintf ('OK.\n\n'); end %if - retval = retval + 1; - catch - % COM not supported - if (dbug), fprintf ('not working.\n\n'); end %if + % Check if MS-Excel COM ActiveX server runs + if (dbug), fprintf ('Checking Excel/ActiveX/COM... '); end %if + try + app = actxserver ('Excel.application'); + % If we get here, the call succeeded & COM works. + xlsinterfaces.COM = 1; + % Close Excel to avoid zombie Excel invocation + app.Quit(); + delete(app); + if (dbug), fprintf ('OK.\n\n'); end %if + retval = retval + 1; + catch + % COM not supported + if (dbug), fprintf ('not working.\n\n'); end %if end %try_catch % Check Java - if (dbug), fprintf ('Checking Java support...\n'); end %if - if (dbug > 1), fprintf (' 1. Checking Java JRE presence.... '); end %if - % Try if Java is installed at all - if (isOctave) - if (ispc) - jtst = (system ('java -version 2> nul')); - else - jtst = (system ('java -version 2> /dev/null')); - end %if - else - tst1 = version ('-java'); + if (dbug), fprintf ('Checking Java support...\n'); end %if + if (dbug > 1), fprintf (' 1. Checking Java JRE presence.... '); end %if + % Try if Java is installed at all + if (isOctave) + if (ispc) + jtst = (system ('java -version 2> nul')); + else + jtst = (system ('java -version 2> /dev/null')); + end %if + else + tst1 = version ('-java'); jtst = isempty (strfind (tst1, 'Java')); - end %if - if (jtst) - error ('Apparently no Java JRE installed.'); - else - if (dbug > 1), fprintf ('OK, found one.\n'); end %if - end %if - if (dbug > 1 && isOctave), fprintf (' 2. Checking Octave Java support... '); end %if - try - jcp = javaclasspath ('-all'); % For Octave java pkg > 1.2.7 - if (isempty (jcp)), jcp = javaclasspath; end %if % For Octave java pkg < 1.2.8 - % If we get here, at least Java works. - if (dbug > 1 && isOctave), fprintf ('Java package seems to work OK.\n'); end %if - % Now check for proper version (> 1.6.x.x) - jver = char (javaMethod ('getProperty', 'java.lang.System', 'java.version')); - cjver = strsplit (jver, '.'); - if (sscanf (cjver{2}, '%d') < 6) - if (dbug) - fprintf (' Java version (%s) too old - you need at least Java 6 (v. 1.6.x.x)\n', jver); - if (isOctave) - warning (' At Octave prompt, try "!system ("java -version")"'); - else - warning (' At Matlab prompt, try "version -java"'); - end %if - end %if - return - else - if (dbug > 2), fprintf (' Java (version %s) seems OK.\n', jver); end %if - end %if - % Under *nix the classpath must first be split up. - % Matlab is braindead here. For ML we need a replacement for Octave's builtin strsplit() - % This is found on ML Central (BSD license so this is allowed) & adapted for input arg order - if (isunix && ~iscell (jcp)); jcp = strsplit (char (jcp), ':'); end %if - if (dbug > 1) - % Check JVM virtual memory settings - jrt = javaMethod ('getRuntime', 'java.lang.Runtime'); - jmem = jrt.maxMemory (); + end %if + if (jtst) + error ('Apparently no Java JRE installed.'); + else + if (dbug > 1), fprintf ('OK, found one.\n'); end %if + end %if + if (dbug > 1 && isOctave), fprintf (' 2. Checking Octave Java support... '); end %if + try + jcp = javaclasspath ('-all'); % For Octave java pkg > 1.2.7 + if (isempty (jcp)), jcp = javaclasspath; end %if % For Octave java pkg < 1.2.8 + % If we get here, at least Java works. + if (dbug > 1 && isOctave), fprintf ('Java package seems to work OK.\n'); end %if + % Now check for proper version (> 1.6.x.x) + jver = char (javaMethod ('getProperty', 'java.lang.System', 'java.version')); + cjver = strsplit (jver, '.'); + if (sscanf (cjver{2}, '%d') < 6) + if (dbug) + fprintf (' Java version (%s) too old - you need at least Java 6 (v. 1.6.x.x)\n', jver); + if (isOctave) + warning (' At Octave prompt, try "!system ("java -version")"'); + else + warning (' At Matlab prompt, try "version -java"'); + end %if + end %if + return + else + if (dbug > 2), fprintf (' Java (version %s) seems OK.\n', jver); end %if + end %if + % Under *nix the classpath must first be split up. + % Matlab is braindead here. For ML we need a replacement for Octave's builtin strsplit() + % This is found on ML Central (BSD license so this is allowed) & adapted for input arg order + if (isunix && ~iscell (jcp)); jcp = strsplit (char (jcp), ':'); end %if + if (dbug > 1) + % Check JVM virtual memory settings + jrt = javaMethod ('getRuntime', 'java.lang.Runtime'); + jmem = jrt.maxMemory (); if (isOctave), jmem = jmem.doubleValue(); end %if - jmem = int16 (jmem/1024/1024); - fprintf (' Maximum JVM memory: %5d MiB; ', jmem); - if (jmem < 400) - fprintf ('should better be at least 400 MB!\n'); - fprintf (' Hint: adapt setting -Xmx in file "java.opts" (supposed to be here:)\n'); - if (isOctave) - fprintf (' %s\n', [matlabroot filesep 'share' filesep 'octave' filesep 'packages' filesep 'java-<version>' filesep 'java.opts']); - else - fprintf (' $matlabroot/bin/<arch>]\n'); - end %if - else - fprintf ('sufficient.\n'); - end %if - end %if - if (dbug), fprintf ('Java support OK\n'); end %if + jmem = int16 (jmem/1024/1024); + fprintf (' Maximum JVM memory: %5d MiB; ', jmem); + if (jmem < 400) + fprintf ('should better be at least 400 MB!\n'); + fprintf (' Hint: adapt setting -Xmx in file "java.opts" (supposed to be here:)\n'); + if (isOctave) + fprintf (' %s\n', [matlabroot filesep 'share' filesep 'octave' filesep 'packages' filesep 'java-<version>' filesep 'java.opts']); + else + fprintf (' $matlabroot/bin/<arch>]\n'); + end %if + else + fprintf ('sufficient.\n'); + end %if + end %if + if (dbug), fprintf ('Java support OK\n'); end %if catch - error ('No Java support found: %s.', lasterr); - end %try_catch + error ('No Java support found: %s.', lasterr); + end %try_catch - if (dbug), fprintf ('\nChecking javaclasspath for .jar class libraries needed for spreadsheet I/O...:\n'); end %if + if (dbug), fprintf ('\nChecking javaclasspath for .jar class libraries needed for spreadsheet I/O...:\n'); end %if - % Try Java & Apache POI. First Check basic .xls (BIFF8) support - if (dbug > 1), fprintf ('\nBasic POI (.xls) <poi-3> <poi-ooxml>:\n'); end %if - jpchk1 = 0; entries1 = {'poi-3', 'poi-ooxml-3'}; missing1 = zeros (1, numel (entries1)); - % Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) - % as javaclasspath is one long string. Under Windows however classpath is a cell array - % so we need the following more subtle, platform-independent approach: - for jj=1:length (entries1) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries1{jj})))) - jpchk1 = jpchk1 + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end %if - end %for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries1{jj}); end %if - missing1(jj) = 1; - end %if - end %for - if (jpchk1 >= numel (entries1)), retval = retval + 2; end %if - if (dbug > 1) - if (jpchk1 >= numel (entries1)) - fprintf (' => Apache (POI) OK\n'); - else - fprintf (' => Not all classes (.jar) required for POI in classpath\n'); - end %if - end %if - % Next, check OOXML support + % Try Java & Apache POI. First Check basic .xls (BIFF8) support + if (dbug > 1), fprintf ('\nBasic POI (.xls) <poi-3> <poi-ooxml>:\n'); end %if + jpchk1 = 0; entries1 = {'poi-3', 'poi-ooxml-3'}; missing1 = zeros (1, numel (entries1)); + % Only under *nix we might use brute force: e.g., strfind (javaclasspath, classname) + % as javaclasspath is one long string. Under Windows however classpath is a cell array + % so we need the following more subtle, platform-independent approach: + for jj=1:length (entries1) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries1{jj})))) + jpchk1 = jpchk1 + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end %for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries1{jj}); end %if + missing1(jj) = 1; + end %if + end %for + if (jpchk1 >= numel (entries1)), retval = retval + 2; end %if + if (dbug > 1) + if (jpchk1 >= numel (entries1)) + fprintf (' => Apache (POI) OK\n'); + else + fprintf (' => Not all classes (.jar) required for POI in classpath\n'); + end %if + end %if + % Next, check OOXML support if (dbug > 1), fprintf ('\nPOI OOXML (.xlsx) <xbean> <poi-ooxml-schemas> <dom4j>:\n'); end %if - jpchk2 = 0; entries2 = {'xbean', 'poi-ooxml-schemas', 'dom4j-1.6.1'}; - missing2 = zeros (1, numel (entries2)); - for jj=1:length (entries2) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries2{jj})))) - jpchk2 = jpchk2 + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end %if - end % for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries2{jj}); end %if - missing2(jj) = 1; - end %if - end % for - % Only update retval if all classes for basic POI have been found in javaclasspath - if (jpchk1 >= numel (entries1) && jpchk2 >= numel (entries2)), retval = retval + 4; end %if - if (dbug > 1) - if (jpchk2 >= numel (entries2)) - fprintf (' => POI OOXML OK\n'); - else - fprintf (' => Some classes for POI OOXML support missing\n'); - end %if - end %if + jpchk2 = 0; entries2 = {'xbean', 'poi-ooxml-schemas', 'dom4j-1.6.1'}; + missing2 = zeros (1, numel (entries2)); + for jj=1:length (entries2) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries2{jj})))) + jpchk2 = jpchk2 + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end % for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries2{jj}); end %if + missing2(jj) = 1; + end %if + end % for + % Only update retval if all classes for basic POI have been found in javaclasspath + if (jpchk1 >= numel (entries1) && jpchk2 >= numel (entries2)), retval = retval + 4; end %if + if (dbug > 1) + if (jpchk2 >= numel (entries2)) + fprintf (' => POI OOXML OK\n'); + else + fprintf (' => Some classes for POI OOXML support missing\n'); + end %if + end %if - % Try Java & JExcelAPI - if (dbug > 1), fprintf ('\nJExcelAPI (.xls (incl. BIFF5 read)) <jxl>:\n'); end %if - jpchk = 0; entries3 = {'jxl'}; missing3 = zeros (1, numel (entries3)); - for jj=1:length (entries3) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries3{jj})))) - jpchk = jpchk + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end % if - end %for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries3{jj}); end %if - missing3(jj) = 1; - end %if - end %for - if (jpchk >= numel (entries3)), retval = retval + 8; end %if - if (dbug > 1) - if (jpchk >= numel (entries3)) - fprintf (' => Java/JExcelAPI (JXL) OK.\n'); - else - fprintf (' => Not all classes (.jar) required for JXL in classpath\n'); - end %if - end %if + % Try Java & JExcelAPI + if (dbug > 1), fprintf ('\nJExcelAPI (.xls (incl. BIFF5 read)) <jxl>:\n'); end %if + jpchk = 0; entries3 = {'jxl'}; missing3 = zeros (1, numel (entries3)); + for jj=1:length (entries3) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries3{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end % if + end %for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries3{jj}); end %if + missing3(jj) = 1; + end %if + end %for + if (jpchk >= numel (entries3)), retval = retval + 8; end %if + if (dbug > 1) + if (jpchk >= numel (entries3)) + fprintf (' => Java/JExcelAPI (JXL) OK.\n'); + else + fprintf (' => Not all classes (.jar) required for JXL in classpath\n'); + end %if + end %if - % Try Java & OpenXLS - if (dbug > 1), fprintf ('\nOpenXLS (.xls (BIFF8)) <OpenXLS>:\n'); end %if - jpchk = 0; entries4 = {'OpenXLS'}; missing4 = zeros (1, numel (entries4)); - for jj=1:length (entries4) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries4{jj})))) - jpchk = jpchk + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end % if - end %for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries4{jj}); end %if - missing4(jj) = 1; - end %if - end %for - if (jpchk >= numel (entries4)), retval = retval + 16; end %if - if (dbug > 1) - if (jpchk >= numel (entries4)) - fprintf (' => Java/OpenXLS (OXS) OK.\n'); - else - fprintf (' => Not all classes (.jar) required for OXS in classpath\n'); - end %if - end %if + % Try Java & OpenXLS + if (dbug > 1), fprintf ('\nOpenXLS (.xls (BIFF8)) <OpenXLS>:\n'); end %if + jpchk = 0; entries4 = {'OpenXLS'}; missing4 = zeros (1, numel (entries4)); + for jj=1:length (entries4) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries4{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end % if + end %for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries4{jj}); end %if + missing4(jj) = 1; + end %if + end %for + if (jpchk >= numel (entries4)), retval = retval + 16; end %if + if (dbug > 1) + if (jpchk >= numel (entries4)) + fprintf (' => Java/OpenXLS (OXS) OK.\n'); + else + fprintf (' => Not all classes (.jar) required for OXS in classpath\n'); + end %if + end %if - % Try Java & ODF toolkit - if (dbug > 1), fprintf ('\nODF Toolkit (.ods) <odfdom> <xercesImpl>:\n'); end %if - jpchk = 0; entries5 = {'odfdom', 'xercesImpl'}; missing5 = zeros (1, numel (entries5)); - for jj=1:length (entries5) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind ( lower (jcpentry), lower (entries5{jj})))) - jpchk = jpchk + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end %if - end %for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries5{jj}); end %if - missing5(jj) = 1; - end %if - end %for - if (jpchk >= numel (entries5)) % Apparently all requested classes present. - % Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6 work OK). - % The odfdom team deemed it necessary to change the version call so we need this: - odfvsn = ' '; - try - % New in 0.8.6 - odfvsn = javaMethod ('getOdfdomVersion', 'org.odftoolkit.odfdom.JarManifest'); - catch - % Worked in 0.7.5 - odfvsn = javaMethod ('getApplicationVersion', 'org.odftoolkit.odfdom.Version'); - end %try_catch - if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6') || strcmp (odfvsn, '0.8.7')) - warning (' *** odfdom version (%s) is not supported - use v. 0.8.6 or 0.8.7.\n', odfvsn); - else - if (dbug > 1), fprintf (' => ODFtoolkit (OTK) OK.\n'); end %if - retval = retval + 32; - end %if + % Try Java & ODF toolkit + if (dbug > 1), fprintf ('\nODF Toolkit (.ods) <odfdom> <xercesImpl>:\n'); end %if + jpchk = 0; entries5 = {'odfdom', 'xercesImpl'}; missing5 = zeros (1, numel (entries5)); + for jj=1:length (entries5) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind ( lower (jcpentry), lower (entries5{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end %for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries5{jj}); end %if + missing5(jj) = 1; + end %if + end %for + if (jpchk >= numel (entries5)) % Apparently all requested classes present. + % Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6 work OK). + % The odfdom team deemed it necessary to change the version call so we need this: + odfvsn = ' '; + try + % New in 0.8.6 + odfvsn = javaMethod ('getOdfdomVersion', 'org.odftoolkit.odfdom.JarManifest'); + catch + % Worked in 0.7.5 + odfvsn = javaMethod ('getApplicationVersion', 'org.odftoolkit.odfdom.Version'); + end %try_catch + if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6') || strcmp (odfvsn, '0.8.7')) + warning (' *** odfdom version (%s) is not supported - use v. 0.8.6 or 0.8.7.\n', odfvsn); + else + if (dbug > 1), fprintf (' => ODFtoolkit (OTK) OK.\n'); end %if + retval = retval + 32; + end %if elseif (dbug > 1) - fprintf (' => Not all required classes (.jar) in classpath for OTK\n'); - end %if + fprintf (' => Not all required classes (.jar) in classpath for OTK\n'); + end %if - % Try Java & jOpenDocument - if (dbug > 1), fprintf ('\njOpenDocument (.ods + experimental .sxc readonly) <jOpendocument>:\n'); end %if - jpchk = 0; entries6 = {'jOpenDocument'}; missing6 = zeros (1, numel (entries6)); - for jj=1:length (entries6) - found = 0; - for ii=1:length (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries6{jj})))) - jpchk = jpchk + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end %if - end %for - if (~found) - if (dbug > 2), fprintf (' %s....jar missing\n', entries6{jj}); end %if - missing6(jj) = 1; - end %if - end %for - if (jpchk >= numel (entries6)), retval = retval + 64; end %if - if (dbug > 1) - if (jpchk >= numel(entries6)) - fprintf (' => jOpenDocument (JOD) OK.\n'); - else - fprintf (' => Not all required classes (.jar) in classpath for JOD\n'); - end %if - end %if + % Try Java & jOpenDocument + if (dbug > 1), fprintf ('\njOpenDocument (.ods + experimental .sxc readonly) <jOpendocument>:\n'); end %if + jpchk = 0; entries6 = {'jOpenDocument'}; missing6 = zeros (1, numel (entries6)); + for jj=1:length (entries6) + found = 0; + for ii=1:length (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries6{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end %for + if (~found) + if (dbug > 2), fprintf (' %s....jar missing\n', entries6{jj}); end %if + missing6(jj) = 1; + end %if + end %for + if (jpchk >= numel (entries6)), retval = retval + 64; end %if + if (dbug > 1) + if (jpchk >= numel(entries6)) + fprintf (' => jOpenDocument (JOD) OK.\n'); + else + fprintf (' => Not all required classes (.jar) in classpath for JOD\n'); + end %if + end %if - % Try Java & UNO - if (dbug > 1), fprintf ('\nUNO/Java (.ods, .xls, .xlsx, .sxc) <OpenOffice.org>:\n'); end %if - % entries0(1) = not a jar but a directory (<000_install_dir/program/>) - jpchk = 0; entries0 = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; - missing0 = zeros (1, numel (entries0)); - for jj=1:numel (entries0) - found = 0; - for ii=1:numel (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries0{jj})))) - jpchk = jpchk + 1; found = 1; - if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if - end %if - end %for - if (~found) - if (dbug > 2) - if (jj == 1) - % Just a dir - fprintf (' %s.... (directory) not found\n', entries0{jj}); - else - fprintf (' %s....jar missing\n', entries0{jj}); - end %if - end %if - missing0(jj) = 1; - end %if - end %for - if (jpchk >= numel (entries0)), retval = retval + 128; end %if - if (dbug > 1) - if (jpchk >= numel (entries0)) - fprintf (' => UNO (OOo) OK\n'); - else - fprintf (' => One or more UNO classes (.jar) missing in javaclasspath\n'); - end %if - end %if + % Try Java & UNO + if (dbug > 1), fprintf ('\nUNO/Java (.ods, .xls, .xlsx, .sxc) <OpenOffice.org>:\n'); end %if + % entries0(1) = not a jar but a directory (<000_install_dir/program/>) + jpchk = 0; entries0 = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + missing0 = zeros (1, numel (entries0)); + for jj=1:numel (entries0) + found = 0; + for ii=1:numel (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries0{jj})))) + jpchk = jpchk + 1; found = 1; + if (dbug > 2), fprintf (' - %s OK\n', jcp{ii}); end %if + end %if + end %for + if (~found) + if (dbug > 2) + if (jj == 1) + % Just a dir + fprintf (' %s.... (directory) not found\n', entries0{jj}); + else + fprintf (' %s....jar missing\n', entries0{jj}); + end %if + end %if + missing0(jj) = 1; + end %if + end %for + if (jpchk >= numel (entries0)), retval = retval + 128; end %if + if (dbug > 1) + if (jpchk >= numel (entries0)) + fprintf (' => UNO (OOo) OK\n'); + else + fprintf (' => One or more UNO classes (.jar) missing in javaclasspath\n'); + end %if + end %if - % If requested, try to add UNO stuff to javaclasspath - ujars_complete = isempty (find (missing0, 1)); + % If requested, try to add UNO stuff to javaclasspath + ujars_complete = isempty (find (missing0, 1)); - if (~ujars_complete && nargin > 0 && ~isempty (path_to_ooo)) - if (dbug), fprintf ('\nTrying to add missing UNO java class libs to javaclasspath...\n'); end %if - if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if - % Add missing jars to javaclasspath. First combine all entries - targt = sum (missing0); - if (missing0(1)) - % Add program dir (= where soffice or soffice.exe or ooffice resides) - programdir = [path_to_ooo filesep entries0{1}]; - if (exist (programdir, 'dir')) - if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', programdir); end %if - try - javaaddpath (programdir); - targt = targt - 1; - if (dbug > 2), fprintf ('OK\n'); end %if - catch - if (dbug > 2), fprintf ('FAILED\n'); end %if - end %try_catch - else - if (dbug > 2), error ('Suggested OpenOffice.org install directory: %s not found!\n', path_to_ooo); end %if - end %if - end %if - % Rest of missing entries. Find where URE is located. Watch out because case of ./ure is unknown - uredir = get_dir_ (path_to_ooo, 'ure'); - if (isempty (uredir)), return; end %if - % Now search for UNO jars - for ii=2:length (entries0) - if (missing0(ii)) - if (ii == 2) - % Special case as unoil.jar usually resides in ./Basis<something>/program/classes - % Find out the exact name of Basis..... - basisdirlst = dir ([path_to_ooo filesep '?asis' '*']); - jj = 1; + if (~ujars_complete && nargin > 0 && ~isempty (path_to_ooo)) + if (dbug), fprintf ('\nTrying to add missing UNO java class libs to javaclasspath...\n'); end %if + if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if + % Add missing jars to javaclasspath. First combine all entries + targt = sum (missing0); + if (missing0(1)) + % Add program dir (= where soffice or soffice.exe or ooffice resides) + programdir = [path_to_ooo filesep entries0{1}]; + if (exist (programdir, 'dir')) + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', programdir); end %if + try + javaaddpath (programdir); + targt = targt - 1; + if (dbug > 2), fprintf ('OK\n'); end %if + catch + if (dbug > 2), fprintf ('FAILED\n'); end %if + end %try_catch + else + if (dbug > 2), error ('Suggested OpenOffice.org install directory: %s not found!\n', path_to_ooo); end %if + end %if + end %if + % Rest of missing entries. Find where URE is located. Watch out because case of ./ure is unknown + uredir = get_dir_ (path_to_ooo, 'ure'); + if (isempty (uredir)), return; end %if + % Now search for UNO jars + for ii=2:length (entries0) + if (missing0(ii)) + if (ii == 2) + % Special case as unoil.jar usually resides in ./Basis<something>/program/classes + % Find out the exact name of Basis..... + basisdirlst = dir ([path_to_ooo filesep '?asis' '*']); + jj = 1; if (numel (basisdirlst) > 0) while (jj <= size (basisdirlst, 1) && jj > 0) basisdir = basisdirlst(jj).name; @@ -441,104 +442,104 @@ else basisdir = path_to_ooo; endif - basisdirentries = {'program', 'classes'}; - tmp = basisdir; jj=1; - while (~isempty (tmp) && jj <= numel (basisdirentries)) - tmp = get_dir_ (tmp, basisdirentries{jj}); - jj = jj + 1; - end %if - unojarpath = tmp; - file = dir ([ unojarpath filesep entries0{2} '*' ]); - else - % Rest of jars in ./ure/share/java or ./ure/java - unojardir = get_dir_ (uredir, 'share'); - if (isempty (unojardir)) - tmp = uredir; - else - tmp = unojardir; - end %if - unojarpath = get_dir_ (tmp, 'java'); - file = dir ([unojarpath filesep entries0{ii} '*']); - end %if - % Path found, now try to add jar - if (isempty (file)) - if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', entries0{ii}); end %if - else - if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file.name); end %if - try - javaaddpath ([unojarpath filesep file.name]); - targt = targt - 1; - if (dbug > 2), fprintf ('OK\n'); end %if - catch - if (dbug > 2), fprintf ('FAILED\n'); end %if + basisdirentries = {'program', 'classes'}; + tmp = basisdir; jj=1; + while (~isempty (tmp) && jj <= numel (basisdirentries)) + tmp = get_dir_ (tmp, basisdirentries{jj}); + jj = jj + 1; + end %if + unojarpath = tmp; + file = dir ([ unojarpath filesep entries0{2} '*' ]); + else + % Rest of jars in ./ure/share/java or ./ure/java + unojardir = get_dir_ (uredir, 'share'); + if (isempty (unojardir)) + tmp = uredir; + else + tmp = unojardir; + end %if + unojarpath = get_dir_ (tmp, 'java'); + file = dir ([unojarpath filesep entries0{ii} '*']); + end %if + % Path found, now try to add jar + if (isempty (file)) + if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', entries0{ii}); end %if + else + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file.name); end %if + try + javaaddpath ([unojarpath filesep file.name]); + targt = targt - 1; + if (dbug > 2), fprintf ('OK\n'); end %if + catch + if (dbug > 2), fprintf ('FAILED\n'); end %if end %try_catch - end %if - end %if - end %for - if (~targt); retval = retval + 128; end %if - if (dbug) - if (targt) - fprintf ('Some UNO class libs still lacking...\n\n'); - else - fprintf ('UNO interface supported now.\n\n'); - end %if - end %f - end %if + end %if + end %if + end %for + if (~targt); retval = retval + 128; end %if + if (dbug) + if (targt) + fprintf ('Some UNO class libs still lacking...\n\n'); + else + fprintf ('UNO interface supported now.\n\n'); + end %if + end %f + end %if % ----------Rest of Java interfaces---------------------------------- - missing = [missing1 missing2 missing3 missing4 missing5 missing6]; - jars_complete = isempty (find (missing, 1)); - if (dbug) - if (jars_complete) - fprintf ('All interfaces already fully supported.\n\n'); - else - fprintf ('Some class libs lacking yet...\n\n'); - end %if - end %if + missing = [missing1 missing2 missing3 missing4 missing5 missing6]; + jars_complete = isempty (find (missing, 1)); + if (dbug) + if (jars_complete) + fprintf ('All interfaces already fully supported.\n\n'); + else + fprintf ('Some class libs lacking yet...\n\n'); + end %if + end %if - if (~jars_complete && nargin > 0 && ~isempty (path_to_jars)) - % Add missing jars to javaclasspath. Assume they're all in the same place - if (dbug), fprintf ('Trying to add missing java class libs to javaclasspath...\n'); end %if - if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if - % First combine all entries - targt = sum (missing); - % Search tru list of missing entries - for ii=1:6 % Adapt in case of future new interfaces - tmpe = eval ([ 'entries' char(ii) + '0' ]); - tmpm = eval ([ 'missing' char(ii) + '0' ]); - if (sum (tmpm)) - for jj=1:numel (tmpe) - if (tmpm(jj)) - file = dir ([path_to_jars filesep tmpe{jj} '*']); - if (isempty (file)) - if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', tmpe{jj}); end %if - else - if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file.name); end %if - try - javaaddpath ([path_to_jars filesep file.name]); - targt = targt - 1; - tmpm(jj) = 0; - if (dbug > 2), fprintf ('OK\n'); end %if - catch - if (dbug > 2), fprintf ('FAILED\n'); end %if - end %try_catch - end %if - end %if - end %for - if (~sum (tmpm)) - retval = retval + 2^ii; - end %if - end %if - end %for - if (dbug) - if (targt) - fprintf ('Some other class libs still lacking...\n\n'); - else - fprintf ('All interfaces fully supported.now.\n\n'); - end %if - end %f - end %if + if (~jars_complete && nargin > 0 && ~isempty (path_to_jars)) + % Add missing jars to javaclasspath. Assume they're all in the same place + if (dbug), fprintf ('Trying to add missing java class libs to javaclasspath...\n'); end %if + if (~ischar (path_to_jars)), error ('Path expected for arg # 1'); end %if + % First combine all entries + targt = sum (missing); + % Search tru list of missing entries + for ii=1:6 % Adapt in case of future new interfaces + tmpe = eval ([ 'entries' char(ii + '0') ]); + tmpm = eval ([ 'missing' char(ii + '0') ]); + if (sum (tmpm)) + for jj=1:numel (tmpe) + if (tmpm(jj)) + file = dir ([path_to_jars filesep tmpe{jj} '*']); + if (isempty (file)) + if (dbug > 2), fprintf (' ? %s<...>.jar ?\n', tmpe{jj}); end %if + else + if (dbug > 2), fprintf (' Found %s, adding it to javaclasspath ... ', file(1).name); end %if + try + javaaddpath ([path_to_jars filesep file(1).name]); + targt = targt - 1; + tmpm(jj) = 0; + if (dbug > 2), fprintf ('OK\n'); end %if + catch + if (dbug > 2), fprintf ('FAILED\n'); end %if + end %try_catch + end %if + end %if + end %for + if (~sum (tmpm)) + retval = retval + 2^ii; + end %if + end %if + end %for + if (dbug) + if (targt) + fprintf ('Some other class libs still lacking...\n\n'); + else + fprintf ('All interfaces fully supported.now.\n\n'); + end %if + end %f + end %if end %function @@ -549,20 +550,20 @@ % at taking care of proper case (esp. for *nix) of existing subdir % in the result. Case of input var req_dir is ignored on purpose. - ret_dir = ''; - % Get list of directory entries - ret_dir_list = dir (base_dir); - % Find matching entries - idx = find (strcmpi ({ret_dir_list.name}, req_dir)); - % On *nix, several files and subdirs in one dir may have the same name as long as case differs - if (~isempty (idx)) - ii = 1; - while (~ret_dir_list(idx(ii)).isdir) - ii = ii + 1; - if (ii > numel (idx)); return; end %if - end %while - % If we get here, a dir with proper name has been found. Construct path - ret_dir = [ base_dir filesep ret_dir_list(idx(ii)).name ]; - end %if + ret_dir = ''; + % Get list of directory entries + ret_dir_list = dir (base_dir); + % Find matching entries + idx = find (strcmpi ({ret_dir_list.name}, req_dir)); + % On *nix, several files and subdirs in one dir may have the same name as long as case differs + if (~isempty (idx)) + ii = 1; + while (~ret_dir_list(idx(ii)).isdir) + ii = ii + 1; + if (ii > numel (idx)); return; end %if + end %while + % If we get here, a dir with proper name has been found. Construct path + ret_dir = [ base_dir filesep ret_dir_list(idx(ii)).name ]; + end %if end %function Modified: trunk/octave-forge/main/io/inst/xlswrite.m =================================================================== --- trunk/octave-forge/main/io/inst/xlswrite.m 2012-06-07 22:09:56 UTC (rev 10588) +++ trunk/octave-forge/main/io/inst/xlswrite.m 2012-06-07 22:10:30 UTC (rev 10589) @@ -102,76 +102,77 @@ ## 2010-01-12 (Bug fix; added unwind_protect to xlsopen...xlsclose calls) ## 2010-01-15 Fixed typos in texinfo ## 2010-08-18 Added check for existence of xls after call to xlsopen to -## avoid unneeded error message clutter +## avoid unneeded error message clutter ## 2010-10-27 Changed range -> crange to unhide other range functions ## 2011-09-08 Minor code syntax updates ## 2012-01-26 Fixed "seealso" help string +## 2012-06-07 Replaced all tabs by double space function [ rstatus ] = xlswrite (filename, arr, arg3, arg4, arg5) - rstatus = 0; + rstatus = 0; - # Sanity checks - if (nargin < 2) - usage ("Insufficient arguments - see 'help xlswrite'"); - elseif (~ischar (filename)) - error ("First argument must be a filename (incl. suffix)"); - elseif (nargin == 2) - # Assume first worksheet and full worksheet starting at A1 - wsh = 1; - if (strcmp (tolower (filename(end-4:end-1)), 'xls')) - crange = "A1:XFD1048576"; # OOXML has ridiculously large limits - else - crange = "A1:IV65536"; # Regular xls limits - endif - elseif (nargin == 3) - # Find out whether 3rd argument = worksheet or range - if (isnumeric (arg3) || (isempty (findstr (arg3, ':')) && ~isempty (arg3))) - # Apparently a worksheet specified - wsh = arg3; - if (strcmp (tolower (filename(end-4:end-1)), 'xls')) - crange = "A1:XFD1048576"; # OOXML has ridiculously large limits - else - crange = "A1:IV65536"; # Regular xls limits - endif - else - # Range specified - wsh = 1; - crange = arg3; - endif - elseif (nargin >= 4) - wsh = arg3; - crange = arg4; - endif - if (nargin == 5) - reqintf = arg5; - else - reqintf = []; - endif - - # Parse range - [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); - - # Check if arr fits in range - [nr, nc] = size (arr); - if ((nr > nrows) || (nc > ncols)) - # Array too big; truncate - nr = min (nrows, nr); - nc = min (ncols, nc); - warning ("xlswrite - array truncated to %d by %d to fit in range %s", ... - nrows, ncols, crange); - endif + # Sanity checks + if (nargin < 2) + usage ("Insufficient arguments - see 'help xlswrite'"); + elseif (~ischar (filename)) + error ("First argument must be a filename (incl. suffix)"); + elseif (nargin == 2) + # Assume first worksheet and full worksheet starting at A1 + wsh = 1; + if (strcmp (tolower (filename(end-4:end-1)), 'xls')) + crange = "A1:XFD1048576"; # OOXML has ridiculously large limits + else + crange = "A1:IV65536"; # Regular xls limits + endif + elseif (nargin == 3) + # Find out whether 3rd argument = worksheet or range + if (isnumeric (arg3) || (isempty (findstr (arg3, ':')) && ~isempty (arg3))) + # Apparently a worksheet specified + wsh = arg3; + if (strcmp (tolower (filename(end-4:end-1)), 'xls')) + crange = "A1:XFD1048576"; # OOXML has ridiculously large limits + else + crange = "A1:IV65536"; # Regular xls limits + endif + else + # Range specified + wsh = 1; + crange = arg3; + endif + elseif (nargin >= 4) + wsh = arg3; + crange = arg4; + endif + if (nargin == 5) + reqintf = arg5; + else + reqintf = []; + endif + + # Parse range + [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); + + # Check if arr fits in range + [nr, nc] = size (arr); + if ((nr > nrows) || (nc > ncols)) + # Array too big; truncate + nr = min (nrows, nr); + nc = min (ncols, nc); + warning ("xlswrite - array truncated to %d by %d to fit in range %s", ... + nrows, ncols, crange); + endif - unwind_protect # Needed to be sure Excel can be closed i.c.o. errors + unwind_protect # Needed to be sure Excel can be closed i.c.o. errors xls_ok = 0; xls = xlsopen (filename, 1, reqintf); xls_ok = 1; [xls, rstatus] = oct2xls (arr(1:nr, 1:nc), xls, wsh, topleft); - unwind_protect_cleanup + unwind_protect_cleanup if (xls_ok), xls = xlsclose (xls); endif - end_unwind_protect + end_unwind_protect endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-07 22:10:02
|
Revision: 10588 http://octave.svn.sourceforge.net/octave/?rev=10588&view=rev Author: prnienhuis Date: 2012-06-07 22:09:56 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Fixed mixed-up lastintf assignments for POI and JXL Modified Paths: -------------- trunk/octave-forge/main/io/inst/xlsopen.m Modified: trunk/octave-forge/main/io/inst/xlsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/xlsopen.m 2012-06-07 18:28:03 UTC (rev 10587) +++ trunk/octave-forge/main/io/inst/xlsopen.m 2012-06-07 22:09:56 UTC (rev 10588) @@ -107,6 +107,7 @@ ## 2012-01-26 Fixed "seealso" help string ## 2012-06-06 Improved interface detection logic. No more messages if same interface is ## requested & used consecutively +## 2012-06-07 Fixed mixed-up lastintf assignments for POI and JXL ## ## Latest subfunction update: 2012-06-06 @@ -271,7 +272,7 @@ xls.workbook = wb; xls.filename = filename; xlssupport += 2; - lastintf = 'JXL'; + lastintf = 'POI'; catch clear xlsin; if (xlsinterfaces.JXL) @@ -298,7 +299,7 @@ xls.workbook = wb; xls.filename = filename; xlssupport += 4; - lastintf = 'POI'; + lastintf = 'JXL'; catch clear xlsin; if (xlsinterfaces.POI) @@ -643,4 +644,4 @@ printf ("Trying to quit Octave w/o invoking xlsclose will only hang Octave.\n\n"); endif -endfunction \ No newline at end of file +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-07 18:28:09
|
Revision: 10587 http://octave.svn.sourceforge.net/octave/?rev=10587&view=rev Author: abarth93 Date: 2012-06-07 18:28:03 +0000 (Thu, 07 Jun 2012) Log Message: ----------- ncread Modified Paths: -------------- trunk/octave-forge/main/octcdf/inst/ncread.m Modified: trunk/octave-forge/main/octcdf/inst/ncread.m =================================================================== --- trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-07 16:58:19 UTC (rev 10586) +++ trunk/octave-forge/main/octcdf/inst/ncread.m 2012-06-07 18:28:03 UTC (rev 10587) @@ -20,7 +20,7 @@ % end index -endi = start + count.*stride; +endi = start + (count-1).*stride; % replace inf in count This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-07 16:58:25
|
Revision: 10586 http://octave.svn.sourceforge.net/octave/?rev=10586&view=rev Author: paramaniac Date: 2012-06-07 16:58:19 +0000 (Thu, 07 Jun 2012) Log Message: ----------- control: further improvements for Makefile by Olaf Till Modified Paths: -------------- trunk/octave-forge/main/control/src/Makefile Modified: trunk/octave-forge/main/control/src/Makefile =================================================================== --- trunk/octave-forge/main/control/src/Makefile 2012-06-07 16:36:19 UTC (rev 10585) +++ trunk/octave-forge/main/control/src/Makefile 2012-06-07 16:58:19 UTC (rev 10586) @@ -1,8 +1,14 @@ MKOCTFILE ?= mkoctfile -LAPACK_LIBS ?= $(shell $(MKOCTFILE) -p LAPACK_LIBS) -BLAS_LIBS ?= $(shell $(MKOCTFILE) -p BLAS_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) all: control_slicot_functions.oct \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-07 16:36:29
|
Revision: 10585 http://octave.svn.sourceforge.net/octave/?rev=10585&view=rev Author: prnienhuis Date: 2012-06-07 16:36:19 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Tabs replaced by double space Modified Paths: -------------- trunk/octave-forge/main/io/inst/xls2oct.m Modified: trunk/octave-forge/main/io/inst/xls2oct.m =================================================================== --- trunk/octave-forge/main/io/inst/xls2oct.m 2012-06-07 16:35:46 UTC (rev 10584) +++ trunk/octave-forge/main/io/inst/xls2oct.m 2012-06-07 16:36:19 UTC (rev 10585) @@ -133,84 +133,85 @@ ## 2012-02-25 Fixed missing quotes in struct check L.149-153 ## 2012-02-26 Updated texinfo header help text ## 2012-06-06 Implemented "formulas_as_text" option for COM +## 2012-06-07 Replaced all tabs by double space ## ## Latest subfunc update: 2012-06-06 function [ rawarr, xls, rstatus ] = xls2oct (xls, wsh=1, datrange='', spsh_opts=[]) - # Check if xls struct pointer seems valid - if (~isstruct (xls)), error ("File ptr struct expected for arg @ 1"); endif - test1 = ~isfield (xls, "xtype"); - test1 = test1 || ~isfield (xls, "workbook"); - test1 = test1 || isempty (xls.workbook); - test1 = test1 || isempty (xls.app); - test1 = test1 || ~ischar (xls.xtype); - if test1 - error ("Invalid xls file pointer struct"); - endif + # Check if xls struct pointer seems valid + if (~isstruct (xls)), error ("File ptr struct expected for arg @ 1"); endif + test1 = ~isfield (xls, "xtype"); + test1 = test1 || ~isfield (xls, "workbook"); + test1 = test1 || isempty (xls.workbook); + test1 = test1 || isempty (xls.app); + test1 = test1 || ~ischar (xls.xtype); + if test1 + error ("Invalid xls file pointer struct"); + endif - # Check worksheet ptr - if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 2"); endif - # Check range - if (~(isempty (datrange) || ischar (datrange))), error ("Character string (range) expected for arg # 3"); endif + # Check worksheet ptr + if (~(ischar (wsh) || isnumeric (wsh))), error ("Integer (index) or text (wsh name) expected for arg # 2"); endif + # Check range + if (~(isempty (datrange) || ischar (datrange))), error ("Character string (range) expected for arg # 3"); endif - # Check & setup options struct - if (nargin < 4 || isempty (spsh_opts)) - spsh_opts.formulas_as_text = 0; - spsh_opts.strip_array = 1; - # Future options: - elseif (isstruct (spsh_opts)) - if (~isfield (spsh_opts', 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif - if (~isfield (spsh_opts', 'strip_array')), spsh_opts.strip_array = 1; endif - % Future options: - else - error ("Structure expected for arg # 4"); - endif + # Check & setup options struct + if (nargin < 4 || isempty (spsh_opts)) + spsh_opts.formulas_as_text = 0; + spsh_opts.strip_array = 1; + # Future options: + elseif (isstruct (spsh_opts)) + if (~isfield (spsh_opts', 'formulas_as_text')), spsh_opts.formulas_as_text = 0; endif + if (~isfield (spsh_opts', 'strip_array')), spsh_opts.strip_array = 1; endif + % Future options: + else + error ("Structure expected for arg # 4"); + endif - # Select the proper interfaces - if (strcmp (xls.xtype, 'COM')) - # Call Excel tru COM / ActiveX server - [rawarr, xls, rstatus] = xls2com2oct (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'POI')) - # Read xls file tru Java POI - [rawarr, xls, rstatus] = xls2jpoi2oct (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'JXL')) - # Read xls file tru JExcelAPI - [rawarr, xls, rstatus] = xls2jxla2oct (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'OXS')) - # Read xls file tru OpenXLS - [rawarr, xls, rstatus] = xls2oxs2oct (xls, wsh, datrange, spsh_opts); - elseif (strcmp (xls.xtype, 'UNO')) - # Read xls file tru OpenOffice.org UNO (Java) bridge - [rawarr, xls, rstatus] = xls2uno2oct (xls, wsh, datrange, spsh_opts); -# elseif ---- <Other interfaces here> - # Call to next interface - else - error (sprintf ("xls2oct: unknown Excel .xls interface - %s.", xls.xtype)); - endif + # Select the proper interfaces + if (strcmp (xls.xtype, 'COM')) + # Call Excel tru COM / ActiveX server + [rawarr, xls, rstatus] = xls2com2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'POI')) + # Read xls file tru Java POI + [rawarr, xls, rstatus] = xls2jpoi2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'JXL')) + # Read xls file tru JExcelAPI + [rawarr, xls, rstatus] = xls2jxla2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'OXS')) + # Read xls file tru OpenXLS + [rawarr, xls, rstatus] = xls2oxs2oct (xls, wsh, datrange, spsh_opts); + elseif (strcmp (xls.xtype, 'UNO')) + # Read xls file tru OpenOffice.org UNO (Java) bridge + [rawarr, xls, rstatus] = xls2uno2oct (xls, wsh, datrange, spsh_opts); +# elseif ---- <Other interfaces here> + # Call to next interface + else + error (sprintf ("xls2oct: unknown Excel .xls interface - %s.", xls.xtype)); + endif - # Optionally strip empty outer rows and columns & keep track of original data location - if (spsh_opts.strip_array) - emptr = cellfun ('isempty', rawarr); - if (all (all (emptr))) - rawarr = {}; - xls.limits = []; - else - nrows = size (rawarr, 1); ncols = size (rawarr, 2); - irowt = 1; - while (all (emptr(irowt, :))), irowt++; endwhile - irowb = nrows; - while (all (emptr(irowb, :))), irowb--; endwhile - icoll = 1; - while (all (emptr(:, icoll))), icoll++; endwhile - icolr = ncols; - while (all (emptr(:, icolr))), icolr--; endwhile + # Optionally strip empty outer rows and columns & keep track of original data location + if (spsh_opts.strip_array) + emptr = cellfun ('isempty', rawarr); + if (all (all (emptr))) + rawarr = {}; + xls.limits = []; + else + nrows = size (rawarr, 1); ncols = size (rawarr, 2); + irowt = 1; + while (all (emptr(irowt, :))), irowt++; endwhile + irowb = nrows; + while (all (emptr(irowb, :))), irowb--; endwhile + icoll = 1; + while (all (emptr(:, icoll))), icoll++; endwhile + icolr = ncols; + while (all (emptr(:, icolr))), icolr--; endwhile - # Crop output cell array and update limits - rawarr = rawarr(irowt:irowb, icoll:icolr); - xls.limits = xls.limits + [icoll-1, icolr-ncols; irowt-1, irowb-nrows]; - endif - endif + # Crop output cell array and update limits + rawarr = rawarr(irowt:irowb, icoll:icolr); + xls.limits = xls.limits + [icoll-1, icolr-ncols; irowt-1, irowb-nrows]; + endif + endif endfunction @@ -270,98 +271,98 @@ function [rawarr, xls, rstatus ] = xls2com2oct (xls, wsh, crange, spsh_opts) - rstatus = 0; rawarr = {}; + rstatus = 0; rawarr = {}; - # Basic checks - if (nargin < 2) error ("xls2com2oct needs a minimum of 2 arguments."); endif - if (size (wsh, 2) > 31) - warning ("Worksheet name too long - truncated") - wsh = wsh(1:31); - endif - app = xls.app; - wb = xls.workbook; - # Check to see if ActiveX is still alive - try - wb_cnt = wb.Worksheets.count; - catch - error ("ActiveX invocation in file ptr struct seems non-functional"); - end_try_catch + # Basic checks + if (nargin < 2) error ("xls2com2oct needs a minimum of 2 arguments."); endif + if (size (wsh, 2) > 31) + warning ("Worksheet name too long - truncated") + wsh = wsh(1:31); + endif + app = xls.app; + wb = xls.workbook; + # Check to see if ActiveX is still alive + try + wb_cnt = wb.Worksheets.count; + catch + error ("ActiveX invocation in file ptr struct seems non-functional"); + end_try_catch - # Check & get handle to requested worksheet - wb_cnt = wb.Worksheets.count; - old_sh = 0; - if (isnumeric (wsh)) - if (wsh < 1 || wsh > wb_cnt) - errstr = sprintf ("Worksheet number: %d out of range 1-%d", wsh, wb_cnt); - error (errstr) - rstatus = 1; - return - else - old_sh = wsh; - endif - else - # Find worksheet number corresponding to name in wsh - wb_cnt = wb.Worksheets.count; - for ii =1:wb_cnt - sh_name = wb.Worksheets(ii).name; - if (strcmp (sh_name, wsh)) old_sh = ii; endif - endfor - if (~old_sh) - errstr = sprintf ("Worksheet name \"%s\" not present", wsh); - error (errstr) - else - wsh = old_sh; - endif - endif - sh = wb.Worksheets (wsh); + # Check & get handle to requested worksheet + wb_cnt = wb.Worksheets.count; + old_sh = 0; + if (isnumeric (wsh)) + if (wsh < 1 || wsh > wb_cnt) + errstr = sprintf ("Worksheet number: %d out of range 1-%d", wsh, wb_cnt); + error (errstr) + rstatus = 1; + return + else + old_sh = wsh; + endif + else + # Find worksheet number corresponding to name in wsh + wb_cnt = wb.Worksheets.count; + for ii =1:wb_cnt + sh_name = wb.Worksheets(ii).name; + if (strcmp (sh_name, wsh)) old_sh = ii; endif + endfor + if (~old_sh) + errstr = sprintf ("Worksheet name \"%s\" not present", wsh); + error (errstr) + else + wsh = old_sh; + endif + endif + sh = wb.Worksheets (wsh); - nrows = 0; - if ((nargin == 2) || (isempty (crange))) - allcells = sh.UsedRange; - # Get actually used range indices - [trow, brow, lcol, rcol] = getusedrange (xls, old_sh); - if (trow == 0 && brow == 0) - # Empty sheet - rawarr = {}; - printf ("Worksheet '%s' contains no data\n", sh.Name); - return; - else - nrows = brow - trow + 1; ncols = rcol - lcol + 1; - topleft = calccelladdress (trow, lcol); - lowerright = calccelladdress (brow, rcol); - crange = [topleft ':' lowerright]; - endif - else - # Extract top_left_cell from range - [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); - brow = trow + nrows - 1; - rcol = lcol + ncols - 1; - endif; + nrows = 0; + if ((nargin == 2) || (isempty (crange))) + allcells = sh.UsedRange; + # Get actually used range indices + [trow, brow, lcol, rcol] = getusedrange (xls, old_sh); + if (trow == 0 && brow == 0) + # Empty sheet + rawarr = {}; + printf ("Worksheet '%s' contains no data\n", sh.Name); + return; + else + nrows = brow - trow + 1; ncols = rcol - lcol + 1; + topleft = calccelladdress (trow, lcol); + lowerright = calccelladdress (brow, rcol); + crange = [topleft ':' lowerright]; + endif + else + # Extract top_left_cell from range + [topleft, nrows, ncols, trow, lcol] = parse_sp_range (crange); + brow = trow + nrows - 1; + rcol = lcol + ncols - 1; + endif; - if (nrows >= 1) - # Get object from Excel sheet, starting at cell top_left_cell - rr = sh.Range (crange); + if (nrows >= 1) + # Get object from Excel sheet, starting at cell top_left_cell + rr = sh.Range (crange); if (spsh_opts.formulas_as_text) rawarr = rr.Formula; else rawarr = rr.Value; endif - delete (rr); + delete (rr); - # Take care of actual singe cell range - if (isnumeric (rawarr) || ischar (rawarr)) - rawarr = {rawarr}; - endif + # Take care of actual singe cell range + if (isnumeric (rawarr) || ischar (rawarr)) + rawarr = {rawarr}; + endif - # If we get here, all seems to have gone OK - rstatus = 1; - # Keep track of data rectangle limits - xls.limits = [lcol, rcol; trow, brow]; - else - error ("No data read from Excel file"); - rstatus = 0; - endif - + # If we get here, all seems to have gone OK + rstatus = 1; + # Keep track of data rectangle limits + xls.limits = [lcol, rcol; trow, brow]; + else + error ("No data read from Excel file"); + rstatus = 0; + endif + endfunction @@ -420,127 +421,127 @@ function [ rawarr, xls, rstatus ] = xls2jpoi2oct (xls, wsh, cellrange, spsh_opts) - persistent ctype; - if (isempty (ctype)) - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype(1) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_NUMERIC'); - ctype(2) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_STRING'); - ctype(3) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_FORMULA'); - ctype(4) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); - ctype(5) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BOOLEAN'); - ctype(6) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_ERROR'); - endif - - rstatus = 0; jerror = 0; - wb = xls.workbook; + persistent ctype; + if (isempty (ctype)) + # Get enumerated cell types. Beware as they start at 0 not 1 + ctype(1) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_NUMERIC'); + ctype(2) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_STRING'); + ctype(3) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_FORMULA'); + ctype(4) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BLANK'); + ctype(5) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_BOOLEAN'); + ctype(6) = java_get ('org.apache.poi.ss.usermodel.Cell', 'CELL_TYPE_ERROR'); + endif + + rstatus = 0; jerror = 0; + wb = xls.workbook; - # Check if requested worksheet exists in the file & if so, get pointer - nr_of_sheets = wb.getNumberOfSheets (); - if (isnumeric (wsh)) - if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif - sh = wb.getSheetAt (wsh - 1); # POI sheet count 0-based - printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); - else - sh = wb.getSheet (wsh); - if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif - end + # Check if requested worksheet exists in the file & if so, get pointer + nr_of_sheets = wb.getNumberOfSheets (); + if (isnumeric (wsh)) + if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif + sh = wb.getSheetAt (wsh - 1); # POI sheet count 0-based + printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); + else + sh = wb.getSheet (wsh); + if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif + end - # Check ranges - firstrow = sh.getFirstRowNum (); # 0-based - lastrow = sh.getLastRowNum (); # 0-based - if (isempty (cellrange)) - if (ischar (wsh)) - # get numeric sheet index - ii = wb.getSheetIndex (sh) + 1; - else - ii = wsh; - endif - [ firstrow, lastrow, lcol, rcol ] = getusedrange (xls, ii); - if (firstrow == 0 && lastrow == 0) - # Empty sheet - rawarr = {}; - printf ("Worksheet '%s' contains no data\n", sh.getSheetName ()); - rstatus = 1; - return; - else - nrows = lastrow - firstrow + 1; - ncols = rcol - lcol + 1; - endif - else - # Translate range to HSSF POI row & column numbers - [topleft, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); - lastrow = firstrow + nrows - 1; - rcol = lcol + ncols - 1; - endif + # Check ranges + firstrow = sh.getFirstRowNum (); # 0-based + lastrow = sh.getLastRowNum (); # 0-based + if (isempty (cellrange)) + if (ischar (wsh)) + # get numeric sheet index + ii = wb.getSheetIndex (sh) + 1; + else + ii = wsh; + endif + [ firstrow, lastrow, lcol, rcol ] = getusedrange (xls, ii); + if (firstrow == 0 && lastrow == 0) + # Empty sheet + rawarr = {}; + printf ("Worksheet '%s' contains no data\n", sh.getSheetName ()); + rstatus = 1; + return; + else + nrows = lastrow - firstrow + 1; + ncols = rcol - lcol + 1; + endif + else + # Translate range to HSSF POI row & column numbers + [topleft, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); + lastrow = firstrow + nrows - 1; + rcol = lcol + ncols - 1; + endif - # Create formula evaluator (needed to infer proper cell type into rawarr) - frm_eval = wb.getCreationHelper().createFormulaEvaluator (); - - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder - for ii = firstrow:lastrow - irow = sh.getRow (ii-1); - if ~isempty (irow) - scol = (irow.getFirstCellNum).intValue (); - ecol = (irow.getLastCellNum).intValue () - 1; - for jj = lcol:rcol - scell = irow.getCell (jj-1); - if ~isempty (scell) - # Explore cell contents - type_of_cell = scell.getCellType (); - if (type_of_cell == ctype(3)) # Formula - if ~(spsh_opts.formulas_as_text) - try # Because not al Excel formulas have been implemented in POI - cvalue = frm_eval.evaluate (scell); - type_of_cell = cvalue.getCellType(); - # Separate switch because form.eval. yields different type - switch type_of_cell - case ctype (1) # Numeric - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getNumberValue (); - case ctype(2) # String - rawarr {ii+1-firstrow, jj+1-lcol} = char (scell.getStringValue ()); - case ctype (5) # Boolean - rawarr {ii+1-firstrow, jj+1-lcol} = scell.BooleanValue (); - otherwise - # Nothing to do here - endswitch - # Set cell type to blank to skip switch below - type_of_cell = ctype(4); - catch - # In case of formula errors we take the cached results - type_of_cell = scell.getCachedFormulaResultType (); - ++jerror; # We only need one warning even for multiple errors - end_try_catch - endif - endif - # Preparations done, get data values into data array - switch type_of_cell - case ctype(1) # 0 Numeric - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getNumericCellValue (); - case ctype(2) # 1 String - rawarr {ii+1-firstrow, jj+1-lcol} = char (scell.getRichStringCellValue ()); - case ctype(3) - if (spsh_opts.formulas_as_text) - tmp = char (scell.getCellFormula ()); - rawarr {ii+1-firstrow, jj+1-lcol} = ['=' tmp]; - endif - case ctype(4) # 3 Blank - # Blank; ignore until further notice - case ctype(5) # 4 Boolean - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getBooleanCellValue (); - otherwise # 5 Error - # Ignore - endswitch - endif - endfor - endif - endfor + # Create formula evaluator (needed to infer proper cell type into rawarr) + frm_eval = wb.getCreationHelper().createFormulaEvaluator (); + + # Read contents into rawarr + rawarr = cell (nrows, ncols); # create placeholder + for ii = firstrow:lastrow + irow = sh.getRow (ii-1); + if ~isempty (irow) + scol = (irow.getFirstCellNum).intValue (); + ecol = (irow.getLastCellNum).intValue () - 1; + for jj = lcol:rcol + scell = irow.getCell (jj-1); + if ~isempty (scell) + # Explore cell contents + type_of_cell = scell.getCellType (); + if (type_of_cell == ctype(3)) # Formula + if ~(spsh_opts.formulas_as_text) + try # Because not al Excel formulas have been implemented in POI + cvalue = frm_eval.evaluate (scell); + type_of_cell = cvalue.getCellType(); + # Separate switch because form.eval. yields different type + switch type_of_cell + case ctype (1) # Numeric + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getNumberValue (); + case ctype(2) # String + rawarr {ii+1-firstrow, jj+1-lcol} = char (scell.getStringValue ()); + case ctype (5) # Boolean + rawarr {ii+1-firstrow, jj+1-lcol} = scell.BooleanValue (); + otherwise + # Nothing to do here + endswitch + # Set cell type to blank to skip switch below + type_of_cell = ctype(4); + catch + # In case of formula errors we take the cached results + type_of_cell = scell.getCachedFormulaResultType (); + ++jerror; # We only need one warning even for multiple errors + end_try_catch + endif + endif + # Preparations done, get data values into data array + switch type_of_cell + case ctype(1) # 0 Numeric + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getNumericCellValue (); + case ctype(2) # 1 String + rawarr {ii+1-firstrow, jj+1-lcol} = char (scell.getRichStringCellValue ()); + case ctype(3) + if (spsh_opts.formulas_as_text) + tmp = char (scell.getCellFormula ()); + rawarr {ii+1-firstrow, jj+1-lcol} = ['=' tmp]; + endif + case ctype(4) # 3 Blank + # Blank; ignore until further notice + case ctype(5) # 4 Boolean + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getBooleanCellValue (); + otherwise # 5 Error + # Ignore + endswitch + endif + endfor + endif + endfor - if (jerror > 0) warning (sprintf ("xls2oct: %d cached values instead of formula evaluations.\n", jerror)); endif - - rstatus = 1; - xls.limits = [lcol, rcol; firstrow, lastrow]; - + if (jerror > 0) warning (sprintf ("xls2oct: %d cached values instead of formula evaluations.\n", jerror)); endif + + rstatus = 1; + xls.limits = [lcol, rcol; firstrow, lastrow]; + endfunction @@ -599,167 +600,167 @@ function [ rawarr, xls, rstatus ] = xls2jxla2oct (xls, wsh, cellrange, spsh_opts) - persistent ctype; persistent months; - if (isempty (ctype)) - ctype = cell (11, 1); - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype( 1) = (java_get ('jxl.CellType', 'BOOLEAN')).toString (); - ctype( 2) = (java_get ('jxl.CellType', 'BOOLEAN_FORMULA')).toString (); - ctype( 3) = (java_get ('jxl.CellType', 'DATE')).toString (); - ctype( 4) = (java_get ('jxl.CellType', 'DATE_FORMULA')).toString (); - ctype( 5) = (java_get ('jxl.CellType', 'EMPTY')).toString (); - ctype( 6) = (java_get ('jxl.CellType', 'ERROR')).toString (); - ctype( 7) = (java_get ('jxl.CellType', 'FORMULA_ERROR')).toString (); - ctype( 8) = (java_get ('jxl.CellType', 'NUMBER')).toString (); - ctype( 9) = (java_get ('jxl.CellType', 'LABEL')).toString (); - ctype(10) = (java_get ('jxl.CellType', 'NUMBER_FORMULA')).toString (); - ctype(11) = (java_get ('jxl.CellType', 'STRING_FORMULA')).toString (); - months = {'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'}; - endif - - rstatus = 0; - wb = xls.workbook; - - # Check if requested worksheet exists in the file & if so, get pointer - nr_of_sheets = wb.getNumberOfSheets (); - shnames = char (wb.getSheetNames ()); - if (isnumeric (wsh)) - if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif - sh = wb.getSheet (wsh - 1); # JXL sheet count 0-based - printf ("(Reading from worksheet %s)\n", shnames {wsh}); - else - sh = wb.getSheet (wsh); - if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif - end + persistent ctype; persistent months; + if (isempty (ctype)) + ctype = cell (11, 1); + # Get enumerated cell types. Beware as they start at 0 not 1 + ctype( 1) = (java_get ('jxl.CellType', 'BOOLEAN')).toString (); + ctype( 2) = (java_get ('jxl.CellType', 'BOOLEAN_FORMULA')).toString (); + ctype( 3) = (java_get ('jxl.CellType', 'DATE')).toString (); + ctype( 4) = (java_get ('jxl.CellType', 'DATE_FORMULA')).toString (); + ctype( 5) = (java_get ('jxl.CellType', 'EMPTY')).toString (); + ctype( 6) = (java_get ('jxl.CellType', 'ERROR')).toString (); + ctype( 7) = (java_get ('jxl.CellType', 'FORMULA_ERROR')).toString (); + ctype( 8) = (java_get ('jxl.CellType', 'NUMBER')).toString (); + ctype( 9) = (java_get ('jxl.CellType', 'LABEL')).toString (); + ctype(10) = (java_get ('jxl.CellType', 'NUMBER_FORMULA')).toString (); + ctype(11) = (java_get ('jxl.CellType', 'STRING_FORMULA')).toString (); + months = {'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'}; + endif + + rstatus = 0; + wb = xls.workbook; + + # Check if requested worksheet exists in the file & if so, get pointer + nr_of_sheets = wb.getNumberOfSheets (); + shnames = char (wb.getSheetNames ()); + if (isnumeric (wsh)) + if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif + sh = wb.getSheet (wsh - 1); # JXL sheet count 0-based + printf ("(Reading from worksheet %s)\n", shnames {wsh}); + else + sh = wb.getSheet (wsh); + if (isempty (sh)), error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); endif + end - if (isempty (cellrange)) - # Get numeric sheet pointer (1-based) - ii = 1; - while (ii <= nr_of_sheets) - if (strcmp (wsh, shnames{ii}) == 1) - wsh = ii; - ii = nr_of_sheets + 1; - else - ++ii; - endif - endwhile - # Get data rectangle row & column numbers (1-based) - [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh); - if (firstrow == 0 && lastrow == 0) - # Empty sheet - rawarr = {}; - printf ("Worksheet '%s' contains no data\n", shnames {wsh}); - rstatus = 1; - return; - else - nrows = lastrow - firstrow + 1; - ncols = rcol - lcol + 1; - endif - else - # Translate range to row & column numbers (1-based) - [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); - # Check for too large requested range against actually present range - lastrow = min (firstrow + nrows - 1, sh.getRows ()); - nrows = min (nrows, sh.getRows () - firstrow + 1); - ncols = min (ncols, sh.getColumns () - lcol + 1); - rcol = lcol + ncols - 1; - endif + if (isempty (cellrange)) + # Get numeric sheet pointer (1-based) + ii = 1; + while (ii <= nr_of_sheets) + if (strcmp (wsh, shnames{ii}) == 1) + wsh = ii; + ii = nr_of_sheets + 1; + else + ++ii; + endif + endwhile + # Get data rectangle row & column numbers (1-based) + [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh); + if (firstrow == 0 && lastrow == 0) + # Empty sheet + rawarr = {}; + printf ("Worksheet '%s' contains no data\n", shnames {wsh}); + rstatus = 1; + return; + else + nrows = lastrow - firstrow + 1; + ncols = rcol - lcol + 1; + endif + else + # Translate range to row & column numbers (1-based) + [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); + # Check for too large requested range against actually present range + lastrow = min (firstrow + nrows - 1, sh.getRows ()); + nrows = min (nrows, sh.getRows () - firstrow + 1); + ncols = min (ncols, sh.getColumns () - lcol + 1); + rcol = lcol + ncols - 1; + endif - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder - for jj = lcol : rcol - for ii = firstrow:lastrow - scell = sh.getCell (jj-1, ii-1); - switch char (scell.getType ()) - case ctype {1} # Boolean - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - case ctype {2} # Boolean formula - if (spsh_opts.formulas_as_text) - tmp = scell.getFormula (); - rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; - else - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - endif - case ctype {3} # Date - try - % Older JXL.JAR, returns float - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - catch - % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( - tmp = strsplit (char (scell.getDate ()), ' '); - yy = str2num (tmp{6}); - mo = find (ismember (months, upper (tmp{2})) == 1); - dd = str2num (tmp{3}); - hh = str2num (tmp{4}(1:2)); - mi = str2num (tmp{4}(4:5)); - ss = str2num (tmp{4}(7:8)); - if (scell.isTime ()) - yy = mo = dd = 0; - endif - rawarr {ii+1-firstrow, jj+1-lcol} = datenum (yy, mo, dd, hh, mi, ss); - end_try_catch - case ctype {4} # Date formula - if (spsh_opts.formulas_as_text) - tmp = scell.getFormula (); - rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; - else - unwind_protect - % Older JXL.JAR, returns float - tmp = scell.getValue (); - % if we get here, we got a float (old JXL). - % Check if it is time - if (~scell.isTime ()) - % Reset rawarr <> so it can be processed below as date string - rawarr {ii+1-firstrow, jj+1-lcol} = []; - else - rawarr {ii+1-firstrow, jj+1-lcol} = tmp; - end - unwind_protect_cleanup - if (isempty (rawarr {ii+1-firstrow, jj+1-lcol})) - % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( - tmp = strsplit (char (scell.getDate ()), ' '); - yy = str2num (tmp{6}); - mo = find (ismember (months, upper (tmp{2})) == 1); - dd = str2num (tmp{3}); - hh = str2num (tmp{4}(1:2)); - mi = str2num (tmp{4}(4:5)); - ss = str2num (tmp{4}(7:8)); - if (scell.isTime ()) - yy = 0; mo = 0; dd = 0; - end - rawarr {ii+1-firstrow, jj+1-lcol} = datenum (yy, mo, dd, hh, mi, ss); - endif - end_unwind_protect - endif - case { ctype {5}, ctype {6}, ctype {7} } - # Empty, Error or Formula error. Nothing to do here - case ctype {8} # Number - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - case ctype {9} # String - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); - case ctype {10} # Numerical formula - if (spsh_opts.formulas_as_text) - tmp = scell.getFormula (); - rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; - else - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); - endif - case ctype {11} # String formula - if (spsh_opts.formulas_as_text) - tmp = scell.getFormula (); - rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; - else - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); - endif - otherwise - # Do nothing - endswitch - endfor - endfor + # Read contents into rawarr + rawarr = cell (nrows, ncols); # create placeholder + for jj = lcol : rcol + for ii = firstrow:lastrow + scell = sh.getCell (jj-1, ii-1); + switch char (scell.getType ()) + case ctype {1} # Boolean + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); + case ctype {2} # Boolean formula + if (spsh_opts.formulas_as_text) + tmp = scell.getFormula (); + rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; + else + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); + endif + case ctype {3} # Date + try + % Older JXL.JAR, returns float + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); + catch + % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( + tmp = strsplit (char (scell.getDate ()), ' '); + yy = str2num (tmp{6}); + mo = find (ismember (months, upper (tmp{2})) == 1); + dd = str2num (tmp{3}); + hh = str2num (tmp{4}(1:2)); + mi = str2num (tmp{4}(4:5)); + ss = str2num (tmp{4}(7:8)); + if (scell.isTime ()) + yy = mo = dd = 0; + endif + rawarr {ii+1-firstrow, jj+1-lcol} = datenum (yy, mo, dd, hh, mi, ss); + end_try_catch + case ctype {4} # Date formula + if (spsh_opts.formulas_as_text) + tmp = scell.getFormula (); + rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; + else + unwind_protect + % Older JXL.JAR, returns float + tmp = scell.getValue (); + % if we get here, we got a float (old JXL). + % Check if it is time + if (~scell.isTime ()) + % Reset rawarr <> so it can be processed below as date string + rawarr {ii+1-firstrow, jj+1-lcol} = []; + else + rawarr {ii+1-firstrow, jj+1-lcol} = tmp; + end + unwind_protect_cleanup + if (isempty (rawarr {ii+1-firstrow, jj+1-lcol})) + % Newer JXL.JAR, returns date string w. epoch = 1-1-1900 :-( + tmp = strsplit (char (scell.getDate ()), ' '); + yy = str2num (tmp{6}); + mo = find (ismember (months, upper (tmp{2})) == 1); + dd = str2num (tmp{3}); + hh = str2num (tmp{4}(1:2)); + mi = str2num (tmp{4}(4:5)); + ss = str2num (tmp{4}(7:8)); + if (scell.isTime ()) + yy = 0; mo = 0; dd = 0; + end + rawarr {ii+1-firstrow, jj+1-lcol} = datenum (yy, mo, dd, hh, mi, ss); + endif + end_unwind_protect + endif + case { ctype {5}, ctype {6}, ctype {7} } + # Empty, Error or Formula error. Nothing to do here + case ctype {8} # Number + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); + case ctype {9} # String + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); + case ctype {10} # Numerical formula + if (spsh_opts.formulas_as_text) + tmp = scell.getFormula (); + rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; + else + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getValue (); + endif + case ctype {11} # String formula + if (spsh_opts.formulas_as_text) + tmp = scell.getFormula (); + rawarr {ii+1-firstrow, jj+1-lcol} = ["=" tmp]; + else + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getString (); + endif + otherwise + # Do nothing + endswitch + endfor + endfor - rstatus = 1; - xls.limits = [lcol, rcol; firstrow, lastrow]; - + rstatus = 1; + xls.limits = [lcol, rcol; firstrow, lastrow]; + endfunction @@ -796,84 +797,84 @@ function [ rawarr, xls, rstatus ] = xls2oxs2oct (xls, wsh, cellrange, spsh_opts) - persistent ctype; - if (isempty (ctype)) - ctype = zeros (6, 1); - # Get enumerated cell types. Beware as they start at 0 not 1 - ctype( 1) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_STRING')); # 0 - ctype( 2) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FP')); # 1 - ctype( 3) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_INT')); # 2 - ctype( 4) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FORMULA')); # 3 - ctype( 5) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_BOOLEAN')); # 4 - ctype( 6) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_DOUBLE')); # 5 - endif - - rstatus = 0; - wb = xls.workbook; - - # Check if requested worksheet exists in the file & if so, get pointer - nr_of_sheets = wb.getNumWorkSheets (); - if (isnumeric (wsh)) - if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif - sh = wb.getWorkSheet (wsh - 1); # OXS sheet count 0-based - printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); - else - try - sh = wb.getWorkSheet (wsh); - catch - error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); - end_try_catch - end + persistent ctype; + if (isempty (ctype)) + ctype = zeros (6, 1); + # Get enumerated cell types. Beware as they start at 0 not 1 + ctype( 1) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_STRING')); # 0 + ctype( 2) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FP')); # 1 + ctype( 3) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_INT')); # 2 + ctype( 4) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_FORMULA')); # 3 + ctype( 5) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_BOOLEAN')); # 4 + ctype( 6) = (java_get ('com.extentech.ExtenXLS.CellHandle', 'TYPE_DOUBLE')); # 5 + endif + + rstatus = 0; + wb = xls.workbook; + + # Check if requested worksheet exists in the file & if so, get pointer + nr_of_sheets = wb.getNumWorkSheets (); + if (isnumeric (wsh)) + if (wsh > nr_of_sheets), error (sprintf ("Worksheet # %d bigger than nr. of sheets (%d) in file %s", wsh, nr_of_sheets, xls.filename)); endif + sh = wb.getWorkSheet (wsh - 1); # OXS sheet count 0-based + printf ("(Reading from worksheet %s)\n", sh.getSheetName ()); + else + try + sh = wb.getWorkSheet (wsh); + catch + error (sprintf ("Worksheet %s not found in file %s", wsh, xls.filename)); + end_try_catch + end - if (isempty (cellrange)) - # Get numeric sheet pointer (0-based) - wsh = sh.getTabIndex (); - # Get data rectangle row & column numbers (1-based) - [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh+1); - if (firstrow == 0 && lastrow == 0) - # Empty sheet - rawarr = {}; - printf ("Worksheet '%s' contains no data\n", shnames {wsh}); - rstatus = 1; - return; - else - nrows = lastrow - firstrow + 1; - ncols = rcol - lcol + 1; - endif - else - # Translate range to row & column numbers (1-based) - [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); - # Check for too large requested range against actually present range - lastrow = min (firstrow + nrows - 1, sh.getLastRow + 1 ()); - nrows = min (nrows, sh.getLastRow () - firstrow + 1); - ncols = min (ncols, sh.getLastCol () - lcol + 1); - rcol = lcol + ncols - 1; - endif + if (isempty (cellrange)) + # Get numeric sheet pointer (0-based) + wsh = sh.getTabIndex (); + # Get data rectangle row & column numbers (1-based) + [firstrow, lastrow, lcol, rcol] = getusedrange (xls, wsh+1); + if (firstrow == 0 && lastrow == 0) + # Empty sheet + rawarr = {}; + printf ("Worksheet '%s' contains no data\n", shnames {wsh}); + rstatus = 1; + return; + else + nrows = lastrow - firstrow + 1; + ncols = rcol - lcol + 1; + endif + else + # Translate range to row & column numbers (1-based) + [dummy, nrows, ncols, firstrow, lcol] = parse_sp_range (cellrange); + # Check for too large requested range against actually present range + lastrow = min (firstrow + nrows - 1, sh.getLastRow + 1 ()); + nrows = min (nrows, sh.getLastRow () - firstrow + 1); + ncols = min (ncols, sh.getLastCol () - lcol + 1); + rcol = lcol + ncols - 1; + endif - # Read contents into rawarr - rawarr = cell (nrows, ncols); # create placeholder - for jj = lcol:rcol - for ii = firstrow:lastrow - try - scell = sh.getCell (ii-1, jj-1); - sctype = scell.getCellType (); - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getVal (); - if (sctype == ctype(2) || sctype == ctype(3) || sctype == ctype(6)) - rawarr {ii+1-firstrow, jj+1-lcol} = scell.getDoubleVal (); - endif - catch - # Empty or non-existing cell - end_try_catch - endfor - endfor + # Read contents into rawarr + rawarr = cell (nrows, ncols); # create placeholder + for jj = lcol:rcol + for ii = firstrow:lastrow + try + scell = sh.getCell (ii-1, jj-1); + sctype = scell.getCellType (); + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getVal (); + if (sctype == ctype(2) || sctype == ctype(3) || sctype == ctype(6)) + rawarr {ii+1-firstrow, jj+1-lcol} = scell.getDoubleVal (); + endif + catch + # Empty or non-existing cell + end_try_catch + endfor + endfor - rstatus = 1; - xls.limits = [lcol, rcol; firstrow, lastrow]; - + rstatus = 1; + xls.limits = [lcol, rcol; firstrow, lastrow]; + endfunction -## Copyright (C) 2011 Philip Nienhuis <prn...@us...> +## Copyright (C) 2011,2012 Philip Nienhuis <prn...@us...> ## ## 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 @@ -909,7 +910,7 @@ # Check sheet pointer if (isnumeric (wsh)) - if (wsh < 1 || wsh > numel (sh_names)) + if (wsh < 1 || wsh > numel (sh_names)) error ("Sheet index %d out of range 1-%d", wsh, numel (sh_names)); endif else @@ -944,8 +945,8 @@ # out-of-range errors [ trow, brow, lcol, rcol ] = getusedrange (xls, wsh); if (isempty (datrange)) - nrows = brow - trow + 1; # Number of rows to be read - ncols = rcol - lcol + 1; # Number of columns to be read + nrows = brow - trow + 1; # Number of rows to be read + ncols = rcol - lcol + 1; # Number of columns to be read else [dummy, nrows, ncols, srow, scol] = parse_sp_range (datrange); # Truncate range silently if needed @@ -953,8 +954,8 @@ rcol = min (scol + ncols - 1, rcol); trow = max (trow, srow); lcol = max (lcol, scol); - nrows = min (brow - trow + 1, nrows); # Number of rows to be read - ncols = min (rcol - lcol + 1, ncols); # Number of columns to be read + nrows = min (brow - trow + 1, nrows); # Number of rows to be read + ncols = min (rcol - lcol + 1, ncols); # Number of columns to be read endif # Create storage for data at Octave side rawarr = cell (nrows, ncols); @@ -965,12 +966,12 @@ XCell = sh.getCellByPosition (jj, ii); cType = XCell.getType().getValue (); switch cType - case 1 # Value + case 1 # Value rawarr{ii-trow+2, jj-lcol+2} = XCell.getValue (); - case 2 # String + case 2 # String unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.text.XText'); rawarr{ii-trow+2, jj-lcol+2} = XCell.queryInterface (unotmp).getString (); - case 3 # Formula + case 3 # Formula if (spsh_opts.formulas_as_text) rawarr{ii-trow+2, jj-lcol+2} = XCell.getFormula (); else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-07 16:35:52
|
Revision: 10584 http://octave.svn.sourceforge.net/octave/?rev=10584&view=rev Author: prnienhuis Date: 2012-06-07 16:35:46 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Updated / spell checks Modified Paths: -------------- trunk/octave-forge/main/io/doc/READ-ODS.html trunk/octave-forge/main/io/doc/READ-XLS.html Modified: trunk/octave-forge/main/io/doc/READ-ODS.html =================================================================== --- trunk/octave-forge/main/io/doc/READ-ODS.html 2012-06-07 15:50:19 UTC (rev 10583) +++ trunk/octave-forge/main/io/doc/READ-ODS.html 2012-06-07 16:35:46 UTC (rev 10584) @@ -18,7 +18,7 @@ Copyright \xA9 2009 - 2012 Philip Nienhuis <prnienhuis at users.sf.net></font></font> </p> <p align="center"><font face="Arial, sans-serif"><font size="2"> - This version April 09, 2012</font></font> + This version June 07, 2012</font></font> </p> <p><font face="Arial, sans-serif"><font size="2"> <i>(ODS = Open Document Format spreadsheet data format, used by e.g., OpenOffice.org.)</i></font></font> @@ -62,7 +62,11 @@ <font face="Arial, sans-serif"><font size="2"><b>calccelladdress.m</b></font></font></dt><dt style="font-style: italic;"> <font face="Arial, sans-serif"><font size="2"><b>parse_sp_range.m</b></font></font></dt><dt> <font face="Arial, sans-serif"><font size="2">Support files called by - the scripts and not meant for direct invocation by users.</font></font></dt><dd></dd> + the scripts and not meant for direct invocation by users.</font></font></dt><dt> + <p><font face="Arial, sans-serif"><font size="2"><i><b>io_ods_testscript.m</b></i> + <br>Script for testing basic operation of ODS spreadsheet functions.</font></font></p><br></dt> + + </dl> <p align="center"><font face="Arial, sans-serif"><font size="4"><u><b>REQUIRED SUPPORT SOFTWARE</b></u></font></font></p><dl> @@ -172,10 +176,10 @@ interface you can:</font></font></dt></dl> <ul> <li> - <font face="Arial, sans-serif"><font size="2">(When reading, <b>od</b><b>s2oct</b>) + <font face="Arial, sans-serif"><font size="2">(When reading, <b>ods2oct</b>) either read spreadsheet formula results, or the literal formula text strings;</font></font></li><li> - <font face="Arial, sans-serif"><font size="2">(When writing, <b>oct2</b><b>od</b><b>s</b>) + <font face="Arial, sans-serif"><font size="2">(When writing, <b>oct2ods</b>) either enter formulas in the worksheet as formulas, or enter them as literal text strings.</font></font></li></ul> <font face="Arial, sans-serif"><font size="2">In short, you can @@ -550,7 +554,7 @@ <font face="Arial, sans-serif"><font size="2">oct2ods.m (revision 7159)</font></font></li></ul> <p><font face="Arial, sans-serif"><font size="2">Enjoy!</font></font></p><p align="center"><font face="Arial, sans-serif"><font size="2">Philip - Nienhuis, April 09, 2012</font></font></p><dl><dd><p align="center"> + Nienhuis, June 07, 2012</font></font></p><dl><dd><p align="center"> <br> </p></dd></dl> </body></html> \ No newline at end of file Modified: trunk/octave-forge/main/io/doc/READ-XLS.html =================================================================== --- trunk/octave-forge/main/io/doc/READ-XLS.html 2012-06-07 15:50:19 UTC (rev 10583) +++ trunk/octave-forge/main/io/doc/READ-XLS.html 2012-06-07 16:35:46 UTC (rev 10584) @@ -13,7 +13,7 @@ <BR> Copyright (C) 2009 - 2012 Philip Nienhuis <prnienhuis at users.sf.net><BR> <BR> -This version Februari 26, 2012</P> +This version June 7, 2012</P> </FONT></FONT><B><U><FONT FACE="Arial, sans-serif" SIZE=4><FONT FACE="Arial, sans-serif" SIZE=4><P ALIGN="CENTER">EXCEL .XLS SUPPORT FILES</P> </B></U></FONT></FONT><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2><DL> <DT><BR> @@ -48,7 +48,11 @@ </DL> <B>spsh_chkrange.m</B>,</FONT></FONT> <B><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2>spsh_prstype.m</B>,</FONT></FONT> <B><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2>getusedrange.m</B>,</FONT></FONT> <B><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2>calccelladdress.m</B>,</FONT></FONT> <B><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2>parse_sp_range.m </B> -<DT>Support files called by the scripts and not meant for direct invocation by users.</DT> +<DT>Support files called by the scripts and not meant for direct invocation by users.<BR></DT> +<BR> +<DT><B>io_xls_testscript.m</B></DT> +<DT>Script for testing basic features of the spreadsheet scripts.</DT> +</DL> <P ALIGN="CENTER"><BR> </FONT></FONT><B><U><FONT FACE="Arial, sans-serif" SIZE=4><FONT FACE="Arial, sans-serif" SIZE=4>REQUIRED SUPPORT SOFTWARE</P> </B></U></FONT></FONT><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2><DL> @@ -165,12 +169,12 @@ </FONT></FONT><B><U><FONT FACE="Arial, sans-serif" SIZE=4><FONT FACE="Arial, sans-serif" SIZE=4><P ALIGN="CENTER">SPREADSHEET FORMULA SUPPORT</P> </B></U></FONT></FONT><FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2><DL> <DT><BR> -When using the POI, JXL and UNO interfaces you can:</DT> +When using the COM, POI, JXL, and UNO interfaces you can:</DT> </DL> <UL> -<LI>(When reading, xls2oct) either read spreadsheet formula results (like in COM interface), or the literal formula text strings;</LI> -<LI>(When writing, oct2xls) either enter formulas in the worksheet as formulas, or enter them as literal text strings. The former is also like in COM.</LI></UL> +<LI>(When reading, xls2oct) either read evaluated spreadsheet formula results, or the literal formula text strings;</LI> +<LI>(When writing, oct2xls) either enter text strings in the form of spreadsheet formulas in the worksheet as formulas, or enter them as literal text strings.</LI></UL> <P>In short, you can enter spreadsheet formulas and in a later stage read them back, change them and re-enter them in the worksheet. </P> <DL> @@ -221,9 +225,9 @@ <DT>JexcelAPI, unlike ApachePOI, doesn't evaluate functions while reading but instead relies on cached results (i.e. results computed by Excel itself). Depending on Excel settings ("Automatic calculation" ON or OFF) this may or may not yield incorrect (or expected) results. <BR> <BR> <b>Apache POI</b> (Java-based and platform-independent too) is based on the OpenOffice.org I/O Excel r/w routines. It is a more versatile than JExcelAPI, while it doesn't support BIFF5 it does support BIFF8 (Excel 97 \x96 2003) and OOXML (Excel 2007).</DT> -<DT>It is slower than native JXL let alone Excel & COM but it features active formula evaluation, although at the moment (v. 3.7) not all Excel functions have been implemented. I've made the relevant subfunction (xls2jpoi2oct) fall back to cached formula results (and yield a suitable warning) for non-implemented Excel functions while reading Excel files. <BR> +<DT>It is slower than native JXL let alone Excel & COM but it features active formula evaluation, although at the moment (v. 3.8) still not all Excel functions have been implemented. I've made the relevant subfunction (xls2jpoi2oct) fall back to cached formula results (and yield a suitable warning) for non-implemented Excel functions while reading Excel files. <BR> <BR> -<b>OpenXLS</b> (an open source version of Extentech's commercial Java-xls product) is still experimental. It seems to work faster than JExcelAPI, but it has other issues - i.e., it locks the .xls file and the unlocking mechanism is a bit wonky. Sometimes xls files keep being locked until Octave is shut down. Currently OXS write support is disabled (but the code is there). OpenmXLS doesn't support reading back formulas astext strings.<BR> +<b>OpenXLS</b> (an open source version of Extentech's commercial Java-xls product) is still experimental. It seems to work faster than JExcelAPI, but it has other issues - i.e., it locks the .xls file and the unlocking mechanism is a bit wonky. Sometimes xls files keep being locked until Octave is shut down. Currently OXS write support is disabled (but the code is there). OpenXLS doesn't support reading back formulas as text strings.<BR> <BR> <b>UNO</b> (invoking OpenOffice.org or clones behind the scenes, a la ActiveX) is experimental. It works FAST (i.e., once OOo itself is loaded which can take some time) and can process much larger spreadsheets than the other Java-based interfaces because the data are not entered in the JVM but in OOo's memory.<BR> A big stumbling block is that odsclose() on a UNO xls struct will kill ALL OpenOffice.org invocations, also those that were not related to Octave! This is due to UNO-Java limitations.<br> @@ -323,6 +327,6 @@ <P>Enjoy!</FONT></FONT> </P> <FONT FACE="Arial, sans-serif" SIZE=2><FONT FACE="Arial, sans-serif" SIZE=2><DL> -<DD ALIGN="CENTER">Philip Nienhuis, Februari 26, 2012</DD> +<DD ALIGN="CENTER">Philip Nienhuis, June 7, 2012</DD> </DL></FONT></FONT></BODY> </HTML> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mtm...@us...> - 2012-06-07 15:50:25
|
Revision: 10583 http://octave.svn.sourceforge.net/octave/?rev=10583&view=rev Author: mtmiller Date: 2012-06-07 15:50:19 +0000 (Thu, 07 Jun 2012) Log Message: ----------- signal: use mkoctfile defined by pkg in the environment Modified Paths: -------------- trunk/octave-forge/main/signal/src/Makefile Modified: trunk/octave-forge/main/signal/src/Makefile =================================================================== --- trunk/octave-forge/main/signal/src/Makefile 2012-06-07 14:42:28 UTC (rev 10582) +++ trunk/octave-forge/main/signal/src/Makefile 2012-06-07 15:50:19 UTC (rev 10583) @@ -1,3 +1,5 @@ +MKOCTFILE ?= mkoctfile + all: cl2bp.oct remez.oct medfilt1.oct sosfilt.oct upfirdn.oct CL2BP_DEFINES = @@ -4,15 +6,15 @@ # CL2BP_DEFINES = -DCL2BP_LOGGING cl2bp.o: cl2bp.cc cl2bp_lib.h - mkoctfile -Wall $(CL2BP_DEFINES) -c $< + $(MKOCTFILE) -Wall $(CL2BP_DEFINES) -c $< cl2bp_lib.o: cl2bp_lib.cc cl2bp_lib.h - mkoctfile -Wall $(CL2BP_DEFINES) -c $< + $(MKOCTFILE) -Wall $(CL2BP_DEFINES) -c $< cl2bp.oct: cl2bp.o cl2bp_lib.o - mkoctfile -Wall -s $^ + $(MKOCTFILE) -Wall -s $^ %.oct: %.cc - mkoctfile -Wall -s $< + $(MKOCTFILE) -Wall -s $< clean: ; -rm -f *.o core octave-core *.oct *~ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-06-07 14:42:39
|
Revision: 10582 http://octave.svn.sourceforge.net/octave/?rev=10582&view=rev Author: benjf5 Date: 2012-06-07 14:42:28 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Focus now on fastlscomplex.cc, which is still a work in progress. Added Paths: ----------- trunk/octave-forge/extra/lssa/fastlscomplex.cc Added: trunk/octave-forge/extra/lssa/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/fastlscomplex.cc (rev 0) +++ trunk/octave-forge/extra/lssa/fastlscomplex.cc 2012-06-07 14:42:28 UTC (rev 10582) @@ -0,0 +1,246 @@ + +#include <octave/oct.h> +#include <octave/unwind-prot.h> +#include <complex> +#include <string> +#include <math.h> +#include <iostream> + +ComplexRowVector flscomplex( RowVector tvec , ComplexRowVector xvec , + int coefficients, int octaves, double maxfreq ); + + +DEFUN_DLD(fastlscomplex,args,nargout, "Takes the complex fast least-squares transform of a set of data.") { + RowVector tvals = args(0).row_vector_value(); + ComplexRowVector xvals = args(1).complex_row_vector_value(); + int ncoeff = args(2).int_value(); + int noctaves = args(3).int_value(); + double omegamax = args(4).double_value(); + octave_value_list retval; + if ( !error_state) { + std::cout << "All values loaded safely! Your problem is in flscomplex." << std::endl; + ComplexRowVector results = flscomplex(tvals,xvals,ncoeff,noctaves,omegamax); + retval(0) = octave_value(results); + } + return retval; + +} + +ComplexRowVector flscomplex( RowVector tvec , ComplexRowVector xvec , + int coefficients, int octaves, double maxfreq ) { + struct Precomputation_Record { + Precomputation_Record *next; + std::complex<double> power_series[12]; // I'm using 12 as a matter of compatibility, only. + bool stored_data; + }; + + ComplexRowVector results = ComplexRowVector (coefficients * octaves ); + + double tau, delta_tau, tau_0, tau_h, n_inv, mu, + omega_oct, omega_multiplier, octavemax, omega_working, + loop_tau_0, loop_delta_tau; + double length = ( tvec((tvec.numel()-1)) - tvec( octave_idx_type (0))); + int octave_iter, coeff_iter; + std::complex<double> zeta, z_accumulator, exp_term, exp_multiplier, alpha; + octave_idx_type n = tvec.numel(); + std::complex<double> temp_array[12]; + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + temp_array[array_iter] = std::complex<double> ( 0 , 0 ); + } + std::cout << "temp_array built." << std::endl; //errcheckline + n_inv = 1.0 / n; + mu = (0.5 * M_PI)/length; // Per the article; this is in place to improve numerical accuracy if desired. + /* Viz. the paper, in which Dtau = c / omega_max, and c is stated as pi/2 for floating point processors, + * In the case of this computation, I'll go by the recommendation. + */ + delta_tau = M_PI / ( 2 * maxfreq ); + tau_0 = tvec(0) + delta_tau; + tau_h = tau_0; + size_t precomp_subset_count = (size_t) ceil( ( tvec(tvec.numel()-1) - tvec(0) ) / ( 2 * delta_tau ) ); + // I've used size_t because it will work for my purposes without threatening undefined behaviour. + const std::complex<double> im = std::complex<double> ( 0 , 1 ); + + octave_idx_type k ( 0 ); // Iterator for accessing xvec, tvec. + + Precomputation_Record * precomp_records_head, *record_current, *record_tail, *record_ref, *record_next; + record_current = precomp_records_head = new Precomputation_Record; + for ( size_t p_r_iter = 1 ; p_r_iter < precomp_subset_count ; p_r_iter++ ) { + record_current->next = new Precomputation_Record; + record_current = record_current->next; + } + record_tail = record_current; + record_current = precomp_records_head; + record_tail->next = 0; + /* A test needs to be included for if there was a failure, but since + * precomp_subset_count is of type size_t, it should be okay. */ + + for( ; record_current ; record_current = record_current->next ) { + for ( int j = 0 ; j < 12 ; j++ ) { + record_current->power_series[j] = std::complex<double> ( 0 , 0 ); + } // To avoid any trouble down the line, although it is an annoyance. + while ( ( k < n ) && ( ( - delta_tau ) <= ( tvec(k) - tau_h ) ) && ( ( tvec(k) - tau_h ) < delta_tau ) ) { + double p; + alpha = std::complex<double> ( 0 , 0 ); + for ( int j = 0 ; j < 12 ; j++ ) { + alpha.real() = xvec(k).real(); + alpha.imag() = xvec(k).imag(); + // alpha = std::complex<double> ( xvec(k).real() , xvec(k).imag() ); + if ( j == 0 ) { + p = 1; + } else { + p *= 1/(double)j; + // alpha *= ( -1 * im * mu * ( tvec(k) - tau_h ) ) * p; + if ( !( j % 2 ) ) { + if ( ! ( j % 4 ) ) { + alpha.real() = xvec(k).real() * pow(mu,j) * pow(tvec(k)-tau_h,j); + alpha.imag() = xvec(k).imag() * pow(mu,j) * pow(tvec(k)-tau_h,j); + } else { + alpha.real() = -1 * xvec(k).real() * pow(mu,j) * pow(tvec(k)-tau_h,j); + alpha.imag() = -1 * xvec(k).imag() * pow(mu,j) * pow(tvec(k)-tau_h,j); + } } else { + if ( ! ( j % 3 ) ) { + alpha.real() = -1 * xvec(k).imag() * pow(mu,j) * pow(tvec(k)-tau_h,j); + alpha.imag() = -1 * xvec(k).real() * pow(mu,j) * pow(tvec(k)-tau_h,j); + } else { + alpha.real() = xvec(k).imag() * pow(mu,j) * pow(tvec(k)-tau_h,j); + alpha.imag() = xvec(k).real() * pow(mu,j) * pow(tvec(k)-tau_h,j); + } + } + } + record_current->power_series[j].real() += alpha.real(); + record_current->power_series[j].imag() += alpha.imag(); + // Computes each next step of the power series for the given power series element. + // j was reused since it was a handy inner-loop variable, even though I used it twice here. + } + record_current->stored_data = true; + k++; + } + tau_h += ( 2 * delta_tau ); + } + std::cout << "all records computed." << std::endl; + // At this point all precomputation records have been exhausted; short-circuit is abused to avoid overflow errors. + + /* Summation of coefficients for each frequency. As we have ncoeffs * noctaves elements, + * it makes sense to work from the top down, as we have omega_max by default (maxfreq) + */ + + omega_oct = maxfreq / mu; + omega_multiplier = exp(-log(2)/coefficients); + octavemax = maxfreq; + loop_tau_0 = tau_0; + loop_delta_tau = delta_tau; + + octave_idx_type iter ( 0 ); + + double real_part = 0, imag_part = 0, real_part_accumulator = 0, imag_part_accumulator = 0; + + // Loops need to first travel over octaves, then coefficients; + + for ( octave_iter = octaves ; ; omega_oct *= 0.5 , octavemax *= 0.5 , loop_tau_0 += loop_delta_tau , loop_delta_tau *= 2 ) { + omega_working = omega_oct; + for ( coeff_iter = 0 ; coeff_iter < coefficients ; coeff_iter++, omega_working *= omega_multiplier){ + exp_term = std::complex<double> ( cos( - omega_working * loop_tau_0 ) , + sin ( - omega_working * loop_tau_0 ) ); + exp_multiplier = std::complex<double> ( cos ( - 2 * omega_working * loop_delta_tau ) , + sin ( - 2 * omega_working * loop_delta_tau ) ); + // zeta = std::complex<double> (0,0); + real_part_accumulator = 0; + imag_part_accumulator = 0; + real_part = 0; + imag_part = 0; + for ( record_current = precomp_records_head ; record_current ; + record_current = record_current->next, exp_term *= exp_multiplier ) { + // z_accumulator = std::complex<double> ( 0 , 0 ); + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + z_accumulator = ( pow(omega_working,array_iter) * record_current->power_series[array_iter] ); + real_part_accumulator += z_accumulator.real(); + imag_part_accumulator += z_accumulator.imag(); + } + real_part = real_part + ( exp_term.real() * real_part_accumulator - ( exp_term.imag() * imag_part_accumulator ) ); + imag_part = imag_part + ( exp_term.imag() * real_part_accumulator + exp_term.real() * imag_part_accumulator ); + // zeta += ( exp_term * z_accumulator ); + } + results(iter) = std::complex<double> ( n_inv * real_part , n_inv * imag_part ); + std::cout << iter << std::endl; + iter++; + } + if ( !(--octave_iter) ) break; + /* If we've already reached the lowest value, stop. + * Otherwise, merge with the next computation range. + */ + std::cout << "100 terms precomputed" << std::endl; + double exp_power_series_elements[12]; + for ( int r_iter = 0 ; r_iter < 12 ; r_iter++ ) { + exp_power_series_elements[r_iter] = ( r_iter == 0 ) ? 1 : exp_power_series_elements[r_iter-1] + * ( mu * loop_delta_tau) * ( 1.0 / ( (double) r_iter ) ); + } + std::cout << "Exponential series computed" << std::endl; + for ( record_current = precomp_records_head ; record_current ; + record_current = record_current->next ) { + if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { + if ( record_current->stored_data ) { + std::complex<double> temp[12]; + for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } + for( int p = 0 ; p < 12 ; p ++ ) { + double step_floor_r = floor( ( (double) p ) / 2.0 ); + double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); + for( int q = 0 ; q < step_floor_r ; q++ ) { + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q )]; + } + for( int q = 0 ; q <= step_floor_i ; q++ ) { + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * record_current->power_series[p - ( 2 * q ) - 1]; + } + } + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + record_current->power_series[array_iter].real() = temp[array_iter].real(); + record_current->power_series[array_iter].imag() = temp[array_iter].imag(); + } + if ( ! record_ref ) break; // Last record was reached + } + else { + record_next = record_ref; + if ( record_current->stored_data ) { + std::complex<double> temp[12]; + for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } + for( int p = 0 ; p < 12 ; p ++ ) { + double step_floor_r = floor( ( (double) p ) / 2.0 ); + double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); + for( int q = 0 ; q < step_floor_r ; q++ ) { + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q )] - record_next->power_series[p - (2*q)] ); + } + for( int q = 0 ; q <= step_floor_i ; q++ ) { + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,q) * ( record_current->power_series[p - ( 2 * q ) - 1] - record_next->power_series[p - ( 2 * q ) - 1 ] ); + } + } + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + record_current->power_series[array_iter].real() = temp[array_iter].real(); + record_current->power_series[array_iter].imag() = temp[array_iter].imag(); + } + } else { + std::complex<double> temp[12]; + for( int array_init = 0 ; array_init < 12 ; array_init++ ) { temp[array_init] = std::complex<double>(0,0); } + for( int p = 0 ; p < 12 ; p ++ ) { + double step_floor_r = floor( ( (double) p ) / 2.0 ); + double step_floor_i = floor( ( (double) ( p - 1 ) ) / 2.0 ); + for( int q = 0 ; q < step_floor_r ; q++ ) { + temp[p] += exp_power_series_elements[2*q] * pow((double)-1,q) * record_next->power_series[p - ( 2 * q )]; + } + for( int q = 0 ; q <= step_floor_i ; q++ ) { + temp[p] += im * exp_power_series_elements[2 * q + 1] * pow((double)-1,(q+1)) * record_next->power_series[p - ( 2 * q ) - 1]; + } + } + for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { + record_current->power_series[array_iter].real() = temp[array_iter].real(); + record_current->power_series[array_iter].imag() = temp[array_iter].imag(); + } + } + record_current->stored_data = true; + record_ref = record_next; + record_current->next = record_ref->next; + delete record_ref; + } + } + } + } + return results; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2012-06-07 13:27:35
|
Revision: 10581 http://octave.svn.sourceforge.net/octave/?rev=10581&view=rev Author: i7tiol Date: 2012-06-07 13:27:29 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Lapack of __disna_optim__, as an exception, may not be configured. Modified Paths: -------------- trunk/octave-forge/main/optim/src/Makefile Modified: trunk/octave-forge/main/optim/src/Makefile =================================================================== --- trunk/octave-forge/main/optim/src/Makefile 2012-06-07 12:01:46 UTC (rev 10580) +++ trunk/octave-forge/main/optim/src/Makefile 2012-06-07 13:27:29 UTC (rev 10581) @@ -1,19 +1,30 @@ MKOCTFILE ?= mkoctfile LAPACK_LIBS ?= $(shell $(MKOCTFILE) -p LAPACK_LIBS) +OCTAVE_LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) # reported necessary for Apple's VecLib framework by Carlo de Falco # <car...@gm...> BLAS_LIBS ?= $(shell $(MKOCTFILE) -p BLAS_LIBS) +OCTAVE_BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) # Passing LFLAGS, supplemented with LAPACK_LIBS and BLAS_LIBS, in the # environment to mkoctfile is prefered over passing LAPACK_LIBS and # BLAS_LIBS in mkoctfiles commandline due to mkoctfiles difficulties # with non-standard flags on some systems (e.g. -framework ... on # Apple) -LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) +OCTAVE_LFLAGS := $(LFLAGS) +LFLAGS += $(LAPACK_LIBS) +LFLAGS += $(BLAS_LIBS) +OCTAVE_LFLAGS += $(OCTAVE_LAPACK_LIBS) +OCTAVE_LFLAGS += $(OCTAVE_BLAS_LIBS) all: __bfgsmin.oct numgradient.oct numhessian.oct samin.oct __disna_optim__.oct +# __disna_optim__ should be linked to the same Lapack library as used by Octave +__disna_optim__.oct: __disna_optim__.cc + LFLAGS="$(OCTAVE_LFLAGS)" $(MKOCTFILE) -s __disna_optim__.cc + %.oct: %.cc LFLAGS="$(LFLAGS)" $(MKOCTFILE) -s $< This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-07 12:01:56
|
Revision: 10580 http://octave.svn.sourceforge.net/octave/?rev=10580&view=rev Author: paramaniac Date: 2012-06-07 12:01:46 +0000 (Thu, 07 Jun 2012) Log Message: ----------- control: apply improved Makefile patch by Olaf Till Modified Paths: -------------- trunk/octave-forge/main/control/src/Makefile Modified: trunk/octave-forge/main/control/src/Makefile =================================================================== --- trunk/octave-forge/main/control/src/Makefile 2012-06-07 11:55:26 UTC (rev 10579) +++ trunk/octave-forge/main/control/src/Makefile 2012-06-07 12:01:46 UTC (rev 10580) @@ -1,8 +1,8 @@ MKOCTFILE ?= mkoctfile -LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) -BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) -FLIBS := $(shell $(MKOCTFILE) -p FLIBS) +LAPACK_LIBS ?= $(shell $(MKOCTFILE) -p LAPACK_LIBS) +BLAS_LIBS ?= $(shell $(MKOCTFILE) -p BLAS_LIBS) +FLIBS ?= $(shell $(MKOCTFILE) -p FLIBS) LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) all: control_slicot_functions.oct \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-07 11:55:32
|
Revision: 10579 http://octave.svn.sourceforge.net/octave/?rev=10579&view=rev Author: paramaniac Date: 2012-06-07 11:55:26 +0000 (Thu, 07 Jun 2012) Log Message: ----------- control: apply Makefile patch by Olaf Till Modified Paths: -------------- trunk/octave-forge/main/control/src/Makefile Modified: trunk/octave-forge/main/control/src/Makefile =================================================================== --- trunk/octave-forge/main/control/src/Makefile 2012-06-07 11:48:22 UTC (rev 10578) +++ trunk/octave-forge/main/control/src/Makefile 2012-06-07 11:55:26 UTC (rev 10579) @@ -3,6 +3,7 @@ LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) FLIBS := $(shell $(MKOCTFILE) -p FLIBS) +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) all: control_slicot_functions.oct \ is_real_scalar.oct \ @@ -28,8 +29,8 @@ # slicot functions control_slicot_functions.oct: control_slicot_functions.cc slicotlibrary.a - $(MKOCTFILE) control_slicot_functions.cc common.cc slicotlibrary.a \ - ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} + LFLAGS="$(LFLAGS)" \ + $(MKOCTFILE) control_slicot_functions.cc common.cc slicotlibrary.a # helpers is_real_scalar.oct: is_real_scalar.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2012-06-07 11:48:31
|
Revision: 10578 http://octave.svn.sourceforge.net/octave/?rev=10578&view=rev Author: i7tiol Date: 2012-06-07 11:48:22 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Allow user-specified LAPACK_LIBS or BLAS_LIBS. Modified Paths: -------------- trunk/octave-forge/main/optim/src/Makefile Modified: trunk/octave-forge/main/optim/src/Makefile =================================================================== --- trunk/octave-forge/main/optim/src/Makefile 2012-06-07 09:33:21 UTC (rev 10577) +++ trunk/octave-forge/main/optim/src/Makefile 2012-06-07 11:48:22 UTC (rev 10578) @@ -1,9 +1,9 @@ MKOCTFILE ?= mkoctfile -LAPACK_LIBS := $(shell $(MKOCTFILE) -p LAPACK_LIBS) +LAPACK_LIBS ?= $(shell $(MKOCTFILE) -p LAPACK_LIBS) # reported necessary for Apple's VecLib framework by Carlo de Falco # <car...@gm...> -BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) +BLAS_LIBS ?= $(shell $(MKOCTFILE) -p BLAS_LIBS) # Passing LFLAGS, supplemented with LAPACK_LIBS and BLAS_LIBS, in the # environment to mkoctfile is prefered over passing LAPACK_LIBS and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <i7...@us...> - 2012-06-07 09:33:31
|
Revision: 10577 http://octave.svn.sourceforge.net/octave/?rev=10577&view=rev Author: i7tiol Date: 2012-06-07 09:33:21 +0000 (Thu, 07 Jun 2012) Log Message: ----------- Pass linker flags with better compatibility. Modified Paths: -------------- trunk/octave-forge/main/optim/DESCRIPTION trunk/octave-forge/main/optim/inst/nonlin_min.m trunk/octave-forge/main/optim/src/Makefile Modified: trunk/octave-forge/main/optim/DESCRIPTION =================================================================== --- trunk/octave-forge/main/optim/DESCRIPTION 2012-06-07 08:27:45 UTC (rev 10576) +++ trunk/octave-forge/main/optim/DESCRIPTION 2012-06-07 09:33:21 UTC (rev 10577) @@ -1,6 +1,6 @@ Name: Optim -Version: 1.1.0 -Date: 2012-05-24 +Version: 1.1.1 +Date: 2012-06-07 Author: various authors Maintainer: Octave-Forge community <oct...@li...> Title: Optimization. Modified: trunk/octave-forge/main/optim/inst/nonlin_min.m =================================================================== --- trunk/octave-forge/main/optim/inst/nonlin_min.m 2012-06-07 08:27:45 UTC (rev 10576) +++ trunk/octave-forge/main/optim/inst/nonlin_min.m 2012-06-07 09:33:21 UTC (rev 10577) @@ -1283,12 +1283,12 @@ function backend = map_backend (backend) switch (backend) - case "bfgs_infeasible" + case "sqp_infeasible" backend = "__sqp__"; case "sqp" backend = "__sqp__"; - case "bfgs_feasible" - backend = "__bfgs_feasible__"; + case "sqp_feasible" + backend = "__sqp_feasible__"; case "siman" backend = "__siman__"; otherwise Modified: trunk/octave-forge/main/optim/src/Makefile =================================================================== --- trunk/octave-forge/main/optim/src/Makefile 2012-06-07 08:27:45 UTC (rev 10576) +++ trunk/octave-forge/main/optim/src/Makefile 2012-06-07 09:33:21 UTC (rev 10577) @@ -5,10 +5,17 @@ # <car...@gm...> BLAS_LIBS := $(shell $(MKOCTFILE) -p BLAS_LIBS) +# Passing LFLAGS, supplemented with LAPACK_LIBS and BLAS_LIBS, in the +# environment to mkoctfile is prefered over passing LAPACK_LIBS and +# BLAS_LIBS in mkoctfiles commandline due to mkoctfiles difficulties +# with non-standard flags on some systems (e.g. -framework ... on +# Apple) +LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) + all: __bfgsmin.oct numgradient.oct numhessian.oct samin.oct __disna_optim__.oct %.oct: %.cc - $(MKOCTFILE) -s $< $(LAPACK_LIBS) $(BLAS_LIBS) + LFLAGS="$(LFLAGS)" $(MKOCTFILE) -s $< clean: $(RM) *.o core octave-core *.oct *~ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2012-06-07 08:27:51
|
Revision: 10576 http://octave.svn.sourceforge.net/octave/?rev=10576&view=rev Author: jpicarbajal Date: 2012-06-07 08:27:45 +0000 (Thu, 07 Jun 2012) Log Message: ----------- statistics: DESCRIPTION: now the packages depends on Octave 3.6.1 due to use of automatic bradcasting Modified Paths: -------------- trunk/octave-forge/main/statistics/DESCRIPTION Modified: trunk/octave-forge/main/statistics/DESCRIPTION =================================================================== --- trunk/octave-forge/main/statistics/DESCRIPTION 2012-06-07 08:26:41 UTC (rev 10575) +++ trunk/octave-forge/main/statistics/DESCRIPTION 2012-06-07 08:27:45 UTC (rev 10576) @@ -6,7 +6,7 @@ Title: Statistics Description: Additional statistics functions for Octave. Categories: Statistics -Depends: octave (>= 2.9.7), io (>= 1.0.18) +Depends: octave (>= 3.6.1), io (>= 1.0.18) Autoload: yes License: GPLv3+, public domain Url: http://octave.sf.net This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2012-06-07 08:26:52
|
Revision: 10575 http://octave.svn.sourceforge.net/octave/?rev=10575&view=rev Author: jpicarbajal Date: 2012-06-07 08:26:41 +0000 (Thu, 07 Jun 2012) Log Message: ----------- statistics: mvnrnd: improving doc. Adding tolerance in check for positive definite. Using broadcasting. Using chol 'upper'. Perturnbing matrix to estabilize chol. Argument tol has a defualt value. Modified Paths: -------------- trunk/octave-forge/main/statistics/NEWS trunk/octave-forge/main/statistics/inst/mvnrnd.m Modified: trunk/octave-forge/main/statistics/NEWS =================================================================== --- trunk/octave-forge/main/statistics/NEWS 2012-06-06 21:22:02 UTC (rev 10574) +++ trunk/octave-forge/main/statistics/NEWS 2012-06-07 08:26:41 UTC (rev 10575) @@ -1,10 +1,14 @@ Summary of important user-visible changes for statistics 1.2.0: ------------------------------------------------------------------- - ** The following functions are new in 1.2.0: + ** The following functions are new: regress_gp + + ** The interface of the following functions has been modified: + mvnrnd + Summary of important user-visible changes for statistics 1.1.3: ------------------------------------------------------------------- Modified: trunk/octave-forge/main/statistics/inst/mvnrnd.m =================================================================== --- trunk/octave-forge/main/statistics/inst/mvnrnd.m 2012-06-06 21:22:02 UTC (rev 10574) +++ trunk/octave-forge/main/statistics/inst/mvnrnd.m 2012-06-07 08:26:41 UTC (rev 10575) @@ -16,12 +16,20 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{s} = mvnrnd (@var{mu}, @var{Sigma}) ## @deftypefnx{Function File} @var{s} = mvnrnd (@var{mu}, @var{Sigma}, @var{n}) +## @deftypefnx{Function File} @var{s} = mvnrnd (@dots{}, @var{tol}) ## Draw @var{n} random @var{d}-dimensional vectors from a multivariate Gaussian ## distribution with mean @var{mu}(@var{n}x@var{d}) and covariance matrix ## @var{Sigma}(@var{d}x@var{d}). +## +## If @var{n} is given then @var{mu} can be a 1-by-@var{d} vector. If it is not +## given @var{mu} must be @var{n}-by-@var{d}. +## +## If the argument @var{tol} is given the eigenvalues of @var{Sigma} are checked +## for positivity against -100*tol. the default value of tol is @code{eps*norm (Sigma, "fro")}. +## ## @end deftypefn -function s = mvnrnd(mu,Sigma,K) +function s = mvnrnd_jpi (mu, Sigma, K, tol=eps*norm (Sigma, "fro")) % Iain Murray 2003 -- I got sick of this simple thing not being in Octave and % locking up a stats-toolbox license in Matlab for no good @@ -32,36 +40,56 @@ % * Add GPL notice. % * Add docs for argument K + % 2012 Juan Pablo Carbajal <car...@if...> + % * Uses Octave 3.6.2 boradcast. + % * Stabilizes chol by perturbing Sigma with a epsilon multiple of the identity. + % The effect on the generated samples is to add additional independent noise + % of variance epsilon. Ref: GPML Rasmussen & Williams. 2006. pp 200-201 + % * Improved doc. + % * Added tolerance to the positive definite check + % * Used chol with option 'upper'. + + warning ("off", "Octave:broadcast"); + % If mu is column vector and Sigma not a scalar then assume user didn't read % help but let them off and flip mu. Don't be more liberal than this or it will % encourage errors (eg what should you do if mu is square?). - if ((size(mu,2)==1)&&(size(Sigma)~=[1,1])) - mu=mu'; + if (size (mu, 2) == 1) && (size (Sigma) != [1,1]) + mu = mu'; end - if nargin==3 - mu=repmat(mu,K,1); + [n,d] = size (mu); + + if nargin >= 3 + n = K; end - [n,d]=size(mu); - - if (size(Sigma)~=[d,d]) - error('Sigma must have dimensions dxd where mu is nxd.'); + if size (Sigma) != [d,d] + error ('Sigma must have dimensions dxd where mu is nxd.'); end try - U=chol(Sigma); + U = chol (Sigma + tol*eye (d),"upper"); catch - [E,Lambda]=eig(Sigma); - if (min(diag(Lambda))<0),error('Sigma must be positive semi-definite.'),end - U = sqrt(Lambda)*E'; + [E , Lambda] = eig (Sigma); + + if min (diag (Lambda)) < -100*tol + error('Sigma must be positive semi-definite. Lowest eigenvaluen %g', ... + min (diag (Lambda))); + else + Lambda(Lambda<0) = 0; + end + warning ("mvnrnd:InvalidInput","Cholesky factorization failed. Using diagonalized matrix.") + U = sqrt (Lambda) * E'; end s = randn(n,d)*U + mu; + + warning ("on", "Octave:broadcast"); endfunction % {{{ END OF CODE --- Guess I should provide an explanation: -% +% % We can draw from axis aligned unit Gaussians with randn(d) % x ~ A*exp(-0.5*x'*x) % We can then rotate this distribution using @@ -76,7 +104,7 @@ % Sigma = U'*U % For a given Sigma we can use the chol function to find the corresponding U, % draw x and find y. We can adjust for a non-zero mean by just adding it on. -% +% % But the Cholsky decomposition function doesn't always work... % Consider Sigma=[1 1;1 1]. Now inv(Sigma) doesn't actually exist, but Matlab's % mvnrnd provides samples with this covariance st x(1)~N(0,1) x(2)=x(1). The @@ -94,7 +122,7 @@ % so we can give up. % % Paul Kienzle adds: -% Where it exists, chol(Sigma) is numerically well behaved. chol(hilb(12)) +% Where it exists, chol(Sigma) is numerically well behaved. chol(hilb(12)) % for doubles and for 100 digit floating point differ in the last digit. % Where chol(Sigma) doesn't exist, X*sqrt(Lambda)*E' will be somewhat % accurate. For example, the elements of sqrt(Lambda)*E' for hilb(12), @@ -102,4 +130,3 @@ % tested using the TNT+JAMA for eig and chol templates, and qlib for % 100 digit precision. % }}} - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <prn...@us...> - 2012-06-06 21:22:09
|
Revision: 10574 http://octave.svn.sourceforge.net/octave/?rev=10574&view=rev Author: prnienhuis Date: 2012-06-06 21:22:02 +0000 (Wed, 06 Jun 2012) Log Message: ----------- Improved & simplified Java-based interface checking and made it less verbose Modified Paths: -------------- trunk/octave-forge/main/io/inst/odsopen.m Modified: trunk/octave-forge/main/io/inst/odsopen.m =================================================================== --- trunk/octave-forge/main/io/inst/odsopen.m 2012-06-06 21:08:51 UTC (rev 10573) +++ trunk/octave-forge/main/io/inst/odsopen.m 2012-06-06 21:22:02 UTC (rev 10574) @@ -74,258 +74,264 @@ ## 2010-03-14 Updated help text (section on readwrite) ## 2010-06-01 Added check for jOpenDocument version + suitable warning ## 2010-06-02 Added ";" to supress debug stuff around lines 115 -## " Moved JOD version check to subfunc getodsinterfaces -## " Fiddled ods.changed flag when creating a spreadsheet to avoid unnamed 1st sheets +## '' Moved JOD version check to subfunc getodsinterfaces +## '' Fiddled ods.changed flag when creating a spreadsheet to avoid unnamed 1st sheets ## 2010-08-23 Added version field "odfvsn" to ods file ptr, set in getodsinterfaces() (odfdom) -## " Moved JOD version check to this func from subfunc getodsinterfaces() -## " Full support for odfdom 0.8.6 (in subfunc) +## '' Moved JOD version check to this func from subfunc getodsinterfaces() +## '' Full support for odfdom 0.8.6 (in subfunc) ## 2010-08-27 Improved help text ## 2010-10-27 Improved tracking of file changes tru ods.changed ## 2010-11-12 Small changes to help text -## " Added try-catch to file open sections to create fallback to other intf +## '' Added try-catch to file open sections to create fallback to other intf ## 2011-05-06 Experimental UNO support ## 2011-05-18 Creating new spreadsheet docs in UNO now works ## 2011-06-06 Tamed down interface verbosity on first startup -## " Multiple requested interfaces now possible +## '' Multiple requested interfaces now possible ## 2011-09-03 Reset chkintf if no ods support was found to allow full interface rediscovery ## (otherwise javaclasspath additions will never be picked up) ## 2012-01-26 Fixed "seealso" help string ## 2012-02-26 Added ";" to suppress echo of filename f UNO +## 2012-06-06 Made interface checking routine less verbose when same requested interface +## was used consecutively ## -## Latest change on subfunctions below: 2012-03-22 +## Latest change on subfunctions below: 2012-06-06 function [ ods ] = odsopen (filename, rw=0, reqinterface=[]) - persistent odsinterfaces; persistent chkintf; - if (isempty (chkintf)) - odsinterfaces = struct ( "OTK", [], "JOD", [], "UNO", [] ); - chkintf = 1; - endif - - if (nargout < 1) usage ("ODS = odsopen (ODSfile, [Rw]). But no return argument specified!"); endif + persistent odsinterfaces; persistent chkintf; persistent lastintf; + if (isempty (chkintf)) + odsinterfaces = struct ( "OTK", [], "JOD", [], "UNO", [] ); + chkintf = 1; + endif + if (isempty (lastintf)); lastintf = '---'; endif + + if (nargout < 1) usage ("ODS = odsopen (ODSfile, [Rw]). But no return argument specified!"); endif - if (~isempty (reqinterface)) - if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif - # Turn arg3 into cell array if needed - if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif - odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; odsinterfaces.UNO = 0; - for ii=1:numel (reqinterface) - reqintf = toupper (reqinterface {ii}); - # Try to invoke requested interface(s) for this call. Check if it - # is supported anyway by emptying the corresponding var. - if (strcmp (reqintf, 'OTK')) - odsinterfaces.OTK = []; - elseif (strcmp (reqintf, 'JOD')) - odsinterfaces.JOD = []; - elseif (strcmp (reqintf, 'UNO')) - odsinterfaces.UNO = []; - else - usage (sprintf ("Unknown .ods interface \"%s\" requested. Only OTK, JOD or UNO supported\n", reqinterface{})); - endif - endfor - printf ("Checking requested interface(s):\n"); - odsinterfaces = getodsinterfaces (odsinterfaces); - # Well, is/are the requested interface(s) supported on the system? - # FIXME check for multiple interfaces - odsintf_cnt = 0; - for ii=1:numel (reqinterface) - if (~odsinterfaces.(toupper (reqinterface{ii}))) - # No it aint - printf ("%s is not supported.\n", toupper (reqinterface{ii})); - else - ++odsintf_cnt; - endif - endfor - # Reset interface check indicator if no requested support found - if (~odsintf_cnt) - chkintf = []; - ods = []; - return - endif - endif - - # Var rw is really used to avoid creating files when wanting to read, or - # not finding not-yet-existing files when wanting to write. + if (~isempty (reqinterface)) + if ~(ischar (reqinterface) || iscell (reqinterface)), usage ("Arg # 3 not recognized"); endif + # Turn arg3 into cell array if needed + if (~iscell (reqinterface)), reqinterface = {reqinterface}; endif + ## Check if previously used interface matches a requested interface + if (isempty (regexpi (reqinterface, lastintf, 'once'){1})) + ## New interface requested + odsinterfaces.OTK = 0; odsinterfaces.JOD = 0; odsinterfaces.UNO = 0; + for ii=1:numel (reqinterface) + reqintf = toupper (reqinterface {ii}); + # Try to invoke requested interface(s) for this call. Check if it + # is supported anyway by emptying the corresponding var. + if (strcmp (reqintf, 'OTK')) + odsinterfaces.OTK = []; + elseif (strcmp (reqintf, 'JOD')) + odsinterfaces.JOD = []; + elseif (strcmp (reqintf, 'UNO')) + odsinterfaces.UNO = []; + else + usage (sprintf ("Unknown .ods interface \"%s\" requested. Only OTK, JOD or UNO supported\n", reqinterface{})); + endif + endfor + printf ("Checking requested interface(s):\n"); + odsinterfaces = getodsinterfaces (odsinterfaces); + # Well, is/are the requested interface(s) supported on the system? + # FIXME check for multiple interfaces + odsintf_cnt = 0; + for ii=1:numel (reqinterface) + if (~odsinterfaces.(toupper (reqinterface{ii}))) + # No it aint + printf ("%s is not supported.\n", toupper (reqinterface{ii})); + else + ++odsintf_cnt; + endif + endfor + # Reset interface check indicator if no requested support found + if (~odsintf_cnt) + chkintf = []; + ods = []; + return + endif + endif + endif + + # Var rw is really used to avoid creating files when wanting to read, or + # not finding not-yet-existing files when wanting to write. - if (rw), rw = 1; endif # Be sure it's either 0 or 1 initially + if (rw), rw = 1; endif # Be sure it's either 0 or 1 initially - # Check if ODS file exists. Set open mode based on rw argument - if (rw), fmode = 'r+b'; else fmode = 'rb'; endif - fid = fopen (filename, fmode); - if (fid < 0) - if (~rw) # Read mode requested but file doesn't exist - err_str = sprintf ("File %s not found\n", filename); - error (err_str) - else # For writing we need more info: - fid = fopen (filename, 'rb'); # Check if it can be opened for reading - if (fid < 0) # Not found => create it - printf ("Creating file %s\n", filename); - rw = 3; - else # Found but not writable = error - fclose (fid); # Do not forget to close the handle neatly - error (sprintf ("Write mode requested but file %s is not writable\n", filename)) - endif - endif - else - # close file anyway to avoid Java errors - fclose (fid); - endif + # Check if ODS file exists. Set open mode based on rw argument + if (rw), fmode = 'r+b'; else fmode = 'rb'; endif + fid = fopen (filename, fmode); + if (fid < 0) + if (~rw) # Read mode requested but file doesn't exist + err_str = sprintf ("File %s not found\n", filename); + error (err_str) + else # For writing we need more info: + fid = fopen (filename, 'rb'); # Check if it can be opened for reading + if (fid < 0) # Not found => create it + printf ("Creating file %s\n", filename); + rw = 3; + else # Found but not writable = error + fclose (fid); # Do not forget to close the handle neatly + error (sprintf ("Write mode requested but file %s is not writable\n", filename)) + endif + endif + else + # close file anyway to avoid Java errors + fclose (fid); + endif # Check for the various ODS interfaces. No problem if they've already # been checked, getodsinterfaces (far below) just returns immediately then. - [odsinterfaces] = getodsinterfaces (odsinterfaces); + [odsinterfaces] = getodsinterfaces (odsinterfaces); # Supported interfaces determined; now check ODS file type. - chk1 = strcmp (tolower (filename(end-3:end)), '.ods'); - # Only jOpenDocument (JOD) can read from .sxc files, but only if odfvsn = 2 - chk2 = strcmp (tolower (filename(end-3:end)), '.sxc'); -# if (~chk1) -# error ("Currently ods2oct can only read reliably from .ods files") -# endif + chk1 = strcmp (tolower (filename(end-3:end)), '.ods'); + # Only jOpenDocument (JOD) can read from .sxc files, but only if odfvsn = 2 + chk2 = strcmp (tolower (filename(end-3:end)), '.sxc'); +# if (~chk1) +# error ("Currently ods2oct can only read reliably from .ods files") +# endif - ods = struct ("xtype", [], "app", [], "filename", [], "workbook", [], "changed", 0, "limits", [], "odfvsn", []); + ods = struct ("xtype", [], "app", [], "filename", [], "workbook", [], "changed", 0, "limits", [], "odfvsn", []); - # Preferred interface = OTK (ODS toolkit & xerces), so it comes first. - # Keep track of which interface is selected. Can be used for fallback to other intf - odssupport = 0; + # Preferred interface = OTK (ODS toolkit & xerces), so it comes first. + # Keep track of which interface is selected. Can be used for fallback to other intf + odssupport = 0; - if (odsinterfaces.OTK && ~odssupport) - # Parts after user gfterry in - # http://www.oooforum.org/forum/viewtopic.phtml?t=69060 - odftk = 'org.odftoolkit.odfdom.doc'; - try - if (rw > 2) - # New spreadsheet - wb = java_invoke ([odftk '.OdfSpreadsheetDocument'], 'newSpreadsheetDocument'); - else - # Existing spreadsheet - wb = java_invoke ([odftk '.OdfDocument'], 'loadDocument', filename); - endif - ods.workbook = wb.getContentDom (); # Reads the entire spreadsheet - ods.xtype = 'OTK'; - ods.app = wb; - ods.filename = filename; - ods.odfvsn = odsinterfaces.odfvsn; - odssupport += 1; - catch - if (odsinterfaces.JOD && ~rw && chk2) - printf ('Couldn''t open file %s using OTK; trying .sxc format with JOD...\n', filename); - else - error ('Couldn''t open file %s using OTK', filename); - endif - end_try_catch - endif + if (odsinterfaces.OTK && ~odssupport) + # Parts after user gfterry in + # http://www.oooforum.org/forum/viewtopic.phtml?t=69060 + odftk = 'org.odftoolkit.odfdom.doc'; + try + if (rw > 2) + # New spreadsheet + wb = java_invoke ([odftk '.OdfSpreadsheetDocument'], 'newSpreadsheetDocument'); + else + # Existing spreadsheet + wb = java_invoke ([odftk '.OdfDocument'], 'loadDocument', filename); + endif + ods.workbook = wb.getContentDom (); # Reads the entire spreadsheet + ods.xtype = 'OTK'; + ods.app = wb; + ods.filename = filename; + ods.odfvsn = odsinterfaces.odfvsn; + odssupport += 1; + lastintf = 'OTK'; + catch + if (odsinterfaces.JOD && ~rw && chk2) + printf ('Couldn''t open file %s using OTK; trying .sxc format with JOD...\n', filename); + else + error ('Couldn''t open file %s using OTK', filename); + endif + end_try_catch + endif - if (odsinterfaces.JOD && ~odssupport) - file = java_new ('java.io.File', filename); - jopendoc = 'org.jopendocument.dom.spreadsheet.SpreadSheet'; - try - if (rw > 2) - # Create an empty 2 x 2 default TableModel template - tmodel= java_new ('javax.swing.table.DefaultTableModel', 2, 2); - wb = java_invoke (jopendoc, 'createEmpty', tmodel); - else - wb = java_invoke (jopendoc, 'createFromFile', file); - endif - ods.workbook = wb; - ods.filename = filename; - ods.xtype = 'JOD'; - ods.app = 'file'; - # Check jOpenDocument version. This can only work here when a - # workbook has been opened - sh = ods.workbook.getSheet (0); - cl = sh.getCellAt (0, 0); - try - # 1.2b3 has public getValueType () - cl.getValueType (); - ods.odfvsn = 3; - catch - # 1.2b2 has not - ods.odfvsn = 2; - printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2\n"); - end_try_catch - odssupport += 2; - catch - error ('Couldn''t open file %s using JOD', filename); - end_try_catch - endif + if (odsinterfaces.JOD && ~odssupport) + file = java_new ('java.io.File', filename); + jopendoc = 'org.jopendocument.dom.spreadsheet.SpreadSheet'; + try + if (rw > 2) + # Create an empty 2 x 2 default TableModel template + tmodel= java_new ('javax.swing.table.DefaultTableModel', 2, 2); + wb = java_invoke (jopendoc, 'createEmpty', tmodel); + else + wb = java_invoke (jopendoc, 'createFromFile', file); + endif + ods.workbook = wb; + ods.filename = filename; + ods.xtype = 'JOD'; + ods.app = 'file'; + # Check jOpenDocument version. This can only work here when a + # workbook has been opened + sh = ods.workbook.getSheet (0); + cl = sh.getCellAt (0, 0); + try + # 1.2b3 has public getValueType () + cl.getValueType (); + ods.odfvsn = 3; + catch + # 1.2b2 has not + ods.odfvsn = 2; + printf ("NOTE: jOpenDocument v. 1.2b2 has limited functionality. Try upgrading to 1.2\n"); + end_try_catch + odssupport += 2; + lastintf = 'JOD'; + catch + error ('Couldn''t open file %s using JOD', filename); + end_try_catch + endif - if (odsinterfaces.UNO && ~odssupport) - # First the file name must be transformed into a URL - if (~isempty (strmatch ("file:///", filename)) || ~isempty (strmatch ("http:///", filename))... - || ~isempty (strmatch ("ftp:///", filename)) || ~isempty (strmatch ("www:///", filename))) - # Seems in proper shape for OOO (at first sight) - else - # Transform into URL form - fname = canonicalize_file_name (strsplit (filename, filesep){end}); - # On Windows, change backslash file separator into forward slash - if (strcmp (filesep, "\\")) - tmp = strsplit (fname, filesep); - flen = numel (tmp); - tmp(2:2:2*flen) = tmp; - tmp(1:2:2*flen) = '/'; - fname = [ tmp{:} ]; - endif - filename = [ 'file://' fname ]; - endif - try - xContext = java_invoke ("com.sun.star.comp.helper.Bootstrap", "bootstrap"); - xMCF = xContext.getServiceManager (); - oDesktop = xMCF.createInstanceWithContext ("com.sun.star.frame.Desktop", xContext); - # Workaround: - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XComponentLoader'); - aLoader = oDesktop.queryInterface (unotmp); - # Some trickery as Octave Java cannot create non-numeric arrays - lProps = javaArray ('com.sun.star.beans.PropertyValue', 1); - lProp = java_new ('com.sun.star.beans.PropertyValue', "Hidden", 0, true, []); - lProps(1) = lProp; - if (rw > 2) - xComp = aLoader.loadComponentFromURL ("private:factory/scalc", "_blank", 0, lProps); - else - xComp = aLoader.loadComponentFromURL (filename, "_blank", 0, lProps); - endif - # Workaround: - unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheetDocument'); - # save in ods struct: - xSpdoc = xComp.queryInterface (unotmp); - ods.workbook = xSpdoc; # Needed to be able to close soffice in odsclose() - ods.filename = filename; - ods.xtype = 'UNO'; - ods.app.xComp = xComp; # Needed to be able to close soffice in odsclose() - ods.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() - ods.odfvsn = 'UNO'; - odssupport += 4; - catch - error ('Couldn''t open file %s using UNO', filename); - end_try_catch - endif + if (odsinterfaces.UNO && ~odssupport) + # First the file name must be transformed into a URL + if (~isempty (strmatch ("file:///", filename)) || ~isempty (strmatch ("http:///", filename))... + || ~isempty (strmatch ("ftp:///", filename)) || ~isempty (strmatch ("www:///", filename))) + # Seems in proper shape for OOO (at first sight) + else + # Transform into URL form + fname = canonicalize_file_name (strsplit (filename, filesep){end}); + # On Windows, change backslash file separator into forward slash + if (strcmp (filesep, "\\")) + tmp = strsplit (fname, filesep); + flen = numel (tmp); + tmp(2:2:2*flen) = tmp; + tmp(1:2:2*flen) = '/'; + fname = [ tmp{:} ]; + endif + filename = [ 'file://' fname ]; + endif + try + xContext = java_invoke ("com.sun.star.comp.helper.Bootstrap", "bootstrap"); + xMCF = xContext.getServiceManager (); + oDesktop = xMCF.createInstanceWithContext ("com.sun.star.frame.Desktop", xContext); + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.frame.XComponentLoader'); + aLoader = oDesktop.queryInterface (unotmp); + # Some trickery as Octave Java cannot create non-numeric arrays + lProps = javaArray ('com.sun.star.beans.PropertyValue', 1); + lProp = java_new ('com.sun.star.beans.PropertyValue', "Hidden", 0, true, []); + lProps(1) = lProp; + if (rw > 2) + xComp = aLoader.loadComponentFromURL ("private:factory/scalc", "_blank", 0, lProps); + else + xComp = aLoader.loadComponentFromURL (filename, "_blank", 0, lProps); + endif + # Workaround: + unotmp = java_new ('com.sun.star.uno.Type', 'com.sun.star.sheet.XSpreadsheetDocument'); + # save in ods struct: + xSpdoc = xComp.queryInterface (unotmp); + ods.workbook = xSpdoc; # Needed to be able to close soffice in odsclose() + ods.filename = filename; + ods.xtype = 'UNO'; + ods.app.xComp = xComp; # Needed to be able to close soffice in odsclose() + ods.app.aLoader = aLoader; # Needed to be able to close soffice in odsclose() + ods.odfvsn = 'UNO'; + odssupport += 4; + lastintf = 'UNO'; + catch + error ('Couldn''t open file %s using UNO', filename); + end_try_catch + endif -# if -# <other interfaces here> +# if +# <other interfaces here> - if (~odssupport) + if (~odssupport) printf ("None.\n"); - warning ("No support for OpenOffice.org .ods I/O"); - ods = []; - else - # From here on rw is tracked via ods.changed in the various lower - # level r/w routines and it is only used to determine if an informative - # message is to be given when saving a newly created ods file. - ods.changed = rw; + warning ("No support for OpenOffice.org .ods I/O"); + ods = []; + chkintf = []; + else + # From here on rw is tracked via ods.changed in the various lower + # level r/w routines and it is only used to determine if an informative + # message is to be given when saving a newly created ods file. + ods.changed = rw; - # Until something was written to existing files we keep status "unchanged". - # ods.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, - # data added) or 3 (pristine, no data added). - if (ods.changed == 1) ods.changed = 0; endif - endif + # Until something was written to existing files we keep status "unchanged". + # ods.changed = 0 (existing/only read from), 1 (existing/data added), 2 (new, + # data added) or 3 (pristine, no data added). + if (ods.changed == 1) ods.changed = 0; endif + endif - if (~isempty (reqinterface) || ~odssupport) - # Reset all found interfaces for re-testing in the next call. Add interfaces if needed. - chkintf = []; - endif - endfunction @@ -392,144 +398,140 @@ ## '' Reset tmp1 (always allow interface rediscovery) for empty odsinterfaces arg ## 2011-09-18 Added temporary warning about UNO interface ## 2012-03-22 Improved Java checks (analogous to xlsopen) +## 2012-06-06 Again improved & simplified Java-based interface checking support function [odsinterfaces] = getodsinterfaces (odsinterfaces) # tmp1 = [] (not initialized), 0 (No Java detected), or 1 (Working Java found) - persistent tmp1 = []; persistent jcp; # Java class path + persistent tmp1 = []; persistent jcp; # Java class path persistent uno_1st_time = 0; - if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) + if (isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) # Assume no interface detection has happened yet - printf ("Detected ODS interfaces: "); + printf ("Detected ODS interfaces: "); tmp1 = []; - elseif (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) + elseif (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) # Can't be first call. Here one of the Java interfaces is requested if (~tmp1) # Check Java support again tmp1 = []; endif - endif - deflt = 0; + endif + deflt = 0; - if (isempty (tmp1)) - # Check Java support - try - jcp = javaclasspath ("-all"); # For java pkg >= 1.2.8 - if (isempty (jcp)), jcp = javaclasspath; endif # For java pkg < 1.2.8 - # If we get here, at least Java works. Now check for proper version (>= 1.6) - jver = char (java_invoke ('java.lang.System', 'getProperty', 'java.version')); - cjver = strsplit (jver, '.'); - if (sscanf (cjver{2}, '%d') < 6) - warning ("\nJava version too old - you need at least Java 6 (v. 1.6.x.x)\n"); - return - endif - # Now check for proper entries in class path. Under *nix the classpath - # must first be split up. In java 1.2.8+ javaclasspath is already a cell array - if (isunix && ~iscell (jcp)), jcp = strsplit (char (jcp), pathsep ()); endif - tmp1 = 1; - catch - # No Java support + if (isempty (tmp1)) + # Check Java support + try + jcp = javaclasspath ("-all"); # For java pkg >= 1.2.8 + if (isempty (jcp)), jcp = javaclasspath; endif # For java pkg < 1.2.8 + # If we get here, at least Java works. Now check for proper version (>= 1.6) + jver = char (java_invoke ('java.lang.System', 'getProperty', 'java.version')); + cjver = strsplit (jver, '.'); + if (sscanf (cjver{2}, '%d') < 6) + warning ("\nJava version too old - you need at least Java 6 (v. 1.6.x.x)\n"); + return + endif + # Now check for proper entries in class path. Under *nix the classpath + # must first be split up. In java 1.2.8+ javaclasspath is already a cell array + if (isunix && ~iscell (jcp)), jcp = strsplit (char (jcp), pathsep ()); endif + tmp1 = 1; + catch + # No Java support tmp1 = 0; - if ~(isempty (odsinterfaces.OTK) && isempty (odsinterfaces.JOD) && isempty (odsinterfaces.UNO)) - # Some Java-based interface explicitly requested but Java support is absent - xlsinterfaces.OTK = 0; - xlsinterfaces.JOD = 0; - xlsinterfaces.UNO = 0; - warning (' No Java support found (no Java JRE? no Java pkg installed AND loaded?'); - else - # No specific Java-based interface requested. Just return (needed for if - # ever a non-Java based interfaces will be implemented) - odsinterfaces.OTK = 0; - odsinterfaces.JOD = 0; - odsinterfaces.UNO = 0; - printf ("\n"); - return; - endif - end_try_catch - endif + if (isempty (odsinterfaces.OTK) || isempty (odsinterfaces.JOD) || isempty (odsinterfaces.UNO)) + # Some or all Java-based interface explicitly requested; but no Java support + warning (' No Java support found (no Java JRE? no Java pkg installed AND loaded?'); + endif + # No specific Java-based interface requested. Just return + odsinterfaces.OTK = 0; + odsinterfaces.JOD = 0; + odsinterfaces.UNO = 0; + printf ("\n"); + return; + end_try_catch + endif - # Try Java & ODF toolkit - if (isempty (odsinterfaces.OTK)) - odsinterfaces.OTK = 0; - jpchk = 0; entries = {"odfdom", "xercesImpl"}; - # Only under *nix we might use brute force: e.g., strfind(classpath, classname); - # under Windows we need the following more subtle, platform-independent approach: - for ii=1:length (jcp) - for jj=1:length (entries) - if (~isempty (strfind ( jcp{ii}, entries{jj}))), ++jpchk; endif - endfor - endfor - if (jpchk >= numel(entries)) # Apparently all requested classes present. - # Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6 work OK). - # The odfdom team deemed it necessary to change the version call so we need this: - odfvsn = ' '; - try - # New in 0.8.6 - odfvsn = java_invoke ('org.odftoolkit.odfdom.JarManifest', 'getOdfdomVersion'); - catch - odfvsn = java_invoke ('org.odftoolkit.odfdom.Version', 'getApplicationVersion'); - end_try_catch - if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6') || strcmp (odfvsn, '0.8.7')) - warning ("\nodfdom version %s is not supported - use v. 0.8.6 or 0.8.7.\n", odfvsn); - else - if (strcmp (odfvsn, '0.7.5')) - warning ("odfdom v. 0.7.5 support won't be maintained - please upgrade to 0.8.6 or higher."); - endif - odsinterfaces.OTK = 1; - printf ("OTK"); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif - endif - odsinterfaces.odfvsn = odfvsn; - else - warning ("\nNot all required classes (.jar) in classpath for OTK"); - endif - endif + # Try Java & ODF toolkit + if (isempty (odsinterfaces.OTK)) + odsinterfaces.OTK = 0; + jpchk = 0; entries = {"odfdom", "xercesImpl"}; + # Only under *nix we might use brute force: e.g., strfind(classpath, classname); + # under Windows we need the following more subtle, platform-independent approach: + for ii=1:length (jcp) + for jj=1:length (entries) + if (~isempty (strfind ( jcp{ii}, entries{jj}))), ++jpchk; endif + endfor + endfor + if (jpchk >= numel(entries)) # Apparently all requested classes present. + # Only now we can check for proper odfdom version (only 0.7.5 & 0.8.6 work OK). + # The odfdom team deemed it necessary to change the version call so we need this: + odfvsn = ' '; + try + # New in 0.8.6 + odfvsn = java_invoke ('org.odftoolkit.odfdom.JarManifest', 'getOdfdomVersion'); + catch + odfvsn = java_invoke ('org.odftoolkit.odfdom.Version', 'getApplicationVersion'); + end_try_catch + if ~(strcmp (odfvsn, '0.7.5') || strcmp (odfvsn, '0.8.6') || strcmp (odfvsn, '0.8.7')) + warning ("\nodfdom version %s is not supported - use v. 0.8.6 or 0.8.7.\n", odfvsn); + else + if (strcmp (odfvsn, '0.7.5')) + warning ("odfdom v. 0.7.5 support won't be maintained - please upgrade to 0.8.6 or higher."); + endif + odsinterfaces.OTK = 1; + printf ("OTK"); + if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif + endif + odsinterfaces.odfvsn = odfvsn; + else + warning ("\nNot all required classes (.jar) in classpath for OTK"); + endif + endif - # Try Java & jOpenDocument - if (isempty (odsinterfaces.JOD)) - odsinterfaces.JOD = 0; - jpchk = 0; entries = {"jOpenDocument"}; - for ii=1:length (jcp) - for jj=1:length (entries) - if (~isempty (strfind (jcp{ii}, entries{jj}))), ++jpchk; endif - endfor - endfor - if (jpchk >= numel(entries)) - odsinterfaces.JOD = 1; - printf ("JOD"); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif - else - warning ("\nNot all required classes (.jar) in classpath for JOD"); - endif - endif + # Try Java & jOpenDocument + if (isempty (odsinterfaces.JOD)) + odsinterfaces.JOD = 0; + jpchk = 0; entries = {"jOpenDocument"}; + for ii=1:length (jcp) + for jj=1:length (entries) + if (~isempty (strfind (jcp{ii}, entries{jj}))), ++jpchk; endif + endfor + endfor + if (jpchk >= numel(entries)) + odsinterfaces.JOD = 1; + printf ("JOD"); + if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; endif + else + warning ("\nNot all required classes (.jar) in classpath for JOD"); + endif + endif - # Try Java & UNO - if (isempty (odsinterfaces.UNO)) - odsinterfaces.UNO = 0; - # entries(1) = not a jar but a directory (<000_install_dir/program/>) - jpchk = 0; entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; - for jj=1:numel (entries) - for ii=1:numel (jcp) - jcplst = strsplit (jcp{ii}, filesep); - jcpentry = jcplst {end}; - if (~isempty (strfind (lower (jcpentry), lower (entries{jj})))) - jpchk = jpchk + 1; - endif - endfor - endfor - if (jpchk >= numel (entries)) - odsinterfaces.UNO = 1; - printf ("UNO"); - if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; uno_1st_time = min (++uno_1st_time, 2); endif - else - warning ("\nOne or more UNO classes (.jar) missing in javaclasspath"); - endif - endif - - # ---- Other interfaces here, similar to the ones above + # Try Java & UNO + if (isempty (odsinterfaces.UNO)) + odsinterfaces.UNO = 0; + # entries(1) = not a jar but a directory (<000_install_dir/program/>) + jpchk = 0; entries = {'program', 'unoil', 'jurt', 'juh', 'unoloader', 'ridl'}; + for jj=1:numel (entries) + for ii=1:numel (jcp) + jcplst = strsplit (jcp{ii}, filesep); + jcpentry = jcplst {end}; + if (~isempty (strfind (lower (jcpentry), lower (entries{jj})))) + jpchk = jpchk + 1; + endif + endfor + endfor + if (jpchk >= numel (entries)) + odsinterfaces.UNO = 1; + printf ("UNO"); + if (deflt), printf ("; "); else, printf ("*; "); deflt = 1; uno_1st_time = min (++uno_1st_time, 2); endif + else + warning ("\nOne or more UNO classes (.jar) missing in javaclasspath"); + endif + endif + + # ---- Other interfaces here, similar to the ones above - if (deflt), printf ("(* = active interface)\n"); endif + if (deflt), printf ("(* = active interface)\n"); endif ## FIXME the below stanza should be dropped once UNO is stable. # Echo a suitable warning about experimental status: @@ -541,5 +543,5 @@ printf ("also those that were started outside and/or before Octave!\n"); printf ("Trying to quit Octave w/o invoking odsclose will only hang Octave.\n\n"); endif - + endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |