Class: Mmana2nec::NecProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/mmana2nec/nec_processor.rb

Class Method Summary collapse

Class Method Details

.write(intermediate_format, output_file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mmana2nec/nec_processor.rb', line 3

def self.write intermediate_format, output_file
  file = File.open(output_file, "w", crlf_newline: true)

  # Comment end
  file.puts("CM Generated by mmana2nec")
  file.puts("CE")

  # Wires
  intermediate_format.wires.each_with_index do |w, index|
    index = index + 1

    end_one = w[:end_one]
    end_two = w[:end_two]
    segments = w[:segments]
    gw = ["GW", index, segments, end_one[:x], end_one[:y], end_one[:z], end_two[:x], end_two[:y], end_two[:z],  "%f" % (w[:diameter] / 2.0)]
    file.puts(gw.join(" "))
    
  end
  file.puts("GE 1")

  # Frequency
  file.puts("FR 0 1 0 0 #{intermediate_format.frequency} 0")
  
  # Source

  intermediate_format.sources.each do |source|
    excitation_type = 0 #Only supported type now
    wire = source[:wire]
    segment = source[:segment]
    voltage = source[:voltage]
    phase = source[:phase]
  
    source = ["EX", excitation_type, wire, segment, 0, voltage, phase]
    
    file.puts(source.join(" "))
  end
  # END
  file.puts("EN")
  
  file.close
end