# How to make standard Julia package with input/options parameters in non compiled Julia files

**URL:** https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549
**Category:** Package Management
**Created:** [May 4, 2021, 10:33pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549 "2021-05-04T22:33:45Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)
#### Post date: [May 4, 2021, 10:33pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/1 "2021-05-04T22:33:45Z")

</div>

I wrote a large scientific package SoilWater-ToolBox [https://github.com/joseph-pollacco/SoilWaterToolbox](https://github.com/joseph-pollacco/SoilWaterToolbox) and now it is time to compile the software into a **Julia Package**

The question is that I have different options of the model in a File _Option.jl_ and would like users to modify the options before running the **SoilWater-ToolBox.**

`The question would it be possible to compile SoilWater-ToolBox and at the same time give the users the possibilities to modify the **Option.jl**?`

**EXAMPLE OF OPTION FILES?**

````julia
module option
const HydroTranslateModel = false # <true>; <false>
      const Hypix = false # <true>; <false>
      const Smap = true # <true> ; <false>
      const BulkDensity = false # <true> <false>
      const θΨ = :Opt # <:Opt>* Optimize hydraulic parameters from θ(Ψ); <:File> from save file; <:No> not available
      const Psd = false	# <true> Derive θ(Ψ) AND/OR hydraulic parameters from Psd; <false>
      const Infilt = false # <true> Derive θ(Ψ) AND/OR hydraulic parameters from Infiltration data; <false>
      const Temporary = false # <true>; <false>
     const Jules = false # <true>; <false>
     		# PLOTTING
      const Plot = false # <true>* plot; <false> no plotting
      const Plot_Show = false # <true>* plot shown in VScode; <false>```
````

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [May 4, 2021, 11:36pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/2 "2021-05-04T23:36:18Z")

</div>

Usually those options would be out in a structure, which may be set by the user and passed to the functions.

The idea of the user modifying a file that actually belongs to the package is not very nice. The alternative I think is to provide an example file that the user should follow and where those variables are defined.

(Note that defining the model with global constants won’t allow the user to run two different models in the same script. I don’t know if that is ok).

---

<div class="post-metadata">

### Author: ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)
#### Post date: [May 5, 2021, 3:03am UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/3 "2021-05-05T03:03:58Z")

</div>

> [@lmiq](#):
>
> Usually those options would be out in a structure, which may be set by the user and passed to the functions.

Thanks for conforming that when a function is compiled into a Package  
it cannot read Julia files as input. As recommended, I will put the _Options_ into a `structure` and read the parameters from a separate input file which will be object of another topic [Discourse](https://discourse.julialang.org/t/what-recommended-format-of-input-parameters-options-of-a-large-hydrological-model-compiled-as-a-julia-package/60561)

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [May 5, 2021, 5:41am UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/4 "2021-05-05T05:41:09Z")

</div>

Store your options in a JSON or TOML file and read that.

(You’re at Landcare? Hi from New Zealand. cc @mortenpi)

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [May 5, 2021, 11:47am UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/5 "2021-05-05T11:47:10Z")

</div>

I use something like this:

```julia
julia> using Parameters, JSON3, StructTypes
       @with_kw struct Options
          opt1::Bool = 1
          opt2::Float64 = 1.0
       end
       StructTypes.StructType(::Type{Options}) = StructTypes.Struct() #needed for JSON

julia> opt = Options(opt2=5.0)
Options
  opt1: Bool true
  opt2: Float64 5.0

julia> JSON3.write("test.dat",opt)
"test.dat"

julia> my_saved_options = JSON3.read(open("test.dat","r"),Options)
Options
  opt1: Bool true
  opt2: Float64 5.0

```

The user defines the `opt` variable, which sets some options he/she wants to change, and passes that variable to the solvers, inner functions, etc.

---

<div class="post-metadata">

### Author: ![rayegun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayegun/32/26729_2.png) [@rayegun](https://discourse.julialang.org/u/rayegun)
#### Post date: [May 5, 2021, 12:29pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/6 "2021-05-05T12:29:03Z")

</div>

Would Preferences.jl work?

---

<div class="post-metadata">

### Author: ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)
#### Post date: [May 6, 2021, 11:27pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/7 "2021-05-06T23:27:15Z")

</div>

Thanks for your help. I understand that in JULIA we have 4 formats to write input parametersand then read them **automatically** into` mutable struct`:

- CSV (I know how to read csv automatically into struct but not very good for giving explanations of the different options available);
- JSON (You must love {{{}}} );
- YAML;
- TOML;

My question which format is more readable for humans and which one will more easily read them **automatically** into` mutable struct`?

Thanks for any suggestions 😀 ?

---

<div class="post-metadata">

### Author: ![JosephPollacco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josephpollacco/32/51404_2.png) [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)
#### Post date: [May 6, 2021, 11:30pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/8 "2021-05-06T23:30:27Z")

</div>

Thanks for the example. Would this be the same code for TOML ?

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [May 6, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-make-standard-julia-package-with-input-options-parameters-in-non-compiled-julia-files/60549/9 "2021-05-06T23:37:55Z")

</div>

> [@JosephPollacco](#):
>
> which format is more readable for humans

TOML
