Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

inputordefault.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function [out, inps] = inputordefault(keyname, defval, inps)
  2. % [out, leftover] = inputordefault(keyname, defval, inps)
  3. % Parses a cell array (usually varargin) looking for a string which matches
  4. % the keyname and then assigns out to the value of the next element of the
  5. % input if it finds it otherwise assignes it to the default value.
  6. % E.g. sessid = inputordefault('sessid', 0, varargin)
  7. % Can also be called on the leftovers to check that there were no missing arguments.
  8. % Can also be called to convert a struct into a list of
  9. if nargin==1
  10. if isstruct(keyname)
  11. % convert to name, value
  12. fn = fieldnames(keyname);
  13. out = cell(1,2*numel(fn));
  14. for fx = 1:numel(fn)
  15. out{2*fx-1} = fn{fx};
  16. out{2*fx} = keyname.(fn{fx});
  17. end
  18. return
  19. end
  20. if ~isempty(keyname)
  21. warning('You have unused keyword arguments')
  22. for argx = 1:2:numel(keyname)
  23. fprintf(2,'%s: %s\n', keyname{argx},keyname{argx+1});
  24. end
  25. end
  26. else
  27. ind = strcmpi(keyname, inps(1:2:end));
  28. % is the keyname in the inputs? Look only at the odd elements of inps, since this keyname could be a value of another input.
  29. if any(ind)
  30. out = inps{2*find(ind)};
  31. inps(2*find(ind)-1:2*find(ind)) = []; % erase these from the list.
  32. else
  33. out = defval;
  34. end
  35. end