Bus errorとSegmentation faultに困ったら見るブログ

物理学者(ポスドク)による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)

【gnuplot】plotするときの線の太さ、色、点線など

(元記事 2011/09/14)

 

set terminal [terminal]
set output "test.[terminal]"
test
q


このようなtestコマンドがあるらしい
[terminal]って所は好みのterminalに変更して使う
(pdf, postscript enhanced color, pngなど)

terminal png

 

terminal postscript enhanced color

terminal pdf



見比べるとわかるが、それぞれで少しずつ仕様が異なる。
だから、線の太さや色あい、また点線にしたいときはこれを参考にすると良いだろう

 

今回は点線をグラフに使いたかったのだが、pdfでいくらやってもうまくいかなかった
なぜなら、pdfには点線がないから・・・・

 

しょうがないので、postscriptで出力することに
そしたらすんなりオーケー

1枚のグラフにいくつもデータをplotするときは色だけだと、見分けがつきにくくなるので色々な工夫が必要ですね

 

--------------------

 

ここからは色や太さの変更するオプションに関するメモ

 

lw

line widthの略
通常時は1
発表のスライドでは3~4あたりを用いるのがよいかも

 

lc

line colorの略
色の変化の仕方は上のtestコマンドの結果参照

 

lt

line typeの略
plotするときの点線の種類を指定できる
testコマンドの結果参照
postscriptでしか効かない?

 

pt

データをplotするときの印を変えられる
大きな点にしたいときとかに使うかも
しかし大きな点は、これだと作れない
これ+ps(印の大きさを指定)で作れたはず(怪しい)


これらのオプションはplotのあとにそのまま付けても効くが(たぶん)
普通は次のようにして使う

 

set style line 1 lc 4 lt 2 lx 2 pt 1
plot "hoge.dat" u 1:2 w l title "aaaaaaa" ls 1

 


plotコマンドの最後のlsは上に書いてあるstyle lineの番号を後ろに付ける
順番とかはエラーはいたら修正する感じで・・・

【シェルスクリプト】ファイルを1行ずつ読み込んで処理する

(元記事 2015/10/25)

 

あるディレクトリにあるファイルのリストに対して処理をするときはよく、

#!/bin/sh
for i in `ls *.txt`
do
 echo $i
done

のような書き方を使う

 


今回は、あるファイルに書かれた各行に対してなんらかの処理をする場合、

#!/bin/sh
while read line; do
 echo $line
done < $data1

 

 

さらにこのファイル$data1に空行が含まれている場合、そこだけ飛ばすようにしたいときは、

#!/bin/sh
while read line; do
if [ -n "$line" ]; then
  echo $line
 fi
done < $data1

 

$lineをダブルコーテーションで囲まないと、そこが空っぽのときにおかしくなるので注意

 

あとは

hoge=`echo $line | awk '{print $1}'`

とかを使ってそれぞれの値を取り出して処理する感じでOK

 

---------------------


(2017/1/18 追記)
上に書いてあるwhile文でデータを読み込むときに、空行を無視する書き方を改めて調べた
というか、この記事のことはまったく忘れていて追記しようと開いたら書いてあった・・・

けど少しだけ書き方が違うのでメモメモ

 

while read line
do
if [ ${#line} -eq 0 ]; then
continue
fi

# do something
echo "hoge"
done <hoge.txt

 

----------

 

(2017/6/12 追記)

 

空行だけじゃなくて、コメント行も無視するようにするには次のようにすればOK

#!/bin/sh

grep -v '^\s*#' hoge.txt |grep -v '^\s*$' > tmp.txt
while read line; do
 
 # ここでなんか処理する
 echo $line

done < tmp.txt
本当はtmp.txtとか中間ファイルを作りたくなくて、
done < `grep -v '^\s*#' hoge.txt |grep -v '^\s*$'`

 


で行けるかと思ったけどなんか動かなかった・・・
なにか大きな勘違いをしてるのかもしれん

 

■ 参考 : grepでコメント行および空白行を削除する

---------------

 

(2018/09/19 追記)

grepで検索条件を満たすものを結果から除外したいとき
(= 検索条件を満たさないものを表示したいとき)

grep -v "hoge" *.txt

 

【gnuplot】titleの位置を変えたい

(元記事 2011/08/26)

 

長らく更新してませんでしたが、生存しています。
新しいことを知れるような機会がないくらいだらだらと研究していたんでしょう。

 

plot "hoge.dat" title "ABCDE"


これでplotしたデータにtitleを付ける事ができる
自分の環境では、右上にタイトルが出る

 

 

 

↑こんな感じ


この場合は特に問題がないが、もし右上の方までデータが伸びていたら見えにくい

そのときは次のようにしてtitleの位置を変更する

 

set key left top


使えるのは
・top (上)
・bottom (下)
・right (右)
・left (左)

これらはもちろん組み合わせて使う事が可能
他にも outside, below (どちらも図の外側)というのもあるらしいが、自分の環境ではうまいこと描写できなかったので割愛

 

 

【TeX】minipageを使って1行に画像を2つ貼りたい

(元記事 2011/08/01)

 

\begin{figure}[h]
\begin{minipage}{0.5\hsize}
\begin{center}
\includegraphics[width=70mm]{hoge.jpg}
\end{center}
\caption{aaaa}
\end{minipage}
\begin{minipage}{0.5\hsize}
\begin{center}
\includegraphics[width=90mm]{hoge.jpg}
\end{center}
\caption{hoge}
\end{minipage}
\end{figure}


数字の書いてあるところをいじったら表示のさせかたが変わる。

かなり自分用メモなので、今回は画像はなしで

 

-------------

 

少し書き直した

\begin{figure}[h]
\begin{minipage}{0.45\hsize}
\begin{center}
\includegraphics[width=\hsize]{hoge.jpg}
\end{center}
\caption{aaaa}
\label{fig:aaaa}
\end{minipage}
\hfill
\begin{minipage}{0.45\hsize}
\begin{center}
\includegraphics[width=\hsize]{hoge.jpg}
\end{center}
\caption{bbbb}
\label{fig:bbbb}
\end{minipage}
\end{figure}


hfillはminipage同士の間の距離をできる限り広げる
そのために、minipageの大きさを0.5hsizeじゃなくて0.45hsizeにしている

 

------------

 

(追記)

この記事からエンマークじゃなくて、バックスラッシュになってる・・・・

 

 

【シェルコマンド】HDF5形式のファイルのヘッダーなどの情報を表示する

h5py をanacondaでインストールしてると自動的にシェルコマンドも使えるっぽい

 

その中でもhdf5ファイルの中身を表示するコマンドがh5dump

 

ヘッダーの情報を返す

h5dump -H ファイル名.h5  

データセットの情報を返す

h5dump -n ファイル名.h5

 

h5dumpのヘルプメッセージ

h5dump -O ファイル名.h5

とかも使える

 

% h5dump
usage: h5dump [OPTIONS] files
  OPTIONS
     -h,   --help         Print a usage message and exit
     -V,   --version      Print version number and exit
--------------- File Options ---------------
     -n,   --contents     Print a list of the file contents and exit
                          Optional value 1 also prints attributes.
     -B,   --superblock   Print the content of the super block
     -H,   --header       Print the header only; no data is displayed
     -f D, --filedriver=D Specify which driver to open the file with
     -o F, --output=F     Output raw data into file F
     -b B, --binary=B     Binary file output, of form B
     -O F, --ddl=F        Output ddl text into file F
                          Use blank(empty) filename F to suppress ddl display
     --s3-cred=<cred>     Supply S3 authentication information to "ros3" vfd.
                          <cred> :: "(<aws-region>,<access-id>,<access-key>)"
                          If absent or <cred> -> "(,,)", no authentication.
                          Has no effect if filedriver is not "ros3".
     --hdfs-attrs=<attrs> Supply configuration information for HDFS file access.
                          For use with "--filedriver=hdfs"
                          <attrs> :: (<namenode name>,<namenode port>,
                                      <kerberos cache path>,<username>,
                                      <buffer size>)
                          Any absent attribute will use a default value.
     --vol-value          Value (ID) of the VOL connector to use for opening the
                          HDF5 file specified
     --vol-name           Name of the VOL connector to use for opening the
                          HDF5 file specified
     --vol-info           VOL-specific info to pass to the VOL connector used for
                          opening the HDF5 file specified
--------------- Object Options ---------------
     -a P, --attribute=P  Print the specified attribute
                          If an attribute name contains a slash (/), escape the

                      slash with a preceding backslash (\).

                          (See example section below.)
     -d P, --dataset=P    Print the specified dataset
     -g P, --group=P      Print the specified group and all members
     -l P, --soft-link=P  Print the value(s) of the specified soft link
     -t P, --datatype=P   Print the specified named datatype
     -N P, --any_path=P   Print any attribute, dataset, group, datatype, or link that matches P
                          P can be the absolute path or just a relative path.
     -A,   --onlyattr     Print the header and value of attributes
                          Optional value 0 suppresses printing attributes.
     --vds-view-first-missing Set the VDS bounds to first missing mapped elements.
     --vds-gap-size=N     Set the missing file gap size, N=non-negative integers
--------------- Object Property Options ---------------
     -i,   --object-ids   Print the object ids
     -p,   --properties   Print dataset filters, storage layout and fill value
     -M L, --packedbits=L Print packed bits as unsigned integers, using mask
                          format L for an integer dataset specified with
                          option -d. L is a list of offset,length values,
                          separated by commas. Offset is the beginning bit in
                          the data value and length is the number of bits of
                          the mask.
     -R,   --region       Print dataset pointed by region references
--------------- Formatting Options ---------------
     -e,   --escape       Escape non printing characters
     -r,   --string       Print 1-byte integer datasets as ASCII
     -y,   --noindex      Do not print array indices with the data
     -m T, --format=T     Set the floating point output format
     -q Q, --sort_by=Q    Sort groups and attributes by index Q
     -z Z, --sort_order=Z Sort groups and attributes by order Z
     --enable-error-stack Prints messages from the HDF5 error stack as they occur.
                          Optional value 2 also prints file open errors.
     --no-compact-subset  Disable compact form of subsetting and allow the use
                          of "[" in dataset names.
     -w N, --width=N      Set the number of columns of output. A value of 0 (zero)
                          sets the number of columns to the maximum (65535).
                          Default width is 80 columns.
--------------- XML Options ---------------
     -x,   --xml          Output in XML using Schema
     -u,   --use-dtd      Output in XML using DTD
     -D U, --xml-dtd=U    Use the DTD or schema at U
     -X S, --xml-ns=S     (XML Schema) Use qualified names n the XML
                          ":": no namespace, default: "hdf5:"
                          E.g., to dump a file called "-f", use h5dump -- -f

--------------- Subsetting Options ---------------
 Subsetting is available by using the following options with a dataset
 option. Subsetting is done by selecting a hyperslab from the data.
 Thus, the options mirror those for performing a hyperslab selection.
 One of the START, COUNT, STRIDE, or BLOCK parameters are mandatory if you do subsetting.
 The STRIDE, COUNT, and BLOCK parameters are optional and will default to 1 in
 each dimension. START is optional and will default to 0 in each dimension.

      -s START,  --start=START    Offset of start of subsetting selection
      -S STRIDE, --stride=STRIDE  Hyperslab stride
      -c COUNT,  --count=COUNT    Number of blocks to include in selection
      -k BLOCK,  --block=BLOCK    Size of block in hyperslab
  START, COUNT, STRIDE, and BLOCK - is a list of integers the number of which are equal to the
      number of dimensions in the dataspace being queried
      (Alternate compact form of subsetting is described in the Reference Manual)

--------------- Option Argument Conventions ---------------
  D - is the file driver to use in opening the file. Acceptable values
      are "sec2", "family", "split", "multi", "direct", and "stream". Without
      the file driver flag, the file will be opened with each driver in
      turn and in the order specified above until one driver succeeds
      in opening the file.
      See examples below for family, split, and multi driver special file name usage.

  F - is a filename.
  P - is the full path from the root group to the object.
  N - is an integer greater than 1.
  T - is a string containing the floating point format, e.g '%.3f'
  U - is a URI reference (as defined in [IETF RFC 2396],
        updated by [IETF RFC 2732])
  B - is the form of binary output: NATIVE for a memory type, FILE for the
        file type, LE or BE for pre-existing little or big endian types.
        Must be used with -o (output file) and it is recommended that
        -d (dataset) is used. B is an optional argument, defaults to NATIVE
  Q - is the sort index type. It can be "creation_order" or "name" (default)
  Z - is the sort order type. It can be "descending" or "ascending" (default)

--------------- Examples ---------------

  1) Attribute foo of the group /bar_none in file quux.h5

      h5dump -a /bar_none/foo quux.h5

     Attribute "high/low" of the group /bar_none in the file quux.h5

      h5dump -a "/bar_none/high\/low" quux.h5

  2) Selecting a subset from dataset /foo in file quux.h5

      h5dump -d /foo -s "0,1" -S "1,1" -c "2,3" -k "2,2" quux.h5

  3) Saving dataset 'dset' in file quux.h5 to binary file 'out.bin'
        using a little-endian type

      h5dump -d /dset -b LE -o out.bin quux.h5

  4) Display two packed bits (bits 0-1 and bits 4-6) in the dataset /dset

      h5dump -d /dset -M 0,1,4,3 quux.h5

  5) Dataset foo in files file1.h5 file2.h5 file3.h5

      h5dump -d /foo file1.h5 file2.h5 file3.h5

  6) Dataset foo in split files splitfile-m.h5 splitfile-r.h5

      h5dump -d /foo -f split splitfile

  7) Dataset foo in multi files mf-s.h5, mf-b.h5, mf-r.h5, mf-g.h5, mf-l.h5 and mf-o.h5

      h5dump -d /foo -f multi mf

  8) Dataset foo in family files fam00000.h5 fam00001.h5 and fam00002.h5

      h5dump -d /foo -f family fam%05d.h5

 

【TeX】ローマ数字の表示の仕方

(元記事 2011/08/01)

 

TeXで「2」を変換した「Ⅱ」と書いても、空白になってしまう。

 

そこで次のようにする

 

\def\rnum#1{\expandafter{\romannumeral #1}}
\def\Rnum#1{\uppercase\expandafter{\romannumeral #1}}


1
\Rnum{1}
\rum{2}

 

って打ったらこんな感じになるはず

 

もっと色々と表示させてみた。↓