Skip to content

Template for startup.jl

Andrea Neumayr edited this page Sep 28, 2021 · 10 revisions

Create your own startup file

This startup template defines how Julia is started. It defines which plotting package you are using and maybe you'd like to use package Revise, as well.

  1. Make sure you installed Julia and all packages. Otherwise the following steps won't work.
  2. Copy the template below
    • Whenever Julia is started, this startup.jl file is executed.
    • Store the template file under <path-to-julia-home>\.julia\config\startup.jl
  3. Create your folder, where you'd like to work.
    • Adapt the juliaWorkingDir variable to your needs (line 5) and save it, (be aware of using /)
  4. Choose your plotting package. This template shows examples for GLMakie and PyPlot.
    • Valid options are: GLMakie, WGLMakie, CairoMakie, PyPlot, NoPlot, SilentNoPlot
    • Make sure you add the corresponding Modia package: ModiaPlot_GLMakie, ModiaPlot_WGLMakie, ModiaPlot_CairoMakie, ModiaPlot_PyPlot
  5. Do you want to use Modia3D for 3D simulations and also visualize your results? Skip this point if not!
    • Download and install the free DLR SimVis Community Edition, e.g. with https://visualization.ltx.de/
    • Set an environment variable or add it to the startup.jl file (remove # in last line of template)
      • ENV["DLR_VISUALIZATION"] = "<path-to-library>/Visualization/Extras/SimVis"
      • remove # in last line of template, and adapt <path-to-library>
# Julia startup file
# This file should contain site-specific commands to be executed on Julia startup;
# Users may store their own personal commands in `~/.julia/config/startup.jl`.

# set variable: juliaWorkingDir, be aware of using /
juliaWorkingDir = "D:/work/julia"

println("... executing startup file ", @__FILE__)
println("... Julia package directories: ", DEPOT_PATH)

# Change Directory of Julia package directory (default: in %USERPROFILE%\.julia)
cd(juliaWorkingDir)
println("... Starting Julia in " * pwd())

# Use revise() in order that code changes are automatically compiled
# make sure you ] add Revise and remove #= =#
# (https://timholy.github.io/Revise.jl/stable/config.html)
#=
atreplinit() do repl
    @async try
        sleep(0.1)
        @eval using Revise
        @async Revise.wait_steal_repl_backend()
    catch
        @warn("Could not load Revise.")
    end
end
=#

### Plotting ###
# Options are: GLMakie, WGLMakie, CairoMakie, PyPlot, NoPlot, SilentNoPlot
# Use GLMakie (remove #= =#)
#=
ENV["MODIA_PLOT"] = "GLMakie"
println("... ENV[\"MODIA_PLOT\"] = \"", ENV["MODIA_PLOT"], "\"")
=#

# Use PyPlot, with Julia's Python (remove #= =#)
#=
ENV["PYTHON"] = ""
ENV["CONDA_JL_USE_MINIFORGE"] = "1"
ENV["MODIA_PLOT"] = "PyPlot"
println("... ENV[\"MODIA_PLOT\"] = \"", ENV["MODIA_PLOT"], "\"")
=#

# Use the DLR Visualization Library for visualizing 3D models, adapt the path to SimVis installation and remove #
# ENV["DLR_VISUALIZATION"] = "<path-to-library>/Visualization/Extras/SimVis"
Clone this wiki locally