diff --git a/src/AcceleratorLattice.jl b/src/AcceleratorLattice.jl index 3fea35f..f434a36 100644 --- a/src/AcceleratorLattice.jl +++ b/src/AcceleratorLattice.jl @@ -72,13 +72,13 @@ export TrackingParams, LengthParams, ReferenceParams, DownstreamReferenceParams, export MasterParams, LordSlaveStatusParams, ACKickerParams export GirderParams, PatchParams, RFAutoParams, OutputParams, full_parameter_name export BeginningParams, Twiss1, Wall2D, Vertex1, InitSpinParams, InitParticleParams, show_changed -export info, ctrl, var, create_external_ele, ele_param_info, units, ele_param_group_syms +export info, ele_param_info, param_units, ele_param_group_syms export show_group, switch_list_dict, lat_sanity_check, NULL_ELE, NULL_BRANCH, is_null export ele_param_struct_field_to_user_sym, multipole!, index, integer, rot_angles, Quaternion export machine_location, body_location, EleRegion, holy_traits, output_parameter export BranchType, LordBranch, TrackingBranch, MultipassBranch, SuperBranch, transform export str_split, str_match, str_unquote, str_quote, str_to_int, associated_names -export ELE_PARAM_GROUP_INFO, ELE_TYPE_INFO, PARAM_GROUPS_LIST, OPEN, CLOSED +export DO_NOT_SHOW_PARAMS_LIST, ELE_PARAM_GROUP_INFO, ELE_TYPE_INFO, PARAM_GROUPS_LIST, OPEN, CLOSED export rotX, rotY, rotZ, rot, rot!, bend_quaternion, lat_ele_dict # From LinearAlgebra diff --git a/src/accessor.jl b/src/accessor.jl index f385f14..95b2241 100644 --- a/src/accessor.jl +++ b/src/accessor.jl @@ -86,7 +86,7 @@ function Base.getproperty(ele::Ele, sym::Symbol) if !isnothing(pinfo.output_group); return output_parameter(sym, ele, pinfo.output_group); end symparent = Symbol(pinfo.parent_group) - if !haskey(pdict, symparent); error(f"Cannot find {sym} in element {ele_name(ele)}"); end + if !haskey(pdict, symparent); error("Cannot find $sym in element $(ele_name(ele))"); end return get_elegroup_param(ele, pdict[symparent], pinfo) end @@ -345,8 +345,8 @@ function get_elegroup_param(ele::Ele, group::Union{BMultipoleParams, EMultipoleP if mtype[end] == 'L' && !integrated return val * ele.L elseif mtype[end] != 'L' && integrated - if ele.L == 0; error(f"Cannot compute non-integrated multipole value {pinfo.user_sym} for" * - f" integrated multipole of element with zero length: {ele_name(ele)}"); end + if ele.L == 0; error("Cannot compute non-integrated multipole value $(pinfo.user_sym) for" * + " integrated multipole of element with zero length: $(ele_name(ele))"); end return val / ele.L else return val @@ -478,49 +478,47 @@ function output_parameter(sym::Symbol, ele::Ele, output_group::Type{T}) where T if :DownstreamReferenceParams ∉ keys(ele.pdict); return NaN; end return ele.E_tot_ref_downstream / massof(ele.species_ref_downstream) - elseif sym == :q_shift + elseif sym == :q_body if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end ag = ele.pdict[:BodyShiftParams] return Quaternion(ag.x_rot, ag.y_rot, ag.z_rot) - elseif sym == :offset_tot + elseif sym == :offset_body_tot if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end - if isnothing(girder(ele)); return ele.offset; end + if isnothing(girder(ele)); return ele.offset_body; end ag = ele.pdict[:BodyShiftParams] - orient_girder = FloorParams(girder(ele).offset_tot, girder(ele).q_shift_tot) - orient_ele = FloorParams(ele.offset, ele.q_shift) + orient_girder = FloorParams(girder(ele).offset_body_tot, girder(ele).q_shift_body_tot) + orient_ele = FloorParams(ele.offset_body, ele.q_body) return coord_transform(orient_ele, orient_girder).r - elseif sym == :x_rot_tot + elseif sym == :x_rot_body_tot if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end - if isnothing(girder(ele)); return ele.x_rot; end + if isnothing(girder(ele)); return ele.x_rot_body; end ag = ele.pdict[:BodyShiftParams] - orient_girder = FloorParams(girder(ele).offset_tot, girder(ele).q_shift_tot) - orient_ele = FloorParams(ele.offset, ele.q_shift) + orient_girder = FloorParams(girder(ele).offset_body_tot, girder(ele).q_body_tot) + orient_ele = FloorParams(ele.offset_body, ele.q_body) return rot_angles(coord_transform(orient_ele, orient_girder).q)[1] - elseif sym == :y_rot_tot + elseif sym == :y_rot_body_tot if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end - if isnothing(girder(ele)); return ele.y_rot; end + if isnothing(girder(ele)); return ele.y_rot_body; end ag = ele.pdict[:BodyShiftParams] - orient_girder = FloorParams(girder(ele).offset_tot, girder(ele).q_shift_tot) - orient_ele = FloorParams(ele.offset, ele.q_shift) + orient_girder = FloorParams(girder(ele).offset_body_tot, girder(ele).q_body_tot) + orient_ele = FloorParams(ele.offset_body, ele.q_body) return rot_angles(coord_transform(orient_ele, orient_girder).q)[2] - elseif sym == :z_rot_tot + elseif sym == :z_rot_body_tot if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end - if isnothing(girder(ele)); return ele.z_rot; end - ag = ele.pdict[:BodyShiftParams] - orient_girder = FloorParams(girder(ele).offset_tot, girder(ele).q_shift_tot) - orient_ele = FloorParams(ele.offset, ele.q_shift) + if isnothing(girder(ele)); return ele.z_rot_body; end + orient_girder = FloorParams(girder(ele).offset_body_tot, girder(ele).q_body_tot) + orient_ele = FloorParams(ele.offset_body, ele.q_body) return rot_angles(coord_transform(orient_ele, orient_girder).q)[3] - elseif sym == :q_shift_tot + elseif sym == :q_body_tot if :BodyShiftParams ∉ keys(ele.pdict); return NaN; end - if isnothing(girder(ele)); return ele.q_shift; end - ag = ele.pdict[:BodyShiftParams] - orient_girder = FloorParams(girder(ele).offset_tot, girder(ele).q_shift_tot) - orient_ele = FloorParams(ele.offset, ele.q_shift) + if isnothing(girder(ele)); return ele.q_body; end + orient_girder = FloorParams(girder(ele).offset_body_tot, girder(ele).q_body_tot) + orient_ele = FloorParams(ele.offset_body, ele.q_body) return coord_transform(orient_ele, orient_girder).q end diff --git a/src/bookkeeper.jl b/src/bookkeeper.jl index 06aba5d..f5ad270 100644 --- a/src/bookkeeper.jl +++ b/src/bookkeeper.jl @@ -375,8 +375,8 @@ function param_conflict_check(ele::Ele, syms...) for sym in syms if haskey(ele.changed, sym); push!(sym_in, sym); end end - if length(sym_in) > 1; error(f"Conflict: {s[1]} and {s[2]} cannot both " * - f"be specified for a {typeof(ele)} element: {ele.name}"); end + if length(sym_in) > 1; error("Conflict: $(s[1]) and $(s[2]) cannot both " * + "be specified for a $(typeof(ele)) element: $(ele.name)"); end return sym_in return @@ -499,12 +499,12 @@ function elegroup_bookkeeper!(ele::Ele, group::Type{BendParams}, changed::Change L = bg.g * bg.angle elseif haskey(cdict, :angle) && haskey(cdict, :L_chord) if bg.L_chord == 0 && bg.angle != 0; - error(f"Bend cannot have finite angle and zero length: {ele_name(ele)}"); end + error("Bend cannot have finite angle and zero length: $(ele_name(ele))"); end bg.angle == 0 ? bg.g = 0.0 : bg.g = 2.0 * sin(bg.angle/2) / bg.L_chord L = bg.angle * bg.g elseif haskey(cdict, :angle) L = ele.L - if L == 0 && bg.angle != 0; error(f"Bend cannot have finite angle and zero length: {ele_name(ele)}"); end + if L == 0 && bg.angle != 0; error("Bend cannot have finite angle and zero length: $(ele_name(ele))"); end bg.angle == 0 ? bg.g = 0 : bg.g = bg.angle / L else L = ele.L @@ -646,13 +646,13 @@ function elegroup_bookkeeper!(ele::Ele, group::Type{ReferenceParams}, changed::C if is_null(previous_ele) # implies BeginningEle if !changed.reference; return; end - if rg.species_ref == Species(); error(f"Species not set for first element in branch: {ele_name(ele)}"); end + if rg.species_ref == Species(); error("Species not set for first element in branch: $(ele_name(ele))"); end drg.species_ref_downstream = rg.species_ref rg.time_ref_downstream = rg.time_ref + rg.extra_dtime_ref if count([haskey(cdict, :pc_ref), haskey(cdict, :E_tot_ref), haskey(cdict, :β_ref), haskey(cdict, :γ_ref)]) > 1 - error(f"Beginning element has more than one of pc_ref, E_tot_ref, β_ref, and γ_ref set in {ele_name(ele)}") + error("Beginning element has more than one of pc_ref, E_tot_ref, β_ref, and γ_ref set in $(ele_name(ele))") elseif haskey(cdict, :E_tot_ref) rg.pc_ref = calc_pc(rg.species_ref, E_tot = rg.E_tot_ref) elseif haskey(cdict, :pc_ref) diff --git a/src/find.jl b/src/find.jl index 1f13210..b790f8b 100644 --- a/src/find.jl +++ b/src/find.jl @@ -65,7 +65,7 @@ function ele_at_offset(reference::Union{Ele,Branch}, offset::Int, wrap::Bool) indx = mod(indx-1, n) + 1 return branch.ele[indx] else - if indx < 1 || indx > n; error(f"BoundsError: " * + if indx < 1 || indx > n; error("BoundsError: " * "Element index: $indx out of range in branch $(branch.ix_branch): $(branch.name)"); end return branch.ele[indx] end @@ -436,7 +436,7 @@ Returns `nothing` if no branch can be matched. """ lat_branch function lat_branch(lat::Lattice, ix::Int) - if ix < 1 || ix > length(lat.branch); error(f"Branch index {ix} out of bounds."); end + if ix < 1 || ix > length(lat.branch); error("Branch index $ix out of bounds."); end return lat.branch[ix] end @@ -444,14 +444,14 @@ function lat_branch(lat::Lattice, who::AbstractString) for branch in lat.branch if branch.name == who; return branch; end end - error(f"Cannot find branch with name {name} in lattice.") + error("Cannot find branch with name $name in lattice.") end function lat_branch(lat::Lattice, who::Type{T}) where T <: BranchType for branch in lat.branch if branch.pdict[:type] == who; return branch; end end - error(f"Cannot find branch with type {name} in lattice.") + error("Cannot find branch with type $name in lattice.") end function lat_branch(ele::Ele) diff --git a/src/lat_construction.jl b/src/lat_construction.jl index 95ee173..e752eaf 100644 --- a/src/lat_construction.jl +++ b/src/lat_construction.jl @@ -133,7 +133,7 @@ Base.:*(n::Int, beamline::BeamLine) = BeamLine(beamline.id * "_m" * string(n), [(n > 0 ? beamline : reflect(beamline)) for i in 1:abs(n)], beamline.pdict) function Base.:*(n::Int, ele::Ele) - if n < 0; error(f"BoundsError: Negative multiplier does not make sense."); end + if n < 0; error("BoundsError: Negative multiplier does not make sense."); end BeamLine(ele.id * "_m" * string(n), [BeamLineEle(ele) for i in 1:n], false, +1) end @@ -185,7 +185,7 @@ function add_beamline_item_to_branch!(branch::Branch, item::BeamLineItem, info:: elseif item isa BeamLine add_beamline_line_to_branch!(branch, item, info) else - error(f"ArgumentError: Beamline item not recognized: {item}") + error("ArgumentError: Beamline item not recognized: $(item)") end return nothing end @@ -203,7 +203,7 @@ Used by the `Lattice` function. function add_beamline_line_to_branch!(branch::Branch, beamline::BeamLine, info::LatticeConstructionInfo) info.n_loop += 1 - if info.n_loop > 100; error(f"InfiniteLoop: Infinite loop of beam lines calling beam lines detected."); end + if info.n_loop > 100; error("InfiniteLoop: Infinite loop of beam lines calling beam lines detected."); end info = deepcopy(info) info.orientation_here = info.orientation_here * beamline.pdict[:orientation] diff --git a/src/parameters.jl b/src/parameters.jl index 5387e2a..bcd8852 100644 --- a/src/parameters.jl +++ b/src/parameters.jl @@ -95,11 +95,11 @@ ELE_PARAM_INFO_DICT = Dict( :z_rot_body => ParamInfo(BodyShiftParams, Number, "Z-axis body rotation of element.", "rad", nothing, :z_rot), :q_body => ParamInfo(BodyShiftParams, Quaternion, "Quaternion orientation of body.", "", OutputParams), - :q_tot => ParamInfo(BodyShiftParams, Quaternion, "Quaternion orientation including Girder orientation.", "", OutputParams), - :offset_tot => ParamInfo(BodyShiftParams, Vector{Number}, "[x, y, z] element offset including Girder orientation.", "m", OutputParams), - :x_rot_tot => ParamInfo(BodyShiftParams, Number, "X-axis body rotation including Girder orientation.", "rad", OutputParams), - :y_rot_tot => ParamInfo(BodyShiftParams, Number, "Y-axis body rotation including Girder orientation.", "rad", OutputParams), - :z_rot_tot => ParamInfo(BodyShiftParams, Number, "Z-axis body rotation including Girder orientation.", "rad", OutputParams), + :q_body_tot => ParamInfo(BodyShiftParams, Quaternion, "Quaternion orientation including Girder orientation.", "", OutputParams), + :offset_body_tot => ParamInfo(BodyShiftParams, Vector{Number}, "[x, y, z] element offset including Girder orientation.", "m", OutputParams), + :x_rot_body_tot => ParamInfo(BodyShiftParams, Number, "X-axis body rotation including Girder orientation.", "rad", OutputParams), + :y_rot_body_tot => ParamInfo(BodyShiftParams, Number, "Y-axis body rotation including Girder orientation.", "rad", OutputParams), + :z_rot_body_tot => ParamInfo(BodyShiftParams, Number, "Z-axis body rotation including Girder orientation.", "rad", OutputParams), :aperture_shape => ParamInfo(ApertureParams, ApertureShape, "Aperture shape. Default is ELLIPTICAL."), :aperture_at => ParamInfo(ApertureParams, BodyLoc.T, "Aperture location. Default is BodyLoc.ENTRANCE_END."), @@ -184,10 +184,10 @@ ELE_PARAM_INFO_DICT = Dict( :flexible => ParamInfo(PatchParams, Bool, "Flexible patch?"), :ref_coords => ParamInfo(PatchParams, BodyLoc.T, "Patch coords with respect to BodyLoc.ENTRANCE_END or BodyLoc.EXIT_END?"), - :offset_position => ParamInfo(BodyShiftParams, Vector{Number}, "[x, y, z] offset.", "m", nothing, :offset), - :x_rot_position => ParamInfo(BodyShiftParams, Number, "X-axis rotation.", "rad", nothing, :x_rot), - :y_rot_position => ParamInfo(BodyShiftParams, Number, "Y-axis rotation.", "rad", nothing, :y_rot), - :z_rot_position => ParamInfo(BodyShiftParams, Number, "Z-axis rotation.", "rad", nothing, :z_rot), + :offset_position => ParamInfo(PositionParams, Vector{Number}, "[x, y, z] offset.", "m", nothing, :offset), + :x_rot_position => ParamInfo(PositionParams, Number, "X-axis rotation.", "rad", nothing, :x_rot), + :y_rot_position => ParamInfo(PositionParams, Number, "Y-axis rotation.", "rad", nothing, :y_rot), + :z_rot_position => ParamInfo(PositionParams, Number, "Z-axis rotation.", "rad", nothing, :z_rot), :species_ref => ParamInfo(ReferenceParams, Species, "Reference species."), :pc_ref => ParamInfo(ReferenceParams, Number, "Reference momentum * c.", "eV"), @@ -247,22 +247,27 @@ end # associated_names(group::Type{T}) """ - associated_names(group::Type{T}) -> Vector{Symbol} + associated_names(group::Type{T}; exclude_do_not_show::Bool = true) -> Vector{Symbol} List of names (symbols) of parameters associated with element parameter group struct `group`. Associated parameters are the fields of the struct plus any associated output parameters. If the "user name" is different from the group field name, the user name is used. -For example, for a `FloorParams`, `r_floor` will be in the name list instead of `r`. +For example, for a `FloorParams`, `:r_floor` will be in the name list instead of `:r`. + +If `exclude_do_not_show` is `true`, parameters in the `DO_NOT_SHOW_PARAMS_LIST` are excluded +from the output list. """ associated_names -function associated_names(group::Type{T}) where T <: EleParams +function associated_names(group::Type{T}; exclude_do_not_show::Bool = true) where T <: EleParams names = [field for field in fieldnames(group)] for (key, pinfo) in ELE_PARAM_INFO_DICT if pinfo.parent_group != group; continue; end if pinfo.user_sym ∉ names; push!(names, pinfo.user_sym); end if pinfo.struct_sym != pinfo.user_sym; deleteat!(names, names .== pinfo.struct_sym); end end + + if exclude_do_not_show; names = setdiff(names, DO_NOT_SHOW_PARAMS_LIST); end return names end @@ -314,18 +319,18 @@ for (param, info) in ELE_PARAM_INFO_DICT end #--------------------------------------------------------------------------------------------------- -# units +# param_units """ - units(param::Union{Symbol,DataType}) -> units::String - units(param::Union{Symbol,DataType}, eletype::Type{T}) where T <: Ele -> units::String + param_units(param::Union{Symbol,DataType}) -> units::String + param_units(param::Union{Symbol,DataType}, eletype::Type{T}) where T <: Ele -> units::String Returns the units associated with symbol. EG: `m` (meters) for `param` = `:L`. `param` may be an element parameter group type (EG: `LengthParams`) in which -case `units` returns a blank string. -""" units +case `param_units` returns a blank string. +""" param_units -function units(param::Union{Symbol,DataType}) +function param_units(param::Union{Symbol,DataType}) if typeof(param) == DataType; return ""; end if param in keys(ele_param_struct_field_to_user_sym) @@ -341,8 +346,8 @@ end #- -function units(param::Union{Symbol,DataType}, eletype::Type{T}) where T <: Ele - return units(param) +function param_units(param::Union{Symbol,DataType}, eletype::Type{T}) where T <: Ele + return param_units(param) end #--------------------------------------------------------------------------------------------------- @@ -506,7 +511,7 @@ function ele_param_info(who::Union{Symbol,DataType}; throw_error = true) end # A DataType means `who` is not an element parameter. - if throw_error; error(f"Unrecognized element parameter: {who}"); end + if throw_error; error("Unrecognized element parameter: $who"); end return nothing end @@ -525,17 +530,17 @@ function ele_param_info(who::Union{Symbol,DataType}, ele::Ele; throw_error = tru end end - error(f"Symbol {who} not in element {ele_name(ele)} which is of type {typeof(ele)}") + error("Symbol $who not in element $(ele_name(ele)) which is of type $(typeof(ele))") else if param_info.parent_group in PARAM_GROUPS_LIST[typeof(ele)] || param_info.parent_group == Nothing; return param_info; end - error(f"Symbol {who} not in element {ele_name(ele)} which is of type {typeof(ele)}") + error("Symbol $who not in element $(ele_name(ele)) which is of type $(typeof(ele))") end end # A DataType means `who` is not an element parameter. - if throw_error; error(f"Unrecognized element parameter: {who}"); end + if throw_error; error("Unrecognized element parameter: $who"); end return nothing end @@ -565,7 +570,7 @@ function toggle_integrated!(ele::Ele, ftype::Type{MAGNETIC}, order::Int) mul.Bs = mul.Bs * L else if L == 0 - error(f"Cannot convert from integrated multipole to non-integrated for element of zero length: {ele_name(ele)}") + error("Cannot convert from integrated multipole to non-integrated for element of zero length: $(ele_name(ele))") end mul.Kn = mul.Kn / L mul.Ks = mul.Ks / L @@ -587,7 +592,7 @@ function toggle_integrated!(ele::Ele, ftype::Type{ELECTRIC}, order::Int) mul.Es = mul.Es * L else if L == 0 - error(f"Cannot convert from integrated multipole to non-integrated for element of zero length: {ele_name(ele)}") + error("Cannot convert from integrated multipole to non-integrated for element of zero length: $(ele_name(ele))") end mul.En = mul.En / L mul.Es = mul.Es / L diff --git a/src/show.jl b/src/show.jl index a343fad..dcfbddc 100644 --- a/src/show.jl +++ b/src/show.jl @@ -26,16 +26,15 @@ but not a key. This restriction is not fundamental and could be remove with a li show_column2 = Dict{Type{T} where T <: BaseEleParams, Dict{Symbol,Symbol}}( BodyShiftParams => Dict{Symbol,Symbol}( - :offset => :offset_tot, - :x_rot => :x_rot_tot, - :y_rot => :y_rot_tot, - :z_rot => :z_rot_tot, + :offset_body => :offset_body_tot, + :x_rot_body => :x_rot_body_tot, + :y_rot_body => :y_rot_body_tot, + :z_rot_body => :z_rot_body_tot, ), ApertureParams => Dict{Symbol,Symbol}( :x_limit => :y_limit, :aperture_shape => :aperture_shifts_with_body, - ), BeginningParams => Dict{Symbol,Symbol}( @@ -94,7 +93,7 @@ show_column2 = Dict{Type{T} where T <: BaseEleParams, Dict{Symbol,Symbol}}( ), FloorParams => Dict{Symbol,Symbol}( - :r => :q, + :r_floor => :q_floor, ), PatchParams => Dict{Symbol,Symbol}( @@ -144,6 +143,18 @@ show_column2 = Dict{Type{T} where T <: BaseEleParams, Dict{Symbol,Symbol}}( ), ) +#--------------------------------------------------------------------------------------------------- +# DO_NOT_SHOW_PARAMS_LIST + +""" + Vector{Symbol} DO_NOT_SHOW_PARAMS_LIST + +List of parameters not to show when displaying the parameters of an element, branch, or lattice. +These parameters are redundant and are not shown to save space. +""" DO_NOT_SHOW_PARAMS_LIST + +DO_NOT_SHOW_PARAMS_LIST = Vector{Symbol}([:q_body, :q_body_tot, :drift_master]) + #--------------------------------------------------------------------------------------------------- # ele_name @@ -253,24 +264,6 @@ ele_param_value_str(branch::Branch; default::AbstractString = "???") = f"Branch ele_param_value_str(str::String; default::AbstractString = "???") = str_quote(str) ele_param_value_str(who; default::AbstractString = "???") = string(who) - -#--------------------------------------------------------------------------------------------------- -# IGNORE_ELE_PDICT_KEY - -""" - Array IGNORE_ELE_PDICT_KEY - -List of `Ele.pdict` keys to ignore when outputting the contents of an element. -Stuff to not output includes, for example, internal bookkeeping information. - -# To Ignore -• `:drift_master` - Used with drift elements that have been superimposed upon to enable mangling -of drift names. - -""" IGNORE_ELE_PDICT_KEY - -IGNORE_ELE_PDICT_KEY = [:drift_master] - #--------------------------------------------------------------------------------------------------- # show_ele @@ -290,7 +283,7 @@ function show_ele(io::IO, ele::Ele, docstring = false) if length(pdict) > 0 # Need test since will bomb on zero length dict # Print non-group, non-changed parameters first like the element index, branch ID, etc. for key in sort(collect(keys(pdict))) - if key in IGNORE_ELE_PDICT_KEY; continue; end + if key in DO_NOT_SHOW_PARAMS_LIST; continue; end val = pdict[key] if typeof(val) <: EleParams || key == :changed; continue; end if key == :name; continue; end @@ -298,9 +291,9 @@ function show_ele(io::IO, ele::Ele, docstring = false) param_name = rpad(string(key), nn2) value_str = ele_param_value_str(pdict, key) if docstring - ele_print_line(io, f" {param_name} {value_str} {units(key)}", description(key)) + ele_print_line(io, f" {param_name} {value_str} {param_units(key)}", description(key)) else - println(io, f" {param_name} {value_str} {units(key)}") + println(io, f" {param_name} {value_str} {param_units(key)}") end end @@ -328,9 +321,9 @@ function show_ele(io::IO, ele::Ele, docstring = false) param_name = rpad(repr(key), nn2) value_str = ele_param_value_str(changed, key) if docstring - ele_print_line(io, f" {param_name} {value_str} {units(key, eletype)}", description(key, eletype)) + ele_print_line(io, f" {param_name} {value_str} {param_units(key, eletype)}", description(key, eletype)) else - println(io, f" {param_name} {value_str} {units(key, eletype)}") + println(io, f" {param_name} {value_str} {param_units(key, eletype)}") end end end @@ -376,7 +369,7 @@ function show_elegroup(io::IO, group::BMultipoleParams, ele::Ele, docstring::Boo for v in group.pole ol = "$(v.order)" if !isnothing(v.integrated) && v.integrated; ol = ol * "L"; end - uk = units(Symbol("Kn$(ol)")); ub = units(Symbol("Bn$(ol)")) + uk = param_units(Symbol("Kn$(ol)")); ub = param_units(Symbol("Bn$(ol)")) Kn = "Kn$ol" Bn = "Bn$ol" println(io, "$(off_str)$(lpad(v.order,7))$(lpad(v.integrated,11))$(lpad(v.tilt,24))" * @@ -399,7 +392,7 @@ function show_elegroup(io::IO, group::EMultipoleParams, ele::Ele, docstring::Boo println(io, "$(off_str) Order Eintegrated $(lpad("Etilt (rad)",22))") for v in group.pole !isnothing(v.Eintegrated) && v.Eintegrated ? ol = "$(v.order)L" : ol = "$(v.order) " - ue = units(Symbol("En$(ol)")) + ue = param_units(Symbol("En$(ol)")) println(io, "$(off_str)$(lpad(v.order,7))$(lpad(v.Eintegrated,11))$(lpad(v.Etilt,24))$(lpad(v.En,24)) En$(ol)$(lpad(v.Es,24)) Es$(ol) ($ue)") end end @@ -418,10 +411,10 @@ function show_elegroup_with_doc(io::IO, group::T; ele::Ele, indent = 0) where T nn = max(18, maximum(length.(fieldnames(gtype)))) println(io, f" {gtype}:") - for field in associated_names(gtype) + for field in associated_names(gtype, exclude_do_not_show = true) param_name = rpad(full_parameter_name(field, gtype), nn) value_str = ele_param_value_str(ele, field) - ele_print_line(io, f" {param_name} {value_str} {units(field)}", description(field)) + ele_print_line(io, f" {param_name} {value_str} {param_units(field)}", description(field)) end end @@ -451,7 +444,7 @@ function show_elegroup_wo_doc(io::IO, group::BaseEleParams, ele::Ele; indent = 0 col2 = show_column2[gtype] n1 = 20 n2 = 20 - for name in associated_names(gtype) + for name in associated_names(gtype, exclude_do_not_show = true) if name in values(col2) n2 = max(n2, length(full_parameter_name(name, gtype))) else @@ -465,32 +458,32 @@ function show_elegroup_wo_doc(io::IO, group::BaseEleParams, ele::Ele; indent = 0 println(io, " "^indent * ".$group_show_name:") end - for field_sym in associated_names(gtype) + for field_sym in associated_names(gtype, exclude_do_not_show = true) if field_sym in values(col2); continue; end # Second column fields handled with first column ones. if field_sym in keys(col2) field_name = rpad(full_parameter_name(field_sym, gtype), n1) vstr = ele_param_value_str(ele, field_sym) - str = f" {field_name} {vstr} {units(field_sym)}" # First column entry + str = " $field_name $vstr $(param_units(field_sym))" # First column entry field2_sym = col2[field_sym] # If field2_sym represents a output parameter then field2_sym will not be in fieldnames(group) field_name = rpad(full_parameter_name(field2_sym, gtype), n2) vstr = ele_param_value_str(ele, field2_sym) - str2 = f" {field_name} {vstr} {units(field2_sym)}" # Second column entry. + str2 = " $field_name $vstr $(param_units(field2_sym))" # Second column entry. if length(str) > col_width_cut || length(str2) > col_width_cut # If length is too big print in two lines. println(io, " "^indent * str) println(io, " "^indent * str2) else # Can print as a single line. - println(io, " "^indent * f"{rpad(str, col_width_cut)}{str2}") + println(io, " "^indent * "$(rpad(str, col_width_cut))$str2") end else if field_sym in fieldnames(gtype) && typeof(getfield(group, field_sym)) <: EleParameterSubParams; continue; end field_name = rpad(full_parameter_name(field_sym, gtype), n1) vstr = ele_param_value_str(ele, field_sym) - println(io, " "^indent * f" {field_name} {vstr} {units(field_sym)}") + println(io, " "^indent * " $field_name $vstr $(param_units(field_sym))") end end # for field_sym in fieldnames(gtype) @@ -503,7 +496,7 @@ end full_parameter_name(field::Symbol, group::Type{T}) where T <: BaseEleParams For fields where the user name is different (EG: `r_floor` and `r` in a FloorParams), -return the string `struct_name (user_name)` (EG: `r (r_floor)`). Also add `(output)` to +return the string `struct_name (user_name)` (EG: `r (.r_floor)`). Also add `(output)` to names of output parameters. """ full_parameter_name diff --git a/src/struct.jl b/src/struct.jl index af74e8c..f2d171c 100644 --- a/src/struct.jl +++ b/src/struct.jl @@ -618,16 +618,16 @@ See the manual for details about how the three rotations are combined. ## Associated Output Parameters -The `tot` parameters are the body coordinates with respect to the branch coordinates. +The `_body_tot` parameters are the body coordinates with respect to the branch coordinates. These parameters are calculated by `AcceleratorLattice` and will be equal to the corresponding non-tot fields if there is no `Girder`. • `q_body::Quaternion` - `Quaternion` representation of `x_rot`, `y_rot`, `tilt` orientation. \\ -• `q_tot:: Quaternion` - `Quaternion` representation of orienttion with Girder shifts. \\ -• `offset_tot::Vector` - `[x, y, z]` offsets including Girder alignment shifts. \\ -• `x_rot_tot::Number` - Rotation around the x-axis including Girder alignment shifts. \\ -• `y_rot_tot::Number` - Rotation around the y-axis including Girder alignment shifts. \\ -• `z_rot_tot::Number` - Rotation around the z-axis including Girder alignment shifts. \\ +• `q_body_tot:: Quaternion` - `Quaternion` representation of orienttion with Girder shifts. \\ +• `offset_body_tot::Vector` - `[x, y, z]` offsets including Girder alignment shifts. \\ +• `x_rot_body_tot::Number` - Rotation around the x-axis including Girder alignment shifts. \\ +• `y_rot_body_tot::Number` - Rotation around the y-axis including Girder alignment shifts. \\ +• `z_rot_body_tot::Number` - Rotation around the z-axis including Girder alignment shifts. \\ """ @kwdef mutable struct BodyShiftParams <: EleParams