mmana2nec 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3b9da81be69b8e15569d1da5cd4fc96d20e2c857364653867a3e7a737a372de5
4
+ data.tar.gz: 5ffc0b7ce243bb16ef50a05ab700678f8686cee36f86b1155d516ccfce85bf22
5
+ SHA512:
6
+ metadata.gz: 53eddc6210716d400c656a33880a2cd3a26cac36cebe35a7fca16def95b7342dccc76588acfcfa86c29068b9353c290f7a61ce7fe5d5bc4e148531b11bbe6525
7
+ data.tar.gz: f047b96aefde8c88b5b34da696b97a91dde2319a4d93b9506dee7ff169ffe299b614f211e5372e3e57e872f69d44623d5a05060bc53310a4d45546b3f7358638
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ mmana2nec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mmana2nec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,31 @@
1
+ Copyright (c) 2019 Grant T. Olson
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of the Grant T. Olson nor the names of
17
+ additional contributors may be used to endorse or promote
18
+ products derived from this software without specific prior
19
+ written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Mmana2nec
2
+
3
+ This is a work-in-progress command line utility to convert various
4
+ antenna model formats.
5
+
6
+ ## End User Install
7
+
8
+ Assuming a working ruby environment on your system, run 'gem install
9
+ mmana2nec'. Getting a working ruby environment is left as an exercise
10
+ to the reader.
11
+
12
+ ## Command Line Usage
13
+
14
+ Generate mmanafile.nec from mmanafile.maa:
15
+
16
+ ```
17
+ mmana2nec mmanafile.maa
18
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mmana2nec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/mmana2nec ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mmana2nec'
4
+
5
+ Mmana2nec::CLI.mmana2nec()
data/lib/mmana2nec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "mmana2nec/version"
2
+
3
+ module Mmana2nec
4
+ class Error < StandardError; end
5
+ end
6
+
7
+ require 'mmana2nec/intermediate_format'
8
+ require 'mmana2nec/nec_processor'
9
+ require 'mmana2nec/mmana_processor'
10
+ require 'mmana2nec/cli'
@@ -0,0 +1,28 @@
1
+ require 'mmana2nec'
2
+ require 'optimist'
3
+
4
+ module Mmana2nec
5
+ module CLI
6
+ def self.mmana2nec
7
+
8
+ opts = Optimist::options do
9
+ opt :frequency, "Specify default frequency in Mhz", :type => :float
10
+ end
11
+
12
+ file_names = ARGV
13
+
14
+ raise "NEED FILE" if file_names.empty?
15
+
16
+ file_names.each do |file_name|
17
+
18
+ Dir.glob(file_name).each do |file_name|
19
+ intermediate_format = Mmana2nec::MmanaProcessor.new.process_file(file_name)
20
+
21
+ new_file = file_name.split(".")[0] + ".nec"
22
+ Mmana2nec::NecProcessor.write(intermediate_format, new_file)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ module Mmana2nec
2
+ class IntermediateFormat
3
+ attr_accessor :wires, :sources, :loads, :segmentation, :frequency
4
+ def initialize
5
+ @wires = []
6
+ @sources = []
7
+ @loads = []
8
+ @segmentation = []
9
+ @frequency ||= 7.0
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,136 @@
1
+ module Mmana2nec
2
+ class MmanaProcessor
3
+
4
+ def new_section?
5
+ (lines.empty? || lines[-1].start_with?("***"))
6
+ end
7
+
8
+ def extract_data
9
+ lines.pop.split(",\t").map {|x| x.include?("w") ? x : x.to_f}
10
+ end
11
+
12
+ def process_list
13
+ list_contents = []
14
+ list_count = lines.pop.to_i
15
+ until new_section?
16
+ list_contents << extract_data
17
+ end
18
+
19
+ if list_contents.length != list_count
20
+ raise "Length check failed"
21
+ end
22
+
23
+ list_contents
24
+
25
+ end
26
+
27
+ def process_wires
28
+ wire_lengths = {}
29
+ wires = []
30
+
31
+ process_list.each_with_index do |data, index|
32
+ x1, y1, z1, x2, y2, z2, diameter, segments = data
33
+
34
+ wire_length = Math.sqrt( (x2-x1) ** 2 + (y2 - y1) ** 2 + (z2 - z1) ** 2)
35
+ wire_lengths[index] = wire_length
36
+
37
+ if segments < -1
38
+ raise "Can't process segment type #{segments}"
39
+ end
40
+
41
+ wires << {end_one: {x: x1, y: y1, z: z1},
42
+ end_two: {x: x2, y: y2, z: z2},
43
+ diameter: diameter,
44
+ segments: segments
45
+ }
46
+
47
+ end
48
+
49
+ wire_lengths = wire_lengths.values.sort
50
+ shortest_wire = wire_lengths[0]
51
+ longest_wire = wire_lengths[-1]
52
+
53
+ if longest_wire >= (shortest_wire * 5) #must use shortest wire or smaller as segment size
54
+ segment_length = shortest_wire
55
+ else # can use any segment size
56
+ wavelength = 300.0 / intermediate_format.frequency
57
+ segment_length = wavelength / (2 * 20) # Half wavelength / 20. What is correct fudge factor?
58
+ end
59
+
60
+ wires.each_with_index do |wire, index|
61
+ if wire[:segments] == -1
62
+ wire_length = wire_lengths[index]
63
+ segments = (wire_length / segment_length).to_i
64
+ segments += 1 if (segments * segment_length) != wire_length
65
+ wire[:segments] = segments
66
+ end
67
+ end
68
+
69
+
70
+ intermediate_format.wires = wires
71
+ end
72
+
73
+ def process_source
74
+ intermediate_format.sources = process_list.map { |data|
75
+ connection, phase, voltage = data
76
+ raise "Unexpected connection value #{connection.inspect}" if !connection.start_with?("w")
77
+ wire = connection[1..-2].to_i
78
+ segment = connection[-1]
79
+
80
+ # TODO: Figure out center and end once we have real segments
81
+ raise "Don't know how to handle segment type #{segment}" if segment != "b"
82
+ segment = 1
83
+
84
+ {wire: wire, segment: segment, phase: phase, voltage: voltage}
85
+ }
86
+
87
+ end
88
+
89
+ def process_load
90
+ intermediate_format.loads = process_list
91
+
92
+ if intermediate_format.loads.length > 0
93
+ raise "Didn't deal with loads yet!"
94
+ end
95
+ end
96
+
97
+ def process_segmentation
98
+ dm1, dm2, sc, ec = extract_data
99
+ intermediate_format.segmentation = {dm1: dm1, dm2: dm2, sc: sc, ec: ec}
100
+ end
101
+
102
+ def process_g_h_m_r_azel_x
103
+ ground_type, h, m, impedance, azimuth, elevation, x = extract_data
104
+ # Figure this out later!
105
+ end
106
+
107
+ attr_reader :lines, :intermediate_format
108
+ def process_file file_name
109
+
110
+ file = File.open(file_name)
111
+
112
+ @lines = file.readlines.map { |x| x.gsub("\r","").gsub("\n", "") }.reverse
113
+ @intermediate_format = IntermediateFormat.new
114
+ #header
115
+
116
+ name = lines.pop
117
+ unknown_header_1 = lines.pop
118
+ unknown_header_2 = lines.pop
119
+
120
+ while !lines.empty?
121
+ current_section = lines.pop
122
+ if !current_section.start_with?("***")
123
+ raise "BAD FILE FORMAT"
124
+ end
125
+
126
+ current_section = current_section[3..-4]
127
+
128
+ section_method = "process_" + current_section.downcase.gsub("/","_")
129
+
130
+ send(section_method)
131
+ end
132
+
133
+ @intermediate_format
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,45 @@
1
+ module Mmana2nec
2
+ class NecProcessor
3
+ def self.write intermediate_format, output_file
4
+ file = File.open(output_file, "w", crlf_newline: true)
5
+
6
+ # Comment end
7
+ file.puts("CM Generated by mmana2nec")
8
+ file.puts("CE")
9
+
10
+ # Wires
11
+ intermediate_format.wires.each_with_index do |w, index|
12
+ index = index + 1
13
+
14
+ end_one = w[:end_one]
15
+ end_two = w[:end_two]
16
+ segments = w[:segments]
17
+ 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)]
18
+ file.puts(gw.join(" "))
19
+
20
+ end
21
+ file.puts("GE 1")
22
+
23
+ # Frequency
24
+ file.puts("FR 0 1 0 0 #{intermediate_format.frequency} 0")
25
+
26
+ # Source
27
+
28
+ intermediate_format.sources.each do |source|
29
+ excitation_type = 0 #Only supported type now
30
+ wire = source[:wire]
31
+ segment = source[:segment]
32
+ voltage = source[:voltage]
33
+ phase = source[:phase]
34
+
35
+ source = ["EX", excitation_type, wire, segment, 0, voltage, phase]
36
+
37
+ file.puts(source.join(" "))
38
+ end
39
+ # END
40
+ file.puts("EN")
41
+
42
+ file.close
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Mmana2nec
2
+ VERSION = "0.1.1"
3
+ end
data/mmana2nec.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mmana2nec/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mmana2nec"
8
+ spec.version = Mmana2nec::VERSION
9
+ spec.authors = ["Grant T. Olson"]
10
+ spec.email = ["kgo@grant-olson.net"]
11
+
12
+ spec.summary = "Utility to convert various antenna model formats."
13
+ spec.homepage = "https://github.com/grant-olson/mmana2nec"
14
+
15
+ spec.license = "BSD-3-Clause"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "optimist", "~> 3.0"
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ end
@@ -0,0 +1,23 @@
1
+ Multiband vertical
2
+ *
3
+ 0.0
4
+ ***Wires***
5
+ 9
6
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.15, 1.200e-04, -1
7
+ 0.0, 0.0, 0.15, 0.15, 0.0, 0.15, 1.200e-04, -1
8
+ 0.0, 0.0, 0.15, -0.15, 0.0, 0.15, 1.200e-04, -1
9
+ 0.0, 0.0, 0.15, 0.0, 0.15, 0.15, 1.200e-04, -1
10
+ 0.0, 0.0, 0.15, 0.0, -0.15, 0.15, 1.200e-04, -1
11
+ 0.0, 0.15, 0.15, 0.0, 0.15, 10.15, 1.200e-04, -1
12
+ 0.0, -0.15, 0.15, 0.0, -0.15, 5.15, 1.200e-04, -1
13
+ 0.15, 0.0, 0.15, 0.15, 0.0, 2.65, 1.200e-04, -1
14
+ -0.15, 0.0, 0.15, -0.15, 0.0, 3.15, 1.200e-04, -1
15
+ ***Source***
16
+ 1, 0
17
+ w1b, 0.0, 1.0
18
+ ***Load***
19
+ 0, 0
20
+ ***Segmentation***
21
+ 800, 80, 2.0, 2
22
+ ***G/H/M/R/AzEl/X***
23
+ 2, 0.0, 0, 50.0, 120, 60, 0.0
@@ -0,0 +1,27 @@
1
+ CE
2
+ GW 1 2 0 0 0 0 0 0.15 0.002
3
+ GW 2 2 0 0 0.15 0.15 0 0.15 0.002
4
+ GW 3 2 0 0 0.15 -0.15 0 0.15 0.002
5
+ GW 4 2 0 0 0.15 0 0.15 0.15 0.002
6
+ GW 5 2 0 0 0.15 0 -0.15 0.15 0.002
7
+ GW 6 38 0 0.15 0.15 0 0.15 10.15 0.002
8
+ GW 7 20 0 -0.15 0.15 0 -0.15 5.15 0.002
9
+ GW 8 10 0.15 0 0.15 0.15 0 2.65 0.002
10
+ GW 9 12 -0.15 0 0.15 -0.15 0 3.15 0.002
11
+ GS 0 0 1
12
+ GE 1
13
+ LD 2 1 1 2 0 3.54859E-07 0
14
+ LD 2 2 1 2 0 3.54859E-07 0
15
+ LD 2 3 1 2 0 3.54859E-07 0
16
+ LD 2 4 1 2 0 3.54859E-07 0
17
+ LD 2 5 1 2 0 3.54859E-07 0
18
+ LD 2 6 1 38 0 3.54859E-07 0
19
+ LD 2 7 1 20 0 3.54859E-07 0
20
+ LD 2 8 1 10 0 3.54859E-07 0
21
+ LD 2 9 1 12 0 3.54859E-07 0
22
+ GN 1
23
+ FR 0 1 0 0 14 0
24
+ EX 0 1 1 0 1.0000 0.0000
25
+ RP 0 1 360 1000 70 0 0 1
26
+ RP 0 181 1 1000 90 0 -1 0
27
+ EN
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmana2nec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Grant T. Olson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: optimist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - kgo@grant-olson.net
58
+ executables:
59
+ - mmana2nec
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - exe/mmana2nec
73
+ - lib/mmana2nec.rb
74
+ - lib/mmana2nec/cli.rb
75
+ - lib/mmana2nec/intermediate_format.rb
76
+ - lib/mmana2nec/mmana_processor.rb
77
+ - lib/mmana2nec/nec_processor.rb
78
+ - lib/mmana2nec/version.rb
79
+ - mmana2nec.gemspec
80
+ - sample_models/multiband_vertical.maa
81
+ - sample_models/multiband_vertical_from_nec2_for_mmana.nec
82
+ homepage: https://github.com/grant-olson/mmana2nec
83
+ licenses:
84
+ - BSD-3-Clause
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.0.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Utility to convert various antenna model formats.
105
+ test_files: []