gphys 1.1.1a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (428) hide show
  1. data/ChangeLog +1777 -0
  2. data/LICENSE.txt +34 -0
  3. data/README +33 -0
  4. data/Rakefile +57 -0
  5. data/TODO_ep_flux +6 -0
  6. data/bin/gdir_client +27 -0
  7. data/bin/gdir_server +129 -0
  8. data/bin/gpaop +146 -0
  9. data/bin/gpcat +148 -0
  10. data/bin/gpcut +102 -0
  11. data/bin/gpedit +228 -0
  12. data/bin/gplist +68 -0
  13. data/bin/gpmath +120 -0
  14. data/bin/gpmaxmin +128 -0
  15. data/bin/gpprint +60 -0
  16. data/bin/gpvect +706 -0
  17. data/bin/gpview +704 -0
  18. data/bin/grads2nc_with_gphys +61 -0
  19. data/doc/attribute.html +19 -0
  20. data/doc/attributenetcdf.html +15 -0
  21. data/doc/axis.html +376 -0
  22. data/doc/coordmapping.html +111 -0
  23. data/doc/coordtransform.html +36 -0
  24. data/doc/derivative/gphys-derivative.html +80 -0
  25. data/doc/derivative/index.html +21 -0
  26. data/doc/derivative/index.rd +14 -0
  27. data/doc/derivative/math-doc/document/document.css +30 -0
  28. data/doc/derivative/math-doc/document/document.html +57 -0
  29. data/doc/derivative/math-doc/document/images.aux +1 -0
  30. data/doc/derivative/math-doc/document/images.log +385 -0
  31. data/doc/derivative/math-doc/document/images.pl +186 -0
  32. data/doc/derivative/math-doc/document/images.tex +364 -0
  33. data/doc/derivative/math-doc/document/img1.png +0 -0
  34. data/doc/derivative/math-doc/document/img10.png +0 -0
  35. data/doc/derivative/math-doc/document/img11.png +0 -0
  36. data/doc/derivative/math-doc/document/img12.png +0 -0
  37. data/doc/derivative/math-doc/document/img13.png +0 -0
  38. data/doc/derivative/math-doc/document/img14.png +0 -0
  39. data/doc/derivative/math-doc/document/img15.png +0 -0
  40. data/doc/derivative/math-doc/document/img16.png +0 -0
  41. data/doc/derivative/math-doc/document/img17.png +0 -0
  42. data/doc/derivative/math-doc/document/img18.png +0 -0
  43. data/doc/derivative/math-doc/document/img19.png +0 -0
  44. data/doc/derivative/math-doc/document/img2.png +0 -0
  45. data/doc/derivative/math-doc/document/img20.png +0 -0
  46. data/doc/derivative/math-doc/document/img21.png +0 -0
  47. data/doc/derivative/math-doc/document/img22.png +0 -0
  48. data/doc/derivative/math-doc/document/img23.png +0 -0
  49. data/doc/derivative/math-doc/document/img24.png +0 -0
  50. data/doc/derivative/math-doc/document/img25.png +0 -0
  51. data/doc/derivative/math-doc/document/img26.png +0 -0
  52. data/doc/derivative/math-doc/document/img27.png +0 -0
  53. data/doc/derivative/math-doc/document/img28.png +0 -0
  54. data/doc/derivative/math-doc/document/img29.png +0 -0
  55. data/doc/derivative/math-doc/document/img3.png +0 -0
  56. data/doc/derivative/math-doc/document/img30.png +0 -0
  57. data/doc/derivative/math-doc/document/img4.png +0 -0
  58. data/doc/derivative/math-doc/document/img5.png +0 -0
  59. data/doc/derivative/math-doc/document/img6.png +0 -0
  60. data/doc/derivative/math-doc/document/img7.png +0 -0
  61. data/doc/derivative/math-doc/document/img8.png +0 -0
  62. data/doc/derivative/math-doc/document/img9.png +0 -0
  63. data/doc/derivative/math-doc/document/index.html +57 -0
  64. data/doc/derivative/math-doc/document/labels.pl +13 -0
  65. data/doc/derivative/math-doc/document/next.png +0 -0
  66. data/doc/derivative/math-doc/document/next_g.png +0 -0
  67. data/doc/derivative/math-doc/document/node1.html +238 -0
  68. data/doc/derivative/math-doc/document/node2.html +75 -0
  69. data/doc/derivative/math-doc/document/prev.png +0 -0
  70. data/doc/derivative/math-doc/document/prev_g.png +0 -0
  71. data/doc/derivative/math-doc/document/up.png +0 -0
  72. data/doc/derivative/math-doc/document/up_g.png +0 -0
  73. data/doc/derivative/math-doc/document.pdf +0 -0
  74. data/doc/derivative/math-doc/document.tex +158 -0
  75. data/doc/derivative/numru-derivative.html +129 -0
  76. data/doc/ep_flux/ep_flux.html +469 -0
  77. data/doc/ep_flux/ggraph_on_merdional_section.html +71 -0
  78. data/doc/ep_flux/index.html +31 -0
  79. data/doc/ep_flux/index.rd +24 -0
  80. data/doc/ep_flux/math-doc/document/WARNINGS +1 -0
  81. data/doc/ep_flux/math-doc/document/contents.png +0 -0
  82. data/doc/ep_flux/math-doc/document/crossref.png +0 -0
  83. data/doc/ep_flux/math-doc/document/document.css +30 -0
  84. data/doc/ep_flux/math-doc/document/document.html +101 -0
  85. data/doc/ep_flux/math-doc/document/images.aux +1 -0
  86. data/doc/ep_flux/math-doc/document/images.log +1375 -0
  87. data/doc/ep_flux/math-doc/document/images.pl +1328 -0
  88. data/doc/ep_flux/math-doc/document/images.tex +1471 -0
  89. data/doc/ep_flux/math-doc/document/img1.png +0 -0
  90. data/doc/ep_flux/math-doc/document/img10.png +0 -0
  91. data/doc/ep_flux/math-doc/document/img100.png +0 -0
  92. data/doc/ep_flux/math-doc/document/img101.png +0 -0
  93. data/doc/ep_flux/math-doc/document/img102.png +0 -0
  94. data/doc/ep_flux/math-doc/document/img103.png +0 -0
  95. data/doc/ep_flux/math-doc/document/img104.png +0 -0
  96. data/doc/ep_flux/math-doc/document/img105.png +0 -0
  97. data/doc/ep_flux/math-doc/document/img106.png +0 -0
  98. data/doc/ep_flux/math-doc/document/img107.png +0 -0
  99. data/doc/ep_flux/math-doc/document/img108.png +0 -0
  100. data/doc/ep_flux/math-doc/document/img109.png +0 -0
  101. data/doc/ep_flux/math-doc/document/img11.png +0 -0
  102. data/doc/ep_flux/math-doc/document/img110.png +0 -0
  103. data/doc/ep_flux/math-doc/document/img111.png +0 -0
  104. data/doc/ep_flux/math-doc/document/img112.png +0 -0
  105. data/doc/ep_flux/math-doc/document/img113.png +0 -0
  106. data/doc/ep_flux/math-doc/document/img114.png +0 -0
  107. data/doc/ep_flux/math-doc/document/img115.png +0 -0
  108. data/doc/ep_flux/math-doc/document/img116.png +0 -0
  109. data/doc/ep_flux/math-doc/document/img117.png +0 -0
  110. data/doc/ep_flux/math-doc/document/img118.png +0 -0
  111. data/doc/ep_flux/math-doc/document/img119.png +0 -0
  112. data/doc/ep_flux/math-doc/document/img12.png +0 -0
  113. data/doc/ep_flux/math-doc/document/img120.png +0 -0
  114. data/doc/ep_flux/math-doc/document/img121.png +0 -0
  115. data/doc/ep_flux/math-doc/document/img122.png +0 -0
  116. data/doc/ep_flux/math-doc/document/img123.png +0 -0
  117. data/doc/ep_flux/math-doc/document/img124.png +0 -0
  118. data/doc/ep_flux/math-doc/document/img125.png +0 -0
  119. data/doc/ep_flux/math-doc/document/img126.png +0 -0
  120. data/doc/ep_flux/math-doc/document/img127.png +0 -0
  121. data/doc/ep_flux/math-doc/document/img128.png +0 -0
  122. data/doc/ep_flux/math-doc/document/img129.png +0 -0
  123. data/doc/ep_flux/math-doc/document/img13.png +0 -0
  124. data/doc/ep_flux/math-doc/document/img130.png +0 -0
  125. data/doc/ep_flux/math-doc/document/img131.png +0 -0
  126. data/doc/ep_flux/math-doc/document/img132.png +0 -0
  127. data/doc/ep_flux/math-doc/document/img133.png +0 -0
  128. data/doc/ep_flux/math-doc/document/img134.png +0 -0
  129. data/doc/ep_flux/math-doc/document/img135.png +0 -0
  130. data/doc/ep_flux/math-doc/document/img136.png +0 -0
  131. data/doc/ep_flux/math-doc/document/img137.png +0 -0
  132. data/doc/ep_flux/math-doc/document/img138.png +0 -0
  133. data/doc/ep_flux/math-doc/document/img139.png +0 -0
  134. data/doc/ep_flux/math-doc/document/img14.png +0 -0
  135. data/doc/ep_flux/math-doc/document/img140.png +0 -0
  136. data/doc/ep_flux/math-doc/document/img141.png +0 -0
  137. data/doc/ep_flux/math-doc/document/img142.png +0 -0
  138. data/doc/ep_flux/math-doc/document/img143.png +0 -0
  139. data/doc/ep_flux/math-doc/document/img144.png +0 -0
  140. data/doc/ep_flux/math-doc/document/img145.png +0 -0
  141. data/doc/ep_flux/math-doc/document/img146.png +0 -0
  142. data/doc/ep_flux/math-doc/document/img147.png +0 -0
  143. data/doc/ep_flux/math-doc/document/img148.png +0 -0
  144. data/doc/ep_flux/math-doc/document/img149.png +0 -0
  145. data/doc/ep_flux/math-doc/document/img15.png +0 -0
  146. data/doc/ep_flux/math-doc/document/img150.png +0 -0
  147. data/doc/ep_flux/math-doc/document/img151.png +0 -0
  148. data/doc/ep_flux/math-doc/document/img152.png +0 -0
  149. data/doc/ep_flux/math-doc/document/img153.png +0 -0
  150. data/doc/ep_flux/math-doc/document/img154.png +0 -0
  151. data/doc/ep_flux/math-doc/document/img155.png +0 -0
  152. data/doc/ep_flux/math-doc/document/img156.png +0 -0
  153. data/doc/ep_flux/math-doc/document/img157.png +0 -0
  154. data/doc/ep_flux/math-doc/document/img158.png +0 -0
  155. data/doc/ep_flux/math-doc/document/img159.png +0 -0
  156. data/doc/ep_flux/math-doc/document/img16.png +0 -0
  157. data/doc/ep_flux/math-doc/document/img160.png +0 -0
  158. data/doc/ep_flux/math-doc/document/img161.png +0 -0
  159. data/doc/ep_flux/math-doc/document/img162.png +0 -0
  160. data/doc/ep_flux/math-doc/document/img163.png +0 -0
  161. data/doc/ep_flux/math-doc/document/img164.png +0 -0
  162. data/doc/ep_flux/math-doc/document/img165.png +0 -0
  163. data/doc/ep_flux/math-doc/document/img166.png +0 -0
  164. data/doc/ep_flux/math-doc/document/img167.png +0 -0
  165. data/doc/ep_flux/math-doc/document/img168.png +0 -0
  166. data/doc/ep_flux/math-doc/document/img169.png +0 -0
  167. data/doc/ep_flux/math-doc/document/img17.png +0 -0
  168. data/doc/ep_flux/math-doc/document/img170.png +0 -0
  169. data/doc/ep_flux/math-doc/document/img171.png +0 -0
  170. data/doc/ep_flux/math-doc/document/img172.png +0 -0
  171. data/doc/ep_flux/math-doc/document/img173.png +0 -0
  172. data/doc/ep_flux/math-doc/document/img174.png +0 -0
  173. data/doc/ep_flux/math-doc/document/img175.png +0 -0
  174. data/doc/ep_flux/math-doc/document/img176.png +0 -0
  175. data/doc/ep_flux/math-doc/document/img177.png +0 -0
  176. data/doc/ep_flux/math-doc/document/img178.png +0 -0
  177. data/doc/ep_flux/math-doc/document/img179.png +0 -0
  178. data/doc/ep_flux/math-doc/document/img18.png +0 -0
  179. data/doc/ep_flux/math-doc/document/img180.png +0 -0
  180. data/doc/ep_flux/math-doc/document/img181.png +0 -0
  181. data/doc/ep_flux/math-doc/document/img182.png +0 -0
  182. data/doc/ep_flux/math-doc/document/img183.png +0 -0
  183. data/doc/ep_flux/math-doc/document/img184.png +0 -0
  184. data/doc/ep_flux/math-doc/document/img185.png +0 -0
  185. data/doc/ep_flux/math-doc/document/img186.png +0 -0
  186. data/doc/ep_flux/math-doc/document/img187.png +0 -0
  187. data/doc/ep_flux/math-doc/document/img188.png +0 -0
  188. data/doc/ep_flux/math-doc/document/img189.png +0 -0
  189. data/doc/ep_flux/math-doc/document/img19.png +0 -0
  190. data/doc/ep_flux/math-doc/document/img190.png +0 -0
  191. data/doc/ep_flux/math-doc/document/img191.png +0 -0
  192. data/doc/ep_flux/math-doc/document/img192.png +0 -0
  193. data/doc/ep_flux/math-doc/document/img193.png +0 -0
  194. data/doc/ep_flux/math-doc/document/img194.png +0 -0
  195. data/doc/ep_flux/math-doc/document/img195.png +0 -0
  196. data/doc/ep_flux/math-doc/document/img196.png +0 -0
  197. data/doc/ep_flux/math-doc/document/img197.png +0 -0
  198. data/doc/ep_flux/math-doc/document/img198.png +0 -0
  199. data/doc/ep_flux/math-doc/document/img199.png +0 -0
  200. data/doc/ep_flux/math-doc/document/img2.png +0 -0
  201. data/doc/ep_flux/math-doc/document/img20.png +0 -0
  202. data/doc/ep_flux/math-doc/document/img200.png +0 -0
  203. data/doc/ep_flux/math-doc/document/img21.png +0 -0
  204. data/doc/ep_flux/math-doc/document/img22.png +0 -0
  205. data/doc/ep_flux/math-doc/document/img23.png +0 -0
  206. data/doc/ep_flux/math-doc/document/img24.png +0 -0
  207. data/doc/ep_flux/math-doc/document/img25.png +0 -0
  208. data/doc/ep_flux/math-doc/document/img26.png +0 -0
  209. data/doc/ep_flux/math-doc/document/img27.png +0 -0
  210. data/doc/ep_flux/math-doc/document/img28.png +0 -0
  211. data/doc/ep_flux/math-doc/document/img29.png +0 -0
  212. data/doc/ep_flux/math-doc/document/img3.png +0 -0
  213. data/doc/ep_flux/math-doc/document/img30.png +0 -0
  214. data/doc/ep_flux/math-doc/document/img31.png +0 -0
  215. data/doc/ep_flux/math-doc/document/img32.png +0 -0
  216. data/doc/ep_flux/math-doc/document/img33.png +0 -0
  217. data/doc/ep_flux/math-doc/document/img34.png +0 -0
  218. data/doc/ep_flux/math-doc/document/img35.png +0 -0
  219. data/doc/ep_flux/math-doc/document/img36.png +0 -0
  220. data/doc/ep_flux/math-doc/document/img37.png +0 -0
  221. data/doc/ep_flux/math-doc/document/img38.png +0 -0
  222. data/doc/ep_flux/math-doc/document/img39.png +0 -0
  223. data/doc/ep_flux/math-doc/document/img4.png +0 -0
  224. data/doc/ep_flux/math-doc/document/img40.png +0 -0
  225. data/doc/ep_flux/math-doc/document/img41.png +0 -0
  226. data/doc/ep_flux/math-doc/document/img42.png +0 -0
  227. data/doc/ep_flux/math-doc/document/img43.png +0 -0
  228. data/doc/ep_flux/math-doc/document/img44.png +0 -0
  229. data/doc/ep_flux/math-doc/document/img45.png +0 -0
  230. data/doc/ep_flux/math-doc/document/img46.png +0 -0
  231. data/doc/ep_flux/math-doc/document/img47.png +0 -0
  232. data/doc/ep_flux/math-doc/document/img48.png +0 -0
  233. data/doc/ep_flux/math-doc/document/img49.png +0 -0
  234. data/doc/ep_flux/math-doc/document/img5.png +0 -0
  235. data/doc/ep_flux/math-doc/document/img50.png +0 -0
  236. data/doc/ep_flux/math-doc/document/img51.png +0 -0
  237. data/doc/ep_flux/math-doc/document/img52.png +0 -0
  238. data/doc/ep_flux/math-doc/document/img53.png +0 -0
  239. data/doc/ep_flux/math-doc/document/img54.png +0 -0
  240. data/doc/ep_flux/math-doc/document/img55.png +0 -0
  241. data/doc/ep_flux/math-doc/document/img56.png +0 -0
  242. data/doc/ep_flux/math-doc/document/img57.png +0 -0
  243. data/doc/ep_flux/math-doc/document/img58.png +0 -0
  244. data/doc/ep_flux/math-doc/document/img59.png +0 -0
  245. data/doc/ep_flux/math-doc/document/img6.png +0 -0
  246. data/doc/ep_flux/math-doc/document/img60.png +0 -0
  247. data/doc/ep_flux/math-doc/document/img61.png +0 -0
  248. data/doc/ep_flux/math-doc/document/img62.png +0 -0
  249. data/doc/ep_flux/math-doc/document/img63.png +0 -0
  250. data/doc/ep_flux/math-doc/document/img64.png +0 -0
  251. data/doc/ep_flux/math-doc/document/img65.png +0 -0
  252. data/doc/ep_flux/math-doc/document/img66.png +0 -0
  253. data/doc/ep_flux/math-doc/document/img67.png +0 -0
  254. data/doc/ep_flux/math-doc/document/img68.png +0 -0
  255. data/doc/ep_flux/math-doc/document/img69.png +0 -0
  256. data/doc/ep_flux/math-doc/document/img7.png +0 -0
  257. data/doc/ep_flux/math-doc/document/img70.png +0 -0
  258. data/doc/ep_flux/math-doc/document/img71.png +0 -0
  259. data/doc/ep_flux/math-doc/document/img72.png +0 -0
  260. data/doc/ep_flux/math-doc/document/img73.png +0 -0
  261. data/doc/ep_flux/math-doc/document/img74.png +0 -0
  262. data/doc/ep_flux/math-doc/document/img75.png +0 -0
  263. data/doc/ep_flux/math-doc/document/img76.png +0 -0
  264. data/doc/ep_flux/math-doc/document/img77.png +0 -0
  265. data/doc/ep_flux/math-doc/document/img78.png +0 -0
  266. data/doc/ep_flux/math-doc/document/img79.png +0 -0
  267. data/doc/ep_flux/math-doc/document/img8.png +0 -0
  268. data/doc/ep_flux/math-doc/document/img80.png +0 -0
  269. data/doc/ep_flux/math-doc/document/img81.png +0 -0
  270. data/doc/ep_flux/math-doc/document/img82.png +0 -0
  271. data/doc/ep_flux/math-doc/document/img83.png +0 -0
  272. data/doc/ep_flux/math-doc/document/img84.png +0 -0
  273. data/doc/ep_flux/math-doc/document/img85.png +0 -0
  274. data/doc/ep_flux/math-doc/document/img86.png +0 -0
  275. data/doc/ep_flux/math-doc/document/img87.png +0 -0
  276. data/doc/ep_flux/math-doc/document/img88.png +0 -0
  277. data/doc/ep_flux/math-doc/document/img89.png +0 -0
  278. data/doc/ep_flux/math-doc/document/img9.png +0 -0
  279. data/doc/ep_flux/math-doc/document/img90.png +0 -0
  280. data/doc/ep_flux/math-doc/document/img91.png +0 -0
  281. data/doc/ep_flux/math-doc/document/img92.png +0 -0
  282. data/doc/ep_flux/math-doc/document/img93.png +0 -0
  283. data/doc/ep_flux/math-doc/document/img94.png +0 -0
  284. data/doc/ep_flux/math-doc/document/img95.png +0 -0
  285. data/doc/ep_flux/math-doc/document/img96.png +0 -0
  286. data/doc/ep_flux/math-doc/document/img97.png +0 -0
  287. data/doc/ep_flux/math-doc/document/img98.png +0 -0
  288. data/doc/ep_flux/math-doc/document/img99.png +0 -0
  289. data/doc/ep_flux/math-doc/document/index.html +101 -0
  290. data/doc/ep_flux/math-doc/document/internals.pl +258 -0
  291. data/doc/ep_flux/math-doc/document/labels.pl +265 -0
  292. data/doc/ep_flux/math-doc/document/next.png +0 -0
  293. data/doc/ep_flux/math-doc/document/next_g.png +0 -0
  294. data/doc/ep_flux/math-doc/document/node1.html +104 -0
  295. data/doc/ep_flux/math-doc/document/node10.html +164 -0
  296. data/doc/ep_flux/math-doc/document/node11.html +86 -0
  297. data/doc/ep_flux/math-doc/document/node12.html +166 -0
  298. data/doc/ep_flux/math-doc/document/node13.html +897 -0
  299. data/doc/ep_flux/math-doc/document/node14.html +1065 -0
  300. data/doc/ep_flux/math-doc/document/node15.html +72 -0
  301. data/doc/ep_flux/math-doc/document/node16.html +81 -0
  302. data/doc/ep_flux/math-doc/document/node2.html +82 -0
  303. data/doc/ep_flux/math-doc/document/node3.html +91 -0
  304. data/doc/ep_flux/math-doc/document/node4.html +149 -0
  305. data/doc/ep_flux/math-doc/document/node5.html +330 -0
  306. data/doc/ep_flux/math-doc/document/node6.html +99 -0
  307. data/doc/ep_flux/math-doc/document/node7.html +98 -0
  308. data/doc/ep_flux/math-doc/document/node8.html +83 -0
  309. data/doc/ep_flux/math-doc/document/node9.html +140 -0
  310. data/doc/ep_flux/math-doc/document/prev.png +0 -0
  311. data/doc/ep_flux/math-doc/document/prev_g.png +0 -0
  312. data/doc/ep_flux/math-doc/document/up.png +0 -0
  313. data/doc/ep_flux/math-doc/document/up_g.png +0 -0
  314. data/doc/ep_flux/math-doc/document.pdf +0 -0
  315. data/doc/ep_flux/math-doc/document.tex +2018 -0
  316. data/doc/gdir.html +412 -0
  317. data/doc/gdir_client.html +16 -0
  318. data/doc/gdir_connect_ftp-like.html +61 -0
  319. data/doc/gdir_server.html +45 -0
  320. data/doc/ggraph.html +1615 -0
  321. data/doc/gpcat.html +44 -0
  322. data/doc/gpcut.html +41 -0
  323. data/doc/gphys.html +532 -0
  324. data/doc/gphys_fft.html +324 -0
  325. data/doc/gphys_grads_io.html +69 -0
  326. data/doc/gphys_grib_io.html +82 -0
  327. data/doc/gphys_io.html +120 -0
  328. data/doc/gphys_io_common.html +18 -0
  329. data/doc/gphys_netcdf_io.html +283 -0
  330. data/doc/gplist.html +24 -0
  331. data/doc/gpmath.html +51 -0
  332. data/doc/gpmaxmin.html +31 -0
  333. data/doc/gpprint.html +34 -0
  334. data/doc/gpview.html +270 -0
  335. data/doc/grads2nc_with_gphys.html +21 -0
  336. data/doc/grads_gridded.html +307 -0
  337. data/doc/grib.html +144 -0
  338. data/doc/grid.html +212 -0
  339. data/doc/index.html +133 -0
  340. data/doc/index.rd +127 -0
  341. data/doc/netcdf_convention.html +136 -0
  342. data/doc/unumeric.html +176 -0
  343. data/doc/update +64 -0
  344. data/doc/varray.html +299 -0
  345. data/doc/varraycomposite.html +67 -0
  346. data/ext_coord.c +209 -0
  347. data/ext_init.c +7 -0
  348. data/extconf.rb +42 -0
  349. data/install.rb +130 -0
  350. data/interpo.c +497 -0
  351. data/lib/numru/dcl_mouse.rb +71 -0
  352. data/lib/numru/dclext_datetime_ax.rb +220 -0
  353. data/lib/numru/derivative.rb +348 -0
  354. data/lib/numru/ganalysis/covariance.rb +154 -0
  355. data/lib/numru/ganalysis/eof.rb +298 -0
  356. data/lib/numru/ganalysis/histogram.rb +252 -0
  357. data/lib/numru/ganalysis/met.rb +317 -0
  358. data/lib/numru/ganalysis/planet.rb +182 -0
  359. data/lib/numru/ganalysis.rb +7 -0
  360. data/lib/numru/gdir.rb +1038 -0
  361. data/lib/numru/gdir_connect_ftp-like.rb +149 -0
  362. data/lib/numru/ggraph.rb +5838 -0
  363. data/lib/numru/ggraph_on_merdional_section.rb +178 -0
  364. data/lib/numru/gphys/assoccoords.rb +359 -0
  365. data/lib/numru/gphys/attribute.rb +129 -0
  366. data/lib/numru/gphys/attributenetcdf.rb +80 -0
  367. data/lib/numru/gphys/axis.rb +963 -0
  368. data/lib/numru/gphys/coordmapping.rb +286 -0
  369. data/lib/numru/gphys/coordtransform.rb +209 -0
  370. data/lib/numru/gphys/derivative.rb +314 -0
  371. data/lib/numru/gphys/ep_flux.rb +868 -0
  372. data/lib/numru/gphys/gpcommon.rb +52 -0
  373. data/lib/numru/gphys/gphys.rb +1207 -0
  374. data/lib/numru/gphys/gphys_fft.rb +886 -0
  375. data/lib/numru/gphys/gphys_grads_io.rb +212 -0
  376. data/lib/numru/gphys/gphys_grib_io.rb +214 -0
  377. data/lib/numru/gphys/gphys_gtool3_io.rb +162 -0
  378. data/lib/numru/gphys/gphys_hdfeos5_io.rb +672 -0
  379. data/lib/numru/gphys/gphys_io.rb +452 -0
  380. data/lib/numru/gphys/gphys_io_common.rb +126 -0
  381. data/lib/numru/gphys/gphys_netcdf_io.rb +800 -0
  382. data/lib/numru/gphys/gphys_nusdas_io.rb +132 -0
  383. data/lib/numru/gphys/grads_gridded.rb +1638 -0
  384. data/lib/numru/gphys/grib.rb +2049 -0
  385. data/lib/numru/gphys/grib_params.rb +1465 -0
  386. data/lib/numru/gphys/grid.rb +723 -0
  387. data/lib/numru/gphys/gtool3.rb +771 -0
  388. data/lib/numru/gphys/interpolate.rb +854 -0
  389. data/lib/numru/gphys/narray_ext.rb +34 -0
  390. data/lib/numru/gphys/netcdf_convention.rb +406 -0
  391. data/lib/numru/gphys/subsetmapping.rb +332 -0
  392. data/lib/numru/gphys/unumeric.rb +522 -0
  393. data/lib/numru/gphys/varray.rb +1109 -0
  394. data/lib/numru/gphys/varraycomposite.rb +415 -0
  395. data/lib/numru/gphys/varraygrads.rb +225 -0
  396. data/lib/numru/gphys/varraygrib.rb +177 -0
  397. data/lib/numru/gphys/varraygtool3.rb +226 -0
  398. data/lib/numru/gphys/varrayhdfeos5.rb +451 -0
  399. data/lib/numru/gphys/varraynetcdf.rb +350 -0
  400. data/lib/numru/gphys/varraynusdas.rb +59 -0
  401. data/lib/numru/gphys.rb +9 -0
  402. data/lib/numru/htdir.rb +170 -0
  403. data/multibitIO.c +567 -0
  404. data/sample/cira86_to_nc.rb +122 -0
  405. data/sample/druby_cli1.rb +21 -0
  406. data/sample/druby_cli2.rb +34 -0
  407. data/sample/druby_serv1.rb +30 -0
  408. data/sample/druby_serv2.rb +64 -0
  409. data/sample/ep_flux/demo_NCEP_1.rb +48 -0
  410. data/sample/ep_flux/demo_NCEP_2.rb +57 -0
  411. data/sample/ep_flux/demo_NCEP_3.rb +81 -0
  412. data/sample/ggraph_latlon_labelling_dr002690.rb +159 -0
  413. data/sample/ggraph_mapfit-axes_dr002687.rb +131 -0
  414. data/sample/map_projection.rb +121 -0
  415. data/sample/ncep_theta_coord.rb +79 -0
  416. data/test/eof_slp.rb +28 -0
  417. data/test/mltbit.dat +0 -0
  418. data/test/test_ep_flux.rb +533 -0
  419. data/test/test_multibitIO.rb +19 -0
  420. data/testdata/T.jan.ctl +12 -0
  421. data/testdata/T.jan.dat +0 -0
  422. data/testdata/T.jan.grib +0 -0
  423. data/testdata/T.jan.nc +0 -0
  424. data/testdata/T.jan.packed.withmiss.nc +0 -0
  425. data/testdata/UV.jan.nc +0 -0
  426. data/testdata/assoc_crds.nc +0 -0
  427. data/testdata/cira86.dat +1332 -0
  428. metadata +621 -0
@@ -0,0 +1,2049 @@
1
+ =begin
2
+ =Status
3
+ * only a Lon-Lat coordinate is supported
4
+ * only simple pakking is supported
5
+ * variable list is not complete for NCEP and ECMWF
6
+ =end
7
+ require "narray_miss"
8
+ require "date"
9
+ require "time"
10
+ require "numru/gphys_ext"
11
+
12
+ ## /--->
13
+ ## backport of String#ord and String#getbyte (ruby 1.9 feature)
14
+ ## to Ruby 1.8 or earlier
15
+ =begin
16
+ if ! 'a'.respond_to?(:ord)
17
+ class String
18
+ def ord
19
+ self[0]
20
+ end
21
+ end
22
+ end
23
+ if ! 'a'.respond_to?(:getbyte)
24
+ class String
25
+ def getbyte(i)
26
+ self[i]
27
+ end
28
+ end
29
+ end
30
+ =end
31
+ ## <---/
32
+
33
+ module NumRu
34
+ module GribUtils
35
+ require "numru/gphys/grib_params"
36
+ private
37
+ =begin
38
+ def str2uint1(str)
39
+ return nil if str.length==0
40
+ return str.ord
41
+ end
42
+ def str2uint2(str)
43
+ return nil if str.length==0
44
+ return (str.ord<<8)+str.getbyte(1)
45
+ end
46
+ def str2uint3(str)
47
+ return nil if str.length==0
48
+ return (str.ord<<16)+(str.getbyte(1)<<8)+str.getbyte(2)
49
+ end
50
+ =end
51
+ def str2int1(str)
52
+ n = str.to_uint1
53
+ return n && n > 127 ? 128-n : n
54
+ end
55
+ def str2int2(str)
56
+ n = str.to_uint2
57
+ return n && n > 32767 ? 32768-n : n
58
+ end
59
+ def str2int3(str)
60
+ n = str.to_uint3
61
+ return n && n > 8388607 ? 8388608-n : n
62
+ end
63
+ def uint2str(i,len)
64
+ str = [sprintf("%0#{len*2}x",i)].pack("H*")
65
+ str.length==len || raise("str length is not valid")
66
+ return str
67
+ end
68
+ def int2str(i,len)
69
+ flag = i<0
70
+ i = -i if flag
71
+ str = sprintf("%0#{len*2}x",i)
72
+ str[0..0] = sprintf("%x",str[0..0].hex+8) if flag
73
+ str = [str].pack("H*")
74
+ str.length==len || raise("str length is not valid")
75
+ return str
76
+ end
77
+ def float_value( str )
78
+ str.length==4 || raise("str length must be 4")
79
+ sa = str2int1(str)
80
+ s = (sa<0) ? -1 : 1
81
+ a = sa.abs
82
+ b = str.to_uint3(1)
83
+ return s*(2.0)**(-24.0)*b*(16.0)**(a-64.0)
84
+ end
85
+ def get_bits( str, nstep, nbits, sbu, ebu, type )
86
+ len = str.length
87
+ bx = NArray.to_na(str,NArray::BYTE)
88
+ nb = nbits/nstep
89
+ y = NArray.new(type,nb).indgen(nb-1,-1)
90
+ if nstep==8
91
+ x = bx.to_type(type)
92
+ y = 256**y
93
+ elsif nstep==4
94
+ x = NArray.new(type,2,len)
95
+ x[0,true] = (bx&240)/16
96
+ x[1,true] = bx&15
97
+ x.reshape!(len*2)
98
+ y = 16**y
99
+ elsif nstep==2
100
+ x = NArray.new(type,4,len)
101
+ x[0,true] = (bx&192)/64
102
+ x[1,true] = (bx&48)/16
103
+ x[2,true] = (bx&12)/4
104
+ x[3,true] = bx&3
105
+ x.reshape!(len*4)
106
+ y = 4**y
107
+ else
108
+ x = NArray.new(type,8,len)
109
+ x[0,true] = (bx&128)/128
110
+ x[1,true] = (bx&64)/64
111
+ x[2,true] = (bx&32)/32
112
+ x[3,true] = (bx&16)/16
113
+ x[4,true] = (bx&8)/8
114
+ x[5,true] = (bx&4)/4
115
+ x[6,true] = (bx&2)/2
116
+ x[7,true] = bx&1
117
+ x.reshape!(len*8)
118
+ y = 2**y
119
+ end
120
+ x = x[sbu..-1-ebu]
121
+ x.reshape!(nb,x.length/nb)
122
+ return (x*y).sum(0)
123
+ end
124
+ def data2str(data, nstep, nbits)
125
+ len = data.length
126
+ data.reshape!(len)
127
+ nb = nbits/nstep
128
+ x = NArray.byte(nb,len)
129
+ nb.times{|n|
130
+ x[nb-n-1,true] = (data/2**(n*nstep))&(2**nstep-1)
131
+ }
132
+ nb2 = 8/nstep
133
+ y = NArray.byte(nb2).indgen(nb2-1,-1)
134
+ y = (2**nstep)**y
135
+ ebu = nb2-x.length%nb2
136
+ ebu = 0 if ebu==nb2
137
+ x2 = NArray.byte(x.length+ebu)
138
+ x2[0..-1-ebu] = x.reshape!(x.length)
139
+ x2.reshape!(nb2,x2.length/nb2)
140
+ x2 = (x2*y).sum(0)
141
+ return [x2.to_s,ebu*nstep]
142
+ end
143
+
144
+ def gausslat(ny)
145
+ # this method was written by Y.Kitamura
146
+ # and modified by S.Nishizawa
147
+ glat = NArray.sfloat(ny)
148
+ gweight = NArray.sfloat(ny)
149
+
150
+ eps = 1.0
151
+ while (eps + 1.0 != 1.0)
152
+ eps = eps/2.0
153
+ end
154
+ eps = eps*16.0
155
+
156
+ 0.upto(ny/2-1) do |i|
157
+ y = Math::sin(Math::PI*(ny + 1.0 - 2.0*(i+1.0))/(2.0*ny + 1.0))
158
+ tmp = 1.0
159
+ while ((tmp/y).abs > eps)
160
+ p0 = 0.0
161
+ p1 = 1.0
162
+ 1.step(ny-1, 2) do |j|
163
+ p0 = ((2*j-1)*y*p1 - (j-1)*p0)/j
164
+ p1 = ((2*j+1)*y*p0 - j*p1)/(j+1)
165
+ end
166
+ p2 = ny*(p0 - y*p1)/(1.0 - y*y)
167
+ tmp = p1/p2
168
+ y = y - tmp
169
+ end
170
+ glat[i] = y
171
+ glat[ny-i-1] = -y
172
+ gweight[i] = 1.0/(p2*p2*(1.0 - glat[i]*glat[i]))
173
+ gweight[ny-i-1] = gweight[i]
174
+ end
175
+ return NMath::asin(glat)*180/Math::PI
176
+ end
177
+
178
+ def get_time(ary)
179
+ d = (ary[0]-D19000101).to_i
180
+ h,m = ary[1]
181
+ return d*24+h+m/60
182
+ end
183
+
184
+ end # GribUtils
185
+
186
+ class Grib
187
+ private
188
+ class GribSegment
189
+ class << self
190
+ include GribUtils
191
+ def create(file)
192
+ obj = GribSegment.new
193
+ obj.file = file
194
+ obj.is = GribIS.new(obj)
195
+ obj.pds = GribPDS.new(obj)
196
+ obj.gds = GribGDS.new(obj)
197
+ obj.bms = GribBMS.new(obj)
198
+ obj.bds = GribBDS.new(obj)
199
+ obj.es = GribES.new(obj)
200
+ obj.is.update_total_length
201
+ return obj
202
+ end
203
+ def parse(file, mbio)
204
+ obj = GribSegment.new
205
+ obj.file = file
206
+ obj.mbio = mbio
207
+ obj.pos = file.pos
208
+
209
+ is = GribIS.new(obj,ss = file.read(8))
210
+ unless is.version == 1
211
+ warn "This Grib version (#{is.version}) has not supported yet"
212
+ return nil
213
+ end
214
+ unless is.grib?
215
+ raise "This file is not Grib file (INITIAL SECTION)"
216
+ end
217
+ obj.is = is
218
+
219
+ pds = GribPDS.new(obj,file.read(file.read(3).to_uint3-3))
220
+ obj.pds = pds
221
+
222
+ str = pds.gds? ? file.read(file.read(3).to_uint3-3) : nil
223
+ gds = GribGDS.new(obj,str)
224
+ obj.gds = gds
225
+
226
+ str = pds.bms? ? file.read(file.read(3).to_uint3-3) : nil
227
+ bms = GribBMS.new(obj,str)
228
+ obj.bms = bms
229
+
230
+ len = file.read(3).to_uint3
231
+ bds = GribBDS.new(obj,file.pos,len)
232
+ obj.bds = bds
233
+ file.seek(len-3,IO::SEEK_CUR)
234
+
235
+ es = GribES.new(obj,file.read(4))
236
+ unless es.grib?
237
+ raise "This file is not Grib file (END SECTION)"
238
+ end
239
+ obj.es = es
240
+
241
+ if is.total_length!=is.length+pds.length+gds.length+bms.length+bds.length+es.length
242
+ raise "total length is not equal to the sum of each section\nfile may be broken"
243
+ end
244
+
245
+ return obj
246
+ end
247
+ end
248
+ attr_accessor :file, :pos, :mbio
249
+ attr_accessor :is, :pds, :gds, :bms, :bds, :es
250
+ def set_xy(x,y)
251
+ pds.set_gds(true)
252
+ if x.att("long_name").downcase=="longitude" && y.att("long_name").downcase=="latitude"
253
+ xv = x.val
254
+ yv = y.val
255
+ rel = false
256
+ if (xv[1]-xv[0])==(xv[-1]-xv[-2]) && (yv[1]-yv[0])==(yv[-1]-yv[-2])
257
+ id = 0
258
+ else
259
+ raise "not defined yet"
260
+ end
261
+ elsif y.att("long_name").downcase=="longitude" && x.att("long_name").downcase=="latitude"
262
+ xv = y.val
263
+ yv = x.val
264
+ rel = true
265
+ if (xv[1]-xv[0])==(xv[-1]-xv[-2]) && (yv[1]-yv[0])==(yv[-1]-yv[-2])
266
+ id = 0
267
+ else
268
+ raise "not defined yet"
269
+ end
270
+ else
271
+ raise "not defined yet"
272
+ end
273
+ gds.set_grid(id,xv,yv,rel)
274
+ end
275
+ def set_level(z)
276
+ if Array===z
277
+ id = Z_TYPES.invert[Z_TYPES.values.assoc(z[0])]
278
+ id = 100 if id.nil?
279
+ pds.set_z_id(id)
280
+ pds.set_z_value(z[1])
281
+ else
282
+ id = Z_TYPES.invert[Z_TYPES.values.assoc(z)]
283
+ pds.set_z_id(id)
284
+ end
285
+ end
286
+ def set_time(t)
287
+ if String===t
288
+ ye,mo,da,ho,mi, = Time.parse(t).to_a.reverse![4..-2]
289
+ else
290
+ if t.nil?
291
+ ye = 0
292
+ mo = 1
293
+ da = 1
294
+ ho = 0
295
+ mi = 0
296
+ else
297
+ d = D19000101 + t/24
298
+ ye = d.year
299
+ mo = d.month
300
+ da = d.day
301
+ ho = t%24
302
+ mi = 0
303
+ end
304
+ end
305
+ pds.set_initial(ye,mo,da,ho,mi)
306
+ end
307
+ def set_var(var,name,units)
308
+ is.set_version(1)
309
+ pds.set_version(2)
310
+ pds.set_center_id(0)
311
+ pds.set_pid(0)
312
+ id = PARAMS_2.invert[NAMES_UNITS.invert[NAMES_UNITS.values.assoc(name)]]
313
+ id = 000 if id.nil?
314
+ pds.set_name_id(id)
315
+ pds.set_time_unit_id(0)
316
+ pds.set_p1(0)
317
+ pds.set_p2(0)
318
+ pds.set_time_range_id(1)
319
+ pds.set_ave(0)
320
+ pds.set_miss(0)
321
+ pds.set_sub_center_id(0)
322
+ pds.set_dfact(0)
323
+ if NArrayMiss===var
324
+ mask = var.get_mask!
325
+ if mask.count_false>0
326
+ pds.set_bms(true)
327
+ bms.set_map_number(0)
328
+ bms.set_map(mask)
329
+ end
330
+ end
331
+ bds.set_grid(true)
332
+ bds.set_simple(true)
333
+ if units && pds.unit
334
+ f,o = Units[units].factor_and_offset(Units[pds.unit])
335
+ var = var*f+o
336
+ end
337
+ if var.typecode==NArray::SINT || var.typecode==NArray::INT
338
+ bds.set_ingeger(true)
339
+ else
340
+ bds.set_float(true)
341
+ end
342
+ bds.set_value(var)
343
+ end
344
+ def write
345
+ tlen = is.update_total_length
346
+ len = 0
347
+ len += @file.write(is.get)
348
+ len += @file.write(pds.get)
349
+ len += @file.write(gds.get)
350
+ len += @file.write(bms.get)
351
+ len += @file.write(bds.get)
352
+ len += @file.write(es.get)
353
+ tlen==len || raise("length is not correct")
354
+ end
355
+ end # end definition of class GribSegment
356
+ class GribIS
357
+ include GribUtils
358
+ def initialize(sgm,str=nil)
359
+ @sgm = sgm
360
+ @is = str || "GRIB"+uint2str(8,3)+uint2str(2,1)
361
+ end
362
+ def length
363
+ return 8
364
+ end
365
+ def grib?
366
+ return @is[0..3]=="GRIB"
367
+ end
368
+ def total_length
369
+ return @is.to_uint3(4)
370
+ end
371
+ def update_total_length
372
+ len = self.length+@sgm.pds.length+@sgm.gds.length+@sgm.bms.length+@sgm.bds.length+@sgm.es.length
373
+ @is[4..6] = uint2str(len,3)
374
+ return len
375
+ end
376
+ def version
377
+ return @is.to_uint1(7)
378
+ end
379
+ def set_version(ver)
380
+ @is[7..7] = uint2str(ver,1)
381
+ return ver
382
+ end
383
+ alias :version= :set_version
384
+ def get
385
+ @is
386
+ end
387
+ end # end definition of class GribIS
388
+ class GribPDS
389
+ include GribUtils
390
+ private
391
+ def param
392
+ nid = @pds.to_uint1(5)
393
+ params = nil
394
+ case version
395
+ when 0
396
+ params = PARAMS_0
397
+ when 1
398
+ params = PARAMS_1
399
+ when 2,3
400
+ if nid<128
401
+ params = PARAMS_2
402
+ else
403
+ if cid==7 # NCEP
404
+ params = PARAMS_NCEP_2
405
+ elsif cid == 34 # JMA
406
+ params = PARAMS_JMA
407
+ end
408
+ end
409
+ else
410
+ if cid==98 # ECMWF
411
+ if version==128
412
+ params = PARAMS_ECMWF_128
413
+ elsif version == 162
414
+ params = PARAMS_ECMWF_162
415
+ end
416
+ end
417
+ end
418
+ if params
419
+ if para_id = params[nid]
420
+ if para = NAMES_UNITS[para_id]
421
+ return para
422
+ else
423
+ warn "parameter ID #{nid} in table version #{version} has not defined yet"
424
+ end
425
+ else
426
+ warn "parameter ID #{nid} in table version #{version} has not defined yet"
427
+ end
428
+ else
429
+ warn "parameter table version #{version}, center id #{cid}, version #{version}, parameter id #{nid} has not defined yet"
430
+ end
431
+ return ["unknown (#{nid})", nid.to_s, "-", nil]
432
+ end
433
+ def cid
434
+ return @pds.to_uint1(1)
435
+ end
436
+ def initialize(sgm,str=nil)
437
+ @sgm = sgm
438
+ @pds = str || "\000"*25
439
+ end
440
+ public
441
+ def length
442
+ @pds.length+3
443
+ end
444
+ def version
445
+ return @pds.to_uint1
446
+ end
447
+ def set_version(ver)
448
+ @pds[0..0] = uint2str(ver,1)
449
+ return ver
450
+ end
451
+ alias :version= :set_version
452
+ def center
453
+ return CENTERS[cid]
454
+ end
455
+ def set_center_id(id)
456
+ @pds[1..1] = uint2str(id,1)
457
+ end
458
+ alias :center_id= :set_center_id
459
+ def pid
460
+ return @pds.to_uint1(2)
461
+ end
462
+ def set_pid(id)
463
+ @pds[2..2] = uint2str(id,1)
464
+ return id
465
+ end
466
+ alias :pid= :set_pid
467
+ def gid
468
+ return @pds.to_uint1(3)
469
+ end
470
+ def set_gid(id)
471
+ @pds[3..3] = uint2str(id,1)
472
+ return id
473
+ end
474
+ alias :gid= :set_gid
475
+ def gds?
476
+ flag = @pds.to_uint1(4)
477
+ return (flag>>7)&1==1
478
+ end
479
+ def set_gds(gds)
480
+ flag = bms? ? 64 : 0
481
+ if gds
482
+ flag += 128
483
+ @pds[4..4] = uint2str(flag,1)
484
+ @sgm.gds.exist
485
+ set_gid(255)
486
+ return true
487
+ else
488
+ @pds[4..4] = uint2str(flag,1)
489
+ @sgm.gds.not_exist
490
+ return false
491
+ end
492
+ end
493
+ alias :gds= :set_gds
494
+ def bms?
495
+ flag = @pds.to_uint1(4)
496
+ return (flag>>6)&1==1
497
+ end
498
+ def set_bms(bms)
499
+ flag = gds? ? 128 : 0
500
+ if bms
501
+ flag += 64
502
+ @pds[4..4] = uint2str(flag,1)
503
+ @sgm.bms.exist
504
+ return true
505
+ else
506
+ @pds[4..4] = uint2str(flag,1)
507
+ @sgm.bms.not_exist
508
+ return false
509
+ end
510
+ end
511
+ alias :bms= :set_bms
512
+ def name
513
+ return param[0]
514
+ end
515
+ def standard_name
516
+ return param[3]
517
+ end
518
+ def set_name_id(id)
519
+ @pds[5..5] = uint2str(id,1)
520
+ return id
521
+ end
522
+ alias :name_id= :set_name_id
523
+ def sname
524
+ zid = @pds.to_uint1(6)
525
+ sn = param[1]
526
+ zt = Z_TYPES[zid]
527
+ zn = zt ? zt[1] : zid.to_s
528
+ return zn=="level" ? sn : sn+"_"+zn
529
+ end
530
+ def unit
531
+ return param[2]
532
+ end
533
+ def z_type
534
+ zid = @pds.to_uint1(6)
535
+ zt = Z_TYPES[zid]
536
+ if zt
537
+ return zt[0]
538
+ else
539
+ warn "z type (#{zid}) is not defined yet"
540
+ return zid.to_s
541
+ end
542
+ end
543
+ def set_z_id(id)
544
+ @pds[6..6] = uint2str(id,1)
545
+ return id
546
+ end
547
+ alias :z_id= :set_z_id
548
+ def z_sname
549
+ zid = @pds.to_uint1(6)
550
+ if zn = Z_TYPES[zid]
551
+ return zn[1]
552
+ else
553
+ warn "z type (#{zid}) is not defined yet"
554
+ return "unknown_#{zid}"
555
+ end
556
+ end
557
+ def z_value
558
+ return @z_value if @z_value
559
+ type = @pds.to_uint1(6)
560
+ str = @pds[7,2]
561
+ ary = Z_LEVELS[type]
562
+ if ary.nil?
563
+ ary = []
564
+ else
565
+ ary = ary.dup
566
+ end
567
+ if ary.length==1
568
+ ary[0] = ary[0].dup.update( {"value"=> str.to_uint2} )
569
+ elsif ary.length==2
570
+ ary[0] = ary[0].dup.update( {"value"=> str.to_uint1} )
571
+ ary[1] = ary[1].dup.update( {"value"=> str.to_uint1(1)} )
572
+ end
573
+ @z_value = ary
574
+ return ary
575
+ end
576
+ def set_z_value(val)
577
+ type = @pds.to_uint1(6)
578
+ ary = Z_LEVELS[type]
579
+ val.length==ary.length || raise("length of val is not collect")
580
+ if val.length==1
581
+ @pds[7,2] = uint2str(val[0],2)
582
+ elsif val.length==2
583
+ @pds[7,1] = uint2str(val[0],1)
584
+ @pds[8,1] = uint2str(val[1],1)
585
+ else
586
+ raise "length of val is too large"
587
+ end
588
+ return val
589
+ end
590
+ alias :z_value= :set_z_value
591
+ def initial
592
+ return [@pds.to_uint1(21), @pds.to_uint1(9), @pds.to_uint1(10), @pds.to_uint1(11), @pds.to_uint1(12), @pds.to_uint1(13)]
593
+ end
594
+ def set_initial(year,month,day,hour,min)
595
+ cent = year/100+1
596
+ year = year%100
597
+ @pds[21,1] = uint2str(cent,1)
598
+ @pds[9,1] = uint2str(year,1)
599
+ @pds[10,1] = uint2str(month,1)
600
+ @pds[11,1] = uint2str(day,1)
601
+ @pds[12,1] = uint2str(hour,1)
602
+ @pds[13,1] = uint2str(min,1)
603
+ return initial
604
+ end
605
+ alias :initial= :set_initial
606
+ def date
607
+ d = Date.new((@pds.to_uint1(21)-1)*100 + @pds.to_uint1(9),
608
+ @pds.to_uint1(10), @pds.to_uint1(11)
609
+ )
610
+ h = [@pds.to_uint1(12), @pds.to_uint1(13)]
611
+ return [d,h]
612
+ end
613
+ def time_unit
614
+ return TIME_UNITS[ @pds.to_uint1(14) ]
615
+ end
616
+ def set_time_unit_id(id)
617
+ @pds[14,1] = uint2str(id,1)
618
+ return id
619
+ end
620
+ alias :time_unit_id= :set_time_unit_id
621
+ def p1
622
+ return @pds.to_uint1(15)
623
+ end
624
+ def set_p1(i)
625
+ @pds[15,1] = uint2str(i,1)
626
+ return i
627
+ end
628
+ alias :p1= :set_p1
629
+ def p2
630
+ return @pds.to_uint1(16)
631
+ end
632
+ def set_p2(i)
633
+ @pds[16,1] = uint2str(i,1)
634
+ return i
635
+ end
636
+ alias :p2= :set_p2
637
+ def time_range
638
+ return @pds.to_uint1(17)
639
+ end
640
+ def set_time_range_id(id)
641
+ @pds[17,1] = uint2str(id,1)
642
+ return id
643
+ end
644
+ alias :time_range_id= :set_time_range_id
645
+ def ave
646
+ return @pds.to_uint2(18)
647
+ end
648
+ def set_ave(val)
649
+ @pds[18,2] = uint2str(val,2)
650
+ return val
651
+ end
652
+ alias :ave= :set_ave
653
+ def miss
654
+ return @pds.to_uint1(20)
655
+ end
656
+ def set_miss(val)
657
+ @pds[20,1] = uint2str(val,1)
658
+ return val
659
+ end
660
+ alias :miss= :set_miss
661
+ def sub_center
662
+ return @pds.to_uint1(22)
663
+ end
664
+ def set_sub_center_id(id)
665
+ @pds[22,1] = uint2str(id,1)
666
+ return id
667
+ end
668
+ alias :sub_center_id= :set_sub_center_id
669
+ def dfact
670
+ return str2int2( @pds[23,2] )
671
+ end
672
+ def set_dfact(val)
673
+ @pds[23..24] = int2str(val,2)
674
+ return val
675
+ end
676
+ alias :dfact= :set_dfact
677
+ def get
678
+ uint2str(length,3)<<@pds
679
+ end
680
+ end # end definition of class GribPDS
681
+ class GribGDS
682
+ include GribUtils
683
+ private
684
+ def gtype
685
+ return @gds.to_uint1(2)
686
+ end
687
+ def get_x_y(grid)
688
+ case gtype
689
+ when 0,4
690
+ #lon_lat (+GussLat)
691
+ flag = grid.to_uint1(10)
692
+ flag_inc = (flag>>7)&1
693
+ flag = grid.to_uint1(21)
694
+ flag_scani = (flag>>7)&1
695
+ flag_scanj = (flag>>6)^1
696
+ flag_ij = (flag>>5)&1
697
+
698
+ lon = Hash.new
699
+ lon["short_name"] = "lon"
700
+ lon["long_name"] = "longitude"
701
+ lon["units"] = "degrees_east"
702
+ nlon = grid.to_uint2
703
+ nlon==0xffff && raise("not defined yet")
704
+ lo1 = str2int3( grid[7,3] )
705
+ lo2 = str2int3( grid[14,3] )
706
+ dlon = grid.to_uint2(17)
707
+ if (!flag_inc)&&dlon==-0x7fff
708
+ dlon = (lo2-lo1)/(nlon-1)
709
+ else
710
+ if lo1>lo2
711
+ if dlon*(nlon-1)!=lo1-lo2
712
+ lo2 += 360000
713
+ else
714
+ dlon = -dlon
715
+ end
716
+ end
717
+ end
718
+ dlon2 = (lo2-lo1).to_f/(nlon-1)
719
+ dlon2.round==dlon.round || warn("Warning: dlon is not same: #{dlon2/1000} != #{dlon.to_f/1000}")
720
+ vlon = NArray.sfloat(nlon).indgen*dlon2+lo1
721
+ if flag_scani==1 && dlon>0 # THIS PART MIGHT BE MEANINGLESS (OR WRONG)
722
+ vlon = vlon[-1..0]
723
+ end
724
+ lon["value"] = vlon/1000
725
+ lon["length"] = vlon.length
726
+
727
+ lat = Hash.new
728
+ lat["short_name"] = "lat"
729
+ lat["long_name"] = "latitude"
730
+ lat["units"] = "degrees_north"
731
+ nlat = grid.to_uint2(2)
732
+ nlat==0xffff && raise("not defined yet")
733
+ la1 = str2int3( grid[4,3] )
734
+ la2 = str2int3( grid[11,3] )
735
+ dlat = grid.to_uint2(19)
736
+ if gtype==0
737
+ if (!flag_inc)&&dlat==-0x7fff
738
+ dlat = (la2-la1)/(nlat-1)
739
+ else
740
+ dlat = -dlat if la1>la2
741
+ end
742
+ dlat2 = (la2-la1).to_f/(nlat-1)
743
+ dlat2.round==dlat.round || raise("dlat is not same: #{dlat2/1000} != #{dlat.to_f/1000}\n")
744
+ vlat = NArray.sfloat(nlat).indgen*dlat2+la1
745
+ vlat = vlat/1000
746
+ elsif gtype==4
747
+ j = NArray.sfloat(dlat*2).indgen(1)
748
+ # glat = NMath::asin(NMath::cos((j-0.5)*Math::PI/dlat/2))*180/Math::PI
749
+ glat = gausslat(dlat*2)
750
+ glat = glat[-1..0] if la1>la2
751
+ tmp = (glat-la1.to_f/1000).abs
752
+ is = tmp.eq(tmp.min).where[0]
753
+ tmp = (glat-la2.to_f/1000).abs
754
+ ie = tmp.eq(tmp.min).where[0]
755
+ vlat = glat[is..ie]
756
+ vlat.length==nlat || raise("length of latitude is not same: #{vlat.length} != #{nlat}")
757
+ if (vlat[0]*1000-la1).abs > (vlat[1]*1000-la1).abs
758
+ warn("Warning: first of latitude is not same: #{vlat[0]} != #{la1.to_f/1000}")
759
+ end
760
+ if (vlat[-1]*1000-la2).abs > (vlat[-2]*1000-la2).abs
761
+ warn("Warning: last of latitude is not same: #{vlat[-1]} != #{la2.to_f/1000}")
762
+ end
763
+ lat["type"] = "Gaussian latitude"
764
+ lat["number_of_latitude_circles"] = NArray[dlat*2]
765
+ end
766
+ if flag_scanj==1 && dlat>0 # THIS PART MIGHT BE MEANINGLESS (OR WRONG)
767
+ vlat = vlat[-1..0]
768
+ end
769
+ lat["value"] = vlat
770
+ lat["length"] = vlat.length
771
+
772
+ if flag_ij==0
773
+ lon["ij"] = 0
774
+ lat["ij"] = 1
775
+ else
776
+ lon["ij"] = 1
777
+ lat["ij"] = 0
778
+ end
779
+ return [lon,lat]
780
+ when 1
781
+ #mercator
782
+ raise "not defined yet"
783
+ when 3
784
+ #lambert
785
+ raise "not defined yet"
786
+ when 5
787
+ #polar
788
+ raise "not defined yet"
789
+ when 50
790
+ #spherical
791
+ raise "not defined yet"
792
+ when 90
793
+ #space
794
+ raise "not defined yet"
795
+ else
796
+ raise "not defined yet"
797
+ end
798
+ end
799
+ def grid2str(gtype,x,y,rev=false)
800
+ case gtype
801
+ when 0,4
802
+ #lat_lon
803
+ grid = "\000"*26
804
+ nlon = x.length
805
+ nlat = y.length
806
+ grid[0,2] = uint2str(nlon,2)
807
+ grid[2,2] = uint2str(nlat,2)
808
+ vlon = x*1000
809
+ vlat = y*1000
810
+ grid[4,3] = int2str(vlat[0],3)
811
+ grid[7,3] = int2str(vlon[0],3)
812
+ flag = 1<<7
813
+ grid[10,1] = uint2str(flag,1)
814
+ grid[11,3] = int2str(vlat[-1],3)
815
+ grid[14,3] = int2str(vlon[-1],3)
816
+ dlon = ((vlon[-1]-vlon[0])/(nlon-1)).abs
817
+ grid[17,2] = uint2str(dlon,2)
818
+ if gtype==0
819
+ dlat = ((vlat[0]-vlat[-1])/(nlat-1)).abs
820
+ grid[19,2] = uint2str(dlat,2)
821
+ else
822
+ raise "not defined yet"
823
+ end
824
+ if rev
825
+ flag=1<<5
826
+ else
827
+ flag=0
828
+ end
829
+ grid[21,1] = uint2str(flag,1)
830
+ return grid
831
+ when 1
832
+ #mercator
833
+ raise "not defined yet"
834
+ when 3
835
+ #lambert
836
+ raise "not defined yet"
837
+ when 5
838
+ #polar
839
+ raise "not defined yet"
840
+ when 50
841
+ #spherical
842
+ raise "not defined yet"
843
+ when 90
844
+ #space
845
+ raise "not defined yet"
846
+ else
847
+ raise "not defined yet"
848
+ end
849
+ end
850
+ def initialize(sgm,str=nil)
851
+ @sgm = sgm
852
+ @gds = str
853
+ end
854
+
855
+ public
856
+ def exist
857
+ @gds = "\000"*41
858
+ @gds[1,1] = uint2str(255,1)
859
+ @sgm.is.update_total_length
860
+ end
861
+ def not_exist
862
+ @gds = nil
863
+ @sgm.is.update_total_length
864
+ end
865
+ def length
866
+ if @gds
867
+ return @gds.length+3
868
+ else
869
+ return 0
870
+ end
871
+ end
872
+ def nv
873
+ return @gds.to_uint1
874
+ end
875
+ def pv
876
+ pv = @gds.to_uint1(1)
877
+ return nil if pv==255 || nv==0
878
+ return pv
879
+ end
880
+ def pl
881
+ pl = @gds.to_uint1(1)
882
+ return nil if pl==255
883
+ return nv*4+pl
884
+ end
885
+ def grid_type
886
+ return GRID_TYPES[ gtype ]
887
+ end
888
+ def grid
889
+ if gtype==3||gtype==1
890
+ grid = @gds[3..38]
891
+ elsif gtype==90
892
+ grid = @gds[3..40]
893
+ else
894
+ grid = @gds[3..28]
895
+ end
896
+ return get_x_y(grid)
897
+ end
898
+ def set_grid(id,x,y,rev)
899
+ @gds[2..2] = uint2str(id,1)
900
+ if id==3||id==1
901
+ str = grid2str(id,x,y,rev)
902
+ str.length==36 || raise("length is not correct")
903
+ @gds[3..38] = str
904
+ @sgm.is.update_total_length
905
+ elsif id==90
906
+ str = grid2str(id,x,y,rev)
907
+ str.length==38 || raise("length is not correct")
908
+ @gds[3..40] = str
909
+ @sgm.is.update_total_length
910
+ else
911
+ str = grid2str(id,x,y,rev)
912
+ str.length==26 || raise("length is not correct")
913
+ @gds[3..28] = str
914
+ @sgm.is.update_total_length
915
+ end
916
+ return [id,x,y]
917
+ end
918
+ def list_pv
919
+ return nil unless pv
920
+ list = NArray.sfloat(nv)
921
+ nv.times{|n|
922
+ list[n] = float_value( @gds[pv-4+n*4...pv-4+(n+1)*4] )
923
+ }
924
+ return list
925
+ end
926
+ def set_list_pv(list)
927
+ nv = list.length/4
928
+ @gds[0..0] = uint2str(nv,1)
929
+ raise "not defined yet"
930
+ if gtype==3||gtype==1
931
+ pv = 43
932
+ elsif gtype==90
933
+ pv = 45
934
+ else
935
+ pv = 33
936
+ end
937
+ @gds[1..1] = uint2str(pv,1)
938
+ @gds[pv-4..-1] = list
939
+ return true
940
+ end
941
+ alias :list_pv= :set_list_pv
942
+ def list_pl
943
+ return @gds[pl-4..-1] if pl
944
+ return nil
945
+ end
946
+ def set_list_pl(list)
947
+ raise "not defined yet"
948
+ pl = nv*4+pv
949
+ @gds[1..1] = uint2str(pl,1)
950
+ @gds[pl-4..-1] = list
951
+ return true
952
+ end
953
+ alias :list_pv= :set_list_pv
954
+ def eq?(str)
955
+ @gds==str
956
+ end
957
+ def ==(other)
958
+ if GribGDS===other
959
+ return other.eq?(@gds)
960
+ else
961
+ return false
962
+ end
963
+ end
964
+ def get
965
+ @gds && uint2str(length,3)<<@gds
966
+ end
967
+ end # end definition of class GribGDS
968
+ class GribBMS
969
+ include GribUtils
970
+ def initialize(sgm,str=nil)
971
+ @sgm = sgm
972
+ @bms = str
973
+ end
974
+ def exist
975
+ @bms = "\000"*3
976
+ @sgm.is.update_total_length
977
+ end
978
+ def not_exist
979
+ @bms = nil
980
+ @sgm.is.update_total_length
981
+ end
982
+ def length
983
+ if @bms
984
+ return @bms.length+3
985
+ else
986
+ return 0
987
+ end
988
+ end
989
+ def map_number
990
+ nmap = @bms.to_uint2(1)
991
+ nmap = false if nmap==0
992
+ return nmap
993
+ end
994
+ def set_map_number(n)
995
+ @bms[1..2] = uint2str(n,2)
996
+ return n
997
+ end
998
+ alias :map_number= :set_map_number
999
+ def has_map?
1000
+ return nil if @bms.nil?
1001
+ return !map_number
1002
+ end
1003
+ def map
1004
+ return nil unless has_map?
1005
+ return get_bits( @bms[3..-1], 1,1, 0,@bms.to_uint1, NArray::BYTE )
1006
+ end
1007
+ def set_map(mask)
1008
+ map,n = data2str(mask,1,1)
1009
+ @bms[0..0] = uint2str(n,1)
1010
+ @bms = @bms[0,3]<<map
1011
+ @sgm.is.update_total_length
1012
+ return true
1013
+ end
1014
+ def get
1015
+ @bms && uint2str(length,3)<<@bms
1016
+ end
1017
+ end # end definition of class GribBMS
1018
+ class GribBDS
1019
+ include GribUtils
1020
+ private
1021
+ def oct4
1022
+ return @oct4 if @oct4
1023
+ @sgm.file.seek(@pos, IO::SEEK_SET)
1024
+ @oct4 = @sgm.file.read(1).to_uint1
1025
+ return @oct4
1026
+ end
1027
+ def oct14
1028
+ return nil if flag4==0
1029
+ return @oct14 if @oct14
1030
+ @sgm.file.seek(@pos+10, IO::SEEK_SET)
1031
+ @oct14 = @sgm.file.read(1).to_uint1
1032
+ return @oct14
1033
+ end
1034
+ def flag1
1035
+ return (oct4>>7)&1
1036
+ end
1037
+ def flag2
1038
+ return (oct4>>6)&1
1039
+ end
1040
+ def flag3
1041
+ return (oct4>>5)&1
1042
+ end
1043
+ def flag4
1044
+ return (oct4>>4)&1
1045
+ end
1046
+ def flag6
1047
+ return oct14 && (oct14>>6)&1
1048
+ end
1049
+ def flag7
1050
+ return oct14 && (oct14>>5)&1
1051
+ end
1052
+ def flag8
1053
+ return oct14 && (oct14>>4)&1
1054
+ end
1055
+ def initialize(sgm,pos=nil,len=nil)
1056
+ @sgm = sgm
1057
+ @pos = pos
1058
+ if @pos.nil?
1059
+ @bds = "\000"*8
1060
+ @oct4 = 0
1061
+ @oct14 = 0
1062
+ else
1063
+ @length = len
1064
+ end
1065
+ end
1066
+ def get_value(file,pos,sb,eb,nbits,nstep)
1067
+ sbu = (sb&7)/nstep
1068
+ sb = sb/8
1069
+ ebu = eb&7
1070
+ ebu = (8-(eb&7))/nstep unless ebu==0
1071
+ eb = (eb+7)/8
1072
+ return NArray.sfloat(0) if eb==sb
1073
+ file.seek(pos+sb,IO::SEEK_SET)
1074
+ str = file.read(eb-sb)
1075
+ return get_bits(str,nstep,nbits,sbu,ebu,NArray::SFLOAT)
1076
+ end
1077
+
1078
+ public
1079
+ def length
1080
+ if @pos
1081
+ return @length
1082
+ else
1083
+ return @bds.length+3
1084
+ end
1085
+ end
1086
+ def grid?
1087
+ return flag1==0
1088
+ end
1089
+ def set_grid(l)
1090
+ @oct4 = oct4&0x7f
1091
+ @oct4 += 128 unless l
1092
+ @bds[0,1] = uint2str(@oct4,1)
1093
+ return l
1094
+ end
1095
+ def spectrum?
1096
+ return flag1==1
1097
+ end
1098
+ def set_spectrum(l)
1099
+ @oct4 = oct4&0x7f
1100
+ @oct4 += 128 if l
1101
+ @bds[0,1] = uint2str(@oct4,1)
1102
+ return l
1103
+ end
1104
+ def simple?
1105
+ return flag2==0
1106
+ end
1107
+ def set_simple(l)
1108
+ @oct4 = oct4&0xbf
1109
+ @oct4 += 64 unless l
1110
+ @bds[0,1] = uint2str(@oct4,1)
1111
+ return l
1112
+ end
1113
+ def complex?
1114
+ return flag2==1
1115
+ end
1116
+ def set_complex(l)
1117
+ @oct4 = oct4&0xbf
1118
+ @oct4 += 64 if l
1119
+ @bds[0,1] = uint2str(@oct4,1)
1120
+ return l
1121
+ end
1122
+ def float?
1123
+ return flag3==0
1124
+ end
1125
+ def set_float(l)
1126
+ @oct4 = oct4&0xdf
1127
+ @oct4 += 32 unless l
1128
+ @bds[0,1] = uint2str(@oct4,1)
1129
+ return l
1130
+ end
1131
+ def integer?
1132
+ return flag3==1
1133
+ end
1134
+ def set_integer(l)
1135
+ @oct4 = oct4&0xdf
1136
+ @oct4 += 32 if l
1137
+ @bds[0,1] = uint2str(@oct4,1)
1138
+ return l
1139
+ end
1140
+ def single?
1141
+ return flag6 && flag6==0
1142
+ end
1143
+ def set_single(l)
1144
+ @oct14 = oct14&0x7f
1145
+ @oct14 += 128 unless l
1146
+ @oct4 = (oct4&0xef)+16
1147
+ @bds[0,1] = uint2str(@oct4,1)
1148
+ @bds[10,1] = uint2str(@oct14,1)
1149
+ return l
1150
+ end
1151
+ def matrix?
1152
+ return flag6 && flag6==1
1153
+ end
1154
+ def set_matrix(l)
1155
+ @oct14 = oct14&0x7f
1156
+ @oct14 += 128 if l
1157
+ @oct4 = (oct4&0xef)+16
1158
+ @bds[0,1] = uint2str(@oct4,1)
1159
+ @bds[10,1] = uint2str(@oct14,1)
1160
+ return l
1161
+ end
1162
+ def bit_maps?
1163
+ return flag7 && flag7==1
1164
+ end
1165
+ def set_bit_map(l)
1166
+ @oct14 = oct14&0xbf
1167
+ @oct14 += 64 if l
1168
+ @oct4 = (oct4&0xef)+16
1169
+ @bds[0,1] = uint2str(@oct4,1)
1170
+ @bds[10,1] = uint2str(@oct14,1)
1171
+ return l
1172
+ end
1173
+ def constant?
1174
+ return flag8 && flag8==0
1175
+ end
1176
+ def set_constant(l)
1177
+ @oct14 = oct14&0xdf
1178
+ @oct14 += 32 unless l
1179
+ @oct4 = (oct4&0xef)+16
1180
+ @bds[0,1] = uint2str(@oct4,1)
1181
+ @bds[10,1] = uint2str(@oct14,1)
1182
+ return l
1183
+ end
1184
+ def offset
1185
+ return @offset if @offset
1186
+ @sgm.file.seek(@pos+3, IO::SEEK_SET)
1187
+ @offset = float_value(@sgm.file.read(4))
1188
+ return @offset
1189
+ end
1190
+ def efactor
1191
+ return @efactor if @efactor
1192
+ @sgm.file.seek(@pos+1, IO::SEEK_SET)
1193
+ @efactor = 2.0**str2int2( @sgm.file.read(2) )
1194
+ return @efactor
1195
+ end
1196
+ def value(shape,*arg)
1197
+ nbits_unuse = oct4&15
1198
+ @sgm.file.seek(@pos+7, IO::SEEK_SET)
1199
+ nbits_pack = @sgm.file.read(1).to_uint1
1200
+ if (nbits_pack%8) == 0
1201
+ nstep = 8
1202
+ elsif (nbits_pack%4) == 0
1203
+ nstep = 4
1204
+ elsif (nbits_pack%2) == 0
1205
+ nstep = 2
1206
+ else
1207
+ nstep = 1
1208
+ end
1209
+ r = offset
1210
+ e = efactor
1211
+ map = @sgm.bms.map
1212
+ nmiss = map ? map.count_false : 0
1213
+ if flag4==0
1214
+ nlen = ((length-3-8)*8-nbits_unuse)/nbits_pack
1215
+ nlon,nlat = shape
1216
+ (nlon*nlat)==nlen+nmiss || raise("length is not collect")
1217
+ if arg.length!=0
1218
+ index, shape2 = arg
1219
+ index = index.collect{|el| Fixnum===el ? el..el : el}
1220
+ il = index[0]
1221
+ i0 = il.first
1222
+ i1 = il.last
1223
+ i0 = i0 < 0 ? nlon+i0 : i0
1224
+ i1 = i1 < 0 ? nlon+i1 : i1
1225
+ index[0] = il.exclude_end? ? i0...i1 : i0..i1
1226
+ il = index[1]
1227
+ i0 = il.first
1228
+ i1 = il.last
1229
+ i0 = i0 < 0 ? nlat+i0 : i0
1230
+ i1 = i1 < 0 ? nlat+i1 : i1
1231
+ index[1] = il.exclude_end? ? i0...i1 : i0..i1
1232
+ j = nil
1233
+ i = nil
1234
+ if map
1235
+ var = NArrayMiss.sfloat(*shape2)
1236
+ map.reshape!(nlon,nlat)
1237
+ mask = map[*index]
1238
+ nd = mask.count_true
1239
+ var[mask.where] = @sgm.mbio.read2D(@pos+8, nbits_pack, nd, 1, 0, nd-1, 1, 0, 0, 1, nil, nil, e, r).reshape!(nd)
1240
+ =begin
1241
+ index[1].each{|j|
1242
+ jj = j-index[1].first
1243
+ sb = j*nlon+index[0].first
1244
+ sb = sb-map[true,0..jj-1].count_false if jj>0
1245
+ sb = sb*nbits_pack
1246
+ eb = sb+mask[true,j].count_true*nbits_pack
1247
+ if sb!=eb
1248
+ var[mask[true,j].where,jj] = get_value(@sgm.file,@pos+8,sb,eb,nbits_pack,nstep)
1249
+ end
1250
+ }
1251
+ =end
1252
+ else
1253
+ var = @sgm.mbio.read2D(@pos+8, nbits_pack, nlon, nlat, index[0].first, index[0].end, 1, index[1].first, index[1].end, 1, nil, nil, e, r)
1254
+ =begin
1255
+ sb = index[1].first*nlon*nbits_pack
1256
+ eb = (index[1].end+1)*nlon*nbits_pack
1257
+ var = get_value(@sgm.file,@pos+8,sb,eb,nbits_pack,nstep)
1258
+ var.reshape!(nlon, var.length/nlon)
1259
+ var = var[index[0],true]
1260
+ =end
1261
+ end
1262
+ else
1263
+ if map
1264
+ eb = nlen*nbits_pack
1265
+ var = NArrayMiss.sfloat(nlon,nlat)
1266
+ # var[map.where] = get_value(@sgm.file,@pos+8,0,eb,nbits_pack,nstep)
1267
+ nd = map.count_true
1268
+ var[map.where] = @sgm.mbio.read2D(@pos+8, nbits_pack, nd, 1, 0, nd-1, 1, 0, 0, 1, nil, nil, e, r).reshape!(nd)
1269
+ else
1270
+ =begin
1271
+ eb = nlen*nbits_pack
1272
+ var = get_value(@sgm.file,@pos+8,0,eb,nbits_pack,nstep)
1273
+ var.reshape!(nlon,nlat)
1274
+ =end
1275
+ var = @sgm.mbio.read2D(@pos+8, nbits_pack, nlon, nlat, 0, nlon-1, 1, 0, nlat-1, 1, nil, nil, e, r)
1276
+ end
1277
+ end
1278
+ # var = var*e+r
1279
+ return var
1280
+ else
1281
+ raise "not defined yet"
1282
+ n1 = @file.read(2).to_uint2
1283
+ @sgm.file.seek(1, IO::SEEK_CUR)
1284
+ str = @sgm.file.read(6)
1285
+ n2 = str.to_uint2
1286
+ p1 = str.to_uint2(2)
1287
+ p2 = str.to_uint2(4) # @bds[15..16]
1288
+ # width = str2uint( @bds[18..??] )
1289
+ # bitmap = str2uint( @bds[??+1..n1-4] )
1290
+ end
1291
+ end
1292
+ def set_value(val)
1293
+ val = val.reshape!(val.length)
1294
+ if NArrayMiss===val
1295
+ val = val.get_array![val.get_mask!.where]
1296
+ end
1297
+ dfact = @sgm.pds.dfact
1298
+ val = val*10**dfact
1299
+ ref = val.min
1300
+ val = val-ref
1301
+ max = val.max
1302
+ nbits = 16
1303
+ e = (Math::log(max)/Math::log(2)).ceil-nbits
1304
+ val = val*2**(-e)
1305
+ if (nbits%8) == 0
1306
+ nstep = 8
1307
+ elsif (nbits%4) == 0
1308
+ nstep = 4
1309
+ elsif (nbits%2) == 0
1310
+ nstep == 2
1311
+ else
1312
+ nstep == 1
1313
+ end
1314
+ str, bu = data2str(val.to_type(NArray::INT),nstep,nbits)
1315
+ @oct4 = (@oct4&15)+bu*16
1316
+ @bds[0,1] = uint2str(@oct4,1)
1317
+ @bds[1,2] = int2str(e,2)
1318
+ s = (ref<0) ? -1 : 1
1319
+ ref = ref.abs
1320
+ a = (Math::log(ref)/Math::log(16)).ceil+64
1321
+ a<0 && raise("invalid range")
1322
+ a = 127 if a>127
1323
+ b = ref*2**24*16**(64-a)
1324
+ a = a*s
1325
+ @bds[3,4] = int2str(a,1)<<uint2str(b,3)
1326
+ @bds[7,1] = uint2str(nbits,1)
1327
+ @bds = @bds[0,8]<<str
1328
+ @sgm.is.update_total_length
1329
+ end
1330
+ def get
1331
+ uint2str(length,3)<<@bds
1332
+ end
1333
+ end # end definition of class GribBDS
1334
+ class GribES
1335
+ def initialize(sgm,str=nil)
1336
+ @sgm = sgm
1337
+ @es = str || "7777"
1338
+ end
1339
+ def length
1340
+ return 4
1341
+ end
1342
+ def grib?
1343
+ @es=="7777"
1344
+ end
1345
+ def get
1346
+ @es
1347
+ end
1348
+ end # end definition of class GribES
1349
+
1350
+
1351
+ # class Grib
1352
+ def initialize(fname,mode="r")
1353
+ case mode
1354
+ when "r","rb"
1355
+ mode = "rb"
1356
+ when "w","wb"
1357
+ mode = "wb"
1358
+ else
1359
+ raise "Unsupported file mode '#{mode}'. Use 'r' or 'w'."
1360
+ end
1361
+ @file = File.open(fname, mode)
1362
+ @vars = Hash.new
1363
+ @attr = Hash.new
1364
+ end
1365
+
1366
+ public
1367
+ =begin
1368
+ =NumRu::Grib -- a class for Grib datasets
1369
+
1370
+ ==Class Methods
1371
+ ---Grib.new(filename, mode="r")
1372
+ make a new Grib object.
1373
+
1374
+ ARGUMENTS
1375
+ * filename (String): name of the file to open
1376
+ * mode (String): IO mode. "r" (read only) or "w" (write only).
1377
+
1378
+ ---Grib.open(filename)
1379
+ open a Grib file.
1380
+
1381
+ ---Grib.create(filename)
1382
+ create a Grib file.
1383
+
1384
+ ---Grib.is_aGrib?(filename)
1385
+ return true when file is a Grib dataset
1386
+
1387
+ ==Methods
1388
+ ---close
1389
+ ---parse
1390
+ ---path
1391
+ ---var_names
1392
+ ---var( name )
1393
+ ---def_var( name )
1394
+ ---enddef
1395
+ ---write
1396
+ =end
1397
+ class << self
1398
+ def is_a_Grib?(fname)
1399
+ file = nil
1400
+ begin
1401
+ file = File.open(fname,"rb")
1402
+ is = (file.read(4) == "GRIB")
1403
+ ensure
1404
+ file.close if file
1405
+ end
1406
+ return defined?(is) && is
1407
+ end
1408
+ def open(fname)
1409
+ f = Grib.new(fname,"r")
1410
+ mbio = NumRu::MultibitIO.new(fname)
1411
+ f.parse(mbio)
1412
+ return f
1413
+ end
1414
+ def create(fname)
1415
+ Grib.new(fname,"w")
1416
+ end
1417
+ end
1418
+
1419
+ def close
1420
+ @grib_vars = nil
1421
+ @vars = nil
1422
+ @attr = nil
1423
+ @file.close
1424
+ end
1425
+ def parse(mbio)
1426
+ @file.rewind
1427
+ while true
1428
+ @file.read(1)=="\000" && next
1429
+ @file.eof? && break
1430
+ @file.seek(-1, IO::SEEK_CUR)
1431
+ sgm = GribSegment.parse(@file, mbio)
1432
+ return nil unless sgm
1433
+ name = sgm.pds.sname
1434
+ if @vars.has_key?(name)
1435
+ @vars[name].push(sgm)
1436
+ else
1437
+ @vars[name] = [sgm]
1438
+ end
1439
+ end
1440
+ return self
1441
+ end
1442
+ def path
1443
+ @file.path
1444
+ end
1445
+ def var_names
1446
+ @vars.keys
1447
+ end
1448
+ def var(name)
1449
+ var = @vars[name]
1450
+ return nil if var.nil?
1451
+ return GribVar.parse(self,var,name)
1452
+ end
1453
+ def def_var(name)
1454
+ until @file.stat.writable?
1455
+ raise("File #{@file.path} is not writable.")
1456
+ end
1457
+ if !String===name
1458
+ raise "def_var(String)"
1459
+ end
1460
+ raise "#{name} is already defined" if @vars.has_key?(name)
1461
+ var = GribVar.new(@file,name)
1462
+ @vars[name] = var
1463
+ return var
1464
+ end
1465
+ def att_names
1466
+ @attr.keys
1467
+ end
1468
+ def att(name)
1469
+ @attr[name]
1470
+ end
1471
+ def write
1472
+ iz=0
1473
+ it=0
1474
+ izmax = 0
1475
+ vn = var_names
1476
+ @file.rewind
1477
+ while (vn.length>0)
1478
+ vn.dup.each{|name|
1479
+ var = @vars[name]
1480
+ sgm = nil
1481
+ if var.rank==2
1482
+ sgm = GribSegment.create(@file)
1483
+ val = [var.get,var.att("long_name"),var.att("units")]
1484
+ z = var.att("level")
1485
+ t = var.att("time")
1486
+ vn.delete(name)
1487
+ elsif var.rank==4
1488
+ sha = var.shape
1489
+ izmax < sha[2] && izmax = sha[2]
1490
+ if iz<sha[2]&&it<sha[3]
1491
+ sgm = GribSegment.create(@file)
1492
+ val = [var[true,true,iz,it],var.att("long_name"),var.att("units")]
1493
+ zd = var.dim(2)
1494
+ zv = zd.get
1495
+ if Array===zv
1496
+ zv = zv.collect{|a| a["value"][iz] }
1497
+ else
1498
+ zv = [zv[iz]]
1499
+ end
1500
+ z = [zd.att("long_name"), zv]
1501
+ t = var.dim(3)[it]
1502
+ elsif it==sha[3]
1503
+ vn.delete(name)
1504
+ end
1505
+ elsif !var.dim_names.include?("time")
1506
+ sha = var.shape
1507
+ izmax < sha[2] && izmax = sha[2]
1508
+ if iz<sha[2]
1509
+ sgm = GribSegment.create(@file)
1510
+ val = [var[true,true,iz],var.att("long_name"),var.att("units")]
1511
+ zd = var.dim(2)
1512
+ zv = zd.get
1513
+ if Array===zv
1514
+ zv = zv.collect{|a| a["value"][iz] }
1515
+ else
1516
+ zv = [zv[iz]]
1517
+ end
1518
+ z = [zd.att("long_name"), zv]
1519
+ t = var.att("time")
1520
+ end
1521
+ vn.delete(name) if iz==sha[2]-1
1522
+ else
1523
+ sha = var.shape
1524
+ if it<sha[2]
1525
+ sgm = GribSegment.create(@file)
1526
+ val = [var[true,true,it],var.att("long_name"),var.att("units")]
1527
+ z = var.att("level")
1528
+ t = var.dim(2)[it]
1529
+ else
1530
+ vn.delete(name)
1531
+ end
1532
+ end
1533
+ if sgm
1534
+ sgm.set_xy(var.dim(0),var.dim(1))
1535
+ sgm.set_level(z)
1536
+ sgm.set_time(t)
1537
+ sgm.set_var(*val)
1538
+ sgm.write
1539
+ end
1540
+ if iz==izmax-1
1541
+ iz = 0
1542
+ it += 1
1543
+ else
1544
+ iz += 1
1545
+ end
1546
+ }
1547
+ end
1548
+ end
1549
+ def inspect
1550
+ "Grib: #{path}"
1551
+ end
1552
+ end # end of definition of class Grib
1553
+
1554
+ =begin
1555
+ =NumRu::GribDim
1556
+
1557
+ ==Class Methods
1558
+ ---new( vat, name, length )
1559
+
1560
+ ==Methods
1561
+ ---var
1562
+ ---length
1563
+ ---name
1564
+ ---typecode
1565
+ ---get
1566
+ ---[](indices)
1567
+ ---put_att(key,val)
1568
+ ---set_att(key,val)
1569
+ ---att(key)
1570
+ ---att_names
1571
+ ---inspect
1572
+
1573
+ =end
1574
+ class GribDim
1575
+ def initialize(var,name)
1576
+ @var = var
1577
+ @name = name
1578
+ @attr = Hash.new
1579
+ end
1580
+ def var
1581
+ @var
1582
+ end
1583
+ def length
1584
+ @length
1585
+ end
1586
+ alias :total :length
1587
+ def name
1588
+ @name
1589
+ end
1590
+ def get
1591
+ @ary
1592
+ end
1593
+ def typecode
1594
+ if NArray===@ary
1595
+ @ary.typecode
1596
+ elsif Array===@ary
1597
+ @ary[0]["value"].typecode
1598
+ end
1599
+ end
1600
+ def val
1601
+ if Array===@ary
1602
+ if att("long_name")=="Hybrid level"
1603
+ return @ary[0]["value"]
1604
+ else
1605
+ return @ary[1]["value"]
1606
+ end
1607
+ else
1608
+ return @ary
1609
+ end
1610
+ end
1611
+ def [](*ind)
1612
+ return val[*ind]
1613
+ end
1614
+ def put(ary)
1615
+ @ary = ary
1616
+ @length = val.length
1617
+ return @ary
1618
+ end
1619
+ def put_att(key,val)
1620
+ @attr[key]=val
1621
+ end
1622
+ alias :set_att :put_att
1623
+ def att(key)
1624
+ @attr[key]
1625
+ end
1626
+ def att_names
1627
+ @attr.keys
1628
+ end
1629
+ def inspect
1630
+ "GribDim: #{name}"
1631
+ end
1632
+ end
1633
+
1634
+ =begin
1635
+ =NumRu::GribVar
1636
+
1637
+ ==Class Methods
1638
+ ---new( file, name, obj, dims )
1639
+
1640
+ ==Methods
1641
+ ---file
1642
+ ---name
1643
+ ---rank
1644
+ ---total
1645
+ ---set_var
1646
+ ---set_miss
1647
+ ---dim_names
1648
+ ---dim( index )
1649
+ ---ndims
1650
+ ---def_dim(name,index)
1651
+ ---put_att( key, value )
1652
+ ---set_att( key, value )
1653
+ ---att( key )
1654
+ ---att_names
1655
+ ---shape
1656
+ ---typecode
1657
+ ---get( indics )
1658
+ ---[]( indics )
1659
+ ---inspect
1660
+
1661
+ =end
1662
+ class GribVar
1663
+ include GribUtils
1664
+ class << self
1665
+ include GribUtils
1666
+ private
1667
+ def vars_same?(var1,var2)
1668
+ pds1 = var1.pds
1669
+ pds2 = var2.pds
1670
+ if pds1.center!=pds2.center
1671
+ warn("center is not same: #{pds1.center} != #{pds2.center}")
1672
+ return false
1673
+ end
1674
+ if pds1.gid!=pds2.gid
1675
+ warn("gid is not same: #{pds1.gid} != #{pds2.gid}")
1676
+ return false
1677
+ end
1678
+ if pds1.unit!=pds2.unit
1679
+ warn("unit is not same: #{pds1.unit} != #{pds2.unit}")
1680
+ return false
1681
+ end
1682
+ zt1 = pds1.z_type
1683
+ zt2 = pds2.z_type
1684
+ if zt1 != zt2
1685
+ if zt1.nil? || zt2.nil?
1686
+ warn("z type is not same: #{zt1 ? zt1 : "nil"} != #{zt2 ? zt2 : "nil"}")
1687
+ else
1688
+ warn("z type is not same: #{zt1} != #{zt2}")
1689
+ return false
1690
+ end
1691
+ end
1692
+ =begin
1693
+ if pds1.time_range!=pds2.time_range
1694
+ warn("time range is not same: #{pds1.time_range} != #{pds2.time_range}")
1695
+ return true
1696
+ # return false
1697
+ end
1698
+ =end
1699
+ if pds1.sub_center!=pds2.sub_center
1700
+ warn("sub center is not same: #{pds1.sub_center} != #{pds2.sub_center}")
1701
+ return false
1702
+ end
1703
+ if var1.gds!=var2.gds
1704
+ warn("gds is not same")
1705
+ return false
1706
+ end
1707
+ return true
1708
+ end
1709
+
1710
+ public
1711
+ def parse(file,sgms,name)
1712
+ miss = false
1713
+ sgms.each{|sgm|
1714
+ pds = sgm.pds
1715
+ if !vars_same?(sgms[0],sgm)
1716
+ raise "coordinate is not same"
1717
+ end
1718
+ miss = miss | pds.bms?
1719
+ }
1720
+ pds = sgms[0].pds
1721
+ gds = sgms[0].gds
1722
+ va = GribVar.new(file,name)
1723
+ va.set_sgms(sgms)
1724
+ va.put_att("long_name",pds.name)
1725
+ std_name = pds.standard_name
1726
+ va.put_att("standard_name",std_name) if std_name
1727
+ va.put_att("units",pds.unit) if pds.unit
1728
+ va.set_miss(miss)
1729
+ vdim = Array.new
1730
+ x,y = gds.grid
1731
+ x_sname = x["short_name"]
1732
+ d = va.def_dim(x_sname,x["ij"])
1733
+ d.put(x["value"])
1734
+ x.each{|k,v|
1735
+ if k!="value"&&k!="ij"&&k!="length"
1736
+ d.put_att(k,v)
1737
+ end
1738
+ }
1739
+ y_sname = y["short_name"]
1740
+ d = va.def_dim(y_sname,y["ij"])
1741
+ d.put(y["value"])
1742
+ y.each{|k,v|
1743
+ if k!="value"&&k!="ij"&&k!="length"
1744
+ d.put_att(k,v)
1745
+ end
1746
+ }
1747
+ if sgms.length>=1
1748
+ nz = pds.z_value.length
1749
+ if nz!=0
1750
+ z = Array.new(nz).collect{Array.new}
1751
+ n=nil
1752
+ m=nil
1753
+ sgms.each{|sgm|
1754
+ zv = sgm.pds.z_value
1755
+ nz.times{|m|
1756
+ if zv[m]
1757
+ z[m].push( zv[m]["value"] )
1758
+ else
1759
+ z[m].push(m)
1760
+ end
1761
+ }
1762
+ }
1763
+ nz.times{|m|
1764
+ z[m].uniq!
1765
+ z[m].length==z[0].length || raise("length is not same")
1766
+ }
1767
+ if z[0].length>1
1768
+ d = va.def_dim(pds.z_sname,2)
1769
+ d.put_att("long_name",pds.z_type)
1770
+ if pds.z_type=="Hybrid level"
1771
+ list_pv = gds.list_pv
1772
+ zval = pds.z_value[0]
1773
+ tmp = Array.new
1774
+ z[0].each{|n|
1775
+ tmp += [n-1,n]
1776
+ }
1777
+ tmp.uniq!
1778
+ tmp.sort!
1779
+ ap = list_pv[0...list_pv.length/2]
1780
+ b = list_pv[list_pv.length/2..-1]
1781
+ z[0] = {"value"=>NArray.to_na(z[0]),"name"=>zval["name"]}
1782
+ z[1] = {"value"=>ap[tmp], "name"=>"ap_half_lev", "long_name"=>"hybrid ap at half levels", "units"=>"Pa"}
1783
+ z[2] = {"value"=>b[tmp], "name"=>"b_half_lev", "long_name"=>"hybrid b at half levels", "units"=>"1"}
1784
+ elsif nz==1
1785
+ zval = pds.z_value[0]
1786
+ z = NArray.to_na(z[0])
1787
+ d.put_att("units",zval["units"])
1788
+ d.put_att("value_type",zval["name"])
1789
+ else
1790
+ nz.times{|mm|
1791
+ m = nz-m-1
1792
+ zval = pds.z_value[m]
1793
+ z[m+1] = {"value"=>NArray.to_na(z[m]),"name"=>zval["name"],"units"=>zval["units"]}
1794
+ }
1795
+ z[0] = {"value"=>NArray.sint(z[0].length).indgen,"name"=>"level number"}
1796
+ end
1797
+ d.put(z)
1798
+ else
1799
+ va.put_att("level", pds.z_type)
1800
+ pds.z_value.each{|zz|
1801
+ va.put_att(zz["name"].gsub(/\s/,"_"), "#{zz["value"]} #{zz["units"]}")
1802
+ }
1803
+ end
1804
+ else
1805
+ va.put_att("level", pds.z_type)
1806
+ end
1807
+ len = sgms.length
1808
+ time = Array.new(len)
1809
+ len.times{|i|
1810
+ time[i] = get_time(sgms[i].pds.date)
1811
+ }
1812
+ # sgms.each{|sgm|
1813
+ # time.push( get_time(sgm.pds.date) )
1814
+ # }
1815
+ time.uniq!
1816
+ if time.length>1
1817
+ time = NArray.to_na(time)
1818
+ d = va.def_dim("time",-1)
1819
+ d.put(time)
1820
+ d.put_att("long_name","time")
1821
+ d.put_att("units","hours since 1900-01-01 00:00:0.0")
1822
+ else
1823
+ date = pds.date
1824
+ va.put_att("time","#{date[0]} #{"%02d"%date[1][0]}:#{"%02d"%date[1][1]}:0.0")
1825
+ end
1826
+ end
1827
+ return va
1828
+ end
1829
+ end # end definition of class methods GribVar
1830
+
1831
+ def initialize(file,name)
1832
+ @file = file
1833
+ @name = name
1834
+ @attr = Hash.new
1835
+ @miss = false
1836
+ @dims = Array.new
1837
+ end
1838
+ def file
1839
+ @file
1840
+ end
1841
+ def name
1842
+ @name
1843
+ end
1844
+ def set_sgms(sgms)
1845
+ @obj = sgms
1846
+ end
1847
+ def set_miss(miss)
1848
+ @miss = miss
1849
+ end
1850
+ def rank
1851
+ dim_names.length
1852
+ end
1853
+ def total
1854
+ total = 1
1855
+ ndims.times{|i|
1856
+ total = total*dim(i).length
1857
+ }
1858
+ total
1859
+ end
1860
+ def dim_names
1861
+ @dims.collect{|d| d.name }
1862
+ end
1863
+ def dim(index)
1864
+ index = dim_names.index(index) if String===index
1865
+ return nil if index.nil?
1866
+ @dims[index]
1867
+ end
1868
+ def ndims
1869
+ @dims.length
1870
+ end
1871
+ def def_dim(name,index)
1872
+ d = GribDim.new(self,name)
1873
+ if index==-1
1874
+ @dims.push(d)
1875
+ else
1876
+ @dims[index] = d
1877
+ end
1878
+ return d
1879
+ end
1880
+ def put_att(key,val)
1881
+ @attr[key]=val
1882
+ end
1883
+ alias :set_att :put_att
1884
+ def att(key)
1885
+ @attr[key]
1886
+ end
1887
+ def att_names
1888
+ @attr.keys
1889
+ end
1890
+ def shape
1891
+ @dims.collect{|d| d.length }
1892
+ end
1893
+ def typecode
1894
+ if @obj.nil?
1895
+ nil
1896
+ elsif Array===@obj
1897
+ NArray::SFLOAT
1898
+ else
1899
+ @obj.typecode
1900
+ end
1901
+ end
1902
+ def get(*indices)
1903
+ if @obj.nil?
1904
+ return nil
1905
+ elsif NArray===@obj||NArrayMiss===@obj
1906
+ return @obj[*indices]
1907
+ else
1908
+ sha = shape
1909
+ if indices.length!=0
1910
+ if indices[0] == false
1911
+ indices[0] = [true]*(sha.length-indices.length+1)
1912
+ elsif indices[-1] == false
1913
+ indices[-1] = [true]*(sha.length-indices.length+1)
1914
+ elsif indices.include?(false)
1915
+ raise "invalid indices"
1916
+ elsif sha.length!=indices.length
1917
+ raise "invalid indices"
1918
+ end
1919
+ sha.length.times{|n|
1920
+ ind = indices[n]
1921
+ if ind==true
1922
+ indices[n] = 0..sha[n]-1
1923
+ next
1924
+ elsif Fixnum===ind
1925
+ sha[n] = 1
1926
+ next
1927
+ elsif Range===ind
1928
+ f = ind.first
1929
+ e = ind.end
1930
+ e = sha[n]-1 if e==-1
1931
+ e -= 1 if ind.exclude_end?
1932
+ sha[n] = e-f+1
1933
+ indices[n] = f..e
1934
+ next
1935
+ else
1936
+ raise "invalid indices"
1937
+ end
1938
+ }
1939
+ if rank>2
1940
+ mask = NArray.byte(*shape[2..-1])
1941
+ mask[*indices[2..-1]]= 1
1942
+ first = Array.new(indices.length-2)
1943
+ first.length.times{|i|
1944
+ ind = indices[2+i]
1945
+ if Fixnum===ind
1946
+ first[i] = ind < 0 ? shape[2+i]+ind : ind
1947
+ elsif Range===ind
1948
+ first[i] = ind.first
1949
+ else
1950
+ raise "invalid indices"
1951
+ end
1952
+ }
1953
+ else
1954
+ mask = true
1955
+ end
1956
+ else
1957
+ mask = true
1958
+ end
1959
+ value = @miss ? NArrayMiss.sfloat(*sha) : NArray.sfloat(*sha)
1960
+ if rank==2
1961
+ vz = nil
1962
+ vt = nil
1963
+ index = []
1964
+ elsif rank==4
1965
+ vz = dim(2).val
1966
+ vt = dim(3).val
1967
+ index = Array.new(2)
1968
+ elsif !dim_names.include?("time")
1969
+ vz = dim(2).val
1970
+ vt = nil
1971
+ index = Array.new(1)
1972
+ else
1973
+ vt = dim(2).val
1974
+ vz = nil
1975
+ index = Array.new(1)
1976
+ end
1977
+ @obj.each{|sgm|
1978
+ pds = sgm.pds
1979
+ if vz
1980
+ index[0] = vz.eq(pds.z_value[0]["value"]).where[0]
1981
+ end
1982
+ if vt
1983
+ index[-1] = vt.eq(get_time(pds.date)).where[0]
1984
+ end
1985
+ next if (NArray===mask && mask[*index]==0)
1986
+ bds = sgm.bds
1987
+ if indices.length==0 || (indices[0]==true&&indices[1]==true)
1988
+ val = bds.value(shape[0..1])
1989
+ else
1990
+ val = bds.value(shape[0..1],indices[0..1],sha[0..1])
1991
+ end
1992
+ d = pds.dfact
1993
+ val = val*10.0**(-d)
1994
+ if NArray === mask
1995
+ index.length==first.length || raise("invalide indices")
1996
+ index.length.times{|i|
1997
+ index[i] = index[i]-first[i]
1998
+ }
1999
+ end
2000
+ value[true,true,*index] = val
2001
+ }
2002
+ sha.delete(1)
2003
+ value.reshape!(*sha)
2004
+ return value
2005
+ end
2006
+ end
2007
+ alias :[] :get
2008
+ alias :val :get
2009
+ def put(val)
2010
+ @obj = val
2011
+ end
2012
+ def inspect
2013
+ "GribVar: #{@file.path}?var=#{@name}"
2014
+ end
2015
+ end
2016
+
2017
+ end
2018
+
2019
+
2020
+ #####################################################
2021
+ if $0 == __FILE__
2022
+
2023
+ include NumRu
2024
+
2025
+ if ARGV.length>0
2026
+ infname = ARGV.shift
2027
+ else
2028
+ infname = "../../../testdata/T.jan.grib"
2029
+ end
2030
+
2031
+
2032
+ Grib.is_a_Grib?(infname) || raise("file is not a Grib dataset")
2033
+ p grib = Grib.open(infname)
2034
+
2035
+
2036
+
2037
+ print "\nVars\n"
2038
+ grib.var_names.each{|vn|
2039
+ p v = grib.var(vn)
2040
+ p v.dim_names
2041
+ v.dim_names.each{|dn| p dn; p v.dim(dn).get }
2042
+ p v.shape
2043
+ v.att_names.each{|an| print an, " => ", v.att(an), "\n" }
2044
+ puts "\n"
2045
+ p v.val
2046
+ }
2047
+
2048
+
2049
+ end