22 lines
657 B
Plaintext
22 lines
657 B
Plaintext
ClearAll[CreateVar, ImportConfig];
|
|
CreateVar[x_, y_String: "True"] := Module[{},
|
|
If[StringFreeQ[y, ","]
|
|
,
|
|
ToExpression[x <> "=" <> y]
|
|
,
|
|
ToExpression[x <> "={" <> StringJoin@Riffle[StringSplit[y, ","], ","] <> "}"]
|
|
]
|
|
]
|
|
ImportConfig[configfile_String] := Module[{data},
|
|
(*data = ImportString[configfile, "List", "Numeric" -> False];*)
|
|
data=Import[configfile,"List","Numeric"\[Rule]False];
|
|
|
|
data = StringTrim /@ data;
|
|
data = Select[data, # =!= "" &];
|
|
data = Select[data, ! StringMatchQ[#, "#" | ";" ~~ ___] &];
|
|
data = If[! StringFreeQ[#, " "], StringSplit[#, " ", 2], {#}] & /@ data;
|
|
|
|
CreateVar @@@ data;
|
|
]
|
|
ImportConfig[file]
|