gphys 1.2.2.1 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (405) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -17
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/ChangeLog +5762 -753
  6. data/LICENSE.txt +30 -18
  7. data/Rakefile +1 -0
  8. data/bin/console +14 -0
  9. data/bin/gpcat +43 -2
  10. data/bin/gpcut +16 -0
  11. data/bin/gpvect +167 -15
  12. data/bin/gpview +254 -51
  13. data/bin/setup +7 -0
  14. data/dim_op.c +1220 -0
  15. data/doc/attribute.html +19 -0
  16. data/doc/attributenetcdf.html +15 -0
  17. data/doc/axis.html +387 -0
  18. data/doc/coordmapping.html +111 -0
  19. data/doc/coordtransform.html +36 -0
  20. data/doc/dclext.html +821 -0
  21. data/doc/derivative/gphys-derivative.html +100 -0
  22. data/doc/derivative/index.html +21 -0
  23. data/doc/derivative/index.rd +14 -0
  24. data/doc/derivative/math-doc/document.pdf +0 -0
  25. data/doc/derivative/math-doc/document.tex +158 -0
  26. data/doc/derivative/math-doc/document/document.css +30 -0
  27. data/doc/derivative/math-doc/document/document.html +57 -0
  28. data/doc/derivative/math-doc/document/images.aux +1 -0
  29. data/doc/derivative/math-doc/document/images.log +385 -0
  30. data/doc/derivative/math-doc/document/images.pl +186 -0
  31. data/doc/derivative/math-doc/document/images.tex +364 -0
  32. data/doc/derivative/math-doc/document/img1.png +0 -0
  33. data/doc/derivative/math-doc/document/img10.png +0 -0
  34. data/doc/derivative/math-doc/document/img11.png +0 -0
  35. data/doc/derivative/math-doc/document/img12.png +0 -0
  36. data/doc/derivative/math-doc/document/img13.png +0 -0
  37. data/doc/derivative/math-doc/document/img14.png +0 -0
  38. data/doc/derivative/math-doc/document/img15.png +0 -0
  39. data/doc/derivative/math-doc/document/img16.png +0 -0
  40. data/doc/derivative/math-doc/document/img17.png +0 -0
  41. data/doc/derivative/math-doc/document/img18.png +0 -0
  42. data/doc/derivative/math-doc/document/img19.png +0 -0
  43. data/doc/derivative/math-doc/document/img2.png +0 -0
  44. data/doc/derivative/math-doc/document/img20.png +0 -0
  45. data/doc/derivative/math-doc/document/img21.png +0 -0
  46. data/doc/derivative/math-doc/document/img22.png +0 -0
  47. data/doc/derivative/math-doc/document/img23.png +0 -0
  48. data/doc/derivative/math-doc/document/img24.png +0 -0
  49. data/doc/derivative/math-doc/document/img25.png +0 -0
  50. data/doc/derivative/math-doc/document/img26.png +0 -0
  51. data/doc/derivative/math-doc/document/img27.png +0 -0
  52. data/doc/derivative/math-doc/document/img28.png +0 -0
  53. data/doc/derivative/math-doc/document/img29.png +0 -0
  54. data/doc/derivative/math-doc/document/img3.png +0 -0
  55. data/doc/derivative/math-doc/document/img30.png +0 -0
  56. data/doc/derivative/math-doc/document/img4.png +0 -0
  57. data/doc/derivative/math-doc/document/img5.png +0 -0
  58. data/doc/derivative/math-doc/document/img6.png +0 -0
  59. data/doc/derivative/math-doc/document/img7.png +0 -0
  60. data/doc/derivative/math-doc/document/img8.png +0 -0
  61. data/doc/derivative/math-doc/document/img9.png +0 -0
  62. data/doc/derivative/math-doc/document/index.html +57 -0
  63. data/doc/derivative/math-doc/document/labels.pl +13 -0
  64. data/doc/derivative/math-doc/document/next.png +0 -0
  65. data/doc/derivative/math-doc/document/next_g.png +0 -0
  66. data/doc/derivative/math-doc/document/node1.html +238 -0
  67. data/doc/derivative/math-doc/document/node2.html +75 -0
  68. data/doc/derivative/math-doc/document/prev.png +0 -0
  69. data/doc/derivative/math-doc/document/prev_g.png +0 -0
  70. data/doc/derivative/math-doc/document/up.png +0 -0
  71. data/doc/derivative/math-doc/document/up_g.png +0 -0
  72. data/doc/derivative/numru-derivative.html +158 -0
  73. data/doc/ep_flux/ep_flux.html +469 -0
  74. data/doc/ep_flux/ggraph_on_merdional_section.html +71 -0
  75. data/doc/ep_flux/index.html +31 -0
  76. data/doc/ep_flux/index.rd +24 -0
  77. data/doc/ep_flux/math-doc/document.pdf +0 -0
  78. data/doc/ep_flux/math-doc/document.tex +2018 -0
  79. data/doc/ep_flux/math-doc/document/WARNINGS +1 -0
  80. data/doc/ep_flux/math-doc/document/contents.png +0 -0
  81. data/doc/ep_flux/math-doc/document/crossref.png +0 -0
  82. data/doc/ep_flux/math-doc/document/document.css +30 -0
  83. data/doc/ep_flux/math-doc/document/document.html +101 -0
  84. data/doc/ep_flux/math-doc/document/images.aux +1 -0
  85. data/doc/ep_flux/math-doc/document/images.log +1375 -0
  86. data/doc/ep_flux/math-doc/document/images.pl +1328 -0
  87. data/doc/ep_flux/math-doc/document/images.tex +1471 -0
  88. data/doc/ep_flux/math-doc/document/img1.png +0 -0
  89. data/doc/ep_flux/math-doc/document/img10.png +0 -0
  90. data/doc/ep_flux/math-doc/document/img100.png +0 -0
  91. data/doc/ep_flux/math-doc/document/img101.png +0 -0
  92. data/doc/ep_flux/math-doc/document/img102.png +0 -0
  93. data/doc/ep_flux/math-doc/document/img103.png +0 -0
  94. data/doc/ep_flux/math-doc/document/img104.png +0 -0
  95. data/doc/ep_flux/math-doc/document/img105.png +0 -0
  96. data/doc/ep_flux/math-doc/document/img106.png +0 -0
  97. data/doc/ep_flux/math-doc/document/img107.png +0 -0
  98. data/doc/ep_flux/math-doc/document/img108.png +0 -0
  99. data/doc/ep_flux/math-doc/document/img109.png +0 -0
  100. data/doc/ep_flux/math-doc/document/img11.png +0 -0
  101. data/doc/ep_flux/math-doc/document/img110.png +0 -0
  102. data/doc/ep_flux/math-doc/document/img111.png +0 -0
  103. data/doc/ep_flux/math-doc/document/img112.png +0 -0
  104. data/doc/ep_flux/math-doc/document/img113.png +0 -0
  105. data/doc/ep_flux/math-doc/document/img114.png +0 -0
  106. data/doc/ep_flux/math-doc/document/img115.png +0 -0
  107. data/doc/ep_flux/math-doc/document/img116.png +0 -0
  108. data/doc/ep_flux/math-doc/document/img117.png +0 -0
  109. data/doc/ep_flux/math-doc/document/img118.png +0 -0
  110. data/doc/ep_flux/math-doc/document/img119.png +0 -0
  111. data/doc/ep_flux/math-doc/document/img12.png +0 -0
  112. data/doc/ep_flux/math-doc/document/img120.png +0 -0
  113. data/doc/ep_flux/math-doc/document/img121.png +0 -0
  114. data/doc/ep_flux/math-doc/document/img122.png +0 -0
  115. data/doc/ep_flux/math-doc/document/img123.png +0 -0
  116. data/doc/ep_flux/math-doc/document/img124.png +0 -0
  117. data/doc/ep_flux/math-doc/document/img125.png +0 -0
  118. data/doc/ep_flux/math-doc/document/img126.png +0 -0
  119. data/doc/ep_flux/math-doc/document/img127.png +0 -0
  120. data/doc/ep_flux/math-doc/document/img128.png +0 -0
  121. data/doc/ep_flux/math-doc/document/img129.png +0 -0
  122. data/doc/ep_flux/math-doc/document/img13.png +0 -0
  123. data/doc/ep_flux/math-doc/document/img130.png +0 -0
  124. data/doc/ep_flux/math-doc/document/img131.png +0 -0
  125. data/doc/ep_flux/math-doc/document/img132.png +0 -0
  126. data/doc/ep_flux/math-doc/document/img133.png +0 -0
  127. data/doc/ep_flux/math-doc/document/img134.png +0 -0
  128. data/doc/ep_flux/math-doc/document/img135.png +0 -0
  129. data/doc/ep_flux/math-doc/document/img136.png +0 -0
  130. data/doc/ep_flux/math-doc/document/img137.png +0 -0
  131. data/doc/ep_flux/math-doc/document/img138.png +0 -0
  132. data/doc/ep_flux/math-doc/document/img139.png +0 -0
  133. data/doc/ep_flux/math-doc/document/img14.png +0 -0
  134. data/doc/ep_flux/math-doc/document/img140.png +0 -0
  135. data/doc/ep_flux/math-doc/document/img141.png +0 -0
  136. data/doc/ep_flux/math-doc/document/img142.png +0 -0
  137. data/doc/ep_flux/math-doc/document/img143.png +0 -0
  138. data/doc/ep_flux/math-doc/document/img144.png +0 -0
  139. data/doc/ep_flux/math-doc/document/img145.png +0 -0
  140. data/doc/ep_flux/math-doc/document/img146.png +0 -0
  141. data/doc/ep_flux/math-doc/document/img147.png +0 -0
  142. data/doc/ep_flux/math-doc/document/img148.png +0 -0
  143. data/doc/ep_flux/math-doc/document/img149.png +0 -0
  144. data/doc/ep_flux/math-doc/document/img15.png +0 -0
  145. data/doc/ep_flux/math-doc/document/img150.png +0 -0
  146. data/doc/ep_flux/math-doc/document/img151.png +0 -0
  147. data/doc/ep_flux/math-doc/document/img152.png +0 -0
  148. data/doc/ep_flux/math-doc/document/img153.png +0 -0
  149. data/doc/ep_flux/math-doc/document/img154.png +0 -0
  150. data/doc/ep_flux/math-doc/document/img155.png +0 -0
  151. data/doc/ep_flux/math-doc/document/img156.png +0 -0
  152. data/doc/ep_flux/math-doc/document/img157.png +0 -0
  153. data/doc/ep_flux/math-doc/document/img158.png +0 -0
  154. data/doc/ep_flux/math-doc/document/img159.png +0 -0
  155. data/doc/ep_flux/math-doc/document/img16.png +0 -0
  156. data/doc/ep_flux/math-doc/document/img160.png +0 -0
  157. data/doc/ep_flux/math-doc/document/img161.png +0 -0
  158. data/doc/ep_flux/math-doc/document/img162.png +0 -0
  159. data/doc/ep_flux/math-doc/document/img163.png +0 -0
  160. data/doc/ep_flux/math-doc/document/img164.png +0 -0
  161. data/doc/ep_flux/math-doc/document/img165.png +0 -0
  162. data/doc/ep_flux/math-doc/document/img166.png +0 -0
  163. data/doc/ep_flux/math-doc/document/img167.png +0 -0
  164. data/doc/ep_flux/math-doc/document/img168.png +0 -0
  165. data/doc/ep_flux/math-doc/document/img169.png +0 -0
  166. data/doc/ep_flux/math-doc/document/img17.png +0 -0
  167. data/doc/ep_flux/math-doc/document/img170.png +0 -0
  168. data/doc/ep_flux/math-doc/document/img171.png +0 -0
  169. data/doc/ep_flux/math-doc/document/img172.png +0 -0
  170. data/doc/ep_flux/math-doc/document/img173.png +0 -0
  171. data/doc/ep_flux/math-doc/document/img174.png +0 -0
  172. data/doc/ep_flux/math-doc/document/img175.png +0 -0
  173. data/doc/ep_flux/math-doc/document/img176.png +0 -0
  174. data/doc/ep_flux/math-doc/document/img177.png +0 -0
  175. data/doc/ep_flux/math-doc/document/img178.png +0 -0
  176. data/doc/ep_flux/math-doc/document/img179.png +0 -0
  177. data/doc/ep_flux/math-doc/document/img18.png +0 -0
  178. data/doc/ep_flux/math-doc/document/img180.png +0 -0
  179. data/doc/ep_flux/math-doc/document/img181.png +0 -0
  180. data/doc/ep_flux/math-doc/document/img182.png +0 -0
  181. data/doc/ep_flux/math-doc/document/img183.png +0 -0
  182. data/doc/ep_flux/math-doc/document/img184.png +0 -0
  183. data/doc/ep_flux/math-doc/document/img185.png +0 -0
  184. data/doc/ep_flux/math-doc/document/img186.png +0 -0
  185. data/doc/ep_flux/math-doc/document/img187.png +0 -0
  186. data/doc/ep_flux/math-doc/document/img188.png +0 -0
  187. data/doc/ep_flux/math-doc/document/img189.png +0 -0
  188. data/doc/ep_flux/math-doc/document/img19.png +0 -0
  189. data/doc/ep_flux/math-doc/document/img190.png +0 -0
  190. data/doc/ep_flux/math-doc/document/img191.png +0 -0
  191. data/doc/ep_flux/math-doc/document/img192.png +0 -0
  192. data/doc/ep_flux/math-doc/document/img193.png +0 -0
  193. data/doc/ep_flux/math-doc/document/img194.png +0 -0
  194. data/doc/ep_flux/math-doc/document/img195.png +0 -0
  195. data/doc/ep_flux/math-doc/document/img196.png +0 -0
  196. data/doc/ep_flux/math-doc/document/img197.png +0 -0
  197. data/doc/ep_flux/math-doc/document/img198.png +0 -0
  198. data/doc/ep_flux/math-doc/document/img199.png +0 -0
  199. data/doc/ep_flux/math-doc/document/img2.png +0 -0
  200. data/doc/ep_flux/math-doc/document/img20.png +0 -0
  201. data/doc/ep_flux/math-doc/document/img200.png +0 -0
  202. data/doc/ep_flux/math-doc/document/img21.png +0 -0
  203. data/doc/ep_flux/math-doc/document/img22.png +0 -0
  204. data/doc/ep_flux/math-doc/document/img23.png +0 -0
  205. data/doc/ep_flux/math-doc/document/img24.png +0 -0
  206. data/doc/ep_flux/math-doc/document/img25.png +0 -0
  207. data/doc/ep_flux/math-doc/document/img26.png +0 -0
  208. data/doc/ep_flux/math-doc/document/img27.png +0 -0
  209. data/doc/ep_flux/math-doc/document/img28.png +0 -0
  210. data/doc/ep_flux/math-doc/document/img29.png +0 -0
  211. data/doc/ep_flux/math-doc/document/img3.png +0 -0
  212. data/doc/ep_flux/math-doc/document/img30.png +0 -0
  213. data/doc/ep_flux/math-doc/document/img31.png +0 -0
  214. data/doc/ep_flux/math-doc/document/img32.png +0 -0
  215. data/doc/ep_flux/math-doc/document/img33.png +0 -0
  216. data/doc/ep_flux/math-doc/document/img34.png +0 -0
  217. data/doc/ep_flux/math-doc/document/img35.png +0 -0
  218. data/doc/ep_flux/math-doc/document/img36.png +0 -0
  219. data/doc/ep_flux/math-doc/document/img37.png +0 -0
  220. data/doc/ep_flux/math-doc/document/img38.png +0 -0
  221. data/doc/ep_flux/math-doc/document/img39.png +0 -0
  222. data/doc/ep_flux/math-doc/document/img4.png +0 -0
  223. data/doc/ep_flux/math-doc/document/img40.png +0 -0
  224. data/doc/ep_flux/math-doc/document/img41.png +0 -0
  225. data/doc/ep_flux/math-doc/document/img42.png +0 -0
  226. data/doc/ep_flux/math-doc/document/img43.png +0 -0
  227. data/doc/ep_flux/math-doc/document/img44.png +0 -0
  228. data/doc/ep_flux/math-doc/document/img45.png +0 -0
  229. data/doc/ep_flux/math-doc/document/img46.png +0 -0
  230. data/doc/ep_flux/math-doc/document/img47.png +0 -0
  231. data/doc/ep_flux/math-doc/document/img48.png +0 -0
  232. data/doc/ep_flux/math-doc/document/img49.png +0 -0
  233. data/doc/ep_flux/math-doc/document/img5.png +0 -0
  234. data/doc/ep_flux/math-doc/document/img50.png +0 -0
  235. data/doc/ep_flux/math-doc/document/img51.png +0 -0
  236. data/doc/ep_flux/math-doc/document/img52.png +0 -0
  237. data/doc/ep_flux/math-doc/document/img53.png +0 -0
  238. data/doc/ep_flux/math-doc/document/img54.png +0 -0
  239. data/doc/ep_flux/math-doc/document/img55.png +0 -0
  240. data/doc/ep_flux/math-doc/document/img56.png +0 -0
  241. data/doc/ep_flux/math-doc/document/img57.png +0 -0
  242. data/doc/ep_flux/math-doc/document/img58.png +0 -0
  243. data/doc/ep_flux/math-doc/document/img59.png +0 -0
  244. data/doc/ep_flux/math-doc/document/img6.png +0 -0
  245. data/doc/ep_flux/math-doc/document/img60.png +0 -0
  246. data/doc/ep_flux/math-doc/document/img61.png +0 -0
  247. data/doc/ep_flux/math-doc/document/img62.png +0 -0
  248. data/doc/ep_flux/math-doc/document/img63.png +0 -0
  249. data/doc/ep_flux/math-doc/document/img64.png +0 -0
  250. data/doc/ep_flux/math-doc/document/img65.png +0 -0
  251. data/doc/ep_flux/math-doc/document/img66.png +0 -0
  252. data/doc/ep_flux/math-doc/document/img67.png +0 -0
  253. data/doc/ep_flux/math-doc/document/img68.png +0 -0
  254. data/doc/ep_flux/math-doc/document/img69.png +0 -0
  255. data/doc/ep_flux/math-doc/document/img7.png +0 -0
  256. data/doc/ep_flux/math-doc/document/img70.png +0 -0
  257. data/doc/ep_flux/math-doc/document/img71.png +0 -0
  258. data/doc/ep_flux/math-doc/document/img72.png +0 -0
  259. data/doc/ep_flux/math-doc/document/img73.png +0 -0
  260. data/doc/ep_flux/math-doc/document/img74.png +0 -0
  261. data/doc/ep_flux/math-doc/document/img75.png +0 -0
  262. data/doc/ep_flux/math-doc/document/img76.png +0 -0
  263. data/doc/ep_flux/math-doc/document/img77.png +0 -0
  264. data/doc/ep_flux/math-doc/document/img78.png +0 -0
  265. data/doc/ep_flux/math-doc/document/img79.png +0 -0
  266. data/doc/ep_flux/math-doc/document/img8.png +0 -0
  267. data/doc/ep_flux/math-doc/document/img80.png +0 -0
  268. data/doc/ep_flux/math-doc/document/img81.png +0 -0
  269. data/doc/ep_flux/math-doc/document/img82.png +0 -0
  270. data/doc/ep_flux/math-doc/document/img83.png +0 -0
  271. data/doc/ep_flux/math-doc/document/img84.png +0 -0
  272. data/doc/ep_flux/math-doc/document/img85.png +0 -0
  273. data/doc/ep_flux/math-doc/document/img86.png +0 -0
  274. data/doc/ep_flux/math-doc/document/img87.png +0 -0
  275. data/doc/ep_flux/math-doc/document/img88.png +0 -0
  276. data/doc/ep_flux/math-doc/document/img89.png +0 -0
  277. data/doc/ep_flux/math-doc/document/img9.png +0 -0
  278. data/doc/ep_flux/math-doc/document/img90.png +0 -0
  279. data/doc/ep_flux/math-doc/document/img91.png +0 -0
  280. data/doc/ep_flux/math-doc/document/img92.png +0 -0
  281. data/doc/ep_flux/math-doc/document/img93.png +0 -0
  282. data/doc/ep_flux/math-doc/document/img94.png +0 -0
  283. data/doc/ep_flux/math-doc/document/img95.png +0 -0
  284. data/doc/ep_flux/math-doc/document/img96.png +0 -0
  285. data/doc/ep_flux/math-doc/document/img97.png +0 -0
  286. data/doc/ep_flux/math-doc/document/img98.png +0 -0
  287. data/doc/ep_flux/math-doc/document/img99.png +0 -0
  288. data/doc/ep_flux/math-doc/document/index.html +101 -0
  289. data/doc/ep_flux/math-doc/document/internals.pl +258 -0
  290. data/doc/ep_flux/math-doc/document/labels.pl +265 -0
  291. data/doc/ep_flux/math-doc/document/next.png +0 -0
  292. data/doc/ep_flux/math-doc/document/next_g.png +0 -0
  293. data/doc/ep_flux/math-doc/document/node1.html +104 -0
  294. data/doc/ep_flux/math-doc/document/node10.html +164 -0
  295. data/doc/ep_flux/math-doc/document/node11.html +86 -0
  296. data/doc/ep_flux/math-doc/document/node12.html +166 -0
  297. data/doc/ep_flux/math-doc/document/node13.html +897 -0
  298. data/doc/ep_flux/math-doc/document/node14.html +1065 -0
  299. data/doc/ep_flux/math-doc/document/node15.html +72 -0
  300. data/doc/ep_flux/math-doc/document/node16.html +81 -0
  301. data/doc/ep_flux/math-doc/document/node2.html +82 -0
  302. data/doc/ep_flux/math-doc/document/node3.html +91 -0
  303. data/doc/ep_flux/math-doc/document/node4.html +149 -0
  304. data/doc/ep_flux/math-doc/document/node5.html +330 -0
  305. data/doc/ep_flux/math-doc/document/node6.html +99 -0
  306. data/doc/ep_flux/math-doc/document/node7.html +98 -0
  307. data/doc/ep_flux/math-doc/document/node8.html +83 -0
  308. data/doc/ep_flux/math-doc/document/node9.html +140 -0
  309. data/doc/ep_flux/math-doc/document/prev.png +0 -0
  310. data/doc/ep_flux/math-doc/document/prev_g.png +0 -0
  311. data/doc/ep_flux/math-doc/document/up.png +0 -0
  312. data/doc/ep_flux/math-doc/document/up_g.png +0 -0
  313. data/doc/gdir.html +412 -0
  314. data/doc/gdir_client.html +16 -0
  315. data/doc/gdir_connect_ftp-like.html +61 -0
  316. data/doc/gdir_server.html +45 -0
  317. data/doc/ggraph.html +1119 -0
  318. data/doc/gpcat.html +45 -0
  319. data/doc/gpcut.html +47 -0
  320. data/doc/gphys.html +624 -0
  321. data/doc/gphys_fft.html +324 -0
  322. data/doc/gphys_grads_io.html +69 -0
  323. data/doc/gphys_grib_io.html +82 -0
  324. data/doc/gphys_io.html +183 -0
  325. data/doc/gphys_io_common.html +18 -0
  326. data/doc/gphys_netcdf_io.html +283 -0
  327. data/doc/gplist.html +24 -0
  328. data/doc/gpmath.html +52 -0
  329. data/doc/gpmaxmin.html +32 -0
  330. data/doc/gpprint.html +35 -0
  331. data/doc/gpview.html +349 -0
  332. data/doc/grads2nc_with_gphys.html +21 -0
  333. data/doc/grads_gridded.html +307 -0
  334. data/doc/grib.html +149 -0
  335. data/doc/grid.html +224 -0
  336. data/doc/index.html +145 -0
  337. data/doc/index.rd +138 -0
  338. data/doc/netcdf_convention.html +136 -0
  339. data/doc/unumeric.html +176 -0
  340. data/doc/update +69 -0
  341. data/doc/update_rdoc +8 -0
  342. data/doc/varray.html +299 -0
  343. data/doc/varraycomposite.html +67 -0
  344. data/ext_init.c +1 -0
  345. data/extconf.rb +16 -6
  346. data/gphys.gemspec +33 -26
  347. data/interpo.c +1 -1
  348. data/lib/numru/dclext.rb +718 -546
  349. data/lib/numru/derivative.rb +2 -0
  350. data/lib/numru/ganalysis.rb +38 -0
  351. data/lib/numru/ganalysis/beta_plane.rb +103 -0
  352. data/lib/numru/ganalysis/eof.rb +3 -2
  353. data/lib/numru/ganalysis/fitting.rb +559 -0
  354. data/lib/numru/ganalysis/histogram.rb +36 -19
  355. data/lib/numru/ganalysis/log_p.rb +130 -0
  356. data/lib/numru/ganalysis/met.rb +396 -2
  357. data/lib/numru/ganalysis/met_z.rb +300 -0
  358. data/lib/numru/ganalysis/planet.rb +17 -7
  359. data/lib/numru/ganalysis/qg.rb +685 -0
  360. data/lib/numru/ganalysis/sigma_coord.rb +90 -0
  361. data/lib/numru/gdir.rb +2 -1
  362. data/lib/numru/ggraph.rb +204 -60
  363. data/lib/numru/ggraph_on_merdional_section.rb +1 -1
  364. data/lib/numru/gphys.rb +6 -0
  365. data/lib/numru/gphys/assoccoords.rb +18 -3
  366. data/lib/numru/gphys/axis.rb +209 -8
  367. data/lib/numru/gphys/derivative.rb +11 -0
  368. data/lib/numru/gphys/gphys.rb +539 -48
  369. data/lib/numru/gphys/gphys_dim_op.rb +331 -0
  370. data/lib/numru/gphys/gphys_fft.rb +48 -2
  371. data/lib/numru/gphys/gphys_io.rb +241 -13
  372. data/lib/numru/gphys/gphys_netcdf_io.rb +77 -39
  373. data/lib/numru/gphys/gphys_nusdas_io.rb +3 -0
  374. data/lib/numru/gphys/grib.rb +133 -54
  375. data/lib/numru/gphys/grib_params.rb +26 -3
  376. data/lib/numru/gphys/grid.rb +75 -34
  377. data/lib/numru/gphys/interpolate.rb +24 -10
  378. data/lib/numru/gphys/mdstorage.rb +160 -0
  379. data/lib/numru/gphys/netcdf_convention.rb +4 -2
  380. data/lib/numru/gphys/subsetmapping.rb +0 -1
  381. data/lib/numru/gphys/unumeric.rb +50 -5
  382. data/lib/numru/gphys/varray.rb +15 -30
  383. data/lib/numru/gphys/varraycomposite.rb +107 -24
  384. data/lib/numru/gphys/varraynetcdf.rb +9 -3
  385. data/lib/numru/gphys/version.rb +5 -0
  386. data/sample/druby_cli1.rb +2 -0
  387. data/sample/druby_cli2.rb +0 -6
  388. data/sample/druby_serv2.rb +0 -13
  389. data/spec/gphys_spec.rb +11 -0
  390. data/spec/spec_helper.rb +2 -0
  391. data/test/test_assoccoords.rb +102 -0
  392. data/test/test_axis.rb +61 -0
  393. data/test/test_fitting.rb +116 -0
  394. data/test/test_gphys.rb +20 -0
  395. data/test/test_met_z.rb +96 -0
  396. data/test/test_sigma_coord.rb +50 -0
  397. data/{test → test_old}/eof_slp.rb +0 -0
  398. data/{test → test_old}/mltbit.dat +0 -0
  399. data/{test → test_old}/test_ep_flux.rb +0 -0
  400. data/{test → test_old}/test_multibitIO.rb +0 -0
  401. metadata +530 -191
  402. data/README.md +0 -29
  403. data/lib/gphys.rb +0 -2
  404. data/lib/numru/dclext_datetime_ax.rb +0 -220
  405. data/lib/version.rb +0 -3
@@ -0,0 +1,331 @@
1
+ # = Operations along a dimension such as running mean
2
+ #
3
+ # (Plan: binning will be supported too)
4
+
5
+ require "numru/gphys/gphys"
6
+ require 'numru/gphys_ext' # extension library
7
+
8
+ module NumRu
9
+ class GPhys
10
+ BC_SIMPLE = 10 # enum in convol_filter.c
11
+ BC_CYCLIC = 11 # enum in convol_filter.c
12
+ BC_TRIM = 12 # enum in convol_filter.c
13
+
14
+ @@default_missval = 9.9692099683868690e+36 # NC_FILL_DOUBLE/FLOAT ~15*2^119
15
+
16
+ # Running mean along a dimension (with optional weight specification).
17
+ #
18
+ # ARGUMENTS
19
+ # * dim (Integer or String) : the dimension
20
+ # * len_or_wgt : If Integer, specifies the length; if 1D NArray,
21
+ # specifies the weight (e.g., NArray[1.0, 2.0, 1.0] for
22
+ # the 1-2-1 smooting)
23
+ # * bc (Integer; optional) : Speficy one of the folloing:
24
+ # * GPhys::BC_SIMPLE (default) : Averaging is trucated at the boundaries
25
+ # (the number of grid points used is reduced near the boundaries).
26
+ # The shape of the object is conserved.
27
+ # * GPhys::BC_CYCLIC : Cyclic boundary condition. Shape conserved.
28
+ # * GPhys::BC_TRIM : Grids near the boundaries are trimmed to
29
+ # secure the number of grid points to average.
30
+ # Shape not conserved; length along the dim is reduced by (len-1).
31
+ # * nminvalid (Integer; optional; defualt=1):
32
+ # This parameter is used only when the data have missing.
33
+ # Minimum number of grid points needed for averaging.
34
+ # Must be from 1 to len.
35
+ #
36
+ # RETURN VALUE
37
+ # * a GPhys
38
+ #
39
+ # REMARK AND LIMITATION
40
+ # * If the length of the running mean is even number, fewer
41
+ # grid points are used from the "left" side; e.g.,
42
+ # If len is 6, result[2] is a mean over self[0]..self[5].
43
+ # * Regardless the na_type of self, double is used for avaraging, so:
44
+ # * This method does not support complex numbers.
45
+ #
46
+ def running_mean(dim, len_or_wgt=nil, bc=BC_SIMPLE, nminvalid=1)
47
+
48
+ #< process arguments >
49
+
50
+ dim = dim_index(dim) # to handle String or negative specification
51
+
52
+ case len_or_wgt
53
+ when nil
54
+ raise ArgumentError, "You need to specify the length (Integer) or the weight (1D NArray) as the 2nd argument"
55
+ when Integer
56
+ # len_or_wgt is a length
57
+ len = len_or_wgt
58
+ wgt = NArray.float(len).fill!(1.0)
59
+ else
60
+ # len_or_wgt is a weight
61
+ wgt = len_or_wgt
62
+ if (!wgt.respond_to?(:rank) || wgt.rank != 1)
63
+ raise ArgumentError, "wgt: expect a 1D NArray(-like obj)"
64
+ end
65
+ len = wgt.length
66
+ end
67
+
68
+ #< calc running mean >
69
+
70
+ vi = self.val
71
+ if (vi.typecode > NArray::DFLOAT)
72
+ raise("This method supports only real or integer data")
73
+ end
74
+ if vi.is_a?(NArrayMiss)
75
+ vi, missval = nam2na_missval(vi)
76
+ vo = c_running_mean(vi,dim,wgt,bc,missval,nminvalid)
77
+ vo = NArrayMiss.to_nam(vo, vo.ne(missval) )
78
+ else
79
+ vo = c_running_mean(vi,dim,wgt,bc)
80
+ end
81
+
82
+ #< grid >
83
+
84
+ if (bc == BC_TRIM)
85
+ fst = (len-1)/2 # if odd len/2, if even len/2-1
86
+ lst = -(len/2) - 1
87
+ grid = self.grid[ *([true]*dim + [fst..lst, false]) ]
88
+ else
89
+ grid = self.grid
90
+ end
91
+
92
+ #< result >
93
+ vvo = VArray.new( vo, self.data, self.name ) # Inherit name & attrs
94
+ GPhys.new( grid, vvo )
95
+
96
+ end
97
+
98
+ # Binning along a dimension (mean)
99
+ #
100
+ # The values are averaged every "len" grids; unlike running_mean
101
+ # the number of grids is reduced to 1/len.
102
+ # Currently, the only available boundary condition is BC_TRIM.
103
+ #
104
+ # ARGUMENTS
105
+ # * dim (Integer or String) : the dimension
106
+ # * len (Integer): length of the bin
107
+ # * nminvalid (Integer; optional; defualt=1): Effective only for data with
108
+ # missing. Minimum number of grid points needed for averaging (1 to len).
109
+ #
110
+ # RETURN VALUE
111
+ # * a GPhys
112
+ #
113
+ def bin_mean(dim, len, nminvalid=1)
114
+ dim = dim_index(dim) # to handle String or negative specification
115
+ GPhys.new( grid.binning(dim, len), data.bin_mean(dim, len, nminvalid) )
116
+ end
117
+
118
+ # Binning along a dimension (summation)
119
+ #
120
+ # Similar to bin_mean, but the values are simply summed without averaging
121
+ #
122
+ # ARGUMENTS
123
+ # * dim (Integer or String) : the dimension
124
+ # * len (Integer): length of the bin
125
+ # * nminvalid (Integer; optional; defualt=1): Effective only for data with
126
+ # missing. Minimum number of grid points needed for averaging (1 to len).
127
+ #
128
+ # RETURN VALUE
129
+ # * a GPhys
130
+ #
131
+ def bin_sum(dim, len, nminvalid=1)
132
+ dim = dim_index(dim) # to handle String or negative specification
133
+ GPhys.new( grid.binning(dim, len), data.bin_sum(dim, len, nminvalid) )
134
+ end
135
+
136
+ ##### private #########
137
+ def nam2na_missval(nam)
138
+ missval = ( (a=get_att('_FillValue')) ? a[0] : nil ) ||
139
+ ( (a=get_att('missing_value')) ? a[0] : nil ) ||
140
+ @@default_missval
141
+ [ nam.to_na(missval), missval ]
142
+ end
143
+ private :nam2na_missval
144
+
145
+ #def convolution(dim, g=nil, bc=BC_SIMPLE)
146
+ #end
147
+ end
148
+
149
+ class VArray
150
+ @@default_missval = 9.9692099683868690e+36 # NC_FILL_DOUBLE/FLOAT ~15*2^119
151
+
152
+ def bin_mean(dim, len, nminvalid=1)
153
+ vi = self.val
154
+ if vi.is_a?(NArrayMiss)
155
+ vi, missval = nam2na_missval(vi)
156
+ vo = c_bin_mean(vi,dim,len,missval,nminvalid) # defined in dim_op.c
157
+ vo = NArrayMiss.to_nam(vo, vo.ne(missval) )
158
+ else
159
+ vo = c_bin_mean(vi,dim,len) # defined in dim_op.c
160
+ end
161
+ VArray.new( vo, self, self.name ) # Inherit name & attrs
162
+ end
163
+
164
+ def bin_sum(dim, len, nminvalid=1)
165
+ vi = self.val
166
+ if vi.is_a?(NArrayMiss)
167
+ vi, missval = nam2na_missval(vi)
168
+ vo = c_bin_sum(vi,dim,len,missval,nminvalid) # defined in dim_op.c
169
+ vo = NArrayMiss.to_nam(vo, vo.ne(missval) )
170
+ else
171
+ vo = c_bin_sum(vi,dim,len) # defined in dim_op.c
172
+ end
173
+ VArray.new( vo, self, self.name ) # Inherit name & attrs
174
+ end
175
+
176
+ ##### private #########
177
+ def nam2na_missval(nam)
178
+ missval = ( (a=get_att('_FillValue')) ? a[0] : nil ) ||
179
+ ( (a=get_att('missing_value')) ? a[0] : nil ) ||
180
+ @@default_missval
181
+ [ nam.to_na(missval), missval ]
182
+ end
183
+ private :nam2na_missval
184
+
185
+ end
186
+
187
+ class Grid
188
+ def binning(dim, len)
189
+ dim = dim_index(dim) # to handle String or negative specification
190
+
191
+ #< axes >
192
+ axes = (0...rank).collect{|d| axis(d)}
193
+ axes[dim] = axes[dim].binning(len) # bin the dim-th axis
194
+ newgrid = Grid.new(*axes)
195
+
196
+ #< assoc coords are retained if it does not have the dim >
197
+ if assoc_coords
198
+ dimname = self.axis(dim).name
199
+ acs = Array.new
200
+ assoccoordnames.each do |nm|
201
+ ac = assoc_coord_gphys(nm)
202
+ acs.push(ac) if !ac.dimnames.include?(dimname)
203
+ end
204
+ newgrid.set_assoc_coords(acs) if acs.length > 0
205
+ end
206
+
207
+ #< return >
208
+ newgrid
209
+ end
210
+ end
211
+
212
+ class Axis
213
+ def binning(len)
214
+ if cell? && cell_center?
215
+ c = cell_center.bin_mean(0,len)
216
+ b = cell_bounds[ {0..-1=>len} ]
217
+ newax = Axis.new(true).set_cell(c,b)
218
+ newax = axcel.dup.set_pos_to_center
219
+ else
220
+ newax = Axis.new().set_pos( pos.bin_mean(0,len) )
221
+ end
222
+ newax
223
+ end
224
+ end
225
+ end
226
+
227
+ ######################################################
228
+ ## < test >
229
+ if $0 == __FILE__
230
+ require 'test/unit'
231
+
232
+ class TC_GPhys_grid_op < Test::Unit::TestCase
233
+ include NumRu
234
+ def setup
235
+ nx = 11
236
+ ny = 5
237
+ vx = VArray.new( NArray.float(nx).indgen! ).rename("x")
238
+ vy = VArray.new( NArray.float(ny).indgen! ).rename("y")
239
+ xax = Axis.new().set_pos(vx)
240
+ yax = Axis.new().set_pos(vy)
241
+ grid = Grid.new(xax, yax)
242
+ z = VArray.new( na = NArray.float(nx, ny).indgen! % 5, nil, "z" )
243
+ zu = VArray.new( NArray.float(nx, ny).fill(3.0), nil, "z" )
244
+
245
+ @gp = GPhys.new(grid,z)
246
+ @gpu = GPhys.new(grid,zu)
247
+
248
+ nam = NArrayMiss.to_nam(na)
249
+ nam.invalidation(1,1)
250
+ nam.invalidation(2,2)
251
+ (1..4).each{|i| nam.invalidation(i,3)}
252
+ zm = VArray.new( nam, nil, "zm" )
253
+ @gpm = GPhys.new(grid,zm)
254
+
255
+ end
256
+
257
+ def test_0_0_running_mean
258
+ puts "*** running_mean: basic ***"
259
+ p(v0 = @gp.val)
260
+
261
+ p(v = @gp.running_mean(0,3).val)
262
+ assert_in_delta(v[4,0], 2.33333, 1e-4)
263
+
264
+ p(v = @gp.running_mean(1,3,GPhys::BC_TRIM).val)
265
+ assert_in_delta(v[2,1], 2.33333, 1e-4)
266
+
267
+ p(v = @gpu.running_mean(0,3,GPhys::BC_TRIM).val)
268
+ assert_in_delta(v[0,0], 3.0, 1e-4)
269
+ assert_equal(v.shape[0], v0.shape[0]-2)
270
+
271
+ p(v = @gp[0..9,true].running_mean(0,5,GPhys::BC_CYCLIC).val)
272
+ assert_in_delta(v[0,0], 2.0, 1e-4)
273
+ end
274
+
275
+ def test_0_1_running_mean
276
+ puts "*** running_mean: weight ***"
277
+ wgt = NArray[1.0, 2.0, 1.0]
278
+ p @gp.val
279
+ p(v = @gp.running_mean(0,wgt).val)
280
+ assert_in_delta(v[4,0], (3.0+4.0*2)/4, 1e-4)
281
+ end
282
+
283
+ def test_0_2_running_mean
284
+ puts "*** running_mean: with data missing ***"
285
+ p @gpm.val
286
+ p(v = @gpm.running_mean(0,3).val)
287
+ assert_in_delta(v[2,2], 1.5, 1e-4)
288
+ assert(v[2,3] > 1e30) # missing value
289
+ end
290
+
291
+ def test_1_0_bin_mean
292
+ puts "*** bin_mean ***"
293
+ p @gp.val
294
+ b = @gp.bin_mean(0,3)
295
+ v = b.val
296
+ p v, b.coord(0).val, b.coord(1).val
297
+ assert_in_delta(b.val[1,1], 5.0/3.0, 1e-4)
298
+ assert_in_delta(b.coord(0).val[1], 4.0, 1e-4)
299
+ end
300
+
301
+ def test_1_1_bin_mean
302
+ puts "*** bin_mean: with data missing ***"
303
+ p @gpm.val
304
+ b = @gpm.bin_mean(0,3,2)
305
+ v = b.val
306
+ p v, b.coord(0).val, b.coord(1).val
307
+ assert_in_delta(v[0,2], 2.5, 1e-4)
308
+ assert(v[0,3] > 1e30) # missing value
309
+ end
310
+
311
+ def test_2_0_bin_sum
312
+ puts "*** bin_sum ***"
313
+ p @gp.val
314
+ b = @gp.bin_sum(0,3)
315
+ v = b.val
316
+ p v, b.coord(0).val, b.coord(1).val
317
+ assert_in_delta(b.val[1,1], 5.0, 1e-4)
318
+ end
319
+
320
+ def test_2_1_bin_sum
321
+ puts "*** bin_sum: with data missing ***"
322
+ p @gpm.val
323
+ b = @gpm.bin_sum(0,3,2)
324
+ v = b.val
325
+ p v, b.coord(0).val, b.coord(1).val
326
+ assert_in_delta(v[0,2], 5.0, 1e-4)
327
+ assert(v[0,3] > 1e30) # missing value
328
+ end
329
+
330
+ end
331
+ end
@@ -439,6 +439,8 @@ module NumRu
439
439
  else
440
440
  val = val.to_na
441
441
  end
442
+ elsif val.is_a?(NArrayMiss) && val.count_invalid == 0
443
+ val = val.to_na
442
444
  end
443
445
  fcoef = FFTW3.fft( val, dir, *dims )
444
446
  else
@@ -454,6 +456,8 @@ module NumRu
454
456
  else
455
457
  val = val.to_na
456
458
  end
459
+ elsif val.is_a?(NArrayMiss) && val.count_invalid == 0
460
+ val = val.to_na
457
461
  end
458
462
  fcoef = FFTW.fftw( val, dir )
459
463
  end
@@ -498,6 +502,30 @@ module NumRu
498
502
  gfc
499
503
  end
500
504
 
505
+ def fft_deriv(dim)
506
+ tp = self.data.typecode
507
+ fc = self.fft(false,dim)
508
+ wn = fc.coord(dim)
509
+ k = wn.val.to_type(NArray::Complex)
510
+ n = k.length
511
+ n2a = (n-1)/2
512
+ n2b = [n/2 + 1, n-1].min # min to avoid error if n=2 (though meaningless)
513
+ kmx = k[-1]+k[1]
514
+ ik = NArray.complex(n)
515
+ ik[0..n2a] = k[0..n2a]*Complex::I
516
+ ik[n2b..-1] = (k[n2b..-1]-kmx) * Complex::I
517
+ dim.times{ik.newdim!(0)}
518
+ (self.rank-dim-1).times{ik.newdim!(-1)}
519
+ fc.replace_val(fc.val*ik)
520
+ deriv = fc.fft(true,dim)
521
+ deriv.units = deriv.units * wn.units
522
+ if tp >= NArray::SCOMPLEX
523
+ deriv
524
+ else
525
+ deriv.real
526
+ end
527
+ end
528
+
501
529
  def __predefined_coord_units_conversion(coord)
502
530
  case coord.units
503
531
  when Units["degree"]
@@ -766,9 +794,9 @@ if $0 == __FILE__
766
794
  include NMath
767
795
 
768
796
  # < make a GPhys from scratch >
769
- vx = VArray.new( NArray.float(11).indgen! * (3*Math::PI/11) ).rename("x")
797
+ vx = VArray.new( NArray.float(11).indgen! * (2*Math::PI/11) ).rename("x")
770
798
  vx.units = 'km'
771
- vy = VArray.new( NArray.float(8).indgen! * (3*Math::PI/8) ).rename("y")
799
+ vy = VArray.new( NArray.float(8).indgen! * (2*Math::PI/8) ).rename("y")
772
800
  vy.units = 'km'
773
801
  xax = Axis.new().set_pos(vx)
774
802
  #yax = Axis.new(true).set_cell_guess_bounds(vy).set_pos_to_center
@@ -880,6 +908,24 @@ if $0 == __FILE__
880
908
  gpf = gp.phase_velocity_filter(0, 2, -0.3, -0.01, 1/kconv, 1/fconv)
881
909
  GGraph::tone gpf[true,0,true],true,"color_bar"=>true
882
910
 
911
+ ###
912
+ grid = Grid.new(xax, yax)
913
+ a = NArray.float(vx.length, vy.length)
914
+ a[] = sin(2*vx.val.newdim(1)) * cos(vy.val.newdim(0))
915
+ v = VArray.new( a )
916
+ v.units = 'm/s'
917
+ gpz = GPhys.new(grid,v)
918
+
919
+ dim = 0
920
+ x = gpz.coord(dim)
921
+ gp_x = gpz.fft_deriv(dim)
922
+ p gp_x
923
+ dim = 1
924
+ gp_y = gpz.fft_deriv(dim)
925
+ p gp_y
926
+ GGraph::tone gpz,true,"color_bar"=>true
927
+ GGraph::tone gp_x,true,"color_bar"=>true
928
+ GGraph::tone gp_y,true,"color_bar"=>true
883
929
 
884
930
  DCL.grcls
885
931
  end
@@ -7,6 +7,7 @@ begin
7
7
  require "numru/gphys/gphys_hdfeos5_io"
8
8
  rescue LoadError
9
9
  end
10
+ require "numru/gphys/mdstorage" # for regexp2files
10
11
 
11
12
 
12
13
  =begin
@@ -24,8 +25,66 @@ For example, (('GPhys::IO.open(file, name)')) simply calls
24
25
 
25
26
  ==Module functions
26
27
 
27
- ---open(files, varname)
28
+ ---open(file, varname)
29
+ Opens a GPhys in (({file})) having the name (({varname})).
30
+
31
+ ARGUMENTS
32
+ * file (String, NetCDF, GRIB,.. etc, or Array, NArray, Regexp) :
33
+ Specifies the file. Path if String; a File pointer if NetCDF etc..
34
+ The processing is forwarded to (('open_multi')), if this argument is
35
+ an Array, NArray, or Regexp.
36
+ * varname (String) : name of the variable
37
+
38
+ RETURN VALUE
39
+ * a GPhys
40
+
41
+ ---open_multi(files, varname)
42
+ Opens a GPhys by combining a variable across multiple files.
43
+ It initializes GPhys objects over the files by calling (('open')) and
44
+ unites them into a single GPhys object by using (({GPhys.join})) or
45
+ (({GPhys.join_md})).
46
+
47
+ ARGUMENTS
48
+ * files (Array, NArray (NArray.object), or Regexp) : Specifies the files.
49
+ * when Array, it must consist of paths or file pointers
50
+ (that are accepted by (('open'))).
51
+ All coordinates of the variable in the files are scanned,
52
+ and a joined object is constructed properly.
53
+ Thus, you can simply put subsets of a 2D tiling in a simple
54
+ non-nested 1D Array. (({GPhys.join})) is used in this case.
55
+ * when NArray, it must consist of paths or file pointers
56
+ (that are accepted by (('open'))).
57
+ Each dimension with multiple elements must correspond
58
+ to a dimension along which joining is made.
59
+ For example, a 2D tiling can be specified as
60
+ files = NArray.to_na([['f00.nc','f10.nc'],['f01.nc','f11.nc']])
61
+ gp = GPhys::IO.open_multi( files, "f" )
62
+ (({GPhys.join_md})) is used in this case.
63
+ * When Regexp, similar to when NArray, but expresses the paths.
64
+ The dimensions to join is specified by "captures"
65
+ (parentheses). For example, the above 2D tiling can be specified as
66
+ files = /f(\d)(\d).nc/
67
+ gp = GPhys::IO.open_multi( files, "f" )
68
+ The regexp can contain a directory path (e.g., /dir\/sub\/f(\d)(d).nc/),
69
+ but the directory part must be unique (i.e., a simple string),
70
+ so only a single directly can be specified. All captures must
71
+ be in the part representing the file names (in the directory).
72
+ (({GPhys.join_md})) is used in this case.
73
+ * varname (String) : name of the variable
74
+
75
+ RETURN VALUE
76
+ * a GPhys
77
+
28
78
  ---write(file, gphys, name=nil)
79
+ Writes a GPhys object in a file
80
+
81
+ ARGUMENTS
82
+ * file (NetCDF, GRIB,.. etc) : the file. Writing must be permitted.
83
+ To close (finalize) it after writing is left to the user.
84
+ * gphys (GPhys) : the GPhys object to write
85
+ * name (String; optional) : if specified, this name is used in the file
86
+ rather than the name of gphys
87
+
29
88
  ---write_grid(file, grid_or_gphys)
30
89
  ---each_along_dims_write(gphyses, files, *loopdims){...} # a block is expected
31
90
  ---var_names(file)
@@ -36,15 +95,13 @@ For example, (('GPhys::IO.open(file, name)')) simply calls
36
95
  Figures out the file type supported in this module.
37
96
 
38
97
  ARGUMENTS
39
- * file (String, Regexp, NetCDF, Grib, or GrADS_Gridded) :
98
+ * file (String, NetCDF, Grib, or GrADS_Gridded) :
40
99
  What to return is of course obvious if it is
41
100
  NetCDF, Grib, or GrADS_Gridded. If it is a String,
42
101
  it is assumed to be a path of a file, and the file type
43
102
  is determined by its suffix when 'nc', 'ctl', or 'grib';
44
103
  In other cases, the type is figured out by reading in
45
- a few bytes from the beginning. If Regexp, currently,
46
- a NetCDF is assumed, since only NetCDF_IO.open supports
47
- Regexp.
104
+ a few bytes from the beginning.
48
105
 
49
106
  RETURN VALUE
50
107
  * GPhys::IO::NETCDF, GPhys::IO::GRIB, or GPhys::IO::GRADS,
@@ -127,7 +184,49 @@ module NumRu
127
184
 
128
185
  ## // module functions to be defined in specific IO modules -->
129
186
  def open(file, varname)
130
- file2specific_module(file)::open(file, varname)
187
+ case file
188
+ when Array, NArray, Regexp
189
+ open_multi(file, varname)
190
+ else
191
+ file2specific_module(file)::open(file, varname)
192
+ end
193
+ end
194
+
195
+ def open_multi(files, varname)
196
+ case files
197
+ when Array
198
+ GPhys.join( files.collect{|f| open(f,varname)} )
199
+ when NArray
200
+ GPhys.join_md( files.collect{|f| open(f,varname)} )
201
+ when Regexp
202
+ GPhys.join_md( regexp2files(files).collect{|f| open(f,varname)} )
203
+ end
204
+ end
205
+
206
+ def regexp2files( pat )
207
+ if /^(.*)\\?\/(.*)$/ =~ (pat.source)
208
+ d=$1
209
+ f=$2
210
+ dir = d.gsub(/\\/,'') + '/'
211
+ pat = Regexp.new(f)
212
+ else
213
+ dir = './'
214
+ end
215
+ flstore = MDStorage.new(1)
216
+ lbs = Array.new
217
+ Dir.open(dir).each do |fn|
218
+ if pat =~ fn
219
+ raise(ArgumentError,"has no capture; need one or more") if $1.nil?
220
+ idx = Array.new
221
+ Regexp.last_match.captures.each_with_index{|lb,i|
222
+ flstore.add_dim if flstore.rank == i # rank smaller by 1 -> add
223
+ lbs[i] = Array.new if lbs[i].nil?
224
+ idx.push( lbs[i].index(lb) || lbs[i].push(lb) && lbs[i].length-1 )
225
+ }
226
+ flstore[*idx] = NetCDF.open(dir+fn)
227
+ end
228
+ end
229
+ flstore.to_na
131
230
  end
132
231
 
133
232
  def write(file, gphys, name=nil)
@@ -203,8 +302,6 @@ module NumRu
203
302
  return NUSDAS
204
303
  when Gtool3
205
304
  return GTOOL3
206
- when Regexp
207
- return NETCDF # So far, only NetCDF_IO supports Regexp.
208
305
  when *@@nc_pattern
209
306
  return NETCDF
210
307
  when *@@grad_pattern
@@ -215,7 +312,7 @@ module NumRu
215
312
  return NUSDAS
216
313
  when String
217
314
  return NETCDF if /^http:\/\// =~ file # assume a DODS URL
218
- return nil unless File.exist?(file)
315
+ raise ArgumentError, "File not found: #{file}" unless File.exist?(file)
219
316
  return NETCDF if NetCDF_IO.is_a_NetCDF?(file)
220
317
  return GRADS if GrADS_IO.is_a_GrADS?(file)
221
318
  return GRIB if Grib_IO.is_a_Grib?(file)
@@ -232,6 +329,8 @@ module NumRu
232
329
  return He5 if HE5_IO.is_a_HE5?(file)
233
330
  end
234
331
  end
332
+ raise "cannot specify the file type of \""+ file + \
333
+ "\"; maybe unsupported format."
235
334
  return nil
236
335
  end
237
336
 
@@ -289,6 +388,13 @@ module NumRu
289
388
  raise "invalid URL: '[@|/]' between path & variable is not found\n\n" +
290
389
  "URL format: " + GTURLfmt
291
390
  end
391
+ if /[\*\?]/ =~ file ## match file names if wildcard expression included.
392
+ raise "\n Any files did not match the given expression: \""+file+\
393
+ "\" \n" if Dir[file].empty?
394
+ file = Dir[file].sort
395
+ elsif (!File.exist?(file))
396
+ raise "File specified by gturl \"#{gturl}\" was not found"
397
+ end
292
398
  if /,/ =~ var
293
399
  slice = Hash.new
294
400
  cut_slice = Hash.new
@@ -328,18 +434,66 @@ module NumRu
328
434
  cut_slice = nil
329
435
  thinning = nil
330
436
  end
437
+ if /[\*\?]/ =~ var ## match var names if wildcard expression included.
438
+ var_reg = var.gsub("*",".*").gsub("?",".") # convert to regular exp.
439
+ case file
440
+ when String
441
+ vars = GPhys::IO.var_names_except_coordinates(file)
442
+ when Array
443
+ vars_t = file.collect{|f| GPhys::IO.var_names_except_coordinates(f)}
444
+ vars = vars_t.flatten.uniq
445
+ end
446
+ vars_matched = vars.select{|v| v.match(/#{var_reg}/)}
447
+ if (vars_matched.empty?)
448
+ raise "\n Any variables in \"#{file}\" did not match the given
449
+ expression: \"#{var}\".\n Included variable(s): #{vars.join(", ")}."
450
+ end
451
+ # put the variable name by String if the number of matched variable is
452
+ # one, otherwise by Array of Strings.
453
+ var = vars_matched.length == 1 ? vars_matched[0] : vars_matched
454
+ end
331
455
  [file, var, slice, cut_slice, thinning]
332
456
  end # def parse_gturl
333
457
 
334
458
  def open_gturl(gturl)
335
459
  file, var, slice, cut_slice, thinning = GPhys::IO.parse_gturl(gturl)
336
- gp = GPhys::IO.open(file,var)
460
+ if var.is_a?(Array)
461
+ raise "This method treats a gturl of a single GPhys object. " +
462
+ "Use open_multi_gturl to treat a gturl of multiple objects."
463
+ end
464
+ gp = GPhys::IO.open(file,var)
337
465
  gp = gp[slice] if slice
338
466
  gp = gp.cut(cut_slice) if cut_slice
339
467
  gp = gp[thinning] if thinning
340
468
  gp
341
469
  end # def open_gturl
342
470
 
471
+ def open_multi_gturl(gturl)
472
+ files, vars, slice, cut_slice, thinning = GPhys::IO.parse_gturl(gturl)
473
+ vars = [vars] unless vars.is_a?(Array)
474
+ gp_array = Array.new
475
+ vars.each do |v|
476
+ begin
477
+ gps = [ GPhys::IO.open(files,v) ] # opened as a single GPhys
478
+ rescue ArgumentError
479
+ if files.is_a?(Array)
480
+ # gturl may designate multiple GPhys objects
481
+ gps = files.collect{|f| gp = GPhys::IO.open(f,v) }
482
+ else
483
+ raise $! # it must have been a real error
484
+ end
485
+ end
486
+ gp_array += gps
487
+ end
488
+ gp_array.map!{|gp|
489
+ gp = gp[slice] if slice
490
+ gp = gp.cut(cut_slice) if cut_slice
491
+ gp = gp[thinning] if thinning
492
+ gp
493
+ }
494
+ gp_array
495
+ end # def open_multi_gturl
496
+
343
497
  def str2gphys(str)
344
498
 
345
499
  case str
@@ -387,7 +541,6 @@ if $0 == __FILE__
387
541
  puts "\n** test str2gphys **\n"
388
542
  p GPhys::IO.str2gphys("../../../testdata/T.jan.nc/T")
389
543
  p GPhys::IO.str2gphys("../../../testdata/T.jan.nc")
390
- exit
391
544
 
392
545
  puts "\n** test NETCDF **\n"
393
546
 
@@ -417,7 +570,7 @@ if $0 == __FILE__
417
570
  GPhys::IO.write(file2,temp_edy)
418
571
  file2.close
419
572
  file3 = NetCDF.create('tmp2.nc')
420
- GPhys::IO.write(file2,temp_xmean)
573
+ GPhys::IO.write(file3,temp_xmean)
421
574
  file3.close
422
575
 
423
576
  p '** test each_along_dims* **'
@@ -465,7 +618,82 @@ if $0 == __FILE__
465
618
  GPhys::IO.write(file2,temp_edy)
466
619
  file2.close
467
620
  file3 = NetCDF.create('tmp2.nc')
468
- GPhys::IO.write(file2,temp_xmean)
621
+ GPhys::IO.write(file3,temp_xmean)
469
622
  file3.close
470
623
 
624
+ puts "\n** test open_multi (1) **"
625
+ # preparation...
626
+ gp = GPhys::IO.open("../../../testdata/T.jan.nc","T")
627
+ GPhys::IO.write(f=NetCDF.create('tmp_z0.nc'),gp[false,0..4]); f.close
628
+ GPhys::IO.write(f=NetCDF.create('tmp_z1.nc'),gp[false,5..-1]); f.close
629
+
630
+ # test...
631
+ gpm = GPhys::IO.open(['tmp_z1.nc','tmp_z0.nc'],"T")
632
+ gp.val == gpm.val ? puts("Test OK") : raise("Test failed")
633
+
634
+ gpm = GPhys::IO.open(/tmp_z(\d).nc/,"T")
635
+ gp.val == gpm.val ? puts("Test OK") : raise("Test failed")
636
+
637
+ puts "\n** test open_multi (2) **"
638
+ # preparation...
639
+ gp = GPhys::IO.open("../../../testdata/T.jan.nc","T")
640
+ GPhys::IO.write(f=NetCDF.create('tmp00.nc'), gp[0..20, 0..8, true]); f.close
641
+ GPhys::IO.write(f=NetCDF.create('tmp10.nc'), gp[21..-1,0..8, true]); f.close
642
+ GPhys::IO.write(f=NetCDF.create('tmp01.nc'), gp[0..20, 9..-1,true]); f.close
643
+ GPhys::IO.write(f=NetCDF.create('tmp11.nc'), gp[21..-1,9..-1,true]); f.close
644
+
645
+ # test...
646
+ files = NArray.to_na([['tmp00.nc','tmp10.nc'],['tmp01.nc','tmp11.nc']])
647
+ gpm = GPhys::IO.open(files,"T")
648
+ gp.val == gpm.val ? puts("Test OK") : raise("Test failed")
649
+
650
+ gpm = GPhys::IO.open(files.transpose(1,0),"T") # fine even if tranposed
651
+ gp.val == gpm.val ? puts("Test OK") : raise("Test failed")
652
+
653
+ files = /tmp(\d)(\d).nc/
654
+ gpm = GPhys::IO.open(files,"T")
655
+ gp.val == gpm.val ? puts("Test OK") : raise("Test failed")
656
+
657
+ # test open_gturl
658
+
659
+ puts "** test open_gturl **"
660
+ sh = GPhys::IO.open_gturl('tmp[01]?.nc@T,lon=20:40,level=1000,lat=0').shape
661
+ sh == [3] ? puts("Test OK") : raise("Test failed")
662
+
663
+ # test open_multi_gturl
664
+
665
+ puts "** test open_multi_gturl **"
666
+
667
+ f=NetCDF.open('tmp11.nc','a')
668
+ f.redef
669
+ GPhys::IO.write(f, gp[21..-1,9..-1,true].copy.rename("R") )
670
+ f.close
671
+
672
+ str = GPhys::IO.open_multi_gturl('tmp[01]?.nc@T').inspect + "\n"
673
+ str += GPhys::IO.open_multi_gturl('tmpE*.nc@T').inspect + "\n"
674
+ str += GPhys::IO.open_multi_gturl('tmp11.nc@*').inspect + "\n"
675
+
676
+ str2comp =<<EOS
677
+ [<NumRu::GPhys grid=<3D grid <axis pos=<NumRu::VArrayComposite shape=[36] #_of_tiles=[2]>>
678
+ <axis pos=<NumRu::VArrayComposite shape=[19] #_of_tiles=[2]>>
679
+ <axis pos=<'level' in 'tmp00.nc' sfloat[9]>>>
680
+ data=<NumRu::VArrayComposite shape=[36, 19, 9] #_of_tiles=[2, 2, 1]>>]
681
+ [<NumRu::GPhys grid=<2D grid <axis pos=<'lat' in 'tmpE0.nc' sfloat[19]>>
682
+ <axis pos=<'level' in 'tmpE0.nc' sfloat[9]>>>
683
+ data=<'T' in 'tmpE0.nc' sfloat[19, 9]>>, <NumRu::GPhys grid=<2D grid <axis pos=<'lat' in 'tmpE1.nc' sfloat[19]>>
684
+ <axis pos=<'level' in 'tmpE1.nc' sfloat[9]>>>
685
+ data=<'T' in 'tmpE1.nc' sfloat[19, 9]>>, <NumRu::GPhys grid=<2D grid <axis pos=<'lat' in 'tmpE2.nc' sfloat[19]>>
686
+ <axis pos=<'level' in 'tmpE2.nc' sfloat[9]>>>
687
+ data=<'T' in 'tmpE2.nc' sfloat[19, 9]>>]
688
+ [<NumRu::GPhys grid=<3D grid <axis pos=<'lon' in 'tmp11.nc' sfloat[15]>>
689
+ <axis pos=<'lat' in 'tmp11.nc' sfloat[10]>>
690
+ <axis pos=<'level' in 'tmp11.nc' sfloat[9]>>>
691
+ data=<'T' in 'tmp11.nc' sfloat[15, 10, 9]>>, <NumRu::GPhys grid=<3D grid <axis pos=<'lon' in 'tmp11.nc' sfloat[15]>>
692
+ <axis pos=<'lat' in 'tmp11.nc' sfloat[10]>>
693
+ <axis pos=<'level' in 'tmp11.nc' sfloat[9]>>>
694
+ data=<'R' in 'tmp11.nc' sfloat[15, 10, 9]>>]
695
+ EOS
696
+
697
+ str == str2comp ? puts("Test OK") : raise("Test failed")
698
+
471
699
  end