gentooboontoo-gphys 0.6.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (401) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +1255 -0
  3. data/README +32 -0
  4. data/bin/gdir_client +9 -0
  5. data/bin/gdir_server +123 -0
  6. data/bin/gpaop +134 -0
  7. data/bin/gpcat +140 -0
  8. data/bin/gpcut +94 -0
  9. data/bin/gpedit +196 -0
  10. data/bin/gplist +67 -0
  11. data/bin/gpmath +114 -0
  12. data/bin/gpmaxmin +127 -0
  13. data/bin/gpprint +57 -0
  14. data/bin/gpvect +657 -0
  15. data/bin/gpview +603 -0
  16. data/bin/grads2nc_with_gphys +56 -0
  17. data/doc/attribute.html +19 -0
  18. data/doc/attributenetcdf.html +15 -0
  19. data/doc/axis.html +368 -0
  20. data/doc/coordmapping.html +111 -0
  21. data/doc/coordtransform.html +36 -0
  22. data/doc/derivative/gphys-derivative.html +80 -0
  23. data/doc/derivative/index.html +21 -0
  24. data/doc/derivative/index.rd +14 -0
  25. data/doc/derivative/math-doc/document/document.css +30 -0
  26. data/doc/derivative/math-doc/document/document.html +57 -0
  27. data/doc/derivative/math-doc/document/images.aux +1 -0
  28. data/doc/derivative/math-doc/document/images.log +385 -0
  29. data/doc/derivative/math-doc/document/images.pl +186 -0
  30. data/doc/derivative/math-doc/document/images.tex +364 -0
  31. data/doc/derivative/math-doc/document/img1.png +0 -0
  32. data/doc/derivative/math-doc/document/img10.png +0 -0
  33. data/doc/derivative/math-doc/document/img11.png +0 -0
  34. data/doc/derivative/math-doc/document/img12.png +0 -0
  35. data/doc/derivative/math-doc/document/img13.png +0 -0
  36. data/doc/derivative/math-doc/document/img14.png +0 -0
  37. data/doc/derivative/math-doc/document/img15.png +0 -0
  38. data/doc/derivative/math-doc/document/img16.png +0 -0
  39. data/doc/derivative/math-doc/document/img17.png +0 -0
  40. data/doc/derivative/math-doc/document/img18.png +0 -0
  41. data/doc/derivative/math-doc/document/img19.png +0 -0
  42. data/doc/derivative/math-doc/document/img2.png +0 -0
  43. data/doc/derivative/math-doc/document/img20.png +0 -0
  44. data/doc/derivative/math-doc/document/img21.png +0 -0
  45. data/doc/derivative/math-doc/document/img22.png +0 -0
  46. data/doc/derivative/math-doc/document/img23.png +0 -0
  47. data/doc/derivative/math-doc/document/img24.png +0 -0
  48. data/doc/derivative/math-doc/document/img25.png +0 -0
  49. data/doc/derivative/math-doc/document/img26.png +0 -0
  50. data/doc/derivative/math-doc/document/img27.png +0 -0
  51. data/doc/derivative/math-doc/document/img28.png +0 -0
  52. data/doc/derivative/math-doc/document/img29.png +0 -0
  53. data/doc/derivative/math-doc/document/img3.png +0 -0
  54. data/doc/derivative/math-doc/document/img30.png +0 -0
  55. data/doc/derivative/math-doc/document/img4.png +0 -0
  56. data/doc/derivative/math-doc/document/img5.png +0 -0
  57. data/doc/derivative/math-doc/document/img6.png +0 -0
  58. data/doc/derivative/math-doc/document/img7.png +0 -0
  59. data/doc/derivative/math-doc/document/img8.png +0 -0
  60. data/doc/derivative/math-doc/document/img9.png +0 -0
  61. data/doc/derivative/math-doc/document/index.html +57 -0
  62. data/doc/derivative/math-doc/document/labels.pl +13 -0
  63. data/doc/derivative/math-doc/document/next.png +0 -0
  64. data/doc/derivative/math-doc/document/next_g.png +0 -0
  65. data/doc/derivative/math-doc/document/node1.html +238 -0
  66. data/doc/derivative/math-doc/document/node2.html +75 -0
  67. data/doc/derivative/math-doc/document/prev.png +0 -0
  68. data/doc/derivative/math-doc/document/prev_g.png +0 -0
  69. data/doc/derivative/math-doc/document/up.png +0 -0
  70. data/doc/derivative/math-doc/document/up_g.png +0 -0
  71. data/doc/derivative/math-doc/document.pdf +0 -0
  72. data/doc/derivative/math-doc/document.tex +158 -0
  73. data/doc/derivative/numru-derivative.html +129 -0
  74. data/doc/ep_flux/ep_flux.html +469 -0
  75. data/doc/ep_flux/ggraph_on_merdional_section.html +71 -0
  76. data/doc/ep_flux/index.html +31 -0
  77. data/doc/ep_flux/index.rd +24 -0
  78. data/doc/ep_flux/math-doc/document/WARNINGS +1 -0
  79. data/doc/ep_flux/math-doc/document/contents.png +0 -0
  80. data/doc/ep_flux/math-doc/document/crossref.png +0 -0
  81. data/doc/ep_flux/math-doc/document/document.css +30 -0
  82. data/doc/ep_flux/math-doc/document/document.html +101 -0
  83. data/doc/ep_flux/math-doc/document/images.aux +1 -0
  84. data/doc/ep_flux/math-doc/document/images.log +1375 -0
  85. data/doc/ep_flux/math-doc/document/images.pl +1328 -0
  86. data/doc/ep_flux/math-doc/document/images.tex +1471 -0
  87. data/doc/ep_flux/math-doc/document/img1.png +0 -0
  88. data/doc/ep_flux/math-doc/document/img10.png +0 -0
  89. data/doc/ep_flux/math-doc/document/img100.png +0 -0
  90. data/doc/ep_flux/math-doc/document/img101.png +0 -0
  91. data/doc/ep_flux/math-doc/document/img102.png +0 -0
  92. data/doc/ep_flux/math-doc/document/img103.png +0 -0
  93. data/doc/ep_flux/math-doc/document/img104.png +0 -0
  94. data/doc/ep_flux/math-doc/document/img105.png +0 -0
  95. data/doc/ep_flux/math-doc/document/img106.png +0 -0
  96. data/doc/ep_flux/math-doc/document/img107.png +0 -0
  97. data/doc/ep_flux/math-doc/document/img108.png +0 -0
  98. data/doc/ep_flux/math-doc/document/img109.png +0 -0
  99. data/doc/ep_flux/math-doc/document/img11.png +0 -0
  100. data/doc/ep_flux/math-doc/document/img110.png +0 -0
  101. data/doc/ep_flux/math-doc/document/img111.png +0 -0
  102. data/doc/ep_flux/math-doc/document/img112.png +0 -0
  103. data/doc/ep_flux/math-doc/document/img113.png +0 -0
  104. data/doc/ep_flux/math-doc/document/img114.png +0 -0
  105. data/doc/ep_flux/math-doc/document/img115.png +0 -0
  106. data/doc/ep_flux/math-doc/document/img116.png +0 -0
  107. data/doc/ep_flux/math-doc/document/img117.png +0 -0
  108. data/doc/ep_flux/math-doc/document/img118.png +0 -0
  109. data/doc/ep_flux/math-doc/document/img119.png +0 -0
  110. data/doc/ep_flux/math-doc/document/img12.png +0 -0
  111. data/doc/ep_flux/math-doc/document/img120.png +0 -0
  112. data/doc/ep_flux/math-doc/document/img121.png +0 -0
  113. data/doc/ep_flux/math-doc/document/img122.png +0 -0
  114. data/doc/ep_flux/math-doc/document/img123.png +0 -0
  115. data/doc/ep_flux/math-doc/document/img124.png +0 -0
  116. data/doc/ep_flux/math-doc/document/img125.png +0 -0
  117. data/doc/ep_flux/math-doc/document/img126.png +0 -0
  118. data/doc/ep_flux/math-doc/document/img127.png +0 -0
  119. data/doc/ep_flux/math-doc/document/img128.png +0 -0
  120. data/doc/ep_flux/math-doc/document/img129.png +0 -0
  121. data/doc/ep_flux/math-doc/document/img13.png +0 -0
  122. data/doc/ep_flux/math-doc/document/img130.png +0 -0
  123. data/doc/ep_flux/math-doc/document/img131.png +0 -0
  124. data/doc/ep_flux/math-doc/document/img132.png +0 -0
  125. data/doc/ep_flux/math-doc/document/img133.png +0 -0
  126. data/doc/ep_flux/math-doc/document/img134.png +0 -0
  127. data/doc/ep_flux/math-doc/document/img135.png +0 -0
  128. data/doc/ep_flux/math-doc/document/img136.png +0 -0
  129. data/doc/ep_flux/math-doc/document/img137.png +0 -0
  130. data/doc/ep_flux/math-doc/document/img138.png +0 -0
  131. data/doc/ep_flux/math-doc/document/img139.png +0 -0
  132. data/doc/ep_flux/math-doc/document/img14.png +0 -0
  133. data/doc/ep_flux/math-doc/document/img140.png +0 -0
  134. data/doc/ep_flux/math-doc/document/img141.png +0 -0
  135. data/doc/ep_flux/math-doc/document/img142.png +0 -0
  136. data/doc/ep_flux/math-doc/document/img143.png +0 -0
  137. data/doc/ep_flux/math-doc/document/img144.png +0 -0
  138. data/doc/ep_flux/math-doc/document/img145.png +0 -0
  139. data/doc/ep_flux/math-doc/document/img146.png +0 -0
  140. data/doc/ep_flux/math-doc/document/img147.png +0 -0
  141. data/doc/ep_flux/math-doc/document/img148.png +0 -0
  142. data/doc/ep_flux/math-doc/document/img149.png +0 -0
  143. data/doc/ep_flux/math-doc/document/img15.png +0 -0
  144. data/doc/ep_flux/math-doc/document/img150.png +0 -0
  145. data/doc/ep_flux/math-doc/document/img151.png +0 -0
  146. data/doc/ep_flux/math-doc/document/img152.png +0 -0
  147. data/doc/ep_flux/math-doc/document/img153.png +0 -0
  148. data/doc/ep_flux/math-doc/document/img154.png +0 -0
  149. data/doc/ep_flux/math-doc/document/img155.png +0 -0
  150. data/doc/ep_flux/math-doc/document/img156.png +0 -0
  151. data/doc/ep_flux/math-doc/document/img157.png +0 -0
  152. data/doc/ep_flux/math-doc/document/img158.png +0 -0
  153. data/doc/ep_flux/math-doc/document/img159.png +0 -0
  154. data/doc/ep_flux/math-doc/document/img16.png +0 -0
  155. data/doc/ep_flux/math-doc/document/img160.png +0 -0
  156. data/doc/ep_flux/math-doc/document/img161.png +0 -0
  157. data/doc/ep_flux/math-doc/document/img162.png +0 -0
  158. data/doc/ep_flux/math-doc/document/img163.png +0 -0
  159. data/doc/ep_flux/math-doc/document/img164.png +0 -0
  160. data/doc/ep_flux/math-doc/document/img165.png +0 -0
  161. data/doc/ep_flux/math-doc/document/img166.png +0 -0
  162. data/doc/ep_flux/math-doc/document/img167.png +0 -0
  163. data/doc/ep_flux/math-doc/document/img168.png +0 -0
  164. data/doc/ep_flux/math-doc/document/img169.png +0 -0
  165. data/doc/ep_flux/math-doc/document/img17.png +0 -0
  166. data/doc/ep_flux/math-doc/document/img170.png +0 -0
  167. data/doc/ep_flux/math-doc/document/img171.png +0 -0
  168. data/doc/ep_flux/math-doc/document/img172.png +0 -0
  169. data/doc/ep_flux/math-doc/document/img173.png +0 -0
  170. data/doc/ep_flux/math-doc/document/img174.png +0 -0
  171. data/doc/ep_flux/math-doc/document/img175.png +0 -0
  172. data/doc/ep_flux/math-doc/document/img176.png +0 -0
  173. data/doc/ep_flux/math-doc/document/img177.png +0 -0
  174. data/doc/ep_flux/math-doc/document/img178.png +0 -0
  175. data/doc/ep_flux/math-doc/document/img179.png +0 -0
  176. data/doc/ep_flux/math-doc/document/img18.png +0 -0
  177. data/doc/ep_flux/math-doc/document/img180.png +0 -0
  178. data/doc/ep_flux/math-doc/document/img181.png +0 -0
  179. data/doc/ep_flux/math-doc/document/img182.png +0 -0
  180. data/doc/ep_flux/math-doc/document/img183.png +0 -0
  181. data/doc/ep_flux/math-doc/document/img184.png +0 -0
  182. data/doc/ep_flux/math-doc/document/img185.png +0 -0
  183. data/doc/ep_flux/math-doc/document/img186.png +0 -0
  184. data/doc/ep_flux/math-doc/document/img187.png +0 -0
  185. data/doc/ep_flux/math-doc/document/img188.png +0 -0
  186. data/doc/ep_flux/math-doc/document/img189.png +0 -0
  187. data/doc/ep_flux/math-doc/document/img19.png +0 -0
  188. data/doc/ep_flux/math-doc/document/img190.png +0 -0
  189. data/doc/ep_flux/math-doc/document/img191.png +0 -0
  190. data/doc/ep_flux/math-doc/document/img192.png +0 -0
  191. data/doc/ep_flux/math-doc/document/img193.png +0 -0
  192. data/doc/ep_flux/math-doc/document/img194.png +0 -0
  193. data/doc/ep_flux/math-doc/document/img195.png +0 -0
  194. data/doc/ep_flux/math-doc/document/img196.png +0 -0
  195. data/doc/ep_flux/math-doc/document/img197.png +0 -0
  196. data/doc/ep_flux/math-doc/document/img198.png +0 -0
  197. data/doc/ep_flux/math-doc/document/img199.png +0 -0
  198. data/doc/ep_flux/math-doc/document/img2.png +0 -0
  199. data/doc/ep_flux/math-doc/document/img20.png +0 -0
  200. data/doc/ep_flux/math-doc/document/img200.png +0 -0
  201. data/doc/ep_flux/math-doc/document/img21.png +0 -0
  202. data/doc/ep_flux/math-doc/document/img22.png +0 -0
  203. data/doc/ep_flux/math-doc/document/img23.png +0 -0
  204. data/doc/ep_flux/math-doc/document/img24.png +0 -0
  205. data/doc/ep_flux/math-doc/document/img25.png +0 -0
  206. data/doc/ep_flux/math-doc/document/img26.png +0 -0
  207. data/doc/ep_flux/math-doc/document/img27.png +0 -0
  208. data/doc/ep_flux/math-doc/document/img28.png +0 -0
  209. data/doc/ep_flux/math-doc/document/img29.png +0 -0
  210. data/doc/ep_flux/math-doc/document/img3.png +0 -0
  211. data/doc/ep_flux/math-doc/document/img30.png +0 -0
  212. data/doc/ep_flux/math-doc/document/img31.png +0 -0
  213. data/doc/ep_flux/math-doc/document/img32.png +0 -0
  214. data/doc/ep_flux/math-doc/document/img33.png +0 -0
  215. data/doc/ep_flux/math-doc/document/img34.png +0 -0
  216. data/doc/ep_flux/math-doc/document/img35.png +0 -0
  217. data/doc/ep_flux/math-doc/document/img36.png +0 -0
  218. data/doc/ep_flux/math-doc/document/img37.png +0 -0
  219. data/doc/ep_flux/math-doc/document/img38.png +0 -0
  220. data/doc/ep_flux/math-doc/document/img39.png +0 -0
  221. data/doc/ep_flux/math-doc/document/img4.png +0 -0
  222. data/doc/ep_flux/math-doc/document/img40.png +0 -0
  223. data/doc/ep_flux/math-doc/document/img41.png +0 -0
  224. data/doc/ep_flux/math-doc/document/img42.png +0 -0
  225. data/doc/ep_flux/math-doc/document/img43.png +0 -0
  226. data/doc/ep_flux/math-doc/document/img44.png +0 -0
  227. data/doc/ep_flux/math-doc/document/img45.png +0 -0
  228. data/doc/ep_flux/math-doc/document/img46.png +0 -0
  229. data/doc/ep_flux/math-doc/document/img47.png +0 -0
  230. data/doc/ep_flux/math-doc/document/img48.png +0 -0
  231. data/doc/ep_flux/math-doc/document/img49.png +0 -0
  232. data/doc/ep_flux/math-doc/document/img5.png +0 -0
  233. data/doc/ep_flux/math-doc/document/img50.png +0 -0
  234. data/doc/ep_flux/math-doc/document/img51.png +0 -0
  235. data/doc/ep_flux/math-doc/document/img52.png +0 -0
  236. data/doc/ep_flux/math-doc/document/img53.png +0 -0
  237. data/doc/ep_flux/math-doc/document/img54.png +0 -0
  238. data/doc/ep_flux/math-doc/document/img55.png +0 -0
  239. data/doc/ep_flux/math-doc/document/img56.png +0 -0
  240. data/doc/ep_flux/math-doc/document/img57.png +0 -0
  241. data/doc/ep_flux/math-doc/document/img58.png +0 -0
  242. data/doc/ep_flux/math-doc/document/img59.png +0 -0
  243. data/doc/ep_flux/math-doc/document/img6.png +0 -0
  244. data/doc/ep_flux/math-doc/document/img60.png +0 -0
  245. data/doc/ep_flux/math-doc/document/img61.png +0 -0
  246. data/doc/ep_flux/math-doc/document/img62.png +0 -0
  247. data/doc/ep_flux/math-doc/document/img63.png +0 -0
  248. data/doc/ep_flux/math-doc/document/img64.png +0 -0
  249. data/doc/ep_flux/math-doc/document/img65.png +0 -0
  250. data/doc/ep_flux/math-doc/document/img66.png +0 -0
  251. data/doc/ep_flux/math-doc/document/img67.png +0 -0
  252. data/doc/ep_flux/math-doc/document/img68.png +0 -0
  253. data/doc/ep_flux/math-doc/document/img69.png +0 -0
  254. data/doc/ep_flux/math-doc/document/img7.png +0 -0
  255. data/doc/ep_flux/math-doc/document/img70.png +0 -0
  256. data/doc/ep_flux/math-doc/document/img71.png +0 -0
  257. data/doc/ep_flux/math-doc/document/img72.png +0 -0
  258. data/doc/ep_flux/math-doc/document/img73.png +0 -0
  259. data/doc/ep_flux/math-doc/document/img74.png +0 -0
  260. data/doc/ep_flux/math-doc/document/img75.png +0 -0
  261. data/doc/ep_flux/math-doc/document/img76.png +0 -0
  262. data/doc/ep_flux/math-doc/document/img77.png +0 -0
  263. data/doc/ep_flux/math-doc/document/img78.png +0 -0
  264. data/doc/ep_flux/math-doc/document/img79.png +0 -0
  265. data/doc/ep_flux/math-doc/document/img8.png +0 -0
  266. data/doc/ep_flux/math-doc/document/img80.png +0 -0
  267. data/doc/ep_flux/math-doc/document/img81.png +0 -0
  268. data/doc/ep_flux/math-doc/document/img82.png +0 -0
  269. data/doc/ep_flux/math-doc/document/img83.png +0 -0
  270. data/doc/ep_flux/math-doc/document/img84.png +0 -0
  271. data/doc/ep_flux/math-doc/document/img85.png +0 -0
  272. data/doc/ep_flux/math-doc/document/img86.png +0 -0
  273. data/doc/ep_flux/math-doc/document/img87.png +0 -0
  274. data/doc/ep_flux/math-doc/document/img88.png +0 -0
  275. data/doc/ep_flux/math-doc/document/img89.png +0 -0
  276. data/doc/ep_flux/math-doc/document/img9.png +0 -0
  277. data/doc/ep_flux/math-doc/document/img90.png +0 -0
  278. data/doc/ep_flux/math-doc/document/img91.png +0 -0
  279. data/doc/ep_flux/math-doc/document/img92.png +0 -0
  280. data/doc/ep_flux/math-doc/document/img93.png +0 -0
  281. data/doc/ep_flux/math-doc/document/img94.png +0 -0
  282. data/doc/ep_flux/math-doc/document/img95.png +0 -0
  283. data/doc/ep_flux/math-doc/document/img96.png +0 -0
  284. data/doc/ep_flux/math-doc/document/img97.png +0 -0
  285. data/doc/ep_flux/math-doc/document/img98.png +0 -0
  286. data/doc/ep_flux/math-doc/document/img99.png +0 -0
  287. data/doc/ep_flux/math-doc/document/index.html +101 -0
  288. data/doc/ep_flux/math-doc/document/internals.pl +258 -0
  289. data/doc/ep_flux/math-doc/document/labels.pl +265 -0
  290. data/doc/ep_flux/math-doc/document/next.png +0 -0
  291. data/doc/ep_flux/math-doc/document/next_g.png +0 -0
  292. data/doc/ep_flux/math-doc/document/node1.html +104 -0
  293. data/doc/ep_flux/math-doc/document/node10.html +164 -0
  294. data/doc/ep_flux/math-doc/document/node11.html +86 -0
  295. data/doc/ep_flux/math-doc/document/node12.html +166 -0
  296. data/doc/ep_flux/math-doc/document/node13.html +897 -0
  297. data/doc/ep_flux/math-doc/document/node14.html +1065 -0
  298. data/doc/ep_flux/math-doc/document/node15.html +72 -0
  299. data/doc/ep_flux/math-doc/document/node16.html +81 -0
  300. data/doc/ep_flux/math-doc/document/node2.html +82 -0
  301. data/doc/ep_flux/math-doc/document/node3.html +91 -0
  302. data/doc/ep_flux/math-doc/document/node4.html +149 -0
  303. data/doc/ep_flux/math-doc/document/node5.html +330 -0
  304. data/doc/ep_flux/math-doc/document/node6.html +99 -0
  305. data/doc/ep_flux/math-doc/document/node7.html +98 -0
  306. data/doc/ep_flux/math-doc/document/node8.html +83 -0
  307. data/doc/ep_flux/math-doc/document/node9.html +140 -0
  308. data/doc/ep_flux/math-doc/document/prev.png +0 -0
  309. data/doc/ep_flux/math-doc/document/prev_g.png +0 -0
  310. data/doc/ep_flux/math-doc/document/up.png +0 -0
  311. data/doc/ep_flux/math-doc/document/up_g.png +0 -0
  312. data/doc/ep_flux/math-doc/document.pdf +0 -0
  313. data/doc/ep_flux/math-doc/document.tex +2018 -0
  314. data/doc/gdir.html +412 -0
  315. data/doc/gdir_client.html +16 -0
  316. data/doc/gdir_connect_ftp-like.html +61 -0
  317. data/doc/gdir_server.html +33 -0
  318. data/doc/ggraph.html +1332 -0
  319. data/doc/gpcat.html +27 -0
  320. data/doc/gpcut.html +27 -0
  321. data/doc/gphys.html +501 -0
  322. data/doc/gphys_fft.html +183 -0
  323. data/doc/gphys_grads_io.html +69 -0
  324. data/doc/gphys_grib_io.html +82 -0
  325. data/doc/gphys_io.html +96 -0
  326. data/doc/gphys_io_common.html +18 -0
  327. data/doc/gphys_netcdf_io.html +283 -0
  328. data/doc/gplist.html +23 -0
  329. data/doc/gpmath.html +34 -0
  330. data/doc/gpmaxmin.html +30 -0
  331. data/doc/gpprint.html +32 -0
  332. data/doc/gpview.html +187 -0
  333. data/doc/grads2nc_with_gphys.html +23 -0
  334. data/doc/grads_gridded.html +307 -0
  335. data/doc/grib.html +101 -0
  336. data/doc/grid.html +240 -0
  337. data/doc/index.html +125 -0
  338. data/doc/index.rd +121 -0
  339. data/doc/netcdf_convention.html +136 -0
  340. data/doc/unumeric.html +127 -0
  341. data/doc/update +64 -0
  342. data/doc/varray.html +293 -0
  343. data/doc/varraycomposite.html +67 -0
  344. data/lib/numru/dclext_datetime_ax.rb +220 -0
  345. data/lib/numru/derivative.rb +298 -0
  346. data/lib/numru/gdir.rb +1038 -0
  347. data/lib/numru/gdir_connect_ftp-like.rb +149 -0
  348. data/lib/numru/ggraph.rb +4604 -0
  349. data/lib/numru/ggraph_on_merdional_section.rb +178 -0
  350. data/lib/numru/gphys/attribute.rb +130 -0
  351. data/lib/numru/gphys/attributenetcdf.rb +80 -0
  352. data/lib/numru/gphys/axis.rb +958 -0
  353. data/lib/numru/gphys/coordmapping.rb +286 -0
  354. data/lib/numru/gphys/coordtransform.rb +209 -0
  355. data/lib/numru/gphys/derivative.rb +297 -0
  356. data/lib/numru/gphys/ep_flux.rb +868 -0
  357. data/lib/numru/gphys/gpcommon.rb +52 -0
  358. data/lib/numru/gphys/gphys.rb +1121 -0
  359. data/lib/numru/gphys/gphys_fft.rb +538 -0
  360. data/lib/numru/gphys/gphys_grads_io.rb +212 -0
  361. data/lib/numru/gphys/gphys_grib_io.rb +214 -0
  362. data/lib/numru/gphys/gphys_io.rb +363 -0
  363. data/lib/numru/gphys/gphys_io_common.rb +126 -0
  364. data/lib/numru/gphys/gphys_netcdf_io.rb +767 -0
  365. data/lib/numru/gphys/gphys_nusdas_io.rb +78 -0
  366. data/lib/numru/gphys/grads_gridded.rb +1539 -0
  367. data/lib/numru/gphys/grib.rb +2005 -0
  368. data/lib/numru/gphys/grib_params.rb +1270 -0
  369. data/lib/numru/gphys/grid.rb +602 -0
  370. data/lib/numru/gphys/netcdf_convention.rb +366 -0
  371. data/lib/numru/gphys/subsetmapping.rb +332 -0
  372. data/lib/numru/gphys/unumeric.rb +452 -0
  373. data/lib/numru/gphys/varray.rb +1079 -0
  374. data/lib/numru/gphys/varraycomposite.rb +415 -0
  375. data/lib/numru/gphys/varraygrads.rb +225 -0
  376. data/lib/numru/gphys/varraygrib.rb +177 -0
  377. data/lib/numru/gphys/varraynetcdf.rb +348 -0
  378. data/lib/numru/gphys/varraynusdas.rb +59 -0
  379. data/lib/numru/gphys.rb +7 -0
  380. data/lib/numru/htdir.rb +170 -0
  381. data/lib/numru/vizshot.rb +697 -0
  382. data/sample/cira86_to_nc.rb +122 -0
  383. data/sample/druby_cli1.rb +21 -0
  384. data/sample/druby_cli2.rb +34 -0
  385. data/sample/druby_serv1.rb +30 -0
  386. data/sample/druby_serv2.rb +64 -0
  387. data/sample/ep_flux/demo_NCEP_1.rb +48 -0
  388. data/sample/ep_flux/demo_NCEP_2.rb +57 -0
  389. data/sample/ep_flux/demo_NCEP_3.rb +81 -0
  390. data/sample/ggraph_latlon_labelling_dr002690.rb +159 -0
  391. data/sample/ggraph_mapfit-axes_dr002687.rb +131 -0
  392. data/sample/map_projection.rb +121 -0
  393. data/test/test_ep_flux.rb +533 -0
  394. data/testdata/T.jan.ctl +12 -0
  395. data/testdata/T.jan.dat +0 -0
  396. data/testdata/T.jan.grib +0 -0
  397. data/testdata/T.jan.nc +0 -0
  398. data/testdata/T.jan.packed.withmiss.nc +0 -0
  399. data/testdata/UV.jan.nc +0 -0
  400. data/testdata/cira86.dat +1332 -0
  401. metadata +527 -0
@@ -0,0 +1,1539 @@
1
+ =begin
2
+ = NumRu::GrADS_Gridded -- a class for GrADS gridded datasets
3
+
4
+ by T Horinouchi and R Mizuta
5
+
6
+ ==Overview
7
+
8
+ a GrADS_Gridded object corresponds to a GrADS control file,
9
+ through which the users can also access its binary data file(s).
10
+
11
+ ==Current Limitations
12
+
13
+ * option 365_day_calendar is not interpreted
14
+ * Partial support of the "template" option
15
+ (only %y2,%y4,%m1,%m2,%d1,%d2,%h1,%h2,%n2)
16
+ (Time is assumed to be increasing monotonically).
17
+
18
+ ==Class Methods
19
+
20
+ ---GrADS_Gridded.new(ctlfilename, mode="r")
21
+ same as GrADS_Gridded.open
22
+
23
+ ---GrADS_Gridded.open(ctlfilename, mode="r")
24
+ make a new GrADS_Gridded object.
25
+
26
+ ARGUMENTS
27
+ * ctlfilename (String): name of the control file to open
28
+ * mode (String): IO mode. "r" (read only) or "w" (write only).
29
+
30
+ REMARK
31
+ * You can modify the object through instance methods even if mode=="r".
32
+ In that case, the modification will not be written in the original
33
+ control file.
34
+
35
+ ---GrADS_Gridded.create(ctlfilename, noclobber=false, share=false)
36
+ make a new GrADS_Gridded object with creating a new control file
37
+
38
+ REMARK
39
+ * It is used with writing methods, but currently writing methods
40
+ does not work.
41
+
42
+ ==Methods
43
+ ---ndims
44
+ returns the number of dimensions in the file (always 4).
45
+
46
+ ---nvars
47
+ returns the number of variables in the file.
48
+
49
+ ---natts
50
+ returns the number of attributes of the variable.
51
+
52
+ ---path
53
+ returns the path of the control file.
54
+
55
+ ---put_att( attname, value )
56
+ set global attribute
57
+
58
+ ARGUMENTS
59
+ * attrname (String): name of an attribute
60
+ * value (String): value of an attribute
61
+
62
+ ---def_var(name="noname",nlev=0,option="99",description="")
63
+ define a variable
64
+
65
+ ARGUMENTS
66
+ * name (String): name of the variable
67
+ * nlev (Integer): number of vertical levels
68
+ * option (String): variable placement option
69
+ ("99": normal, "-1,30": transpose lon and lat)
70
+
71
+ ---var( varname=nil )
72
+ opens an existing variable in the file.
73
+
74
+ ARGUMENTS
75
+ * varname (String): name of the variable to open
76
+
77
+ RETURN VALUE
78
+ * a GrADSVar object.
79
+
80
+ ---vars( names=nil )
81
+ opens existing variables in the file.
82
+
83
+ ARGUMENTS
84
+ * names (Array): names(String) of the variable to open
85
+
86
+ RETURN VALUE
87
+ * Array of GrADSVar objects.
88
+ returns all variables if names==nil
89
+
90
+ ---get_att( key=nil )
91
+ returns tha value of the global attribute
92
+
93
+ ---dim_names
94
+ returns the names of all dimensions in the control file.
95
+
96
+ ---var_names
97
+ returns the names of all variables in the control file.
98
+
99
+ ---att_names
100
+ returns the names of all the global attributes.
101
+
102
+ ---to_ctl
103
+ returns the contents of the corresponding control file as a String.
104
+
105
+ REMARK
106
+ * The contents is reconstructed from the internal data of the object.
107
+ Therefore, even when the object is based on a read-only control file,
108
+ it is not necessarily the same as the original one. It is especially
109
+ true when the object was modified after it is opened.
110
+
111
+ ---get(name, z, t)
112
+ reads the binary data and returns as a NArray.
113
+
114
+ ARGUMENTS
115
+ * name (String): name of the variable to read
116
+ * z (Integer, currently): vertical level to read (0,1,2,...; starting
117
+ from 0). Currently only one vertical levels must be chosen, but in the
118
+ future, it is planned to support multiple levels.
119
+ * t (Integer, currently): time to read (0,1,2,...; starting
120
+ from 0). Currently only one time must be chosen, but in the
121
+ future, it is planned to support multiple times.
122
+
123
+ ---put(ary)
124
+ writes the NArray on the binary data file.
125
+
126
+ ARGUMENTS
127
+ * ary (NArray): data to write.
128
+
129
+ ---varnames
130
+ Returns names of the variable in the GrADS file as an Array in the order
131
+ placed.
132
+
133
+ ---dimensions
134
+ Returns info on the four dimensions.
135
+
136
+ RETURN VALUE
137
+ * an Array of 4 elements: dimension[0] for x, dimension[1] for y,
138
+ dimension[2] for z, and dimension[3] for t. Each of them is a
139
+ Hash like the following:
140
+ {:name=>"x",
141
+ :len=>132,
142
+ :flag=>"LINEAR",
143
+ :spec=>"-0.7500 1.5000",
144
+ :start=>-0.75, :increment=>1.5,
145
+ :description=>"longitude",
146
+ :units=>"degrees_east"}
147
+ Here, :len, :flag, and :spec are directly from the control file, while
148
+ others are derived properties for internal use.
149
+
150
+ WARNING
151
+ * Each elements of the return value is not a clone but is a direct
152
+ association to an internal object of the object. Therefore, to
153
+ modify it is to modify the object. That is, dimensions[0][:len]=10
154
+ would actually change the internal variable, while dimensions[0]=nil
155
+ has no effect (the former is a substitution IN a Hash, while the latter
156
+ is a substitution OF the Hash).
157
+
158
+ ---get_dim(dim)
159
+ returns positions of a dimension as an NArray.
160
+
161
+ ARGUMENTS
162
+ * dim (String): a dimension name
163
+
164
+ RETURN VALUE
165
+ * an NArray
166
+
167
+
168
+ ---title
169
+ ---title=
170
+ get/set the title
171
+
172
+ ---undef
173
+ ---undef=
174
+ get/set the undef value
175
+
176
+ ---dset
177
+ ---dset=
178
+ get/set the dset string
179
+
180
+
181
+
182
+ = GrADSVar -- a class for a variable of GrADS gridded datasets
183
+
184
+ by R Mizuta
185
+
186
+ ==Overview
187
+
188
+ a GrADSVar object corresponds to one variable in a GrADS control file.
189
+ It is intended to behave as a correspondent of a NetCDFVar object.
190
+
191
+ ==Current Limitations
192
+
193
+ * Only a part of the methods can work.
194
+ * Writing methods are not supported.
195
+
196
+ ==Class Methods
197
+
198
+ ---GrADSVar.new(file, varname)
199
+ make a new GrADSVar object.
200
+
201
+ ARGUMENTS
202
+ * file (GrADS_Gridded or String): a GrADS_Gridded object or
203
+ a name of the control file to open
204
+ * varname (String): name of the variable to open
205
+
206
+
207
+ ==Methods
208
+
209
+ ---shape_ul0
210
+ returns the shape of the variable, but the length of the unlimited
211
+ dimension is set to zero.
212
+
213
+ RETURN VALUE
214
+ * Array. [length of 0th dim, length of 1st dim,.. ]
215
+
216
+ ---shape_current
217
+ returns the current shape of the variable.
218
+
219
+ RETURN VALUE
220
+ * Array. [length of 0th dim, length of 1st dim,.. ]
221
+
222
+ ---dim_names
223
+ returns the names of all dimensions of the variable.
224
+
225
+ ---att_names
226
+ returns the names of all attributes of the variable.
227
+
228
+ ---name
229
+ returns the name of the variable.
230
+
231
+ ---ndims
232
+ returns the number of dimensions in the file (always 4).
233
+
234
+ ---rank
235
+ alias of ndims
236
+
237
+ ---vartype
238
+ returns "sfloat" in order to behave as NetCDFVar#vartype.
239
+
240
+ ---natts
241
+ returns the number of attributes of the variable.
242
+
243
+ ---file
244
+ returns the file name that controls the variable.
245
+
246
+ ---get_att( name=nil )
247
+ returns tha value of the attribute of the variable.
248
+
249
+ ---put_att( name, value )
250
+ set an attribute of the variable.
251
+
252
+ ARGUMENTS
253
+ * name (String): name of an attribute
254
+ * value (String): value of an attribute
255
+
256
+ ---get(hash=nil)
257
+ returns values of the variable.
258
+
259
+ ARGUMENTS
260
+ * hash (Hash) : Optional argument to limit the portion of the
261
+ variable to output values. If omitted, the whole variable is
262
+ subject to the output. This argument accepts a Hash whose keys
263
+ contain either "index" or a combination of "start","end", and
264
+ "stride". The value of "index" points the index of a scalar
265
+ portion of the variable. The other case is used to designate a
266
+ regularly ordered subset, where "start" and "end" specifies
267
+ bounds in each dimension and "stride" specifies intervals in
268
+ it. As in Array "start", "end", and "index" can take negative
269
+ values to specify index backward from the end. However,
270
+ "stride" has to be positive, so reversing the array must be
271
+ done afterwards if you like.
272
+
273
+ RETURN VALUE
274
+ * an NArray object
275
+
276
+ REMARK
277
+ "stride","index" is not supported yet.
278
+
279
+ ---[]
280
+ Same as GrADSVar#get but a subset is specified as in the method []
281
+ of NArray.
282
+
283
+
284
+ =end
285
+
286
+ require "date"
287
+ require "narray_miss"
288
+ require "numru/gphys/attribute"
289
+
290
+ module NumRu
291
+ class GrADS_Gridded
292
+
293
+ class << self
294
+ alias open new
295
+
296
+ def create(ctlfilename,noclobber=false,share=false)
297
+ #if(noclobber)
298
+ # raise "noclobber = true is not supported."
299
+ #end
300
+ if(share)
301
+ raise "share = true is not supported."
302
+ end
303
+ #if (File.exists?(ctlfilename))
304
+ if(noclobber && File.exists?(ctlfilename))
305
+ print "#{ctlfilename} already exists.\n"
306
+ print "overwrite #{ctlfilename} (y/n)? "
307
+ ans = gets[0].chr
308
+ if ans != "y"
309
+ raise "#{ctlfilename} already exists."
310
+ end
311
+ end
312
+
313
+ # GrADS_Gridded.new(ctlfilename, "w+")
314
+ GrADS_Gridded.new(ctlfilename, "w")
315
+ end
316
+ end
317
+
318
+ def initialize(ctlfilename, mode="r")
319
+
320
+ case(mode)
321
+ when /^r/
322
+ @mode = 'rb'
323
+ when /^w/
324
+ @mode = 'wb'
325
+ else
326
+ raise ArgumentError, "Unsupported IO mode: #{mode}"
327
+ end
328
+
329
+ # @ctlfile = File.open(ctlfilename, mode)
330
+ @options = { # initialization
331
+ "yrev"=>nil,
332
+ "zrev"=>nil,
333
+ "sequential"=>nil,
334
+ "byteswapped"=>nil,
335
+ "template"=>nil,
336
+ "big_endian"=>nil,
337
+ "little_endian"=>nil,
338
+ "cray_32bit_ieee"=>nil,
339
+ "365_day_calendar"=>nil,
340
+ }
341
+
342
+ case(@mode)
343
+ when('rb')
344
+ if (File.exists?(ctlfilename))
345
+ @ctlfile = File.open(ctlfilename, mode)
346
+ parse_ctl
347
+ else
348
+ raise "File #{ctlfilename} does not exist."
349
+ end
350
+ when('wb')
351
+ @ctlfile = File.open(ctlfilename, mode)
352
+
353
+ @dimensions = []
354
+ @variables = []
355
+
356
+ #<attributes>
357
+ @dset = nil
358
+ # @title = nil
359
+ @title = ""
360
+ @undef = nil
361
+ @fileheader_len = 0
362
+
363
+ #<internal control parameters>
364
+ @define_mode = true
365
+ @ctl_dumped = false
366
+ else
367
+ raise ArgumentError, "Unsupported IO mode: #{@mode}"
368
+ end
369
+ end
370
+
371
+ def close
372
+ @ctlfile.close
373
+ end
374
+
375
+ def path
376
+ @ctlfile.path
377
+ end
378
+
379
+ def ndims
380
+ 4
381
+ end
382
+
383
+ def nvars
384
+ @variables.length
385
+ end
386
+
387
+ def natts
388
+ 2
389
+ end
390
+
391
+ def put_att(key,value)
392
+ case key
393
+ when "dset"
394
+ @dset = value
395
+ when "title"
396
+ @title = value
397
+ when "undef"
398
+ @undef = value
399
+ else
400
+ if ! (value.is_a?(TrueClass) || value.is_a?(NilClass) )
401
+ raise ArgumentError, "2nd arg: not a true nor nil"
402
+ end
403
+ if (@options.has_key?(key))
404
+ @options[key] = value
405
+ else
406
+ raise "Invalid/unsupported option: "+key
407
+ end
408
+ end
409
+ end
410
+
411
+ def def_var(name="noname",nlev=0,option="99",description="")
412
+ @variables.push({:name=>name.to_s, :nlev=>nlev.to_s,
413
+ :option=>option.to_s, :description=>description.to_s})
414
+ end
415
+
416
+ def var( varname=nil )
417
+ GrADSVar.new(self,varname)
418
+ end
419
+
420
+ def vars( names=nil ) # return all if names==nil
421
+ # if names == nil
422
+ # vars = (0..nvars()-1).collect{ |varid| id2var(varid) }
423
+ # else
424
+ raise TypeError, "names is not an array" if ! names.is_a?(Array)
425
+ vars = names.collect{|name| var(name)}
426
+ raise ArgumentError, "One or more variables do not exist" if vars.include?(nil)
427
+ # end
428
+ vars
429
+ end
430
+
431
+ # def att
432
+ def get_att( key=nil )
433
+ case(key)
434
+ when("dset")
435
+ att = @dset
436
+ when("title")
437
+ att = @title
438
+ when "undef"
439
+ att = @undef
440
+ else
441
+ raise "Invalid/unsupported option: "+key
442
+ end
443
+ att
444
+ end
445
+
446
+ # def fill=
447
+ # def each_dim
448
+ # def each_var
449
+ # def each_att
450
+
451
+ def dim_names
452
+ ary = Array.new()
453
+ @dimensions.each{|dim| ary.push(dim[:name])}
454
+ ary
455
+ end
456
+
457
+ def var_names
458
+ ary = Array.new()
459
+ @variables.each{|dim| ary.push(dim[:name])}
460
+ ary
461
+ end
462
+
463
+ def att_names
464
+ ary = ["dset","title","undef"]
465
+ ary
466
+ end
467
+
468
+ def to_ctl
469
+ if( !@dimensions[3][:spec] )
470
+ start = generate_starttime(@dimensions[3][:startdatetime])
471
+ increment = generate_timeincrement(@dimensions[3][:increment],@dimensions[3][:increment_units])
472
+ @dimensions[3][:spec] = "#{start} #{increment}"
473
+ end
474
+ @title = "<no title>" if @title==""
475
+ @undef = -999.0 if @undef==nil
476
+ return <<EOS
477
+ DSET #{if @dset[0]=="/" then @dset else "^"+@dset end}
478
+ TITLE #{@title}
479
+ UNDEF #{@undef}
480
+ OPTIONS #{op=""; @options.each{|key,val| op += key+" " if(val)}; op}
481
+ XDEF #{@dimensions[0][:len]} #{@dimensions[0][:flag]} #{@dimensions[0][:spec]}
482
+ YDEF #{@dimensions[1][:len]} #{@dimensions[1][:flag]} #{@dimensions[1][:spec]}
483
+ ZDEF #{@dimensions[2][:len]} #{@dimensions[2][:flag]} #{@dimensions[2][:spec]}
484
+ TDEF #{@dimensions[3][:len]} #{@dimensions[3][:flag]} #{@dimensions[3][:spec]}
485
+ VARS #{nvars}
486
+ #{@variables.collect{|i| i[:name]+" "+i[:nlev].to_s+" "+i[:option].to_s+
487
+ " "+i[:description]}.join("\n")}
488
+ ENDVARS
489
+ EOS
490
+ end
491
+
492
+ def inspect
493
+ return <<EOS
494
+ #{self.class}
495
+ file: #{@ctlfile.path}
496
+ DSET #{@dset}
497
+ OPTIONS #{@options.inspect}
498
+ XDIM #{@dimensions[0].inspect}
499
+ YDIM #{@dimensions[1].inspect}
500
+ ZDIM #{@dimensions[2].inspect}
501
+ TDIM #{@dimensions[3].inspect}
502
+ VARS
503
+ #{@variables.collect{|i| " "+i[:name]+"\t"+i[:nlev].to_s+"\t"+i[:option].to_s+
504
+ "\t"+i[:description]}.join("\n")}
505
+ ENDVARS
506
+ EOS
507
+ end
508
+
509
+ def put(ary)
510
+
511
+ if( ary.class == NArrayMiss )
512
+ raise "UNDEF is not specified" if @undef == nil
513
+ ary = ary.to_na(@undef)
514
+ end
515
+
516
+ ary = convert_endian_write(ary)
517
+
518
+ raise "DSET is not specified" if @dset == nil
519
+
520
+ putfile = File.open(@dset,"wb")
521
+ putfile << ary.to_s
522
+ putfile.close
523
+
524
+ end
525
+
526
+ def get(name, z, t, lonlat=nil)
527
+
528
+ # t: [0,1,2,..] : record number
529
+ # time: [0,1/24,2/24,...] days since 00:00Z01jan2000 : Numeric with units
530
+ # date: [00:00Z01jan2000,01:00Z01jan2000,...] : DateTime class
531
+
532
+ if ( @options["template"] )
533
+
534
+ ary_time = get_dim(@dimensions[3])
535
+ start_date = @dimensions[3][:startdatetime]
536
+
537
+ case dimensions[3][:increment_units]
538
+ when 'years'
539
+ target_date = start_date >> (ary_time[t]*12)
540
+ when 'months'
541
+ target_date = start_date >> ary_time[t]
542
+ when 'days'
543
+ target_date = start_date + ary_time[t]
544
+ when 'hours'
545
+ target_date = start_date + Rational((ary_time[t]*60).to_i,24*60)
546
+ when 'minutes'
547
+ target_date = start_date + Rational(ary_time[t].to_i,24*60)
548
+ end
549
+
550
+ # substitute DSET by the target file name
551
+ # and determine first record in the target file (="init_xxxx")
552
+
553
+ init_year = start_date.year
554
+ init_month = start_date.month
555
+ init_day = start_date.day
556
+ init_hour = start_date.hour
557
+ init_min = start_date.min
558
+
559
+ @dset_r = @dset.dup
560
+ if ( @dset_r =~ /%y[24]/ )
561
+ init_year = target_date.year
562
+ init_month = 1 if !( @dset_r =~ /%m[12]/ )
563
+ init_day = 1 if !( @dset_r =~ /%d[12]/ )
564
+ init_hour = 0 if !( @dset_r =~ /%h[12]/ )
565
+ init_min = 0 if !( @dset_r =~ /%n2/ )
566
+ @dset_r.gsub!( /%y2/, sprintf("%02d",init_year%100) )
567
+ @dset_r.gsub!( /%y4/, sprintf("%04d",init_year) )
568
+ end
569
+ if ( @dset_r =~ /%m[12]/ )
570
+ init_month = target_date.month
571
+ init_day = 1 if !( @dset_r =~ /%d[12]/ )
572
+ init_hour = 0 if !( @dset_r =~ /%h[12]/ )
573
+ init_min = 0 if !( @dset_r =~ /%n2/ )
574
+ @dset_r.gsub!( /%m1/, sprintf("%d",init_month) )
575
+ @dset_r.gsub!( /%m2/, sprintf("%02d",init_month) )
576
+ end
577
+ if ( @dset_r =~ /%d[12]/ )
578
+ init_day = target_date.day
579
+ init_hour = 0 if !( @dset_r =~ /%h[12]/ )
580
+ init_min = 0 if !( @dset_r =~ /%n2/ )
581
+ @dset_r.gsub!( /%d1/, sprintf("%d",init_day) )
582
+ @dset_r.gsub!( /%d2/, sprintf("%02d",init_day) )
583
+ end
584
+ if ( @dset_r =~ /%h[12]/ )
585
+ init_hour = target_date.hour
586
+ init_min = 0 if !( @dset_r =~ /%n2/ )
587
+ @dset_r.gsub!( /%h1/, sprintf("%d",init_hour) )
588
+ @dset_r.gsub!( /%h2/, sprintf("%02d",init_hour) )
589
+ end
590
+ if ( @dset_r =~ /%n2/ )
591
+ init_min = target_date.min
592
+ @dset_r.gsub!( /%n2/, sprintf("%02d",init_min) )
593
+ end
594
+
595
+ init_date = DateTime.new(init_year,init_month,init_day,init_hour,init_min)
596
+ init_t = 0
597
+
598
+ ary_time[0..t].to_a.each_with_index{ |time, idx|
599
+
600
+ case dimensions[3][:increment_units]
601
+ when 'years'
602
+ before_target_file = ((start_date >> (time*12)) < init_date)
603
+ when 'months'
604
+ before_target_file = ((start_date >> time) < init_date)
605
+ when 'days'
606
+ before_target_file = ((start_date + time) < init_date)
607
+ when 'hours'
608
+ before_target_file = ((start_date + Rational((time*60).to_i,24*60)) < init_date)
609
+ when 'minutes'
610
+ before_target_file = ((start_date + Rational(time.to_i,24*60)) < init_date)
611
+ end
612
+ init_t = idx + 1 if before_target_file
613
+ }
614
+
615
+ t_in_target_file = t - init_t
616
+
617
+ start_byte = start_byte(name, z, t_in_target_file)
618
+ @datafile = File.open(@dset_r,"rb")
619
+ else
620
+ start_byte = start_byte(name, z, t)
621
+ @datafile = File.open(@dset,"rb")
622
+ end
623
+
624
+ @x_len = @dimensions[0][:len]
625
+ @y_len = @dimensions[1][:len]
626
+
627
+ if(lonlat)
628
+ if !(lonlat.is_a?(Array) || lonlat.is_a?(NArray))
629
+ raise "lonlat must be given Array or NArray"
630
+ end
631
+ lon_str = lonlat[0]
632
+ lon_end = lonlat[1]
633
+ lat_str = lonlat[2]
634
+ lat_end = lonlat[3]
635
+
636
+ if( @map[name][:xytranspose] )
637
+ @datafile.pos = start_byte + @y_len*lon_str*@map[name][:byte]
638
+ readdata = @datafile.read(@y_len*(lon_end-lon_str+1)*@map[name][:byte])
639
+
640
+ if( readdata == nil )
641
+ raise "File Read Error: #{@datafile.path}, " +
642
+ "#{@x_len*(lat_end-lat_str+1)*@map[name][:byte]} bytes " +
643
+ "at #{@datafile.pos} bytes\n" +
644
+ "specified by #{@ctlfile.path}, #{name} ( z=#{z}, t=#{t} ) (Perhaps there is a mismatch between the control and data files)"
645
+ end
646
+
647
+ ary = NArray.to_na(readdata, @map[name][:type], @y_len, lon_end-lon_str+1)
648
+
649
+ ary = convert_endian_read(ary)
650
+ ary = ary[lat_str..lat_end,true].transpose
651
+ else
652
+ @datafile.pos = start_byte + @x_len*lat_str*@map[name][:byte]
653
+ readdata = @datafile.read(@x_len*(lat_end-lat_str+1)*@map[name][:byte])
654
+
655
+ if( readdata == nil )
656
+ raise "File Read Error: #{@datafile.path}, " +
657
+ "#{@x_len*(lat_end-lat_str+1)*@map[name][:byte]} bytes " +
658
+ "at #{@datafile.pos} bytes\n" +
659
+ "specified by #{@ctlfile.path}, #{name} ( z=#{z}, t=#{t} ) (Perhaps there is a mismatch between the control and data files)"
660
+ end
661
+
662
+ ary = NArray.to_na(readdata, @map[name][:type], @x_len, lat_end-lat_str+1)
663
+
664
+ ary = convert_endian_read(ary)
665
+ ary = ary[lon_str..lon_end,true]
666
+ end
667
+ else
668
+ @datafile.pos = start_byte
669
+ readdata = @datafile.read(@x_len*@y_len*@map[name][:byte])
670
+
671
+ if( readdata == nil )
672
+ raise "File Read Error: #{@datafile.path}, " +
673
+ "#{@x_len*(lat_end-lat_str+1)*@map[name][:byte]} bytes " +
674
+ "at #{@datafile.pos} bytes\n" +
675
+ "specified by #{@ctlfile.path}, #{name} ( z=#{z}, t=#{t} ) (Perhaps there is a mismatch between the control and data files)"
676
+ end
677
+
678
+ ary = NArray.to_na(readdata, @map[name][:type], @dimensions[0][:len],@dimensions[1][:len])
679
+
680
+ ary = convert_endian_read(ary)
681
+ ary = ary.transpose if ( @map[name][:xytranspose] )
682
+ end
683
+
684
+ @datafile.close
685
+ ary
686
+ end
687
+
688
+ attr_accessor(:title, :undef, :dset, :dimensions, :variables)
689
+ attr_reader(:ctlfile)
690
+
691
+ def get_dim(dim)
692
+ name = dim[:name]
693
+ if (dim[:levels])
694
+ var_dim = NArray.to_na(dim[:levels])
695
+ elsif (dim[:start] && dim[:increment] && dim[:len])
696
+ var_dim = NArray.float(dim[:len]).indgen!*dim[:increment]+dim[:start]
697
+ else
698
+ raise "cannot define dimension "+name
699
+ end
700
+ var_dim = var_dim[-1..0] if (name == 'y' && @options["yrev"])
701
+ var_dim = var_dim[-1..0] if (name == 'z' && @options["zrev"])
702
+ return var_dim
703
+ end
704
+
705
+ def varnames
706
+ @variables.collect{|i| i[:name]}
707
+ end
708
+
709
+ def get_alldim
710
+ ax = Hash.new
711
+ @dimensions.each{|dim|
712
+ name = dim[:name]
713
+ ax[name] = get_dim(dim)
714
+ }
715
+ return ax
716
+ end
717
+
718
+ def ctlfilename # obsolete
719
+ @ctlfile.path
720
+ end
721
+
722
+ ########## private methods #############
723
+ private
724
+
725
+ def parse_ctl
726
+ @ctlfile.rewind
727
+ @fileheader_len = 0 # defalut value
728
+ @title = ""
729
+ @variables = [] # initalization
730
+ @dimensions = [] # initalization
731
+ while ( line = @ctlfile.gets )
732
+ case(line)
733
+ when /^\s*\*/,/^\s*$/
734
+ # do nothing
735
+ when /^\s*DSET\s*(\S*)/i
736
+ if ($1)
737
+ # @dset = $1
738
+ # @dset = $1.gsub(/(\^)/,"./") # replace "^" with "./"
739
+ @dset = $1.gsub(/(^\^|^([^\/]))/,File.dirname(@ctlfile.path)+'/\2')
740
+ # relative -> absolute path (e.g. '^a' or 'a' -> '/hoge/a')
741
+ # @datafile = File.open(@dset,@mode)
742
+ else
743
+ raise "Invalid line: "+line
744
+ end
745
+ when /^\s*TITLE\s*(\S+.*)$/i
746
+ if ($1)
747
+ @title = $1
748
+ else
749
+ raise "Invalid line: "+line
750
+ end
751
+ when /^\s*UNDEF\s*(\S*)/i
752
+ if ($1)
753
+ @undef = $1.to_f
754
+ else
755
+ raise "Invalid line: "+line
756
+ end
757
+ when /^\s*FILEHEADER\s*(\S*)/i
758
+ if ($1)
759
+ @fileheader_len = $1.to_i
760
+ else
761
+ raise "Invalid line: "+line
762
+ end
763
+ when /^\s*BYTESWAPPED\s*$/i
764
+ @options["byteswapped"] = true
765
+ when /^\s*OPTIONS\s*(\S+.*)$/i
766
+ if ($1)
767
+ # $1.split.each{ |opt|
768
+ $1.downcase.split.each{ |opt|
769
+ if (@options.has_key?(opt))
770
+ @options[opt] = true
771
+ else
772
+ raise "Invalid/unsupported option: "+opt
773
+ end
774
+ }
775
+ else
776
+ raise "Invalid line: "+line
777
+ end
778
+ when /^\s*[XYZT]DEF/i
779
+ # /^\s*([XYZT])DEF\s+(\d+)\s+(\S+)\s+(.*)$/i =~ line
780
+ /^\s*([XYZT])DEF\s+(\d+)\s+(\S+)+(.*)$/i =~ line
781
+ if ( (len=$2) && (flag=$3) && (spec=$4))
782
+ dim = {:len=>len.to_i, :flag=>flag, :spec=>spec}
783
+ case $1
784
+ when /X/i
785
+ idim=0
786
+ dim[:name] = 'x'
787
+ dim[:description] = 'longitude'
788
+ dim[:units] = 'degrees_east'
789
+ when /Y/i
790
+ idim=1
791
+ dim[:name] = 'y'
792
+ dim[:description] = 'latitude'
793
+ dim[:units] = 'degrees_north'
794
+ when /Z/i
795
+ idim=2
796
+ dim[:name] = 'z'
797
+ dim[:description] = 'pressure level'
798
+ dim[:units] = 'hPa'
799
+ when /T/i
800
+ dim[:name] = 't'
801
+ dim[:description] = 'time'
802
+ idim=3
803
+ end
804
+ if (idim!=3)
805
+ if (dim[:flag] =~ /LINEAR/i)
806
+ begin
807
+ dim[:start],dim[:increment] = spec.split.collect!{|i| i.to_f}
808
+ rescue NameError,StandardError
809
+ raise $!.to_s+"\nCannot read start and increment from: "+spec
810
+ end
811
+ elsif (dim[:flag] =~ /LEVELS/i)
812
+ dim[:levels] = []
813
+ pos = @ctlfile.pos # back up for a one-line rewind
814
+ # dim[:spec] = "\n"
815
+ dim[:spec] += levs = spec+"\n"
816
+ if( /^\s*[\d\-\.]/ =~ levs )
817
+ dim[:levels] += levs.split.collect!{|i| i.to_f}
818
+ end
819
+ # while (dim[:spec] += levs = @ctlfile.gets)
820
+ while (levs = @ctlfile.gets)
821
+ if( /^\s*[\d\-\.]/ =~ levs )
822
+ dim[:spec] += levs
823
+ dim[:levels] += levs.split.collect!{|i| i.to_f}
824
+ #p '### levels',dim[:levels].length," ",levs.split
825
+ pos = @ctlfile.pos # back up for a one-line rewind
826
+ else
827
+ @ctlfile.pos = pos # one-line rewind (note: IO#lineno= doesn't work for this purpose)
828
+ break
829
+ end
830
+ end
831
+ else
832
+ raise "invalid or not-yet-supported dimension flag: "+dim[:flag]
833
+ end
834
+ else
835
+ # idim = 3 --- time
836
+ if (dim[:flag] =~ /LINEAR/i)
837
+ start,increment= spec.split
838
+ dim[:start] = 0.0
839
+ dim[:startdatetime] = parse_starttime(start)
840
+ dim[:increment],dim[:increment_units] = parse_timeincrement(increment)
841
+ dim[:units] = dim[:increment_units]+" since "+dim[:startdatetime].strftime("%Y-%m-%d %H:%MZ")
842
+
843
+ else
844
+ raise "invalid dimension flag(only LINEAR is available for time)"
845
+ end
846
+ end
847
+ @dimensions[idim]=dim
848
+ else
849
+ raise "Invalid line: "+line
850
+ end
851
+ when /^\s*VARS/i
852
+ total_lev_bytes=0
853
+ while ( vline = @ctlfile.gets )
854
+ case(vline)
855
+ when /^\s*\*/,/^\s*$/
856
+ # do nothing
857
+ when /^\s*ENDVARS/i
858
+ break
859
+ else
860
+ vline =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+.*?)\s*$/
861
+ # vline =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*(\S+.*?)\s*$/
862
+ if( !($1 && $2 && $3 && $4) )
863
+ raise "Something is wrong with this line: "+vline
864
+ end
865
+ name = $1; option = $3; description = $4; units = $5
866
+ nlev = max($2.to_i,1)
867
+ # total_levs += nlev
868
+ # case ($3)
869
+ case (option)
870
+ when /^0/,/^99/,/^-1,30/
871
+ byte=4; type="sfloat"
872
+ when /^-1,40,4/
873
+ byte=4; type="int"
874
+ when /^-1,40,2,-1/
875
+ byte=2; type="sint"
876
+ when /^-1,40,1/
877
+ byte=1; type="byte"
878
+ else
879
+ p option
880
+ raise "invalid or unsupported variable placement option: "
881
+ end
882
+ total_lev_bytes += nlev*byte
883
+ # @variables.push({:name=>$1,:nlev=>nlev,:option=>$3,
884
+ # :description=>$4})
885
+ if( ! $5 )
886
+ @variables.push({:name=>name,:nlev=>nlev,:option=>$3,:type=>type,:byte=>byte,
887
+ :description=>description})
888
+ else
889
+ @variables.push({:name=>$1,:nlev=>nlev,:option=>$3,:type=>type,:byte=>byte,
890
+ :description=>description, :units=>$5})
891
+ end
892
+ end
893
+ end
894
+ @map=Hash.new
895
+ cum_lev_bytes = 0
896
+ @variables.each{|i|
897
+ varname = i[:name]
898
+ @map[varname]={:offset=>@fileheader_len,:nlev=>i[:nlev],
899
+ :start=>cum_lev_bytes,:zstep=>i[:byte],:tstep=>total_lev_bytes,
900
+ :type=>i[:type],:byte=>i[:byte]}
901
+ if i[:option] =~ /^-1,30/
902
+ @map[varname][:xytranspose]=true
903
+ end
904
+ cum_lev_bytes += i[:nlev]*i[:byte]
905
+ }
906
+ end
907
+
908
+ end
909
+
910
+ #<check whether all the mandatory specifications are done>
911
+ for i in 0..3
912
+ raise "#{i}-th dimension is not found " if( ! @dimensions[i] )
913
+ end
914
+ raise "UNDEF field is not found" if(!@undef)
915
+ raise "DSET field is not found" if(!@dset)
916
+ raise "VARS field is not found" if(!@variables)
917
+
918
+ # #<post processing>
919
+ # @xybytes = 4 * @dimensions[0][:len] * @dimensions[1][:len]
920
+ # @xy = @dimensions[0][:len] * @dimensions[1][:len]
921
+
922
+ end
923
+
924
+ def start_byte(name, level, time)
925
+ # offset to read an xy section of the variable with NAME
926
+ # at LEVEL(counted from 0) at TIME(conted from 0)
927
+ if (map = @map[name] )
928
+ if (level<0 || level>=map[:nlev])
929
+ raise "Level #{level} is out of the range of the variable #{name}"
930
+ end
931
+ if (time<0 || time>=@dimensions[3][:len])
932
+ raise "Time #{time} is not in the data period"
933
+ end
934
+ iblock = map[:start]+level*map[:zstep]+time*map[:tstep]
935
+ str_byte = map[:offset] + @dimensions[0][:len] * @dimensions[1][:len] * iblock
936
+ if( @options["sequential"] )
937
+ str_byte += iblock*2 + 4
938
+ end
939
+ else
940
+ raise "Variable does not exist: "+name
941
+ end
942
+ str_byte
943
+ end
944
+
945
+ def parse_starttime(string)
946
+ ## interpret the hh:mmZddmmmyyyy format for grads
947
+
948
+ if (/([\d:]*)Z(.*)/i =~ string)
949
+ stime = $1
950
+ sdate = $2
951
+ else
952
+ # must be date, not time, since month and year are mandatory
953
+ sdate = string
954
+ stime = ''
955
+ end
956
+
957
+ if ( /(\d\d):(\d\d)/ =~ stime )
958
+ begin
959
+ shour = $1
960
+ smin = $2
961
+ hour = shour.to_i
962
+ min = smin.to_i
963
+ rescue StandardError,NameError
964
+ raise "Cannot convert hour or time into interger: "+stime
965
+ end
966
+ else
967
+ hour = 0
968
+ min = 0
969
+ end
970
+
971
+ if ( /(\d*)(\w\w\w)(\d\d\d\d)/ =~ sdate )
972
+ sday = $1
973
+ smon = $2
974
+ syear = $3
975
+ begin
976
+ if(sday == "")
977
+ day = 1
978
+ else
979
+ day = sday.to_i
980
+ end
981
+ year = syear.to_i
982
+ mon=['jan','feb','mar','apr','may','jun','jul','aug','sep',
983
+ 'oct','nov','dec'].index(smon.downcase) + 1
984
+ rescue StandardError, NameError
985
+ raise "Could not parse the date string: "+sdate+"\n"+$!
986
+ end
987
+ else
988
+ raise "The date part must be [dd]mmmyyyy, but what was given is: "+sdate
989
+ end
990
+
991
+ return DateTime.new(year,mon,day,hour,min)
992
+ end
993
+
994
+ def parse_timeincrement(string)
995
+ if ( /(\d+)(\w\w)/ =~ string )
996
+ sincrement = $1.to_i
997
+ sunits = $2
998
+ case sunits
999
+ when /mn/i
1000
+ # fact = 1.0/1440.0 # factor to convert into days
1001
+ # units = 'days'
1002
+ fact = 1.0
1003
+ units = 'minutes'
1004
+ increment = sincrement * fact
1005
+ when /hr/i
1006
+ # fact = 1.0/24.0
1007
+ # units = 'days'
1008
+ fact = 1.0
1009
+ units = 'hours'
1010
+ increment = sincrement * fact
1011
+ when /dy/i
1012
+ fact = 1.0
1013
+ units = 'days'
1014
+ increment = sincrement * fact
1015
+ when /mo/i
1016
+ fact = 1.0
1017
+ units = 'months'
1018
+ increment = sincrement * fact
1019
+ when /yr/i
1020
+ fact = 1.0
1021
+ units = 'years'
1022
+ increment = sincrement * fact
1023
+ else
1024
+ raise "invalid units: "+sunits
1025
+ end
1026
+ else
1027
+ raise "invalid time-increment string: #{sunits}"
1028
+ end
1029
+ return [increment, units]
1030
+ end
1031
+
1032
+ def max(a,b)
1033
+ a>b ? a : b
1034
+ end
1035
+
1036
+ def generate_starttime(datetime)
1037
+ mon = Date::ABBR_MONTHNAMES[datetime.mon]
1038
+ return datetime.strftime("%H:%MZ%d#{mon}%Y")
1039
+ end
1040
+
1041
+ def generate_timeincrement(increment,units)
1042
+ increment = increment[0] if(increment.class==NArray)
1043
+ sincrement = increment
1044
+ case units
1045
+ when /min/i
1046
+ sunits = "mn"
1047
+ when /hour/i
1048
+ sunits = "hr"
1049
+ when /day/i
1050
+ sunits = "dy"
1051
+ when /mon/i
1052
+ sunits = "mo"
1053
+ when /year/i
1054
+ sunits = "yr"
1055
+ else
1056
+ raise "invalid time increment units: #{units}"
1057
+ end
1058
+
1059
+ if(sunits == "dy")
1060
+ if( increment < 0.0 )
1061
+ raise "invalid time increment: #{increment}"
1062
+ elsif( increment >= 365 && (increment.to_f/365) / (increment.to_i/365) < 1.003 )
1063
+ sincrement = (increment/365).to_i
1064
+ sunits = "yr"
1065
+ elsif( increment >= 28 && (increment.to_f/28) / (increment.to_i/28) < 1.11 )
1066
+ sincrement = (increment/28).to_i
1067
+ sunits = "mo"
1068
+ elsif( increment < 1.0 )
1069
+ if( increment >= 0.0416 && (increment*1440)%60 < 5 )
1070
+ sincrement = (increment*24).to_i
1071
+ sunits = "hr"
1072
+ else
1073
+ sincrement = increment*1440
1074
+ sunits = "mn"
1075
+ end
1076
+ end
1077
+ end
1078
+
1079
+ return sprintf("%2d",sincrement)+sunits
1080
+ end
1081
+
1082
+ def convert_endian_read(ary)
1083
+
1084
+ if( (@options["big_endian"] || @options["cray_32bit_ieee"]) &&
1085
+ @options["little_endian"] )
1086
+ raise "endian specification error"
1087
+ end
1088
+
1089
+ if( @options["big_endian"] || @options["cray_32bit_ieee"] )
1090
+ ary = ary.ntoh
1091
+ elsif( @options["little_endian"] )
1092
+ ary = ary.vtoh
1093
+ elsif( @options["byteswapped"] )
1094
+ ary = ary.swap_byte
1095
+ end
1096
+
1097
+ ary
1098
+ end
1099
+
1100
+ def convert_endian_write(ary)
1101
+
1102
+ if( (@options["big_endian"] || @options["cray_32bit_ieee"]) &&
1103
+ @options["little_endian"] )
1104
+ raise "endian specification error"
1105
+ end
1106
+
1107
+ if( @options["big_endian"] || @options["cray_32bit_ieee"] )
1108
+ ary = ary.hton
1109
+ elsif( @options["little_endian"] )
1110
+ ary = ary.htov
1111
+ elsif( @options["byteswapped"] )
1112
+ ary = ary.swap_byte
1113
+ end
1114
+
1115
+ ary
1116
+ end
1117
+
1118
+ end
1119
+
1120
+ class GrADSVar
1121
+
1122
+ def initialize(file,varname)
1123
+ @varname = varname
1124
+
1125
+ if file.is_a?(String)
1126
+ file = GrADS_Gridded.open(file)
1127
+ elsif ! file.is_a?(GrADS_Gridded)
1128
+ raise ArgumentError, "1st arg must be a GrADS_Gridded or a file name"
1129
+ end
1130
+ @ctl = file # control file name
1131
+ # @ctl = ctl
1132
+
1133
+ @idim = -1
1134
+ for i in 0...@ctl.dimensions.length
1135
+ # p @ctl.dimensions[i][:name]
1136
+ if @varname == @ctl.dimensions[i][:name]
1137
+ @idim = i
1138
+ end
1139
+ end
1140
+
1141
+ @attr = NumRu::Attribute.new
1142
+ if( @idim != -1 )
1143
+ @dimensions = [ @ctl.dimensions[@idim] ]
1144
+ @rank = 1
1145
+ @attr[:name] = @dimensions[0][:name]
1146
+ @attr[:long_name] = @dimensions[0][:description]
1147
+ @attr[:units] = @dimensions[0][:units]
1148
+
1149
+ @shape = [@dimensions[0][:len]]
1150
+ else
1151
+ @dimensions = @ctl.dimensions
1152
+ @rank = @dimensions.length
1153
+ found = false
1154
+ for i in 0...@ctl.variables.length
1155
+ if @varname == @ctl.variables[i][:name]
1156
+ @attr[:long_name] = @ctl.variables[i][:description]
1157
+ @attr[:nlev] = @ctl.variables[i][:nlev].to_s
1158
+
1159
+ @shape = [@dimensions[0][:len],@dimensions[1][:len],
1160
+ @dimensions[2][:len],@dimensions[3][:len]]
1161
+ @shape[2] = @ctl.variables[i][:nlev].to_i if( @ctl.variables[i][:nlev] )
1162
+
1163
+ @attr[:missing_value] = NArray.sfloat(1).fill!(@ctl.undef)
1164
+ found = true
1165
+ end
1166
+ end
1167
+ raise "variable #{@varname} is not found" if !found
1168
+ end
1169
+ end
1170
+
1171
+ attr_accessor (:rank)
1172
+ alias :ndims :rank
1173
+
1174
+ # def dim(name)
1175
+ # def dims(names)
1176
+
1177
+ def dim_names
1178
+ ary = Array.new()
1179
+ @dimensions.each{|dim| ary.push(dim[:name])}
1180
+ ary
1181
+ end
1182
+
1183
+ def name
1184
+ @varname
1185
+ end
1186
+
1187
+ def name=
1188
+ raise "name= not supported"
1189
+ end
1190
+
1191
+ def ndims
1192
+ @rank
1193
+ end
1194
+
1195
+ def vartype
1196
+ if( @idim == -1 )
1197
+ for i in 0...@ctl.variables.length
1198
+ if @varname == @ctl.variables[i][:name]
1199
+ type = @ctl.variables[i][:type]
1200
+ end
1201
+ end
1202
+ else
1203
+ type = "float"
1204
+ end
1205
+ type
1206
+ end
1207
+ alias ntype vartype
1208
+
1209
+ def typecode
1210
+ if( @idim == -1 )
1211
+ for i in 0...@ctl.variables.length
1212
+ if @varname == @ctl.variables[i][:name]
1213
+ byte = @ctl.variables[i][:byte]
1214
+ end
1215
+ end
1216
+ else
1217
+ byte = 4
1218
+ end
1219
+ byte
1220
+ end
1221
+
1222
+ def att(name)
1223
+ raise "use get_att instead of att"
1224
+ end
1225
+
1226
+ def get_att(name)
1227
+ @attr[name]
1228
+ end
1229
+
1230
+ def natts
1231
+ @attr.length
1232
+ end
1233
+
1234
+ def att_names
1235
+ @attr.keys
1236
+ end
1237
+
1238
+ def each_att
1239
+ raise "each_att not supported"
1240
+ end
1241
+
1242
+ def put_att(name,value)
1243
+ @attr[name] = value
1244
+ end
1245
+
1246
+ def attr # obsolete
1247
+ @attr
1248
+ end
1249
+
1250
+ def file
1251
+ @ctl.ctlfile
1252
+ end
1253
+
1254
+ # def shape_ul0
1255
+ # sh = []
1256
+ # @dimensions.each{|dim|
1257
+ ## if d.unlimited? then
1258
+ ## sh.push(0)
1259
+ ## else
1260
+ # sh.push(dim[:len])
1261
+ ## end
1262
+ # }
1263
+ # sh
1264
+ # end
1265
+
1266
+ def shape_current
1267
+ # sh = []
1268
+ # @dimensions.each{|dim|
1269
+ # sh.push(dim[:len])
1270
+ # }
1271
+ # sh
1272
+ @shape
1273
+ end
1274
+
1275
+ alias shape_ul0 shape_current
1276
+
1277
+ def scaled_put(var,hash=nil)
1278
+ raise "scaled_put not supported"
1279
+ end
1280
+
1281
+ def scaled_get(hash=nil)
1282
+ raise "scaled_get not supported"
1283
+ end
1284
+
1285
+ def put(var,hash=nil)
1286
+ raise "put not supported"
1287
+ end
1288
+
1289
+ def get(hash=nil)
1290
+ if @idim != -1
1291
+ na = @ctl.get_dim(@dimensions[0])
1292
+ if hash == nil
1293
+
1294
+ elsif hash.key?("start")==true
1295
+ h_sta = hash["start"]
1296
+ endq = hash.key?("end")
1297
+ strq = hash.key?("stride")
1298
+ if endq == false && strq == false
1299
+ na = na[h_sta[0]..-1]
1300
+ elsif endq == true && strq == false
1301
+ h_end = hash["end"]
1302
+ na = na[h_sta[0]..h_end[0]]
1303
+ elsif endq == false && strq == true
1304
+ h_str = hash["stride"]
1305
+ raise "sorry, stride is not supported yet."
1306
+ else endq == true && strq == true
1307
+ h_end = hash["end"]
1308
+ h_str = hash["stride"]
1309
+ raise "sorry, stride is not supported yet."
1310
+ end
1311
+ end
1312
+ else
1313
+ h_sta = [0, 0, 0, 0]
1314
+ h_end = [-1, -1, -1, -1]
1315
+ if hash == nil
1316
+ # elsif hash.key?("index")==true
1317
+ else
1318
+ if hash.key?("start")==true
1319
+ h_sta = hash["start"]
1320
+ if hash.key?("end")==true
1321
+ h_end = hash["end"]
1322
+ end
1323
+ end
1324
+ if hash.key?("stride")==true
1325
+ raise "sorry, stride is not supported yet."
1326
+ end
1327
+ end
1328
+
1329
+ idx_x = NArray.int(@shape[0]).indgen!
1330
+ idx_y = NArray.int(@shape[1]).indgen!
1331
+ idx_z = NArray.int(@shape[2]).indgen!
1332
+ idx_t = NArray.int(@shape[3]).indgen!
1333
+ str_x = idx_x[h_sta[0]]; end_x = idx_x[h_end[0]]
1334
+ str_y = idx_y[h_sta[1]]; end_y = idx_y[h_end[1]]
1335
+ str_z = idx_z[h_sta[2]]; end_z = idx_z[h_end[2]]
1336
+ str_t = idx_t[h_sta[3]]; end_t = idx_t[h_end[3]]
1337
+
1338
+ na = NArrayMiss.new(vartype,end_x-str_x+1,end_y-str_y+1,end_z-str_z+1,end_t-str_t+1)
1339
+ for t in str_t..end_t
1340
+ for z in str_z..end_z
1341
+ na_xy = @ctl.get(@varname,z,t,[str_x,end_x,str_y,end_y])
1342
+ mask = ( na_xy.ne @ctl.undef )
1343
+ na[true,true,z-str_z,t-str_t] = NArrayMiss.to_nam(na_xy,mask)
1344
+ end
1345
+ end
1346
+ end
1347
+ na
1348
+ end
1349
+
1350
+ alias simple_put put
1351
+ alias simple_get get
1352
+
1353
+ def __rubber_expansion( args ) # copied from NetCDFVar class
1354
+ if (id = args.index(false)) # substitution into id
1355
+ # false is incuded
1356
+ alen = args.length
1357
+ if args.rindex(false) != id
1358
+ raise ArguemntError,"only one rubber dimension is permitted"
1359
+ elsif alen > rank+1
1360
+ raise ArgumentError, "too many args"
1361
+ end
1362
+ ar = ( id!=0 ? args[0..id-1] : [] )
1363
+ args = ar + [true]*(rank-alen+1) + args[id+1..-1]
1364
+ elsif args.length == 0 # to support empty [], []=
1365
+ args = [true]*rank
1366
+ end
1367
+ args
1368
+ end
1369
+ private :__rubber_expansion
1370
+
1371
+ def [](*a) # copied from NetCDFVar class
1372
+ a = __rubber_expansion(a)
1373
+ first = Array.new
1374
+ last = Array.new
1375
+ stride = Array.new
1376
+ set_stride = false
1377
+ a.each{|i|
1378
+ if(i.is_a?(Fixnum))
1379
+ first.push(i)
1380
+ last.push(i)
1381
+ stride.push(1)
1382
+ elsif(i.is_a?(Range))
1383
+ first.push(i.first)
1384
+ last.push(i.exclude_end? ? i.last-1 : i.last)
1385
+ stride.push(1)
1386
+ elsif(i.is_a?(Hash))
1387
+ r = (i.to_a[0])[0]
1388
+ s = (i.to_a[0])[1]
1389
+ if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
1390
+ raise TypeError, "Hash argument must be {a_Range, step}"
1391
+ end
1392
+ first.push(r.first)
1393
+ last.push(r.exclude_end? ? r.last-1 : r.last)
1394
+ stride.push(s)
1395
+ set_stride = true
1396
+ elsif(i.is_a?(TrueClass))
1397
+ first.push(0)
1398
+ last.push(-1)
1399
+ stride.push(1)
1400
+ elsif( i.is_a?(Array) || i.is_a?(NArray))
1401
+ a_new = a.dup
1402
+ at = a.index(i)
1403
+ i = NArray.to_na(i) if i.is_a?(Array)
1404
+ for n in 0..i.length-1
1405
+ a_new[at] = i[n]..i[n]
1406
+ na_tmp = self[*a_new]
1407
+ if n==0 then
1408
+ k = at
1409
+ if at > 0
1410
+ a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
1411
+ end
1412
+ shape_tmp = na_tmp.shape
1413
+ shape_tmp[k] = i.length
1414
+ na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
1415
+ index_tmp = Array.new(shape_tmp.length,true)
1416
+ end
1417
+ index_tmp[k] = n..n
1418
+ na[*index_tmp] = na_tmp
1419
+ end
1420
+ return na
1421
+ else
1422
+ raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
1423
+ end
1424
+ }
1425
+
1426
+ if(set_stride)
1427
+ na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
1428
+ else
1429
+ na = self.get({"start"=>first, "end"=>last})
1430
+ end
1431
+ shape = na.shape
1432
+ (a.length-1).downto(0){ |i|
1433
+ shape.delete_at(i) if a[i].is_a?(Fixnum)
1434
+ }
1435
+ na.reshape!( *shape )
1436
+ na
1437
+ end
1438
+
1439
+ def []=(*a) # copied from NetCDFVar class
1440
+ val = a.pop
1441
+ a = __rubber_expansion(a)
1442
+ first = Array.new
1443
+ last = Array.new
1444
+ stride = Array.new
1445
+ set_stride = false
1446
+ a.each{|i|
1447
+ if(i.is_a?(Fixnum))
1448
+ first.push(i)
1449
+ last.push(i)
1450
+ stride.push(1)
1451
+ elsif(i.is_a?(Range))
1452
+ first.push(i.first)
1453
+ last.push(i.exclude_end? ? i.last-1 : i.last)
1454
+ stride.push(1)
1455
+ elsif(i.is_a?(Hash))
1456
+ r = (i.to_a[0])[0]
1457
+ s = (i.to_a[0])[1]
1458
+ if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
1459
+ raise ArgumentError, "Hash argument must be {first..last, step}"
1460
+ end
1461
+ first.push(r.first)
1462
+ last.push(r.exclude_end? ? r.last-1 : r.last)
1463
+ stride.push(s)
1464
+ set_stride = true
1465
+ elsif(i.is_a?(TrueClass))
1466
+ first.push(0)
1467
+ last.push(-1)
1468
+ stride.push(1)
1469
+ elsif(i.is_a?(Array) || i.is_a?(NArray))
1470
+ a_new = a.dup
1471
+ at = a.index(i)
1472
+ i = NArray.to_na(i) if i.is_a?(Array)
1473
+ val = NArray.to_na(val) if val.is_a?(Array)
1474
+ rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length
1475
+ if val.rank != rank_of_subset
1476
+ raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
1477
+ "of the subset specified by #{a.inspect} (#{rank_of_subset})"
1478
+ end
1479
+ k = at
1480
+ a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
1481
+ if i.length != val.shape[k]
1482
+ raise "length of the #{k+1}-th dim of rhs is incorrect "+
1483
+ "(#{i.length} for #{val.shape[k]})"
1484
+ end
1485
+ index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
1486
+ for n in 0..i.length-1
1487
+ a_new[at] = i[n]..i[n]
1488
+ if !val.is_a?(Numeric) then
1489
+ index_tmp[k] = n..n
1490
+ self[*a_new] = val[*index_tmp]
1491
+ else
1492
+ self[*a_new] = val
1493
+ end
1494
+ end
1495
+ return self
1496
+ else
1497
+ raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
1498
+ end
1499
+ }
1500
+
1501
+ if(set_stride)
1502
+ self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
1503
+ else
1504
+ self.put(val, {"start"=>first, "end"=>last})
1505
+ end
1506
+ end
1507
+
1508
+ end
1509
+
1510
+ end
1511
+
1512
+ if __FILE__ == $0 then
1513
+
1514
+ include NumRu
1515
+
1516
+ begin
1517
+ gr = GrADS_Gridded.open("../../testdata/T.jan.ctl")
1518
+ rescue
1519
+ gr = GrADS_Gridded.open("../../../testdata/T.jan.ctl")
1520
+ end
1521
+ print gr.to_ctl
1522
+ p gr
1523
+ p gr.path
1524
+ p gr.var_names
1525
+ p gr.get_dim(gr.dimensions[2])
1526
+ p gr.get('T',0,0)
1527
+
1528
+ begin
1529
+ grvar = GrADSVar.new("../../testdata/T.jan.ctl","T")
1530
+ rescue
1531
+ grvar = GrADSVar.new("../../../testdata/T.jan.ctl","T")
1532
+ end
1533
+
1534
+ p grvar.dim_names
1535
+ p grvar.shape_ul0
1536
+ t = grvar[3..9,5..15,0,0]
1537
+ p t
1538
+
1539
+ end