changeset 872:f190e35bb57a bcSetupExperiment

Clean up verifyFormat
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 01 Nov 2018 12:02:25 +0100
parents 526b039c0ecc
children dee5b5a57be6
files +scheme/+bc/verifyFormat.m
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/+scheme/+bc/verifyFormat.m	Thu Nov 01 11:41:03 2018 +0100
+++ b/+scheme/+bc/verifyFormat.m	Thu Nov 01 12:02:25 2018 +0100
@@ -1,4 +1,6 @@
+% Errors with a more or less detailed error message if there is a problem with the bc specification
 function verifyBcFormat(bcs, diffOp)
+    assertType(bcs, 'cell');
     for i = 1:length(bcs)
         assertType(bcs{i}, 'struct');
         assertStructFields(bcs{i}, {'type', 'boundary'});
@@ -11,15 +13,19 @@
             error('bcs{%d}.data should be a function of time or a function of time and space',i);
         end
 
+        % Find dimension of boundary
         b = diffOp.grid.getBoundary(bcs{i}.boundary);
+        dim = size(b,2);
 
-        dim = size(b,2);
+        % Assert that the data function has a valid number of input arguments
+        if ~(nargin(bcs{i}.data) == 1 || nargin(bcs{i}.data) == 1 + dim)
+            error('sbplib:scheme:bcSetup:DataWrongNumberOfArguments', 'bcs{%d}.data has the wrong number of input arguments. Must be either only time or time and space.', i);
+        end
 
         if nargin(bcs{i}.data) == 1
             % Grid data (only function of time)
+            % Assert that the data has the correct dimension
             assertSize(bcs{i}.data(0), 1, size(b));
-        elseif nargin(bcs{i}.data) ~= 1+dim
-           error('sbplib:scheme:bcSetup:DataWrongNumberOfArguments', 'bcs{%d}.data has the wrong number of input arguments. Must be either only time or time and space.', i);
         end
     end
 end