Option Explicit On Option Strict On Public Class Form1 Private fnamedvi As String Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click Call main() End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Dim dvipath As String 'カレントフォルダを出力ファイルのフォルダにする dvipath = System.IO.Path.GetDirectoryName(fnamedvi) System.IO.Directory.SetCurrentDirectory(dvipath) 'platex.exe実行 System.Diagnostics.Process.Start("c:\w32tex\bin\platex.exe", fnamedvi) End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click Dim dvipath As String 'dvipdfmによるpdf化 dvipath = System.IO.Path.GetDirectoryName(fnamedvi) fnamedvi = dvipath & "\" & System.IO.Path.GetFileNameWithoutExtension(fnamedvi) fnamedvi = fnamedvi & ".dvi" System.Diagnostics.Process.Start("c:\w32tex\bin\dvipdfm.exe", fnamedvi) End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click Dim pdfpath As String 'pdf表示 pdfpath = System.IO.Path.GetDirectoryName(fnamedvi) fnamedvi = pdfpath & "\" & System.IO.Path.GetFileNameWithoutExtension(fnamedvi) fnamedvi = fnamedvi & ".pdf" System.Diagnostics.Process.Start(fnamedvi) End Sub Private Sub main() '作図用変数宣言 Dim HSIZE As Double '画像横寸法(mm) Dim DHL As Double '画像左余白寸法:縦軸描画用(mm) Dim DHR As Double '画像右余白寸法(mm) Dim VSIZE As Double '画像縦寸法(mm) Dim DVL As Double '画像下余白寸法:横軸描画用(mm) Dim DVU As Double '画像上余白寸法(mm) Dim sxjiku As String 'x軸名(単位含む) Dim xmin As Double 'x軸最小値 Dim xmax As Double 'x軸最大値 Dim dx As Double 'x軸増分 Dim slogx As String 'x軸の種類(L:対数,N:普通) Dim syjiku As String 'y軸名(単位含む) Dim ymin As Double 'y軸最小値 Dim ymax As Double 'y軸最大値 Dim dy As Double 'y軸増分 Dim slogy As String 'y軸の種類(L:対数,N:普通) Dim kxi As Double : Dim kxf As Double Dim kyi As Double : Dim kyf As Double Dim xx As Double : Dim yy As Double Dim str0 As String : Dim str1 As String : Dim str2 As String : Dim str3 As String : Dim str4 As String Dim kxx As Double : Dim kyy As Double 'データ格納用変数宣言 Dim datax() As Double Dim datay() As Double Dim psname() As String Dim steel() As String Dim ksteel() As Integer Dim ktdrl() As Integer Dim nd As Integer 'データ入出力用変数宣言 Dim sr As System.IO.StreamReader Dim sw As System.IO.StreamWriter Dim dat As String Dim sbuf() As String Dim delim() As Char = {","c} Dim fnameR As String = "" Dim fnameW As String = "" Dim i As Integer 'データ読み込み OpenFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory() If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then fnameR = OpenFileDialog1.FileName sr = New System.IO.StreamReader(fnameR, System.Text.Encoding.Default) dat = sr.ReadLine() dat = sr.ReadLine() : sbuf = dat.Split(delim) : sxjiku = sbuf(0) : syjiku = sbuf(1) dat = sr.ReadLine() : sbuf = dat.Split(delim) : HSIZE = CDbl(sbuf(0)) : DHL = CDbl(sbuf(1)) : DHR = CDbl(sbuf(2)) dat = sr.ReadLine() : sbuf = dat.Split(delim) : VSIZE = CDbl(sbuf(0)) : DVL = CDbl(sbuf(1)) : DVU = CDbl(sbuf(2)) dat = sr.ReadLine() : sbuf = dat.Split(delim) : xmin = CDbl(sbuf(0)) : xmax = CDbl(sbuf(1)) : dx = CDbl(sbuf(2)) : slogx = sbuf(3) dat = sr.ReadLine() : sbuf = dat.Split(delim) : ymin = CDbl(sbuf(0)) : ymax = CDbl(sbuf(1)) : dy = CDbl(sbuf(2)) : slogy = sbuf(3) dat = sr.ReadLine() : sbuf = dat.Split(delim) : nd = CInt(sbuf(0)) - 1 ReDim datax(nd) ReDim datay(nd) ReDim psname(nd) ReDim steel(nd) ReDim ksteel(nd) ReDim ktdrl(nd) dat = sr.ReadLine() '1行読み飛ばし i = 0 Do Until sr.EndOfStream dat = sr.ReadLine() sbuf = dat.Split(delim) psname(i) = sbuf(0).Trim() '発電所名 datax(i) = CDbl(sbuf(1)) '完成年 datay(i) = CDbl(sbuf(2)) 'H*D steel(i) = sbuf(4).Trim() & "(" & sbuf(5).Trim() & ")" '強度クラス+発電区分 ktdrl(i) = CInt(sbuf(6)) '発電所名表記箇所 i = i + 1 Loop sr.Close() nd = i - 1 For i = 0 To nd Select Case steel(i) Case "400MPa(一般水力)" : ksteel(i) = 0 Case "490MPa(一般水力)" : ksteel(i) = 1 Case "490MPa(揚水)" : ksteel(i) = 2 Case "570MPa(一般水力)" : ksteel(i) = 3 Case "570MPa(揚水)" : ksteel(i) = 4 Case "690MPa(一般水力)" : ksteel(i) = 5 Case "690MPa(揚水)" : ksteel(i) = 6 Case "780MPa(揚水)" : ksteel(i) = 7 Case "950MPa(一般水力)" : ksteel(i) = 8 Case "950MPa(揚水)" : ksteel(i) = 9 End Select Next i 'プロット領域定義 kxi = DHL kxf = HSIZE - DHR kyi = DVU kyf = VSIZE - DVL '対数値処理 If slogx = "L" Then For i = 0 To nd If datax(i) < System.Math.Pow(10.0, xmin) Then datax(i) = System.Math.Pow(10.0, xmin) datax(i) = System.Math.Log10(datax(i)) Next i End If If slogy = "L" Then For i = 0 To nd If datay(i) < System.Math.Pow(10.0, ymin) Then datay(i) = System.Math.Pow(10.0, ymin) datay(i) = System.Math.Log10(datay(i)) Next i End If 'プロット領域定義 kxi = DHL kxf = HSIZE - DHR kyi = DVL kyf = VSIZE - DVU '対数値処理 If slogx = "L" Then For i = 0 To nd If datax(i) < System.Math.Pow(10.0, xmin) Then datax(i) = System.Math.Pow(10.0, xmin) datax(i) = System.Math.Log10(datax(i)) Next i End If If slogy = "L" Then For i = 0 To nd If datay(i) < System.Math.Pow(10.0, ymin) Then datay(i) = System.Math.Pow(10.0, ymin) datay(i) = System.Math.Log10(datay(i)) Next i End If 'TeXファイル書き込み SaveFileDialog1.Filter = "*.tex|*.tex" If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then fnameW = SaveFileDialog1.FileName fnamedvi = fnameW sw = New System.IO.StreamWriter(fnameW, False, System.Text.Encoding.Default) sw.WriteLine("\documentclass[a4paper,10pt]{jsarticle}") sw.WriteLine("\input{jartfmt}") sw.WriteLine("\usepackage[dvipdfm]{graphics,graphicx}") sw.WriteLine("\begin{document}") sw.WriteLine("\begin{center}") sw.WriteLine("\unitlength=1mm") sw.WriteLine("\begin{picture}(" & HSIZE.ToString("0.000") & "," & VSIZE.ToString("0.000") & ")") 'x−y軸描画 If slogx = "N" Then Call TeX_DRN_XJIKU(sw, xmin, xmax, dx, kxi, kxf, kyi, kyf) If slogy = "N" Then Call TeX_DRN_YJIKU(sw, ymin, ymax, dy, kxi, kxf, kyi, kyf) If slogx = "L" Then Call TeX_DRL_XJIKU(sw, xmin, xmax, kxi, kxf, kyi, kyf) If slogy = "L" Then Call TeX_DRL_YJIKU(sw, ymin, ymax, kxi, kxf, kyi, kyf) '枠線描画 str1 = kxi.ToString("0.000") str2 = kyi.ToString("0.000") str3 = kxf.ToString("0.000") str4 = kyi.ToString("0.000") sw.WriteLine("\path(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")") str1 = kxf.ToString("0.000") str2 = kyi.ToString("0.000") str3 = kxf.ToString("0.000") str4 = kyf.ToString("0.000") sw.WriteLine("\path(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")") str1 = kxf.ToString("0.000") str2 = kyf.ToString("0.000") str3 = kxi.ToString("0.000") str4 = kyf.ToString("0.000") sw.WriteLine("\path(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")") str1 = kxi.ToString("0.000") str2 = kyf.ToString("0.000") str3 = kxi.ToString("0.000") str4 = kyi.ToString("0.000") sw.WriteLine("\path(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")") 'x軸名描画 str1 = (0.5 * (kxi + kxf)).ToString("0.000") str2 = (kyi - 8.0).ToString("0.000") sw.WriteLine("\put(" & str1 & "," & str2 & "){\makebox(0,0){" & sxjiku & "}}") 'y軸名描画 str1 = (kxi - 15.0).ToString("0.000") str2 = (0.5 * (kyi + kyf)).ToString("0.000") sw.WriteLine("\put(" & str1 & "," & str2 & "){\makebox(0,0){\rotatebox{90}{" & syjiku & "}}}") '**************************************** 'データプロット '**************************************** For i = 0 To nd If 0 < ktdrl(i) Then xx = datax(i) yy = datay(i) kxx = kxi + (xx - xmin) * (kxf - kxi) / (xmax - xmin) kyy = kyi + (yy - ymin) * (kyf - kyi) / (ymax - ymin) str0 = "\makebox(0,0){" & SYMB(ksteel(i)) & "}" str1 = kxx.ToString("0.000") str2 = kyy.ToString("0.000") sw.WriteLine("\put(" & str1 & "," & str2 & "){" & str0 & "}") End If Next i '**************************************** '発電所名表示 '**************************************** '\tiny 50% '\scriptsize 70% '\footnotesize 80% '\small 90% '\normalsize 100% '\large 120% '\Large 140% '\LARGE 170% '\huge 210% '\Huge 250% '--------------------------------------------------- 'normalsize=10pt(1pt=0.3514mm) '--------------------------------------------------- Dim df As Double = 2.5 '1文字寸法(mm)=10pt*0.3514mm*0.7 sw.WriteLine("\scriptsize") For i = 0 To nd If 0 < ktdrl(i) Then xx = datax(i) yy = datay(i) kxx = kxi + (xx - xmin) * (kxf - kxi) / (xmax - xmin) kyy = kyi + (yy - ymin) * (kyf - kyi) / (ymax - ymin) str0 = "\makebox(0,0){" & psname(i) & "}" Select Case ktdrl(i) Case 1 '左 str1 = (kxx - psname(i).Length * df / 2 - df / 2).ToString("0.000") str2 = kyy.ToString("0.000") Case 2 '右 str1 = (kxx + psname(i).Length * df / 2 + df / 2).ToString("0.000") str2 = kyy.ToString("0.000") Case 3 '上 str1 = kxx.ToString("0.000") str2 = (kyy + df).ToString("0.000") Case 4 '下 str1 = kxx.ToString("0.000") str2 = (kyy - df).ToString("0.000") End Select sw.WriteLine("\put(" & str1 & "," & str2 & "){" & str0 & "}") End If Next i '**************************************** '凡例表示 '**************************************** kxx = kxi + 3.0 kyy = kyf - 3.0 df = df + 0.5 Dim bw As Double = 11 * (df - 0.5) '凡例ボックス幅 Dim bh As Double = 11 * df + df / 2 '凡例ボックス高 'eepicsup.styのshade機能により\pathで囲んだ範囲を白塗りする dat = "\shade[0.0]\path" str1 = "(" & kxx.ToString("0.000") & "," & kyy.ToString("0.000") & ")" str2 = "(" & (kxx + bw).ToString("0.000") & "," & kyy.ToString("0.000") & ")" str3 = "(" & (kxx + bw).ToString("0.000") & "," & (kyy - bh).ToString("0.000") & ")" str4 = "(" & kxx.ToString("0.000") & "," & (kyy - bh).ToString("0.000") & ")" dat = dat & str1 & str2 & str3 & str4 & str1 sw.WriteLine(dat) str0 = "" kxx = kxx + df / 2 For i = 0 To 10 Select Case i Case 0 : str0 = "凡例 :鋼板引張強さ区分" Case 1 To 10 : str0 = SYMB(i - 1) & " :" & SREM(i - 1) End Select kyy = kyy - df str1 = kxx.ToString("0.000") str2 = kyy.ToString("0.000") sw.WriteLine("\put(" & str1 & "," & str2 & "){" & str0 & "}") Next i sw.WriteLine("\end{picture}") sw.WriteLine("\end{center}") sw.WriteLine("\end{document}") sw.Close() End Sub Private Function SYMB(ByVal k As Integer) As String SYMB = "" Select Case k Case 0 : SYMB = "$\diamond$" Case 1 : SYMB = "$\circ$" Case 2 : SYMB = "$\bullet$" Case 3 : SYMB = "{\tiny $\square$}" Case 4 : SYMB = "{\tiny $\blacksquare$}" Case 5 : SYMB = "{\scriptsize $\triangle$}" Case 6 : SYMB = "{\scriptsize $\blacktriangle$}" Case 7 : SYMB = "$\circledcirc$" Case 8 : SYMB = "\ding{73}" Case 9 : SYMB = "\ding{72}" End Select End Function Private Function SREM(ByVal k As Integer) As String SREM = "" Select Case k Case 0 : SREM = "400MPa(一般水力)" Case 1 : SREM = "490MPa(一般水力)" Case 2 : SREM = "490MPa(揚水)" Case 3 : SREM = "570MPa(一般水力)" Case 4 : SREM = "570MPa(揚水)" Case 5 : SREM = "690MPa(一般水力)" Case 6 : SREM = "690MPa(揚水)" Case 7 : SREM = "780MPa(揚水)" Case 8 : SREM = "950MPa(一般水力)" Case 9 : SREM = "950MPa(揚水)" End Select End Function Private Sub TeX_DRN_XJIKU(ByVal sw As System.IO.StreamWriter, _ ByVal xmin As Double, ByVal xmax As Double, ByVal dx As Double, _ ByVal kxi As Double, ByVal kxf As Double, _ ByVal kyi As Double, ByVal kyf As Double) Dim i As Integer Dim ix As Integer Dim xx As Double Dim kxx As Double Dim wv As Double Dim str0 As String Dim str1 As String Dim str2 As String Dim str3 As String Dim str4 As String Dim dat1 As String Dim dat2 As String '普通x軸描画 ix = CInt((xmax - xmin) / dx) For i = 0 To ix xx = xmin + CDbl(i) * dx kxx = kxi + (xx - xmin) * (kxf - kxi) / (xmax - xmin) wv = xmin + CDbl(i) * dx str0 = wv.ToString("0") If CInt(dx * 1000.0) Mod 10 <> 0 Then str0 = wv.ToString("0.000") If CInt(dx * 1000.0) Mod 10 = 0 And CInt(dx * 100.0) Mod 10 <> 0 Then str0 = wv.ToString("0.00") If (CInt(dx * 1000.0) Mod 10 = 0 And CInt(dx * 100.0) Mod 10 = 0) And CInt(dx * 10.0) Mod 10 <> 0 Then str0 = wv.ToString("0.0") str1 = kxx.ToString("0.000") str2 = kyi.ToString("0.000") str3 = kxx.ToString("0.000") str4 = kyf.ToString("0.000") dat1 = "\dottedline{1}(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")" str2 = (kyi - 3.0).ToString("0.000") dat2 = "\put(" & str1 & "," & str2 & "){\makebox(0,0){" & str0 & "}}" sw.WriteLine(dat1 & dat2) Next i End Sub Private Sub TeX_DRN_YJIKU(ByVal sw As System.IO.StreamWriter, _ ByVal ymin As Double, ByVal ymax As Double, ByVal dy As Double, _ ByVal kxi As Double, ByVal kxf As Double, _ ByVal kyi As Double, ByVal kyf As Double) Dim i As Integer Dim iy As Integer Dim yy As Double Dim kyy As Double Dim wv As Double Dim str0 As String Dim str1 As String Dim str2 As String Dim str3 As String Dim str4 As String Dim dat1 As String Dim dat2 As String '普通y軸描画 iy = CInt((ymax - ymin) / dy) For i = 0 To iy yy = ymin + CDbl(i) * dy kyy = kyi + (yy - ymin) * (kyf - kyi) / (ymax - ymin) wv = ymin + CDbl(i) * dy str0 = wv.ToString("0") If CInt(dy * 1000.0) Mod 10 <> 0 Then str0 = wv.ToString("0.000") If CInt(dy * 1000.0) Mod 10 = 0 And CInt(dy * 100.0) Mod 10 <> 0 Then str0 = wv.ToString("0.00") If (CInt(dy * 1000.0) Mod 10 = 0 And CInt(dy * 100.0) Mod 10 = 0) And CInt(dy * 10.0) Mod 10 <> 0 Then str0 = wv.ToString("0.0") str1 = kxi.ToString("0.000") str2 = kyy.ToString("0.000") str3 = kxf.ToString("0.000") str4 = kyy.ToString("0.000") dat1 = "\dottedline{1}(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")" str1 = (kxi - 6.0).ToString("0.000") dat2 = "\put(" & str1 & "," & str2 & "){\makebox(0,0){" & str0 & "}}" sw.WriteLine(dat1 & dat2) Next i End Sub Private Sub TeX_DRL_XJIKU(ByVal sw As System.IO.StreamWriter, _ ByVal xmin As Double, ByVal xmax As Double, _ ByVal kxi As Double, ByVal kxf As Double, _ ByVal kyi As Double, ByVal kyf As Double) Dim i As Integer Dim xx As Double Dim kxx As Double Dim str0 As String Dim str1 As String Dim str2 As String Dim str3 As String Dim str4 As String Dim dat1 As String Dim dat2 As String '対数x軸描画 For i = CInt(xmin) To CInt(xmax) - 1 For j = 1 To 9 xx = System.Math.Log10(CDbl(j) * System.Math.Pow(10.0, CDbl(i))) kxx = kxi + (xx - xmin) * (kxf - kxi) / (xmax - xmin) str1 = kxx.ToString("0.000") str2 = kyi.ToString("0.000") str3 = kxx.ToString("0.000") str4 = kyf.ToString("0.000") dat1 = "\dottedline{1}(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")" sw.WriteLine(dat1) Next j Next i For i = CInt(xmin) To CInt(xmax) xx = CDbl(i) kxx = kxi + (xx - xmin) * (kxf - kxi) / (xmax - xmin) str0 = CStr(System.Math.Pow(10.0, CDbl(i))) str1 = kxx.ToString("0.000") str2 = (kyi - 3.0).ToString("0.000") dat2 = "\put(" & str1 & "," & str2 & "){\makebox(0,0){" & str0 & "}}" sw.WriteLine(dat2) Next i End Sub Private Sub TeX_DRL_YJIKU(ByVal sw As System.IO.StreamWriter, _ ByVal ymin As Double, ByVal ymax As Double, _ ByVal kxi As Double, ByVal kxf As Double, _ ByVal kyi As Double, ByVal kyf As Double) Dim i As Integer Dim j As Integer Dim yy As Double Dim kyy As Double Dim str0 As String Dim str1 As String Dim str2 As String Dim str3 As String Dim str4 As String Dim dat1 As String Dim dat2 As String '対数y軸描画 For i = CInt(ymin) To CInt(ymax) - 1 For j = 1 To 9 yy = System.Math.Log10(CDbl(j) * System.Math.Pow(10.0, CDbl(i))) kyy = kyi + (yy - ymin) * (kyf - kyi) / (ymax - ymin) str1 = kxi.ToString("0.000") str2 = kyy.ToString("0.000") str3 = kxf.ToString("0.000") str4 = kyy.ToString("0.000") dat1 = "\dottedline{1}(" & str1 & "," & str2 & ")(" & str3 & "," & str4 & ")" sw.WriteLine(dat1) Next j Next i For i = CInt(ymin) To CInt(ymax) yy = CDbl(i) kyy = kyi + (yy - ymin) * (kyf - kyi) / (ymax - ymin) str0 = CStr(System.Math.Pow(10.0, CDbl(i))) str1 = (kxi - 6.0).ToString("0.000") str2 = kyy.ToString("0.000") dat2 = "\put(" & str1 & "," & str2 & "){\makebox(0,0){" & str0 & "}}" sw.WriteLine(dat2) Next i End Sub End Class