2017年5月12日金曜日

nclの実行時間を測定し表示させる

参考URL
get_cpu_time https://www.ncl.ucar.edu/Document/Functions/Built-in/get_cpu_time.shtml
Tracking Note: Macでプログラムの実行時間を測定する https://trackingnote-yoshi.blogspot.jp/2017/05/mac.html

昔の自分のほうが賢かった。
nclにもcpuの実行時間を返す関数がある。

cputime_min=get_cpu_time/60
print(sprintf("cputime=%f min",cputime_min))

とすれば、

(0) cputime=0.185446 min

とターミナルに返ってくる。
デフォルトは秒単位なので、上の場合は60で割って分単位に直している。


2017年5月11日木曜日

nclでwrfのアウトプットを高度面、気圧面に内挿する時はループしなくて良い

nclはスクリプト言語で、ループの数を減らすことが実行時間の短縮につながるのだが…

参考URL
wrf_user_intrp3d https://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_user_intrp3d.shtml

今までこの関数を使う時、馬鹿正直に鉛直層数分ループして、内挿させていたが、ループしなくていいじゃないか(公式もそう書いてあった)

つまり...

height = (/1800,2000,2200/) ;meter
n_height = dimsizes(height)
do iz = 0,n_height-1,1
vv_levs(iz,:,:)   = wrf_user_intrp3d(vv(:,:,:),zz(:,:,:),"h", height(iz),0.,False)
end do

ではなく、

height = (/1800,2000,2200/) ;meter
vv_levs(:,:,:) = wrf_user_intrp3d(vv(:,:,:),zz(:,:,:),"h", height,0.,False)

で、良い。笑
これで一つループを減らせる。

2017年5月10日水曜日

Macでプログラムの実行時間を測定する

参考URL
Windows&Mac両対応 コマンド大事典 - [time]コマンドの実行時間を知りたい(Macのみ):ITpro http://itpro.nikkeibp.co.jp/atcl/column/15/042000103/080600050/?rt=nocnt

nclが実行される時間をどうやって測るのか…と思ったけど、結局timeコマンドになりそう。

$ time ncl wrf_SkewT1.ncl 
 Copyright (C) 1995-2015 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.3.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(中略)
real 0m31.404s
user 0m13.747s
sys 0m3.872s

ちなみに

real:プログラムの呼び出しから終了までにかかった実時間(秒)
user:プログラム自体の処理時間(ユーザーCPU時間・秒)
sys:プログラムを処理するために、OSが処理をした時間(システム時間・秒)

基本的には、realの時間をチェックしておけば問題ない。
userもたまには必要になることがあるかな。

2017年5月7日日曜日

nclのスクリプトでmkdirする方法

参考URL
systemfunc https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml

nclのスクリプトでmkdirする方法。
公式HPにも載っているけども。

OUT_dirc = "/Volumes/HDD01/research/ncl/wrf/track/"←directoryのパス
ret = systemfunc("test -d "+OUT_dirc+"; echo $?")
if(ret .eq. 0) then
print("--> "+OUT_dirc+": exists")                  ;-- do what you want to do
else if(ret .eq.1) then
print("--> "+OUT_dirc+": doesn't exist: create")   ;-- create the desired directory
system("mkdir " + OUT_dirc)
end if
end if

とすれば、スクリプト内でdirectoryが存在しない時に、OUT_dircをmkdirする。

ちなみに、testコマンドはこちら

Linuxコマンド集 - 【 test 】 条件式の真偽を判定する:ITpro http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230901/


2017年5月6日土曜日

macportsでvaporをインストールできない問題【未解決】

Macportsでvaporを気分転換にインストールしようとしたら…

$ sudo port install vapor
Password:
--->  Computing dependencies for py27-certifi
--->  Fetching archive for py27-certifi
--->  Attempting to fetch py27-certifi-2017.04.17_0.darwin_16.noarch.tbz2 from https://packages.macports.org/py27-certifi
--->  Attempting to fetch py27-certifi-2017.04.17_0.darwin_16.noarch.tbz2.rmd160 from https://packages.macports.org/py27-certifi
--->  Installing py27-certifi @2017.04.17_0
--->  Cleaning py27-certifi
--->  Computing dependencies for py27-certifi
--->  Deactivating py27-certifi @2017.01.23_0
--->  Cleaning py27-certifi
--->  Activating py27-certifi @2017.04.17_0
--->  Cleaning py27-certifi
--->  Computing dependencies for vapor
The following dependencies will be installed: 
 assimp2
 glew
 libmng
 py27-scipy
 qt4-mac
 swig
 swig-python
Continue? [Y/n]: Y    
--->  Fetching archive for assimp2
--->  Attempting to fetch assimp2-2.0.863_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/assimp2
--->  Attempting to fetch assimp2-2.0.863_0.darwin_16.x86_64.tbz2 from http://fco.it.packages.macports.org/mirrors/macports-packages/assimp2
--->  Attempting to fetch assimp2-2.0.863_0.darwin_16.x86_64.tbz2 from http://her.gr.packages.macports.org/assimp2
--->  Fetching distfiles for assimp2
--->  Attempting to fetch assimp--2.0.863-sdk.zip from http://cytranet.dl.sourceforge.net/assimp
--->  Verifying checksums for assimp2                                                
--->  Extracting assimp2
--->  Configuring assimp2
--->  Building assimp2
--->  Staging assimp2 into destroot
--->  Installing assimp2 @2.0.863_0
--->  Activating assimp2 @2.0.863_0
--->  Cleaning assimp2
--->  Fetching archive for glew
--->  Attempting to fetch glew-2.0.0_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/glew
--->  Attempting to fetch glew-2.0.0_0.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/glew
--->  Installing glew @2.0.0_0
--->  Activating glew @2.0.0_0
--->  Cleaning glew
--->  Fetching archive for swig
--->  Attempting to fetch swig-3.0.12_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/swig
--->  Attempting to fetch swig-3.0.12_0.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/swig
--->  Installing swig @3.0.12_0
--->  Activating swig @3.0.12_0
--->  Cleaning swig
--->  Fetching archive for swig-python
--->  Attempting to fetch swig-python-3.0.12_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/swig-python
--->  Attempting to fetch swig-python-3.0.12_0.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/swig-python
--->  Installing swig-python @3.0.12_0
--->  Activating swig-python @3.0.12_0
--->  Cleaning swig-python
--->  Fetching archive for py27-scipy
--->  Attempting to fetch py27-scipy-0.19.0_0+gfortran.darwin_16.x86_64.tbz2 from https://packages.macports.org/py27-scipy
--->  Attempting to fetch py27-scipy-0.19.0_0+gfortran.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/py27-scipy
--->  Installing py27-scipy @0.19.0_0+gfortran
--->  Activating py27-scipy @0.19.0_0+gfortran
--->  Cleaning py27-scipy
--->  Fetching archive for libmng
--->  Attempting to fetch libmng-2.0.3_0.darwin_16.x86_64.tbz2 from https://packages.macports.org/libmng
--->  Attempting to fetch libmng-2.0.3_0.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/libmng
--->  Installing libmng @2.0.3_0
--->  Activating libmng @2.0.3_0
--->  Cleaning libmng
--->  Fetching archive for qt4-mac
--->  Attempting to fetch qt4-mac-4.8.7_4.darwin_16.x86_64.tbz2 from https://packages.macports.org/qt4-mac
--->  Attempting to fetch qt4-mac-4.8.7_4.darwin_16.x86_64.tbz2.rmd160 from https://packages.macports.org/qt4-mac
--->  Installing qt4-mac @4.8.7_4
--->  Activating qt4-mac @4.8.7_4
NOTE: Qt database plugins for mysql55, postgresql91, and sqlite2 are NOT installed by this port; they are installed by qt4-mac-*-plugin instead.
--->  Cleaning qt4-mac
--->  Fetching archive for vapor
--->  Attempting to fetch vapor-2.2.4_11.darwin_16.x86_64.tbz2 from https://packages.macports.org/vapor
--->  Attempting to fetch vapor-2.2.4_11.darwin_16.x86_64.tbz2 from http://fco.it.packages.macports.org/mirrors/macports-packages/vapor
--->  Attempting to fetch vapor-2.2.4_11.darwin_16.x86_64.tbz2 from http://her.gr.packages.macports.org/vapor
--->  Fetching distfiles for vapor
--->  Attempting to fetch vapor-2.2.4-src.tar.gz from https://www.vapor.ucar.edu/sites/default/files/
--->  Verifying checksums for vapor                                                  
--->  Extracting vapor
--->  Applying patches to vapor
--->  Configuring vapor
--->  Building vapor
Error: Failed to build vapor: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_science_vapor/vapor/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets to report a bug.
Error: Processing of port vapor failed

捕まった。気分転換だから、何もしていない。笑
いつかやろう。

2017年4月28日金曜日

OSをアップデートした時、macportsの更新【これも解決してない】

参考URL
Migration – MacPorts https://trac.macports.org/wiki/Migration

1週間くらい前に、YosemiteからSierraにアップデートした。
研究室で借りているimacは問題なかった気がするのだけど、私物のMacBook Airはつまずいた。
公式HP通り手順を踏んだら、とりあえず以前インストールしていたものについては順調に動いているが、selfupdateしたところ

$ sudo port selfupdate
Password:
Error: Current platform "darwin 16" does not match expected platform "darwin 14"
Error: If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration
OS platform mismatch
    while executing
"mportinit ui_options global_options global_variations"
Error: /opt/local/bin/port: Failed to initialize MacPorts, OS platform mismatch

おう。OS platform mismatchと出た。
出先でやる仕事じゃない気がしたので、とりあえずメモだけ残して。

スクリプト言語とコンパイル言語

参考URL
プログラミング言語がたくさんある理由 | Think IT(シンクイット) https://thinkit.co.jp/story/2011/04/13/2085?page=0%2C2
【みんな知ってる?】スクリプト言語とコンパイル言語の違いとは?
http://media.tech-salon.com/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E8%A8%80%E8%AA%9E-%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E8%A8%80%E8%AA%9E/

スクリプト言語とコンパイル言語の違いが書いてあるページ。

githubの基本用語

ある仕事でGithubをちゃんと使うようになって、いろんな基本用語(知識)があやふやなことに気付いたのでメモ。 リポジトリ ファイルやディレクトリの状態を保存する場所。 手元の端末 にある「ローカルリポジトリ」とサーバなどネットワーク上にある「リモートリポジトリ」の...