function [varargout] = align(varargin) %align set alignment of the objects in the block % % align(align_spec, obj <, obj> <, align_spec, obj> ...); % % sets delays of the objects within the block to achieve the desired % alignment. % All previously configured delays within objects are taken into account % during calculating of the block duration but then reset according to % the selected alignment. % Possible values for align_spec are 'left', 'center', 'right' % WARNING: 'center' may break gradient raster alignment % When a numerical parameter is passed amongst the events it is % interpreted as the required duration of the block. If the duration of % any of the events exceeds this required duration an error will be thrown. % The required block duration is optionally returned as the last % parameter in the output list. If used within seq.addBlock() required % duration is always passed at the end of the list of the block events. % % See also Sequence.addBlock % % Maxim Zaitsev alignment_options={'left', 'center', 'right'}; % parse parameters if ~ischar(varargin{1}) error('first parameter must be a string'); end curr_align=find(strcmp(varargin{1},alignment_options)); if isempty(curr_align) error('invalid alignment spec'); end iobjects=[]; alignments=[]; required_duration=[]; for i=2:length(varargin) if ischar(varargin{i}) curr_align=find(strcmp(varargin{i},alignment_options)); if isempty(curr_align) error('invalid alignment spec'); end continue; end if isnumeric(varargin{i}) if ~isempty(required_duration) error('More than one numeric parameter given to align()'); end required_duration=varargin{i}; continue; end iobjects(end+1)=i; alignments=[alignments curr_align]; end objects={varargin{iobjects}}; dur=mr.calcDuration(objects); if ~isempty(required_duration) if dur-required_duration>eps error('Required block duration is %g s but actual block duration is %g s', required_duration, dur); end dur=required_duration; end % set new delays for i=1:length(objects) if isfield(objects{i},'id') error('attempting to align() readily registered object! please register objects after calling this function or deregister the argument(s) by calling rmfield(...,''id'')'); end switch alignments(i) case 1 objects{i}.delay=0; case 2 objects{i}.delay=(dur - mr.calcDuration(objects{i}) + objects{i}.delay)/2; case 3 ev=objects{i}; ev_dur=mr.calcDuration(ev); %if isfield(ev,'ringdownTime') % ev_dur=ev_dur+ev.ringdownTime; %end objects{i}.delay=dur - ev_dur + objects{i}.delay; if objects{i}.delay < 0 error('align() attempts to set a negative delay, probably some RF pulses ignore rfRingdownTime'); end end end if nargout==length(objects) varargout=objects; elseif ~isempty(required_duration) && nargout==length(objects)+1 varargout=objects; varargout{end+1}=required_duration; elseif nargout==1 if isempty(required_duration) varargout={objects}; else varargout={[objects {required_duration}]}; end elseif nargout