[Dart-dev] DART/branches Revision: 11840

dart at ucar.edu dart at ucar.edu
Thu Jul 20 16:56:52 MDT 2017


thoar at ucar.edu
2017-07-20 16:56:51 -0600 (Thu, 20 Jul 2017)
221
Adding better error messages for when the CopyMetaData or QCMetaData
strings do not match what is in the file.
Moved read_obs_netcdf.m out of the private directory because the
web pages give an example on how to use it.




Modified: DART/branches/rma_trunk/diagnostics/matlab/private/get_copy_index.m
===================================================================
--- DART/branches/rma_trunk/diagnostics/matlab/private/get_copy_index.m	2017-07-20 20:53:33 UTC (rev 11839)
+++ DART/branches/rma_trunk/diagnostics/matlab/private/get_copy_index.m	2017-07-20 22:56:51 UTC (rev 11840)
@@ -1,7 +1,8 @@
-function copy_index = get_copy_index(fname, copystring)
-%% GET_COPY_INDEX  Gets an index corresponding to copy meta_data string
-% Retrieves index associated with a given copy meta_data string in
-% file fname. If string is not found in meta_data list, a -1 is returned.
+function copy_index = get_copy_index(fname, copystring, context)
+%% GET_COPY_INDEX  Gets an index corresponding to copy metadata string
+% Retrieves index associated with a given string in the 
+% CopyMetaData netCDF variable in the given file. If the string
+% does not exist - a fatal error is thrown.
 %
 % Example:
 % fname = 'obs_diag_output.nc';
@@ -14,6 +15,15 @@
 %
 % DART $Id$
 
+errorstring = sprintf('\nERROR: "%s" is not a valid CopyMetaData value for file %s\n', ...
+              strtrim(copystring), fname);
+
+if (nargin == 3)
+   msgstring = sprintf('valid values for "%s" are', context);
+else
+   msgstring = 'valid values for CopyMetaData are';
+end
+
 if ( exist(fname,'file') ~= 2 ), error('%s does not exist.',fname); end
 
 % Matlab seems to always need to transpose character variables.
@@ -42,13 +52,10 @@
 % Provide modest error support
 
 if (copy_index < 0)
-   fprintf('ERROR: %s is not a valid metadata string for file %s\n', ...
-                strtrim(copystring), fname)
-   disp('valid metadata strings are: ')
    for i = 1:num_copies,
-      fprintf('%s\n',deblank(copy_meta_data(i,:)))
+      msgstring = sprintf('%s\n%s',msgstring,deblank(copy_meta_data(i,:)));
    end
-   error('Thats all. Start over')
+   error(sprintf('%s\n%s',errorstring,msgstring))
 end
 
 

Modified: DART/branches/rma_trunk/diagnostics/matlab/private/get_qc_index.m
===================================================================
--- DART/branches/rma_trunk/diagnostics/matlab/private/get_qc_index.m	2017-07-20 20:53:33 UTC (rev 11839)
+++ DART/branches/rma_trunk/diagnostics/matlab/private/get_qc_index.m	2017-07-20 22:56:51 UTC (rev 11840)
@@ -1,7 +1,7 @@
-function copy_index = get_qc_index(fname, copystring)
-%% get_qc_index  Gets an index corresponding to QC meta_data string
-% Retrieves index associated with a given QC meta_data string in
-% file fname. If string is not found in meta_data list, a -1 is returned.
+function copy_index = get_qc_index(fname, copystring, context)
+%% get_qc_index  Gets an index corresponding to QCMetaData string
+% Retrieves index associated with a given QCMetaData string in fname.
+% If string does not match any, a fatal error is thrown. 
 %
 % Example:
 % fname = 'obs_epoch_001.nc';
@@ -14,9 +14,18 @@
 %
 % DART $Id$
 
-% Need to get the QC MetaData (strings with the names)
+% Need to get the QCMetaData (strings with the names)
 % We then search the metadata for each copy for the appropriate copies.
 
+errorstring = sprintf('\nERROR: "%s" is not a valid QCMetaData value for file %s\n', ...
+              strtrim(copystring), fname);
+
+if (nargin == 3)
+   msgstring = sprintf('valid values for "%s" are', context);
+else
+   msgstring = 'valid values for QCMetaData are';
+end
+
 if ( exist(fname,'file') ~= 2 ), error('%s does not exist.',fname); end
 
 qc_meta_data    = ncread(fname,'QCMetaData')';
@@ -45,13 +54,10 @@
 % Provide modest error support
 
 if (copy_index < 0)
-   fprintf('ERROR: %s is not a valid metadata string for file %s\n', ...
-                copystring, fname)
-   disp('valid metadata strings are: ')
    for i = 1:num_copies,
-      disp(sprintf('%s',deblank(qc_meta_data(i,:))))
+      msgstring = sprintf('%s\n%s',msgstring,deblank(qc_meta_data(i,:)));
    end
-   error('please try again')
+   error(sprintf('%s\n%s',errorstring,msgstring))
 end
 


More information about the Dart-dev mailing list