AnsweredAssumed Answered

Sum duplicate entries from input data file

Question asked by amarv on Nov 30, 2017
Latest reply on Dec 1, 2017 by Susanne.Heip

Is there a command to sum duplicate entries from an input data file in an "initializations from..." block?


For example, if I have a file input.dat:

Cost: [

(A) 1

(A) 2

(B) 5


and my Mosel code contains:


Materials: set of string

Cost: array(Materials) of real



initializations from "input.dat"




forall(m in Materials) writeln(m + " costs: " + Cost(m))


I'd like to see that Material "A" costs 3 ( = 1+2 ), but will instead see that it costs 2 (only the last duplicate value in the data file overwrites all previous duplicates). I understand that this is intended behavior, and that I could seek to do the summation on my data source, but is there an easy way to do this in Mosel?