Public Class Form1 Dim enc_euc As System.Text.Encoding = System.Text.Encoding.GetEncoding("euc-jp") Dim enc_utf As System.Text.UTF8Encoding = New System.Text.UTF8Encoding(False) Dim enc As System.Text.Encoding Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.Visible = True ToolStripStatusLabel1.Text = "Size and Png file name" ToolStripComboBox1.Items.Add("EUC") ToolStripComboBox1.Items.Add("UTF8N") ToolStripComboBox1.Text = "EUC" ToolStripLabel1.Text = ToolStripComboBox1.SelectedItem End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click Dim sr As System.IO.StreamReader Dim sw As System.IO.StreamWriter Dim fnameR As String = "" Dim fnameW As String = "" Dim dat As String Dim sbuf() As String Dim delim As Char = ","c Dim fnameF As String Dim fnameZ As String Dim ps_name() As String Dim ps_type() As String Dim st_class() As String Dim co_YEAR() As Double Dim ps_HD() As Double Dim tbrl() As String Dim mark() As Integer Dim ps_Jname() As String Dim bboxv(3) As Integer Dim fnt As String = "" ToolStripLabel1.Text = ToolStripComboBox1.SelectedItem If ToolStripLabel1.Text = "EUC" Then enc = enc_euc If ToolStripLabel1.Text = "UTF8N" Then enc = enc_utf If enc.EncodingName = "日本語 (EUC)" Then fnt = "GothicBBB-Medium-EUC-H" If enc.EncodingName = "Unicode (UTF-8)" Then fnt = "GothicBBB-Medium-UniJIS-UTF8-H" Dim sxjiku As String Dim syjiku As String Dim xmin As Double Dim xmax As Double Dim dx As Double Dim ymin As Double Dim ymax As Double Dim dy As Double Dim nd As Integer Dim xx As Double Dim yy As Double Dim dlx As Double Dim dly As Double Dim str As String Dim i As Integer Dim k As Integer 'BoundingBox指定:変更無し bboxv(0) = 50 bboxv(1) = 50 bboxv(2) = 410 bboxv(3) = 302 '********************************************** '入出力ファイル指定 '********************************************** OpenFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory() If OpenFileDialog1.ShowDialog() = DialogResult.OK Then fnameR = OpenFileDialog1.FileName If SaveFileDialog1.ShowDialog() = DialogResult.OK Then fnameW = SaveFileDialog1.FileName '********************************************** 'データ入力 '********************************************** sr = New System.IO.StreamReader(fnameR, System.Text.Encoding.Default) dat = sr.ReadLine() : sbuf = dat.Split(delim) : fnameF = sbuf(0) dat = sr.ReadLine() : sbuf = dat.Split(delim) : sxjiku = sbuf(0) : syjiku = sbuf(1) dat = sr.ReadLine() : sbuf = dat.Split(delim) xmin = Double.Parse(sbuf(0)) : xmax = Double.Parse(sbuf(1)) : dx = Double.Parse(sbuf(2)) dat = sr.ReadLine() : sbuf = dat.Split(delim) ymin = Double.Parse(sbuf(0)) : ymax = Double.Parse(sbuf(1)) : dy = Double.Parse(sbuf(2)) dat = sr.ReadLine() : sbuf = dat.Split(delim) : nd = Integer.Parse(sbuf(0)) ReDim ps_name(nd) ReDim ps_type(nd) ReDim st_class(nd) ReDim co_YEAR(nd) ReDim ps_HD(nd) ReDim tbrl(nd) ReDim mark(nd) ReDim ps_Jname(nd) dat = sr.ReadLine() k = 0 For i = 0 To nd - 1 dat = sr.ReadLine() : sbuf = dat.Split(delim) If sbuf(5).Trim() <> "0" Then ps_name(k) = sbuf(0).Trim() ps_type(k) = sbuf(1).Trim() co_YEAR(k) = Double.Parse(sbuf(2).Trim()) ps_HD(k) = Double.Parse(sbuf(3).Trim()) st_class(k) = sbuf(4).Trim() tbrl(k) = sbuf(5).Trim() ps_Jname(k) = sbuf(7).Trim() If st_class(k) = "400MPa" And ps_type(k) = "C" Then mark(k) = 0 If st_class(k) = "490MPa" And ps_type(k) = "C" Then mark(k) = 1 If st_class(k) = "490MPa" And ps_type(k) = "P" Then mark(k) = 2 If st_class(k) = "570MPa" And ps_type(k) = "C" Then mark(k) = 3 If st_class(k) = "570MPa" And ps_type(k) = "P" Then mark(k) = 4 If st_class(k) = "690MPa" And ps_type(k) = "C" Then mark(k) = 5 If st_class(k) = "690MPa" And ps_type(k) = "P" Then mark(k) = 6 If st_class(k) = "780MPa" And ps_type(k) = "P" Then mark(k) = 7 If st_class(k) = "950MPa" And ps_type(k) = "P" Then mark(k) = 8 k = k + 1 End If Next i sr.Close() nd = k '********************************************** 'gnuplot制御用データ書き込み '********************************************** sw = New System.IO.StreamWriter(fnameW, False, enc) dat = String.Format("set terminal postscript eps enhanced font ""{0:s}"" 14", fnt) : sw.WriteLine(dat) dat = String.Format("set output ""{0:s}""", fnameF) : sw.WriteLine(dat) dat = "set key left top" : sw.WriteLine(dat) dat = "set key width -4" : sw.WriteLine(dat) dat = "set key box" : sw.WriteLine(dat) dat = "set key title ""凡例""" : sw.WriteLine(dat) dat = "set key Left top" : sw.WriteLine(dat) dat = "set key spacing 1.2" : sw.WriteLine(dat) dat = String.Format("set xlabel ""{0:s}""", sxjiku) : sw.WriteLine(dat) dat = String.Format("set ylabel ""{0:s}""", syjiku) : sw.WriteLine(dat) dat = String.Format("set xrange [{0:F0}:{1:F0}]", xmin, xmax) : sw.WriteLine(dat) dat = String.Format("set xtics {0:F0}", dx) : sw.WriteLine(dat) dat = String.Format("set format x ""{0:s}""", "%.0f") : sw.WriteLine(dat) dat = String.Format("set yrange [{0:F0}:{1:F0}]", ymin, ymax) : sw.WriteLine(dat) dat = String.Format("set ytics {0:F0}", dy) : sw.WriteLine(dat) dat = String.Format("set format y ""{0:s}""", "%.0f") : sw.WriteLine(dat) dlx = 0.0 : dly = 0.0 str = "" For i = 0 To nd - 1 If tbrl(i) = "t" Then dlx = 0.0 : dly = 150.0 : str = "center" End If If tbrl(i) = "b" Then dlx = 0.0 : dly = -120.0 : str = "center" End If If tbrl(i) = "r" Then dlx = -0.7 : dly = 0.0 : str = "right" End If If tbrl(i) = "l" Then dlx = 0.7 : dly = 0.0 : str = "left" End If xx = co_YEAR(i) + dlx yy = ps_HD(i) + dly dat = String.Format("set label ""{0:s}"" at {1:F3},{2:F3} {3:s} font ""{4:s},12""", ps_Jname(i), xx, yy, str, fnt) sw.WriteLine(dat) Next i '軸作成 dat = "set grid xtics ytics mxtics mytics" : sw.WriteLine(dat) dat = "plot \" : sw.WriteLine(dat) dat = """-"" with points pointtype 12 pointsize 1.0 title "" 400MPa: 一般 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 6 pointsize 1.0 title "" 490MPa: 一般 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 7 pointsize 1.0 title "" 490MPa: 揚水 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 4 pointsize 1.0 title "" 570MPa: 一般 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 5 pointsize 1.0 title "" 570MPa: 揚水 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 8 pointsize 1.0 title "" 690MPa: 一般 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 9 pointsize 1.0 title "" 690MPa: 揚水 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 21 pointsize 1.3 title "" 780MPa: 揚水 "",\" : sw.WriteLine(dat) dat = """-"" with points pointtype 37 pointsize 1.3 title "" 950MPa: 揚水 """ : sw.WriteLine(dat) For k = 0 To 8 For i = 0 To nd - 1 If mark(i) = k Then dat = String.Format("{0:F0} {1:F0} #{2:s}", co_YEAR(i), ps_HD(i), ps_Jname(i)) : sw.WriteLine(dat) End If Next i dat = "e" : sw.WriteLine(dat) Next k dat = "quit" : sw.WriteLine(dat) sw.Close() 'fnameF のフルパス指定 fnameF = System.IO.Path.GetDirectoryName(fnameR) & "\" & fnameF '************************************************************** 'gnuplot 起動+epsファイル作成 (fnameW: コマンド記述ファイル名) '************************************************************** GPL(fnameW) System.Threading.Thread.Sleep(1000) '1秒待つ '************************************************************** 'eps の BoundingBox 修正 (fnameF: eps画像ファイル名) '************************************************************** fnameZ = fnameF.Replace("_eps_", "_eps_z_") BBOX(fnameF, fnameZ, bboxv) '************************************************************** 'ImageMagick による png 画像作成 (fnameZ: eps画像ファイル名) '************************************************************** IMCVT(fnameZ) '************************************************************** 'ImageMagick による 白背景合成 (fnameZ: png画像ファイル名) '************************************************************** fnameZ = fnameZ.Replace("eps", "png") IMCMP(fnameZ) '************************************************************** 'png 画像画面表示 (fnameZ: png画像ファイル名) '************************************************************** fnameZ = fnameZ.Replace("_png_z_", "_png_zw_") VIEWPNG(fnameZ) End Sub '-------------------------------------------------------------------------------------------- Private Sub GPL(ByVal fnameR As String) '***************************************************** 'gnuplot 起動+epsファイル作成 '***************************************************** Dim pr As System.Diagnostics.Process Dim sw As System.IO.StreamWriter Dim dir As String = "" Dim fname As String = "" Dim dat As String = "" dir = System.IO.Path.GetDirectoryName(fnameR) System.IO.Directory.SetCurrentDirectory(dir) fname = System.IO.Path.GetFileName(fnameR) pr = New System.Diagnostics.Process() pr.StartInfo.FileName = "gnuplot.exe" pr.StartInfo.RedirectStandardInput = True pr.StartInfo.RedirectStandardOutput = True pr.StartInfo.UseShellExecute = False pr.StartInfo.CreateNoWindow = True pr.Start() sw = pr.StandardInput dat = String.Format("load ""{0:s}""", fname) sw.WriteLine(dat) sw.Close() pr.WaitForExit() pr.Close() End Sub '-------------------------------------------------------------------------------------------- Private Sub BBOX(ByVal fnameR As String, ByVal fnameW As String, ByRef bboxv() As Integer) Dim sr As System.IO.StreamReader Dim sw As System.IO.StreamWriter Dim dat As String Dim i As Integer 'データ入力 sr = New System.IO.StreamReader(fnameR, enc) sw = New System.IO.StreamWriter(fnameW, False, enc) i = 0 Do Until sr.EndOfStream i = i + 1 dat = sr.ReadLine() If i = 6 Then dat = String.Format("%%BoundingBox: {0:D} {1:D} {2:D} {3:D}", bboxv(0), bboxv(1), bboxv(2), bboxv(3)) sw.WriteLine(dat) Loop sr.Close() sw.Close() End Sub '-------------------------------------------------------------------------------------------- Private Sub IMCVT(ByVal fnameF As String) '***************************************************** 'ImageMagick convert で png 画像作成 '***************************************************** Dim fnameP As String Dim pr As System.Diagnostics.Process Dim sw As System.IO.StreamWriter Dim dat As String = "" fnameP = fnameF.Replace("eps", "png") pr = New System.Diagnostics.Process() pr.StartInfo.FileName = "cmd.exe" pr.StartInfo.RedirectStandardInput = True pr.StartInfo.RedirectStandardOutput = True pr.StartInfo.UseShellExecute = False pr.StartInfo.CreateNoWindow = True pr.Start() sw = pr.StandardInput dat = String.Format("convert -density 300 {0:s} {1:s}", fnameF, fnameP) sw.WriteLine(dat) sw.Close() pr.WaitForExit() pr.Close() End Sub '-------------------------------------------------------------------------------------------- Private Sub IMCMP(ByVal fnameZ As String) '***************************************************** 'ImageMagick convert で 白背景合成画像作成 '***************************************************** Dim fnameP As String Dim fnameB As String Dim pr As System.Diagnostics.Process Dim sw As System.IO.StreamWriter Dim dat As String = "" Dim img As Image Dim ww As Integer Dim hh As Integer img = Image.FromFile(fnameZ) ww = img.Width hh = img.Height img.Dispose() fnameP = fnameZ.Replace("_z_", "_zw_") fnameB = System.IO.Path.GetDirectoryName(fnameP) & "\base.png" pr = New System.Diagnostics.Process() pr.StartInfo.FileName = "cmd.exe" pr.StartInfo.RedirectStandardInput = True pr.StartInfo.RedirectStandardOutput = True pr.StartInfo.UseShellExecute = False pr.StartInfo.CreateNoWindow = True pr.Start() sw = pr.StandardInput dat = String.Format("convert -size {0:D}x{1:D} xc:""#FFFFFF"" {2:s}", ww, hh, fnameB) sw.WriteLine(dat) dat = String.Format("convert {0:s} {1:s} -composite {2:s}", fnameB, fnameZ, fnameP) sw.WriteLine(dat) sw.Close() pr.WaitForExit() pr.Close() End Sub '-------------------------------------------------------------------------------------------- Private Sub VIEWPNG(ByVal fnameZ As String) '***************************************************** 'png 画像画面表示 (50%縮尺) '***************************************************** Dim img As Image Dim bmp As Bitmap Dim g As Graphics Dim ratio As Single = 0.5 Dim ww As Integer Dim hh As Integer Dim w_org As Integer Dim h_org As Integer img = Image.FromFile(fnameZ) w_org = img.Width h_org = img.Height ww = CInt(ratio * w_org) hh = CInt(ratio * h_org) PictureBox1.Size = New Size(ww, hh) bmp = New Bitmap(ww, hh) PictureBox1.Image = bmp g = Graphics.FromImage(PictureBox1.Image) g.DrawImage(img, 0, 0, ww, hh) g.Dispose() img.Dispose() PictureBox1.Left = 0 PictureBox1.Top = ToolStrip1.Height Me.ClientSize = New Size(PictureBox1.Width, PictureBox1.Height + ToolStrip1.Height + StatusStrip1.Height) ToolStripStatusLabel1.Text = String.Format("{0:D} x {1:D} : {2:s}", w_org, h_org, fnameZ) End Sub End Class