#!/usr/bin/env ruby
#
# 表題: dcchart お絵描きサムネイル HTML 作成スクリプト
#
# 履歴: 2003/09/28 やまだ由
# 2004/02/18 やまだ由 ($head 付加)
# 2004/03/15 塚原大輔 (やまだ由氏の ape-thum.rb を改訂)
# 2005/03/21 石渡正樹 dcchart-thum.rb のpath を変更
#
# 注意1: 本プログラムは,
# dcphoto.pl Ver 1.02 - 写真用 HTML作成スクリプト
# Mitsuda Chihiro
# を ruby で写経し, やまだ由さん用にカスタマイズしたものを
# 塚原がぱくったものである.
#
# 注意1: 本プログラムでは以下を仮定している;
#
# 1. dcchart-thum-make.rb を作成したディレクトリに画像がある.
# 2.
#
# ---------------------------------------------------------
# 初期値
#
# コメントファイル名
$comment_txt = File.basename(Dir::pwd).gsub(/\./, "_")
#
# 年. コメントファイル名より取得
$year = $comment_txt.scan(/\d\d\d\d/)[0]
#
# 物理量. コメントファイル名より取得
$phys = $comment_txt.split('_')[0]
#
# データソース名. コメントファイル名より取得
$src = $comment_txt.split('_')[-1]
#
# html タイトル
$name = {
"UWND" => "東西風速",
"VWND" => "南北風速",
"OMEGA" => "鉛直風速",
"HGT" => "ジオポテンシャルハイト",
"RHUM" => "相対湿度",
"SHUM" => "比湿",
"ULWRF" => "外向き長波放射フラックス",
"STRM" => "質量流線関数",
"T" => "気温",
"EPFLX" => "E-P フラックス",
"PRATE" => "降雨"
}
#
# コメント
$comment = {
"UWND" => "帯状平均をとった東西風速(単位:m/s). #{$year} 年度各月及び季節, 年平均図.",
"VWND" => "帯状平均をとった南北風速(単位:m/s). #{$year} 年度各月及び季節, 年平均図.",
"OMEGA" => "帯状平均をとった鉛直風速(単位:m/s). #{$year} 年度各月及び季節, 年平均図.",
"HGT" => "ジオポテンシャルハイト(単位:m). #{$year} 年度各月及び季節, 年平均図.",
"RHUM" => "帯状平均をとった相対湿度(単位:%). #{$year} 年度各月及び季節, 年平均図.",
"SHUM" => "帯状平均をとった比湿(単位:%). #{$year} 年度各月及び季節, 年平均図.",
"STRM" => "帯状平均をとった質量流線関数(単位:kg/s). 南北風のデータより計算(gtstrm.rb を利用).
#{$year} 年度各月及び季節, 年平均図. 正(右回り)の領域にトーンをつけている.",
"ULWRF" => "外向き長波放射フラックス(単位:W/m^2). #{$year} 年度各月及び季節, 年平均図.",
"T" => "大気温度(単位:K). #{$year} 年度各月及び季節, 年平均図.",
"EPFLX" => "子午面の Elliassen-Palm フラックス(緯度成分:m^2/s^2, 鉛直成分:N/m/s^2)およびその発散(単位:m/s^2).
ただし発散は単位質量あたりの加速の形にしてある. #{$year} 年度各月及び季節, 年平均図.",
"PRATE" => "単位面積・単位時間あたりの降水量(単位:Kg/m^2/s). #{$year} 年度各月及び季節, 年平均図."
}
# ---------------------------------------------------------
# include
require 'date'
$KCODE = "e"
# ---------------------------------------------------------
# main()
def apethum_rd
mkinfo ; p "mkinfo end"
makethum_rd ; p "mkthum_rd end"
end
def apethum
mkinfo ; p "mkinfo end"
makethum ; p "mkthum end"
makethum_rd ; p "mkthum_rd end"
end
# ---------------------------------------------------------
# 以下サブルーチン群
# -------------------------
# 画像情報取得 (jpg ファイル名, 枚数, コメントファイル)
def mkinfo
# img-web から画像ファイル名一覧をとりだし, 配列 imgfiles へ代入
$imgfiles = []
Dir.foreach("#{$figdir}") { |item|
if item =~ /#{$base}$/
$imgfiles.push( (File.basename(item, $base) ).split($head) )
end
}
# 画像ファイル数
$file_num = $imgfiles.size
$imgfiles = $imgfiles.sort
## $infofile がなければ作成
# unless File.exist?($infofile) then
# ifile = open($infofile, "w")
# $file_num.times{ |num|
# ifile.print "#{$imgfiles[num]}:\n" % num
# }
# ifile.close
## end
# $infofile がなければ作成
unless File.exist?($infofile) then
ifile = open($infofile, "w")
# データダウンロードページ用
if $layout
info = <月平均
title:
title:
title:
#{$phys}_#{$year}-01_#{$src}:nclink
#{$phys}_#{$year}-02_#{$src}:nclink
#{$phys}_#{$year}-03_#{$src}:nclink
#{$phys}_#{$year}-04_#{$src}:nclink
#{$phys}_#{$year}-05_#{$src}:nclink
#{$phys}_#{$year}-06_#{$src}:nclink
#{$phys}_#{$year}-07_#{$src}:nclink
#{$phys}_#{$year}-08_#{$src}:nclink
#{$phys}_#{$year}-09_#{$src}:nclink
#{$phys}_#{$year}-10_#{$src}:nclink
#{$phys}_#{$year}-11_#{$src}:nclink
#{$phys}_#{$year}-12_#{$src}:nclink
title:
季節平均
title:
title:
title:
#{$phys}_#{$year}-DJF_#{$src}:冬(#{$year.to_i-1}/12, #{$year}/01, #{$year}/02)
#{$phys}_#{$year}-MAM_#{$src}:春(#{$year}/03, #{$year}/04, #{$year}/05)
#{$phys}_#{$year}-JJA_#{$src}:夏(#{$year}/06, #{$year}/07, #{$year}/08)
#{$phys}_#{$year}-SON_#{$src}:秋(#{$year}/09, #{$year}/10, #{$year}/11)
title:
年平均
title:
title:
title:
#{$phys}_#{$year}-ANN_#{$src}:(#{$year}/01-#{$year}/12)
EOF
ifile.print info
# 通常
else
$file_num.times{ |num|
ifile.print "#{$imgfiles[num]}:\n" % num
}
end
ifile.close
end
# $infofile からファイル名とコメントを取り出す
# $info[true][0] にはファイル名, $info[0][true] にはコメントが入る
$info = []
ifile = open($infofile, "r")
ifile.each { |line|
$info.push(line.chomp.split(/:/))
}
ifile.close
# $infofile からファイル数を再定義
$file_num = $info.size
# p $info
end
# -------------------------
# サムネイル $index の作成
def makethum
# 元ファイル削除
File.delete($index + ".html") if File.exist?($index + ".html")
# 初期化
$htmls = ""
# ヘッダ部
$htmls = htmlhead
# 本文表題部
$htmls << htmltitle
# サムネイル部分作成
$file_num.times { |num|
$htmls << htmlthum(num)
}
# table 末処理
amari = ($file_num - 1 ) % $figtable_num
figtable_1 = $figtable_num -1
figtable_2 = $figtable_num -2
amari.upto(figtable_2) { |num|
$htmls << <
HTMLEOF
}
$htmls << %| \n| unless amari == figtable_1
# フッタ処理
$htmls << htmlfoot
# ファイルの書きだし
ifile = open( $index + ".html", "w")
ifile.print $htmls
ifile.close
end
# -------------------------
# rd 組み込み用サムネイル $index の作成
def makethum_rd
# ディレクトリ作成, 元ファイル削除
Dir.mkdir("html",0775) unless File.exist?("html")
File.delete("html/table_" + $index + ".rd") if File.exist?("html/table_" + $index + ".rd")
# 初期化
$htmls = ""
$htmls << %|=begin html\n|
$htmls << %|\n|
$htmls << %|\n|
# サムネイル部分作成
$file_num.times { |num|
$htmls << htmlthum(num)
}
# table 末処理
amari = ($file_num - 1 ) % $figtable_num
figtable_1 = $figtable_num -1
figtable_2 = $figtable_num -2
amari.upto(figtable_2) { |num|
$htmls << <
HTMLEOF
}
$htmls << %| \n| unless amari == figtable_1
$htmls << %|
\n|
$htmls << %|\n|
$htmls << %|=end html\n|
# ファイルの書きだし
ifile = open( "html/table_" + $index + ".rd", "w")
ifile.print $htmls
ifile.close
end
#-------------------------------------------------------------
# サムネイル $index 用サブルーチン
# html ヘッダ部
def htmlhead
htmls = <
#{$title}
HTMLEOF
return htmls
end
# html thumnail 繰り返し部
def htmlthum(num)
picname = $info[num][0]
amari = num % $figtable_num
figtable_1 = $figtable_num -1
comment = $info[num][1]
# テーブルの配置によって のつけたしをおこなう.
# 左端 : 3n+1 ($amari == 0)
# 右端 : 3n ($amari == 2)
htmls = ""
htmls = %|
\n| if amari == 0
if picname == "title" then
htmls << <
#{comment}
HTMLEOF
elsif picname == nil then
htmls << <
HTMLEOF
else
if $figdir == "./"
url = "#{$head}#{picname}#{$base}"
else
url = "#{$figdir}/#{$head}#{picname}#{$base}"
end
if comment == "nclink"
comment = "(download nc file)"
end
htmls << <
#{picname}
#{comment}
HTMLEOF
end
htmls << %|
\n| if amari == figtable_1
return htmls
end
# フッター
def htmlfoot
htmls = <
#{$footer}
|