# Defining Unitful Units Programmatically

**URL:** <https://discourse.julialang.org/t/defining-unitful-units-programmatically/49260>\
**Category:** General Usage\
**Created:** [October 29, 2020, 8:07pm UTC](https://discourse.julialang.org/t/defining-unitful-units-programmatically/49260 "2020-10-29T20:07:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrPapa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drpapa/32/6835_2.png) [@DrPapa](https://discourse.julialang.org/u/DrPapa)\
**Post date:** [October 29, 2020, 8:07pm UTC](https://discourse.julialang.org/t/defining-unitful-units-programmatically/49260/1 "2020-10-29T20:07:40Z")

</div>

I am processing some datasets involving altitude measurements that mixes MSL and AGL altitude units. I would like to define custom units to minimize opportunity for error. In my case, the reference offset altitude will be read from a file.

I would like to do something like:

```julia
using Unitful
Unitful.register(@ __MODULE__ )

@unit ft_MSL "ft_MSL" FtMSL 1*u"ft" false
function make_AGL_unit(f)
   msl_alt = alt_from_file(f) * u"ft_MSL"
   @affineunit ft_AGL "ft_AGL" $(altitude(dz))
end

```

However, interpolation doesn’t work, producing `LoadError: syntax: "$" expression outside quote`.
