time | Calls | line |
---|
| | 582 | function [data, map, filename, format, paramPairs] = parse_inputs(varargin)
|
| | 583 |
|
< 0.001 | 10 | 584 | data = [];
|
< 0.001 | 10 | 585 | map = [];
|
< 0.001 | 10 | 586 | filename = '';
|
< 0.001 | 10 | 587 | format = '';
|
< 0.001 | 10 | 588 | paramPairs = {};
|
| | 589 |
|
< 0.001 | 10 | 590 | if (nargin < 2)
|
| | 591 | error(message('MATLAB:imagesci:validate:wrongNumberOfInputs'));
|
< 0.001 | 10 | 592 | end
|
| | 593 |
|
< 0.001 | 10 | 594 | firstString = [];
|
< 0.001 | 10 | 595 | for k = 1:length(varargin)
|
< 0.001 | 20 | 596 | if (ischar(varargin{k}))
|
< 0.001 | 10 | 597 | firstString = k;
|
< 0.001 | 10 | 598 | break;
|
< 0.001 | 10 | 599 | end
|
< 0.001 | 10 | 600 | end
|
| | 601 |
|
< 0.001 | 10 | 602 | if (isempty(firstString))
|
| | 603 | error(message('MATLAB:imagesci:imwrite:missingFilename'));
|
< 0.001 | 10 | 604 | end
|
| | 605 |
|
< 0.001 | 10 | 606 | switch firstString
|
< 0.001 | 10 | 607 | case 1
|
| | 608 | error(message('MATLAB:imagesci:imwrite:firstArgString'));
|
| | 609 |
|
< 0.001 | 10 | 610 | case 2
|
| | 611 | % imwrite(data, filename, ...)
|
< 0.001 | 10 | 612 | data = varargin{1};
|
< 0.001 | 10 | 613 | filename = varargin{2};
|
| | 614 |
|
| | 615 | case 3
|
| | 616 | % imwrite(data, map, filename, ...)
|
| | 617 | data = varargin{1};
|
| | 618 | map = varargin{2};
|
| | 619 | filename = varargin{3};
|
| | 620 | if (size(map,2) ~= 3)
|
| | 621 | error(message('MATLAB:imagesci:imwrite:invalidColormap'));
|
| | 622 | end
|
| | 623 |
|
| | 624 | validateattributes(map,{'numeric'},{'>=',0,'<=',1},'','COLORMAP');
|
| | 625 |
|
| | 626 | otherwise
|
| | 627 | error(message('MATLAB:imagesci:imwrite:badFilenameArgumentPosition'));
|
< 0.001 | 10 | 628 | end
|
| | 629 |
|
< 0.001 | 10 | 630 | if (length(varargin) > firstString)
|
| | 631 | % There are additional arguments after the filename.
|
< 0.001 | 10 | 632 | if (~ischar(varargin{firstString + 1}))
|
| | 633 | error(message('MATLAB:imagesci:imwrite:invalidArguments'));
|
< 0.001 | 10 | 634 | end
|
| | 635 |
|
| | 636 | % Is the argument after the filename a format specifier?
|
0.008 | 10 | 637 | fmt_s = imformats(varargin{firstString + 1});
|
| | 638 |
|
< 0.001 | 10 | 639 | if (~isempty(fmt_s))
|
| | 640 | % imwrite(..., filename, fmt, ...)
|
< 0.001 | 10 | 641 | format = varargin{firstString + 1};
|
< 0.001 | 10 | 642 | paramPairs = varargin((firstString + 2):end);
|
| | 643 |
|
| | 644 | else
|
| | 645 | % imwrite(..., filename, prop1, val1, prop2, val2, ...)
|
| | 646 | paramPairs = varargin((firstString + 1):end);
|
< 0.001 | 10 | 647 | end
|
| | 648 |
|
| | 649 | % Do some validity checking on param-value pairs
|
< 0.001 | 10 | 650 | if (rem(length(paramPairs), 2) ~= 0)
|
| | 651 | error(message('MATLAB:imagesci:imwrite:invalidSyntaxOrFormat',varargin{firstString + 1}));
|
< 0.001 | 10 | 652 | end
|
| | 653 |
|
< 0.001 | 10 | 654 | end
|
| | 655 |
|
< 0.001 | 10 | 656 | for k = 1:2:length(paramPairs)
|
< 0.001 | 50 | 657 | validateattributes(paramPairs{k},{'char', 'string'},{'nonempty', 'scalartext'},'','PARAMETER NAME');
|
< 0.001 | 50 | 658 | end
|
| | 659 |
|
< 0.001 | 10 | 660 | end
|
Other subfunctions in this file are not included in this listing.