Module: NumRu::DCLExt

Defined in:
lib/numru/dclext.rb,
lib/numru/dclext_datetime_ax.rb

Constant Summary collapse

@@empty_hash =

<<< module data >>>

Hash.new
@@lon_ax_options =

<<< longitude/latitude axes package >>>

Misc::KeywordOptAutoHelp.new(
  ['yax', false, 'true => y-axis, false => x-axis'],
  ['cside', nil, '"b", "t", "l", "r", nil (=>left/bottom), or false (=>right/top)'],
  ['dtick1', nil, 'Interval of small tickmark (if nil, internally determined)'],
  ['dtick2', nil, 'Interval of large tickmark with labels (if nil, internally determined)']
)
@@lat_ax_options =
Misc::KeywordOptAutoHelp.new(
  ['xax', false, 'true => x-axis, false => y-axis'],
  ['cside', nil, '"b", "t", "l", "r", nil (=>left/bottom), or false (=>right/top)'],
  ['dtick1', nil, 'Interval of small tickmark (if nil, internally determined)'],
  ['dtick2', nil, 'Interval of large tickmark with labels (if nil, internally determined)']
)
@@unit_vect_options =
Misc::KeywordOptAutoHelp.new(
  ['vxunit', 0.05, "x unit vect len in V coord. Used only when fxunit is omitted (default)"],
  ['vyunit', 0.05, "y unit vect len in V coord. Used only when fyunit is omitted (default)"],
  ['vxuloc', nil, "Starting x position of unit vect"],
  ['vyuloc', nil, "Starting y position of unit vect"],
  ['vxuoff', 0.05, "Specify vxuloc by offset from right-bottom corner"],
  ['vyuoff', 0.0, "Specify vyuloc by offset from right-bottom corner"],
  ['inplace',true, "Whether to print labels right by the unit vector (true) or below the x axis (false)"],
  ['rsizet', nil, "Label size(default taken from uz-parameter 'rsizel1')"],
  ['index',  3," Line index of the unit vector"],
  ['vertical', true,"(used only in unit_vect_single) the unit vector is directed upward if true, to the right if not."]
)
@@next_unit_vect_options =
nil
@@color_bar_options =

<<< color bar >>>

Misc::KeywordOptAutoHelp.new(
  ["levels",  nil, "tone levels (if omitted, latest ones are used)"],
  ["patterns", nil, "tone patterns (~colors) (if omitted, latest ones are used)"],
  ["voff", nil, "how far is the bar from the viewport in the V coordinate"],
  ["vcent",nil, "center position of the bar in the V coordinate (VX or VY)"],
  ["vlength", 0.3, "bar length in the V coordinate"],
  ["vwidth", 0.02, "bar width in the V coordinate"],
  ["inffact", 2.25, "factor to change the length of triangle on the side for infinity (relative to 'vwidth')"],
  ["landscape", false, "if true, horizonlly long (along x axes)"],
  ["portrait", true, "if true, vertically long (along y axes)"],
  ["top",  false, "place the bar at the top (effective if landscape)"],
  ["left", false, "place the bar in the left (effective if portrait)"],
  ["units", nil, "units of the axis of the color bar"],
  ["units_voff", 0.0, "offset value for units from the default position in the V coordinate (only for 'units' != nil)"],
  ["title", nil, "title of the color bar"],
  ["title_voff", 0.0, "offset value for title from the default position in the V coordinate (only for 'title' != nil)"],
  ["tickintv", 1, "0,1,2,3,.. to specify how frequently the dividing tick lines are drawn (0: no tick lines, 1: every time, 2: ever other:,...)"],
  ["labelintv", nil, "0,1,2,3,.. to specify how frequently labels are drawn (0: no labels, 1: every time, 2: ever other:,... default: internally determined)"],
  ["labels_ud", nil, "user-defined labels for replacing the default labels (Array of String)"],
  ["charfact", 0.9, "factor to change the label/units/title character size (relative to 'rsizel1')"],
  ["log", false, "set the color bar scale to logarithmic"],
  ["constwidth", false, "if true, each color is drawn with the same width"],
  ["index", nil, "index of tick lines and bar frame"],
  ["charindex", nil, "index of labels, units, and title"],
  ["chval_fmt", nil, "string to specify the DCL.chval format for labeling"]
)
@@datetime_ax_options =
Misc::KeywordOptAutoHelp.new(
  ['yax', false, 'true => y-axis, false => x-axis'],
  ['cside', nil, '"b", "t", "l", "r", nil (=>left/bottom), or false (=>right/top)'],
  ['dtick1', 1, 'small tick interval in hours'],
  ['dtick2', nil, 'large tick (with hour labels) interval in hours'],
  ['year', false, 'true => add year to date label'],
  ['month', true, 'true => add month to date label']
)

Class Method Summary collapse

Class Method Details

.__truncate(float, order = 2) ⇒ Object

<<< flow vector package >>>



1110
1111
1112
1113
1114
1115
1116
# File 'lib/numru/dclext.rb', line 1110

def __truncate(float, order=2)
  # truncate (round) a floating number with the number digits
  # specified by "order".
  # e.g., if order=3, -0.012345 => -0.0123;  6.6666 => 6.67
  exponent = 10**(-Math::log10(float.abs).floor+order-1)
  (float * exponent).round.to_f/exponent
end

.color_bar(options = nil) ⇒ Object



1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
# File 'lib/numru/dclext.rb', line 1630

def color_bar(options=nil)

  # < set parameters >
  opt = @@color_bar_options.interpret(options)
  lsetx = DCL.uwqgxz
  lsety = DCL.uwqgyz

  rmiss = DCL.glrget('rmiss')

  levels = opt['levels']
  patterns = opt['patterns']

  if (levels.nil? && !patterns.nil?) || (!levels.nil? && patterns.nil?)
    raise "levels and patterns must be set at same time\n"
  end

  landscape = opt["landscape"] || !opt["portrait"]
  portrait  = ! landscape

  if !levels.nil?
    ue_set_tone(levels,patterns)
  end

  labels_ud = opt["labels_ud"]
  if !labels_ud.nil?
    if labels_ud.class != Array
      raise ArgumentError,"'labels_ud' must be an Array of String"
    elsif labels_ud.size == 0
      raise ArgumentError,"'labels_ud' must be an Array of String"
    else
      labels_ud.each do |lbl_ud|
        if lbl_ud.class != String
          raise ArgumentError,"'labels_ud' must be an Array of String"
        end
      end
    end
  end

  if opt["index"]
    index = opt["index"]
    index = 1 if index <= 0
  else
    index = DCL::uziget("indext2")
  end
  indext1_bk = DCL::uziget("indext1")
  indext2_bk = DCL::uziget("indext2")
  DCL::uziset("indext1",index)
  DCL::uziset("indext2",index)

  if opt["charindex"]
    charindex = opt["charindex"]
    charindex = 1 if charindex <= 0
  else
    charindex = DCL::uziget("indexl1")
  end
  indexl1_bk = DCL::uziget("indexl1")
  DCL::uziset("indexl1",charindex)

  charfact = opt["charfact"]
  rsizel1_bk = DCL::uzrget("rsizel1")
  DCL::uzrset("rsizel1",charfact*rsizel1_bk)

  nton = DCL::ueqntl
  if nton==0
    raise "no tone patern was set\n"
  end
  lev1 = Array.new
  lev2 = Array.new
  patterns = Array.new if !opt['patterns']
  for n in 0..nton-1
    tlev1,tlev2,ipat = DCL::ueqtlv(n+1)
    lev1.push(tlev1)
    lev2.push(tlev2)
    patterns.push(ipat) if !opt['patterns']
  end

  #levels = lev1+lev2
  #levels = levels.uniq.sort
  #levels.delete(rmiss)
  #if levels.ne(levels.sort).any?
  #  raise "levels is not in order\n"
  #end

  levels = lev1.push(lev2[-1]) if !levels
  levels = NArray.to_na(levels) if levels.is_a?(Array)
  patterns = NArray.to_na(patterns) if patterns.is_a?(Array)

  vx1, vx2, vy1, vy2 = DCL.sgqvpt

  if opt['log']
    lv = levels[levels.ne(rmiss).where]
    if lv.length >= 4 && lv[0]*lv[-1]<0
      iturn = 0
      for i in 0...levels.length
        if levels[i] != rmiss
          if levels[i]*lv[0] < 0
            iturn = i
            break
          end
        end
      end
      opt['vlength'] /= 2
      vc0 = opt['vcent'] || ( portrait && (vy1+vy2)/2) || (vx1+vx2)/2

      opt["voff"] ||=
            DCL.uzrget('pad1')*DCL::uzrget("rsizec2") +
           ( portrait ? DCL.uzrget('roffyr') : - DCL.uzrget('roffxb') )

      vsep2 = 0.02

      opt['levels']   = levels[0..iturn-1]
      opt['patterns'] = patterns[0..iturn-2]
      opt['vcent'] = vc0 - opt['vlength']/2 - vsep2
      units = opt['units']
      opt['units'] = nil
      color_bar(opt)

      opt['levels']   = levels[iturn..-1]
      opt['patterns'] = patterns[iturn..-1]
      opt['vcent'] = vc0 + opt['vlength']/2 + vsep2
      opt['units'] = units
      color_bar(opt)

      # fill between the two bars
      if portrait
        x1 = vx2 + opt["voff"]
        x2 = x1 + opt['vwidth']
        y1 = vc0 - vsep2
        y2 = vc0 + vsep2
      else
        x1 = vc0 - vsep2
        x2 = vc0 + vsep2
        y1 = vy1 - opt["voff"]
        y2 = y1 - opt['vwidth']
      end
      bk = DCLExt.sg_set_params({'lclip'=>false})
      DCL.sgtnzv([x1,x2,x2,x1],[y1,y1,y2,y2],patterns[iturn-1])
      DCL.sgplzv([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1],1,3)
      DCLExt.sg_set_params(bk)
      return
    end
  end

  if levels.length <= 1
    $stderr.print( "WARNING #{__FILE__}:#{__LINE__}: # of levels <= 1. No color bar is drawn." )
    return
  end

  # BACKUP CURRENT PARAMETERS
  itrsv = DCL::sgqtrn
  if itrsv <= 4
    ux1sv, ux2sv, uy1sv, uy2sv = DCL.sgqwnd
  elsif itrsv <= 9
    simfacsv, vxoffsv, vyoffsv = DCL.sgqsim
  else
    ux1sv, ux2sv, uy1sv, uy2sv = DCL.sgqwnd
    simfacsv, vxoffsv, vyoffsv = DCL.sgqsim
    #plxsv, plysv, plrotsv = DCL.sgqmpl()
    plxsv, plysv, plrotsv = DCL.umqcnt
    lglobesv = DCL::umpget('lglobe')
    grstxysv = %w(txmin txmax tymin tymax).map{|key| DCL::sgrget(key)}
  end
  # END OF BACKUP

  vwidth = opt["vwidth"]
  vlength = opt["vlength"]

  if portrait
    if !opt["left"]
      # left
      voff =  opt["voff"] ||
          DCL.uzrget('roffyr') + DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
      vxmin = vx2 + voff
      vxmax = vx2 + voff + vwidth
    else
      # right
      voff =  opt["voff"] ? -opt["voff"] : \
          DCL.uzrget('roffyl') - DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
      vxmax = vx1 + voff
      vxmin = vx1 + voff - vwidth
    end
    vymin =( opt["vcent"] ? opt["vcent"]-vlength/2 : vy1 )
    vymax =( opt["vcent"] ? opt["vcent"]+vlength/2 : vy1+vlength )
  else  ## landscape ##
    vxmin =( opt["vcent"] ? opt["vcent"]-vlength/2 : (vx1+vx2)/2-vlength/2 )
    vxmax =( opt["vcent"] ? opt["vcent"]+vlength/2 : (vx1+vx2)/2+vlength/2 )
    if opt["top"]
      # top
      voff =  opt["voff"] ||
           DCL.uzrget('roffxt') + DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
      vymin = vy2 + voff
      vymax = vy2 + voff + vwidth
    else
      # bottom
      voff =  opt["voff"] ? -opt["voff"] : \
           DCL.uzrget('roffxb') - DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
      vymax = vy1 + voff
      vymin = vy1 + voff - vwidth
    end
  end

  min = levels[levels.ne(rmiss).where].min
  max = levels[levels.ne(rmiss).where].max
  if levels[0] == rmiss
    inf0 = true
    dummy1,dummy2,ipat0 = DCL::ueqtlv(1)
    return if levels.length==2
  else
    inf0 = false
  end
  if levels[-1] == rmiss
    inf1 = true
    dummy1,dummy2,ipat1 = DCL::ueqtlv(nton)
    return if levels.length==2
  else
    inf1 = false
  end

  # < paint color tones >

  lclip_bk = DCL::sglget("lclip")
  DCL::sglset("lclip", false)

  inffact = opt["inffact"]
  if opt["constwidth"]

    if inf0
      levels = levels[1..-1]
      patterns = patterns[1..-1]
    end
    if inf1
      levels = levels[0..-2]
      patterns = patterns[0..-2]
    end
    nlev = levels.length
    npat = patterns.length

    if portrait
      vy = (NArray.sfloat(npat+1).indgen!)*(vymax-vymin)/npat + vymin

      # paint color tones for infinity (with drawing frame)
      if inf0
        vy3 = [vymin, vymin-vwidth*inffact, vymin]
        vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
        DCL.sgtnzv(vx3,vy3,ipat0)
        DCL.sgplzv(vx3,vy3,1,index)
      end
      if inf1
        vy3 = [vymax, vymax+vwidth*inffact, vymax]
        vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
        DCL.sgtnzv(vx3,vy3,ipat1)
        DCL.sgplzv(vx3,vy3,1,index)
      end

      # paint color tones for each range (with drawing long-side frame)
      for i in 0..npat-1
        DCL::sgtnzv([vxmin,vxmax,vxmax,vxmin],[vy[i],vy[i],vy[i+1],vy[i+1]],patterns[i])
        DCL::sgplzv([vxmin,vxmin],[vy[i],vy[i+1]],1,index)
        DCL::sgplzv([vxmax,vxmax],[vy[i],vy[i+1]],1,index)
      end

    else ## landscape ##
      vx = (NArray.sfloat(npat+1).indgen!)*(vxmax-vxmin)/npat + vxmin

      # paint color tones for infinity (with drawing frame)
      if inf0
        vx3 = [vxmin, vxmin-vwidth*inffact, vxmin]
        vy3 = [vymax, (vymax+vymin)/2, vymin]
        DCL.sgtnzv(vx3,vy3,ipat0)
        DCL.sgplzv(vx3,vy3,1,index)
      end
      if inf1
        vx3 = [vxmax, vxmax+vwidth*inffact, vxmax]
        vy3 = [vymax, (vymax+vymin)/2, vymin]
        DCL.sgtnzv(vx3,vy3,ipat1)
        DCL.sgplzv(vx3,vy3,1,index)
      end

      # paint color tones for each range (with drawing long-side frame)
      for i in 0..npat-1
        DCL::sgtnzv([vx[i],vx[i],vx[i+1],vx[i+1]],[vymin,vymax,vymax,vymin],patterns[i])
        DCL::sgplzv([vx[i],vx[i+1]],[vymin,vymin],1,index)
        DCL::sgplzv([vx[i],vx[i+1]],[vymax,vymax],1,index)
      end
    end

  else  ### opt["constwidth"] == false ###

    # paint color tones for infinity (with drawing frame)
    if portrait
      if inf0
        vy3 = [vymin, vymin-vwidth*inffact, vymin]
        vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
        DCL.sgtnzv(vx3,vy3,ipat0)
        DCL.sgplzv(vx3,vy3,1,index)
      end
      if inf1
        vy3 = [vymax, vymax+vwidth*inffact, vymax]
        vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
        DCL.sgtnzv(vx3,vy3,ipat1)
        DCL.sgplzv(vx3,vy3,1,index)
      end
    else ## landscape ##
      if inf0
        vx3 = [vxmin, vxmin-vwidth*inffact, vxmin]
        vy3 = [vymax, (vymax+vymin)/2, vymin]
        DCL.sgtnzv(vx3,vy3,ipat0)
        DCL.sgplzv(vx3,vy3,1,index)
      end
      if inf1
        vx3 = [vxmax, vxmax+vwidth*inffact, vxmax]
        vy3 = [vymax, (vymax+vymin)/2, vymin]
        DCL.sgtnzv(vx3,vy3,ipat1)
        DCL.sgplzv(vx3,vy3,1,index)
      end
    end

    # paint color tones for each range
    nbar = 100
    bar = NArray.float(nbar,2)
    for i in 0..nbar-1
      bar[i,true] = min + (max-min).to_f/(nbar-1)*i
    end

    xb = DCL::uzlget("labelxb")
    yl = DCL::uzlget("labelyl")
    if portrait
      xmin = 0.0
      xmax = 1.0
      ymin = min
      ymax = max
      DCL::uzlset("labelxb",false)
      DCL::uzlset("labelyl",true)
      bar = bar.transpose(-1,0)
      DCL::uwsgxa([0,1])
      DCL::uwsgya(bar[0,true])
    else
      xmin = min
      xmax = max
      ymin = 0.0
      ymax = 1.0
      DCL::uzlset("labelxb",true)
      DCL::uzlset("labelyl",false)
      DCL::uwsgxa(bar[true,0])
      DCL::uwsgya([0,1])
    end

    type = 1
    if opt["log"]
      type +=1
      type +=1 if !portrait
    end

    DCL::grfig
    DCL::grsvpt(vxmin,vxmax,vymin,vymax)
    DCL::grswnd(xmin,xmax,ymin,ymax)
    DCL::grstrn(type)
    DCL::grstrf

    DCL::uetone(bar)
    DCL.uwsgxz(false)
    DCL.uwsgyz(false)

  end

  # < set ticking and labeling levels >

  if opt["labelintv"]
    labelintv = opt["labelintv"]
  else
    ntn = nton
    ntn -= 1 if inf0
    ntn -= 1 if inf1
    if portrait
      labelintv = (ntn-1) / 9  + 1
    else
      labelintv = (ntn-1) / 5  + 1
    end
  end
  if labelintv <= 0
    no_label = true
    labelintv = 1
  else
    no_label = false
  end

  tickintv = opt["tickintv"]
  if tickintv <= 0
    no_tick = true
    tickintv = labelintv
  else
    no_tick = false
  end

  eps = 1e-5
  dummy = -9.9e-38
  dz = dzp = dzc = dummy
  idu = Array.new
  (1...levels.length).each do |i|
    dzc = (levels[i] - levels[i-1]).abs
    if (dzc-dzp).abs <= eps * [dzc.abs,dzp.abs].max
      dz = dzc  # set dz if two consecutive inrements are the same
      idu.push( i-1 )
    end
    dzp = (levels[i] - levels[i-1]).abs
  end
  if idu.length > 0
    idumin = idu.min - 1
    idumax = idu.max + 1
  else
    idumin = 0
    idumax = levels.length-1
  end
  if dz != dummy
#        if idumin == 1 and levels[0] != rmiss
#          # to correct non-uniform intv at the beginning
#          levels[0] = levels[1] - dz
#          idumin = 0
#          min = levels[0]
#        end
#        if idumax == levels.length-2 and levels[-1] != rmiss
#          # to correct non-uniform intv at the end
#          levels[-1] = levels[-2] + dz
#          idumax = levels.length-1
#          max = levels[-1]
#        end
    # use the algorithm used in DCL.udgcla
    offs_tick = ( (-levels[idumin]/dz).round % tickintv + idumin ) % tickintv
    offs_label = ( (-levels[idumin]/dz).round % labelintv + idumin ) % labelintv
  else
    md = 0
    if ( (idx=levels.eq(0.0).where).length > 0 )
      md = idx[0] % labelintv
    else
      a = levels[0...([labelintv,levels.length].min)]
      b = a * 10**( -NMath.log10(a.abs).floor.min )
      (0...b.length).each{|i| md=i if (b[i].round-b[i]).abs < 1e-5 }
    end
    offs_tick = (md % tickintv)
    offs_label = md
  end

  if levels.length >= 4
    lvmx = levels[1..-2].max
    lvmn = levels[1..-2].min
    dlv = (lvmx-lvmn) / (levels.length-3)
  elsif levels.length == 3 or levels.length == 2
    lvmn = lvmx = dlv = levels[1]
  else
    lvmn = lvmx = dlv = levels[0]
  end

  # < draw units, title, labels, and tick lines>

  if opt["constwidth"]

    if !no_label && labels_ud
      ilbl = 0
      for i in 0..nlev-1
        if (i % labelintv) == offs_label
          ilbl += 1
        end
      end
      if labels_ud.size != ilbl
        raise ArgumentError, "'labels_ud' must be an Array of length==#{ilbl} in this case"
      end
    end

    if portrait

      if voff > 0
        cent = -1
        vxlabel = vxmax+DCL::uzrget('pad1')*DCL::uzrget('rsizel1')
        # title
        DCL::sgtxzr(vxmin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), (vymin+vymax)/2.0+opt['title_voff'], opt['title'], DCL::uzrget('rsizel1'), 90, 0, charindex) if opt['title']
        # units
        DCL::sgtxzr(vxmax+DCL::uzrget('pad1')*DCL::uzrget('rsizel1'), vymax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      else
        cent = 1
        vxlabel = vxmin-DCL::uzrget('pad1')*DCL::uzrget('rsizel1')
        # title
        DCL::sgtxzr(vxmax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), (vymin+vymax)/2.0-opt['title_voff'], opt['title'], DCL::uzrget('rsizel1'), -90, 0, charindex) if opt['title']
        # units
        DCL::sgtxzr(vxmin-DCL::uzrget('pad1')*DCL::uzrget('rsizel1'), vymax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], opt['units'], DCL::uzrget('rsizel1'), 0, 1, charindex) if opt['units']
      end

      ilbl_ud = 0
      for i in 0..nlev-1
        # labels
        if !no_label && (i % labelintv) == offs_label
          if labels_ud
            char = labels_ud[ilbl_ud]
            DCL::sgtxzr(vxlabel,vy[i],char,DCL::uzrget('rsizel1'),0,cent,charindex)
            ilbl_ud += 1
          else
            begin
              if(opt['chval_fmt'])
                char = DCL::chval(opt['chval_fmt'],levels[i])
              else
                char = sprintf_level(levels[i],lvmx,lvmn,dlv)
              end
              DCL::sgtxzr(vxlabel,vy[i],char,DCL::uzrget('rsizel1'),0,cent,charindex)
            rescue
              DCL::sgtxzr(vxlabel,vy[i],levels[i].to_s,DCL::uzrget('rsizel1'),0,cent,charindex)
            end
          end
        end
        # tick lines and short-side frame
        if (!no_tick && (i % tickintv) == offs_tick) || (!inf0 && i == 0) || (!inf1 && i == nlev-1)
          DCL::sgplzv([vxmin,vxmax],[vy[i],vy[i]],1,index)
        end
      end

    else  ## landscape ##
      if voff > 0
        vylabel = vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1')
        # title
        DCL::sgtxzr((vxmin+vxmax)/2.0+opt['title_voff'], vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['title'], DCL::uzrget('rsizel1'), 0, 0, charindex) if opt['title']
        # units
        DCL::sgtxzr(vxmax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      else
        vylabel = vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1')
        # title
        DCL::sgtxzr((vxmin+vxmax)/2.0+opt['title_voff'], vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['title'], DCL::uzrget('rsizel1'), 0, 0, charindex) if opt['title']
        # units
        DCL::sgtxzr(vxmax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      end

      ilbl_ud = 0
      for i in 0..nlev-1
        # labels
        if !no_label && (i % labelintv) == offs_label
          if labels_ud
            char = labels_ud[ilbl_ud]
            DCL::sgtxzr(vx[i],vylabel,char,DCL::uzrget('rsizel1'),0,0,charindex)
            ilbl_ud += 1
          else
            begin
              if(opt['chval_fmt'])
                char = DCL::chval(opt['chval_fmt'],levels[i])
              else
                char = sprintf_level(levels[i],lvmx,lvmn,dlv)
              end
              DCL::sgtxzr(vx[i],vylabel,char,DCL::uzrget('rsizel1'),0,0,charindex)
            rescue
              DCL::sgtxzr(vx[i],vylabel,levels[i].to_s,DCL::uzrget('rsizel1'),0,0,charindex)
            end
          end
        end
        # tick lines and short-side frame
        if (!no_tick && (i % tickintv) == offs_tick) || (!inf0 && i == 0) || (!inf1 && i == nlev-1)
          DCL::sgplzv([vx[i],vx[i]],[vymin,vymax],1,index)
        end
      end
    end

  else  ### opt["constwidth"] == false ###

    inner_bk = DCL::uziget('inner')
    uz_set_params('inner'=>1)

    tick1 = Array.new
    tick2 = Array.new
    for i in 0..levels.length-1
#          if i>=idumin && i<=idumax && levels[i]!=rmiss
      if levels[i]!=rmiss
        tick1.push(levels[i]) if (i % tickintv) == offs_tick
        tick2.push(levels[i]) if (i % labelintv) == offs_label
      end
    end

    if portrait

      if voff > 0
        before = uz_set_params('labelyl'=>false,'labelyr'=>true,'icentyr'=>-1.0)
      else
        before = uz_set_params('labelyl'=>true,'labelyr'=>false,'icentyl'=>1.0)
      end

      # draw frame, tick lines, and labels
      cfmt_bk = DCL::uyqfmt
      if opt["log"]
        fmt = opt['chval_fmt'] || "b"
      else
        fmt = opt['chval_fmt'] || level_chval_fmt(lvmx,lvmn,dlv)
      end
      DCL::uysfmt(fmt)

      rsizet1_bk = DCL::uzrget("rsizet1")
      rsizet2_bk = DCL::uzrget("rsizet2")
      uz_set_params('rsizet1'=>vwidth,'rsizet2'=>0.0)
      if no_label
        nl_labelxt = DCL::uzlget('labelxt')
        nl_labelxb = DCL::uzlget('labelxb')
        nl_labelyl = DCL::uzlget('labelyl')
        nl_labelyr = DCL::uzlget('labelyr')
        uz_set_params('labelxt'=>false,'labelxb'=>false,'labelyl'=>false,'labelyr'=>false)
      end
      if no_tick
        nt_rsizet1 = DCL::uzrget('rsizet1')
        DCL::uzrset("rsizet1",0.0)
      end

      if labels_ud
        if labels_ud.size != tick2.size
          raise ArgumentError, "'labels_ud' must be an Array of length==#{tick2.size} in this case"
        end
        nc = labels_ud.collect{|c| c.size}.max
        DCL::uyaxlb("l",tick1,tick2,labels_ud,nc)
        DCL::uyaxlb("r",tick1,tick2,labels_ud,nc)
      else
        DCL::uyaxnm("l",tick1,tick2)
        DCL::uyaxnm("r",tick1,tick2)
      end
      DCL::uxaxdv("b",1,index) if !inf0
      DCL::uxaxdv("t",1,index) if !inf1

      if no_tick
        DCL::uzrset("rsizet1",nt_rsizet1)
      end
      if no_label
        uz_set_params('labelxt'=>nl_labelxt,'labelxb'=>nl_labelxb,'labelyl'=>nl_labelyl,'labelyr'=>nl_labelyr)
      end
      DCL::uzrset("rsizet1",rsizet1_bk)
      DCL::uzrset("rsizet2",rsizet2_bk)

      DCL::uysfmt(cfmt_bk)

      if voff > 0
        # title
        DCL::sgtxzr(vxmin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), (vymin+vymax)/2.0+opt['title_voff'], opt['title'], DCL::uzrget('rsizel1'), 90, 0, charindex) if opt["title"]
        # units
        DCL::sgtxzr(vxmax+DCL::uzrget('pad1')*DCL::uzrget('rsizel1'), vymax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      else
        # title
        DCL::sgtxzr(vxmax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), (vymin+vymax)/2.0-opt['title_voff'], opt['title'], DCL::uzrget('rsizel1'), -90, 0, charindex) if opt["title"]
        # units
        DCL::sgtxzr(vxmin-DCL::uzrget('pad1')*DCL::uzrget('rsizel1'), vymax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], opt['units'], DCL::uzrget('rsizel1'), 0, 1, charindex) if opt['units']
      end

      uz_set_params(before)

    else  ## landscape ##

      if voff > 0
        before = uz_set_params('labelxt'=>true,'labelxb'=>false)
      else
        before = uz_set_params('labelxt'=>false,'labelxb'=>true)
      end

      # draw frame, tick lines, and labels
      cfmt_bk = DCL::uxqfmt
      if opt["log"]
        fmt = opt['chval_fmt'] || "b"
      else
        fmt = opt['chval_fmt'] || level_chval_fmt(lvmx,lvmn,dlv)
      end
      DCL::uxsfmt(fmt)

      rsizet1_bk = DCL::uzrget("rsizet1")
      rsizet2_bk = DCL::uzrget("rsizet2")
      uz_set_params('rsizet1'=>vwidth,'rsizet2'=>0.0)
      if no_label
        nl_labelxt = DCL::uzlget('labelxt')
        nl_labelxb = DCL::uzlget('labelxb')
        nl_labelyl = DCL::uzlget('labelyl')
        nl_labelyr = DCL::uzlget('labelyr')
        uz_set_params('labelxt'=>false,'labelxb'=>false,'labelyl'=>false,'labelyr'=>false)
      end
      if no_tick
        nt_rsizet1 = DCL::uzrget('rsizet1')
        DCL::uzrset("rsizet1",0.0)
      end

      if labels_ud
        if labels_ud.size != tick2.size
          raise ArgumentError, "'labels_ud' must be an Array of length==#{tick2.size} in this case"
        end
        nc = labels_ud.collect{|c| c.size}.max
        DCL::uxaxlb("t",tick1,tick2,labels_ud,nc)
        DCL::uxaxlb("b",tick1,tick2,labels_ud,nc)
      else
        DCL::uxaxnm("t",tick1,tick2)
        DCL::uxaxnm("b",tick1,tick2)
      end
      DCL::uyaxdv("l",1,index) if !inf0
      DCL::uyaxdv("r",1,index) if !inf1

      if no_tick
        DCL::uzrset("rsizet1",nt_rsizet1)
      end
      if no_label
        uz_set_params('labelxt'=>nl_labelxt,'labelxb'=>nl_labelxb,'labelyl'=>nl_labelyl,'labelyr'=>nl_labelyr)
      end
      DCL::uzrset("rsizet1",rsizet1_bk)
      DCL::uzrset("rsizet2",rsizet2_bk)

      DCL::uxsfmt(cfmt_bk)

      if voff > 0
        # title
        DCL::sgtxzr((vxmin+vxmax)/2.0+opt['title_voff'], vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['title'], DCL::uzrget('rsizel1'), 0, 0, charindex) if opt["title"]
        # units
        DCL::sgtxzr(vxmax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      else
        # title
        DCL::sgtxzr((vxmin+vxmax)/2.0+opt['title_voff'], vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['title'], DCL::uzrget('rsizel1'), 0, 0, charindex) if opt["title"]
        # units
        DCL::sgtxzr(vxmax+2.6*DCL::uzrget('rsizel1')+opt['units_voff'], vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1'), opt['units'], DCL::uzrget('rsizel1'), 0, -1, charindex) if opt['units']
      end

      uz_set_params(before)

    end

    DCL::uzlset("labelxb",xb)
    DCL::uzlset("labelyl",yl)

    DCL::grsvpt(vx1,vx2,vy1,vy2)
    if itrsv <= 4
      DCL::grswnd(ux1sv, ux2sv, uy1sv, uy2sv)
      DCL::grstrn(itrsv)
    elsif itrsv <= 9
      DCL::sgssim(simfacsv,vxoffsv,vyoffsv)
      DCL::grstrn(itrsv)
    ### TENTATIVE WORKAROUND (2012/2/9)
    elsif itrsv <= 34
      DCL::grswnd(ux1sv, ux2sv, uy1sv, uy2sv)
      DCL.sgstrn(itrsv)
      DCL.umpset('lglobe', lglobesv)
      DCL::grstxy(*grstxysv)
      DCL.umscnt(plxsv,plysv,plrotsv)
      DCL.umpfit
    ###
      DCL.sgssim(simfacsv,vxoffsv,vyoffsv)
      #DCL.sgsmpl(plxsv,plysv,plrotsv)
    end
    DCL::grstrf

    uz_set_params('inner'=>inner_bk)
  end

  DCL::uziset("indext1",indext1_bk)
  DCL::uziset("indext2",indext2_bk)
  DCL::uziset("indexl1",indexl1_bk)
  DCL::uzrset("rsizel1",rsizel1_bk)

  DCL::sglset("lclip", lclip_bk)
  nil
end

.datetime_ax(date_from, date_to, options = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/numru/dclext_datetime_ax.rb', line 20

def datetime_ax(date_from, date_to, options=nil)
  # date_from [a DateTime] : start on this date&time
  # date_to [a DateTime]   : end on this date&time

  opt = @@datetime_ax_options.interpret(options)

  yax = opt['yax']
  xax = !yax
  if xax
	xy='x'
  else
	xy='y'
  end

  if opt['cside']
	cside = opt['cside']
  elsif opt['cside'].nil?
	if xax
	  cside='b'
	else
	  cside='l'
	end
  else
	if xax
	  cside='t'
	else
	  cside='r'
	end
  end

  if opt['year']
	datefmt = '%Y/%m/%d'
  elsif opt['month']
	datefmt = '%m/%d'
  else
	datefmt = '%d'
  end

  # < window parameters >

  ux1,ux2,uy1,uy2 = DCL.sgqwnd
  if xax
	u1, u2 = ux1, ux2
  else
	u1, u2 = uy1, uy2
  end

  loffset_save = DCL.uzpget('loffset')
  xyfact_save = DCL.uzpget(xy+'fact')
  xyoffset_save = DCL.uzpget(xy+'offset')

  tu1 = date_from.day_fraction.to_f
  range_day = date_to - date_from    # time btwn start and end (in days)
  tu2 = tu1 + range_day

  # < axis in hours >

  DCL.uzpset('loffset',true)

  DCL.uzpset(xy+'fact',24.0)
  DCL.uzpset(xy+'offset',(tu1-u1)*24)

  dtick1 = opt['dtick1']
  if opt['dtick2']
	dtick2 = opt['dtick2']
  else
	if range_day >= 4
	  dtick2 = 24
	elsif range_day >= 2
	  dtick2 = 12
	elsif range_day >= 1
	  dtick2 = 6
	elsif range_day >= 0.5
	  dtick2 = 3
	elsif range_day >= 0.25
	  dtick2 = 2
	else
	  dtick2 = 1
	end
  end

  str_hour = (tu1*24).ceil
  end_hour = (tu2*24).floor
  tick1=Array.new
  tick2=Array.new
  labels=Array.new
  h1 = str_hour + (-str_hour % dtick1)
  (h1..end_hour).step(dtick1){|i| tick1.push(i)}
  h2 = str_hour + (-str_hour % dtick2)
  (h2..end_hour).step(dtick2) do |i|
	tick2.push(i)
	labels.push((i%24).to_s)
  end
  if xax
	DCL.uxaxlb(cside, tick1, tick2, labels, 2)
  else
	irotl_save = DCL.uzpget('irotly'+cside)
	icent_save = DCL.uzpget('icenty'+cside)
	DCL.uzpset('irotly'+cside,1)
	DCL.uzpset('icenty'+cside,0)
	DCL.uyaxlb(cside, tick1, tick2, labels, 2)
  end

  # < labels in days >

  if DCL.uzpget('label'+xy+cside)
	DCL.uzpset(xy+'fact',1.0)
	DCL.uzpset(xy+'offset',0.0)

	str_day = tu1.floor
	end_day = tu2.floor
	pos=Array.new
	labels=Array.new
	(str_day..end_day).step(1) do |i|
	  u = i.to_f + 0.5 + (u1- tu1)
	  u = (u1+u+0.5)/2 if u < u1
	  u = (u2+u-0.5)/2 if u > u2
	  pos.push(u)
	  str = (date_from+i).strftime(datefmt)
	  str.sub!(/^0/,'') if !opt['year'] && opt['month']
	  labels.push(str)
	end

    if xax
	  DCL.uxsaxz(cside,DCL.uzpget('roffx'+cside))
	  DCL.uxplbl(cside,1,pos,labels,10)
	else
	  DCL.uysaxz(cside,DCL.uzpget('roffy'+cside))
	  DCL.uyplbl(cside,1,pos,labels,10)
	#  DCL.uzpset('irotly'+cside,irotl_save)
	#  DCL.uzpset('icenty'+cside,icent_save)
	end

  end

  if xax
  else
	DCL.uzpset('irotly'+cside,irotl_save)
	DCL.uzpset('icenty'+cside,icent_save)
  end

  # < to finish >

  DCL.uzpset('loffset',loffset_save)
  DCL.uzpset(xy+'fact',xyfact_save)
  DCL.uzpset(xy+'offset',xyoffset_save)

end

.flow_itr5(gpx, gpy, factor = 1.0, unit_vect = false) ⇒ Object

Raises:

  • (ArgumentError)


1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
# File 'lib/numru/dclext.rb', line 1476

def flow_itr5( gpx, gpy, factor=1.0, unit_vect=false )
  raise ArgumentError,"Expect 2D arrays" if gpx.rank != 2 || gpy.rank != 2
  raise ArgumentError,"gpx.shape != gpy.shape" if gpx.shape != gpy.shape

  raise "Transform. No. should be 5" if DCL.sgpget('itr') != 5

  theta = gpx.coord(1) / 180 * Math::PI
  theta = theta.reshape(1,theta.shape[0])

  vx = gpx * theta.cos - gpy * theta.sin   # UC component -> VC
  vy = gpx * theta.sin + gpy * theta.cos   # UC component -> VC

  DCL.sglset('LCLIP',false)
  before1 = DCLExt.ug_set_params(
               {'LUNIT'=>true, 'LUMSG'=>true} ) if unit_vect
  before2 = DCLExt.ug_set_params(
               {'LNRMAL'=>false,
                'XFACT1'=>factor, 'YFACT1'=>factor} ) if factor != 1.0
  DCL.ugvect( vx.val, vy.val )

  if unit_vect
    uxunit = sprintf("%.2g",DCL.ugrget('UXUNIT'))
    uyunit = sprintf("%.2g",DCL.ugrget('UXUNIT'))
    vxuloc = DCL.ugrget('VXULOC')
    vyuloc = DCL.ugrget('VYULOC')
    rsize  = DCL.ugrget('RSIZET')
    dv = rsize
    DCL.sgtxzv(vxuloc, vyuloc-dv, uxunit, rsize,  0, -1, 3 )
    DCL.sgtxzv(vxuloc-dv, vyuloc, uyunit, rsize, 90, -1, 3 )
  end

  ug_set_params( before2 ) if factor != 1.0
  ug_set_params( before1 ) if unit_vect
end

.flow_vect(fx, fy, factor = 1.0, xintv = 1, yintv = 1, vxfxratio = nil, vyfyratio = nil) ⇒ Object

Raises:

  • (ArgumentError)


1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
# File 'lib/numru/dclext.rb', line 1244

def flow_vect( fx, fy, factor=1.0, xintv=1, yintv=1,
               vxfxratio=nil, vyfyratio=nil)
  raise ArgumentError,"Expect 2D arrays" if fx.rank != 2 || fy.rank != 2
  raise ArgumentError,"fx.shape != fy.shape" if fx.shape != fy.shape
  raise ArgumentError,"xintv must be a positive integer" if xintv < 0
  raise ArgumentError,"yintv must be a positive integer" if yintv < 0
  nx, ny = fx.shape
  if xintv >= 2
    idx = NArray.int(nx/xintv).indgen!*xintv  # [0,xintv,2*xintv,..]
    fx = fx[idx, true]
    fy = fy[idx, true]
  end
  if yintv >= 2
    idx = NArray.int(ny/yintv).indgen!*yintv  # [0,yintv,2*yintv,..]
    fx = fx[true, idx]
    fy = fy[true, idx]
  end
  nx, ny = fx.shape  # again, because of xintv & yintv
  vx0,vx1,vy0,vy1 = DCL.sgqvpt
  wnd = DCL.sgqwnd
  if wnd.include?(DCL.glrget('rundef'))
    ux0,ux1,uy0,uy1 = DCL.sgqtxy
  else
    ux0,ux1,uy0,uy1 = wnd
  end
  dvx = (vx1-vx0)/nx
  dvy = (vy1-vy0)/ny
  ax = (vx1-vx0)/(ux1-ux0)   # factor to convert from U to V coordinate
  ay = (vy1-vy0)/(uy1-uy0)   # factor to convert from U to V coordinate
  fxmx = fx.abs.max
  fymx = fy.abs.max
  raise "fx has no data or all zero" if fxmx == 0
  raise "fy has no data or all zero" if fymx == 0
  cn = [ dvx/(ax*fxmx),  dvy/(ay*fymx) ].min  # normarization constant
  vxfxratio = factor*cn*ax if !vxfxratio
  vyfyratio = factor*cn*ay if !vyfyratio
  before = ug_set_params( {'LNRMAL'=>false, 'LMSG'=>false,
                           'XFACT1'=>1.0, 'YFACT1'=>1.0} )
  DCL.ugvect( vxfxratio*fx, vyfyratio*fy )
  ug_set_params( before )
  unit_vect_info = [ vxfxratio, vyfyratio, fxmx, fymx ]
  return unit_vect_info
end

.flow_vect_anyproj(fx, fy, xg, yg, factor = 1.0, xintv = 1, yintv = 1, distvect_map = true, vfratio = nil, polar_thinning = nil) ⇒ Object

Raises:

  • (ArgumentError)


1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
# File 'lib/numru/dclext.rb', line 1288

def flow_vect_anyproj(fx, fy, xg, yg,  
                      factor=1.0, xintv=1, yintv=1, 
                      distvect_map=true, vfratio=nil, polar_thinning=nil)

  #< parameters to handle singularity of the projection  >

  ddv = 0.3e-3  # Initial value for viewport sampling to find directions.
                # This parameter is modified below if the round off error
                # may be severe.
  eps = 0.05  # Allowed maximum inconsistency in two sampling results
  acc = 1e7   # order of mantissa of sfloat
  epsbk = 3e-6  # factor to judge whether a grid point is on the backside
                # when the projection is multi-valued as map projections

  #< preparation >

  raise ArgumentError,"Expect 2D arrays" if fx.rank != 2 || fy.rank != 2
  raise ArgumentError,"fx.shape != fy.shape" if fx.shape != fy.shape
  raise ArgumentError,"xintv must be a positive integer" if xintv < 0
  raise ArgumentError,"yintv must be a positive integer" if yintv < 0
  nx, ny = fx.shape
  if xg.rank == 1
    raise ArgumentError,"len of xg (#{xg.length}) != #{nx}" if xg.length!=nx
  else
    raise ArgumentError,"xg.shape != shape of data" if xg.shape != fx.shape
  end
  if yg.rank == 1
    raise ArgumentError,"len of yg (#{yg.length}) != #{ny}" if yg.length!=ny
  else
    raise ArgumentError,"yg.shape != shape of data" if yg.shape != fx.shape
  end
  if xintv >= 2
    idx = NArray.int(nx/xintv).indgen!*xintv  # [0,xintv,2*xintv,..]
    fx = fx[idx, true]
    fy = fy[idx, true]
    xg = xg[idx, false]
  end
  if yintv >= 2
    idx = NArray.int(ny/yintv).indgen!*yintv  # [0,yintv,2*yintv,..]
    fx = fx[true, idx]
    fy = fy[true, idx]
    yg = yg[false,idx]
  end
  nx, ny = fx.shape  # again, because of xintv & yintv

  #< read DCL parameters >

  index  = DCL.ugpget('index')
  rsizem = DCL.ugpget('rsizem')
  itype2 = DCL.ugpget('itype2')
  lmissp = DCL.ugpget('lmissp')
  lmiss  = DCL.glpget('lmiss')
  rmiss  = DCL.glpget('rmiss')

  #< Missing value treatment >
  # -- needed to later caluculate flenmax properly

  if lmiss
    fx = NArrayMiss.to_nam(fx, fx.ne(rmiss)) if fx.is_a?(NArray)
    fy = NArrayMiss.to_nam(fy, fy.ne(rmiss)) if fy.is_a?(NArray)
  end

  #< DCL scales >

  wnd = DCL.sgqwnd
  if wnd.include?(DCL.glrget('rundef'))
    ux0,ux1,uy0,uy1 = DCL.sgqtxy
  else
    ux0,ux1,uy0,uy1 = wnd
  end
  flen = Misc::EMath.sqrt( fx*fx + fy*fy )
  flenmax = flen.max
  if !vfratio
    vx0,vx1,vy0,vy1 = DCL.sgqvpt
    dvf = Math::sqrt( (vx1-vx0)*(vy1-vy0)/nx/ny )
    vfratio = factor * dvf / flenmax  # factor to get arrow length in V crd
  end 

  #< parameter modification if needed >
  r = [ [ux0.abs, ux1.abs].min / (ux0-ux1).abs, 
        [uy0.abs, uy1.abs].min / (uy0-uy1).abs ].max
  e = acc*ddv*eps
  if ( r > e )
    # ddv is too small for the current window, so the round off error 
    # may be severer. --> increase it up to a prescribed limit.
    ddv = [ r/e*ddv, 0.1 ].min
  end

  #< handling of distance-based vectors under map projection >

  itr = DCL::sgqtrn
  map_proj = ( itr >= 10 and itr <= 40 )
  if map_proj and distvect_map
    cosphi = Misc::EMath.cos( yg * (Math::PI/180.0) )
    umodi = true
  else
    umodi = false
  end

  #< vector drawing >

  if map_proj
    uodr = 360.0   # order of domain size in U coordinate
  else
    uodr = [xg.max, -xg.min, yg.max, -yg.min].max
  end
  dbk = epsbk*uodr

  u = NMatrix.float(2,2)   # NMatrix's index: [column,row]
  ap = NMatrix.float(2,2)
  an = NMatrix.float(2,2)
  for j in 0...ny
    if polar_thinning && xg.rank==1 && yg.rank==1
      j1 = [j+1,ny-1].min
      dy=(yg[j1]-yg[j1-1]).abs
      dx = (xg[1]-xg[0]).abs * cos(yg[j]/180*Math::PI)
      xstep = [ (dy / dx * polar_thinning).round, 1 ].max
    else
      xstep = 1
    end
    (0...nx).step(xstep) do |i|
      x = ( xg.rank==1 ? xg[i] : xg[i,j] )
      y = ( yg.rank==1 ? yg[j] : yg[i,j] )
      if ( ( fx.is_a?(NArrayMiss) && !fx.valid?(i,j) ) ||
           ( fy.is_a?(NArrayMiss) && !fy.valid?(i,j) ) )
        DCL.sgpmzu([x],[y],itype2,index,rsizem) if lmissp
        next
      end
      vx0, vy0 = DCL.stftrf(x, y) 
      xrev, yrev = DCL.stitrf(vx0, vy0)
      xdif = (xrev-x).abs
      ydif = (yrev-y).abs
      xdif = 360.0-xdif if map_proj && xdif > 359.0
      if xdif > dbk || ydif > dbk
        next   # Not plotted, because the current point is on the backside
      end
      if umodi
        cos = ( cosphi.rank==1 ? cosphi[j] : cosphi[i,j] )
      end
      um = NMatrix[ [x,x], [y,y] ]
      u[0,0],u[0,1] = DCL.stitrf(vx0+ddv, vy0)
      u[1,0],u[1,1] = DCL.stitrf(vx0, vy0+ddv)
      ap = u - um 
      (ap[true,0] >=  180.0).where.to_a.each{|i| ap[i,0] -= 360.0}
      (ap[true,0] <= -180.0).where.to_a.each{|i| ap[i,0] += 360.0}
      u[0,0],u[0,1] = DCL.stitrf(vx0-ddv, vy0)
      u[1,0],u[1,1] = DCL.stitrf(vx0, vy0-ddv)
      an = um - u
      (an[true,0] >=  180.0).where.to_a.each{|i| an[i,0] -= 360.0}
      (an[true,0] <= -180.0).where.to_a.each{|i| an[i,0] += 360.0}
      if umodi
        ap[0,0] *= cos
        ap[1,0] *= cos
        an[0,0] *= cos
        an[1,0] *= cos
      end
      f = NVector[ fx[i,j],fy[i,j] ]
      vfp = nil
      begin
        aip = ap.inverse
        vfp = aip * f
      rescue
      end
      vfn = nil
      begin
        ain = an.inverse
        vfn = ain * f
      rescue
      end
      if vfp && vfn
        vf = (vfp+vfn)/2
        err = (vfp - vfn).abs.max / vf.abs.max
        vn = vf * ( vfratio*flen[i,j] / Math.sqrt(vf[0]**2+vf[1]**2) )
        if err>=eps  
          DCL.sgpmzv([vx0],[vy0],itype2,index,rsizem) if lmissp
        elsif vn[0].nan? || vn[1].nan?
          DCL.sgpmzv([vx0],[vy0],itype2,index,rsizem)
        else
          DCL.sglazv(vx0, vy0, vx0+vn[0], vy0+vn[1], 1, index) 
        end
      end
    end
  end
  [ vfratio, flenmax ]
end

.lat_ax(options = nil) ⇒ Object



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/numru/dclext.rb', line 998

def lat_ax(options=nil)
  opt = @@lat_ax_options.interpret(options)

  xax = opt['xax']
  yax = !xax
  if xax
    xy='x'
  else
    xy='y'
  end

  if opt['cside']
    cside = opt['cside']
  elsif opt['cside'].nil?
    if xax
      cside='b'
    else
      cside='l'
    end
  else
    if xax
      cside='t'
    else
      cside='r'
    end
  end

  vxmin, vxmax, vymin, vymax = DCL.sgqvpt
  uxmin, uxmax, uymin, uymax = DCL.sgqwnd
  if xax
    vmin, vmax = [vxmin,vxmax].min, [vxmin,vxmax].max
    umin, umax = [uxmin,uxmax].min, [uxmin,uxmax].max
  else
    vmin, vmax = [vymin,vymax].min, [vymin,vymax].max
    umin, umax = [uymin,uymax].min, [uymin,uymax].max
  end

  # get dtick1 & dtick2
  dtick1 = opt['dtick1']
  dtick2 = opt['dtick2']
  unless dtick1 && dtick2
    irota = DCL.uzpget("irotl#{xy}#{cside}")
    irota += 1 if yax
    mode = irota.modulo(2)
    DCL.ususcu(xy.capitalize,umin,umax,vmin,vmax,mode)
    dtick1 = DCL.uspget("d#{xy}t") unless dtick1
    dtick2 = DCL.uspget("d#{xy}l") unless dtick2
  end

  lepsl = DCL.glpget('lepsl')
  repsl = DCL.glpget('repsl')
  DCL.glpset('lepsl',true)

  # generate numbers for small tickmarks
  nn = 0
  rx = DCL.irle(umin/dtick1)*dtick1
  if DCL.lreq(umin,rx)
    x = rx
  else
    x = rx + dtick1
  end
  u1 = []
  while DCL.lrle(x,umax)
    if x.abs < dtick1*repsl*nn
      x = 0.0
    end
    u1[nn] = x
    nn = nn + 1
    x = x + dtick1
  end

  # generate numbers for large tickmarks and labels
  nn = 0
  rx = DCL.irle(umin/dtick2)*dtick2
  if DCL.lreq(umin,rx)
    x = rx
  else
    x = rx + dtick2
  end
  u2 = []
  while DCL.lrle(x,umax)
    if x.abs < dtick2*repsl*nn
      x = 0
    end
    u2[nn] = x
    nn = nn + 1
    x = x + dtick2
  end

  # generate labels
  c2 = NArray.to_na(u2)
  c2 = c2.to_a.collect do |c|
    if c == 0
      'EQ'
    elsif c > 0
      c.to_i.to_s + 'N'
    else
      c.abs.to_i.to_s + 'S'
    end
  end
  nc = c2.collect{|c| c.size}.max

  # call DCL.u[xy]axlb
  if xax
    DCL.uxaxlb(cside,u1,u2,c2,nc)
  else
    DCL.uyaxlb(cside,u1,u2,c2,nc)
  end
end

.legend(str, type, index, line = false, size = nil, vx = nil, dx = nil, vy = nil, first = true, mark_size = nil) ⇒ Object

Annotates line/mark type and index (and size if mark). By default it is shown in the right margin of the viewport.

  • str is a String to show

  • line: true->line ; false->mark

  • vx: vx of the left-hand point of legend line (or mark position).

    * nil : internally determined
    * Float && > 0 : set explicitly
    * Float && < 0 : move it relatively to the left from the default
    
  • dx: length of the legend line (not used if mark).

    * nil : internally determined
    * Float && > 0 : set explicitly
    
  • vy: vy of the legend (not used if !first – see below).

    * nil : internally determined
    * Float && > 0 : set explicitly
    * Float && < 0 : move it relatively lower from the default
    
  • first : if false, vy is moved lower relatively from the previous vy.

  • mark_size : size of the mark. if nil, size is used.



2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
# File 'lib/numru/dclext.rb', line 2399

def legend(str, type, index, line=false, size=nil,
           vx=nil, dx=nil, vy=nil, first=true, mark_size=nil)

  size = DCL::uzrget("rsizel1")*0.95 if !size
  mark_size = size if !mark_size

  vpx1,vpx2,vpy1,vpy2 = DCL.sgqvpt
  if first
    if !vy
      vy = vpy2 - 0.04
    elsif vy < 0
      vy = ( vpy2 - 0.04 ) + vy
    end
    @vy = vy
  else
    vy = @vy - 1.5*size
  end

  if !vx
    vx = vpx2 + 0.015
  elsif vx < 0
    vx = (vpx2 + 0.015) + vx
  end

  if line
    dx=0.06 if !dx
    vx2 = vx + dx
    DCL::sgplzv([vx,vx2],[vy,vy],type,index)
    DCL.sgtxzv(vx2+0.01,vy,str,size,0,-1,3)
  else  # --> mark
    DCL::sgpmzv([vx],[vy],type,index,mark_size)
    DCL.sgtxzv(vx+0.015+mark_size*0.5,vy,str,size,0,-1,3)
  end
  nil
end

.level_chval_fmt(max, min, dx) ⇒ Object



1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/numru/dclext.rb', line 1558

def level_chval_fmt(max,min,dx)
  # returns a format for DCL.chval suitable for color-ba labels
  dxabs = dx.abs
  eps = 1e-4 * dxabs
  order = log10_or_0(dxabs).floor
  if ( (dxabs+eps*0.1) % 10**order < eps )
    # 1 keta
    least_order = order
  else
    # >=2 keta --> limit to 2 keta
    least_order = order - 1
  end
  ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
  if ng <= 3
    fmt = 'b'
  else
    n = log10_or_0([max.abs,min.abs].max).floor
    nn = log10_or_0([max.abs,min.abs].min).floor
    if least_order >= 0 and nn >= 0
      ifg = 'i'
    elsif 0 <= n and n <= 4
      ifg = 'f'
    else
      ifg = 'g'
    end
    case(ifg)
    when 'i'
      fmt = '(i15)'
    when 'g'
      ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
      ng = [ ng, 2 ].max
      fmt = "(g15.#{ng})"
    when 'f'
      nf = [ -least_order, 0].max
      fmt = "(f15.#{nf})"
    end
  end
  fmt
end

.log10_or_0(val) ⇒ Object



1554
1555
1556
# File 'lib/numru/dclext.rb', line 1554

def log10_or_0(val)
  log10_safe(val) || 0
end

.log10_safe(val) ⇒ Object



1546
1547
1548
1549
1550
1551
1552
# File 'lib/numru/dclext.rb', line 1546

def log10_safe(val)
  begin
    Math::log10(val)
  rescue Errno::ERANGE
    nil
  end
end

.lon_ax(options = nil) ⇒ Object



878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
# File 'lib/numru/dclext.rb', line 878

def lon_ax(options=nil)
  opt = @@lon_ax_options.interpret(options)

  yax = opt['yax']
  xax = !yax
  if xax
    xy='x'
  else
    xy='y'
  end

  if opt['cside']
    cside = opt['cside']
  elsif opt['cside'].nil?
    if xax
      cside='b'
    else
      cside='l'
    end
  else
    if xax
      cside='t'
    else
      cside='r'
    end
  end

  vxmin, vxmax, vymin, vymax = DCL.sgqvpt
  uxmin, uxmax, uymin, uymax = DCL.sgqwnd
  if xax
    vmin, vmax = [vxmin,vxmax].min, [vxmin,vxmax].max
    umin, umax = [uxmin,uxmax].min, [uxmin,uxmax].max
  else
    vmin, vmax = [vymin,vymax].min, [vymin,vymax].max
    umin, umax = [uymin,uymax].min, [uymin,uymax].max
  end

  # get dtick1 & dtick2
  dtick1 = opt['dtick1']
  dtick2 = opt['dtick2']
  unless dtick1 && dtick2
    irota = DCL.uzpget("irotl#{xy}#{cside}")
    irota += 1 if yax
    mode = irota.modulo(2)
    DCL.ususcu(xy.capitalize,umin,umax,vmin,vmax,mode)
    dtick1 = DCL.uspget("d#{xy}t") unless dtick1
    dtick2 = DCL.uspget("d#{xy}l") unless dtick2
  end

  lepsl = DCL.glpget('lepsl')
  repsl = DCL.glpget('repsl')
  DCL.glpset('lepsl',true)

  # generate numbers for small tickmarks
  nn = 0
  rx = DCL.irle(umin/dtick1)*dtick1
  if DCL.lreq(umin,rx)
    x = rx
  else
    x = rx + dtick1
  end
  u1 = []
  while DCL.lrle(x,umax)
    if x.abs < dtick1*repsl*nn
      x = 0.0
    end
    u1[nn] = x
    nn = nn + 1
    x = x + dtick1
  end

  # generate numbers for large tickmarks and labels
  nn = 0
  rx = DCL.irle(umin/dtick2)*dtick2
  if DCL.lreq(umin,rx)
    x = rx
  else
    x = rx + dtick2
  end
  u2 = []
  while DCL.lrle(x,umax)
    if x.abs < dtick2*repsl*nn
      x = 0
    end
    u2[nn] = x
    nn = nn + 1
    x = x + dtick2
  end

  # generate labels
  c2 = NArray.to_na(u2)
  c2[c2.gt(180)] -= 360.0
  c2[c2.lt(-180)] += 360.0
  c2[c2.eq(-180)] = 180.0
  c2 = c2.to_a.collect do |c|
    if c == 0 || c == 180
      c.to_i.to_s
    elsif c > 0
      c.to_i.to_s + 'E'
    else
      c.abs.to_i.to_s + 'W'
    end
  end
  nc = c2.collect{|c| c.size}.max

  # call DCL.u[xy]axlb
  if xax
   DCL.uxaxlb(cside,u1,u2,c2,nc)
  else
   DCL.uyaxlb(cside,u1,u2,c2,nc)
  end
end

.next_unit_vect_options(options) ⇒ Object



1136
1137
1138
1139
1140
1141
1142
1143
# File 'lib/numru/dclext.rb', line 1136

def next_unit_vect_options(options)
  if options.is_a?(Hash)
    @@next_unit_vect_options = options
  else
    raise TypeError,"Hash expected"
  end
  nil
end

.quasi_log_levels(lev0, lev1, cycle = 1) ⇒ Object

Returns approximately log-scaled contour/tone levels as well as major/minor flags for contours. No DCL call is made in here.

  • cycle (Integer; 1, or 2 or 3) : number of level in one-order. e.g. 1,10,100,.. for cycle==1; 1,3,10,30,.. for cycle==2; 1,2,5,10,20,50,.. for cycle==3

  • lev0, lev1 (Float) : levels are set between this two params

    • if lev0 & lev1 > 0 : positive only

    • if lev0 & lev1 < 0 : negative only

    • if lev0 * lev1 < 0 : both positive and negative (usig +-[lev0.abs,lev1.abs])

RETURN VALUE:

  • levels, mjmn

Raises:

  • (ArgumentError)


2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
# File 'lib/numru/dclext.rb', line 2486

def quasi_log_levels(lev0, lev1, cycle=1)
  raise(ArgumentError, "lev0 is zero (non-zero required)") if lev0 == 0.0
  raise(ArgumentError, "lev1 is zero (non-zero required)") if lev1 == 0.0
  case cycle
  when 1
    cycl_levs = [1.0]
  when 2
    cycl_levs = [1.0, 3.0]
  when 3
    cycl_levs = [1.0, 2.0, 5.0]
  else
    raise(ArgumentError, "cycle must be 1,2,or 3, which is now #{cycle}")
  end

  if lev0 > 0 and lev1 > 0
    positive = true
    negative = false
  elsif  lev0 < 0 and lev1 < 0
    positive = false
    negative = true
  else
    positive = true
    negative = true
  end
  sml, big = [lev0.abs,lev1.abs].sort

  expsml = Math::log10(sml).floor
  expbig = Math::log10(big).ceil

  levels = Array.new
  mjmn = Array.new

  for i in expsml..expbig-1
    for k in 0..cycle-1
      lev = cycl_levs[k] * 10**i
      if lev >= sml && lev <= big
        levels.push( lev )
        mjmn.push( k==0 ? 1 : 0 )
      end
    end
  end
  lev = 10**expbig
  if lev == big
    levels.push( lev )
    mjmn.push( 1 )
  end

  if negative && !positive
    levels = levels.reverse.collect{|x| -x}
    mjmn = mjmn.reverse
  elsif negative && positive
    levels.dup.each{|x| levels.unshift(-x)}
    mjmn.dup.each{|x| mjmn.unshift(x)}
  end

  [ levels, mjmn ]
end

.quasi_log_levels_z(vals, nlev = nil, max = nil, min = nil, cycle = 1) ⇒ Object

Driver of quasi_log_levels with data values



2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
# File 'lib/numru/dclext.rb', line 2436

def quasi_log_levels_z(vals, nlev=nil, max=nil, min=nil, cycle=1)
  if max && min
    quasi_log_levels(max.to_f, min.to_f, cycle)
  else
    if nlev
      eps = 0.1
      norder = (nlev-1.0+eps)/cycle
    else
      norder = 3
    end
    mx1 = vals.max
    mx2 = vals.min
    if min && min < 0
      max = min
      min = nil
    elsif max && max < 0
      min = max
      max = nil
    end
    maxsv = max
    minsv = min
    if !max
      max = [ mx1.abs, mx2.abs ].max.to_f
      max = -max if mx1<0
    end
    if !min
      min = max/10**norder
    else
      max = min*10**norder if nlev
    end
    if !(minsv && minsv>0) && !(maxsv && maxsv <0) && ( mx2<0 && mx1>0 )
      min = -min
    end
    quasi_log_levels(max, min, cycle)
  end
end

.set_color_bar_options(options) ⇒ Object



1542
1543
1544
# File 'lib/numru/dclext.rb', line 1542

def set_color_bar_options(options)
  @@color_bar_options.set(options)
end

.set_unit_vect_options(options) ⇒ Object



1131
1132
1133
# File 'lib/numru/dclext.rb', line 1131

def set_unit_vect_options(options)
  @@unit_vect_options.set(options)
end

.sprintf_level(x, max, min, dx) ⇒ Object



1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
# File 'lib/numru/dclext.rb', line 1598

def sprintf_level(x,max,min,dx)
  # format a float for color-bar labels.
  # like DCL.hval('b',x) but changes according to dx
  if x==0
    fg = 'f'
  else
    n = log10_or_0(x.abs).floor
    if 0 <= n and n <= 4
      fg = 'f'
    else
      fg = 'g'
    end
  end
  eps = 1e-6
  if ( dx.abs % 10**log10_or_0(dx.abs) < eps )
    # 1 keta
    least_order = log10_or_0(dx.abs).floor
  else
    # >=2 keta --> limit to 2 keta
    least_order = log10_or_0(dx.abs).floor - 1
  end
  if fg == 'g'
    ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
    ng = [ ng, 2 ].max
    fmt = "%.#{ng}g"
  else
    nf = [ -least_order, 0].max
    fmt = "%.#{nf}f"
  end
  sprintf(fmt,x).sub(/\.0*$/,'')
end

.ud_add_contour(levels, index = nil, line_type = nil, label = nil, label_height = nil) ⇒ Object



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/numru/dclext.rb', line 692

def ud_add_contour(levels,index=nil,line_type=nil,label=nil,label_height=nil)

  # < check levels >
  case levels
  when Array, NArray
    # This is expected. Nothing to do.
  when Numric
    levels = [levels]
  else
    raise ArgumentError, "invalid level specification (#{levels})"
  end

  nlev = levels.length

  # < index >
  index = index.to_a if index.is_a?(NArray)
  case index
  when Array
    raise ArgumentError, "index is an empty array" if index.length == 0
    while (index.length < nlev )
      index += index
    end
  when Numeric
    index = [index]*nlev
  when nil
    index = [DCL.udpget('indxmn')]*nlev
  else
    raise ArgumentError, "unsupported index type (#{index.class})"
  end

  # < line_type >
  line_type = line_type.to_a if line_type.is_a?(NArray)
  case line_type
  when Array
    raise ArgumentError, "line_type is an empty array" if line_type.length == 0
    while (line_type.length < nlev )
      line_type += line_type
    end
  when Numeric
    line_type = [line_type]*nlev
  when nil
    line_type = [1]*nlev
  else
    raise ArgumentError, "unsupported index type (#{index.class})"
  end

  # < label >
  label = label.to_a if label.is_a?(NArray)
  case label
  when Array
    raise ArgumentError, "label is an empty array" if label.length == 0
    while (label.length < nlev )
      label += label
    end
  when String
    label = [label]*nlev
  when false
    label = [""]*nlev
  when true
    label = (0...nlev).collect{|i|
        DCL.udlabl(levels[i])
    }
  when nil
    indxmj = DCL.udpget('indxmj')
    label = (0...nlev).collect{|i|
      if index[i]==indxmj
        DCL.udlabl(levels[i])
      else
        ""
      end
    }
  else
    raise ArgumentError, "unsupported index type (#{index.class})"
  end

  # < label_height >
  label_height = label_height.to_a if label_height.is_a?(NArray)
  case label_height
  when Array
    raise ArgumentError, "label_height is an empty array" if label_height.length == 0
    while (label_height.length < nlev )
      label_height += label_height
    end
  when Numeric
    label_height = [label_height]*nlev
  when nil
    label_height = label.collect{|lv| lv=="" ? 0.0 : DCL.udpget('rsizel')}
  else
    raise ArgumentError, "unsupported index type (#{index.class})"
  end

  # < set levels >

  for i in 0...nlev
    DCL.udsclv(levels[i],index[i],line_type[i],label[i],label_height[i])
  end
  nil
end

.ud_coloring(clr_min = 13, clr_max = 99) ⇒ Object

<<< udpack >>>



623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/numru/dclext.rb', line 623

def ud_coloring(clr_min=13, clr_max=99)
  # change the colors of existing contours to make a gradation
  # (rainbow colors with the default color map).
  nlev = DCL.udqcln
  cont_params = Array.new
  for i in 1..nlev
    cont_params.push( DCL.udqclv(i) )   # => [zlev,indx,ityp,clv,hl]
  end
  DCL.udiclv     # clear the contours

  colors = clr_min +
           NArray.int(nlev).indgen! * (clr_max-clr_min) / nlev

  cont_params.sort!
  for i in 0...nlev
    cont_params[i][1] += colors[i]*10   # indx += colors[i]*10
    DCL.udsclv(*cont_params[i])
  end
end

.ud_set_contour(*args) ⇒ Object



687
688
689
690
# File 'lib/numru/dclext.rb', line 687

def ud_set_contour(*args)
  DCL.udiclv
  ud_add_contour(*args)
end

.ud_set_linear_levs(v, options = nil) ⇒ Object

Raises:

  • (TypeError)


643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/numru/dclext.rb', line 643

def ud_set_linear_levs(v, options=nil)
  #Accepted options
  #  name        default  description
  #  'min'       nil      minimum contour value (Numeric)
  #  'max'       nil      maximum contour value (Numeric)
  #  'nlev'      nil      number of levels (Integer)
  #  'interval'  nil      contour interval (Numeric)
  #  'nozero'    false    delete zero contour (true/false)
  #  'coloring'  false    set color contours with ud_coloring (true/false)
  #  'clr_min'   13       (if coloring) minimum color  number for the
  #                       maximum data values (Integer)
  #  'clr_max'   99      (if coloring) maximum color number for the
  #                       maximum data values (Integer)
  options = @@empty_hash if !options
  raise TypeError, "options must be a Hash" if !options.is_a?(Hash)
  min = options['min']
  max = options['max']
  nlev = options['nlev']
  interval = options['interval']
  nozero = options['nozero']
  if interval
    dx = interval
  elsif nlev
    dx = -nlev
  else
    dx = 0
  end
  if min || max
    min = v.min if !min
    max = v.max if !max
    DCL.udgcla(min, max, dx)
  else
    DCL.udgclb(v, dx)
  end
  if nozero
    DCL.uddclv(0.0)
  end
  if options['coloring']
    clr_min = ( options['clr_min'] || 13 )
    clr_max = ( options['clr_max'] || 99 )
    ud_coloring( clr_min, clr_max )
  end
end

.ue_add_tone(levels, patterns) ⇒ Object



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
# File 'lib/numru/dclext.rb', line 826

def ue_add_tone(levels, patterns)

  # < check types >

  if !levels.is_a?(Array) && !levels.is_a?(NArray)
    raise TypeError, "levels: Array or NArray expected (#{levels.inspect})"
  end
  if !patterns.is_a?(Array) && !patterns.is_a?(NArray)
    raise TypeError, "patterns: Array or NArray expected (#{patterns.inspect})"
  end

  # < set levels >

  nlev = levels.length
  npat = patterns.length

  case (nlev - npat)
  when 1
    for i in 0...nlev-1
      DCL.uestlv(levels[i],levels[i+1],patterns[i])
    end
  when 0
    for i in 0...nlev-1
      DCL.uestlv(levels[i],levels[i+1],patterns[i])
    end
    DCL.uestlv(levels[-1],DCL.glpget('rmiss'),patterns[-1])
  when -1
    DCL.uestlv(DCL.glpget('rmiss'),levels[0],patterns[0])
    for i in 1...nlev
      DCL.uestlv(levels[i-1],levels[i],patterns[i])
    end
    DCL.uestlv(levels[-1],DCL.glpget('rmiss'),patterns[-1])
  else
    raise ArgumentError,
      "lengths of levels(#{nlev}) and patterns(#{npat}) are inconsistent"
  end
  nil
end

.ue_set_linear_levs(v, options = nil) ⇒ Object

<<< uepack >>>

Raises:

  • (TypeError)


793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
# File 'lib/numru/dclext.rb', line 793

def ue_set_linear_levs(v, options=nil)
  #  'min'       nil      minimum tone level (Numeric)
  #  'max'       nil      maximum tone level (Numeric)
  #  'nlev'      nil      number of levels (Integer)
  #  'interval'  nil      tone-level interval (Numeric)
  options = @@empty_hash if !options
  raise TypeError, "options must be a Hash" if !options.is_a?(Hash)
  min = options['min']
  max = options['max']
  nlev = options['nlev']
  interval = options['interval']
  if interval
    dx = interval
  elsif nlev
    dx = -nlev
  else
    dx = 0
  end
  if min || max
    min = v.min if !min
    max = v.max if !max
    DCL.uegtla(min, max, dx)
  else
    v = v.reshape(v.length,1) if v.rank==1
    DCL.uegtlb(v, dx)
  end
end

.ue_set_tone(levels, patterns) ⇒ Object



821
822
823
824
# File 'lib/numru/dclext.rb', line 821

def ue_set_tone(levels, patterns)
  DCL.ueitlv
  ue_add_tone(levels, patterns)
end

.unit_vect(vxfxratio, vyfyratio, fxunit = nil, fyunit = nil, options = nil) ⇒ Object

(V cood length)/(actual length) in x



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
# File 'lib/numru/dclext.rb', line 1145

def unit_vect( vxfxratio,   # (V cood length)/(actual length) in x
               vyfyratio,   # (V cood length)/(actual length) in y
               fxunit=nil,  # If specified, x unit vect len
               fyunit=nil,  # If specified, y unit vect len
               options=nil )
  #< options >
  if @@next_unit_vect_options
    options = ( options ? @@next_unit_vect_options.update(options) :
                          @@next_unit_vect_options )
    @@next_unit_vect_options = nil
  end
  opt = @@unit_vect_options.interpret(options)
  vxunit = opt['vxunit']
  vyunit = opt['vyunit']
  vxuloc = opt['vxuloc']
  vyuloc = opt['vyuloc']
  rsizet = opt['rsizet']
  index = opt['index']

  #< unit vector >
  if fxunit
    vxunit = vxfxratio * fxunit
  else
    fxunit = vxunit / vxfxratio
  end
  if fyunit
    vyunit = vyfyratio * fyunit
  else
    fyunit = vyunit / vyfyratio
  end
  fxunit = __truncate( (uxusv=fxunit) )
  fyunit = __truncate( (uyusv=fyunit) )
  vxunit = vxunit * (fxunit/uxusv)
  vyunit = vyunit * (fyunit/uyusv)
  if !(vxuloc && vyuloc)
    vx0,vx1,vy0,vy1 = DCL.sgqvpt
    vxuloc = vx1 + opt['vxuoff'] if !vxuloc
    vyuloc = vy0 + opt['vyuoff'] if !vyuloc
  end
  DCL.sglazv( vxuloc, vyuloc,  vxuloc+vxunit, vyuloc,        1, index )
  DCL.sglazv( vxuloc, vyuloc,  vxuloc,        vyuloc+vyunit, 1, index )

  #< labelling >
  sfxunit = sprintf("%.2g",fxunit)
  sfyunit = sprintf("%.2g",fyunit)
  rsizet = DCL.uzpget('rsizel1') if !rsizet
  if opt['inplace']
    DCL.sgtxzv(vxuloc, vyuloc-1.2*rsizet,
               sfxunit, rsizet, 0, -1, index)
    DCL.sgtxzv(vxuloc+1.2*rsizet, vyuloc+0.5*rsizet,
               sfyunit, rsizet, 90, -1, index)
  else
    msg= "UNIT VECTOR X:#{sfxunit} Y:#{sfyunit}"
    before = uz_set_params({'rsizec1'=>rsizet})
    DCL.uxsttl('b',' ',0.0)
    DCL.uxsttl('b',msg,0.0)
    uz_set_params(before)
  end
end

.unit_vect_single(vfratio, flen, options = nil) ⇒ Object



1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
# File 'lib/numru/dclext.rb', line 1205

def unit_vect_single(vfratio, flen, options=nil )
  #< options >
  if @@next_unit_vect_options
    options = ( options ? @@next_unit_vect_options.update(options) :
                          @@next_unit_vect_options )
    @@next_unit_vect_options = nil
  end
  opt = @@unit_vect_options.interpret(options)
  vxuloc = opt['vxuloc']
  vyuloc = opt['vyuloc']
  rsizet = opt['rsizet'] || DCL.uzpget('rsizel1')
  index = opt['index']
  vertical = opt['vertical']

  #< show the unit vector and the label >

  if !(vxuloc && vyuloc)
    vx0,vx1,vy0,vy1 = DCL.sgqvpt
    vxuloc = vx1 + opt['vxuoff'] if !vxuloc
    vyuloc = vy0 + opt['vyuoff'] if !vyuloc
  end
  vlen = vfratio * flen
  label = DCL.chval("B",flen)

  lclip_bk = DCL::sglget("lclip")
  DCL::sglset("lclip", false)
  if vertical
    DCL.sglazv( vxuloc, vyuloc,  vxuloc,      vyuloc+vlen, 1, index )
    DCL.sgtxzv( vxuloc+1.2*rsizet, vyuloc+0.4*vlen,
                label, rsizet, 90, 0, index)
  else
    DCL.sglazv( vxuloc, vyuloc,  vxuloc+vlen, vyuloc,        1, index )
    DCL.sgtxzv( vxuloc+0.4*vlen, vyuloc-1.2*rsizet,
                label, rsizet, 0, 0, index)
  end
  DCL::sglset("lclip", lclip_bk)
  nil
end