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: <aba...@us...> - 2012-06-22 15:52:42
|
Revision: 10673 http://octave.svn.sourceforge.net/octave/?rev=10673&view=rev Author: abarth93 Date: 2012-06-22 15:52:36 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/display.m trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncsub.m trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsasgn.m trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsref.m Added: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/display.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/display.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/display.m 2012-06-22 15:52:36 UTC (rev 10673) @@ -0,0 +1,4 @@ +function display(self) +disp([self.varname ' from ' self.filename]); +%self.vinfo +%self.dims Added: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m 2012-06-22 15:52:36 UTC (rev 10673) @@ -0,0 +1,62 @@ +% V = ncBaseArray(filename,varname) +% V = ncBaseArray(filename,varname,'property',value,...) +% create a ncBaseArray that can be accessed as a normal matlab array. +% Ths object is a helper object. Users should normally call ncArray. +% +% For read access filename can be compressed if it has the extensions +% ".gz" or ".bz2". It use the function cache_decompress to cache to +% decompressed files. +% +% Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue +% are thus replaced by NaN and the scaling (add_offset and +% scale_factor) is applied during loading and saving. +% +% Properties: +% 'tooBigToLoad': if tooBigToLoad is set to true, then only the minimum +% data will be loaded. However this can be quite slow. +% +% Example: +% +% Loading the variable (assuming V is 3 dimensional): +% +% x = V(1,1,1); % load element 1,1,1 +% x = V(:,:,:); % load the complete array +% x = V(); x = full(V) % loads also the complete array +% +% Saving data in the netcdf file: +% V(1,1,1) = x; % save x in element 1,1,1 +% V(:,:,:) = x; +% +% Attributes +% units = V.units; % get attribute called "units" +% V.units = 'degree C'; % set attributes; +% +% Note: use the '.()' notation if the attribute has a leading underscore +% (due to a limitation in the matlab parser): +% +% V.('_someStrangeAttribute') = 123; +% +% see also cache_decompress + +function retval = ncBaseArray(filename,varname,varargin) + +self.tooBigToLoad = false; +prop = varargin; + +for i=1:2:length(prop) + if strcmp(prop{i},'tooBigToLoad ') + self.tooBigToLoad = prop{i+1}; + end +end + +self.filename = filename; +self.varname = varname; + +self.vinfo = ncinfo(cached_decompress(filename),varname); +self.sz = self.vinfo.Size; + +self.dims = self.vinfo.Dimensions; +self.nd = length(self.dims); + +retval = class(self,'ncBaseArray',BaseArray(self.sz)); +end Added: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncsub.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncsub.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncsub.m 2012-06-22 15:52:36 UTC (rev 10673) @@ -0,0 +1,61 @@ +function [start, count, stride] = ncsub(self,idx) + +assert(strcmp(idx.type,'()')) + +% number of dimension (including singleton dimensions) +%n = length(size(self)); +n = self.nd; + +% number of subscripts +ns = length(idx.subs); + +if ns == 0 + % load all + start = ones(1,n); + count = self.sz; + stride = ones(1,n); +else + + start = ones(1,ns); + count = ones(1,ns); + stride = ones(1,ns); + + % sz is the size padded by 1 if more indices are given than n + sz = ones(1,ns); + sz(1:length(self.sz)) = self.sz; + + for i=1:ns + if isempty(idx.subs{i}) + count(i) = 0; + + elseif strcmp(idx.subs{i},':') + count(i) = sz(i); + + else + tmp = idx.subs{i}; + + if length(tmp) == 1 + start(i) = tmp; + else + test = tmp(1):tmp(2)-tmp(1):tmp(end); + + if all(tmp == test) + start(i) = tmp(1); + stride(i) = tmp(2)-tmp(1); + count(i) = (tmp(end)-tmp(1))/stride(i) +1; + else + error('indeces'); + end + end + end + end + + assert(all(count(n+1:end) == 1 | count(n+1:end) == 0)) + assert(all(start(n+1:end) == 1)) + + if ~any(count == 0) + count = count(1:n); + start = start(1:n); + stride = stride(1:n); + end +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsasgn.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsasgn.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsasgn.m 2012-06-22 15:52:36 UTC (rev 10673) @@ -0,0 +1,10 @@ +function self = subsasgn(self,idxs,x) +%idx + +idx = idxs(1); +assert(strcmp(idx.type,'()')) +[start, count, stride] = ncsub(self,idx); + +if all(count ~= 0) + ncwrite(self.filename,self.varname,x,start,stride); +end Added: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsref.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/subsref.m 2012-06-22 15:52:36 UTC (rev 10673) @@ -0,0 +1,65 @@ +function x = subsref(self,idx) + +assert(length(idx) == 1) + +if strcmp(idx.type,'()') + % load data + + if strcmp(idx.type,'()') && length(idx.subs) == 1 ... + && length(idx.subs) < self.nd + % reference like A([2 3 1 5]) + + if self.tooBigToLoad + % number of elements in x + ind = idx.subs{1}; + + % transform index to subscript + subs = cell(1,self.nd); + [subs{:}] = ind2sub(size(self),ind); + + % make a nice array length(ind) by self.nd + subs = cell2mat(subs); + + % output array + x = zeros(size(ind)); + x(:) = NaN; + + + % get every element + % can be quite slow + idxe.type = '()'; + idxe.subs = cell(1,self.nd); + + for i=1:length(ind) + idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd)); + x(i) = subsref(self,idxe); + end + else + % load full array + tmp = full(self); + x = subsref(tmp,idx); + end + else + [start, count, stride] = ncsub(self,idx); + + if any(count == 0) + x = zeros(count); + else + x = ncread(cached_decompress(self.filename),self.varname,... + start,count,stride); + end + end +elseif strcmp(idx.type,'.') + % load attribute + name = idx.subs; + index = strmatch(name,{self.vinfo.Attributes(:).Name}); + + if isempty(index) + error('variable %s has no attribute called %s',self.varname,name); + else + x = self.vinfo.Attributes(index).Value; + end +else + error('not supported'); + +end \ 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: <aba...@us...> - 2012-06-22 15:51:56
|
Revision: 10672 http://octave.svn.sourceforge.net/octave/?rev=10672&view=rev Author: abarth93 Date: 2012-06-22 15:51:46 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/COPYING Added: trunk/octave-forge/extra/ncArray/COPYING =================================================================== --- trunk/octave-forge/extra/ncArray/COPYING (rev 0) +++ trunk/octave-forge/extra/ncArray/COPYING 2012-06-22 15:51:46 UTC (rev 10672) @@ -0,0 +1,337 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Modified: trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m 2012-06-22 15:20:33 UTC (rev 10671) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m 2012-06-22 15:51:46 UTC (rev 10672) @@ -52,7 +52,9 @@ end end - +elseif strcmp(idx.type,'.') + % load attributes from first array + B = subsref(self.arrays{1},idx); else B = subsref_canonical(self,idx); end Modified: trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m 2012-06-22 15:20:33 UTC (rev 10671) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m 2012-06-22 15:51:46 UTC (rev 10672) @@ -1,6 +1,42 @@ +% V = ncBaseArray(filename,varname) +% V = ncBaseArray(filename,varname,'property',value,...) +% create a ncBaseArray that can be accessed as a normal matlab array. +% +% For read access filename can be compressed if it has the extensions +% ".gz" or ".bz2". It use the function cache_decompress to cache to +% decompressed files. +% +% Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue +% are thus replaced by NaN and the scaling (add_offset and +% scale_factor) is applied during loading and saving. +% +% +% Example: +% +% Loading the variable (assuming V is 3 dimensional): +% +% x = V(1,1,1); % load element 1,1,1 +% x = V(:,:,:); % load the complete array +% x = V(); x = full(V) % loads also the complete array +% +% Saving data in the netcdf file: +% V(1,1,1) = x; % save x in element 1,1,1 +% V(:,:,:) = x; +% +% Attributes +% units = V.units; % get attribute called "units" +% V.units = 'degree C'; % set attributes; +% +% Note: use the '.()' notation if the attribute has a leading underscore +% (due to a limitation in the matlab parser): +% +% V.('_someStrangeAttribute') = 123; +% +% see also cache_decompress + +% hidded constructor signature: % data = ncArray(filename,varname) -% data = ncArray(var,dims,coord) -% data with coordinate values +% is used to create data with coordinate values by ncCatArray function retval = ncArray(varargin) Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:20:33 UTC (rev 10671) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:51:46 UTC (rev 10672) @@ -1,5 +1,5 @@ function test_ncarray() -% test ncBaseArray, ncCatArray, ncArray and ncCatArray +% test ncBaseArray, ncCatArray and ncArray varname = 'SST'; @@ -58,14 +58,44 @@ assert(isequalwithequalnans(3 * r,SST_ref)); + +%%% test ncArray + +% reading + +copyfile(files{2},tmpfname); +SST = ncArray(tmpfname,varname); +test = SST(:,:,:); +SST_ref = ncread(tmpfname,varname); + +assert(isequalwithequalnans(test,SST_ref)) +assert(isempty(SST(:,:,:,[]))); +assert(isequalwithequalnans(SST_ref, SST(:,:,:,1))) + +ind = floor(numel(SST_ref) * rand(100,1))+1; +assert(isequalwithequalnans(SST(ind),SST_ref(ind))) + +% writing + +r = round(randn(size(SST))); +SST(:,:,:) = r; +SST_ref = ncread(tmpfname,varname); +assert(isequalwithequalnans(r,SST_ref)); + +SST(:,:,:) = 3 * r; +SST_ref = ncread(tmpfname,varname); +assert(isequalwithequalnans(3 * r,SST_ref)); + + + %%% CatArray % reading CA = CatArray(3,{... - ncBaseArray(filename,varname),... - ncBaseArray(files{2},varname),... - ncBaseArray(files{3},varname)... + ncArray(filename,varname),... + ncArray(files{2},varname),... + ncArray(files{3},varname)... }); assert(isequalwithequalnans(size(CA),[220 144 3])) @@ -84,9 +114,9 @@ assert(isequalwithequalnans(SST_test,SST_ref)) CA2 = CatArray(4,{... - ncBaseArray(files{1},varname),... - ncBaseArray(files{2},varname),... - ncBaseArray(files{3},varname)... + ncArray(files{1},varname),... + ncArray(files{2},varname),... + ncArray(files{3},varname)... }); SST_test = CA2(:,:,:,2); @@ -162,7 +192,7 @@ if 1 - % test ncArray (constructor: ncData(var,dims,coord) + % test ncArray (constructor: ncArray(var,dims,coord) SST = ncBaseArray(filename,varname); SST_ref = ncread(filename,varname); @@ -229,5 +259,6 @@ SST_ref = ncread(files{2},'SST'); assert(isequalwithequalnans(SST_test,SST_ref)) +assert(strcmp(CA2.units,'degC')); + disp('All tests passed.') - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:20:44
|
Revision: 10671 http://octave.svn.sourceforge.net/octave/?rev=10671&view=rev Author: abarth93 Date: 2012-06-22 15:20:33 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m trunk/octave-forge/extra/ncArray/inst/ncCatData.m Deleted: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,81 +0,0 @@ -% C = ncCatArray(dim,filenames,varname) -% C = ncCatArray(dim,pattern,varname) -% C = ncCatArray(dim,filenamefun,varname,range) -% -% create a concatenated array from variables (varname) in a list of -% netcdf files along dimension dim.Individual elements can be accessed by -% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded -% -% This list of netcdf files can be specified as a cell array (filenames), -% shell wildcard pattern (e.g. file_*.nc) or a function handle -% filenamefun. In this later case, this i-th filename is -% filenamefun(range(i)). -% -% Example: -% -% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') -% -% data = ncCatArray(3,'file-*.nc','SST') -% -% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... -% datenum(2012,07,08):datenum(2012,07,09)); -% -% Note: in Octave the glob function is used to determine files matching the -% shell wildcard pattern, while in Matlab rdir is used. The function rdir -% is available from Matlab exchange under BSD license -% (http://www.mathworks.com/matlabcentral/fileexchange/19550). - -% Author: Alexander Barth (bar...@gm...) -% -function ncCA = ncCatArray(dim,pattern,varname,range) - -if iscell(pattern) - filenames = pattern; - -elseif ischar(pattern) - try - filenames = glob(pattern); - catch - try - d = rdir(pattern); - filenames = {d(:).name}; - catch - error(['The function rdir or glob (octave) is not available. '... - 'rdir can be installed from '... - 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); - end - end -elseif isa(pattern, 'function_handle') - filenames = cell(1,length(range)); - - for i=1:length(range) - filenames{i} = pattern(range(i)); - end -end - -arrays = cell(1,length(filenames)); - -for i=1:length(filenames) - arrays{i} = ncBaseArray(filenames{i},varname); -end - - -ncCA = CatArray(dim,arrays); - -% Copyright (C) 2012 Alexander Barth <bar...@gm...> -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; If not, see <http://www.gnu.org/licenses/>. - - - Copied: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m (from rev 10669, trunk/octave-forge/extra/ncArray/inst/ncCatData.m) =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -0,0 +1,111 @@ +% C = ncCatArray(dim,filenames,varname) +% C = ncCatArray(dim,pattern,varname) +% C = ncCatArray(dim,filenamefun,varname,range) +% +% create a concatenated array from variables (varname) in a list of +% netcdf files along dimension dim.Individual elements can be accessed by +% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded + +% This list of netcdf files can be specified as a cell array (filenames), +% shell wildcard pattern (e.g. file_*.nc) or a function handle +% filenamefun. In this later case, this i-th filename is +% filenamefun(range(i)). +% +% Example: +% +% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') +% +% data = ncCatArray(3,'file-*.nc','SST') +% +% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... +% datenum(2012,07,08):datenum(2012,07,09)); +% +% Note: in Octave the glob function is used to determine files matching the +% shell wildcard pattern, while in Matlab rdir is used. The function rdir +% is available from Matlab exchange under BSD license +% (http://www.mathworks.com/matlabcentral/fileexchange/19550). + +% Author: Alexander Barth (bar...@gm...) +% +function data = ncCatArray(dim,pattern,varname,range) + +catdimname = '_cat_dim'; + +if iscell(pattern) + filenames = pattern; + +elseif ischar(pattern) + try + filenames = glob(pattern); + catch + try + d = rdir(pattern); + filenames = {d(:).name}; + catch + error(['The function rdir or glob (octave) is not available. '... + 'rdir can be installed from '... + 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); + end + end +elseif isa(pattern, 'function_handle') + filenames = cell(1,length(range)); + + for i=1:length(range) + filenames{i} = pattern(range(i)); + end +end + +if nargin == 3 + range = 1:length(filenames); +end + +var = arr(dim,filenames,varname); + +[dims,coord] = nccoord(cached_decompress(filenames{1}),varname); + +if dim > length(dims) + % concatenate is new dimension + dims{dim} = catdimname; + coord(dim).dims = {catdimname}; + coord(dim).val = range; +end + + +for i=1:length(coord) + % coordinates do also depend on the dimension only which we concatenate + coord(i).val = arr(dim,filenames,coord(i).name); + if dim > length(coord(i).dims) + coord(i).dims{dim} = catdimname; + end +end + +data = ncArray(var,dims,coord); + +end + + +function CA = arr(dim,filenames,varname) +arrays = cell(1,length(filenames)); +for i=1:length(filenames) + arrays{i} = ncBaseArray(filenames{i},varname); +end + +CA = CatArray(dim,arrays); +end +% Copyright (C) 2012 Alexander Barth <bar...@gm...> +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see <http://www.gnu.org/licenses/>. + + + Deleted: trunk/octave-forge/extra/ncArray/inst/ncCatData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,111 +0,0 @@ -% C = ncCatArray(dim,filenames,varname) -% C = ncCatArray(dim,pattern,varname) -% C = ncCatArray(dim,filenamefun,varname,range) -% -% create a concatenated array from variables (varname) in a list of -% netcdf files along dimension dim.Individual elements can be accessed by -% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded - -% This list of netcdf files can be specified as a cell array (filenames), -% shell wildcard pattern (e.g. file_*.nc) or a function handle -% filenamefun. In this later case, this i-th filename is -% filenamefun(range(i)). -% -% Example: -% -% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') -% -% data = ncCatArray(3,'file-*.nc','SST') -% -% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... -% datenum(2012,07,08):datenum(2012,07,09)); -% -% Note: in Octave the glob function is used to determine files matching the -% shell wildcard pattern, while in Matlab rdir is used. The function rdir -% is available from Matlab exchange under BSD license -% (http://www.mathworks.com/matlabcentral/fileexchange/19550). - -% Author: Alexander Barth (bar...@gm...) -% -function data = ncCatData(dim,pattern,varname,range) - -catdimname = '_cat_dim'; - -if iscell(pattern) - filenames = pattern; - -elseif ischar(pattern) - try - filenames = glob(pattern); - catch - try - d = rdir(pattern); - filenames = {d(:).name}; - catch - error(['The function rdir or glob (octave) is not available. '... - 'rdir can be installed from '... - 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); - end - end -elseif isa(pattern, 'function_handle') - filenames = cell(1,length(range)); - - for i=1:length(range) - filenames{i} = pattern(range(i)); - end -end - -if nargin == 3 - range = 1:length(filenames); -end - -var = arr(dim,filenames,varname); - -[dims,coord] = nccoord(cached_decompress(filenames{1}),varname); - -if dim > length(dims) - % concatenate is new dimension - dims{dim} = catdimname; - coord(dim).dims = {catdimname}; - coord(dim).val = range; -end - - -for i=1:length(coord) - % coordinates do also depend on the dimension only which we concatenate - coord(i).val = arr(dim,filenames,coord(i).name); - if dim > length(coord(i).dims) - coord(i).dims{dim} = catdimname; - end -end - -data = ncArray(var,dims,coord); - -end - - -function CA = arr(dim,filenames,varname) -arrays = cell(1,length(filenames)); -for i=1:length(filenames) - arrays{i} = ncBaseArray(filenames{i},varname); -end - -CA = CatArray(dim,arrays); -end -% Copyright (C) 2012 Alexander Barth <bar...@gm...> -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2 of the License, or -% (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this program; If not, see <http://www.gnu.org/licenses/>. - - - Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:16:45 UTC (rev 10670) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:20:33 UTC (rev 10671) @@ -1,5 +1,5 @@ function test_ncarray() -% test ncBaseArray, ncCatArray, ncArray and ncCatData +% test ncBaseArray, ncCatArray, ncArray and ncCatArray varname = 'SST'; @@ -224,7 +224,7 @@ -CA2 = ncCatData(3,fullfile(tmpdir,'file*nc'),varname); +CA2 = ncCatArray(3,fullfile(tmpdir,'file*nc'),varname); SST_test = CA2(:,:,2); SST_ref = ncread(files{2},'SST'); assert(isequalwithequalnans(SST_test,SST_ref)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 15:16:51
|
Revision: 10670 http://octave.svn.sourceforge.net/octave/?rev=10670&view=rev Author: paramaniac Date: 2012-06-22 15:16:45 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: handle tsam in cat method Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-06-22 15:15:16 UTC (rev 10669) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/cat.m 2012-06-22 15:16:45 UTC (rev 10670) @@ -82,7 +82,8 @@ ## store all datasets in a single struct 'tmp' ## tmp is not a valid iddata set anymore, - ## but it doesn't matter, we want just a struct + ## but it doesn't matter, we want just a + ## temporary struct containing all the data tmp = cellfun (@iddata, varargin); [n, p, m, e] = cellfun (@size, varargin, "uniformoutput", false); @@ -91,6 +92,7 @@ ## default values for metadata ## some of them are overwritten in the switch statement below + tsam = tmp(1).tsam; expname = tmp(1).expname; outname = tmp(1).outname; outunit = tmp(1).outunit; @@ -128,13 +130,14 @@ y = vertcat (tmp.y); u = vertcat (tmp.u); + tsam = vertcat (tmp.tsam); expname = vertcat (tmp.expname); otherwise error ("iddata: cat: '%d' is an invalid dimension", dim); endswitch - dat = iddata (y, u); + dat = iddata (y, u, tsam); ## copy metadata dat.expname = expname; @@ -143,7 +146,7 @@ dat.inname = inname; dat.inunit = inunit; - % TODO: handle tsam, w + % TODO: handle w endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:15:27
|
Revision: 10669 http://octave.svn.sourceforge.net/octave/?rev=10669&view=rev Author: abarth93 Date: 2012-06-22 15:15:16 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/ncCatData.m trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/@ncArray/ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/@ncArray/ncData.m trunk/octave-forge/extra/ncArray/inst/ncData/ Copied: trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m (from rev 10668, trunk/octave-forge/extra/ncArray/inst/ncData/ncData.m) =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m 2012-06-22 15:15:16 UTC (rev 10669) @@ -0,0 +1,30 @@ +% data = ncArray(filename,varname) +% data = ncArray(var,dims,coord) +% data with coordinate values + +function retval = ncArray(varargin) + +if ischar(varargin{1}) + filename = varargin{1}; + varname = varargin{2}; + var = ncBaseArray(filename,varname); + [dims,coord] = nccoord(cached_decompress(filename),varname); + + for i=1:length(coord) + coord(i).val = ncBaseArray(filename,coord(i).name); + end +else + var = varargin{1}; + dims = varargin{2}; + coord = varargin{3}; +end + +self.var = var; +self.dims = dims; +self.nd = length(self.dims); +self.coord = coord; + +retval = class(self,'ncArray',BaseArray(size(self.var))); + + + Deleted: trunk/octave-forge/extra/ncArray/inst/@ncArray/ncData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncData/ncData.m 2012-06-22 15:13:45 UTC (rev 10668) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncData.m 2012-06-22 15:15:16 UTC (rev 10669) @@ -1,30 +0,0 @@ -% data = ncData(filename,varname) -% data = ncData(var,dims,coord) -% data with coordinate values - -function retval = ncData(varargin) - -if ischar(varargin{1}) - filename = varargin{1}; - varname = varargin{2}; - var = ncBaseArray(filename,varname); - [dims,coord] = nccoord(cached_decompress(filename),varname); - - for i=1:length(coord) - coord(i).val = ncBaseArray(filename,coord(i).name); - end -else - var = varargin{1}; - dims = varargin{2}; - coord = varargin{3}; -end - -self.var = var; -self.dims = dims; -self.nd = length(self.dims); -self.coord = coord; - -retval = class(self,'ncData',BaseArray(size(self.var))); - - - Modified: trunk/octave-forge/extra/ncArray/inst/ncCatData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:13:45 UTC (rev 10668) +++ trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:15:16 UTC (rev 10669) @@ -79,7 +79,7 @@ end end -data = ncData(var,dims,coord); +data = ncArray(var,dims,coord); end Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:13:45 UTC (rev 10668) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:15:16 UTC (rev 10669) @@ -1,5 +1,5 @@ function test_ncarray() -% test ncBaseArray, ncCatArray, ncData and ncCatData +% test ncBaseArray, ncCatArray, ncArray and ncCatData varname = 'SST'; @@ -162,7 +162,7 @@ if 1 - % test ncData (constructor: ncData(var,dims,coord) + % test ncArray (constructor: ncData(var,dims,coord) SST = ncBaseArray(filename,varname); SST_ref = ncread(filename,varname); @@ -177,7 +177,7 @@ coord(3).val = ncBaseArray(filename,'time'); coord(3).dims = {'time'}; - data = ncData(SST,{'x','y','time'},coord); + data = ncArray(SST,{'x','y','time'},coord); [x,y,t] = data(:,:,:).coord; @@ -192,8 +192,8 @@ [x,y,t] = data(1:3:end,:,:).coord; assert(isequalwithequalnans(x,lon_ref(1:3:end,:))) - % test ncData (constructor: ncData(filename,varname) - SST = ncData(filename,varname); + % test ncArray (constructor: ncData(filename,varname) + SST = ncArray(filename,varname); [x,y,t] = data(:,:,:).coord; assert(isequalwithequalnans(data(:,:,:),SST_ref)) @@ -218,7 +218,7 @@ zname = [tmpfname '.gz']; system(['gzip --stdout ' tmpfname ' > ' zname]); -SST = ncData(zname,'SST'); +SST = ncArray(zname,'SST'); SST_ref = ncread(tmpfname,'SST'); assert(isequalwithequalnans(SST(),SST_ref)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:13:51
|
Revision: 10668 http://octave.svn.sourceforge.net/octave/?rev=10668&view=rev Author: abarth93 Date: 2012-06-22 15:13:45 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m trunk/octave-forge/extra/ncArray/inst/ncCatData.m trunk/octave-forge/extra/ncArray/inst/ncData/ncData.m trunk/octave-forge/extra/ncArray/inst/ncData/subsref.m trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/ncData/ Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/@ncData/ Modified: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:09:28 UTC (rev 10667) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:13:45 UTC (rev 10668) @@ -56,7 +56,7 @@ arrays = cell(1,length(filenames)); for i=1:length(filenames) - arrays{i} = ncArray(filenames{i},varname); + arrays{i} = ncBaseArray(filenames{i},varname); end Modified: trunk/octave-forge/extra/ncArray/inst/ncCatData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:09:28 UTC (rev 10667) +++ trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:13:45 UTC (rev 10668) @@ -87,7 +87,7 @@ function CA = arr(dim,filenames,varname) arrays = cell(1,length(filenames)); for i=1:length(filenames) - arrays{i} = ncArray(filenames{i},varname); + arrays{i} = ncBaseArray(filenames{i},varname); end CA = CatArray(dim,arrays); Modified: trunk/octave-forge/extra/ncArray/inst/ncData/ncData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/ncData.m 2012-06-22 15:05:53 UTC (rev 10665) +++ trunk/octave-forge/extra/ncArray/inst/ncData/ncData.m 2012-06-22 15:13:45 UTC (rev 10668) @@ -7,11 +7,11 @@ if ischar(varargin{1}) filename = varargin{1}; varname = varargin{2}; - var = ncArray(filename,varname); + var = ncBaseArray(filename,varname); [dims,coord] = nccoord(cached_decompress(filename),varname); for i=1:length(coord) - coord(i).val = ncArray(filename,coord(i).name); + coord(i).val = ncBaseArray(filename,coord(i).name); end else var = varargin{1}; Modified: trunk/octave-forge/extra/ncArray/inst/ncData/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/subsref.m 2012-06-22 15:05:53 UTC (rev 10665) +++ trunk/octave-forge/extra/ncArray/inst/ncData/subsref.m 2012-06-22 15:13:45 UTC (rev 10668) @@ -27,6 +27,6 @@ varargout{i} = subsref(self.coord(i).val,idx_c); end else - % pass subsref to underlying ncArray + % pass subsref to underlying ncBaseArray varargout{1} = subsref(self.var,idx); end \ No newline at end of file Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:09:28 UTC (rev 10667) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:13:45 UTC (rev 10668) @@ -1,5 +1,5 @@ function test_ncarray() -% test ncArray, ncCatArray, ncData and ncCatData +% test ncBaseArray, ncCatArray, ncData and ncCatData varname = 'SST'; @@ -30,12 +30,12 @@ assert(isequalwithequalnans(test,SST_ref)) -%%% test ncArray +%%% test ncBaseArray % reading copyfile(files{2},tmpfname); -SST = ncArray(tmpfname,varname); +SST = ncBaseArray(tmpfname,varname); test = SST(:,:,:); SST_ref = ncread(tmpfname,varname); @@ -63,9 +63,9 @@ % reading CA = CatArray(3,{... - ncArray(filename,varname),... - ncArray(files{2},varname),... - ncArray(files{3},varname)... + ncBaseArray(filename,varname),... + ncBaseArray(files{2},varname),... + ncBaseArray(files{3},varname)... }); assert(isequalwithequalnans(size(CA),[220 144 3])) @@ -84,9 +84,9 @@ assert(isequalwithequalnans(SST_test,SST_ref)) CA2 = CatArray(4,{... - ncArray(files{1},varname),... - ncArray(files{2},varname),... - ncArray(files{3},varname)... + ncBaseArray(files{1},varname),... + ncBaseArray(files{2},varname),... + ncBaseArray(files{3},varname)... }); SST_test = CA2(:,:,:,2); @@ -164,17 +164,17 @@ if 1 % test ncData (constructor: ncData(var,dims,coord) - SST = ncArray(filename,varname); + SST = ncBaseArray(filename,varname); SST_ref = ncread(filename,varname); lon_ref = ncread(filename,'lon'); - coord(1).val = ncArray(filename,'lon'); + coord(1).val = ncBaseArray(filename,'lon'); coord(1).dims = {'x','y'}; - coord(2).val = ncArray(filename,'lat'); + coord(2).val = ncBaseArray(filename,'lat'); coord(2).dims = {'x','y'}; - coord(3).val = ncArray(filename,'time'); + coord(3).val = ncBaseArray(filename,'time'); coord(3).dims = {'time'}; data = ncData(SST,{'x','y','time'},coord); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:09:34
|
Revision: 10667 http://octave.svn.sourceforge.net/octave/?rev=10667&view=rev Author: abarth93 Date: 2012-06-22 15:09:28 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray@/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:08:43
|
Revision: 10666 http://octave.svn.sourceforge.net/octave/?rev=10666&view=rev Author: abarth93 Date: 2012-06-22 15:08:33 +0000 (Fri, 22 Jun 2012) Log Message: ----------- Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray@/ Removed Paths: ------------- trunk/octave-forge/extra/ncArray/inst/@ncArray/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aba...@us...> - 2012-06-22 15:06:04
|
Revision: 10665 http://octave.svn.sourceforge.net/octave/?rev=10665&view=rev Author: abarth93 Date: 2012-06-22 15:05:53 +0000 (Fri, 22 Jun 2012) Log Message: ----------- initial import of ncArray Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/@BaseArray/ trunk/octave-forge/extra/ncArray/inst/@BaseArray/BaseArray.m trunk/octave-forge/extra/ncArray/inst/@BaseArray/end.m trunk/octave-forge/extra/ncArray/inst/@BaseArray/full.m trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m trunk/octave-forge/extra/ncArray/inst/@CatArray/ trunk/octave-forge/extra/ncArray/inst/@CatArray/CatArray.m trunk/octave-forge/extra/ncArray/inst/@CatArray/display.m trunk/octave-forge/extra/ncArray/inst/@CatArray/idx_global_local_.m trunk/octave-forge/extra/ncArray/inst/@CatArray/subsasgn.m trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m trunk/octave-forge/extra/ncArray/inst/@ncArray/ trunk/octave-forge/extra/ncArray/inst/@ncArray/display.m trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m trunk/octave-forge/extra/ncArray/inst/@ncArray/ncsub.m trunk/octave-forge/extra/ncArray/inst/@ncArray/subsasgn.m trunk/octave-forge/extra/ncArray/inst/@ncArray/subsref.m trunk/octave-forge/extra/ncArray/inst/@ncData/ trunk/octave-forge/extra/ncArray/inst/@ncData/coord.m trunk/octave-forge/extra/ncArray/inst/@ncData/ncData.m trunk/octave-forge/extra/ncArray/inst/@ncData/subsasgn.m trunk/octave-forge/extra/ncArray/inst/@ncData/subsref.m Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/BaseArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/BaseArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/BaseArray.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,7 @@ +% sz size of the array (with at least two elements) + +function retval = BaseArray(sz) + +self.sz = sz; + +retval = class(self,'BaseArray'); \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/end.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/end.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/end.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,3 @@ +function e = end(self,k,n) + +e = size(self,k); Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/full.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/full.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/full.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,10 @@ +function F = full(self); + +n = length(self.sz); +idx.type = '()'; + +for i=1:n + idx.subs{i} = ':'; +end + +F = subsref(self,idx); \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,8 @@ +function sz = size(self,dim) + +sz = self.sz; + +if nargin == 2 + sz = sz(dim); +end + Added: trunk/octave-forge/extra/ncArray/inst/@CatArray/CatArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/CatArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/CatArray.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,70 @@ +% C = CatArray(dim,{array1,array2,...}) +% +% Create a concatenated array from a cell-list of arrays. Individual +% elements can be accessed by subscribs, e.g.: +% C(2,3) + + +function retval = CatArray(dim,arrays) + +self.dim = dim; +self.arrays = arrays; +self.na = length(arrays); + +% number of dimensions +self.nd = length(size(arrays{1})); +if dim > self.nd + self.nd = dim; +end + +self.size = ones(self.na,self.nd); +self.start = ones(self.na,self.nd); + +% get size of all arrays +for i=1:self.na + tmp = size(arrays{i}); + self.size(i,1:length(tmp)) = tmp; +end + +% check if dimensions are consistent +ncd = 1:self.nd ~= dim; +for i=2:self.na + if ~all(self.size(i,ncd) == self.size(1,ncd)) + error('Array number %d has inconsistent dimension',i); + end +end + +% start index of each sub-array + +for i=2:self.na + self.start(i,:) = self.start(i-1,:); + self.start(i,dim) = self.start(i,dim) + self.size(i-1,dim); +end + +self.end = self.start + self.size - 1; + +self.sz = self.size(1,:); +self.sz(dim) = sum(self.size(:,dim)); +self.overlap = false; +self.bounds = [0; cumsum(prod(self.size,2))]; + +retval = class(self,'CatArray',BaseArray(self.sz)); + + +% Copyright (C) 2012 Alexander Barth <bar...@gm...> +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see <http://www.gnu.org/licenses/>. + + + Added: trunk/octave-forge/extra/ncArray/inst/@CatArray/display.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/display.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/display.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,6 @@ +function display(self) + +for i=1:self.na + display(self.arrays{i}) +end + \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@CatArray/idx_global_local_.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/idx_global_local_.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/idx_global_local_.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,58 @@ +% private method + +function [idx_global,idx_local,sz] = idx_global_local_(self,idx) + +assert(strcmp(idx.type,'()')) + +n = length(size(self)); + +% number of indices must be equal to dimension +assert(length(idx.subs) == n) + +lb = ones(1,n); % lower bound +ub = ones(1,n); % upper bound +sz = ones(1,n); % size + +% transform all colons to index range +for i=1:n + if strcmp(idx.subs{i},':') + idx.subs{i} = 1:self.sz(i); + end + + lb(i) = min(idx.subs{i}); + ub(i) = max(idx.subs{i}); + sz(i) = length(idx.subs{i}); +end + +%sz = ub-lb+1; + +idx_local = cell(1,self.na); +idx_global = cell(1,self.na); + +% loop over all arrays +for j=1:self.na + idx_local{j} = idx; + idx_global{j} = idx; + + % loop over all dimensions + for i=1:n + % rebase subscribt at self.start(j,i) + tmp = idx.subs{i} - self.start(j,i) + 1; + + % only indeces within bounds of the j-th array + sel = 1 <= tmp & tmp <= self.size(j,i); + + % index for getting the data from the local j-th array + idx_local{j}.subs{i} = tmp(sel); + + % index for setting the data in the global B array + %idx_global{j}.subs{i} = idx.subs{i}(sel) - lb(i)+1; + + if sum(sel) == 0 + idx_global{j}.subs{i} = []; + else + idx_global{j}.subs{i} = (1:sum(sel)) + find(sel,1,'first') - 1; + end + end + +end Added: trunk/octave-forge/extra/ncArray/inst/@CatArray/subsasgn.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/subsasgn.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/subsasgn.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,14 @@ +function self = subsasgn(self,idx,x) + +[idx_global,idx_local,sz] = idx_global_local_(self,idx); + + + + +for j=1:self.na + % get subset from global array x + subset = subsref(x,idx_global{j}); + + % set subset in j-th array + subsasgn(self.arrays{j},idx_local{j},subset); +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@CatArray/subsref.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,79 @@ +function B = subsref(self,idx) + +% handle case with a single subscript +% for example CA(234) + +if strcmp(idx.type,'()') && length(idx.subs) == 1 + % indices of elements in B + ind = idx.subs{1}; + + % output array + B = zeros(size(ind)); + B(:) = NaN; + + if self.overlap + % transform index to subscript + subs = cell(1,self.nd); + [subs{:}] = ind2sub(size(self),ind); + + % make a nice array length(ind) by self.nd + subs = cell2mat(subs); + + + % get every element + idxe.type = '()'; + idxe.subs = cell(1,self.nd); + + for i=1:length(ind) + idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd)); + %B(i) = subsref_canonical(self,idxe); + + [idx_global,idx_local,sz] = idx_global_local_(self,idxe); + tmp = zeros(sz); + tmp(:) = NaN; + + + for j=1:self.na + % get subset from j-th array + subset = subsref(self.arrays{j},idx_local{j}); + + % set subset in global array B + tmp = subsasgn(tmp,idx_global{j},subset); + end + B(i) = tmp; + + end + else + % assume all arrays does not overlap + + for j=1:self.na + sel = self.bounds(j) < ind & ind <= self.bounds(j+1); + B(sel) = self.arrays{j}(ind(sel) - self.bounds(j)); + end + + end + +else + B = subsref_canonical(self,idx); +end + +end + +% for this function we assume that idx.subs has the same dimension than +% the array + +function B = subsref_canonical(self,idx) +[idx_global,idx_local,sz] = idx_global_local_(self,idx); + +B = zeros(sz); +B(:) = NaN; + +for j=1:self.na + % get subset from j-th array + subset = subsref(self.arrays{j},idx_local{j}); + + % set subset in global array B + B = subsasgn(B,idx_global{j},subset); +end + +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@ncArray/display.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/display.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/display.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,4 @@ +function display(self) +disp([self.varname ' from ' self.filename]); +%self.vinfo +%self.dims Added: trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncArray.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,61 @@ +% V = ncArray(filename,varname) +% V = ncArray(filename,varname,'property',value,...) +% create a ncArray that can be accessed as a normal matlab array. +% +% For read access filename can be compressed if it has the extensions +% ".gz" or ".bz2". It use the function cache_decompress to cache to +% decompressed files. +% +% Data is loaded by ncread and saved by ncwrite. Values equal to _FillValue +% are thus replaced by NaN and the scaling (add_offset and +% scale_factor) is applied during loading and saving. +% +% Properties: +% 'tooBigToLoad': if tooBigToLoad is set to true, then only the minimum +% data will be loaded. However this can be quite slow. +% +% Example: +% +% Loading the variable (assuming V is 3 dimensional): +% +% x = V(1,1,1); % load element 1,1,1 +% x = V(:,:,:); % load the complete array +% x = V(); x = full(V) % loads also the complete array +% +% Saving data in the netcdf file: +% V(1,1,1) = x; % save x in element 1,1,1 +% V(:,:,:) = x; +% +% Attributes +% units = V.units; % get attribute called "units" +% V.units = 'degree C'; % set attributes; +% +% Note: use the '.()' notation if the attribute has a leading underscore +% (due to a limitation in the matlab parser): +% +% V.('_someStrangeAttribute') = 123; +% +% see also cache_decompress + +function retval = ncArray(filename,varname,varargin) + +self.tooBigToLoad = false; +prop = varargin; + +for i=1:2:length(prop) + if strcmp(prop{i},'tooBigToLoad ') + self.tooBigToLoad = prop{i+1}; + end +end + +self.filename = filename; +self.varname = varname; + +self.vinfo = ncinfo(cached_decompress(filename),varname); +self.sz = self.vinfo.Size; + +self.dims = self.vinfo.Dimensions; +self.nd = length(self.dims); + +retval = class(self,'ncArray',BaseArray(self.sz)); +end Added: trunk/octave-forge/extra/ncArray/inst/@ncArray/ncsub.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/ncsub.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/ncsub.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,61 @@ +function [start, count, stride] = ncsub(self,idx) + +assert(strcmp(idx.type,'()')) + +% number of dimension (including singleton dimensions) +%n = length(size(self)); +n = self.nd; + +% number of subscripts +ns = length(idx.subs); + +if ns == 0 + % load all + start = ones(1,n); + count = self.sz; + stride = ones(1,n); +else + + start = ones(1,ns); + count = ones(1,ns); + stride = ones(1,ns); + + % sz is the size padded by 1 if more indices are given than n + sz = ones(1,ns); + sz(1:length(self.sz)) = self.sz; + + for i=1:ns + if isempty(idx.subs{i}) + count(i) = 0; + + elseif strcmp(idx.subs{i},':') + count(i) = sz(i); + + else + tmp = idx.subs{i}; + + if length(tmp) == 1 + start(i) = tmp; + else + test = tmp(1):tmp(2)-tmp(1):tmp(end); + + if all(tmp == test) + start(i) = tmp(1); + stride(i) = tmp(2)-tmp(1); + count(i) = (tmp(end)-tmp(1))/stride(i) +1; + else + error('indeces'); + end + end + end + end + + assert(all(count(n+1:end) == 1 | count(n+1:end) == 0)) + assert(all(start(n+1:end) == 1)) + + if ~any(count == 0) + count = count(1:n); + start = start(1:n); + stride = stride(1:n); + end +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@ncArray/subsasgn.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/subsasgn.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/subsasgn.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,10 @@ +function self = subsasgn(self,idxs,x) +%idx + +idx = idxs(1); +assert(strcmp(idx.type,'()')) +[start, count, stride] = ncsub(self,idx); + +if all(count ~= 0) + ncwrite(self.filename,self.varname,x,start,stride); +end Added: trunk/octave-forge/extra/ncArray/inst/@ncArray/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncArray/subsref.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncArray/subsref.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,65 @@ +function x = subsref(self,idx) + +assert(length(idx) == 1) + +if strcmp(idx.type,'()') + % load data + + if strcmp(idx.type,'()') && length(idx.subs) == 1 ... + && length(idx.subs) < self.nd + % reference like A([2 3 1 5]) + + if self.tooBigToLoad + % number of elements in x + ind = idx.subs{1}; + + % transform index to subscript + subs = cell(1,self.nd); + [subs{:}] = ind2sub(size(self),ind); + + % make a nice array length(ind) by self.nd + subs = cell2mat(subs); + + % output array + x = zeros(size(ind)); + x(:) = NaN; + + + % get every element + % can be quite slow + idxe.type = '()'; + idxe.subs = cell(1,self.nd); + + for i=1:length(ind) + idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd)); + x(i) = subsref(self,idxe); + end + else + % load full array + tmp = full(self); + x = subsref(tmp,idx); + end + else + [start, count, stride] = ncsub(self,idx); + + if any(count == 0) + x = zeros(count); + else + x = ncread(cached_decompress(self.filename),self.varname,... + start,count,stride); + end + end +elseif strcmp(idx.type,'.') + % load attribute + name = idx.subs; + index = strmatch(name,{self.vinfo.Attributes(:).Name}); + + if isempty(index) + error('variable %s has no attribute called %s',self.varname,name); + else + x = self.vinfo.Attributes(index).Value; + end +else + error('not supported'); + +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@ncData/coord.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/coord.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncData/coord.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,3 @@ +function c = coord(self) +c = self.coord; +%'her' \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/@ncData/ncData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/ncData.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncData/ncData.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,30 @@ +% data = ncData(filename,varname) +% data = ncData(var,dims,coord) +% data with coordinate values + +function retval = ncData(varargin) + +if ischar(varargin{1}) + filename = varargin{1}; + varname = varargin{2}; + var = ncArray(filename,varname); + [dims,coord] = nccoord(cached_decompress(filename),varname); + + for i=1:length(coord) + coord(i).val = ncArray(filename,coord(i).name); + end +else + var = varargin{1}; + dims = varargin{2}; + coord = varargin{3}; +end + +self.var = var; +self.dims = dims; +self.nd = length(self.dims); +self.coord = coord; + +retval = class(self,'ncData',BaseArray(size(self.var))); + + + Added: trunk/octave-forge/extra/ncArray/inst/@ncData/subsasgn.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/subsasgn.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncData/subsasgn.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,3 @@ +function self = subsasgn(self,idx,x) + +self = subsasgn(self.var,idx,x); Added: trunk/octave-forge/extra/ncArray/inst/@ncData/subsref.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncData/subsref.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@ncData/subsref.m 2012-06-22 15:05:53 UTC (rev 10665) @@ -0,0 +1,32 @@ +function varargout = subsref(self,idx) + +if strcmp(idx(1).type,'()') + + % no subscripts mean that we load all () -> (:,:,...) + if isempty(idx(1).subs) + for i=1:self.nd + idx(1).subs{i} = ':'; + end + end +end + +% catch expressions like: +% data(:,:,:).coord + +if length(idx) == 2 && strcmp(idx(2).type,'.') && strcmp(idx(2).subs,'coord') + for i=1:length(self.coord) + % get indeces of the dimensions of the i-th coordinate which are also + % coordinate of the variable + + % replace dummy by ~ once older version have died + [dummy,j] = intersect(self.dims,self.coord(i).dims); + j = sort(j); + idx_c.type = '()'; + idx_c.subs = idx(1).subs(j); + + varargout{i} = subsref(self.coord(i).val,idx_c); + end +else + % pass subsref to underlying ncArray + varargout{1} = subsref(self.var,idx); +end \ 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: <aba...@us...> - 2012-06-22 15:04:49
|
Revision: 10664 http://octave.svn.sourceforge.net/octave/?rev=10664&view=rev Author: abarth93 Date: 2012-06-22 15:04:40 +0000 (Fri, 22 Jun 2012) Log Message: ----------- initial import of ncArray Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/private/ trunk/octave-forge/extra/ncArray/inst/private/ncarray_example_file.m Added: trunk/octave-forge/extra/ncArray/inst/private/ncarray_example_file.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/private/ncarray_example_file.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/private/ncarray_example_file.m 2012-06-22 15:04:40 UTC (rev 10664) @@ -0,0 +1,35 @@ +function ncarray_example_file(filename,data) + +nc = netcdf(filename,'c'); + +% dimensions + +nc('x') = size(data,1); +nc('y') = size(data,2); +nc('time') = size(data,3); + +% variables + +nc{'lon'} = ncfloat('y','x'); % 31680 elements +nc{'lon'}.long_name = ncchar('Longitude'); +nc{'lon'}.units = ncchar('degrees_east'); + +nc{'lat'} = ncfloat('y','x'); % 31680 elements +nc{'lat'}.long_name = ncchar('Latitude'); +nc{'lat'}.units = ncchar('degrees_north'); + +nc{'time'} = ncfloat('time'); % 1 elements +nc{'time'}.long_name = ncchar('Time'); +nc{'time'}.units = ncchar('days since 1858-11-17 00:00:00 GMT'); + +nc{'SST'} = ncfloat('time','y','x'); % 31680 elements +nc{'SST'}.missing_value = ncfloat(9999); +nc{'SST'}.FillValue_ = ncfloat(9999); +nc{'SST'}.units = ncchar('degC'); +nc{'SST'}.long_name = ncchar('Sea Surface Temperature'); +nc{'SST'}.coordinates = ncchar('lat lon'); + +% global attributes + +nc{'SST'}(:) = permute(data,[3 2 1]); +close(nc) \ 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: <aba...@us...> - 2012-06-22 15:04:20
|
Revision: 10663 http://octave.svn.sourceforge.net/octave/?rev=10663&view=rev Author: abarth93 Date: 2012-06-22 15:04:09 +0000 (Fri, 22 Jun 2012) Log Message: ----------- initial import of ncArray Added Paths: ----------- trunk/octave-forge/extra/ncArray/ trunk/octave-forge/extra/ncArray/DESCRIPTION trunk/octave-forge/extra/ncArray/inst/ trunk/octave-forge/extra/ncArray/inst/cached_decompress.m trunk/octave-forge/extra/ncArray/inst/ncCatArray.m trunk/octave-forge/extra/ncArray/inst/ncCatData.m trunk/octave-forge/extra/ncArray/inst/nccoord.m trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added: trunk/octave-forge/extra/ncArray/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/ncArray/DESCRIPTION (rev 0) +++ trunk/octave-forge/extra/ncArray/DESCRIPTION 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,11 @@ +Name: ncArray +Version: 1.0.0 +Date: 2012-06-22 +Author: Alexander Barth <bar...@gm...> +Maintainer: Alexander Barth <bar...@gm...> +Title: ncArray +Description: Subsetting and concatenating of NetCDF files +Depends: octave (>= 3.4.0) +Autoload: yes +License: GPL version 2 or later +Url: http://octave.sf.net Added: trunk/octave-forge/extra/ncArray/inst/cached_decompress.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/cached_decompress.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/cached_decompress.m 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,118 @@ +% [fname,success]=cached_decompress(filename) +% +% Decompress a file if it is not already in cache +% +% Input: +% filename: name of the file which is possibly compressed +% +% Output: +% fname: the filename of the uncompressed file +% +% Example: +% +% +% Alexander Barth, 2012-06-13 +% + + +function [fname]=cached_decompress(url) +global CASHED_GUNZIP_DIR +global CASHED_GUNZIP_LOG_FID + + +cache_dir = CASHED_GUNZIP_DIR; +if isempty(cache_dir) +% cache_dir = fullfile(getenv('HOME'),'tmp','Cache'); + cache_dir = fullfile(getenv('HOME'),'tmp','Cache'); +end + + +if endswith(url,'.gz') || endswith(url,'.bz2') + if exist(cache_dir,'dir') ~= 7 + error(['cache directory for compressed files does not exist. '... + 'Please create the directory %s or change le value of the '... + 'global variable CASHED_GUNZIP_DIR'],cache_dir); + end +else + fname = url; + return +end + +% where to print logs? default to screen + +fid=CASHED_GUNZIP_LOG_FID; + +if (isempty(fid)) + fid=1; +end + +% form filename for cache + +fname = url; +fname = strrep(fname,'/','_SLASH_'); +fname = strrep(fname,'*','_STAR_'); +fname = fullfile(cache_dir,fname); + +% test if in cache + +if exist(fname,'file') ~= 2 + if endswith(url,'.gz') + syscmd('gunzip --stdout "%s" > "%s"',url,fname); + else + syscmd('bunzip2 --stdout "%s" > "%s"',url,fname); + end +else +% fprintf(fid,'retrieve from cache %s\n',url); +end + +% check cache size + +d=dir(cache_dir); +cashe_size = sum([d.bytes]); +max_cache_size = 1e10; + +if (cashe_size > max_cache_size) + + % look for oldest files + fdate = zeros(1,length(d)); + for i=1:length(d); + fdate(i) = datenum(d(i).date); + end + + [fdate,index] = sort(fdate,'descend'); + d=d(index); + + cum_size = cumsum([d(:).bytes]); + todelete = find(cum_size > max_cache_size); + + for i=todelete + if (d(i).isdir == 0) + fprintf(fid,'clean cashe: delete %s\n', d(i).name); + delete(fullfile(cache_dir,d(i).name)); + end + end +end +end + +function t = endswith(s,ext) + +if length(ext) <= length(s) + t = strcmp(s(end-length(ext)+1:end),ext); +else + t = 0; +end +end + + +function syscmd(varargin) + +cmd = sprintf(varargin{:}); +%disp(cmd) +status = 0; +[status, output] = system(cmd); + +disp(output); +if status ~= 0 + error(['command "' cmd '" failed: ' output]); +end +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/ncCatArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatArray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/ncCatArray.m 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,81 @@ +% C = ncCatArray(dim,filenames,varname) +% C = ncCatArray(dim,pattern,varname) +% C = ncCatArray(dim,filenamefun,varname,range) +% +% create a concatenated array from variables (varname) in a list of +% netcdf files along dimension dim.Individual elements can be accessed by +% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded +% +% This list of netcdf files can be specified as a cell array (filenames), +% shell wildcard pattern (e.g. file_*.nc) or a function handle +% filenamefun. In this later case, this i-th filename is +% filenamefun(range(i)). +% +% Example: +% +% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') +% +% data = ncCatArray(3,'file-*.nc','SST') +% +% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... +% datenum(2012,07,08):datenum(2012,07,09)); +% +% Note: in Octave the glob function is used to determine files matching the +% shell wildcard pattern, while in Matlab rdir is used. The function rdir +% is available from Matlab exchange under BSD license +% (http://www.mathworks.com/matlabcentral/fileexchange/19550). + +% Author: Alexander Barth (bar...@gm...) +% +function ncCA = ncCatArray(dim,pattern,varname,range) + +if iscell(pattern) + filenames = pattern; + +elseif ischar(pattern) + try + filenames = glob(pattern); + catch + try + d = rdir(pattern); + filenames = {d(:).name}; + catch + error(['The function rdir or glob (octave) is not available. '... + 'rdir can be installed from '... + 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); + end + end +elseif isa(pattern, 'function_handle') + filenames = cell(1,length(range)); + + for i=1:length(range) + filenames{i} = pattern(range(i)); + end +end + +arrays = cell(1,length(filenames)); + +for i=1:length(filenames) + arrays{i} = ncArray(filenames{i},varname); +end + + +ncCA = CatArray(dim,arrays); + +% Copyright (C) 2012 Alexander Barth <bar...@gm...> +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see <http://www.gnu.org/licenses/>. + + + Added: trunk/octave-forge/extra/ncArray/inst/ncCatData.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/ncCatData.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/ncCatData.m 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,111 @@ +% C = ncCatArray(dim,filenames,varname) +% C = ncCatArray(dim,pattern,varname) +% C = ncCatArray(dim,filenamefun,varname,range) +% +% create a concatenated array from variables (varname) in a list of +% netcdf files along dimension dim.Individual elements can be accessed by +% subscribs, e.g. C(2,3) and the corrsponding subset of the appropriate file is loaded + +% This list of netcdf files can be specified as a cell array (filenames), +% shell wildcard pattern (e.g. file_*.nc) or a function handle +% filenamefun. In this later case, this i-th filename is +% filenamefun(range(i)). +% +% Example: +% +% data = ncCatArray(3,{'file-20120708.nc','file-20120709.nc'},'SST') +% +% data = ncCatArray(3,'file-*.nc','SST') +% +% data = ncCatArray(3,@(t) ['file-' datestr(t,'yyyymmdd') '.nc'],... +% datenum(2012,07,08):datenum(2012,07,09)); +% +% Note: in Octave the glob function is used to determine files matching the +% shell wildcard pattern, while in Matlab rdir is used. The function rdir +% is available from Matlab exchange under BSD license +% (http://www.mathworks.com/matlabcentral/fileexchange/19550). + +% Author: Alexander Barth (bar...@gm...) +% +function data = ncCatData(dim,pattern,varname,range) + +catdimname = '_cat_dim'; + +if iscell(pattern) + filenames = pattern; + +elseif ischar(pattern) + try + filenames = glob(pattern); + catch + try + d = rdir(pattern); + filenames = {d(:).name}; + catch + error(['The function rdir or glob (octave) is not available. '... + 'rdir can be installed from '... + 'http://www.mathworks.com/matlabcentral/fileexchange/19550']); + end + end +elseif isa(pattern, 'function_handle') + filenames = cell(1,length(range)); + + for i=1:length(range) + filenames{i} = pattern(range(i)); + end +end + +if nargin == 3 + range = 1:length(filenames); +end + +var = arr(dim,filenames,varname); + +[dims,coord] = nccoord(cached_decompress(filenames{1}),varname); + +if dim > length(dims) + % concatenate is new dimension + dims{dim} = catdimname; + coord(dim).dims = {catdimname}; + coord(dim).val = range; +end + + +for i=1:length(coord) + % coordinates do also depend on the dimension only which we concatenate + coord(i).val = arr(dim,filenames,coord(i).name); + if dim > length(coord(i).dims) + coord(i).dims{dim} = catdimname; + end +end + +data = ncData(var,dims,coord); + +end + + +function CA = arr(dim,filenames,varname) +arrays = cell(1,length(filenames)); +for i=1:length(filenames) + arrays{i} = ncArray(filenames{i},varname); +end + +CA = CatArray(dim,arrays); +end +% Copyright (C) 2012 Alexander Barth <bar...@gm...> +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; If not, see <http://www.gnu.org/licenses/>. + + + Added: trunk/octave-forge/extra/ncArray/inst/nccoord.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/nccoord.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/nccoord.m 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,54 @@ +% coord = nccoord(filename,varname) +% get coordinates of a variables using CF convention + +function [dims,coord] = nccoord(filename,varname) + +finfo = ncinfo(filename); +vinfo = ncinfo(filename,varname); + +% determine coordinates +% using CF convention + +dims = vinfo.Dimensions; + +% create empty coord array with the fields name and dims +coord = struct('name',{},'dims',{}); + +% check the coordinate attribute +index = strmatch('coordinates',{vinfo.Attributes(:).Name}); +if ~isempty(index) + tmp = strsplit(vinfo.Attributes(index).Value,' '); + + for i=1:length(tmp) + coord = addcoord(coord,tmp{i},finfo); + end +end + +% check for coordinate dimensions +for i=1:length(dims) + % check if variable with the same name than the dimension exist + index = strmatch(dims{i},{finfo.Variables(:).Name}); + if ~isempty(index) + coord = addcoord(coord,dims{i},finfo); + end +end + + +end + +function coord = addcoord(coord,name,finfo) + +% check if coordinate is aleady in the list +if isempty(strmatch(name,{coord(:).name})) + + % check if name is variable + index = strmatch(name,{finfo.Variables(:).Name}); + if ~isempty(index) + c.name = name; + c.dims = finfo.Variables(index).Dimensions; + + coord(end+1) = c; + end +end + +end \ No newline at end of file Added: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-22 15:04:09 UTC (rev 10663) @@ -0,0 +1,233 @@ +function test_ncarray() +% test ncArray, ncCatArray, ncData and ncCatData + +varname = 'SST'; + +tmpdir = tempname; +mkdir(tmpdir); + +tmpfname = tempname(tmpdir); +for i = 1:3 + files{i} = fullfile(tmpdir,sprintf('file%d.nc',i)); + ncarray_example_file(files{i},randn(220,144)); +end + + +filename = files{1}; + + +% test ncread/ncwrite + +copyfile(files{1},tmpfname); +SST_ref = ncread(files{1},'SST'); +ncwrite(tmpfname,'SST',zeros(size(SST_ref))); +test = ncread(tmpfname,'SST'); + +assert(all(test(:) == 0)) + +ncwrite(tmpfname,'SST',SST_ref); +test = ncread(tmpfname,'SST'); +assert(isequalwithequalnans(test,SST_ref)) + + +%%% test ncArray + +% reading + +copyfile(files{2},tmpfname); +SST = ncArray(tmpfname,varname); +test = SST(:,:,:); +SST_ref = ncread(tmpfname,varname); + +assert(isequalwithequalnans(test,SST_ref)) +assert(isempty(SST(:,:,:,[]))); +assert(isequalwithequalnans(SST_ref, SST(:,:,:,1))) + +ind = floor(numel(SST_ref) * rand(100,1))+1; +assert(isequalwithequalnans(SST(ind),SST_ref(ind))) + +% writing + +r = round(randn(size(SST))); +SST(:,:,:) = r; +SST_ref = ncread(tmpfname,varname); +assert(isequalwithequalnans(r,SST_ref)); + +SST(:,:,:) = 3 * r; +SST_ref = ncread(tmpfname,varname); +assert(isequalwithequalnans(3 * r,SST_ref)); + + +%%% CatArray + +% reading + +CA = CatArray(3,{... + ncArray(filename,varname),... + ncArray(files{2},varname),... + ncArray(files{3},varname)... + }); + +assert(isequalwithequalnans(size(CA),[220 144 3])) + +SST_ref = ncread(filename,'SST'); +tmp2 = CA(:,:,1); +assert(isequalwithequalnans(SST_ref,tmp2)) + + + +SST_test = CA(:,:,2); +SST_ref = ncread(files{2},'SST'); + + + +assert(isequalwithequalnans(SST_test,SST_ref)) + +CA2 = CatArray(4,{... + ncArray(files{1},varname),... + ncArray(files{2},varname),... + ncArray(files{3},varname)... + }); + +SST_test = CA2(:,:,:,2); + +assert(isequalwithequalnans(SST_test,SST_ref)) + +CA2 = ncCatArray(3,{... + files{1},... + files{2},... + files{3}},... + varname); + +SST_test = CA2(:,:,2); +assert(isequalwithequalnans(SST_test,SST_ref)) + +CA2 = ncCatArray(3,fullfile(tmpdir,'file*nc'),varname); +SST_test = CA2(:,:,2); +assert(isequalwithequalnans(SST_test,SST_ref)) + + +CA2 = ncCatArray(3,... + @(i) fullfile(tmpdir,sprintf('file%d.nc',i)),... + varname,... + 1:3); + +SST_test = CA2(:,:,2); +assert(isequalwithequalnans(SST_test,SST_ref)) + +SST_ref = cat(3,... + ncread(files{1},'SST'),... + ncread(files{2},'SST'),... + ncread(files{3},'SST')); + + +assert(isequalwithequalnans(CA2(:,:,:),SST_ref)) + +assert(isequalwithequalnans(CA2(:,:,1),SST_ref(:,:,1))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:100,1),SST_ref(3:5:50,3:5:100,1))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:100,2),SST_ref(3:5:50,3:5:100,2))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:100,3),SST_ref(3:5:50,3:5:100,3))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:100,end),SST_ref(3:5:50,3:5:100,end))) +assert(isequalwithequalnans(CA2(50,100,1:3),SST_ref(50,100,1:3))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:100,1:2:3),SST_ref(3:5:50,3:5:100,1:2:3))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:end,1:2:3),SST_ref(3:5:50,3:5:end,1:2:3))) +assert(isequalwithequalnans(CA2(3:5:50,3:5:end,:),SST_ref(3:5:50,3:5:end,:))) +ind = floor(numel(SST_ref) * rand(100,1))+1; +assert(isequalwithequalnans(CA2(ind),SST_ref(ind))) + +% writing + +for i=1:3 + list{i} = tempname; + copyfile(filename,list{i}); +end + +CA2 = ncCatArray(3,list,varname); +r = round(randn(size(CA2))); +CA2(:,:,:) = r; + +check = ncread(list{2},varname); +assert(isequalwithequalnans(check,r(:,:,2))) + +r2 = round(randn(size(CA2))); +r(3:5:50,3:5:end,:) = r2(3:5:50,3:5:end,:); +CA2(3:5:50,3:5:end,:) = r2(3:5:50,3:5:end,:); +assert(isequalwithequalnans(CA2(:,:,:),r)) + +r(end-1,3:5:end,1:2:3) = 2*r2(end-1,3:5:end,1:2:3); +CA2(end-1,3:5:end,1:2:3) = 2*r2(end-1,3:5:end,1:2:3); +assert(isequalwithequalnans(CA2(:,:,:),r)) + + + + +if 1 + % test ncData (constructor: ncData(var,dims,coord) + + SST = ncArray(filename,varname); + SST_ref = ncread(filename,varname); + lon_ref = ncread(filename,'lon'); + + coord(1).val = ncArray(filename,'lon'); + coord(1).dims = {'x','y'}; + + coord(2).val = ncArray(filename,'lat'); + coord(2).dims = {'x','y'}; + + coord(3).val = ncArray(filename,'time'); + coord(3).dims = {'time'}; + + data = ncData(SST,{'x','y','time'},coord); + + [x,y,t] = data(:,:,:).coord; + + assert(isequalwithequalnans(data(:,:,:),SST_ref)) + assert(isequalwithequalnans(x,lon_ref)) + + assert(isequalwithequalnans(data(),SST_ref)) + [x,y,t] = data().coord; + assert(isequalwithequalnans(x,lon_ref)) + + assert(isequalwithequalnans(data(1:3:end,:,:),SST_ref(1:3:end,:,:))) + [x,y,t] = data(1:3:end,:,:).coord; + assert(isequalwithequalnans(x,lon_ref(1:3:end,:))) + + % test ncData (constructor: ncData(filename,varname) + SST = ncData(filename,varname); + [x,y,t] = data(:,:,:).coord; + + assert(isequalwithequalnans(data(:,:,:),SST_ref)) + assert(isequalwithequalnans(x,lon_ref)) + + assert(isequalwithequalnans(data(),SST_ref)) + [x,y,t] = data().coord; + assert(isequalwithequalnans(x,lon_ref)) + + assert(isequalwithequalnans(data(1:3:end,:,:),SST_ref(1:3:end,:,:))) + [x,y,t] = data(1:3:end,:,:).coord; + assert(isequalwithequalnans(x,lon_ref(1:3:end,:))) + + + assert(strcmp(SST.units,'degC')) + assert(strcmp(SST.('units'),'degC')) + +end + + +% read compressed data +zname = [tmpfname '.gz']; +system(['gzip --stdout ' tmpfname ' > ' zname]); + +SST = ncData(zname,'SST'); +SST_ref = ncread(tmpfname,'SST'); +assert(isequalwithequalnans(SST(),SST_ref)) + + + +CA2 = ncCatData(3,fullfile(tmpdir,'file*nc'),varname); +SST_test = CA2(:,:,2); +SST_ref = ncread(files{2},'SST'); +assert(isequalwithequalnans(SST_test,SST_ref)) + +disp('All tests passed.') + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 13:41:40
|
Revision: 10662 http://octave.svn.sourceforge.net/octave/?rev=10662&view=rev Author: paramaniac Date: 2012-06-22 13:41:29 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control: use dare directly instead of dlqr Modified Paths: -------------- trunk/octave-forge/main/control/inst/dlqe.m Modified: trunk/octave-forge/main/control/inst/dlqe.m =================================================================== --- trunk/octave-forge/main/control/inst/dlqe.m 2012-06-22 13:09:39 UTC (rev 10661) +++ trunk/octave-forge/main/control/inst/dlqe.m 2012-06-22 13:41:29 UTC (rev 10662) @@ -91,17 +91,17 @@ endif if (isempty (g)) - [~, p, e] = dlqr (a.', c.', q, r, s); # dlqe (a, [], c, q, r, s), g=I + [p, e] = dare (a.', c.', q, r, s); # dlqe (a, [], c, q, r, s), g=I elseif (columns (g) != rows (q) || ! issquare (q)) error ("dlqe: matrices g(%dx%d) and q(%dx%d) have incompatible dimensions", \ rows (g), columns (g), rows (q), columns (q)); elseif (isempty (s)) - [~, p, e] = dlqr (a.', c.', g*q*g.', r); + [p, e] = dare (a.', c.', g*q*g.', r); elseif (columns (g) != rows (s)) error ("dlqe: matrices g(%dx%d) and s(%dx%d) have incompatible dimensions", \ rows (g), columns (g), rows (s), columns (s)); else - [~, p, e] = dlqr (a.', c.', g*q*g.', r, g*s); + [p, e] = dare (a.', c.', g*q*g.', r, g*s); endif m = p*c.' / (c*p*c.' + r); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 13:09:45
|
Revision: 10661 http://octave.svn.sourceforge.net/octave/?rev=10661&view=rev Author: paramaniac Date: 2012-06-22 13:09:39 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: add docstring to moen4 Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/moen4.m Modified: trunk/octave-forge/extra/control-devel/inst/moen4.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-06-22 12:32:09 UTC (rev 10660) +++ trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-06-22 13:09:39 UTC (rev 10661) @@ -23,6 +23,52 @@ ## Combined method: MOESP algorithm for finding the ## matrices A and C, and N4SID algorithm for ## finding the matrices B and D. +## +## @strong{Inputs} +## @table @var +## @item dat +## iddata set containing the measurements. +## @item n +## The desired order of the resulting state-space system @var{sys}. +## If not specified, @var{n} is chosen automatically according +## to the singular values and tolerances. +## @item @dots{} +## Optional pairs of keys and values. @code{'key1', value1, 'key2', value2}. +## @item opt +## Optional struct with keys as field names. +## Struct @var{opt} can be created directly or +## by command @command{options}. @code{opt.key1 = value1, opt.key2 = value2}. +## @end table +## +## +## @strong{Outputs} +## @table @var +## @item sys +## Discrete-time state-space model. +## @item x0 +## Initial state vector. If @var{dat} is a multi-experiment dataset, +## @var{x0} becomes a cell vector containing an initial state vector +## for each experiment. +## @item info +## Struct containing additional information. +## @table @var +## @item info.K +## Kalman gain matrix. +## @item info.Q +## State covariance matrix. +## @item info.Ry +## Output covariance matrix. +## @item info.S +## State-output cross-covariance matrix. +## @item info.L +## Noise variance matrix factor. LL'=Ry. +## @end table +## @end table +## +## @strong{Algorithm}@* +## Uses SLICOT IB01AD, IB01BD and IB01CD by courtesy of +## @uref{http://www.slicot.org, NICONET e.V.} +## ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 12:32:15
|
Revision: 10660 http://octave.svn.sourceforge.net/octave/?rev=10660&view=rev Author: paramaniac Date: 2012-06-22 12:32:09 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: enhance docstrings of iddata methods Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m trunk/octave-forge/extra/control-devel/inst/@iddata/get.m trunk/octave-forge/extra/control-devel/inst/@iddata/ifft.m trunk/octave-forge/extra/control-devel/inst/@iddata/plot.m trunk/octave-forge/extra/control-devel/inst/@iddata/set.m trunk/octave-forge/extra/control-devel/inst/@iddata/size.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{dat} =} fft (@var{dat}) ## @deftypefnx {Function File} {@var{dat} =} fft (@var{dat}, @var{n}) -## Compute the discrete Fourier transform of @var{dat} using a Fast Fourier -## Transform (FFT) algorithm. +## Transform iddata objects from time to frequency domain +## using a Fast Fourier Transform (FFT) algorithm. ## ## @strong{Inputs} ## @table @var Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/get.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/get.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/get.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -16,9 +16,10 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} get (@var{sys}) +## @deftypefn {Function File} get (@var{dat}) ## @deftypefnx {Function File} {@var{value} =} get (@var{dat}, @var{"property"}) ## Access property values of iddata objects. +## Type @command{get(dat)} to display a list of available properties. ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/ifft.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/ifft.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/ifft.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -17,11 +17,26 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{dat} =} ifft (@var{dat}) -## @deftypefnx {Function File} {@var{dat} =} ifft (@var{dat}, @var{ord}) -## Detrend outputs and inputs of dataset @var{dat} by -## removing the best fit of a polynomial of order @var{ord}. -## If @var{ord} is not specified, default value 0 is taken. -## This corresponds to removing a constant. +## Transform iddata objects from frequency to time domain. +## +## @strong{Inputs} +## @table @var +## @item dat +## iddata set containing signals in frequency domain. +## The frequency values must be distributed equally from 0 +## to the Nyquist frequency. The Nyquist frequency is +## only included for even signal lengths. +## @end table +## +## @strong{Outputs} +## @table @var +## @item dat +## iddata identification dataset in time domain. +## In order to preserve signal power and noise level, +## the FFTs are normalized by multiplying each transform +## by the square root of the signal length. +## @end table +## ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/plot.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/plot.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/plot.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -17,7 +17,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} plot (@var{dat}) -## Plot. +## Plot iddata sets. ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/set.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/set.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/set.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -17,10 +17,10 @@ ## -*- texinfo -*- ## @deftypefn {Function File} set (@var{dat}) -## @deftypefnx {Function File} set (@var{retdat}, @var{"property"}, @var{value}, @dots{}) +## @deftypefnx {Function File} set (@var{dat}, @var{"property"}, @var{value}, @dots{}) ## @deftypefnx {Function File} {@var{dat} =} set (@var{dat}, @var{"property"}, @var{value}, @dots{}) ## Set or modify properties of iddata objects. -## If no return argument @var{retdat} is specified, the modified LTI object is stored +## If no return argument @var{dat} is specified, the modified LTI object is stored ## in input argument @var{dat}. @command{set} can handle multiple properties in one call: ## @code{set (dat, 'prop1', val1, 'prop2', val2, 'prop3', val3)}. ## @code{set (dat)} prints a list of the object's property names. Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/size.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/size.m 2012-06-22 11:06:07 UTC (rev 10659) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/size.m 2012-06-22 12:32:09 UTC (rev 10660) @@ -16,15 +16,15 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{nvec} =} size (@var{sys}) -## @deftypefnx {Function File} {@var{n} =} size (@var{sys}, @var{dim}) -## @deftypefnx {Function File} {[@var{n}, @var{p}, @var{m}, @var{ne}] =} size (@var{sys}) -## LTI model size, i.e. number of outputs and inputs. +## @deftypefn {Function File} {@var{nvec} =} size (@var{dat}) +## @deftypefnx {Function File} {@var{ndim} =} size (@var{dat}, @var{dim}) +## @deftypefnx {Function File} {[@var{n}, @var{p}, @var{m}, @var{e}] =} size (@var{dat}) +## Return dimensions of iddata set @var{dat}. ## ## @strong{Inputs} ## @table @var -## @item sys -## LTI system. +## @item dat +## iddata set. ## @item dim ## If given a second argument, @command{size} will return the size of the ## corresponding dimension. @@ -33,14 +33,19 @@ ## @strong{Outputs} ## @table @var ## @item nvec -## Row vector. The first element is the number of outputs (rows) and the second -## element the number of inputs (columns). +## Row vector. The first element is the total number of samples (rows of dat.y and dat.u). +## The second element is the number of outputs (columns of dat.y) and the third element +## the number of inputs (columns of dat.u). The fourth element is the number of experiments. +## @item ndim +## Scalar value. The size of the dimension @var{dim}. ## @item n -## Scalar value. The size of the dimension @var{dim}. +## Row vector containing the number of samples of each experiment. ## @item p ## Number of outputs. ## @item m ## Number of inputs. +## @item e +## Number of experiments. ## @end table ## @end deftypefn This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 11:06:18
|
Revision: 10659 http://octave.svn.sourceforge.net/octave/?rev=10659&view=rev Author: paramaniac Date: 2012-06-22 11:06:07 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: finish doc of fft method Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m 2012-06-22 09:17:22 UTC (rev 10658) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/fft.m 2012-06-22 11:06:07 UTC (rev 10659) @@ -17,11 +17,35 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{dat} =} fft (@var{dat}) -## @deftypefnx {Function File} {@var{dat} =} fft (@var{dat}, @var{ord}) -## Detrend outputs and inputs of dataset @var{dat} by -## removing the best fit of a polynomial of order @var{ord}. -## If @var{ord} is not specified, default value 0 is taken. -## This corresponds to removing a constant. +## @deftypefnx {Function File} {@var{dat} =} fft (@var{dat}, @var{n}) +## Compute the discrete Fourier transform of @var{dat} using a Fast Fourier +## Transform (FFT) algorithm. +## +## @strong{Inputs} +## @table @var +## @item dat +## iddata set containing signals in time-domain. +## @item n +## Length of the FFT transformations. If @var{n} does not match +## the signal length, the signals in @var{dat} are shortened or +## padded with zeros. @var{n} is a vector with as many elements +## as there are experiments in @var{dat} or a scalar with a common +## length for all experiments. +## If not specified, the signal lengths are taken as default values. +## @end table +## +## @strong{Outputs} +## @table @var +## @item dat +## iddata identification dataset in frequency-domain. +## In order to preserve signal power and noise level, +## the FFTs are normalized by dividing each transform +## by the square root of the signal length. +## The frequency values are distributed equally from 0 +## to the Nyquist frequency. The Nyquist frequency is +## only included for even signal lengths. +## @end table +## ## @end deftypefn ## Author: Lukas Reichlin <luk...@gm...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 09:17:33
|
Revision: 10658 http://octave.svn.sourceforge.net/octave/?rev=10658&view=rev Author: paramaniac Date: 2012-06-22 09:17:22 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: add draft code Added Paths: ----------- trunk/octave-forge/extra/control-devel/inst/@iddata/resample.m Added: trunk/octave-forge/extra/control-devel/inst/@iddata/resample.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/resample.m (rev 0) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/resample.m 2012-06-22 09:17:22 UTC (rev 10658) @@ -0,0 +1,40 @@ +## Copyright (C) 2012 Lukas F. Reichlin +## +## This file is part of LTI Syncope. +## +## LTI Syncope is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## LTI Syncope is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{dat} =} diff (@var{dat}) +## @deftypefnx {Function File} {@var{dat} =} diff (@var{dat}, @var{k}) +## Return @var{k}-th difference of outputs and inputs of dataset @var{dat}. +## If @var{k} is not specified, default value 1 is taken. +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: June 2012 +## Version: 0.1 + +function dat = resample (dat, p, q, n = 0) + + if (nargin < 3 || nargin > 4) + print_usage (); + endif + + h = fir1 (n, 1/q); + + dat.y = cellfun (@(y) resample (y, p, q, h), dat.y, "uniformoutput", false); + dat.u = cellfun (@(u) resample (u, p, q, h), dat.u, "uniformoutput", false); + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 09:08:17
|
Revision: 10657 http://octave.svn.sourceforge.net/octave/?rev=10657&view=rev Author: paramaniac Date: 2012-06-22 09:08:11 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control-devel: specify common tsam for all experiments, improve doc Modified Paths: -------------- trunk/octave-forge/extra/control-devel/INDEX trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m Modified: trunk/octave-forge/extra/control-devel/INDEX =================================================================== --- trunk/octave-forge/extra/control-devel/INDEX 2012-06-22 05:34:37 UTC (rev 10656) +++ trunk/octave-forge/extra/control-devel/INDEX 2012-06-22 09:08:11 UTC (rev 10657) @@ -7,13 +7,11 @@ @iddata/diff @iddata/fft @iddata/get - @iddata/horzcat @iddata/ifft @iddata/merge @iddata/plot @iddata/set @iddata/size - @iddata/vertcat System Identification arx fitfrd Modified: trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m 2012-06-22 05:34:37 UTC (rev 10656) +++ trunk/octave-forge/extra/control-devel/inst/@iddata/iddata.m 2012-06-22 09:08:11 UTC (rev 10657) @@ -42,6 +42,10 @@ ## and n(i) the individual number of samples for each experiment. ## @item tsam ## Sampling time. If not specified, default value -1 (unspecified) is taken. +## For multi-experiment data, @var{tsam} becomes a +## e-by-1 or 1-by-e cell vector containing individual +## sampling times for each experiment. If a scalar @var{tsam} +## is provided, then all experiments have the same sampling time. ## @item @dots{} ## Optional pairs of properties and values. ## @end table Modified: trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m 2012-06-22 05:34:37 UTC (rev 10656) +++ trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m 2012-06-22 09:08:11 UTC (rev 10657) @@ -40,9 +40,13 @@ error ("iddata: invalid sampling time"); endif - if (numel (tsam) != e) + nt = numel (tsam); + + if (nt == 1 && e > 1) + tsam = repmat (tsam, e, 1); + elseif (nt != e) error ("iddata: there are %d experiments, but only %d sampling times", \ - e, numel (tsam)); + e, nt); endif endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-22 05:34:44
|
Revision: 10656 http://octave.svn.sourceforge.net/octave/?rev=10656&view=rev Author: paramaniac Date: 2012-06-22 05:34:37 +0000 (Fri, 22 Jun 2012) Log Message: ----------- control: rename a variable in dlqe Modified Paths: -------------- trunk/octave-forge/main/control/inst/dlqe.m Modified: trunk/octave-forge/main/control/inst/dlqe.m =================================================================== --- trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 23:13:45 UTC (rev 10655) +++ trunk/octave-forge/main/control/inst/dlqe.m 2012-06-22 05:34:37 UTC (rev 10656) @@ -17,10 +17,10 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefn {Function File} {[@var{m}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{m}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefnx {Function File} {[@var{m}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{m}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) ## Kalman filter for discrete-time systems. ## ## @example @@ -50,7 +50,7 @@ ## ## @strong{Outputs} ## @table @var -## @item l +## @item m ## Kalman filter gain matrix (n-by-p). ## @item p ## Unique stabilizing solution of the discrete-time Riccati equation (n-by-n). @@ -64,16 +64,16 @@ ## @strong{Equations} ## @example ## @group -## x[k|k] = x[k|k-1] + L(y[k] - Cx[k|k-1] -Du[k]) +## x[k|k] = x[k|k-1] + M(y[k] - Cx[k|k-1] - Du[k]) ## ## x[k+1|k] = Ax[k|k] + Bu[k] for S=0 ## ## x[k+1|k] = Ax[k|k] + Bu[k] + G*S*(C*P*C' + R)^-1*(y[k] - C*x[k|k-1]) for non-zero S ## ## -## E = eig(A - A*L*C) for S=0 +## E = eig(A - A*M*C) for S=0 ## -## E = eig(A - A*L*C - G*S*(C*P*C' + Rv)^-1*C) for non-zero S +## E = eig(A - A*M*C - G*S*(C*P*C' + Rv)^-1*C) for non-zero S ## ## @end group ## @end example @@ -84,7 +84,7 @@ ## Created: April 2012 ## Version: 0.1 -function [l, p, z, e] = dlqe (a, g, c, q, r, s = []) +function [m, p, z, e] = dlqe (a, g, c, q, r, s = []) if (nargin < 5 || nargin > 6) print_usage (); @@ -104,8 +104,9 @@ [~, p, e] = dlqr (a.', c.', g*q*g.', r, g*s); endif - l = p*c.' / (c*p*c.' + r); + m = p*c.' / (c*p*c.' + r); - z = p - l*c*p; + z = p - m*c*p; + z = (z + z.') / 2; endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-06-21 23:13:51
|
Revision: 10655 http://octave.svn.sourceforge.net/octave/?rev=10655&view=rev Author: benjf5 Date: 2012-06-21 23:13:45 +0000 (Thu, 21 Jun 2012) Log Message: ----------- Added documentation to fastlsreal. Modified Paths: -------------- trunk/octave-forge/extra/lssa/fastlsreal.cc Modified: trunk/octave-forge/extra/lssa/fastlsreal.cc =================================================================== --- trunk/octave-forge/extra/lssa/fastlsreal.cc 2012-06-21 11:26:26 UTC (rev 10654) +++ trunk/octave-forge/extra/lssa/fastlsreal.cc 2012-06-21 23:13:45 UTC (rev 10655) @@ -15,7 +15,16 @@ double maxfreq , int octaves , int coefficients); -DEFUN_DLD(fastlsreal,args,nargout, "fastlsreal(time,magnitude,maximum_frequency,octaves,coefficients)") { +DEFUN_DLD(fastlsreal,args,nargout, + "-*- texinfo -*-\n\ +@deftypefn {Function File} { C = } fastlsreal(@var{time},@var{magnitude},@var{maximum_frequency},@var{octaves},@var{coefficients})\n\ +\n\ +Return the real least-sqaures spectral fit to the (@var{time},@var{magnitude})\n\ +data supplied, using the fast algorithm.\n\ +\n\ +@seealso{fastlscomplex}\n\ +@seealso{lsreal}\n\ +@end deftypefn") { if ( args.length() != 5 ) { print_usage(); return octave_value_list (); @@ -37,7 +46,7 @@ if ( omegamax == 0 ) error("No difference between minimal and maximal frequency."); octave_value_list retval; if ( !error_state) { - ComplexRowVector results = flscomplex(tvals,xvals,omegamax,noctaves,ncoeff); + ComplexRowVector results = flsreal(tvals,xvals,omegamax,noctaves,ncoeff); retval(0) = octave_value(results); } else { return octave_value_list (); @@ -224,11 +233,11 @@ zeta_real_part_accumulator += z_accumulator.real(); zeta_imag_part_accumulator += z_accumulator.imag(); } - zeta_real_part = zeta_real_part + ( zeta_exp_term.real() * zeta_real_part_accumulator - zeta_exp_term.imag() * zeta_imag_part_accumulator ) ); + zeta_real_part = zeta_real_part + ( zeta_exp_term.real() * zeta_real_part_accumulator - zeta_exp_term.imag() * zeta_imag_part_accumulator ); zeta_imag_part = zeta_imag_part + ( zeta_exp_term.imag() * zeta_real_part_accumulator + zeta_exp_term.real() * zeta_imag_part_accumulator ); } for ( iota_record_current = iota_precomp_records_head; iota_record_current ; - iota_record_current = iota_record_current->next, iota_exp_term = iota_exp_term_multiplier ) { + iota_record_current = iota_record_current->next, iota_exp_term = iota_exp_multiplier ) { for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { i_accumulator = ( pow(omega_working,array_iter) * iota_record_current->power_series[array_iter] ); iota_real_part_accumulator += i_accumulator.real(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-21 11:26:33
|
Revision: 10654 http://octave.svn.sourceforge.net/octave/?rev=10654&view=rev Author: paramaniac Date: 2012-06-21 11:26:26 +0000 (Thu, 21 Jun 2012) Log Message: ----------- control: doc fixes Modified Paths: -------------- trunk/octave-forge/main/control/inst/dlqe.m trunk/octave-forge/main/control/inst/lqe.m Modified: trunk/octave-forge/main/control/inst/dlqe.m =================================================================== --- trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 09:21:55 UTC (rev 10653) +++ trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 11:26:26 UTC (rev 10654) @@ -17,10 +17,10 @@ ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefn {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} dlqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) ## Kalman filter for discrete-time systems. ## ## @example @@ -33,8 +33,6 @@ ## ## @strong{Inputs} ## @table @var -## @item sys -## Continuous or discrete-time LTI model (p-by-m, n states). ## @item a ## State transition matrix of discrete-time system (n-by-n). ## @item g @@ -46,7 +44,8 @@ ## @item r ## Measurement noise covariance matrix (p-by-p). ## @item s -## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. +## Optional cross term covariance matrix (g-by-p), s = cov(w,v). +## If @var{s} is not specified, a zero matrix is assumed. ## @end table ## ## @strong{Outputs} @@ -55,6 +54,7 @@ ## Kalman filter gain matrix (n-by-p). ## @item p ## Unique stabilizing solution of the discrete-time Riccati equation (n-by-n). +## Symmetric matrix. ## @item z ## Error covariance (n-by-n), cov(x(k|k)-x) ## @item e Modified: trunk/octave-forge/main/control/inst/lqe.m =================================================================== --- trunk/octave-forge/main/control/inst/lqe.m 2012-06-21 09:21:55 UTC (rev 10653) +++ trunk/octave-forge/main/control/inst/lqe.m 2012-06-21 11:26:26 UTC (rev 10654) @@ -49,7 +49,8 @@ ## @item r ## Measurement noise covariance matrix (p-by-p). ## @item s -## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. +## Optional cross term covariance matrix (g-by-p), s = cov(w,v). +## If @var{s} is not specified, a zero matrix is assumed. ## @end table ## ## @strong{Outputs} @@ -58,6 +59,8 @@ ## Kalman filter gain matrix (n-by-p). ## @item p ## Unique stabilizing solution of the continuous-time Riccati equation (n-by-n). +## Symmetric matrix. If @var{sys} is a discrete-time model, the solution of the +## corresponding discrete-time Riccati equation is returned. ## @item e ## Closed-loop poles (n-by-1). ## @end table @@ -102,5 +105,8 @@ endif l = l.'; + + ## NOTE: for discrete-time sys, the solution L' from DARE + ## is different to L from DLQE (a, s) endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pau...@us...> - 2012-06-21 09:22:07
|
Revision: 10653 http://octave.svn.sourceforge.net/octave/?rev=10653&view=rev Author: pauldreik Date: 2012-06-21 09:21:55 +0000 (Thu, 21 Jun 2012) Log Message: ----------- release version 1.0.8 Maintainer changed to Paul Dreik Modified Paths: -------------- trunk/octave-forge/main/sockets/DESCRIPTION trunk/octave-forge/main/sockets/NEWS Modified: trunk/octave-forge/main/sockets/DESCRIPTION =================================================================== --- trunk/octave-forge/main/sockets/DESCRIPTION 2012-06-21 09:12:15 UTC (rev 10652) +++ trunk/octave-forge/main/sockets/DESCRIPTION 2012-06-21 09:21:55 UTC (rev 10653) @@ -1,12 +1,12 @@ Name: sockets -Version: 1.0.7 -Date: 2011-03-03 +Version: 1.0.8 +Date: 2012-06-22 Author: John Swensen <jps...@co...> -Maintainer: Tom Holroyd <to...@ku...> +Maintainer: Paul Dreik <sl...@pa...> Title: Sockets Description: Socket functions for networking from within octave. Categories: Sockets Depends: octave (>= 2.9.10) Autoload: no License: GPLv3+ -Url: http://octave.sf.net +Url: http://octave.sourceforge.net Modified: trunk/octave-forge/main/sockets/NEWS =================================================================== --- trunk/octave-forge/main/sockets/NEWS 2012-06-21 09:12:15 UTC (rev 10652) +++ trunk/octave-forge/main/sockets/NEWS 2012-06-21 09:21:55 UTC (rev 10653) @@ -1,4 +1,4 @@ -Summary of important user-visible changes for sockets 1.X.X: +Summary of important user-visible changes for sockets 1.0.8: ------------------------------------------------------------------- - ** + ** updated function documentation with more details This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pau...@us...> - 2012-06-21 09:12:26
|
Revision: 10652 http://octave.svn.sourceforge.net/octave/?rev=10652&view=rev Author: pauldreik Date: 2012-06-21 09:12:15 +0000 (Thu, 21 Jun 2012) Log Message: ----------- update of documentation strings Modified Paths: -------------- trunk/octave-forge/main/sockets/src/sockets.cc Modified: trunk/octave-forge/main/sockets/src/sockets.cc =================================================================== --- trunk/octave-forge/main/sockets/src/sockets.cc 2012-06-21 08:51:48 UTC (rev 10651) +++ trunk/octave-forge/main/sockets/src/sockets.cc 2012-06-21 09:12:15 UTC (rev 10652) @@ -340,7 +340,7 @@ // Function to create a socket DEFUN_DLD(socket,args,nargout, "s=socket(domain,type,protocol)\n" - "Creates a socket. Domain is an integer, where the value AF_INET\n" + "Creates a socket s. Domain is an integer, where the value AF_INET\n" "can be used to create an IPv4 socket.\n" "type is an integer describing the socket. When using IP, specifying " "SOCK_STREAM gives a TCP socket.\n" @@ -348,7 +348,7 @@ "\n" "If no input arguments are given, default values AF_INET and \n" "SOCK_STREAM are used.\n" - "See the local socket() reference for more details\n") + "See the local socket() reference for more details.\n") { int domain = AF_INET; int type = SOCK_STREAM; @@ -407,14 +407,14 @@ // PKG_ADD: autoload ("connect", "sockets.oct"); // function to create an outgoing connection DEFUN_DLD(connect,args,nargout, \ - "status=connect(sock,serverinfo)\n" - "Connects the socket given in sock following the information\n" - "given in the struct serverinfo\n" + "status=connect(s,serverinfo)\n" + "Connects the socket s following the information\n" + "in the struct serverinfo.\n" "serverinfo shall contain the following fields:\n" " addr - a string with the host name to connect to\n" " port - the port number to connect to (an integer)\n" "\n" - "On successful connect, zero is returned in status.\n" + "On successful connect, the returned status is zero.\n" "\n" "See the connect() man pages for further details.\n") { @@ -422,9 +422,9 @@ struct sockaddr_in serverInfo; struct hostent* hostInfo; - if ( args.length() < 2 ) + if ( args.length() != 2 ) { - error("connect: you must specify 2 paramters"); + error("connect: you must specify 2 parameters."); return octave_value(-1); } @@ -444,7 +444,7 @@ } else { - error ("connect: invalid input: no 'addr' field"); + error ("connect: invalid input: no 'addr' field in serverinfo."); return octave_value (-1); } @@ -456,7 +456,7 @@ } else { - error ("connect: invalid input: no 'port' field"); + error ("connect: invalid input: no 'port' field in serverinfo."); return octave_value (-1); } #endif @@ -476,7 +476,7 @@ } else { - error("connect: expecting a octave_socket or integer"); + error("connect: expecting an octave_socket or integer"); return octave_value(-1); } @@ -510,8 +510,10 @@ // PKG_ADD: autoload ("disconnect", "sockets.oct"); // function to disconnect asocket DEFUN_DLD(disconnect,args,nargout, \ - "disconnect(octave_socket)\n" - "Since we can't call fclose on the fd directly, use this to disconnect") + "disconnect(s)\n" + "Disconnects the socket s.\n" + "Since we can't call fclose on the file descriptor directly,\n" + "use this function to disconnect the socket.") { // Determine the socket on which to operate octave_socket* s = NULL; @@ -527,7 +529,7 @@ } else { - error("connect: expecting a octave_socket or integer"); + error("connect: expecting an octave_socket or integer"); return octave_value(-1); } @@ -540,8 +542,13 @@ // PKG_ADD: autoload ("gethostbyname", "sockets.oct"); // function to get a host number from a host name DEFUN_DLD(gethostbyname,args,nargout, \ - "gethostbyname(string)\n" - "See the gethostbyname() man pages") + "addr=gethostbyname(hostname)\n" + "Returns an IP adress addr for a host name.\n" + "Example:\n" + "addr=gethostbyname('localhost')\n" + "addr = 127.0.0.1\n" + "\n" + "See the gethostbyname() man pages for details.") { int nargin = args.length (); struct hostent* hostInfo = NULL; @@ -573,16 +580,17 @@ // PKG_ADD: autoload ("send", "sockets.oct"); // function to send data over a socket DEFUN_DLD(send,args,nargout, \ - "send(octave_socket,octave_value,flags)\n" - "See the send() man pages. This will only allow the\n" - "user to send uint8 arrays or strings\n") + "send(s,data,flags)\n" + "Sends data on socket s. data should be an uint8 array or\n" + "a string.\n" + "See the send() man pages for further details.\n") { int retval = 0; int flags = 0; if ( args.length() < 2 ) { - error( "send: you must specify 2 parameters"); + error( "send: you must specify two or more parameters"); return octave_value(-1); } @@ -604,7 +612,7 @@ } else { - error("connect: expecting a octave_socket or integer"); + error("connect: expecting an octave_socket or integer"); return octave_value(-1); } @@ -636,8 +644,8 @@ // PKG_ADD: autoload ("recv", "sockets.oct"); // function to receive data over a socket DEFUN_DLD(recv,args,nargout, \ - "[data,count]=recv(sock,len,flags)\n" - "Requests reading len bytes from the socket given in sock.\n" + "[data,count]=recv(s,len,flags)\n" + "Requests reading len bytes from the socket s.\n" "The integer flags parameter can be used to modify the behaviour\n" "of recv.\n" "\n" @@ -645,7 +653,7 @@ "bytes read is returned in count\n" "\n" "You can get non-blocking operation by using the flag MSG_DONTWAIT\n" - "which makes the recv() call return immediately. If there is no\n" + "which makes the recv() call return immediately. If there are no\n" "data, -1 is returned.\n" "See the recv() man pages for further details.\n") { @@ -675,7 +683,7 @@ } else { - error("recv: expecting a octave_socket or integer"); + error("recv: expecting an octave_socket or integer"); return octave_value(-1); } @@ -722,12 +730,12 @@ // PKG_ADD: autoload ("bind", "sockets.oct"); // function to bind a socket DEFUN_DLD(bind,args,nargout, \ - "bind(octave_socket,int)\n" - "See the bind() man pages. This will bind a socket to a" \ - " specific port\n") + "bind(s,portnumber)\n" + "binds the sockets to port portnumber.\n" + "See the bind() man pages for further details.\n") { int retval = 0; - if ( args.length() < 2 ) + if ( args.length() != 2 ) { error( "bind: you must specify 2 parameters" ); return octave_value(-1); @@ -747,7 +755,7 @@ } else { - error("connect: expecting a octave_socket or integer"); + error("connect: expecting an octave_socket or integer"); return octave_value(-1); } @@ -767,11 +775,15 @@ // PKG_ADD: autoload ("listen", "sockets.oct"); // function to listen on a socket DEFUN_DLD(listen,args,nargout, \ - "listen(octave_socket,int)\n" - "See the listen() man pages\n") + "r=listen(s,backlog)\n" + "Listens on socket s for connections. backlog specifies\n" + "how large the queue of incoming connections is allowed to\n" + "grow.\n" + "On success, zero is returned.\n" + "See the listen() man pages for details.\n") { int retval = 0; - if ( args.length() < 2 ) + if ( args.length() != 2 ) { error( "listen: you must specify 2 parameters" ); return octave_value(-1); @@ -791,7 +803,7 @@ } else { - error("connect: expecting a octave_socket or integer"); + error("connect: expecting an octave_socket or integer"); return octave_value(-1); } @@ -807,8 +819,11 @@ // PKG_ADD: autoload ("accept", "sockets.oct"); // function to accept on a listening socket DEFUN_DLD(accept,args,nargout, \ - "accept(octave_socket)\n" - "See the accept() man pages\n") + "[client,info]=accept(s)\n" + "Accepts an incoming connection on the socket s.\n" + "The newly created socket is returned in client, and\n" + "associated information in a struct info.\n" + "See the accept() man pages for details.\n") { int retval = 0; struct sockaddr_in clientInfo; @@ -834,7 +849,7 @@ } else { - error("accept: expecting a octave_socket or integer"); + error("accept: expecting an octave_socket or integer"); return octave_value(-1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pau...@us...> - 2012-06-21 08:51:57
|
Revision: 10651 http://octave.svn.sourceforge.net/octave/?rev=10651&view=rev Author: pauldreik Date: 2012-06-21 08:51:48 +0000 (Thu, 21 Jun 2012) Log Message: ----------- minor change to build with gcc 4.7 Modified Paths: -------------- trunk/octave-forge/main/sockets/src/sockets.cc Modified: trunk/octave-forge/main/sockets/src/sockets.cc =================================================================== --- trunk/octave-forge/main/sockets/src/sockets.cc 2012-06-21 07:41:04 UTC (rev 10650) +++ trunk/octave-forge/main/sockets/src/sockets.cc 2012-06-21 08:51:48 UTC (rev 10651) @@ -50,9 +50,7 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> -#ifdef __CYGWIN__ #include <unistd.h> -#endif #else typedef unsigned int socklen_t; #include <winsock2.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-21 07:41:15
|
Revision: 10650 http://octave.svn.sourceforge.net/octave/?rev=10650&view=rev Author: paramaniac Date: 2012-06-21 07:41:04 +0000 (Thu, 21 Jun 2012) Log Message: ----------- control: test dimensions that are impossible to handle by subsequent lqr/dlqr calls, use lqe in example "Anderson" Modified Paths: -------------- trunk/octave-forge/main/control/inst/Anderson.m trunk/octave-forge/main/control/inst/dlqe.m trunk/octave-forge/main/control/inst/lqe.m Modified: trunk/octave-forge/main/control/inst/Anderson.m =================================================================== --- trunk/octave-forge/main/control/inst/Anderson.m 2012-06-21 07:16:50 UTC (rev 10649) +++ trunk/octave-forge/main/control/inst/Anderson.m 2012-06-21 07:41:04 UTC (rev 10650) @@ -47,7 +47,7 @@ V = 1; F = lqr (G, Q, R) -L = lqr (G.', W, V).' +L = lqe (G, W, V) % Coprime Factorization using Balanced Truncation Approximation figure (1) Modified: trunk/octave-forge/main/control/inst/dlqe.m =================================================================== --- trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 07:16:50 UTC (rev 10649) +++ trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 07:41:04 UTC (rev 10650) @@ -92,8 +92,14 @@ if (isempty (g)) [~, p, e] = dlqr (a.', c.', q, r, s); # dlqe (a, [], c, q, r, s), g=I + elseif (columns (g) != rows (q) || ! issquare (q)) + error ("dlqe: matrices g(%dx%d) and q(%dx%d) have incompatible dimensions", \ + rows (g), columns (g), rows (q), columns (q)); elseif (isempty (s)) [~, p, e] = dlqr (a.', c.', g*q*g.', r); + elseif (columns (g) != rows (s)) + error ("dlqe: matrices g(%dx%d) and s(%dx%d) have incompatible dimensions", \ + rows (g), columns (g), rows (s), columns (s)); else [~, p, e] = dlqr (a.', c.', g*q*g.', r, g*s); endif Modified: trunk/octave-forge/main/control/inst/lqe.m =================================================================== --- trunk/octave-forge/main/control/inst/lqe.m 2012-06-21 07:16:50 UTC (rev 10649) +++ trunk/octave-forge/main/control/inst/lqe.m 2012-06-21 07:41:04 UTC (rev 10650) @@ -89,8 +89,14 @@ [l, p, e] = lqr (a.', g, c, q); # lqe (sys, q, r, s), g=I, works like lqr (sys.', q, r, s).' elseif (isempty (g)) [l, p, e] = lqr (a.', c.', q, r, s); # lqe (a, [], c, q, r, s), g=I, works like lqr (a.', c.', q, r, s).' + elseif (columns (g) != rows (q) || ! issquare (q)) + error ("lqe: matrices g(%dx%d) and q(%dx%d) have incompatible dimensions", \ + rows (g), columns (g), rows (q), columns (q)); elseif (isempty (s)) [l, p, e] = lqr (a.', c.', g*q*g.', r); + elseif (columns (g) != rows (s)) + error ("lqe: matrices g(%dx%d) and s(%dx%d) have incompatible dimensions", \ + rows (g), columns (g), rows (s), columns (s)); else [l, p, e] = lqr (a.', c.', g*q*g.', r, g*s); endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-06-21 07:17:01
|
Revision: 10649 http://octave.svn.sourceforge.net/octave/?rev=10649&view=rev Author: paramaniac Date: 2012-06-21 07:16:50 +0000 (Thu, 21 Jun 2012) Log Message: ----------- control: move completed functions into place Modified Paths: -------------- trunk/octave-forge/main/control/INDEX trunk/octave-forge/main/control/NEWS Added Paths: ----------- trunk/octave-forge/main/control/inst/dlqe.m trunk/octave-forge/main/control/inst/lqe.m Removed Paths: ------------- trunk/octave-forge/main/control/devel/dlqe.m trunk/octave-forge/main/control/devel/lqe.m Modified: trunk/octave-forge/main/control/INDEX =================================================================== --- trunk/octave-forge/main/control/INDEX 2012-06-21 07:08:29 UTC (rev 10648) +++ trunk/octave-forge/main/control/INDEX 2012-06-21 07:16:50 UTC (rev 10649) @@ -78,9 +78,11 @@ place rlocus Linear-Quadratic Control + dlqe dlqr estim kalman + lqe lqr Robust Control augw Modified: trunk/octave-forge/main/control/NEWS =================================================================== --- trunk/octave-forge/main/control/NEWS 2012-06-21 07:08:29 UTC (rev 10648) +++ trunk/octave-forge/main/control/NEWS 2012-06-21 07:16:50 UTC (rev 10649) @@ -7,8 +7,12 @@ ** Fixed a silly mistake in MIMO transfer function to state-space conversion. The bug has been introduced with control-2.3.51. (Thanks to Jim Rawlings for providing the test case) - +** dlqe, lqe + Added new functions for linear quadratic estimators. + (Thanks to Megan Zagrobelny) + + =============================================================================== control-2.3.51 Release Date: 2012-06-03 Release Manager: Lukas Reichlin =============================================================================== Deleted: trunk/octave-forge/main/control/devel/dlqe.m =================================================================== --- trunk/octave-forge/main/control/devel/dlqe.m 2012-06-21 07:08:29 UTC (rev 10648) +++ trunk/octave-forge/main/control/devel/dlqe.m 2012-06-21 07:16:50 UTC (rev 10649) @@ -1,105 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## Copyright (C) 2012 Megan Zagrobelny -## -## This file is part of LTI Syncope. -## -## LTI Syncope is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## LTI Syncope is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) -## Kalman filter for discrete-time systems. -## -## @example -## @group -## x[k] = Ax[k] + Bu[k] + Gw[k] (State equation) -## y[k] = Cx[k] + Du[k] + v[k] (Measurement Equation) -## E(w) = 0, E(v) = 0, cov(w) = Q, cov(v) = R, cov(w,v) = S -## @end group -## @end example -## -## @strong{Inputs} -## @table @var -## @item sys -## Continuous or discrete-time LTI model (p-by-m, n states). -## @item a -## State transition matrix of discrete-time system (n-by-n). -## @item g -## Process noise matrix of discrete-time system (n-by-g). -## @item c -## Measurement matrix of discrete-time system (p-by-n). -## @item q -## Process noise covariance matrix (g-by-g). -## @item r -## Measurement noise covariance matrix (p-by-p). -## @item s -## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. -## @end table -## -## @strong{Outputs} -## @table @var -## @item l -## Kalman filter gain matrix (n-by-p). -## @item p -## Unique stabilizing solution of the discrete-time Riccati equation (n-by-n). -## @item z -## Error covariance (n-by-n), cov(x(k|k)-x) -## @item e -## Closed-loop poles (n-by-1). -## @end table -## -## @strong{Equations} -## @example -## @group -## x[k|k] = x[k|k-1] + L(y[k] - Cx[k|k-1] -Du[k]) -## -## x[k+1|k] = Ax[k|k] + Bu[k] for S=0 -## -## x[k+1|k] = Ax[k|k] + Bu[k] + G*S*(C*P*C' + R)^-1*(y[k] - C*x[k|k-1]) for non-zero S -## -## -## E = eig(A - A*L*C) for S=0 -## -## E = eig(A - A*L*C - G*S*(C*P*C' + Rv)^-1*C) for non-zero S -## -## @end group -## @end example -## @seealso{dare, care, dlqr, lqr, lqe} -## @end deftypefn - -## Author: Lukas Reichlin <luk...@gm...> -## Created: April 2012 -## Version: 0.1 - -function [l, p, z, e] = dlqe (a, g, c, q, r, s = []) - - if (nargin < 5 || nargin > 6) - print_usage (); - endif - - if (isempty (g)) - [~, p, e] = dlqr (a.', c.', q, r, s); # dlqe (a, [], c, q, r, s), g=I - elseif (isempty (s)) - [~, p, e] = dlqr (a.', c.', g*q*g.', r); - else - [~, p, e] = dlqr (a.', c.', g*q*g.', r, g*s); - endif - - l = p*c.' / (c*p*c.' + r); - - z = p - l*c*p; - -endfunction Deleted: trunk/octave-forge/main/control/devel/lqe.m =================================================================== --- trunk/octave-forge/main/control/devel/lqe.m 2012-06-21 07:08:29 UTC (rev 10648) +++ trunk/octave-forge/main/control/devel/lqe.m 2012-06-21 07:16:50 UTC (rev 10649) @@ -1,100 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## Copyright (C) 2012 Megan Zagrobelny -## -## This file is part of LTI Syncope. -## -## LTI Syncope is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## LTI Syncope is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r}, @var{s}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) -## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) -## Kalman filter for continuous-time systems. -## -## @example -## @group -## . -## x = Ax + Bu + Gw (State equation) -## y = Cx + Du + v (Measurement Equation) -## E(w) = 0, E(v) = 0, cov(w) = Q, cov(v) = R, cov(w,v) = S -## @end group -## @end example -## -## @strong{Inputs} -## @table @var -## @item sys -## Continuous or discrete-time LTI model (p-by-m, n states). -## @item a -## State transition matrix of continuous-time system (n-by-n). -## @item g -## Process noise matrix of continuous-time system (n-by-g). -## @item c -## Measurement matrix of continuous-time system (p-by-n). -## @item q -## Process noise covariance matrix (g-by-g). -## @item r -## Measurement noise covariance matrix (p-by-p). -## @item s -## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. -## @end table -## -## @strong{Outputs} -## @table @var -## @item l -## Kalman filter gain matrix (n-by-p). -## @item p -## Unique stabilizing solution of the continuous-time Riccati equation (n-by-n). -## @item e -## Closed-loop poles (n-by-1). -## @end table -## -## @strong{Equations} -## @example -## @group -## . -## x = Ax + Bu + L(y - Cx -Du) -## -## E = eig(A - L*C) -## -## @end group -## @end example -## @seealso{dare, care, dlqr, lqr, dlqe} -## @end deftypefn - -## Author: Lukas Reichlin <luk...@gm...> -## Created: April 2012 -## Version: 0.1 - -function [l, p, e] = lqe (a, g, c, q = [], r = [], s = []) - - if (nargin < 3 || nargin > 6) - print_usage (); - endif - - if (isa (a, "lti")) - [l, p, e] = lqr (a.', g, c, q); # lqe (sys, q, r, s), g=I, works like lqr (sys.', q, r, s).' - elseif (isempty (g)) - [l, p, e] = lqr (a.', c.', q, r, s); # lqe (a, [], c, q, r, s), g=I, works like lqr (a.', c.', q, r, s).' - elseif (isempty (s)) - [l, p, e] = lqr (a.', c.', g*q*g.', r); - else - [l, p, e] = lqr (a.', c.', g*q*g.', r, g*s); - endif - - l = l.'; - -endfunction Copied: trunk/octave-forge/main/control/inst/dlqe.m (from rev 10648, trunk/octave-forge/main/control/devel/dlqe.m) =================================================================== --- trunk/octave-forge/main/control/inst/dlqe.m (rev 0) +++ trunk/octave-forge/main/control/inst/dlqe.m 2012-06-21 07:16:50 UTC (rev 10649) @@ -0,0 +1,105 @@ +## Copyright (C) 2012 Lukas F. Reichlin +## Copyright (C) 2012 Megan Zagrobelny +## +## This file is part of LTI Syncope. +## +## LTI Syncope is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## LTI Syncope is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{z}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) +## Kalman filter for discrete-time systems. +## +## @example +## @group +## x[k] = Ax[k] + Bu[k] + Gw[k] (State equation) +## y[k] = Cx[k] + Du[k] + v[k] (Measurement Equation) +## E(w) = 0, E(v) = 0, cov(w) = Q, cov(v) = R, cov(w,v) = S +## @end group +## @end example +## +## @strong{Inputs} +## @table @var +## @item sys +## Continuous or discrete-time LTI model (p-by-m, n states). +## @item a +## State transition matrix of discrete-time system (n-by-n). +## @item g +## Process noise matrix of discrete-time system (n-by-g). +## @item c +## Measurement matrix of discrete-time system (p-by-n). +## @item q +## Process noise covariance matrix (g-by-g). +## @item r +## Measurement noise covariance matrix (p-by-p). +## @item s +## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. +## @end table +## +## @strong{Outputs} +## @table @var +## @item l +## Kalman filter gain matrix (n-by-p). +## @item p +## Unique stabilizing solution of the discrete-time Riccati equation (n-by-n). +## @item z +## Error covariance (n-by-n), cov(x(k|k)-x) +## @item e +## Closed-loop poles (n-by-1). +## @end table +## +## @strong{Equations} +## @example +## @group +## x[k|k] = x[k|k-1] + L(y[k] - Cx[k|k-1] -Du[k]) +## +## x[k+1|k] = Ax[k|k] + Bu[k] for S=0 +## +## x[k+1|k] = Ax[k|k] + Bu[k] + G*S*(C*P*C' + R)^-1*(y[k] - C*x[k|k-1]) for non-zero S +## +## +## E = eig(A - A*L*C) for S=0 +## +## E = eig(A - A*L*C - G*S*(C*P*C' + Rv)^-1*C) for non-zero S +## +## @end group +## @end example +## @seealso{dare, care, dlqr, lqr, lqe} +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: April 2012 +## Version: 0.1 + +function [l, p, z, e] = dlqe (a, g, c, q, r, s = []) + + if (nargin < 5 || nargin > 6) + print_usage (); + endif + + if (isempty (g)) + [~, p, e] = dlqr (a.', c.', q, r, s); # dlqe (a, [], c, q, r, s), g=I + elseif (isempty (s)) + [~, p, e] = dlqr (a.', c.', g*q*g.', r); + else + [~, p, e] = dlqr (a.', c.', g*q*g.', r, g*s); + endif + + l = p*c.' / (c*p*c.' + r); + + z = p - l*c*p; + +endfunction Copied: trunk/octave-forge/main/control/inst/lqe.m (from rev 10648, trunk/octave-forge/main/control/devel/lqe.m) =================================================================== --- trunk/octave-forge/main/control/inst/lqe.m (rev 0) +++ trunk/octave-forge/main/control/inst/lqe.m 2012-06-21 07:16:50 UTC (rev 10649) @@ -0,0 +1,100 @@ +## Copyright (C) 2012 Lukas F. Reichlin +## Copyright (C) 2012 Megan Zagrobelny +## +## This file is part of LTI Syncope. +## +## LTI Syncope is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## LTI Syncope is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{sys}, @var{q}, @var{r}, @var{s}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{g}, @var{c}, @var{q}, @var{r}, @var{s}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}) +## @deftypefnx {Function File} {[@var{l}, @var{p}, @var{e}] =} lqe (@var{a}, @var{[]}, @var{c}, @var{q}, @var{r}, @var{s}) +## Kalman filter for continuous-time systems. +## +## @example +## @group +## . +## x = Ax + Bu + Gw (State equation) +## y = Cx + Du + v (Measurement Equation) +## E(w) = 0, E(v) = 0, cov(w) = Q, cov(v) = R, cov(w,v) = S +## @end group +## @end example +## +## @strong{Inputs} +## @table @var +## @item sys +## Continuous or discrete-time LTI model (p-by-m, n states). +## @item a +## State transition matrix of continuous-time system (n-by-n). +## @item g +## Process noise matrix of continuous-time system (n-by-g). +## @item c +## Measurement matrix of continuous-time system (p-by-n). +## @item q +## Process noise covariance matrix (g-by-g). +## @item r +## Measurement noise covariance matrix (p-by-p). +## @item s +## Optional cross term covariance matrix (g-by-p), s = cov(w,v) If @var{s} is not specified, a zero matrix is assumed. +## @end table +## +## @strong{Outputs} +## @table @var +## @item l +## Kalman filter gain matrix (n-by-p). +## @item p +## Unique stabilizing solution of the continuous-time Riccati equation (n-by-n). +## @item e +## Closed-loop poles (n-by-1). +## @end table +## +## @strong{Equations} +## @example +## @group +## . +## x = Ax + Bu + L(y - Cx -Du) +## +## E = eig(A - L*C) +## +## @end group +## @end example +## @seealso{dare, care, dlqr, lqr, dlqe} +## @end deftypefn + +## Author: Lukas Reichlin <luk...@gm...> +## Created: April 2012 +## Version: 0.1 + +function [l, p, e] = lqe (a, g, c, q = [], r = [], s = []) + + if (nargin < 3 || nargin > 6) + print_usage (); + endif + + if (isa (a, "lti")) + [l, p, e] = lqr (a.', g, c, q); # lqe (sys, q, r, s), g=I, works like lqr (sys.', q, r, s).' + elseif (isempty (g)) + [l, p, e] = lqr (a.', c.', q, r, s); # lqe (a, [], c, q, r, s), g=I, works like lqr (a.', c.', q, r, s).' + elseif (isempty (s)) + [l, p, e] = lqr (a.', c.', g*q*g.', r); + else + [l, p, e] = lqr (a.', c.', g*q*g.', r, g*s); + endif + + l = l.'; + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |