amrex.jl 1.61 KB
Newer Older
William F Godoy's avatar
William F Godoy committed
1

2
3
4
abstract type AbstractAmrex <: AbstractExtractor end

mutable struct Amrex <: AbstractAmrex 
William F Godoy's avatar
William F Godoy committed
5
6
7
  app::String
  outputPrefix::String
  degreesOfFreedom
8
9
  
  Amrex() = new()
William F Godoy's avatar
William F Godoy committed
10
11
end

William F Godoy's avatar
William F Godoy committed
12
13
14
15
16
17
18
"""
   
   initialize members of the extractor::Amrex type
   Using bang convention as init modifies the extractor::Amrex
   https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
"""
function init!(extractor::Amrex, outputPrefix::String)
William F Godoy's avatar
William F Godoy committed
19
20
  extractor.app = "Amrex"
  extractor.outputPrefix = outputPrefix
21
  extractor.degreesOfFreedom = [ 
William F Godoy's avatar
William F Godoy committed
22
23
24
25
26
27
            "max_step", 
            "amr.check_int",
            "amr.plot_int",
            "amr.n_cell",
            "amr.max_level"
        ]
28
29
end

William F Godoy's avatar
William F Godoy committed
30
31
32
33
34
35
36
"""
    Parses an input file with entries key = value, returns all entries in a Dict
    # Arguments
    - `extractor::AbstractAmrex` : input type extending AbstractAmrex
    - `inputFile::String` : input file to be parsed, absolute path is preferred
"""
function input_parser(extractor::AbstractAmrex, inputFile::String)::Dict{String,String} 
37
  
William F Godoy's avatar
William F Godoy committed
38
39
  parameters = Dict{String,String}()
  # get file contents in a single iterable type, \n newline is removed 
40
41
  fileContents = readlines(inputFile)
  
William F Godoy's avatar
William F Godoy committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  # go through each line
  for line in fileContents
    
    if isempty(line)
      continue  
    end
    
    # remove comments marked with #
    result = findfirst("#", line)
    
    if isnothing(result) == false
      line = SubString(line, 1, result[1]-1)
      if isempty(line)
        continue
      end
    end
    
    parameter = split(line,"=")
    parameters[strip(parameter[1])] = strip(parameter[2])
    
  end 
63
  
William F Godoy's avatar
William F Godoy committed
64
  return parameters  
William F Godoy's avatar
William F Godoy committed
65
end