~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/lua/x26.lua

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--[[ -*- coding: utf-8 -*-
 
2
   
 
3
   $Id: x26.lua 11717 2011-04-21 00:47:06Z airwin $
 
4
 
 
5
   Multi-lingual version of the first page of example 4.
 
6
 
 
7
   Copyright (C) 2009 Werner Smekal
 
8
 
 
9
   Thanks to the following for providing translated strings for this example:
 
10
   Valery Pipin (Russian)
 
11
  
 
12
   This file is part of PLplot.
 
13
    
 
14
   PLplot is free software you can redistribute it and/or modify
 
15
   it under the terms of the GNU Library General Public License as published
 
16
   by the Free Software Foundation either version 2 of the License, or
 
17
   (at your option) any later version.
 
18
   
 
19
   PLplot is distributed in the hope that it will be useful,
 
20
   but WITHOUT ANY WARRANTY without even the implied warranty of
 
21
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
   GNU Library General Public License for more details.
 
23
    
 
24
   You should have received a copy of the GNU Library General Public License
 
25
   along with PLplot if not, write to the Free Software
 
26
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
27
--]]
 
28
 
 
29
 
 
30
--[[
 
31
  This example designed just for devices (e.g., psttfc and the
 
32
  cairo-related devices) that use the pango and fontconfig libraries. The
 
33
  best choice of glyph is selected by fontconfig and automatically rendered
 
34
  by pango in way that is sensitive to complex text layout (CTL) language
 
35
  issues for each unicode character in this example. Of course, you must
 
36
  have the appropriate TrueType fonts installed to have access to all the
 
37
  required glyphs.
 
38
 
 
39
  Translation instructions: The strings to be translated are given by
 
40
  x_label, y_label, alty_label, title_label, and line_label below.  The 
 
41
  encoding used must be UTF-8.
 
42
 
 
43
  The following strings to be translated involve some scientific/mathematical 
 
44
  jargon which is now discussed further to help translators.
 
45
 
 
46
  (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel .
 
47
  (2) degrees is an angular measure, see 
 
48
      http://en.wikipedia.org/wiki/Degree_(angle) .
 
49
  (3) low-pass filter is one that transmits (passes) low frequencies.
 
50
  (4) pole is in the mathematical sense, see
 
51
      http://en.wikipedia.org/wiki/Pole_(complex_analysis) .  "Single Pole"
 
52
      means a particular mathematical transformation of the filter function has
 
53
      a single pole, see
 
54
      http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html .  
 
55
      Furthermore, a single-pole filter must have an inverse square decline 
 
56
      (or -20 db/decade). Since the filter plotted here does have that 
 
57
      characteristic, it must by definition be a single-pole filter, see also
 
58
      http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm
 
59
  (5) decade represents a factor of 10, see
 
60
      http://en.wikipedia.org/wiki/Decade_(log_scale) .
 
61
--]]
 
62
 
 
63
-- initialise Lua bindings for PLplot examples.
 
64
dofile("plplot_examples.lua")
 
65
 
 
66
x_label = { "Frequency", "Частота" }
 
67
y_label = { "Amplitude (dB)", "Амплитуда (dB)" }
 
68
alty_label = { "Phase shift (degrees)", "Фазовый сдвиг (градусы)" }
 
69
-- Short rearranged versions of y_label and alty_label.
 
70
legend_text = {
 
71
  {"Amplitude", "Phase shift"},
 
72
  {"Амплитуда", "Фазовый сдвиг"}
 
73
  }
 
74
title_label = { "Single Pole Low-Pass Filter", "Однополюсный Низко-Частотный Фильтр" }
 
75
line_label = { "-20 dB/decade", "-20 dB/десяток" }
 
76
 
 
77
-- return single bit (for OR)
 
78
function bit(x,b)
 
79
  return (math.mod(x, 2^b) - math.mod(x,2^(b-1)) > 0)
 
80
end
 
81
 
 
82
-- logic OR for number values
 
83
 
 
84
function lor(x,y)
 
85
  result = 0
 
86
  for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and 2^(p-1) or 0) end
 
87
  return result
 
88
end
 
89
 
 
90
----------------------------------------------------------------------------
 
91
-- plot1
 
92
--
 
93
-- Log-linear plot.
 
94
----------------------------------------------------------------------------
 
95
 
 
96
function plot1(type, x_label, y_label, alty_label, title_label, line_label, legend_text)
 
97
  freql = {}
 
98
  ampl = {}
 
99
  phase = {}
 
100
 
 
101
  pl.adv(0)
 
102
 
 
103
  -- Set up data for log plot 
 
104
 
 
105
  f0 = 1
 
106
  for i = 1, 101 do
 
107
    freql[i] = -2 + (i-1)/20
 
108
    freq = 10^freql[i]
 
109
    ampl[i] = 20 * math.log10(1/math.sqrt(1+(freq/f0)^2))
 
110
    phase[i] = -180/math.pi*math.atan(freq/f0)
 
111
  end
 
112
 
 
113
  pl.vpor(0.15, 0.85, 0.1, 0.9)
 
114
  pl.wind(-2, 3, -80, 0)
 
115
 
 
116
  -- Try different axis and labelling styles. 
 
117
  pl.col0(1)
 
118
  if type==0 then
 
119
    pl.box("bclnst", 0, 0, "bnstv", 0, 0)
 
120
  elseif type==1 then
 
121
    pl.box("bcfghlnst", 0, 0, "bcghnstv", 0, 0)
 
122
  else
 
123
    pl.abort("type must be 0 or 1")
 
124
    pl.plend()
 
125
    os.exit()
 
126
  end
 
127
 
 
128
  -- Plot ampl vs freq 
 
129
  pl.col0(2)
 
130
  pl.line(freql, ampl)
 
131
  pl.col0(2)
 
132
  pl.ptex(1.6, -30, 1, -20, 0.5, line_label)
 
133
 
 
134
  -- Put labels on 
 
135
  pl.col0(1)
 
136
  pl.mtex("b", 3.2, 0.5, 0.5, x_label)
 
137
  pl.mtex("t", 2, 0.5, 0.5, title_label)
 
138
  pl.col0(2)
 
139
  pl.mtex("l", 5, 0.5, 0.5, y_label)
 
140
 
 
141
  -- For the gridless case, put phase vs freq on same plot 
 
142
  if type==0 then
 
143
    pl.col0(1)
 
144
    pl.wind(-2, 3, -100, 0)
 
145
    pl.box("", 0, 0, "cmstv", 30, 3)
 
146
    pl.col0(3)
 
147
    pl.line(freql, phase)
 
148
    pl.string(freql, phase, "*")
 
149
    pl.col0(3)
 
150
    pl.mtex("r", 5, 0.5, 0.5, alty_label)
 
151
    nlegend = 2
 
152
  else
 
153
    nlegend = 1
 
154
  end
 
155
 
 
156
  -- Draw a legend.
 
157
  opt_array = {}
 
158
  text_colors = {}
 
159
  text = {}
 
160
  box_colors = {}
 
161
  box_patterns = {}
 
162
  box_scales = {}
 
163
  box_line_widths = {}
 
164
  line_colors = {}
 
165
  line_styles = {}
 
166
  line_widths = {}
 
167
  symbol_colors = {}
 
168
  symbol_scales = {}
 
169
  symbol_numbers = {}
 
170
  symbols = {}
 
171
 
 
172
  -- Data for the first legend entry.
 
173
  opt_array[1] = pl.PL_LEGEND_LINE
 
174
  text_colors[1] = 2
 
175
  text[1] = legend_text[1]
 
176
  -- box data unused so initialize to arbitrary values.
 
177
  box_colors[1] = 0
 
178
  box_patterns[1] = 0
 
179
  box_scales[1] = 0
 
180
  box_line_widths[1] = 0
 
181
  line_colors[1] = 2
 
182
  line_styles[1] = 1
 
183
  line_widths[1] = 1
 
184
  -- unused arbitrary data
 
185
  symbol_colors[1]  = 0
 
186
  symbol_scales[1]  = 0
 
187
  symbol_numbers[1] = 0
 
188
  symbols[1]        = ""
 
189
 
 
190
  -- Data for the second legend entry.
 
191
  if nlegend > 1 then
 
192
    opt_array[2]      = lor(pl.PL_LEGEND_LINE, pl.PL_LEGEND_SYMBOL)
 
193
    text_colors[2]    = 3
 
194
    text[2]           = legend_text[2]
 
195
  -- box data unused so initialize to arbitrary values.
 
196
    box_colors[2] = 0
 
197
    box_patterns[2] = 0
 
198
    box_scales[2] = 0
 
199
    box_line_widths[2] = 0
 
200
    line_colors[2]    = 3
 
201
    line_styles[2]    = 1
 
202
    line_widths[2]    = 1
 
203
    symbol_colors[2]  = 3
 
204
    symbol_scales[2]  = 1.
 
205
    symbol_numbers[2] = 4
 
206
    symbols[2]        = "*"
 
207
  end
 
208
 
 
209
  pl.scol0a( 15, 32, 32, 32, 0.70 )
 
210
 
 
211
  legend_width, legend_height = pl.legend(
 
212
    lor(pl.PL_LEGEND_BACKGROUND, pl.PL_LEGEND_BOUNDING_BOX), 0, 0.0, 0.0,
 
213
    0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0,
 
214
    1., text_colors, text, 
 
215
    box_colors, box_patterns, box_scales, box_line_widths, 
 
216
    line_colors, line_styles, line_widths,
 
217
    symbol_colors, symbol_scales, symbol_numbers, symbols )
 
218
 
 
219
end
 
220
 
 
221
 
 
222
----------------------------------------------------------------------------
 
223
-- main
 
224
--
 
225
-- Illustration of logarithmic axes, and redefinition of window.
 
226
----------------------------------------------------------------------------
 
227
 
 
228
-- Parse and process command line arguments 
 
229
pl.parseopts(arg, pl.PL_PARSE_FULL)
 
230
 
 
231
-- Initialize plplot 
 
232
pl.init()
 
233
nlang = # x_label
 
234
if nlang ~= (# y_label) or 
 
235
  nlang ~= (# alty_label) or
 
236
  nlang ~= (# title_label) or
 
237
  nlang ~= (# line_label) or
 
238
   nlang ~= (# legend_text) then
 
239
  pl.abort("All data must be expressed in the same number of languages")
 
240
  pl.plend()
 
241
  os.exit()
 
242
end
 
243
 
 
244
pl.font(2)
 
245
-- Make log plots using two different styles. 
 
246
for i = 1, nlang do
 
247
  plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i],  line_label[i], legend_text[i])
 
248
end
 
249
 
 
250
pl.plend()