gphys 1.1.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) hide show
  1. data/.gitignore +17 -0
  2. data/ChangeLog +221 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +18 -30
  5. data/README +23 -26
  6. data/README.md +29 -0
  7. data/Rakefile +1 -56
  8. data/bin/gpaop +2 -1
  9. data/bin/gpcut +3 -2
  10. data/bin/gpedit +6 -2
  11. data/bin/gpmath +3 -2
  12. data/bin/gpmaxmin +3 -2
  13. data/bin/gpprint +2 -1
  14. data/bin/gpvect +28 -5
  15. data/bin/gpview +43 -5
  16. data/extconf.rb +5 -6
  17. data/gphys.gemspec +34 -0
  18. data/interpo.c +63 -24
  19. data/lib/gphys.rb +2 -0
  20. data/lib/numru/dclext.rb +2636 -0
  21. data/lib/numru/derivative.rb +53 -12
  22. data/lib/numru/ganalysis/eof.rb +4 -0
  23. data/lib/numru/ganalysis/histogram.rb +73 -5
  24. data/lib/numru/ganalysis/met.rb +163 -2
  25. data/lib/numru/ganalysis/planet.rb +230 -20
  26. data/lib/numru/ggraph.rb +147 -2247
  27. data/lib/numru/gphys/assoccoords.rb +19 -3
  28. data/lib/numru/gphys/axis.rb +1 -1
  29. data/lib/numru/gphys/coordmapping.rb +2 -2
  30. data/lib/numru/gphys/derivative.rb +56 -13
  31. data/lib/numru/gphys/gphys.rb +17 -1
  32. data/lib/numru/gphys/gphys_grads_io.rb +6 -5
  33. data/lib/numru/gphys/gphys_grib_io.rb +6 -6
  34. data/lib/numru/gphys/gphys_io.rb +25 -6
  35. data/lib/numru/gphys/grads_gridded.rb +31 -29
  36. data/lib/numru/gphys/grib.rb +13 -9
  37. data/lib/numru/gphys/interpolate.rb +153 -29
  38. data/lib/numru/gphys/unumeric.rb +29 -6
  39. data/lib/numru/gphys/varray.rb +9 -0
  40. data/lib/numru/gphys/varraygrib.rb +70 -8
  41. data/lib/version.rb +3 -0
  42. metadata +247 -531
  43. data/doc/attribute.html +0 -19
  44. data/doc/attributenetcdf.html +0 -15
  45. data/doc/axis.html +0 -376
  46. data/doc/coordmapping.html +0 -111
  47. data/doc/coordtransform.html +0 -36
  48. data/doc/derivative/gphys-derivative.html +0 -80
  49. data/doc/derivative/index.html +0 -21
  50. data/doc/derivative/index.rd +0 -14
  51. data/doc/derivative/math-doc/document/document.css +0 -30
  52. data/doc/derivative/math-doc/document/document.html +0 -57
  53. data/doc/derivative/math-doc/document/images.aux +0 -1
  54. data/doc/derivative/math-doc/document/images.log +0 -385
  55. data/doc/derivative/math-doc/document/images.pl +0 -186
  56. data/doc/derivative/math-doc/document/images.tex +0 -364
  57. data/doc/derivative/math-doc/document/img1.png +0 -0
  58. data/doc/derivative/math-doc/document/img10.png +0 -0
  59. data/doc/derivative/math-doc/document/img11.png +0 -0
  60. data/doc/derivative/math-doc/document/img12.png +0 -0
  61. data/doc/derivative/math-doc/document/img13.png +0 -0
  62. data/doc/derivative/math-doc/document/img14.png +0 -0
  63. data/doc/derivative/math-doc/document/img15.png +0 -0
  64. data/doc/derivative/math-doc/document/img16.png +0 -0
  65. data/doc/derivative/math-doc/document/img17.png +0 -0
  66. data/doc/derivative/math-doc/document/img18.png +0 -0
  67. data/doc/derivative/math-doc/document/img19.png +0 -0
  68. data/doc/derivative/math-doc/document/img2.png +0 -0
  69. data/doc/derivative/math-doc/document/img20.png +0 -0
  70. data/doc/derivative/math-doc/document/img21.png +0 -0
  71. data/doc/derivative/math-doc/document/img22.png +0 -0
  72. data/doc/derivative/math-doc/document/img23.png +0 -0
  73. data/doc/derivative/math-doc/document/img24.png +0 -0
  74. data/doc/derivative/math-doc/document/img25.png +0 -0
  75. data/doc/derivative/math-doc/document/img26.png +0 -0
  76. data/doc/derivative/math-doc/document/img27.png +0 -0
  77. data/doc/derivative/math-doc/document/img28.png +0 -0
  78. data/doc/derivative/math-doc/document/img29.png +0 -0
  79. data/doc/derivative/math-doc/document/img3.png +0 -0
  80. data/doc/derivative/math-doc/document/img30.png +0 -0
  81. data/doc/derivative/math-doc/document/img4.png +0 -0
  82. data/doc/derivative/math-doc/document/img5.png +0 -0
  83. data/doc/derivative/math-doc/document/img6.png +0 -0
  84. data/doc/derivative/math-doc/document/img7.png +0 -0
  85. data/doc/derivative/math-doc/document/img8.png +0 -0
  86. data/doc/derivative/math-doc/document/img9.png +0 -0
  87. data/doc/derivative/math-doc/document/index.html +0 -57
  88. data/doc/derivative/math-doc/document/labels.pl +0 -13
  89. data/doc/derivative/math-doc/document/next.png +0 -0
  90. data/doc/derivative/math-doc/document/next_g.png +0 -0
  91. data/doc/derivative/math-doc/document/node1.html +0 -238
  92. data/doc/derivative/math-doc/document/node2.html +0 -75
  93. data/doc/derivative/math-doc/document/prev.png +0 -0
  94. data/doc/derivative/math-doc/document/prev_g.png +0 -0
  95. data/doc/derivative/math-doc/document/up.png +0 -0
  96. data/doc/derivative/math-doc/document/up_g.png +0 -0
  97. data/doc/derivative/math-doc/document.pdf +0 -0
  98. data/doc/derivative/math-doc/document.tex +0 -158
  99. data/doc/derivative/numru-derivative.html +0 -129
  100. data/doc/ep_flux/ep_flux.html +0 -469
  101. data/doc/ep_flux/ggraph_on_merdional_section.html +0 -71
  102. data/doc/ep_flux/index.html +0 -31
  103. data/doc/ep_flux/index.rd +0 -24
  104. data/doc/ep_flux/math-doc/document/WARNINGS +0 -1
  105. data/doc/ep_flux/math-doc/document/contents.png +0 -0
  106. data/doc/ep_flux/math-doc/document/crossref.png +0 -0
  107. data/doc/ep_flux/math-doc/document/document.css +0 -30
  108. data/doc/ep_flux/math-doc/document/document.html +0 -101
  109. data/doc/ep_flux/math-doc/document/images.aux +0 -1
  110. data/doc/ep_flux/math-doc/document/images.log +0 -1375
  111. data/doc/ep_flux/math-doc/document/images.pl +0 -1328
  112. data/doc/ep_flux/math-doc/document/images.tex +0 -1471
  113. data/doc/ep_flux/math-doc/document/img1.png +0 -0
  114. data/doc/ep_flux/math-doc/document/img10.png +0 -0
  115. data/doc/ep_flux/math-doc/document/img100.png +0 -0
  116. data/doc/ep_flux/math-doc/document/img101.png +0 -0
  117. data/doc/ep_flux/math-doc/document/img102.png +0 -0
  118. data/doc/ep_flux/math-doc/document/img103.png +0 -0
  119. data/doc/ep_flux/math-doc/document/img104.png +0 -0
  120. data/doc/ep_flux/math-doc/document/img105.png +0 -0
  121. data/doc/ep_flux/math-doc/document/img106.png +0 -0
  122. data/doc/ep_flux/math-doc/document/img107.png +0 -0
  123. data/doc/ep_flux/math-doc/document/img108.png +0 -0
  124. data/doc/ep_flux/math-doc/document/img109.png +0 -0
  125. data/doc/ep_flux/math-doc/document/img11.png +0 -0
  126. data/doc/ep_flux/math-doc/document/img110.png +0 -0
  127. data/doc/ep_flux/math-doc/document/img111.png +0 -0
  128. data/doc/ep_flux/math-doc/document/img112.png +0 -0
  129. data/doc/ep_flux/math-doc/document/img113.png +0 -0
  130. data/doc/ep_flux/math-doc/document/img114.png +0 -0
  131. data/doc/ep_flux/math-doc/document/img115.png +0 -0
  132. data/doc/ep_flux/math-doc/document/img116.png +0 -0
  133. data/doc/ep_flux/math-doc/document/img117.png +0 -0
  134. data/doc/ep_flux/math-doc/document/img118.png +0 -0
  135. data/doc/ep_flux/math-doc/document/img119.png +0 -0
  136. data/doc/ep_flux/math-doc/document/img12.png +0 -0
  137. data/doc/ep_flux/math-doc/document/img120.png +0 -0
  138. data/doc/ep_flux/math-doc/document/img121.png +0 -0
  139. data/doc/ep_flux/math-doc/document/img122.png +0 -0
  140. data/doc/ep_flux/math-doc/document/img123.png +0 -0
  141. data/doc/ep_flux/math-doc/document/img124.png +0 -0
  142. data/doc/ep_flux/math-doc/document/img125.png +0 -0
  143. data/doc/ep_flux/math-doc/document/img126.png +0 -0
  144. data/doc/ep_flux/math-doc/document/img127.png +0 -0
  145. data/doc/ep_flux/math-doc/document/img128.png +0 -0
  146. data/doc/ep_flux/math-doc/document/img129.png +0 -0
  147. data/doc/ep_flux/math-doc/document/img13.png +0 -0
  148. data/doc/ep_flux/math-doc/document/img130.png +0 -0
  149. data/doc/ep_flux/math-doc/document/img131.png +0 -0
  150. data/doc/ep_flux/math-doc/document/img132.png +0 -0
  151. data/doc/ep_flux/math-doc/document/img133.png +0 -0
  152. data/doc/ep_flux/math-doc/document/img134.png +0 -0
  153. data/doc/ep_flux/math-doc/document/img135.png +0 -0
  154. data/doc/ep_flux/math-doc/document/img136.png +0 -0
  155. data/doc/ep_flux/math-doc/document/img137.png +0 -0
  156. data/doc/ep_flux/math-doc/document/img138.png +0 -0
  157. data/doc/ep_flux/math-doc/document/img139.png +0 -0
  158. data/doc/ep_flux/math-doc/document/img14.png +0 -0
  159. data/doc/ep_flux/math-doc/document/img140.png +0 -0
  160. data/doc/ep_flux/math-doc/document/img141.png +0 -0
  161. data/doc/ep_flux/math-doc/document/img142.png +0 -0
  162. data/doc/ep_flux/math-doc/document/img143.png +0 -0
  163. data/doc/ep_flux/math-doc/document/img144.png +0 -0
  164. data/doc/ep_flux/math-doc/document/img145.png +0 -0
  165. data/doc/ep_flux/math-doc/document/img146.png +0 -0
  166. data/doc/ep_flux/math-doc/document/img147.png +0 -0
  167. data/doc/ep_flux/math-doc/document/img148.png +0 -0
  168. data/doc/ep_flux/math-doc/document/img149.png +0 -0
  169. data/doc/ep_flux/math-doc/document/img15.png +0 -0
  170. data/doc/ep_flux/math-doc/document/img150.png +0 -0
  171. data/doc/ep_flux/math-doc/document/img151.png +0 -0
  172. data/doc/ep_flux/math-doc/document/img152.png +0 -0
  173. data/doc/ep_flux/math-doc/document/img153.png +0 -0
  174. data/doc/ep_flux/math-doc/document/img154.png +0 -0
  175. data/doc/ep_flux/math-doc/document/img155.png +0 -0
  176. data/doc/ep_flux/math-doc/document/img156.png +0 -0
  177. data/doc/ep_flux/math-doc/document/img157.png +0 -0
  178. data/doc/ep_flux/math-doc/document/img158.png +0 -0
  179. data/doc/ep_flux/math-doc/document/img159.png +0 -0
  180. data/doc/ep_flux/math-doc/document/img16.png +0 -0
  181. data/doc/ep_flux/math-doc/document/img160.png +0 -0
  182. data/doc/ep_flux/math-doc/document/img161.png +0 -0
  183. data/doc/ep_flux/math-doc/document/img162.png +0 -0
  184. data/doc/ep_flux/math-doc/document/img163.png +0 -0
  185. data/doc/ep_flux/math-doc/document/img164.png +0 -0
  186. data/doc/ep_flux/math-doc/document/img165.png +0 -0
  187. data/doc/ep_flux/math-doc/document/img166.png +0 -0
  188. data/doc/ep_flux/math-doc/document/img167.png +0 -0
  189. data/doc/ep_flux/math-doc/document/img168.png +0 -0
  190. data/doc/ep_flux/math-doc/document/img169.png +0 -0
  191. data/doc/ep_flux/math-doc/document/img17.png +0 -0
  192. data/doc/ep_flux/math-doc/document/img170.png +0 -0
  193. data/doc/ep_flux/math-doc/document/img171.png +0 -0
  194. data/doc/ep_flux/math-doc/document/img172.png +0 -0
  195. data/doc/ep_flux/math-doc/document/img173.png +0 -0
  196. data/doc/ep_flux/math-doc/document/img174.png +0 -0
  197. data/doc/ep_flux/math-doc/document/img175.png +0 -0
  198. data/doc/ep_flux/math-doc/document/img176.png +0 -0
  199. data/doc/ep_flux/math-doc/document/img177.png +0 -0
  200. data/doc/ep_flux/math-doc/document/img178.png +0 -0
  201. data/doc/ep_flux/math-doc/document/img179.png +0 -0
  202. data/doc/ep_flux/math-doc/document/img18.png +0 -0
  203. data/doc/ep_flux/math-doc/document/img180.png +0 -0
  204. data/doc/ep_flux/math-doc/document/img181.png +0 -0
  205. data/doc/ep_flux/math-doc/document/img182.png +0 -0
  206. data/doc/ep_flux/math-doc/document/img183.png +0 -0
  207. data/doc/ep_flux/math-doc/document/img184.png +0 -0
  208. data/doc/ep_flux/math-doc/document/img185.png +0 -0
  209. data/doc/ep_flux/math-doc/document/img186.png +0 -0
  210. data/doc/ep_flux/math-doc/document/img187.png +0 -0
  211. data/doc/ep_flux/math-doc/document/img188.png +0 -0
  212. data/doc/ep_flux/math-doc/document/img189.png +0 -0
  213. data/doc/ep_flux/math-doc/document/img19.png +0 -0
  214. data/doc/ep_flux/math-doc/document/img190.png +0 -0
  215. data/doc/ep_flux/math-doc/document/img191.png +0 -0
  216. data/doc/ep_flux/math-doc/document/img192.png +0 -0
  217. data/doc/ep_flux/math-doc/document/img193.png +0 -0
  218. data/doc/ep_flux/math-doc/document/img194.png +0 -0
  219. data/doc/ep_flux/math-doc/document/img195.png +0 -0
  220. data/doc/ep_flux/math-doc/document/img196.png +0 -0
  221. data/doc/ep_flux/math-doc/document/img197.png +0 -0
  222. data/doc/ep_flux/math-doc/document/img198.png +0 -0
  223. data/doc/ep_flux/math-doc/document/img199.png +0 -0
  224. data/doc/ep_flux/math-doc/document/img2.png +0 -0
  225. data/doc/ep_flux/math-doc/document/img20.png +0 -0
  226. data/doc/ep_flux/math-doc/document/img200.png +0 -0
  227. data/doc/ep_flux/math-doc/document/img21.png +0 -0
  228. data/doc/ep_flux/math-doc/document/img22.png +0 -0
  229. data/doc/ep_flux/math-doc/document/img23.png +0 -0
  230. data/doc/ep_flux/math-doc/document/img24.png +0 -0
  231. data/doc/ep_flux/math-doc/document/img25.png +0 -0
  232. data/doc/ep_flux/math-doc/document/img26.png +0 -0
  233. data/doc/ep_flux/math-doc/document/img27.png +0 -0
  234. data/doc/ep_flux/math-doc/document/img28.png +0 -0
  235. data/doc/ep_flux/math-doc/document/img29.png +0 -0
  236. data/doc/ep_flux/math-doc/document/img3.png +0 -0
  237. data/doc/ep_flux/math-doc/document/img30.png +0 -0
  238. data/doc/ep_flux/math-doc/document/img31.png +0 -0
  239. data/doc/ep_flux/math-doc/document/img32.png +0 -0
  240. data/doc/ep_flux/math-doc/document/img33.png +0 -0
  241. data/doc/ep_flux/math-doc/document/img34.png +0 -0
  242. data/doc/ep_flux/math-doc/document/img35.png +0 -0
  243. data/doc/ep_flux/math-doc/document/img36.png +0 -0
  244. data/doc/ep_flux/math-doc/document/img37.png +0 -0
  245. data/doc/ep_flux/math-doc/document/img38.png +0 -0
  246. data/doc/ep_flux/math-doc/document/img39.png +0 -0
  247. data/doc/ep_flux/math-doc/document/img4.png +0 -0
  248. data/doc/ep_flux/math-doc/document/img40.png +0 -0
  249. data/doc/ep_flux/math-doc/document/img41.png +0 -0
  250. data/doc/ep_flux/math-doc/document/img42.png +0 -0
  251. data/doc/ep_flux/math-doc/document/img43.png +0 -0
  252. data/doc/ep_flux/math-doc/document/img44.png +0 -0
  253. data/doc/ep_flux/math-doc/document/img45.png +0 -0
  254. data/doc/ep_flux/math-doc/document/img46.png +0 -0
  255. data/doc/ep_flux/math-doc/document/img47.png +0 -0
  256. data/doc/ep_flux/math-doc/document/img48.png +0 -0
  257. data/doc/ep_flux/math-doc/document/img49.png +0 -0
  258. data/doc/ep_flux/math-doc/document/img5.png +0 -0
  259. data/doc/ep_flux/math-doc/document/img50.png +0 -0
  260. data/doc/ep_flux/math-doc/document/img51.png +0 -0
  261. data/doc/ep_flux/math-doc/document/img52.png +0 -0
  262. data/doc/ep_flux/math-doc/document/img53.png +0 -0
  263. data/doc/ep_flux/math-doc/document/img54.png +0 -0
  264. data/doc/ep_flux/math-doc/document/img55.png +0 -0
  265. data/doc/ep_flux/math-doc/document/img56.png +0 -0
  266. data/doc/ep_flux/math-doc/document/img57.png +0 -0
  267. data/doc/ep_flux/math-doc/document/img58.png +0 -0
  268. data/doc/ep_flux/math-doc/document/img59.png +0 -0
  269. data/doc/ep_flux/math-doc/document/img6.png +0 -0
  270. data/doc/ep_flux/math-doc/document/img60.png +0 -0
  271. data/doc/ep_flux/math-doc/document/img61.png +0 -0
  272. data/doc/ep_flux/math-doc/document/img62.png +0 -0
  273. data/doc/ep_flux/math-doc/document/img63.png +0 -0
  274. data/doc/ep_flux/math-doc/document/img64.png +0 -0
  275. data/doc/ep_flux/math-doc/document/img65.png +0 -0
  276. data/doc/ep_flux/math-doc/document/img66.png +0 -0
  277. data/doc/ep_flux/math-doc/document/img67.png +0 -0
  278. data/doc/ep_flux/math-doc/document/img68.png +0 -0
  279. data/doc/ep_flux/math-doc/document/img69.png +0 -0
  280. data/doc/ep_flux/math-doc/document/img7.png +0 -0
  281. data/doc/ep_flux/math-doc/document/img70.png +0 -0
  282. data/doc/ep_flux/math-doc/document/img71.png +0 -0
  283. data/doc/ep_flux/math-doc/document/img72.png +0 -0
  284. data/doc/ep_flux/math-doc/document/img73.png +0 -0
  285. data/doc/ep_flux/math-doc/document/img74.png +0 -0
  286. data/doc/ep_flux/math-doc/document/img75.png +0 -0
  287. data/doc/ep_flux/math-doc/document/img76.png +0 -0
  288. data/doc/ep_flux/math-doc/document/img77.png +0 -0
  289. data/doc/ep_flux/math-doc/document/img78.png +0 -0
  290. data/doc/ep_flux/math-doc/document/img79.png +0 -0
  291. data/doc/ep_flux/math-doc/document/img8.png +0 -0
  292. data/doc/ep_flux/math-doc/document/img80.png +0 -0
  293. data/doc/ep_flux/math-doc/document/img81.png +0 -0
  294. data/doc/ep_flux/math-doc/document/img82.png +0 -0
  295. data/doc/ep_flux/math-doc/document/img83.png +0 -0
  296. data/doc/ep_flux/math-doc/document/img84.png +0 -0
  297. data/doc/ep_flux/math-doc/document/img85.png +0 -0
  298. data/doc/ep_flux/math-doc/document/img86.png +0 -0
  299. data/doc/ep_flux/math-doc/document/img87.png +0 -0
  300. data/doc/ep_flux/math-doc/document/img88.png +0 -0
  301. data/doc/ep_flux/math-doc/document/img89.png +0 -0
  302. data/doc/ep_flux/math-doc/document/img9.png +0 -0
  303. data/doc/ep_flux/math-doc/document/img90.png +0 -0
  304. data/doc/ep_flux/math-doc/document/img91.png +0 -0
  305. data/doc/ep_flux/math-doc/document/img92.png +0 -0
  306. data/doc/ep_flux/math-doc/document/img93.png +0 -0
  307. data/doc/ep_flux/math-doc/document/img94.png +0 -0
  308. data/doc/ep_flux/math-doc/document/img95.png +0 -0
  309. data/doc/ep_flux/math-doc/document/img96.png +0 -0
  310. data/doc/ep_flux/math-doc/document/img97.png +0 -0
  311. data/doc/ep_flux/math-doc/document/img98.png +0 -0
  312. data/doc/ep_flux/math-doc/document/img99.png +0 -0
  313. data/doc/ep_flux/math-doc/document/index.html +0 -101
  314. data/doc/ep_flux/math-doc/document/internals.pl +0 -258
  315. data/doc/ep_flux/math-doc/document/labels.pl +0 -265
  316. data/doc/ep_flux/math-doc/document/next.png +0 -0
  317. data/doc/ep_flux/math-doc/document/next_g.png +0 -0
  318. data/doc/ep_flux/math-doc/document/node1.html +0 -104
  319. data/doc/ep_flux/math-doc/document/node10.html +0 -164
  320. data/doc/ep_flux/math-doc/document/node11.html +0 -86
  321. data/doc/ep_flux/math-doc/document/node12.html +0 -166
  322. data/doc/ep_flux/math-doc/document/node13.html +0 -897
  323. data/doc/ep_flux/math-doc/document/node14.html +0 -1065
  324. data/doc/ep_flux/math-doc/document/node15.html +0 -72
  325. data/doc/ep_flux/math-doc/document/node16.html +0 -81
  326. data/doc/ep_flux/math-doc/document/node2.html +0 -82
  327. data/doc/ep_flux/math-doc/document/node3.html +0 -91
  328. data/doc/ep_flux/math-doc/document/node4.html +0 -149
  329. data/doc/ep_flux/math-doc/document/node5.html +0 -330
  330. data/doc/ep_flux/math-doc/document/node6.html +0 -99
  331. data/doc/ep_flux/math-doc/document/node7.html +0 -98
  332. data/doc/ep_flux/math-doc/document/node8.html +0 -83
  333. data/doc/ep_flux/math-doc/document/node9.html +0 -140
  334. data/doc/ep_flux/math-doc/document/prev.png +0 -0
  335. data/doc/ep_flux/math-doc/document/prev_g.png +0 -0
  336. data/doc/ep_flux/math-doc/document/up.png +0 -0
  337. data/doc/ep_flux/math-doc/document/up_g.png +0 -0
  338. data/doc/ep_flux/math-doc/document.pdf +0 -0
  339. data/doc/ep_flux/math-doc/document.tex +0 -2018
  340. data/doc/gdir.html +0 -412
  341. data/doc/gdir_client.html +0 -16
  342. data/doc/gdir_connect_ftp-like.html +0 -61
  343. data/doc/gdir_server.html +0 -45
  344. data/doc/ggraph.html +0 -1615
  345. data/doc/gpcat.html +0 -44
  346. data/doc/gpcut.html +0 -41
  347. data/doc/gphys.html +0 -532
  348. data/doc/gphys_fft.html +0 -324
  349. data/doc/gphys_grads_io.html +0 -69
  350. data/doc/gphys_grib_io.html +0 -82
  351. data/doc/gphys_io.html +0 -120
  352. data/doc/gphys_io_common.html +0 -18
  353. data/doc/gphys_netcdf_io.html +0 -283
  354. data/doc/gplist.html +0 -24
  355. data/doc/gpmath.html +0 -51
  356. data/doc/gpmaxmin.html +0 -31
  357. data/doc/gpprint.html +0 -34
  358. data/doc/gpview.html +0 -270
  359. data/doc/grads2nc_with_gphys.html +0 -21
  360. data/doc/grads_gridded.html +0 -307
  361. data/doc/grib.html +0 -144
  362. data/doc/grid.html +0 -212
  363. data/doc/index.html +0 -133
  364. data/doc/index.rd +0 -127
  365. data/doc/netcdf_convention.html +0 -136
  366. data/doc/unumeric.html +0 -176
  367. data/doc/update +0 -64
  368. data/doc/varray.html +0 -299
  369. data/doc/varraycomposite.html +0 -67
@@ -0,0 +1,2636 @@
1
+ require "numru/dcl"
2
+ require "numru/misc"
3
+ require "numru/dclext_datetime_ax"
4
+ require "narray_miss"
5
+
6
+ ############################################################
7
+
8
+ =begin
9
+ =module NumRu::DCLExt
10
+
11
+ An extension of RubyDCL.
12
+
13
+ ==Index
14
+
15
+ Original methods
16
+ * ((<lon_ax>))
17
+ Draw longitude axis. (label format: degrees + 'E' or 'W')
18
+ * ((<lat_ax>))
19
+ Draw latitude axis. (label format: degrees + 'N' or 'S')
20
+ * ((<unit_vect>)) Show the "unit vector", which indicate the vector scaling.
21
+ * ((<unit_vect_single>)) Draw a unit vector (only one arrow is drawn).
22
+ * ((<set_unit_vect_options>))
23
+ Change the default option values for ((<unit_vect>)).
24
+ * ((<next_unit_vect_options>))
25
+ Set the option values effective only in the next call of ((<unit_vect>))
26
+ * ((<flow_vect>)) 2D Vector plot. Unlike (({DCL::ugvect})), scaling are made in term of the physical (or "U") coordinate.
27
+ * ((<flow_vect_anyproj>)) flow_vect available in any coordinate projections
28
+ * ((<flow_itr5>)) 2D Vector plot on the 2-dim polar coodinate.
29
+ * ((<color_bar>)) Color Bar
30
+ * ((<set_color_bar_options>))
31
+ * ((<legend>))
32
+ Annotates line/mark type and index (and size if mark).
33
+ * ((<quasi_log_levels_z>))
34
+ Driver of quasi_log_levels with data values
35
+ * ((<quasi_log_levels>))
36
+ Returns approximately log-scaled contour/tone levels.
37
+
38
+ MATH1
39
+ * ((<glpack>))
40
+ * ((<gl_set_params>))
41
+ Calls (({DCL.glpset})) multiple times (for each key and val of (({hash}))).
42
+ GRPH1
43
+ * ((<sgpack>))
44
+ * ((<sg_set_params>))
45
+ Calls (({DCL.sgpset})) multiple times (for each key and val of (({hash}))).
46
+ * ((<slpack>))
47
+ * ((<sl_set_params>))
48
+ Calls (({DCL.slpset})) multiple times (for each key and val of (({hash}))).
49
+ * ((<swpack>))
50
+ * ((<sw_set_params>))
51
+ Calls (({DCL.swpset})) multiple times (for each key and val of (({hash}))).
52
+ GRPH2
53
+ * ((<uzpack>))
54
+ * ((<uz_set_params>))
55
+ Calls (({DCL.uzpset})) multiple times (for each key and val of (({hash}))).
56
+ * ((<ulpack>))
57
+ * ((<ul_set_params>))
58
+ Calls (({DCL.ulpset})) multiple times (for each key and val of (({hash}))).
59
+ * ((<ucpack>))
60
+ * ((<uc_set_params>))
61
+ Calls (({DCL.ucpset})) multiple times (for each key and val of (({hash}))).
62
+ * ((<uupack>))
63
+ * ((<uu_set_params>))
64
+ Calls (({DCL.uupset})) multiple times (for each key and val of (({hash}))).
65
+ * ((<uspack>))
66
+ * ((<us_set_params>))
67
+ Calls (({DCL.uspset})) multiple times (for each key and val of (({hash}))).
68
+ * ((<udpack>))
69
+ * ((<ud_set_params>))
70
+ Calls (({DCL.udpset})) multiple times (for each key and val of (({hash}))).
71
+ * ((<ud_set_linear_levs>))
72
+ Set contour levels with a constant interval
73
+ * ((<ud_set_contour>))
74
+ Set contours of at specified levels.
75
+ * ((<ud_add_contour>))
76
+ Same as ((<ud_set_contour>)), but does not clear the contour levels that have
77
+ been set.
78
+ * ((<uepack>))
79
+ * ((<ue_set_params>))
80
+ Calls (({DCL.uepset})) multiple times (for each key and val of (({hash}))).
81
+ * ((<ue_set_linear_levs>))
82
+ Set tone levels with a constant interval
83
+ * ((<ue_set_tone>))
84
+ Set tone levels and patterns.
85
+ * ((<ue_add_tone>))
86
+ Same as ((<ue_set_tone>)), but does not clear the tone levels that have
87
+ been set.
88
+ * ((<ugpack>))
89
+ * ((<ug_set_params>))
90
+ Calls (({DCL.ugpset})) multiple times (for each key and val of (({hash}))).
91
+ See ((<gl_set_params>)) for usage.
92
+ * ((<umpack>))
93
+ * ((<um_set_params>))
94
+ Calls (({DCL.umpset})) multiple times (for each key and val of (({hash}))).
95
+
96
+
97
+
98
+ ==Module Functions
99
+
100
+ ===glpack
101
+ ---gl_set_params(hash)
102
+ Calls (({DCL.glpset})) multiple times (for each key and val of (({hash}))).
103
+
104
+ ARGUMENTS
105
+ * hash (Hash) : combinations of parameter names and values for udpset
106
+
107
+ RETURN VALUE
108
+ * a Hash containing the parameter names and their old values that were
109
+ replaced.
110
+
111
+ EXAMPLES
112
+ * You can modify parameters temporarily as follows.
113
+
114
+ before = DCLExt.gl_set_params({'lmiss'=>true,'rmiss'=>9999.0})
115
+ ....
116
+ DCLExt.gl_set_params(before) # reset the change
117
+
118
+ ===sgpack
119
+ ---sg_set_params(hash)
120
+ Calls (({DCL.sgpset})) multiple times (for each key and val of (({hash}))).
121
+
122
+ See ((<gl_set_params>)) for usage.
123
+
124
+ ===slpack
125
+ ---sl_set_params(hash)
126
+ Calls (({DCL.slpset})) multiple times (for each key and val of (({hash}))).
127
+
128
+ See ((<gl_set_params>)) for usage.
129
+
130
+ ===swpack
131
+ ---sw_set_params(hash)
132
+ Calls (({DCL.swpset})) multiple times (for each key and val of (({hash}))).
133
+
134
+ See ((<gl_set_params>)) for usage.
135
+
136
+ ===uzpack
137
+ ---uz_set_params(hash)
138
+ Calls (({DCL.uzpset})) multiple times (for each key and val of (({hash}))).
139
+
140
+ See ((<gl_set_params>)) for usage.
141
+
142
+ ===ulpack
143
+ ---ul_set_params(hash)
144
+ Calls (({DCL.ulpset})) multiple times (for each key and val of (({hash}))).
145
+
146
+ See ((<gl_set_params>)) for usage.
147
+
148
+ ===ucpack
149
+ ---uc_set_params(hash)
150
+ Calls (({DCL.ucpset})) multiple times (for each key and val of (({hash}))).
151
+
152
+ See ((<gl_set_params>)) for usage.
153
+
154
+ ===uupack
155
+ ---uu_set_params(hash)
156
+ Calls (({DCL.uupset})) multiple times (for each key and val of (({hash}))).
157
+
158
+ See ((<gl_set_params>)) for usage.
159
+
160
+ ===uspack
161
+ ---us_set_params(hash)
162
+ Calls (({DCL.uspset})) multiple times (for each key and val of (({hash}))).
163
+
164
+ See ((<gl_set_params>)) for usage.
165
+
166
+ ===udpack
167
+ ---ud_set_params(hash)
168
+ Calls (({DCL.udpset})) multiple times (for each key and val of (({hash}))).
169
+
170
+ ARGUMENTS
171
+ * hash (Hash) : combinations of parameter names and values for udpset
172
+
173
+ RETURN VALUE
174
+ * a Hash containing the parameter names and their old values that were
175
+ replaced.
176
+
177
+ EXAMPLES
178
+ * You can modify parameters temporarily as follows.
179
+
180
+ before = DCLExt.ud_set_params('indxmj'=>4,'lmsg'=>false)
181
+ DCL.udcntz(data)
182
+ DCLExt.ud_set_params(before) # reset the change
183
+
184
+ ---ud_set_linear_levs(v, options)
185
+ Set contour levels with a constant interval
186
+
187
+ ARGUMENTS
188
+ * v : Data values to be fed to udcnt[rz]
189
+ * options (Hash) : option specification by keys and values. Available
190
+ options are
191
+ name default value description
192
+ 'min' nil minimum contour value (Numeric)
193
+ 'max' nil maximum contour value (Numeric)
194
+ 'nlev' nil number of levels (Integer)
195
+ 'interval' nil contour interval (Numeric)
196
+ 'nozero' nil delete zero contour (true/false)
197
+ 'coloring' false set color contours with ud_coloring (true/false)
198
+ 'clr_min' 13 (if coloring) minimum color id (Integer)
199
+ 'clr_max' 99 (if coloring) maximum color id (Integer)
200
+ Here, (({interval})) has a higher precedence over (({nlev})).
201
+ Since all the default values are nil, only those explicitly specified
202
+ are interpreted. If no option is provided, the levels generated will
203
+ be the default ones set by udcnt[rz] without any level specification.
204
+
205
+ ---ud_set_contour(levels,index=nil,line_type=nil,label=nil,label_height=nil)
206
+ Set contours of at specified levels.
207
+
208
+ Normally you do not have to specify (({label})) and (({label_height})).
209
+
210
+ It calls DCL.udsclv for each level. So the arguments are basically
211
+ the same as DCL.udsclv, but only levels are mandatory here.
212
+
213
+ ARGUMENTS
214
+ * levels (Array, NArray, or Numeric) : contour levels to be set.
215
+ If Numeric, a single level is set.
216
+ * index (Array of integers, Integer, or nil) :
217
+ index(es) of the contours. If it is an Array and its length is
218
+ shorter than that of (({levels})), the same Array is repeated (so
219
+ for instance [1,1,3] is interpreted as [1,1,3,1,1,3,1,1,3,...]).
220
+ If it is a single Integer, all the contour will have the same index.
221
+ If nil, the value of 'indxmn' is used.
222
+ * line_type (Array of integers, Integer, or nil) :
223
+ line type(s) of the contours. If it is an Array and its length is
224
+ shorter than that of (({levels})), the same Array is repeated.
225
+ the length must agree with that of (({levels})).
226
+ If it is a single Integer, all the contour will have the same type.
227
+ If nil, set to be 1.
228
+ * label (Array of String, String, true, false, nil) :
229
+ Label(s) of the contours. If it is an Array and its length is
230
+ shorter than that of (({levels})), the same Array is repeated.
231
+ the length must agree with that of (({levels})).
232
+ If it is a single String, all the contour will have the same label.
233
+ If true, all the contours will have the labels representing the levels.
234
+ If false, no label will be drawn (set to "").
235
+ If nil, same as true for the contours whose index is equal to "INDXMJ",
236
+ and same as false otherwise.
237
+ * label_height (Array of Numeric, Numeric, or nil) :
238
+ Heigh of Labels. Normally you do not have to use this.
239
+ If it is an Array and its length is
240
+ shorter than that of (({levels})), the same Array is repeated.
241
+ If nil, the default value ("RSIZEL") is used for non-empty labels.
242
+ If a single Numeric, the same value is used for all the contours.
243
+ Note that it is recommended to not to use this parameter but
244
+ use DCL.udpset('RZISEL'. label_height), since a positive value
245
+ here always means to draw labels even when the label is empty.
246
+
247
+ RETURN VALUE
248
+ * nil
249
+
250
+ ---ud_add_contour(levels,index=nil,line_type=nil,label=nil,label_height=nil)
251
+ Same as ((<ud_set_contour>)), but does not clear the contour levels that have
252
+ been set.
253
+
254
+ ===uepack
255
+ ---ue_set_params(hash)
256
+ Calls (({DCL.uepset})) multiple times (for each key and val of (({hash}))).
257
+
258
+ See ((<gl_set_params>)) for usage.
259
+
260
+ ---ue_set_linear_levs(v, options)
261
+ Set tone levels with a constant interval
262
+
263
+ ARGUMENTS
264
+ * v : Data values to be fed to udcnt[rz]
265
+ * options (Hash) : option specification by keys and values. Available
266
+ options are
267
+ name default value description
268
+ 'min' nil minimum tone level (Numeric)
269
+ 'max' nil maximum tone level (Numeric)
270
+ 'nlev' nil number of levels (Integer)
271
+ 'interval' nil tone-level interval (Numeric)
272
+ Here, (({interval})) has a higher precedence over (({nlev})).
273
+ Since all the default values are nil, only those explicitly specified
274
+ are interpreted. If no option is provided, the levels generated will
275
+ be the default ones set by udcnt[rz] without any level specification.
276
+
277
+ ---ue_set_tone(levels, patterns)
278
+ Set tone levels and patterns.
279
+
280
+ patterns are set between levels as follows:
281
+
282
+ when (levels.length == patterns.length+1)
283
+
284
+ levels[0] | levels[1] | levels[2] ... | levels[-2] | levels[-1]
285
+ patterns[0] patterns[1] ... patterns[-2] patterns[-1]
286
+
287
+ when (levels.length == patterns.length)
288
+
289
+ levels[0] | levels[1] | levels[2] ... | levels[-1] | +infty
290
+ patterns[0] patterns[1] ... patterns[-2] patterns[-1]
291
+
292
+ when (levels.length == patterns.length-1)
293
+
294
+ -infty | levels[0] | levels[1] ... | levels[-1] | +infty
295
+ patterns[0] patterns[1] ... patterns[-2] patterns[-1]
296
+
297
+ else
298
+ error (exception raised)
299
+
300
+ ARGUMENTS
301
+ * levels (Array or NArray of Numeric) : tone levels. Its length must be
302
+ either 1 larger than, equal to, or 1 smaller than the length of patterns
303
+ * patterns (Array or NArray of Numeric) : tone patterns
304
+
305
+ RETURN VALUE
306
+ * nil
307
+
308
+ ---ue_add_tone(levels, patterns)
309
+ Same as ((<ue_set_tone>)), but does not clear the tone levels that have
310
+ been set.
311
+
312
+ ===ugpack
313
+ ---ug_set_params(hash)
314
+ Calls (({DCL.ugpset})) multiple times (for each key and val of (({hash}))).
315
+ See ((<gl_set_params>)) for usage.
316
+
317
+ ===umpack
318
+ ---um_set_params(hash)
319
+ Calls (({DCL.umpset})) multiple times (for each key and val of (({hash}))).
320
+
321
+ See ((<gl_set_params>)) for usage.
322
+
323
+ ==Original methods:
324
+
325
+ ===Longitude/Latitude Axes
326
+ ---lon_ax( options=nil )
327
+
328
+ Draw longitude axis. (label format: degrees + 'E' or 'W')
329
+
330
+ ARGUMENTS
331
+ * options (Hash) : options to change the default behavior if specified.
332
+ It is a Hash with option names (String) as keys and their values.
333
+ Options are interpreted by a NumRu::Misc::KeywordOptAutoHelp,
334
+ so you can shorten the keys (by omitting tails) as long as it is
335
+ unambiguous.
336
+ option name default value # description:
337
+ "yax" false # true => draw y-axis, false => draw x-axis
338
+ "cside" nil # "b", "t", "l", "r",
339
+ # nil (=>left/bottom), or false (=>right/top)
340
+ "dtick1" nil # Interval of small tickmark
341
+ # (if nil, internally determined)
342
+ "dtick2" nil # Interval of large tickmark with labels
343
+ # (if nil, internally determined)
344
+
345
+ ---lat_ax( options=nil )
346
+
347
+ Draw latitude axis. (label format: degrees + 'N' or 'S')
348
+
349
+ ARGUMENTS
350
+ * options (Hash) : options to change the default behavior if specified.
351
+ It is a Hash with option names (String) as keys and their values.
352
+ Options are interpreted by a NumRu::Misc::KeywordOptAutoHelp,
353
+ so you can shorten the keys (by omitting tails) as long as it is
354
+ unambiguous.
355
+ option name default value # description:
356
+ "xax" false # true => draw x-axis, false => draw y-axis
357
+ "cside" nil # "b", "t", "l", "r",
358
+ # nil (=>left/bottom), or false (=>right/top)
359
+ "dtick1" nil # Interval of small tickmark
360
+ # (if nil, internally determined)
361
+ "dtick2" nil # Interval of large tickmark with labels
362
+ # (if nil, internally determined)
363
+
364
+ ===Vectors
365
+ ---unit_vect( vxfxratio, vyfyratio, fxunit=nil, fyunit=nil, options=nil )
366
+
367
+ Show the "unit vector", which indicate the vector scaling.
368
+
369
+ ARGUMENTS
370
+ * vxfxratio (Float) : (V cood length)/(actual length) in x
371
+ * vyfyratio (Float) : (V cood length)/(actual length) in y
372
+ * fxunit (Float) : If specified, x unit vect len
373
+ * fyunit (Float) : If specified, y unit vect len
374
+ * options (Hash) : options to change the default behavior if specified.
375
+ It is a Hash with option names (String) as keys and their values.
376
+ Options are interpreted by a NumRu::Misc::KeywordOptAutoHelp,
377
+ so you can shorten the keys (by omitting tails) as long as it is
378
+ unambiguous.
379
+ option name default value # description:
380
+ "vxunit" 0.05 # x unit vect len in V coord. Used only when
381
+ # fxunit is omitted (default)
382
+ "vyunit" 0.05 # y unit vect len in V coord. Used only when
383
+ # fyunit is omitted (default)
384
+ "vxuloc" nil # Starting x position of unit vect
385
+ "vyuloc" nil # Starting y position of unit vect
386
+ "vxuoff" 0.05 # Specify vxuloc by offset from right-bottom
387
+ # corner
388
+ "vyuoff" 0.0 # Specify vyuloc by offset from right-bottom
389
+ # corner
390
+ "inplace" true # Whether to print labels right by the unit
391
+ # vector (true) or below the x axis (false)
392
+ "rsizet" nil # Label size(default taken from uz-parameter
393
+ # 'rsizel1')
394
+ "index" 3 # Line index of the unit vector
395
+ "help" false # show help message if true
396
+ "vertical" true # (used only in unit_vect_single) the unit vector
397
+ # is directed upward if true, to the right if not.
398
+
399
+ ---unit_vect_single(vfratio, flen, options=nil )
400
+ Draw a unit vector (only one arrow is drawn). Suitable to called after ((<flow_vect_anyproj>)).
401
+
402
+ ARGUMENTS
403
+ * vfratio (Numeric) : see ((<flow_vect_anyproj>)).
404
+ * flen (Numeric) : length of the unit vector
405
+ * options (Hash) : see ((<unit_vect>)).
406
+
407
+ ---set_unit_vect_options(options)
408
+ Change the default option values for ((<unit_vect>)).
409
+
410
+ ---next_unit_vect_options(options)
411
+ Set the option values effective only in the next call of ((<unit_vect>))
412
+
413
+ ---flow_vect( fx, fy, factor=1.0, xintv=1, yintv=1)
414
+
415
+ 2D Vector plot. Unlike (({DCL::ugvect})), scaling are made in term of the physical (or "U") coordinate.
416
+
417
+ This method is meant to substitute (({DCL::ugvect})). The scaling
418
+ is made in terms of the U coordinate. This method is suitable to
419
+ show vectors such as velocity, since the arrow direction represets
420
+ the direction in the U coordinate. Also, one can re-scale the
421
+ vector length easily by using the argument (({factor})).
422
+
423
+ Currently, this method is not compatible with map projection,
424
+ since it calls (({DCL::ugvect})) internally.
425
+
426
+ ARGUMENTS
427
+ * fx, fy (2D NArray or Array) : the vector field.
428
+ * factor (Integer) : factor to change the arrow length.
429
+ By default, arrows are scaled so that the longest one
430
+ match the grid interval.
431
+ * xintv, yintv (Interger) : interval to thin out (({fx})) and (({fy})),
432
+ respectively. Useful if the grid points are too many.
433
+
434
+ ---flow_vect_anyproj(fx, fy, xg, yg, factor=1.0, xintv=1, yintv=1, distvect_map=true, vfratio=nil)
435
+
436
+ flow_vect that can be used under any of the projections supported by DCL.
437
+ Arrows drawn by this method have lengths proportional to sqrt(fx**2+fy**2),
438
+ and their directions are properly directed locally (consistent with the
439
+ local coordinate). A special treatment
440
+ is made for map projections if distvect_map==true (see below). Singular
441
+ points of the projection is heuristically handled (see the source code
442
+ for details).
443
+
444
+ ARGUMENTS
445
+ * fx, fy [2D NArray or NArrayMiss] : the vector field.
446
+ * xg, yg [1D (or 2D) NArray] : the grid points
447
+ * factor (Integer) : factor to change the arrow length.
448
+ By default, arrows are scaled so that the longest one
449
+ matches the typical grid interval.
450
+ * xintv, yintv (Integer) : interval to thin out (({fx})) and (({fy})),
451
+ respectively. Useful if the grid points are too many.
452
+ * distvect_map [true/false] : (effective only for map projections)
453
+ by default (true) it is assumed that the vector (fx,fy) is based
454
+ on lengths (such as wind velocities in m/s,
455
+ and fluxes in which wind velocities are incorporated [q*u, q*v]);
456
+ set it to false if the vector is based on angles
457
+ (such as the time derivatives of longitude and latitude).
458
+ When true, a directional correction is made to match the scaling of
459
+ DCL's window, which is based on angles (longitude and latitude).
460
+ * vfratio [nil or Numeric] : if Numeric, specifies the ratio
461
+ between the lengths of vectors in the V coordinate and the actual
462
+ length (sqrt(fx**2+fy**2)). Good to unify the scaling over multiple
463
+ plots
464
+
465
+ RETURN VALUE
466
+ * [ vfratio, flenmax ] :
467
+ * vfratio : see above
468
+ * flenmax : maximum of sqrt(fx**2+fy**2)
469
+
470
+ ---flow_itr5( fx, fy, factor=1.0, unit_vect=false )
471
+
472
+ 2D Vector plot on the polar coodinate.
473
+
474
+ This method just perform rotatation of the vector in U-coordinate
475
+ to N-coordinate and passed to DCL.ugvect.
476
+
477
+ ARGUMENTS
478
+ * fx, fy (2D GPhys) : the vector field.
479
+ * factor (Integer) : factor for scaling in ugvect. When it equals 1,
480
+ vector field will be scaled in DCL.ugvect automatically.
481
+ * unit_vect() : Show the unit vector
482
+
483
+ ===Color bars
484
+ ---set_color_bar_options(options)
485
+ To set options of ((<color_bar>)) effective in the rest.
486
+
487
+ ---color_bar(options=nil)
488
+ * Descroption:
489
+ Draws color bars
490
+
491
+ * Example
492
+ Here is the simplest case, where no argument is given to color_bar.
493
+
494
+ DCL.uetone(hoge)
495
+ DCL.usdaxs
496
+ ...
497
+ DCL.color_bar
498
+
499
+ This draws a color bar by using the levels and tone patterns(colors)
500
+ set previously. There are many parameters you can set manually,
501
+ as introduced below:
502
+
503
+ * Description of options
504
+ option name default value # description:
505
+ "levels" nil # tone levels (if omitted, latest ones are used)
506
+ "patterns" nil # tone patterns (~colors) (if omitted, latest
507
+ # ones are used)
508
+ "voff" nil # how far is the bar from the viewport in the V
509
+ # coordinate
510
+ "vcent" nil # center position of the bar in the V coordinate
511
+ # (VX or VY)
512
+ "vlength" 0.3 # bar length in the V coordinate
513
+ "vwidth" 0.02 # bar width in the V coordinate
514
+ "inffact" 2.25 # factor to change the length of triangle on the
515
+ # side for infinity (relative to 'vwidth')
516
+ "landscape" false # if true, horizonlly long (along x axes)
517
+ "portrait" true # if true, vertically long (along y axes)
518
+ "top" false # place the bar at the top (effective if
519
+ # landscape)
520
+ "left" false # place the bar in the left (effective if
521
+ # portrait)
522
+ "units" nil # units of the axis of the color bar
523
+ "units_voff" 0.0 # offset value for units from the default position
524
+ # in the V coordinate (only for 'units' != nil)
525
+ "title" nil # title of the color bar
526
+ "title_voff" 0.0 # offset value for title from the default position
527
+ # in the V coordinate (only for 'title' != nil)
528
+ "tickintv" 1 # 0,1,2,3,.. to specify how frequently the
529
+ # dividing tick lines are drawn (0: no tick lines,
530
+ # 1: every time, 2: ever other:,...)
531
+ "labelintv" nil # 0,1,2,3,.. to specify how frequently labels are
532
+ # drawn (0: no labels, 1: every time, 2: ever
533
+ # other:,... default: internally determined)
534
+ "labels_ud" nil # user-defined labels for replacing the default
535
+ # labels (Array of String)
536
+ "charfact" 0.9 # factor to change the label/units/title character
537
+ # size (relative to 'rsizel1')
538
+ "log" false # set the color bar scale to logarithmic
539
+ "constwidth" false # if true, each color is drawn with the same width
540
+ "index" nil # line index of tick lines and bar frame
541
+ "charindex" nil # line index of labels, units, and title
542
+ "chval_fmt" nil # string to specify the DCL.chval format for
543
+ # labeling
544
+ "help" false # show help message if true
545
+
546
+ ===Others
547
+ ---legend(str, type, index, line=false, size=nil, vx=nil, dx=nil, vy=nil, first=true, mark_size=nil)
548
+
549
+ Annotates line/mark type and index (and size if mark).
550
+ By default it is shown in the right margin of the viewport.
551
+
552
+ * str is a String to show
553
+ * line: true->line ; false->mark
554
+ * vx: vx of the left-hand point of legend line (or mark position).
555
+ * nil : internally determined
556
+ * Float && > 0 : set explicitly
557
+ * Float && < 0 : move it relatively to the left from the default
558
+ * dx: length of the legend line (not used if mark).
559
+ * nil : internally determined
560
+ * Float && > 0 : set explicitly
561
+ * vy: vy of the legend (not used if !first -- see below).
562
+ * nil : internally determined
563
+ * Float && > 0 : set explicitly
564
+ * Float && < 0 : move it relatively lower from the default
565
+ * first : if false, vy is moved lower relatively from the previous vy.
566
+ * mark_size : size of the mark. if nil, size is used.
567
+
568
+ ---quasi_log_levels_z(vals, nlev=nil, max=nil, min=nil, cycle=1)
569
+
570
+ Driver of quasi_log_levels with data values
571
+
572
+ ---quasi_log_levels(lev0, lev1, cycle=1)
573
+
574
+ Returns approximately log-scaled contour/tone levels as well as
575
+ major/minor flags for contours. No DCL call is made in here.
576
+
577
+ * cycle (Integer; 1, or 2 or 3) : number of level in one-order.
578
+ e.g. 1,10,100,.. for cycle==1; 1,3,10,30,.. for cycle==2;
579
+ 1,2,5,10,20,50,.. for cycle==3
580
+ * lev0, lev1 (Float) : levels are set between this two params
581
+ * if lev0 & lev1 > 0 : positive only
582
+ * if lev0 & lev1 < 0 : negative only
583
+ * if lev0 * lev1 < 0 : both positive and negative
584
+ (usig +-[lev0.abs,lev1.abs])
585
+ RETURN VALUE:
586
+ * [ levels, mjmn ]
587
+
588
+ =end
589
+ ############################################################
590
+
591
+ module NumRu
592
+
593
+ module DCLExt
594
+ # to be included in the RubyDCL distribution
595
+
596
+ module_function
597
+
598
+ #<<< for many packages >>>
599
+
600
+ %w!gl sg sl sw uz ul uc uu us ud ue ug um!.each do |pkg|
601
+ eval <<-EOS, nil, __FILE__, __LINE__+1
602
+ def #{pkg}_set_params(hash)
603
+ before = Hash.new
604
+ hash.each{|k,v|
605
+ before[k]=DCL.#{pkg}pget(k)
606
+ if(v.is_a? String) then
607
+ DCL.#{pkg}cset(k,v)
608
+ else
609
+ DCL.#{pkg}pset(k,v)
610
+ end
611
+ }
612
+ before
613
+ end
614
+ EOS
615
+ end
616
+
617
+ #<<< module data >>>
618
+
619
+ @@empty_hash = Hash.new
620
+
621
+ #<<< udpack >>>
622
+
623
+ def ud_coloring(clr_min=13, clr_max=99)
624
+ # change the colors of existing contours to make a gradation
625
+ # (rainbow colors with the default color map).
626
+ nlev = DCL.udqcln
627
+ cont_params = Array.new
628
+ for i in 1..nlev
629
+ cont_params.push( DCL.udqclv(i) ) # => [zlev,indx,ityp,clv,hl]
630
+ end
631
+ DCL.udiclv # clear the contours
632
+
633
+ colors = clr_min +
634
+ NArray.int(nlev).indgen! * (clr_max-clr_min) / nlev
635
+
636
+ cont_params.sort!
637
+ for i in 0...nlev
638
+ cont_params[i][1] += colors[i]*10 # indx += colors[i]*10
639
+ DCL.udsclv(*cont_params[i])
640
+ end
641
+ end
642
+
643
+ def ud_set_linear_levs(v, options=nil)
644
+ #Accepted options
645
+ # name default description
646
+ # 'min' nil minimum contour value (Numeric)
647
+ # 'max' nil maximum contour value (Numeric)
648
+ # 'nlev' nil number of levels (Integer)
649
+ # 'interval' nil contour interval (Numeric)
650
+ # 'nozero' false delete zero contour (true/false)
651
+ # 'coloring' false set color contours with ud_coloring (true/false)
652
+ # 'clr_min' 13 (if coloring) minimum color number for the
653
+ # maximum data values (Integer)
654
+ # 'clr_max' 99 (if coloring) maximum color number for the
655
+ # maximum data values (Integer)
656
+ options = @@empty_hash if !options
657
+ raise TypeError, "options must be a Hash" if !options.is_a?(Hash)
658
+ min = options['min']
659
+ max = options['max']
660
+ nlev = options['nlev']
661
+ interval = options['interval']
662
+ nozero = options['nozero']
663
+ if interval
664
+ dx = interval
665
+ elsif nlev
666
+ dx = -nlev
667
+ else
668
+ dx = 0
669
+ end
670
+ if min || max
671
+ min = v.min if !min
672
+ max = v.max if !max
673
+ DCL.udgcla(min, max, dx)
674
+ else
675
+ DCL.udgclb(v, dx)
676
+ end
677
+ if nozero
678
+ DCL.uddclv(0.0)
679
+ end
680
+ if options['coloring']
681
+ clr_min = ( options['clr_min'] || 13 )
682
+ clr_max = ( options['clr_max'] || 99 )
683
+ ud_coloring( clr_min, clr_max )
684
+ end
685
+ end
686
+
687
+ def ud_set_contour(*args)
688
+ DCL.udiclv
689
+ ud_add_contour(*args)
690
+ end
691
+
692
+ def ud_add_contour(levels,index=nil,line_type=nil,label=nil,label_height=nil)
693
+
694
+ # < check levels >
695
+ case levels
696
+ when Array, NArray
697
+ # This is expected. Nothing to do.
698
+ when Numric
699
+ levels = [levels]
700
+ else
701
+ raise ArgumentError, "invalid level specification (#{levels})"
702
+ end
703
+
704
+ nlev = levels.length
705
+
706
+ # < index >
707
+ index = index.to_a if index.is_a?(NArray)
708
+ case index
709
+ when Array
710
+ raise ArgumentError, "index is an empty array" if index.length == 0
711
+ while (index.length < nlev )
712
+ index += index
713
+ end
714
+ when Numeric
715
+ index = [index]*nlev
716
+ when nil
717
+ index = [DCL.udpget('indxmn')]*nlev
718
+ else
719
+ raise ArgumentError, "unsupported index type (#{index.class})"
720
+ end
721
+
722
+ # < line_type >
723
+ line_type = line_type.to_a if line_type.is_a?(NArray)
724
+ case line_type
725
+ when Array
726
+ raise ArgumentError, "line_type is an empty array" if line_type.length == 0
727
+ while (line_type.length < nlev )
728
+ line_type += line_type
729
+ end
730
+ when Numeric
731
+ line_type = [line_type]*nlev
732
+ when nil
733
+ line_type = [1]*nlev
734
+ else
735
+ raise ArgumentError, "unsupported index type (#{index.class})"
736
+ end
737
+
738
+ # < label >
739
+ label = label.to_a if label.is_a?(NArray)
740
+ case label
741
+ when Array
742
+ raise ArgumentError, "label is an empty array" if label.length == 0
743
+ while (label.length < nlev )
744
+ label += label
745
+ end
746
+ when String
747
+ label = [label]*nlev
748
+ when false
749
+ label = [""]*nlev
750
+ when true
751
+ label = (0...nlev).collect{|i|
752
+ DCL.udlabl(levels[i])
753
+ }
754
+ when nil
755
+ indxmj = DCL.udpget('indxmj')
756
+ label = (0...nlev).collect{|i|
757
+ if index[i]==indxmj
758
+ DCL.udlabl(levels[i])
759
+ else
760
+ ""
761
+ end
762
+ }
763
+ else
764
+ raise ArgumentError, "unsupported index type (#{index.class})"
765
+ end
766
+
767
+ # < label_height >
768
+ label_height = label_height.to_a if label_height.is_a?(NArray)
769
+ case label_height
770
+ when Array
771
+ raise ArgumentError, "label_height is an empty array" if label_height.length == 0
772
+ while (label_height.length < nlev )
773
+ label_height += label_height
774
+ end
775
+ when Numeric
776
+ label_height = [label_height]*nlev
777
+ when nil
778
+ label_height = label.collect{|lv| lv=="" ? 0.0 : DCL.udpget('rsizel')}
779
+ else
780
+ raise ArgumentError, "unsupported index type (#{index.class})"
781
+ end
782
+
783
+ # < set levels >
784
+
785
+ for i in 0...nlev
786
+ DCL.udsclv(levels[i],index[i],line_type[i],label[i],label_height[i])
787
+ end
788
+ nil
789
+ end
790
+
791
+ #<<< uepack >>>
792
+
793
+ def ue_set_linear_levs(v, options=nil)
794
+ # 'min' nil minimum tone level (Numeric)
795
+ # 'max' nil maximum tone level (Numeric)
796
+ # 'nlev' nil number of levels (Integer)
797
+ # 'interval' nil tone-level interval (Numeric)
798
+ options = @@empty_hash if !options
799
+ raise TypeError, "options must be a Hash" if !options.is_a?(Hash)
800
+ min = options['min']
801
+ max = options['max']
802
+ nlev = options['nlev']
803
+ interval = options['interval']
804
+ if interval
805
+ dx = interval
806
+ elsif nlev
807
+ dx = -nlev
808
+ else
809
+ dx = 0
810
+ end
811
+ if min || max
812
+ min = v.min if !min
813
+ max = v.max if !max
814
+ DCL.uegtla(min, max, dx)
815
+ else
816
+ v = v.reshape(v.length,1) if v.rank==1
817
+ DCL.uegtlb(v, dx)
818
+ end
819
+ end
820
+
821
+ def ue_set_tone(levels, patterns)
822
+ DCL.ueitlv
823
+ ue_add_tone(levels, patterns)
824
+ end
825
+
826
+ def ue_add_tone(levels, patterns)
827
+
828
+ # < check types >
829
+
830
+ if !levels.is_a?(Array) && !levels.is_a?(NArray)
831
+ raise TypeError, "levels: Array or NArray expected (#{levels.inspect})"
832
+ end
833
+ if !patterns.is_a?(Array) && !patterns.is_a?(NArray)
834
+ raise TypeError, "patterns: Array or NArray expected (#{patterns.inspect})"
835
+ end
836
+
837
+ # < set levels >
838
+
839
+ nlev = levels.length
840
+ npat = patterns.length
841
+
842
+ case (nlev - npat)
843
+ when 1
844
+ for i in 0...nlev-1
845
+ DCL.uestlv(levels[i],levels[i+1],patterns[i])
846
+ end
847
+ when 0
848
+ for i in 0...nlev-1
849
+ DCL.uestlv(levels[i],levels[i+1],patterns[i])
850
+ end
851
+ DCL.uestlv(levels[-1],DCL.glpget('rmiss'),patterns[-1])
852
+ when -1
853
+ DCL.uestlv(DCL.glpget('rmiss'),levels[0],patterns[0])
854
+ for i in 1...nlev
855
+ DCL.uestlv(levels[i-1],levels[i],patterns[i])
856
+ end
857
+ DCL.uestlv(levels[-1],DCL.glpget('rmiss'),patterns[-1])
858
+ else
859
+ raise ArgumentError,
860
+ "lengths of levels(#{nlev}) and patterns(#{npat}) are inconsistent"
861
+ end
862
+ nil
863
+ end
864
+
865
+ ############################################################
866
+ # RELATIVELY INDEPENDENT OF DCL SUBLIBRARIES
867
+ ############################################################
868
+
869
+ # <<< longitude/latitude axes package >>>
870
+
871
+ @@lon_ax_options = Misc::KeywordOptAutoHelp.new(
872
+ ['yax', false, 'true => y-axis, false => x-axis'],
873
+ ['cside', nil, '"b", "t", "l", "r", nil (=>left/bottom), or false (=>right/top)'],
874
+ ['dtick1', nil, 'Interval of small tickmark (if nil, internally determined)'],
875
+ ['dtick2', nil, 'Interval of large tickmark with labels (if nil, internally determined)']
876
+ )
877
+
878
+ def lon_ax(options=nil)
879
+ opt = @@lon_ax_options.interpret(options)
880
+
881
+ yax = opt['yax']
882
+ xax = !yax
883
+ if xax
884
+ xy='x'
885
+ else
886
+ xy='y'
887
+ end
888
+
889
+ if opt['cside']
890
+ cside = opt['cside']
891
+ elsif opt['cside'].nil?
892
+ if xax
893
+ cside='b'
894
+ else
895
+ cside='l'
896
+ end
897
+ else
898
+ if xax
899
+ cside='t'
900
+ else
901
+ cside='r'
902
+ end
903
+ end
904
+
905
+ vxmin, vxmax, vymin, vymax = DCL.sgqvpt
906
+ uxmin, uxmax, uymin, uymax = DCL.sgqwnd
907
+ if xax
908
+ vmin, vmax = [vxmin,vxmax].min, [vxmin,vxmax].max
909
+ umin, umax = [uxmin,uxmax].min, [uxmin,uxmax].max
910
+ else
911
+ vmin, vmax = [vymin,vymax].min, [vymin,vymax].max
912
+ umin, umax = [uymin,uymax].min, [uymin,uymax].max
913
+ end
914
+
915
+ # get dtick1 & dtick2
916
+ dtick1 = opt['dtick1']
917
+ dtick2 = opt['dtick2']
918
+ unless dtick1 && dtick2
919
+ irota = DCL.uzpget("irotl#{xy}#{cside}")
920
+ irota += 1 if yax
921
+ mode = irota.modulo(2)
922
+ DCL.ususcu(xy.capitalize,umin,umax,vmin,vmax,mode)
923
+ dtick1 = DCL.uspget("d#{xy}t") unless dtick1
924
+ dtick2 = DCL.uspget("d#{xy}l") unless dtick2
925
+ end
926
+
927
+ lepsl = DCL.glpget('lepsl')
928
+ repsl = DCL.glpget('repsl')
929
+ DCL.glpset('lepsl',true)
930
+
931
+ # generate numbers for small tickmarks
932
+ nn = 0
933
+ rx = DCL.irle(umin/dtick1)*dtick1
934
+ if DCL.lreq(umin,rx)
935
+ x = rx
936
+ else
937
+ x = rx + dtick1
938
+ end
939
+ u1 = []
940
+ while DCL.lrle(x,umax)
941
+ if x.abs < dtick1*repsl*nn
942
+ x = 0.0
943
+ end
944
+ u1[nn] = x
945
+ nn = nn + 1
946
+ x = x + dtick1
947
+ end
948
+
949
+ # generate numbers for large tickmarks and labels
950
+ nn = 0
951
+ rx = DCL.irle(umin/dtick2)*dtick2
952
+ if DCL.lreq(umin,rx)
953
+ x = rx
954
+ else
955
+ x = rx + dtick2
956
+ end
957
+ u2 = []
958
+ while DCL.lrle(x,umax)
959
+ if x.abs < dtick2*repsl*nn
960
+ x = 0
961
+ end
962
+ u2[nn] = x
963
+ nn = nn + 1
964
+ x = x + dtick2
965
+ end
966
+
967
+ # generate labels
968
+ c2 = NArray.to_na(u2)
969
+ c2[c2.gt(180)] -= 360.0
970
+ c2[c2.lt(-180)] += 360.0
971
+ c2[c2.eq(-180)] = 180.0
972
+ c2 = c2.to_a.collect do |c|
973
+ if c == 0 || c == 180
974
+ c.to_i.to_s
975
+ elsif c > 0
976
+ c.to_i.to_s + 'E'
977
+ else
978
+ c.abs.to_i.to_s + 'W'
979
+ end
980
+ end
981
+ nc = c2.collect{|c| c.size}.max
982
+
983
+ # call DCL.u[xy]axlb
984
+ if xax
985
+ DCL.uxaxlb(cside,u1,u2,c2,nc)
986
+ else
987
+ DCL.uyaxlb(cside,u1,u2,c2,nc)
988
+ end
989
+ end
990
+
991
+ @@lat_ax_options = Misc::KeywordOptAutoHelp.new(
992
+ ['xax', false, 'true => x-axis, false => y-axis'],
993
+ ['cside', nil, '"b", "t", "l", "r", nil (=>left/bottom), or false (=>right/top)'],
994
+ ['dtick1', nil, 'Interval of small tickmark (if nil, internally determined)'],
995
+ ['dtick2', nil, 'Interval of large tickmark with labels (if nil, internally determined)']
996
+ )
997
+
998
+ def lat_ax(options=nil)
999
+ opt = @@lat_ax_options.interpret(options)
1000
+
1001
+ xax = opt['xax']
1002
+ yax = !xax
1003
+ if xax
1004
+ xy='x'
1005
+ else
1006
+ xy='y'
1007
+ end
1008
+
1009
+ if opt['cside']
1010
+ cside = opt['cside']
1011
+ elsif opt['cside'].nil?
1012
+ if xax
1013
+ cside='b'
1014
+ else
1015
+ cside='l'
1016
+ end
1017
+ else
1018
+ if xax
1019
+ cside='t'
1020
+ else
1021
+ cside='r'
1022
+ end
1023
+ end
1024
+
1025
+ vxmin, vxmax, vymin, vymax = DCL.sgqvpt
1026
+ uxmin, uxmax, uymin, uymax = DCL.sgqwnd
1027
+ if xax
1028
+ vmin, vmax = [vxmin,vxmax].min, [vxmin,vxmax].max
1029
+ umin, umax = [uxmin,uxmax].min, [uxmin,uxmax].max
1030
+ else
1031
+ vmin, vmax = [vymin,vymax].min, [vymin,vymax].max
1032
+ umin, umax = [uymin,uymax].min, [uymin,uymax].max
1033
+ end
1034
+
1035
+ # get dtick1 & dtick2
1036
+ dtick1 = opt['dtick1']
1037
+ dtick2 = opt['dtick2']
1038
+ unless dtick1 && dtick2
1039
+ irota = DCL.uzpget("irotl#{xy}#{cside}")
1040
+ irota += 1 if yax
1041
+ mode = irota.modulo(2)
1042
+ DCL.ususcu(xy.capitalize,umin,umax,vmin,vmax,mode)
1043
+ dtick1 = DCL.uspget("d#{xy}t") unless dtick1
1044
+ dtick2 = DCL.uspget("d#{xy}l") unless dtick2
1045
+ end
1046
+
1047
+ lepsl = DCL.glpget('lepsl')
1048
+ repsl = DCL.glpget('repsl')
1049
+ DCL.glpset('lepsl',true)
1050
+
1051
+ # generate numbers for small tickmarks
1052
+ nn = 0
1053
+ rx = DCL.irle(umin/dtick1)*dtick1
1054
+ if DCL.lreq(umin,rx)
1055
+ x = rx
1056
+ else
1057
+ x = rx + dtick1
1058
+ end
1059
+ u1 = []
1060
+ while DCL.lrle(x,umax)
1061
+ if x.abs < dtick1*repsl*nn
1062
+ x = 0.0
1063
+ end
1064
+ u1[nn] = x
1065
+ nn = nn + 1
1066
+ x = x + dtick1
1067
+ end
1068
+
1069
+ # generate numbers for large tickmarks and labels
1070
+ nn = 0
1071
+ rx = DCL.irle(umin/dtick2)*dtick2
1072
+ if DCL.lreq(umin,rx)
1073
+ x = rx
1074
+ else
1075
+ x = rx + dtick2
1076
+ end
1077
+ u2 = []
1078
+ while DCL.lrle(x,umax)
1079
+ if x.abs < dtick2*repsl*nn
1080
+ x = 0
1081
+ end
1082
+ u2[nn] = x
1083
+ nn = nn + 1
1084
+ x = x + dtick2
1085
+ end
1086
+
1087
+ # generate labels
1088
+ c2 = NArray.to_na(u2)
1089
+ c2 = c2.to_a.collect do |c|
1090
+ if c == 0
1091
+ 'EQ'
1092
+ elsif c > 0
1093
+ c.to_i.to_s + 'N'
1094
+ else
1095
+ c.abs.to_i.to_s + 'S'
1096
+ end
1097
+ end
1098
+ nc = c2.collect{|c| c.size}.max
1099
+
1100
+ # call DCL.u[xy]axlb
1101
+ if xax
1102
+ DCL.uxaxlb(cside,u1,u2,c2,nc)
1103
+ else
1104
+ DCL.uyaxlb(cside,u1,u2,c2,nc)
1105
+ end
1106
+ end
1107
+
1108
+ # <<< flow vector package >>>
1109
+
1110
+ def __truncate(float, order=2)
1111
+ # truncate (round) a floating number with the number digits
1112
+ # specified by "order".
1113
+ # e.g., if order=3, -0.012345 => -0.0123; 6.6666 => 6.67
1114
+ exponent = 10**(-Math::log10(float.abs).floor+order-1)
1115
+ (float * exponent).round.to_f/exponent
1116
+ end
1117
+
1118
+ @@unit_vect_options = Misc::KeywordOptAutoHelp.new(
1119
+ ['vxunit', 0.05, "x unit vect len in V coord. Used only when fxunit is omitted (default)"],
1120
+ ['vyunit', 0.05, "y unit vect len in V coord. Used only when fyunit is omitted (default)"],
1121
+ ['vxuloc', nil, "Starting x position of unit vect"],
1122
+ ['vyuloc', nil, "Starting y position of unit vect"],
1123
+ ['vxuoff', 0.05, "Specify vxuloc by offset from right-bottom corner"],
1124
+ ['vyuoff', 0.0, "Specify vyuloc by offset from right-bottom corner"],
1125
+ ['inplace',true, "Whether to print labels right by the unit vector (true) or below the x axis (false)"],
1126
+ ['rsizet', nil, "Label size(default taken from uz-parameter 'rsizel1')"],
1127
+ ['index', 3," Line index of the unit vector"],
1128
+ ['vertical', true,"(used only in unit_vect_single) the unit vector is directed upward if true, to the right if not."]
1129
+ )
1130
+
1131
+ def set_unit_vect_options(options)
1132
+ @@unit_vect_options.set(options)
1133
+ end
1134
+
1135
+ @@next_unit_vect_options = nil
1136
+ def next_unit_vect_options(options)
1137
+ if options.is_a?(Hash)
1138
+ @@next_unit_vect_options = options
1139
+ else
1140
+ raise TypeError,"Hash expected"
1141
+ end
1142
+ nil
1143
+ end
1144
+
1145
+ def unit_vect( vxfxratio, # (V cood length)/(actual length) in x
1146
+ vyfyratio, # (V cood length)/(actual length) in y
1147
+ fxunit=nil, # If specified, x unit vect len
1148
+ fyunit=nil, # If specified, y unit vect len
1149
+ options=nil )
1150
+ #< options >
1151
+ if @@next_unit_vect_options
1152
+ options = ( options ? @@next_unit_vect_options.update(options) :
1153
+ @@next_unit_vect_options )
1154
+ @@next_unit_vect_options = nil
1155
+ end
1156
+ opt = @@unit_vect_options.interpret(options)
1157
+ vxunit = opt['vxunit']
1158
+ vyunit = opt['vyunit']
1159
+ vxuloc = opt['vxuloc']
1160
+ vyuloc = opt['vyuloc']
1161
+ rsizet = opt['rsizet']
1162
+ index = opt['index']
1163
+
1164
+ #< unit vector >
1165
+ if fxunit
1166
+ vxunit = vxfxratio * fxunit
1167
+ else
1168
+ fxunit = vxunit / vxfxratio
1169
+ end
1170
+ if fyunit
1171
+ vyunit = vyfyratio * fyunit
1172
+ else
1173
+ fyunit = vyunit / vyfyratio
1174
+ end
1175
+ fxunit = __truncate( (uxusv=fxunit) )
1176
+ fyunit = __truncate( (uyusv=fyunit) )
1177
+ vxunit = vxunit * (fxunit/uxusv)
1178
+ vyunit = vyunit * (fyunit/uyusv)
1179
+ if !(vxuloc && vyuloc)
1180
+ vx0,vx1,vy0,vy1 = DCL.sgqvpt
1181
+ vxuloc = vx1 + opt['vxuoff'] if !vxuloc
1182
+ vyuloc = vy0 + opt['vyuoff'] if !vyuloc
1183
+ end
1184
+ DCL.sglazv( vxuloc, vyuloc, vxuloc+vxunit, vyuloc, 1, index )
1185
+ DCL.sglazv( vxuloc, vyuloc, vxuloc, vyuloc+vyunit, 1, index )
1186
+
1187
+ #< labelling >
1188
+ sfxunit = sprintf("%.2g",fxunit)
1189
+ sfyunit = sprintf("%.2g",fyunit)
1190
+ rsizet = DCL.uzpget('rsizel1') if !rsizet
1191
+ if opt['inplace']
1192
+ DCL.sgtxzv(vxuloc, vyuloc-1.2*rsizet,
1193
+ sfxunit, rsizet, 0, -1, index)
1194
+ DCL.sgtxzv(vxuloc+1.2*rsizet, vyuloc+0.5*rsizet,
1195
+ sfyunit, rsizet, 90, -1, index)
1196
+ else
1197
+ msg= "UNIT VECTOR X:#{sfxunit} Y:#{sfyunit}"
1198
+ before = uz_set_params({'rsizec1'=>rsizet})
1199
+ DCL.uxsttl('b',' ',0.0)
1200
+ DCL.uxsttl('b',msg,0.0)
1201
+ uz_set_params(before)
1202
+ end
1203
+ end
1204
+
1205
+ def unit_vect_single(vfratio, flen, options=nil )
1206
+ #< options >
1207
+ if @@next_unit_vect_options
1208
+ options = ( options ? @@next_unit_vect_options.update(options) :
1209
+ @@next_unit_vect_options )
1210
+ @@next_unit_vect_options = nil
1211
+ end
1212
+ opt = @@unit_vect_options.interpret(options)
1213
+ vxuloc = opt['vxuloc']
1214
+ vyuloc = opt['vyuloc']
1215
+ rsizet = opt['rsizet'] || DCL.uzpget('rsizel1')
1216
+ index = opt['index']
1217
+ vertical = opt['vertical']
1218
+
1219
+ #< show the unit vector and the label >
1220
+
1221
+ if !(vxuloc && vyuloc)
1222
+ vx0,vx1,vy0,vy1 = DCL.sgqvpt
1223
+ vxuloc = vx1 + opt['vxuoff'] if !vxuloc
1224
+ vyuloc = vy0 + opt['vyuoff'] if !vyuloc
1225
+ end
1226
+ vlen = vfratio * flen
1227
+ label = DCL.chval("B",flen)
1228
+
1229
+ lclip_bk = DCL::sglget("lclip")
1230
+ DCL::sglset("lclip", false)
1231
+ if vertical
1232
+ DCL.sglazv( vxuloc, vyuloc, vxuloc, vyuloc+vlen, 1, index )
1233
+ DCL.sgtxzv( vxuloc+1.2*rsizet, vyuloc+0.4*vlen,
1234
+ label, rsizet, 90, 0, index)
1235
+ else
1236
+ DCL.sglazv( vxuloc, vyuloc, vxuloc+vlen, vyuloc, 1, index )
1237
+ DCL.sgtxzv( vxuloc+0.4*vlen, vyuloc-1.2*rsizet,
1238
+ label, rsizet, 0, 0, index)
1239
+ end
1240
+ DCL::sglset("lclip", lclip_bk)
1241
+ nil
1242
+ end
1243
+
1244
+ def flow_vect( fx, fy, factor=1.0, xintv=1, yintv=1,
1245
+ vxfxratio=nil, vyfyratio=nil)
1246
+ raise ArgumentError,"Expect 2D arrays" if fx.rank != 2 || fy.rank != 2
1247
+ raise ArgumentError,"fx.shape != fy.shape" if fx.shape != fy.shape
1248
+ raise ArgumentError,"xintv must be a positive integer" if xintv < 0
1249
+ raise ArgumentError,"yintv must be a positive integer" if yintv < 0
1250
+ nx, ny = fx.shape
1251
+ if xintv >= 2
1252
+ idx = NArray.int(nx/xintv).indgen!*xintv # [0,xintv,2*xintv,..]
1253
+ fx = fx[idx, true]
1254
+ fy = fy[idx, true]
1255
+ end
1256
+ if yintv >= 2
1257
+ idx = NArray.int(ny/yintv).indgen!*yintv # [0,yintv,2*yintv,..]
1258
+ fx = fx[true, idx]
1259
+ fy = fy[true, idx]
1260
+ end
1261
+ nx, ny = fx.shape # again, because of xintv & yintv
1262
+ vx0,vx1,vy0,vy1 = DCL.sgqvpt
1263
+ wnd = DCL.sgqwnd
1264
+ if wnd.include?(DCL.glrget('rundef'))
1265
+ ux0,ux1,uy0,uy1 = DCL.sgqtxy
1266
+ else
1267
+ ux0,ux1,uy0,uy1 = wnd
1268
+ end
1269
+ dvx = (vx1-vx0)/nx
1270
+ dvy = (vy1-vy0)/ny
1271
+ ax = (vx1-vx0)/(ux1-ux0) # factor to convert from U to V coordinate
1272
+ ay = (vy1-vy0)/(uy1-uy0) # factor to convert from U to V coordinate
1273
+ fxmx = fx.abs.max
1274
+ fymx = fy.abs.max
1275
+ raise "fx has no data or all zero" if fxmx == 0
1276
+ raise "fy has no data or all zero" if fymx == 0
1277
+ cn = [ dvx/(ax*fxmx), dvy/(ay*fymx) ].min # normarization constant
1278
+ vxfxratio = factor*cn*ax if !vxfxratio
1279
+ vyfyratio = factor*cn*ay if !vyfyratio
1280
+ before = ug_set_params( {'LNRMAL'=>false, 'LMSG'=>false,
1281
+ 'XFACT1'=>1.0, 'YFACT1'=>1.0} )
1282
+ DCL.ugvect( vxfxratio*fx, vyfyratio*fy )
1283
+ ug_set_params( before )
1284
+ unit_vect_info = [ vxfxratio, vyfyratio, fxmx, fymx ]
1285
+ return unit_vect_info
1286
+ end
1287
+
1288
+ def flow_vect_anyproj(fx, fy, xg, yg,
1289
+ factor=1.0, xintv=1, yintv=1,
1290
+ distvect_map=true, vfratio=nil, polar_thinning=nil)
1291
+
1292
+ #< parameters to handle singularity of the projection >
1293
+
1294
+ ddv = 0.3e-3 # Initial value for viewport sampling to find directions.
1295
+ # This parameter is modified below if the round off error
1296
+ # may be severe.
1297
+ eps = 0.05 # Allowed maximum inconsistency in two sampling results
1298
+ acc = 1e7 # order of mantissa of sfloat
1299
+ epsbk = 3e-6 # factor to judge whether a grid point is on the backside
1300
+ # when the projection is multi-valued as map projections
1301
+
1302
+ #< preparation >
1303
+
1304
+ raise ArgumentError,"Expect 2D arrays" if fx.rank != 2 || fy.rank != 2
1305
+ raise ArgumentError,"fx.shape != fy.shape" if fx.shape != fy.shape
1306
+ raise ArgumentError,"xintv must be a positive integer" if xintv < 0
1307
+ raise ArgumentError,"yintv must be a positive integer" if yintv < 0
1308
+ nx, ny = fx.shape
1309
+ if xg.rank == 1
1310
+ raise ArgumentError,"len of xg (#{xg.length}) != #{nx}" if xg.length!=nx
1311
+ else
1312
+ raise ArgumentError,"xg.shape != shape of data" if xg.shape != fx.shape
1313
+ end
1314
+ if yg.rank == 1
1315
+ raise ArgumentError,"len of yg (#{yg.length}) != #{ny}" if yg.length!=ny
1316
+ else
1317
+ raise ArgumentError,"yg.shape != shape of data" if yg.shape != fx.shape
1318
+ end
1319
+ if xintv >= 2
1320
+ idx = NArray.int(nx/xintv).indgen!*xintv # [0,xintv,2*xintv,..]
1321
+ fx = fx[idx, true]
1322
+ fy = fy[idx, true]
1323
+ xg = xg[idx, false]
1324
+ end
1325
+ if yintv >= 2
1326
+ idx = NArray.int(ny/yintv).indgen!*yintv # [0,yintv,2*yintv,..]
1327
+ fx = fx[true, idx]
1328
+ fy = fy[true, idx]
1329
+ yg = yg[false,idx]
1330
+ end
1331
+ nx, ny = fx.shape # again, because of xintv & yintv
1332
+
1333
+ #< read DCL parameters >
1334
+
1335
+ index = DCL.ugpget('index')
1336
+ rsizem = DCL.ugpget('rsizem')
1337
+ itype2 = DCL.ugpget('itype2')
1338
+ lmissp = DCL.ugpget('lmissp')
1339
+ lmiss = DCL.glpget('lmiss')
1340
+ rmiss = DCL.glpget('rmiss')
1341
+
1342
+ #< Missing value treatment >
1343
+ # -- needed to later caluculate flenmax properly
1344
+
1345
+ if lmiss
1346
+ fx = NArrayMiss.to_nam(fx, fx.ne(rmiss)) if fx.is_a?(NArray)
1347
+ fy = NArrayMiss.to_nam(fy, fy.ne(rmiss)) if fy.is_a?(NArray)
1348
+ end
1349
+
1350
+ #< DCL scales >
1351
+
1352
+ wnd = DCL.sgqwnd
1353
+ if wnd.include?(DCL.glrget('rundef'))
1354
+ ux0,ux1,uy0,uy1 = DCL.sgqtxy
1355
+ else
1356
+ ux0,ux1,uy0,uy1 = wnd
1357
+ end
1358
+ flen = Misc::EMath.sqrt( fx*fx + fy*fy )
1359
+ flenmax = flen.max
1360
+ if !vfratio
1361
+ vx0,vx1,vy0,vy1 = DCL.sgqvpt
1362
+ dvf = Math::sqrt( (vx1-vx0)*(vy1-vy0)/nx/ny )
1363
+ vfratio = factor * dvf / flenmax # factor to get arrow length in V crd
1364
+ end
1365
+
1366
+ #< parameter modification if needed >
1367
+ r = [ [ux0.abs, ux1.abs].min / (ux0-ux1).abs,
1368
+ [uy0.abs, uy1.abs].min / (uy0-uy1).abs ].max
1369
+ e = acc*ddv*eps
1370
+ if ( r > e )
1371
+ # ddv is too small for the current window, so the round off error
1372
+ # may be severer. --> increase it up to a prescribed limit.
1373
+ ddv = [ r/e*ddv, 0.1 ].min
1374
+ end
1375
+
1376
+ #< handling of distance-based vectors under map projection >
1377
+
1378
+ itr = DCL::sgqtrn
1379
+ map_proj = ( itr >= 10 and itr <= 40 )
1380
+ if map_proj and distvect_map
1381
+ cosphi = Misc::EMath.cos( yg * (Math::PI/180.0) )
1382
+ umodi = true
1383
+ else
1384
+ umodi = false
1385
+ end
1386
+
1387
+ #< vector drawing >
1388
+
1389
+ if map_proj
1390
+ uodr = 360.0 # order of domain size in U coordinate
1391
+ else
1392
+ uodr = [xg.max, -xg.min, yg.max, -yg.min].max
1393
+ end
1394
+ dbk = epsbk*uodr
1395
+
1396
+ u = NMatrix.float(2,2) # NMatrix's index: [column,row]
1397
+ ap = NMatrix.float(2,2)
1398
+ an = NMatrix.float(2,2)
1399
+ for j in 0...ny
1400
+ if polar_thinning && xg.rank==1 && yg.rank==1
1401
+ j1 = [j+1,ny-1].min
1402
+ dy=(yg[j1]-yg[j1-1]).abs
1403
+ dx = (xg[1]-xg[0]).abs * cos(yg[j]/180*Math::PI)
1404
+ xstep = [ (dy / dx * polar_thinning).round, 1 ].max
1405
+ else
1406
+ xstep = 1
1407
+ end
1408
+ (0...nx).step(xstep) do |i|
1409
+ x = ( xg.rank==1 ? xg[i] : xg[i,j] )
1410
+ y = ( yg.rank==1 ? yg[j] : yg[i,j] )
1411
+ if ( ( fx.is_a?(NArrayMiss) && !fx.valid?(i,j) ) ||
1412
+ ( fy.is_a?(NArrayMiss) && !fy.valid?(i,j) ) )
1413
+ DCL.sgpmzu([x],[y],itype2,index,rsizem) if lmissp
1414
+ next
1415
+ end
1416
+ vx0, vy0 = DCL.stftrf(x, y)
1417
+ xrev, yrev = DCL.stitrf(vx0, vy0)
1418
+ xdif = (xrev-x).abs
1419
+ ydif = (yrev-y).abs
1420
+ xdif = 360.0-xdif if map_proj && xdif > 359.0
1421
+ if xdif > dbk || ydif > dbk
1422
+ next # Not plotted, because the current point is on the backside
1423
+ end
1424
+ if umodi
1425
+ cos = ( cosphi.rank==1 ? cosphi[j] : cosphi[i,j] )
1426
+ end
1427
+ um = NMatrix[ [x,x], [y,y] ]
1428
+ u[0,0],u[0,1] = DCL.stitrf(vx0+ddv, vy0)
1429
+ u[1,0],u[1,1] = DCL.stitrf(vx0, vy0+ddv)
1430
+ ap = u - um
1431
+ (ap[true,0] >= 180.0).where.to_a.each{|i| ap[i,0] -= 360.0}
1432
+ (ap[true,0] <= -180.0).where.to_a.each{|i| ap[i,0] += 360.0}
1433
+ u[0,0],u[0,1] = DCL.stitrf(vx0-ddv, vy0)
1434
+ u[1,0],u[1,1] = DCL.stitrf(vx0, vy0-ddv)
1435
+ an = um - u
1436
+ (an[true,0] >= 180.0).where.to_a.each{|i| an[i,0] -= 360.0}
1437
+ (an[true,0] <= -180.0).where.to_a.each{|i| an[i,0] += 360.0}
1438
+ if umodi
1439
+ ap[0,0] *= cos
1440
+ ap[1,0] *= cos
1441
+ an[0,0] *= cos
1442
+ an[1,0] *= cos
1443
+ end
1444
+ f = NVector[ fx[i,j],fy[i,j] ]
1445
+ vfp = nil
1446
+ begin
1447
+ aip = ap.inverse
1448
+ vfp = aip * f
1449
+ rescue
1450
+ end
1451
+ vfn = nil
1452
+ begin
1453
+ ain = an.inverse
1454
+ vfn = ain * f
1455
+ rescue
1456
+ end
1457
+ if vfp && vfn
1458
+ vf = (vfp+vfn)/2
1459
+ err = (vfp - vfn).abs.max / vf.abs.max
1460
+ vn = vf * ( vfratio*flen[i,j] / Math.sqrt(vf[0]**2+vf[1]**2) )
1461
+ if err>=eps
1462
+ DCL.sgpmzv([vx0],[vy0],itype2,index,rsizem) if lmissp
1463
+ elsif vn[0].nan? || vn[1].nan?
1464
+ DCL.sgpmzv([vx0],[vy0],itype2,index,rsizem)
1465
+ else
1466
+ DCL.sglazv(vx0, vy0, vx0+vn[0], vy0+vn[1], 1, index)
1467
+ end
1468
+ end
1469
+ end
1470
+ end
1471
+ [ vfratio, flenmax ]
1472
+ end
1473
+
1474
+
1475
+
1476
+ def flow_itr5( gpx, gpy, factor=1.0, unit_vect=false )
1477
+ raise ArgumentError,"Expect 2D arrays" if gpx.rank != 2 || gpy.rank != 2
1478
+ raise ArgumentError,"gpx.shape != gpy.shape" if gpx.shape != gpy.shape
1479
+
1480
+ raise "Transform. No. should be 5" if DCL.sgpget('itr') != 5
1481
+
1482
+ theta = gpx.coord(1) / 180 * Math::PI
1483
+ theta = theta.reshape(1,theta.shape[0])
1484
+
1485
+ vx = gpx * theta.cos - gpy * theta.sin # UC component -> VC
1486
+ vy = gpx * theta.sin + gpy * theta.cos # UC component -> VC
1487
+
1488
+ DCL.sglset('LCLIP',false)
1489
+ before1 = DCLExt.ug_set_params(
1490
+ {'LUNIT'=>true, 'LUMSG'=>true} ) if unit_vect
1491
+ before2 = DCLExt.ug_set_params(
1492
+ {'LNRMAL'=>false,
1493
+ 'XFACT1'=>factor, 'YFACT1'=>factor} ) if factor != 1.0
1494
+ DCL.ugvect( vx.val, vy.val )
1495
+
1496
+ if unit_vect
1497
+ uxunit = sprintf("%.2g",DCL.ugrget('UXUNIT'))
1498
+ uyunit = sprintf("%.2g",DCL.ugrget('UXUNIT'))
1499
+ vxuloc = DCL.ugrget('VXULOC')
1500
+ vyuloc = DCL.ugrget('VYULOC')
1501
+ rsize = DCL.ugrget('RSIZET')
1502
+ dv = rsize
1503
+ DCL.sgtxzv(vxuloc, vyuloc-dv, uxunit, rsize, 0, -1, 3 )
1504
+ DCL.sgtxzv(vxuloc-dv, vyuloc, uyunit, rsize, 90, -1, 3 )
1505
+ end
1506
+
1507
+ ug_set_params( before2 ) if factor != 1.0
1508
+ ug_set_params( before1 ) if unit_vect
1509
+ end
1510
+
1511
+ ######################################
1512
+
1513
+ # <<< color bar >>>
1514
+
1515
+ @@color_bar_options = Misc::KeywordOptAutoHelp.new(
1516
+ ["levels", nil, "tone levels (if omitted, latest ones are used)"],
1517
+ ["patterns", nil, "tone patterns (~colors) (if omitted, latest ones are used)"],
1518
+ ["voff", nil, "how far is the bar from the viewport in the V coordinate"],
1519
+ ["vcent",nil, "center position of the bar in the V coordinate (VX or VY)"],
1520
+ ["vlength", 0.3, "bar length in the V coordinate"],
1521
+ ["vwidth", 0.02, "bar width in the V coordinate"],
1522
+ ["inffact", 2.25, "factor to change the length of triangle on the side for infinity (relative to 'vwidth')"],
1523
+ ["landscape", false, "if true, horizonlly long (along x axes)"],
1524
+ ["portrait", true, "if true, vertically long (along y axes)"],
1525
+ ["top", false, "place the bar at the top (effective if landscape)"],
1526
+ ["left", false, "place the bar in the left (effective if portrait)"],
1527
+ ["units", nil, "units of the axis of the color bar"],
1528
+ ["units_voff", 0.0, "offset value for units from the default position in the V coordinate (only for 'units' != nil)"],
1529
+ ["title", nil, "title of the color bar"],
1530
+ ["title_voff", 0.0, "offset value for title from the default position in the V coordinate (only for 'title' != nil)"],
1531
+ ["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:,...)"],
1532
+ ["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)"],
1533
+ ["labels_ud", nil, "user-defined labels for replacing the default labels (Array of String)"],
1534
+ ["charfact", 0.9, "factor to change the label/units/title character size (relative to 'rsizel1')"],
1535
+ ["log", false, "set the color bar scale to logarithmic"],
1536
+ ["constwidth", false, "if true, each color is drawn with the same width"],
1537
+ ["index", nil, "index of tick lines and bar frame"],
1538
+ ["charindex", nil, "index of labels, units, and title"],
1539
+ ["chval_fmt", nil, "string to specify the DCL.chval format for labeling"]
1540
+ )
1541
+
1542
+ def set_color_bar_options(options)
1543
+ @@color_bar_options.set(options)
1544
+ end
1545
+
1546
+ def log10_safe(val)
1547
+ begin
1548
+ Math::log10(val)
1549
+ rescue Errno::ERANGE
1550
+ nil
1551
+ end
1552
+ end
1553
+
1554
+ def log10_or_0(val)
1555
+ log10_safe(val) || 0
1556
+ end
1557
+
1558
+ def level_chval_fmt(max,min,dx)
1559
+ # returns a format for DCL.chval suitable for color-ba labels
1560
+ dxabs = dx.abs
1561
+ eps = 1e-4 * dxabs
1562
+ order = log10_or_0(dxabs).floor
1563
+ if ( (dxabs+eps*0.1) % 10**order < eps )
1564
+ # 1 keta
1565
+ least_order = order
1566
+ else
1567
+ # >=2 keta --> limit to 2 keta
1568
+ least_order = order - 1
1569
+ end
1570
+ ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
1571
+ if ng <= 3
1572
+ fmt = 'b'
1573
+ else
1574
+ n = log10_or_0([max.abs,min.abs].max).floor
1575
+ nn = log10_or_0([max.abs,min.abs].min).floor
1576
+ if least_order >= 0 and nn >= 0
1577
+ ifg = 'i'
1578
+ elsif 0 <= n and n <= 4
1579
+ ifg = 'f'
1580
+ else
1581
+ ifg = 'g'
1582
+ end
1583
+ case(ifg)
1584
+ when 'i'
1585
+ fmt = '(i15)'
1586
+ when 'g'
1587
+ ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
1588
+ ng = [ ng, 2 ].max
1589
+ fmt = "(g15.#{ng})"
1590
+ when 'f'
1591
+ nf = [ -least_order, 0].max
1592
+ fmt = "(f15.#{nf})"
1593
+ end
1594
+ end
1595
+ fmt
1596
+ end
1597
+
1598
+ def sprintf_level(x,max,min,dx)
1599
+ # format a float for color-bar labels.
1600
+ # like DCL.hval('b',x) but changes according to dx
1601
+ if x==0
1602
+ fg = 'f'
1603
+ else
1604
+ n = log10_or_0(x.abs).floor
1605
+ if 0 <= n and n <= 4
1606
+ fg = 'f'
1607
+ else
1608
+ fg = 'g'
1609
+ end
1610
+ end
1611
+ eps = 1e-6
1612
+ if ( dx.abs % 10**log10_or_0(dx.abs) < eps )
1613
+ # 1 keta
1614
+ least_order = log10_or_0(dx.abs).floor
1615
+ else
1616
+ # >=2 keta --> limit to 2 keta
1617
+ least_order = log10_or_0(dx.abs).floor - 1
1618
+ end
1619
+ if fg == 'g'
1620
+ ng = log10_or_0([max.abs,min.abs,eps].max).floor - least_order + 1
1621
+ ng = [ ng, 2 ].max
1622
+ fmt = "%.#{ng}g"
1623
+ else
1624
+ nf = [ -least_order, 0].max
1625
+ fmt = "%.#{nf}f"
1626
+ end
1627
+ sprintf(fmt,x).sub(/\.0*$/,'')
1628
+ end
1629
+
1630
+ def color_bar(options=nil)
1631
+
1632
+ # < set parameters >
1633
+ opt = @@color_bar_options.interpret(options)
1634
+ lsetx = DCL.uwqgxz
1635
+ lsety = DCL.uwqgyz
1636
+
1637
+ rmiss = DCL.glrget('rmiss')
1638
+
1639
+ levels = opt['levels']
1640
+ patterns = opt['patterns']
1641
+
1642
+ if (levels.nil? && !patterns.nil?) || (!levels.nil? && patterns.nil?)
1643
+ raise "levels and patterns must be set at same time\n"
1644
+ end
1645
+
1646
+ landscape = opt["landscape"] || !opt["portrait"]
1647
+ portrait = ! landscape
1648
+
1649
+ if !levels.nil?
1650
+ ue_set_tone(levels,patterns)
1651
+ end
1652
+
1653
+ labels_ud = opt["labels_ud"]
1654
+ if !labels_ud.nil?
1655
+ if labels_ud.class != Array
1656
+ raise ArgumentError,"'labels_ud' must be an Array of String"
1657
+ elsif labels_ud.size == 0
1658
+ raise ArgumentError,"'labels_ud' must be an Array of String"
1659
+ else
1660
+ labels_ud.each do |lbl_ud|
1661
+ if lbl_ud.class != String
1662
+ raise ArgumentError,"'labels_ud' must be an Array of String"
1663
+ end
1664
+ end
1665
+ end
1666
+ end
1667
+
1668
+ if opt["index"]
1669
+ index = opt["index"]
1670
+ index = 1 if index <= 0
1671
+ else
1672
+ index = DCL::uziget("indext2")
1673
+ end
1674
+ indext1_bk = DCL::uziget("indext1")
1675
+ indext2_bk = DCL::uziget("indext2")
1676
+ DCL::uziset("indext1",index)
1677
+ DCL::uziset("indext2",index)
1678
+
1679
+ if opt["charindex"]
1680
+ charindex = opt["charindex"]
1681
+ charindex = 1 if charindex <= 0
1682
+ else
1683
+ charindex = DCL::uziget("indexl1")
1684
+ end
1685
+ indexl1_bk = DCL::uziget("indexl1")
1686
+ DCL::uziset("indexl1",charindex)
1687
+
1688
+ charfact = opt["charfact"]
1689
+ rsizel1_bk = DCL::uzrget("rsizel1")
1690
+ DCL::uzrset("rsizel1",charfact*rsizel1_bk)
1691
+
1692
+ nton = DCL::ueqntl
1693
+ if nton==0
1694
+ raise "no tone patern was set\n"
1695
+ end
1696
+ lev1 = Array.new
1697
+ lev2 = Array.new
1698
+ patterns = Array.new if !opt['patterns']
1699
+ for n in 0..nton-1
1700
+ tlev1,tlev2,ipat = DCL::ueqtlv(n+1)
1701
+ lev1.push(tlev1)
1702
+ lev2.push(tlev2)
1703
+ patterns.push(ipat) if !opt['patterns']
1704
+ end
1705
+
1706
+ #levels = lev1+lev2
1707
+ #levels = levels.uniq.sort
1708
+ #levels.delete(rmiss)
1709
+ #if levels.ne(levels.sort).any?
1710
+ # raise "levels is not in order\n"
1711
+ #end
1712
+
1713
+ levels = lev1.push(lev2[-1]) if !levels
1714
+ levels = NArray.to_na(levels) if levels.is_a?(Array)
1715
+ patterns = NArray.to_na(patterns) if patterns.is_a?(Array)
1716
+
1717
+ vx1, vx2, vy1, vy2 = DCL.sgqvpt
1718
+
1719
+ if opt['log']
1720
+ lv = levels[levels.ne(rmiss).where]
1721
+ if lv.length >= 4 && lv[0]*lv[-1]<0
1722
+ iturn = 0
1723
+ for i in 0...levels.length
1724
+ if levels[i] != rmiss
1725
+ if levels[i]*lv[0] < 0
1726
+ iturn = i
1727
+ break
1728
+ end
1729
+ end
1730
+ end
1731
+ opt['vlength'] /= 2
1732
+ vc0 = opt['vcent'] || ( portrait && (vy1+vy2)/2) || (vx1+vx2)/2
1733
+
1734
+ opt["voff"] ||=
1735
+ DCL.uzrget('pad1')*DCL::uzrget("rsizec2") +
1736
+ ( portrait ? DCL.uzrget('roffyr') : - DCL.uzrget('roffxb') )
1737
+
1738
+ vsep2 = 0.02
1739
+
1740
+ opt['levels'] = levels[0..iturn-1]
1741
+ opt['patterns'] = patterns[0..iturn-2]
1742
+ opt['vcent'] = vc0 - opt['vlength']/2 - vsep2
1743
+ units = opt['units']
1744
+ opt['units'] = nil
1745
+ color_bar(opt)
1746
+
1747
+ opt['levels'] = levels[iturn..-1]
1748
+ opt['patterns'] = patterns[iturn..-1]
1749
+ opt['vcent'] = vc0 + opt['vlength']/2 + vsep2
1750
+ opt['units'] = units
1751
+ color_bar(opt)
1752
+
1753
+ # fill between the two bars
1754
+ if portrait
1755
+ x1 = vx2 + opt["voff"]
1756
+ x2 = x1 + opt['vwidth']
1757
+ y1 = vc0 - vsep2
1758
+ y2 = vc0 + vsep2
1759
+ else
1760
+ x1 = vc0 - vsep2
1761
+ x2 = vc0 + vsep2
1762
+ y1 = vy1 - opt["voff"]
1763
+ y2 = y1 - opt['vwidth']
1764
+ end
1765
+ bk = DCLExt.sg_set_params({'lclip'=>false})
1766
+ DCL.sgtnzv([x1,x2,x2,x1],[y1,y1,y2,y2],patterns[iturn-1])
1767
+ DCL.sgplzv([x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1],1,3)
1768
+ DCLExt.sg_set_params(bk)
1769
+ return
1770
+ end
1771
+ end
1772
+
1773
+ if levels.length <= 1
1774
+ $stderr.print( "WARNING #{__FILE__}:#{__LINE__}: # of levels <= 1. No color bar is drawn." )
1775
+ return
1776
+ end
1777
+
1778
+ # BACKUP CURRENT PARAMETERS
1779
+ itrsv = DCL::sgqtrn
1780
+ if itrsv <= 4
1781
+ ux1sv, ux2sv, uy1sv, uy2sv = DCL.sgqwnd
1782
+ elsif itrsv <= 9
1783
+ simfacsv, vxoffsv, vyoffsv = DCL.sgqsim
1784
+ else
1785
+ ux1sv, ux2sv, uy1sv, uy2sv = DCL.sgqwnd
1786
+ simfacsv, vxoffsv, vyoffsv = DCL.sgqsim
1787
+ #plxsv, plysv, plrotsv = DCL.sgqmpl()
1788
+ plxsv, plysv, plrotsv = DCL.umqcnt
1789
+ lglobesv = DCL::umpget('lglobe')
1790
+ grstxysv = %w(txmin txmax tymin tymax).map{|key| DCL::sgrget(key)}
1791
+ end
1792
+ # END OF BACKUP
1793
+
1794
+ vwidth = opt["vwidth"]
1795
+ vlength = opt["vlength"]
1796
+
1797
+ if portrait
1798
+ if !opt["left"]
1799
+ # left
1800
+ voff = opt["voff"] ||
1801
+ DCL.uzrget('roffyr') + DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
1802
+ vxmin = vx2 + voff
1803
+ vxmax = vx2 + voff + vwidth
1804
+ else
1805
+ # right
1806
+ voff = opt["voff"] ? -opt["voff"] : \
1807
+ DCL.uzrget('roffyl') - DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
1808
+ vxmax = vx1 + voff
1809
+ vxmin = vx1 + voff - vwidth
1810
+ end
1811
+ vymin =( opt["vcent"] ? opt["vcent"]-vlength/2 : vy1 )
1812
+ vymax =( opt["vcent"] ? opt["vcent"]+vlength/2 : vy1+vlength )
1813
+ else ## landscape ##
1814
+ vxmin =( opt["vcent"] ? opt["vcent"]-vlength/2 : (vx1+vx2)/2-vlength/2 )
1815
+ vxmax =( opt["vcent"] ? opt["vcent"]+vlength/2 : (vx1+vx2)/2+vlength/2 )
1816
+ if opt["top"]
1817
+ # top
1818
+ voff = opt["voff"] ||
1819
+ DCL.uzrget('roffxt') + DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
1820
+ vymin = vy2 + voff
1821
+ vymax = vy2 + voff + vwidth
1822
+ else
1823
+ # bottom
1824
+ voff = opt["voff"] ? -opt["voff"] : \
1825
+ DCL.uzrget('roffxb') - DCL.uzrget('pad1')*DCL::uzrget("rsizec2")
1826
+ vymax = vy1 + voff
1827
+ vymin = vy1 + voff - vwidth
1828
+ end
1829
+ end
1830
+
1831
+ min = levels[levels.ne(rmiss).where].min
1832
+ max = levels[levels.ne(rmiss).where].max
1833
+ if levels[0] == rmiss
1834
+ inf0 = true
1835
+ dummy1,dummy2,ipat0 = DCL::ueqtlv(1)
1836
+ return if levels.length==2
1837
+ else
1838
+ inf0 = false
1839
+ end
1840
+ if levels[-1] == rmiss
1841
+ inf1 = true
1842
+ dummy1,dummy2,ipat1 = DCL::ueqtlv(nton)
1843
+ return if levels.length==2
1844
+ else
1845
+ inf1 = false
1846
+ end
1847
+
1848
+ # < paint color tones >
1849
+
1850
+ lclip_bk = DCL::sglget("lclip")
1851
+ DCL::sglset("lclip", false)
1852
+
1853
+ inffact = opt["inffact"]
1854
+ if opt["constwidth"]
1855
+
1856
+ if inf0
1857
+ levels = levels[1..-1]
1858
+ patterns = patterns[1..-1]
1859
+ end
1860
+ if inf1
1861
+ levels = levels[0..-2]
1862
+ patterns = patterns[0..-2]
1863
+ end
1864
+ nlev = levels.length
1865
+ npat = patterns.length
1866
+
1867
+ if portrait
1868
+ vy = (NArray.sfloat(npat+1).indgen!)*(vymax-vymin)/npat + vymin
1869
+
1870
+ # paint color tones for infinity (with drawing frame)
1871
+ if inf0
1872
+ vy3 = [vymin, vymin-vwidth*inffact, vymin]
1873
+ vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
1874
+ DCL.sgtnzv(vx3,vy3,ipat0)
1875
+ DCL.sgplzv(vx3,vy3,1,index)
1876
+ end
1877
+ if inf1
1878
+ vy3 = [vymax, vymax+vwidth*inffact, vymax]
1879
+ vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
1880
+ DCL.sgtnzv(vx3,vy3,ipat1)
1881
+ DCL.sgplzv(vx3,vy3,1,index)
1882
+ end
1883
+
1884
+ # paint color tones for each range (with drawing long-side frame)
1885
+ for i in 0..npat-1
1886
+ DCL::sgtnzv([vxmin,vxmax,vxmax,vxmin],[vy[i],vy[i],vy[i+1],vy[i+1]],patterns[i])
1887
+ DCL::sgplzv([vxmin,vxmin],[vy[i],vy[i+1]],1,index)
1888
+ DCL::sgplzv([vxmax,vxmax],[vy[i],vy[i+1]],1,index)
1889
+ end
1890
+
1891
+ else ## landscape ##
1892
+ vx = (NArray.sfloat(npat+1).indgen!)*(vxmax-vxmin)/npat + vxmin
1893
+
1894
+ # paint color tones for infinity (with drawing frame)
1895
+ if inf0
1896
+ vx3 = [vxmin, vxmin-vwidth*inffact, vxmin]
1897
+ vy3 = [vymax, (vymax+vymin)/2, vymin]
1898
+ DCL.sgtnzv(vx3,vy3,ipat0)
1899
+ DCL.sgplzv(vx3,vy3,1,index)
1900
+ end
1901
+ if inf1
1902
+ vx3 = [vxmax, vxmax+vwidth*inffact, vxmax]
1903
+ vy3 = [vymax, (vymax+vymin)/2, vymin]
1904
+ DCL.sgtnzv(vx3,vy3,ipat1)
1905
+ DCL.sgplzv(vx3,vy3,1,index)
1906
+ end
1907
+
1908
+ # paint color tones for each range (with drawing long-side frame)
1909
+ for i in 0..npat-1
1910
+ DCL::sgtnzv([vx[i],vx[i],vx[i+1],vx[i+1]],[vymin,vymax,vymax,vymin],patterns[i])
1911
+ DCL::sgplzv([vx[i],vx[i+1]],[vymin,vymin],1,index)
1912
+ DCL::sgplzv([vx[i],vx[i+1]],[vymax,vymax],1,index)
1913
+ end
1914
+ end
1915
+
1916
+ else ### opt["constwidth"] == false ###
1917
+
1918
+ # paint color tones for infinity (with drawing frame)
1919
+ if portrait
1920
+ if inf0
1921
+ vy3 = [vymin, vymin-vwidth*inffact, vymin]
1922
+ vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
1923
+ DCL.sgtnzv(vx3,vy3,ipat0)
1924
+ DCL.sgplzv(vx3,vy3,1,index)
1925
+ end
1926
+ if inf1
1927
+ vy3 = [vymax, vymax+vwidth*inffact, vymax]
1928
+ vx3 = [vxmax, (vxmax+vxmin)/2, vxmin]
1929
+ DCL.sgtnzv(vx3,vy3,ipat1)
1930
+ DCL.sgplzv(vx3,vy3,1,index)
1931
+ end
1932
+ else ## landscape ##
1933
+ if inf0
1934
+ vx3 = [vxmin, vxmin-vwidth*inffact, vxmin]
1935
+ vy3 = [vymax, (vymax+vymin)/2, vymin]
1936
+ DCL.sgtnzv(vx3,vy3,ipat0)
1937
+ DCL.sgplzv(vx3,vy3,1,index)
1938
+ end
1939
+ if inf1
1940
+ vx3 = [vxmax, vxmax+vwidth*inffact, vxmax]
1941
+ vy3 = [vymax, (vymax+vymin)/2, vymin]
1942
+ DCL.sgtnzv(vx3,vy3,ipat1)
1943
+ DCL.sgplzv(vx3,vy3,1,index)
1944
+ end
1945
+ end
1946
+
1947
+ # paint color tones for each range
1948
+ nbar = 100
1949
+ bar = NArray.float(nbar,2)
1950
+ for i in 0..nbar-1
1951
+ bar[i,true] = min + (max-min).to_f/(nbar-1)*i
1952
+ end
1953
+
1954
+ xb = DCL::uzlget("labelxb")
1955
+ yl = DCL::uzlget("labelyl")
1956
+ if portrait
1957
+ xmin = 0.0
1958
+ xmax = 1.0
1959
+ ymin = min
1960
+ ymax = max
1961
+ DCL::uzlset("labelxb",false)
1962
+ DCL::uzlset("labelyl",true)
1963
+ bar = bar.transpose(-1,0)
1964
+ DCL::uwsgxa([0,1])
1965
+ DCL::uwsgya(bar[0,true])
1966
+ else
1967
+ xmin = min
1968
+ xmax = max
1969
+ ymin = 0.0
1970
+ ymax = 1.0
1971
+ DCL::uzlset("labelxb",true)
1972
+ DCL::uzlset("labelyl",false)
1973
+ DCL::uwsgxa(bar[true,0])
1974
+ DCL::uwsgya([0,1])
1975
+ end
1976
+
1977
+ type = 1
1978
+ if opt["log"]
1979
+ type +=1
1980
+ type +=1 if !portrait
1981
+ end
1982
+
1983
+ DCL::grfig
1984
+ DCL::grsvpt(vxmin,vxmax,vymin,vymax)
1985
+ DCL::grswnd(xmin,xmax,ymin,ymax)
1986
+ DCL::grstrn(type)
1987
+ DCL::grstrf
1988
+
1989
+ DCL::uetone(bar)
1990
+ DCL.uwsgxz(false)
1991
+ DCL.uwsgyz(false)
1992
+
1993
+ end
1994
+
1995
+ # < set ticking and labeling levels >
1996
+
1997
+ if opt["labelintv"]
1998
+ labelintv = opt["labelintv"]
1999
+ else
2000
+ ntn = nton
2001
+ ntn -= 1 if inf0
2002
+ ntn -= 1 if inf1
2003
+ if portrait
2004
+ labelintv = (ntn-1) / 9 + 1
2005
+ else
2006
+ labelintv = (ntn-1) / 5 + 1
2007
+ end
2008
+ end
2009
+ if labelintv <= 0
2010
+ no_label = true
2011
+ labelintv = 1
2012
+ else
2013
+ no_label = false
2014
+ end
2015
+
2016
+ tickintv = opt["tickintv"]
2017
+ if tickintv <= 0
2018
+ no_tick = true
2019
+ tickintv = labelintv
2020
+ else
2021
+ no_tick = false
2022
+ end
2023
+
2024
+ eps = 1e-5
2025
+ dummy = -9.9e-38
2026
+ dz = dzp = dzc = dummy
2027
+ idu = Array.new
2028
+ (1...levels.length).each do |i|
2029
+ dzc = (levels[i] - levels[i-1]).abs
2030
+ if (dzc-dzp).abs <= eps * [dzc.abs,dzp.abs].max
2031
+ dz = dzc # set dz if two consecutive inrements are the same
2032
+ idu.push( i-1 )
2033
+ end
2034
+ dzp = (levels[i] - levels[i-1]).abs
2035
+ end
2036
+ if idu.length > 0
2037
+ idumin = idu.min - 1
2038
+ idumax = idu.max + 1
2039
+ else
2040
+ idumin = 0
2041
+ idumax = levels.length-1
2042
+ end
2043
+ if dz != dummy
2044
+ # if idumin == 1 and levels[0] != rmiss
2045
+ # # to correct non-uniform intv at the beginning
2046
+ # levels[0] = levels[1] - dz
2047
+ # idumin = 0
2048
+ # min = levels[0]
2049
+ # end
2050
+ # if idumax == levels.length-2 and levels[-1] != rmiss
2051
+ # # to correct non-uniform intv at the end
2052
+ # levels[-1] = levels[-2] + dz
2053
+ # idumax = levels.length-1
2054
+ # max = levels[-1]
2055
+ # end
2056
+ # use the algorithm used in DCL.udgcla
2057
+ offs_tick = ( (-levels[idumin]/dz).round % tickintv + idumin ) % tickintv
2058
+ offs_label = ( (-levels[idumin]/dz).round % labelintv + idumin ) % labelintv
2059
+ else
2060
+ md = 0
2061
+ if ( (idx=levels.eq(0.0).where).length > 0 )
2062
+ md = idx[0] % labelintv
2063
+ else
2064
+ a = levels[0...([labelintv,levels.length].min)]
2065
+ b = a * 10**( -NMath.log10(a.abs).floor.min )
2066
+ (0...b.length).each{|i| md=i if (b[i].round-b[i]).abs < 1e-5 }
2067
+ end
2068
+ offs_tick = (md % tickintv)
2069
+ offs_label = md
2070
+ end
2071
+
2072
+ if levels.length >= 4
2073
+ lvmx = levels[1..-2].max
2074
+ lvmn = levels[1..-2].min
2075
+ dlv = (lvmx-lvmn) / (levels.length-3)
2076
+ elsif levels.length == 3 or levels.length == 2
2077
+ lvmn = lvmx = dlv = levels[1]
2078
+ else
2079
+ lvmn = lvmx = dlv = levels[0]
2080
+ end
2081
+
2082
+ # < draw units, title, labels, and tick lines>
2083
+
2084
+ if opt["constwidth"]
2085
+
2086
+ if !no_label && labels_ud
2087
+ ilbl = 0
2088
+ for i in 0..nlev-1
2089
+ if (i % labelintv) == offs_label
2090
+ ilbl += 1
2091
+ end
2092
+ end
2093
+ if labels_ud.size != ilbl
2094
+ raise ArgumentError, "'labels_ud' must be an Array of length==#{ilbl} in this case"
2095
+ end
2096
+ end
2097
+
2098
+ if portrait
2099
+
2100
+ if voff > 0
2101
+ cent = -1
2102
+ vxlabel = vxmax+DCL::uzrget('pad1')*DCL::uzrget('rsizel1')
2103
+ # title
2104
+ 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']
2105
+ # units
2106
+ 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']
2107
+ else
2108
+ cent = 1
2109
+ vxlabel = vxmin-DCL::uzrget('pad1')*DCL::uzrget('rsizel1')
2110
+ # title
2111
+ 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']
2112
+ # units
2113
+ 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']
2114
+ end
2115
+
2116
+ ilbl_ud = 0
2117
+ for i in 0..nlev-1
2118
+ # labels
2119
+ if !no_label && (i % labelintv) == offs_label
2120
+ if labels_ud
2121
+ char = labels_ud[ilbl_ud]
2122
+ DCL::sgtxzr(vxlabel,vy[i],char,DCL::uzrget('rsizel1'),0,cent,charindex)
2123
+ ilbl_ud += 1
2124
+ else
2125
+ begin
2126
+ if(opt['chval_fmt'])
2127
+ char = DCL::chval(opt['chval_fmt'],levels[i])
2128
+ else
2129
+ char = sprintf_level(levels[i],lvmx,lvmn,dlv)
2130
+ end
2131
+ DCL::sgtxzr(vxlabel,vy[i],char,DCL::uzrget('rsizel1'),0,cent,charindex)
2132
+ rescue
2133
+ DCL::sgtxzr(vxlabel,vy[i],levels[i].to_s,DCL::uzrget('rsizel1'),0,cent,charindex)
2134
+ end
2135
+ end
2136
+ end
2137
+ # tick lines and short-side frame
2138
+ if (!no_tick && (i % tickintv) == offs_tick) || (!inf0 && i == 0) || (!inf1 && i == nlev-1)
2139
+ DCL::sgplzv([vxmin,vxmax],[vy[i],vy[i]],1,index)
2140
+ end
2141
+ end
2142
+
2143
+ else ## landscape ##
2144
+ if voff > 0
2145
+ vylabel = vymax+(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1')
2146
+ # title
2147
+ 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']
2148
+ # units
2149
+ 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']
2150
+ else
2151
+ vylabel = vymin-(0.5+DCL::uzrget('pad1'))*DCL::uzrget('rsizel1')
2152
+ # title
2153
+ 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']
2154
+ # units
2155
+ 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']
2156
+ end
2157
+
2158
+ ilbl_ud = 0
2159
+ for i in 0..nlev-1
2160
+ # labels
2161
+ if !no_label && (i % labelintv) == offs_label
2162
+ if labels_ud
2163
+ char = labels_ud[ilbl_ud]
2164
+ DCL::sgtxzr(vx[i],vylabel,char,DCL::uzrget('rsizel1'),0,0,charindex)
2165
+ ilbl_ud += 1
2166
+ else
2167
+ begin
2168
+ if(opt['chval_fmt'])
2169
+ char = DCL::chval(opt['chval_fmt'],levels[i])
2170
+ else
2171
+ char = sprintf_level(levels[i],lvmx,lvmn,dlv)
2172
+ end
2173
+ DCL::sgtxzr(vx[i],vylabel,char,DCL::uzrget('rsizel1'),0,0,charindex)
2174
+ rescue
2175
+ DCL::sgtxzr(vx[i],vylabel,levels[i].to_s,DCL::uzrget('rsizel1'),0,0,charindex)
2176
+ end
2177
+ end
2178
+ end
2179
+ # tick lines and short-side frame
2180
+ if (!no_tick && (i % tickintv) == offs_tick) || (!inf0 && i == 0) || (!inf1 && i == nlev-1)
2181
+ DCL::sgplzv([vx[i],vx[i]],[vymin,vymax],1,index)
2182
+ end
2183
+ end
2184
+ end
2185
+
2186
+ else ### opt["constwidth"] == false ###
2187
+
2188
+ inner_bk = DCL::uziget('inner')
2189
+ uz_set_params('inner'=>1)
2190
+
2191
+ tick1 = Array.new
2192
+ tick2 = Array.new
2193
+ for i in 0..levels.length-1
2194
+ # if i>=idumin && i<=idumax && levels[i]!=rmiss
2195
+ if levels[i]!=rmiss
2196
+ tick1.push(levels[i]) if (i % tickintv) == offs_tick
2197
+ tick2.push(levels[i]) if (i % labelintv) == offs_label
2198
+ end
2199
+ end
2200
+
2201
+ if portrait
2202
+
2203
+ if voff > 0
2204
+ before = uz_set_params('labelyl'=>false,'labelyr'=>true,'icentyr'=>-1.0)
2205
+ else
2206
+ before = uz_set_params('labelyl'=>true,'labelyr'=>false,'icentyl'=>1.0)
2207
+ end
2208
+
2209
+ # draw frame, tick lines, and labels
2210
+ cfmt_bk = DCL::uyqfmt
2211
+ if opt["log"]
2212
+ fmt = opt['chval_fmt'] || "b"
2213
+ else
2214
+ fmt = opt['chval_fmt'] || level_chval_fmt(lvmx,lvmn,dlv)
2215
+ end
2216
+ DCL::uysfmt(fmt)
2217
+
2218
+ rsizet1_bk = DCL::uzrget("rsizet1")
2219
+ rsizet2_bk = DCL::uzrget("rsizet2")
2220
+ uz_set_params('rsizet1'=>vwidth,'rsizet2'=>0.0)
2221
+ if no_label
2222
+ nl_labelxt = DCL::uzlget('labelxt')
2223
+ nl_labelxb = DCL::uzlget('labelxb')
2224
+ nl_labelyl = DCL::uzlget('labelyl')
2225
+ nl_labelyr = DCL::uzlget('labelyr')
2226
+ uz_set_params('labelxt'=>false,'labelxb'=>false,'labelyl'=>false,'labelyr'=>false)
2227
+ end
2228
+ if no_tick
2229
+ nt_rsizet1 = DCL::uzrget('rsizet1')
2230
+ DCL::uzrset("rsizet1",0.0)
2231
+ end
2232
+
2233
+ if labels_ud
2234
+ if labels_ud.size != tick2.size
2235
+ raise ArgumentError, "'labels_ud' must be an Array of length==#{tick2.size} in this case"
2236
+ end
2237
+ nc = labels_ud.collect{|c| c.size}.max
2238
+ DCL::uyaxlb("l",tick1,tick2,labels_ud,nc)
2239
+ DCL::uyaxlb("r",tick1,tick2,labels_ud,nc)
2240
+ else
2241
+ DCL::uyaxnm("l",tick1,tick2)
2242
+ DCL::uyaxnm("r",tick1,tick2)
2243
+ end
2244
+ DCL::uxaxdv("b",1,index) if !inf0
2245
+ DCL::uxaxdv("t",1,index) if !inf1
2246
+
2247
+ if no_tick
2248
+ DCL::uzrset("rsizet1",nt_rsizet1)
2249
+ end
2250
+ if no_label
2251
+ uz_set_params('labelxt'=>nl_labelxt,'labelxb'=>nl_labelxb,'labelyl'=>nl_labelyl,'labelyr'=>nl_labelyr)
2252
+ end
2253
+ DCL::uzrset("rsizet1",rsizet1_bk)
2254
+ DCL::uzrset("rsizet2",rsizet2_bk)
2255
+
2256
+ DCL::uysfmt(cfmt_bk)
2257
+
2258
+ if voff > 0
2259
+ # title
2260
+ 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"]
2261
+ # units
2262
+ 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']
2263
+ else
2264
+ # title
2265
+ 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"]
2266
+ # units
2267
+ 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']
2268
+ end
2269
+
2270
+ uz_set_params(before)
2271
+
2272
+ else ## landscape ##
2273
+
2274
+ if voff > 0
2275
+ before = uz_set_params('labelxt'=>true,'labelxb'=>false)
2276
+ else
2277
+ before = uz_set_params('labelxt'=>false,'labelxb'=>true)
2278
+ end
2279
+
2280
+ # draw frame, tick lines, and labels
2281
+ cfmt_bk = DCL::uxqfmt
2282
+ if opt["log"]
2283
+ fmt = opt['chval_fmt'] || "b"
2284
+ else
2285
+ fmt = opt['chval_fmt'] || level_chval_fmt(lvmx,lvmn,dlv)
2286
+ end
2287
+ DCL::uxsfmt(fmt)
2288
+
2289
+ rsizet1_bk = DCL::uzrget("rsizet1")
2290
+ rsizet2_bk = DCL::uzrget("rsizet2")
2291
+ uz_set_params('rsizet1'=>vwidth,'rsizet2'=>0.0)
2292
+ if no_label
2293
+ nl_labelxt = DCL::uzlget('labelxt')
2294
+ nl_labelxb = DCL::uzlget('labelxb')
2295
+ nl_labelyl = DCL::uzlget('labelyl')
2296
+ nl_labelyr = DCL::uzlget('labelyr')
2297
+ uz_set_params('labelxt'=>false,'labelxb'=>false,'labelyl'=>false,'labelyr'=>false)
2298
+ end
2299
+ if no_tick
2300
+ nt_rsizet1 = DCL::uzrget('rsizet1')
2301
+ DCL::uzrset("rsizet1",0.0)
2302
+ end
2303
+
2304
+ if labels_ud
2305
+ if labels_ud.size != tick2.size
2306
+ raise ArgumentError, "'labels_ud' must be an Array of length==#{tick2.size} in this case"
2307
+ end
2308
+ nc = labels_ud.collect{|c| c.size}.max
2309
+ DCL::uxaxlb("t",tick1,tick2,labels_ud,nc)
2310
+ DCL::uxaxlb("b",tick1,tick2,labels_ud,nc)
2311
+ else
2312
+ DCL::uxaxnm("t",tick1,tick2)
2313
+ DCL::uxaxnm("b",tick1,tick2)
2314
+ end
2315
+ DCL::uyaxdv("l",1,index) if !inf0
2316
+ DCL::uyaxdv("r",1,index) if !inf1
2317
+
2318
+ if no_tick
2319
+ DCL::uzrset("rsizet1",nt_rsizet1)
2320
+ end
2321
+ if no_label
2322
+ uz_set_params('labelxt'=>nl_labelxt,'labelxb'=>nl_labelxb,'labelyl'=>nl_labelyl,'labelyr'=>nl_labelyr)
2323
+ end
2324
+ DCL::uzrset("rsizet1",rsizet1_bk)
2325
+ DCL::uzrset("rsizet2",rsizet2_bk)
2326
+
2327
+ DCL::uxsfmt(cfmt_bk)
2328
+
2329
+ if voff > 0
2330
+ # title
2331
+ 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"]
2332
+ # units
2333
+ 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']
2334
+ else
2335
+ # title
2336
+ 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"]
2337
+ # units
2338
+ 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']
2339
+ end
2340
+
2341
+ uz_set_params(before)
2342
+
2343
+ end
2344
+
2345
+ DCL::uzlset("labelxb",xb)
2346
+ DCL::uzlset("labelyl",yl)
2347
+
2348
+ DCL::grsvpt(vx1,vx2,vy1,vy2)
2349
+ if itrsv <= 4
2350
+ DCL::grswnd(ux1sv, ux2sv, uy1sv, uy2sv)
2351
+ DCL::grstrn(itrsv)
2352
+ elsif itrsv <= 9
2353
+ DCL::sgssim(simfacsv,vxoffsv,vyoffsv)
2354
+ DCL::grstrn(itrsv)
2355
+ ### TENTATIVE WORKAROUND (2012/2/9)
2356
+ elsif itrsv <= 34
2357
+ DCL::grswnd(ux1sv, ux2sv, uy1sv, uy2sv)
2358
+ DCL.sgstrn(itrsv)
2359
+ DCL.umpset('lglobe', lglobesv)
2360
+ DCL::grstxy(*grstxysv)
2361
+ DCL.umscnt(plxsv,plysv,plrotsv)
2362
+ DCL.umpfit
2363
+ ###
2364
+ DCL.sgssim(simfacsv,vxoffsv,vyoffsv)
2365
+ #DCL.sgsmpl(plxsv,plysv,plrotsv)
2366
+ end
2367
+ DCL::grstrf
2368
+
2369
+ uz_set_params('inner'=>inner_bk)
2370
+ end
2371
+
2372
+ DCL::uziset("indext1",indext1_bk)
2373
+ DCL::uziset("indext2",indext2_bk)
2374
+ DCL::uziset("indexl1",indexl1_bk)
2375
+ DCL::uzrset("rsizel1",rsizel1_bk)
2376
+
2377
+ DCL::sglset("lclip", lclip_bk)
2378
+ nil
2379
+ end
2380
+
2381
+ # Annotates line/mark type and index (and size if mark).
2382
+ # By default it is shown in the right margin of the viewport.
2383
+ #
2384
+ # * str is a String to show
2385
+ # * line: true->line ; false->mark
2386
+ # * vx: vx of the left-hand point of legend line (or mark position).
2387
+ # * nil : internally determined
2388
+ # * Float && > 0 : set explicitly
2389
+ # * Float && < 0 : move it relatively to the left from the default
2390
+ # * dx: length of the legend line (not used if mark).
2391
+ # * nil : internally determined
2392
+ # * Float && > 0 : set explicitly
2393
+ # * vy: vy of the legend (not used if !first -- see below).
2394
+ # * nil : internally determined
2395
+ # * Float && > 0 : set explicitly
2396
+ # * Float && < 0 : move it relatively lower from the default
2397
+ # * first : if false, vy is moved lower relatively from the previous vy.
2398
+ # * mark_size : size of the mark. if nil, size is used.
2399
+ def legend(str, type, index, line=false, size=nil,
2400
+ vx=nil, dx=nil, vy=nil, first=true, mark_size=nil)
2401
+
2402
+ size = DCL::uzrget("rsizel1")*0.95 if !size
2403
+ mark_size = size if !mark_size
2404
+
2405
+ vpx1,vpx2,vpy1,vpy2 = DCL.sgqvpt
2406
+ if first
2407
+ if !vy
2408
+ vy = vpy2 - 0.04
2409
+ elsif vy < 0
2410
+ vy = ( vpy2 - 0.04 ) + vy
2411
+ end
2412
+ @vy = vy
2413
+ else
2414
+ vy = @vy - 1.5*size
2415
+ end
2416
+
2417
+ if !vx
2418
+ vx = vpx2 + 0.015
2419
+ elsif vx < 0
2420
+ vx = (vpx2 + 0.015) + vx
2421
+ end
2422
+
2423
+ if line
2424
+ dx=0.06 if !dx
2425
+ vx2 = vx + dx
2426
+ DCL::sgplzv([vx,vx2],[vy,vy],type,index)
2427
+ DCL.sgtxzv(vx2+0.01,vy,str,size,0,-1,3)
2428
+ else # --> mark
2429
+ DCL::sgpmzv([vx],[vy],type,index,mark_size)
2430
+ DCL.sgtxzv(vx+0.015+mark_size*0.5,vy,str,size,0,-1,3)
2431
+ end
2432
+ nil
2433
+ end
2434
+
2435
+ # Driver of quasi_log_levels with data values
2436
+ def quasi_log_levels_z(vals, nlev=nil, max=nil, min=nil, cycle=1)
2437
+ if max && min
2438
+ quasi_log_levels(max.to_f, min.to_f, cycle)
2439
+ else
2440
+ if nlev
2441
+ eps = 0.1
2442
+ norder = (nlev-1.0+eps)/cycle
2443
+ else
2444
+ norder = 3
2445
+ end
2446
+ mx1 = vals.max
2447
+ mx2 = vals.min
2448
+ if min && min < 0
2449
+ max = min
2450
+ min = nil
2451
+ elsif max && max < 0
2452
+ min = max
2453
+ max = nil
2454
+ end
2455
+ maxsv = max
2456
+ minsv = min
2457
+ if !max
2458
+ max = [ mx1.abs, mx2.abs ].max.to_f
2459
+ max = -max if mx1<0
2460
+ end
2461
+ if !min
2462
+ min = max/10**norder
2463
+ else
2464
+ max = min*10**norder if nlev
2465
+ end
2466
+ if !(minsv && minsv>0) && !(maxsv && maxsv <0) && ( mx2<0 && mx1>0 )
2467
+ min = -min
2468
+ end
2469
+ quasi_log_levels(max, min, cycle)
2470
+ end
2471
+ end
2472
+
2473
+ # Returns approximately log-scaled contour/tone levels as well as
2474
+ # major/minor flags for contours. No DCL call is made in here.
2475
+ #
2476
+ # * cycle (Integer; 1, or 2 or 3) : number of level in one-order.
2477
+ # e.g. 1,10,100,.. for cycle==1; 1,3,10,30,.. for cycle==2;
2478
+ # 1,2,5,10,20,50,.. for cycle==3
2479
+ # * lev0, lev1 (Float) : levels are set between this two params
2480
+ # * if lev0 & lev1 > 0 : positive only
2481
+ # * if lev0 & lev1 < 0 : negative only
2482
+ # * if lev0 * lev1 < 0 : both positive and negative
2483
+ # (usig +-[lev0.abs,lev1.abs])
2484
+ # RETURN VALUE:
2485
+ # * [ levels, mjmn ]
2486
+ def quasi_log_levels(lev0, lev1, cycle=1)
2487
+ raise(ArgumentError, "lev0 is zero (non-zero required)") if lev0 == 0.0
2488
+ raise(ArgumentError, "lev1 is zero (non-zero required)") if lev1 == 0.0
2489
+ case cycle
2490
+ when 1
2491
+ cycl_levs = [1.0]
2492
+ when 2
2493
+ cycl_levs = [1.0, 3.0]
2494
+ when 3
2495
+ cycl_levs = [1.0, 2.0, 5.0]
2496
+ else
2497
+ raise(ArgumentError, "cycle must be 1,2,or 3, which is now #{cycle}")
2498
+ end
2499
+
2500
+ if lev0 > 0 and lev1 > 0
2501
+ positive = true
2502
+ negative = false
2503
+ elsif lev0 < 0 and lev1 < 0
2504
+ positive = false
2505
+ negative = true
2506
+ else
2507
+ positive = true
2508
+ negative = true
2509
+ end
2510
+ sml, big = [lev0.abs,lev1.abs].sort
2511
+
2512
+ expsml = Math::log10(sml).floor
2513
+ expbig = Math::log10(big).ceil
2514
+
2515
+ levels = Array.new
2516
+ mjmn = Array.new
2517
+
2518
+ for i in expsml..expbig-1
2519
+ for k in 0..cycle-1
2520
+ lev = cycl_levs[k] * 10**i
2521
+ if lev >= sml && lev <= big
2522
+ levels.push( lev )
2523
+ mjmn.push( k==0 ? 1 : 0 )
2524
+ end
2525
+ end
2526
+ end
2527
+ lev = 10**expbig
2528
+ if lev == big
2529
+ levels.push( lev )
2530
+ mjmn.push( 1 )
2531
+ end
2532
+
2533
+ if negative && !positive
2534
+ levels = levels.reverse.collect{|x| -x}
2535
+ mjmn = mjmn.reverse
2536
+ elsif negative && positive
2537
+ levels.dup.each{|x| levels.unshift(-x)}
2538
+ mjmn.dup.each{|x| mjmn.unshift(x)}
2539
+ end
2540
+
2541
+ [ levels, mjmn ]
2542
+ end
2543
+ end
2544
+
2545
+ end
2546
+
2547
+ if $0 == __FILE__
2548
+ include NumRu
2549
+
2550
+ require "numru/derivative"
2551
+ include Misc::EMath
2552
+ nx = 33
2553
+ ny = 17
2554
+ x = NArray.sfloat(nx).indgen! * (2*PI/(nx-1))
2555
+ #y = ( NArray.sfloat(ny).indgen! - (ny-1)/2.0 ) *(PI/ny)
2556
+ y = ( NArray.sfloat(ny).indgen! - (ny-1)/2.0 ) *(PI/(ny-1))
2557
+ #p x,y
2558
+ xdeg = x*(180/PI)
2559
+ ydeg = y*(180/PI)
2560
+ #xdegc = xdeg[[0..-1,0]]
2561
+ #xdegc[-1] += 360
2562
+ xx = x.newdim(1)
2563
+ yy = y.newdim(0)
2564
+ z = (cos(4*yy)-1)*sin(2*xx) - 2*cos(2*yy)
2565
+ u = - Derivative.cderiv(z,y,1,Derivative::CYCLIC_EXT)
2566
+ v = Derivative.cderiv(z,x,0,Derivative::CYCLIC_EXT) / cos(yy)
2567
+ u = NArrayMiss.to_nam(u)
2568
+ #DCL.ugpset('lmissp',true)
2569
+ u.invalidation(2..6,-5..-2)
2570
+ v[7..10,-5] = 999.0
2571
+
2572
+ DCL.gropn(1)
2573
+ DCL.glpset('lmiss',true)
2574
+
2575
+ DCL.sgpset('lclip',true)
2576
+
2577
+ for itr in [10,12]
2578
+ DCL.grfrm
2579
+ DCL.grstrn(itr)
2580
+ DCL.grsvpt(0.1,0.9,0.25,0.75)
2581
+ DCL.umscnt(180, 0, 0)
2582
+ DCL.grswnd(xdeg[0],xdeg[-1],ydeg[0],ydeg[-1])
2583
+ DCL.grstxy(-180, 180, -90, 90 )
2584
+ DCL.umpset('lglobe', true)
2585
+ DCL.umpfit
2586
+ DCL.grstrf
2587
+ DCL.udcntz(z)
2588
+ vfratio, flenmax = DCLExt.flow_vect_anyproj(u, v, xdeg, ydeg)
2589
+ DCLExt.unit_vect_single(vfratio, flenmax)
2590
+ DCL.umplim
2591
+ end
2592
+
2593
+ itr = 30
2594
+ DCL.grfrm
2595
+ DCL.grstrn(itr)
2596
+ DCL.grsvpt(0.1,0.9,0.1,0.9)
2597
+ DCL.umscnt(180, 90, 0)
2598
+ DCL.grswnd(xdeg[0],xdeg[-1],ydeg[0],ydeg[-1])
2599
+ DCL.grssim(0.3,0,0)
2600
+ DCL.grstxy(-180, 180, 10, 90 )
2601
+ DCL.umpset('lglobe', true)
2602
+ DCL.umpfit
2603
+ DCL.grstrf
2604
+ DCL.udcntz(z)
2605
+ vfratio, flenmax =
2606
+ DCLExt.flow_vect_anyproj(u[true,ny/2+1..-1], v[true,ny/2+1..-1],
2607
+ xdeg, ydeg[ny/2+1..-1])
2608
+ DCLExt.unit_vect_single(vfratio, flenmax)
2609
+ DCL.umplim
2610
+
2611
+ itr = 30
2612
+ DCL.grfrm
2613
+ DCL.grstrn(itr)
2614
+ DCL.grsvpt(0.1,0.9,0.1,0.9)
2615
+ DCL.umscnt(180, 30, 0)
2616
+ DCL.grswnd(xdeg[0],xdeg[-1],ydeg[0],ydeg[-1])
2617
+ DCL.grssim(0.3,0,0)
2618
+ DCL.grstxy(-180, 180, 0, 90 )
2619
+ DCL.umpset('lglobe', true)
2620
+ DCL.umpfit
2621
+ DCL.grstrf
2622
+ #DCL.udcntz(z[true,ny/2+1..-1])
2623
+ DCL.uepset("ltone",true)
2624
+ DCL.udcntz(z[true,ny/2+1..-1])
2625
+ vfratio, flenmax =
2626
+ DCLExt.flow_vect_anyproj(u, v,
2627
+ xdeg, ydeg,
2628
+ 1.0,1,1,true,nil,0.3)
2629
+ #DCLExt.flow_vect_anyproj(u[true,ny/2..-1], v[true,ny/2..-1],
2630
+ # xdeg, ydeg[ny/2..-1])
2631
+ DCLExt.unit_vect_single(vfratio, flenmax)
2632
+ DCL.umplim
2633
+
2634
+ DCL.grcls
2635
+
2636
+ end