Skip to content

Commit

Permalink
deleted strings options for setunits
Browse files Browse the repository at this point in the history
  • Loading branch information
lllx125 committed Nov 4, 2024
1 parent 9b94371 commit 6094656
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions src/set_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
ACCELERATOR

const ACCELERATOR = [
"eV/c^2",
"m",
"s",
"eV",
"e"]
u"eV/c^2",
u"m",
u"s",
u"eV",
u"e"]

# MKS
"""
Expand All @@ -31,11 +31,11 @@ const ACCELERATOR = [
MKS

const MKS = [
"kg",
"m",
"s",
"J",
"C"]
u"kg",
u"m",
u"s",
u"J",
u"C"]
# quasi-CGS
"""
CGS
Expand All @@ -49,11 +49,11 @@ const MKS = [
CGS

const CGS = [
"g",
"cm",
"s",
"J",
"C"]
u"g",
u"cm",
u"s",
u"J",
u"C"]

"""
setunits(unitsystem::UnitSystem=ACCELERATOR;
Expand Down Expand Up @@ -99,29 +99,13 @@ Prints current units at the end (optional).
"""
setunits

function setunits(unitsystem::Vector{String}=ACCELERATOR;
mass_unit::Union{Unitful.FreeUnits,AbstractString}=unitsystem[1],
length_unit::Union{Unitful.FreeUnits,AbstractString}=unitsystem[2],
time_unit::Union{Unitful.FreeUnits,AbstractString}=unitsystem[3],
energy_unit::Union{Unitful.FreeUnits,AbstractString}=unitsystem[4],
charge_unit::Union{Unitful.FreeUnits,AbstractString}=unitsystem[5],
function setunits(unitsystem=ACCELERATOR;
mass_unit::Unitful.FreeUnits=unitsystem[1],
length_unit::Unitful.FreeUnits=unitsystem[2],
time_unit::Unitful.FreeUnits=unitsystem[3],
energy_unit::Unitful.FreeUnits=unitsystem[4],
charge_unit::Unitful.FreeUnits=unitsystem[5],
)
# convert types to Unitful.FreeUnits
if mass_unit isa AbstractString
mass_unit = uparse(mass_unit)
end
if length_unit isa AbstractString
length_unit = uparse(length_unit)
end
if time_unit isa AbstractString
time_unit = uparse(time_unit)
end
if energy_unit isa AbstractString
energy_unit = uparse(energy_unit)
end
if charge_unit isa AbstractString
charge_unit = uparse(charge_unit)
end
# check dimensions of units
if dimension(mass_unit) != dimension(u"kg")
throw(ErrorException("unit for mass does not have proper dimension"))
Expand Down

0 comments on commit 6094656

Please sign in to comment.