fname = "namelist.txt"  # Fortran namelist file
open(fname,"r") do fid
    for line in eachline(fid)
        line = strip(replace(line,","," "))
        (line[1] == '&' || line[1] == '/') && continue
        include_string("global const " * line)
    end
end

(Untested).  Note that it isn't necessary to declare the types--they will 
be inferred by the format in the file.  And since the variables are 
declared const, the types won't change.

--Peter

On Friday, June 6, 2014 2:21:37 PM UTC-7, Andrei Berceanu wrote:
>
> I have an input file with the following structure:
>
> INPUT:
>
> &indata
> run          = 1         ,
> in_sswf_rk   = 0         ,
> in_sswf_sp   = 200       ,
> kount_st     = 150         ,
> kount_end    = 150       ,
> kappa_C      = 0.12      ,
> ......
>
> How can I read all these parameters in Julia into global constants? I am 
> saying constants because I read that performance-wise it is not a good idea 
> to define global variables. Also, can I give each constant a specific type 
> (float, int)?
>
> PS: I guess in Python I would be using the ConfigParser module.
>
> Tnx!
>

Reply via email to