0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python > 可変列の3ファイルを合成して、各行に3項目ずつ出力する実装

Last updated at Posted at 2017-03-15
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。

関連 bash > 可変列の3ファイルを合成して、各行に3項目ずつ出力する実装 > 遅い実装と速い実装
のPython実装。

参考 http://stackoverflow.com/questions/7637957/reading-space-separated-input-in-python

combine_3files_170315.py
#!/usr/bin/env python

with open('out_val_170315') as vfp:
	val = vfp.read()
with open('out_lat_170315') as afp:
	lat = afp.read()
with open('out_lon_170315') as ofp:
	lon = ofp.read()

for elm in zip(val.split(),lat.split(),lon.split()):
	print(elm)

bashで処理しても、その後の処理(緯度経度値によるフィルタなど)はPythonの方が楽な気がしてきたのでPythonに変更した。

結果
$ python combine_3files_170315.py | head
('0.00', '36.07', '131.17')
('0.00', '36.07', '131.29')
('0.00', '36.07', '131.41')
('0.00', '36.07', '131.53')
('0.00', '36.07', '131.65')
('0.00', '36.07', '131.77')
('0.00', '36.07', '131.89')
('0.00', '36.07', '132.01')
('0.00', '36.07', '132.13')
('0.00', '36.07', '132.25')
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?