From b3f132c866fcdf11203bbd948e149f8edf517dac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Thu, 15 May 2014 12:31:53 +0200
Subject: [PATCH] Various optimizations and cosmetic changes.

---
 matlab/@dates/dates.m               | 6 +++---
 matlab/@dates/subsref.m             | 6 +++---
 matlab/utilities/dates/isdate.m     | 8 ++++----
 matlab/utilities/dates/ismonthly.m  | 6 +++++-
 matlab/utilities/dates/isquaterly.m | 8 ++++++--
 matlab/utilities/dates/isweekly.m   | 6 +++++-
 matlab/utilities/dates/isyearly.m   | 6 +++++-
 7 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/matlab/@dates/dates.m b/matlab/@dates/dates.m
index 5df103424a..c442b4bb2b 100644
--- a/matlab/@dates/dates.m
+++ b/matlab/@dates/dates.m
@@ -110,7 +110,7 @@ switch nargin
         dd = subsref(dd,S);
         return
     else
-        error(['dates::dates: Wrong calling sequence!'])
+        error('dates::dates: Wrong calling sequence!')
     end
     for i=2:dd.ndat
         if isdate(varargin{i})
@@ -118,10 +118,10 @@ switch nargin
             if isequal(date.freq,dd.freq)
                 dd.time(i,:) = date.time;
             else
-                 error(['dates::dates: Check that all the inputs have the same frequency (see input number ' str2num(i) ')!'])
+                 error(sprintf('dates::dates: Check that all the inputs have the same frequency (see input number %i)!',i))
             end
         else
-            error(['dates::dates: Input ' str2num(i) ' has to be a string date!'])
+            error(sprintf('dates::dates: Input %i has to be a string date!',i))
         end
     end
 end
diff --git a/matlab/@dates/subsref.m b/matlab/@dates/subsref.m
index 0cd0cd4014..e966fc1e95 100644
--- a/matlab/@dates/subsref.m
+++ b/matlab/@dates/subsref.m
@@ -93,7 +93,7 @@ switch S(1).type
                 elseif isequal(m,1)
                     B.time = [S(1).subs{2}, ones(n,1)];
                 else
-                    error(['dates::subsref: This is a bug!'])
+                    error('dates::subsref: This is a bug!')
                 end
                 B.ndat = rows(B.time);
             elseif isequal(length(S(1).subs),3)
@@ -148,7 +148,7 @@ switch S(1).type
                 elseif isequal(m,1) && isequal(B.freq,1)
                     B.time = [S(1).subs{1}, ones(n,1)];
                 else
-                    error(['dates::subsref: This is a bug!'])
+                    error('dates::subsref: This is a bug!')
                 end
                 B.ndat = rows(B.time);
             else
@@ -267,7 +267,7 @@ end
 %$
 %$ % Define a ranges of dates using qq.
 %$ try
-%$     r1 = qq(1950,1):qq([1950, 3]);
+%$     r1 = qq(1950,1):qq(1950,3);%qq([1950, 3]);
 %$     t(1) = 1;
 %$ catch
 %$     t(1) = 0;
diff --git a/matlab/utilities/dates/isdate.m b/matlab/utilities/dates/isdate.m
index ebcd2816e4..2fb6038030 100644
--- a/matlab/utilities/dates/isdate.m
+++ b/matlab/utilities/dates/isdate.m
@@ -25,11 +25,11 @@ function b = isdate(str)  % --*-- Unitary tests --*--
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-if length(str)>1
+%if length(str)>1
     b = isquaterly(str) || isyearly(str) || ismonthly(str) || isweekly(str);
-else
-    b = 0;
-end
+    %else
+    %b = 0;
+    %end
 
 %@test:1
 %$
diff --git a/matlab/utilities/dates/ismonthly.m b/matlab/utilities/dates/ismonthly.m
index 7d3a60f652..a66d06e695 100644
--- a/matlab/utilities/dates/ismonthly.m
+++ b/matlab/utilities/dates/ismonthly.m
@@ -26,7 +26,11 @@ function b = ismonthly(str)  % --*-- Unitary tests --*--
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 if ischar(str)
-    b = ~isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$'));
+    if isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$','once'))
+        b = 0;
+    else
+        b = 1;
+    end
 else
     b = 0;
 end
diff --git a/matlab/utilities/dates/isquaterly.m b/matlab/utilities/dates/isquaterly.m
index 92b1c6dc27..2b154ef3c5 100644
--- a/matlab/utilities/dates/isquaterly.m
+++ b/matlab/utilities/dates/isquaterly.m
@@ -25,8 +25,12 @@ function b = isquaterly(str)  % --*-- Unitary tests --*--
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-if ischar(str)    
-    b = ~isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$'));
+if ischar(str)
+    if isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$','once'))
+        b = 0;
+    else
+        b = 1;
+    end
 else
     b = 0;
 end
diff --git a/matlab/utilities/dates/isweekly.m b/matlab/utilities/dates/isweekly.m
index ea7eca9926..d9988f5253 100644
--- a/matlab/utilities/dates/isweekly.m
+++ b/matlab/utilities/dates/isweekly.m
@@ -26,7 +26,11 @@ function b = isweekly(str)  % --*-- Unitary tests --*--
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 if ischar(str)
-    b = ~isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$'));
+    if isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once'))
+        b = 0;
+    else
+        b = 1;
+    end
 else
     b = 0;
 end
diff --git a/matlab/utilities/dates/isyearly.m b/matlab/utilities/dates/isyearly.m
index ef56c46b9e..d1345a0a18 100644
--- a/matlab/utilities/dates/isyearly.m
+++ b/matlab/utilities/dates/isyearly.m
@@ -26,7 +26,11 @@ function b = isyearly(str)  % --*-- Unitary tests --*--
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 if ischar(str)
-    b = ~isempty(regexp(str,'^-?[0-9]*[YyAa]$'));
+    if isempty(regexp(str,'^-?[0-9]*[YyAa]$','once'))
+        b = 0;
+    else
+        b = 1;
+    end
 else
     b = 0;
 end
-- 
GitLab