Skip to content

Commit

Permalink
Re #1776 fixed kf_sphere_proj.m constructor, to have Ei as first para…
Browse files Browse the repository at this point in the history
…meter
  • Loading branch information
abuts committed Jan 24, 2025
1 parent b4666c4 commit 1f1e1c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
13 changes: 10 additions & 3 deletions herbert_core/utilities/scientific/neutron_constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
%
% >> s=neutron_constants % return structure
% >> neutron_constants % list constants
% >> val = neutron_constants(constant_name) % returns particular
% constant.


mlock; % for stability
persistent structure

if isempty(structure)
Expand All @@ -24,10 +25,16 @@
end

if nargout>0
if narin == 0
if nargin == 0
s=structure;
else
s = structure.(constant_name);
if isfield(structure,constant_name)
s = structure.(constant_name);
else
error('HERBERT:utilities:invalid_argument', ...
'name: "%s" is not a correct neutron constant name', ...
constant_name)
end
end
else
nam=fieldnames(structure);
Expand Down
12 changes: 11 additions & 1 deletion horace_core/sqw/coord_transform/@CurveProjBase/CurveProjBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
obj = obj.check_combo_arg();
end
else
opt = [sphere_proj.fields_to_save_(:);aProjectionBase.init_params(:)];
opt = obj.init_order_fields();
[obj,remains] = ...
set_positional_and_key_val_arguments(obj,...
opt,false,varargin{:});
Expand Down Expand Up @@ -197,6 +197,16 @@
S.v = S.ex;
end
end
function flds = init_order_fields(~)
% Addition to serailizable interface allowing to reorder
% saveableFields in order, convenient for constructing a
% projection. While saveableFields specify public interface
% which fully defines projection, the convenient order of these
% fields in construction or init may be different as people may
% prefer define most important fields first and fields with
% reasonable defaults -- after them
flds = [sphere_proj.fields_to_save_(:);aProjectionBase.init_params(:)];
end
end
methods
% Old ez,ex interface:
Expand Down
16 changes: 15 additions & 1 deletion horace_core/sqw/coord_transform/@kf_sphere_proj/kf_sphere_proj.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
% The axis to calculate theta angle from.
% v -- [1,3] vector of hkl direction of x-axis of the spherical
% coordinate system, the axis to calculate Phi angle from.
% NOTE:
% the idea of this projection is that u and v should be set to
% the values of u,v vectors, used to obtain sqw object i.e. u
% should coicide with beam direction and v selected to define the
% uv plane, where rotation occurs.
%
% type-- 3-letter character array, defining the spherical
% coordinate system units (see type property below)
Expand Down Expand Up @@ -89,7 +94,7 @@
ei = obj.Ei_;
end
function obj = set.Ei(obj,val)
if ~isnumeric(val)||numel(val)
if ~isnumeric(val)||~isscalar(val)
error('HORACE:kf_sphere_proj:invalid_arguments', ...
'Incident beam must be poisitive. Got %d',val);
end
Expand Down Expand Up @@ -164,6 +169,15 @@
%=====================================================================
% SERIALIZABLE INTERFACE
%----------------------------------------------------------------------
methods(Access=protected)
function flds = init_order_fields(obj)
% overloadeded field construction order to put incident energy
% first
flds = init_order_fields@CurveProjBase(obj);
flds = ['Ei';flds(:)];
end
end

methods
function flds = saveableFields(obj)
flds = saveableFields@sphere_proj(obj);
Expand Down

0 comments on commit 1f1e1c4

Please sign in to comment.