Victor-Garcia-p / DWF-Model

Undergraduate thesis project for Marine Sciences degree at University of Barcelona
0 stars 0 forks source link

Unnecessary path verification #12

Closed rogersamso closed 2 years ago

rogersamso commented 2 years ago

In the plots2d.jl file you do this:

path = joinpath(@__DIR__, "grids_generation.jl")
filepath_in= joinpath(@__DIR__, "..", "data","model_data_sim.jld2")

if isfile(path)
    include(path)
else
    # Put an error message
    error("Missing grid file") 
end

Verifying if the file exists is interesting if you expect your code to read from or write in this file during execution, and you are not sure the file will be there. However, the grids_generation.jl file is just part of your code, and you are pretty sure it will be there. Besides, the grids_generation.jl is in the same folder than the plots2d.jl file, therefore the include method does not need the full path of the file to find it. Therefore, you can remove the path variable and remove the isfile validation and just write:

include("grids_generation.jl")
rogersamso commented 2 years ago

Also, in case you don't know this, since grids_generation.jl is a script (it contains executable code, not functions), when you include it in the plots2d.jl file, it will run all the code that is in the grids_generation.jl.

In other words, every time you run the plots2d.jl file, you are also running the grids_generation.jl file.

Victor-Garcia-p commented 2 years ago

@rogersamso I have changed the verification in all the files. For the other question, I know that "include" with an script will make it to execute but I don't know more ways to load the code. I am really interested in loading functions, tomorrow, so I will ask more about the topic.