LTspice のコツ - 極座標フォーマットのテキストを CSV に変換する方法
細田 隆之
2021年 7月 17日
English English edition is here.

LTspice XVII の AC 解析の Polar 形式のテキスト出力を CSV や Tab 区切りテキストにするには

LTspice の polar: (db,deg) フォーマットには ISO/IEC 8859-1 の 1-byte キャラクタの ° (degree, 0xb0) が使われています。
このため日本語などのマルチバイト環境では文字化けが発生して扱いにくくなります。
そこで、Microsoft Excel や gnuplot 等で扱いやすくするため CSV や Tab 区切りテキストに変換する スクリプト書きました。
sed と bash の使える環境であれば使用可能です。
スクリプト名を polar2csv とすると LTspice の polar: (db,deg) 形式を CSV に変換して、標準出力に出力します。
スクリプト名が polar2csv 以外の場合 (例 polar2tab)、 Tab 区切りのテキストに変換し、標準出力に出力します。

polar2csv / polar2txt (shell script)
#!/bin/sh
#
# polar2csv - Polar: (db,deg) format of the LTspice XVII to CSV conversion.
#
# Usage
#   polar2csv input_file
#
# Example
#   polar2csv input_file.txt > output_file.csv
#
#  You must set LC_ALL=C to remove the single byte degree charactor (0xb0)
# used in the export text format of Polar: (dB,deg) of the AC simulation
# results of the LTspice XVII.
#  In bash, $'string' causes "ANSI-C expansion". And that is what most of
# us expect when we use things like \t, \r, \n, etc.
# c.f. www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
#
export LC_ALL=C
if [ $# -ne 1 ]; then
   echo "${0##*/} - Polar: (db,deg) format of the LTspice XVII to CSV conversion."
   echo "Usage : ${0##*/} input_file"
   exit;
fi
if [ "${0##*/}" = "polar2csv" ]; then
    sed < $1 -e 's/^Freq/#Freq/' -e 's/[(,)]//g' -e 's/\xb0//g' -e $'s/\t/, /g' -e $'s/dB/, /g'
else
    sed < $1 -e 's/^Freq/#Freq/' -e 's/[(,)]//g' -e 's/\xb0//g' -e $'s/dB/\t/g'
fi
#EOF

See also

External link



www.finetune.co.jp [Mail] © 2000 Takayuki HOSODA.