Yamamoto's Laboratory
コンピューター グラフ作成 web_gnuplot ソースリスト

web_gnuplotソースリスト


index.php

web_gnuplot のソースリスト

001   <!-- -*- coding:euc-jp -*- -->
002   
003   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
004   <html lang="ja">
005   
006     <head> 
007       <META HTTP-EQUIV = "Content-Type" CONTENT = "text/html; charset=EUC-JP">
008       <META http-equiv="Pragma" content="no-cache">
009       <META http-equiv="Cache-Control" content="no-cache">
010       <META http-equiv="Expires" content="0">
011       <meta http-equiv="Content-Script-Type" content="text/javascript">
012       <link rel="stylesheet" href="../../../stylesheet.css" type="text/css">
013       <TITLE>webを使った gnuplot グラフ作成</TITLE>
014       <STYLE TYPE="text/css">
015       <!--
016       BLOCKQUOTE {margin:3px 20px 5px 100px}
017       .list {margin:4px 20px 4px 20px}
018       .enumerate {margin:7px 40px 7px 50px}
019       .CommandName {font-size:12pt; color:#1F6f1F}
020       .discriptin {padding-bottom : 20px}
021       a.help:link {color:#00FFFF;text-decoration:none}
022       a.help:visited {color:#00FFFF;text-decoration:none}
023       a.help:hover {color:#ffffff;text-decoration:none}
024       -->
025       </STYLE>
026     </HEAD>
027   
028   
029     <body class="frame">
030   
031       <?PHP
032       mb_http_output("EUC_JP");
033       mb_internal_encoding("EUC_JP");
034       ob_start("mb_output_handler");
035       $side_webgnuplot=TRUE;
036       include "../../../head_menu.php";
037       include "../begin_side_menu_graph.php";
038       ob_end_flush();
039       ?>
040   
041       <div class="page_top">
042   
043         <div class="path">
044       <span class="parent"><a href="../../index.html">コンピューター</a></span>
045       <span class="parent"><a href="../index.php">グラフ作成</a></span>
046       <span class="self">web_gnuplot</span>
047         </div>
048   
049         <h1 class="title">web_gnuplot<span class="subtitle">ブラウザから gnuplot の実行</span></h1>
050   
051       </div>
052       
053       <hr>
054   
055       <!-- ========================================================= -->
056       <h2 class="body" id="introduction">webを使ったグラフ作成ツール</h2>
057       <!-- ========================================================= -->
058   
059       <P>webのインターフェースを使ったグラフ作成ツールです.グラフはgnuplotで作成します.</P>
060   
061       <p>簡単な例を<a href="help/example_1.png">ここ</a>に載せておきます.<a href="help/example_1.png">この例</a>のように記述して,プロットボタンをクリックするとグラフができます.いろいろな機能がありますので,使ってください.</p>
062   
063       <p>グラフデータ入力画面の項目をクリックするとヘルプがあらわれます.作図するときの参考にしてください.</p>
064   
065       <p>また,<a href="source.php">ソースリスト</a>を載せておきます.汚いプログラムですが,何かの参考になると思います.</p>
066   
067       <!-- --------------------------------------------------------- -->
068       <h3 class="body" id="input_form">グラフデータ入力画面</h3>
069       <!-- --------------------------------------------------------- -->
070   
071       <?PHP
072       if(isset($_GET["status"]) && $_GET["status"]=="clear"){
073         setcookie("webgp_data[plot_data]","",0);
074       }else{
075         $_GET["status"]="keep";
076       }
077    
078       $x_low=array("1列","2列","3列","4列","5列","6列","7列","8列","9列");
079       $y_low=array("1列","2列","3列","4列","5列","6列","7列","8列","9列");
080       $line=array("","折線","スプライン","指数","対数","定数","1次関数","2次関数","3次関数","4次関数","5次関数","6次関数",
081                    "7次関数","8次関数","9次関数",
082                    "1次関数(原点通過)","2次関数(原点通過)","3次関数(原点通過)",
083                    "4次関数(原点通過)","5次関数(原点通過)","6次関数(原点通過)",
084                    "7次関数(原点通過)","8次関数(原点通過)","9次関数(原点通過)");
085       $g_file=array("emf","eps","png","png(透明)");
086       ?>
087   
088       <FORM method="POST" action="mk_graph.php">
089         <TABLE border="1" style="background-color:indianred;">
090       <TBODY>
091         
092         <!-- ---------- タイトル ------------- -->
093         <TD><a href="help/title.php" class="help">タイトル</a></TD>
094         <TD><INPUT size="60" type="text" name="title" <?php 
095                               if(isset($_COOKIE['webgp_data']['title'])){
096        print "value=\"".$_COOKIE['webgp_data']['title']."\">&nbsp;\n";
097                               }else{
098                                 print ">&nbsp;\n";
099                               }?>
100       </TR>
101       <TR>
102         
103         <!-- ---------- x軸 ------------- -->
104         <TR>
105       <TD><a href="help/x_axis.php" class="help">x軸</a></TD>
106       <TD>最小&nbsp;<INPUT size="8" type="text" name="x_min" <?PHP
107                                  if(isset($_COOKIE['webgp_data']['x_min'])){
108                              print "value=\"".$_COOKIE['webgp_data']['x_min']."\">\n";
109                                  }else{
110                              print ">\n";
111                                  }
112                          print "&nbsp;最大&nbsp;<INPUT size=\"8\" type=\"text\" name=\"x_max\"";
113                          if(isset($_COOKIE['webgp_data']['x_max'])){
114                              print "value=\"".$_COOKIE['webgp_data']['x_max']."\">\n";
115                          }else{
116                              print ">\n";
117                              }
118   
119                  if(isset($_COOKIE['webgp_data']['x_axis'])){
120                  print '<INPUT type="checkbox" name="x_axis" value="checked"'.$_COOKIE['webgp_data']['x_axis'].">対数\n";
121                }else{
122                  print '<INPUT type="checkbox" name="x_axis" value="checked"'.">対数\n";
123                }
124   
125                          print "&nbsp;ラベル&nbsp;<INPUT size=\"15\" type=\"text\" name=\"x_label\"";
126                          if(isset($_COOKIE['webgp_data']['x_label'])){
127                              print "value=\"".$_COOKIE['webgp_data']['x_label']."\">\n";
128                          }else{
129                              print ">\n";
130                          }
131                          ?>
132           </TD>
133       </TR>
134   
135        <!-- ---------- y軸 ------------- -->
136       <TR>
137       <TD><a href="/yamamoto/comp/graph/web_gnuplot/help/y_axis.php" class="help">y軸</a></TD>
138       <TD>最小&nbsp;<INPUT size="8" type="text" name="y_min" <?PHP
139                          if(isset($_COOKIE['webgp_data']['y_min'])){
140                              print "value=\"".$_COOKIE['webgp_data']['y_min']."\">\n";
141                          }else{
142                              print ">\n";
143                          }
144                          print "&nbsp;最大&nbsp;<INPUT size=\"8\" type=\"text\" name=\"y_max\"";
145                          if(isset($_COOKIE['webgp_data']['y_max'])){
146                              print "value=\"".$_COOKIE['webgp_data']['y_max']."\">\n";
147                          }else{
148                              print ">\n";
149                              }
150                  if(isset($_COOKIE['webgp_data']['y_axis'])){
151                print '<INPUT type="checkbox" name="y_axis" value="checked"'.$_COOKIE['webgp_data']['y_axis'].">対数\n";
152                  }else{
153                print '<INPUT type="checkbox" name="y_axis" value="checked"'.">対数\n";
154                  }
155   
156                          print "&nbsp;ラベル&nbsp;<INPUT size=\"15\" type=\"text\" name=\"y_label\"";
157                          if(isset($_COOKIE['webgp_data']['y_label'])){
158                              print "value=\"".$_COOKIE['webgp_data']['y_label']."\">\n";
159                          }else{
160                              print ">\n";
161                          }
162                          ?>
163           </TD>
164       </TR>
165   
166       <!-- ---------- 表示 ------------- -->
167       <TR>
168       <TD><a href="/yamamoto/comp/graph/web_gnuplot/help/hyoji.php" class="help">表示</a></TD>
169       <TD>グリッド&nbsp;<?PHP
170                 if(isset($_COOKIE['webgp_data']['x_grid'])){
171                   print "<INPUT type=\"checkbox\" name=\"x_grid\" value=\"checked\" ".
172                     $_COOKIE['webgp_data']['x_grid'].">x\n";
173                 }else{
174                   print "<INPUT type=\"checkbox\" name=\"x_grid\" value=\"checked\" ".">x\n";
175                 }
176   
177                  if(isset($_COOKIE['webgp_data']['y_grid'])){
178                print "<INPUT type=\"checkbox\" name=\"y_grid\" value=\"checked\" ".
179                              $_COOKIE['webgp_data']['y_grid'].">y\n";
180                  }else{
181                print "<INPUT type=\"checkbox\" name=\"y_grid\" value=\"checked\" ".">y\n";
182                  }
183   
184         print "&nbsp;&nbsp;\n";
185         if(isset($_COOKIE['webgp_data']['monochrome'])){
186           print '<INPUT type="checkbox" name="monochrome" value="checked" '.
187             $_COOKIE['webgp_data']['monochrome'].">白黒\n";
188         }else{
189           print '<INPUT type="checkbox" name="monochrome" value="checked" '.">白黒\n";
190         }
191   
192                          ?>
193   
194   
195       </TR>
196   
197       <!-- ---------- xデータ ------------- -->
198       <TR>
199       <TD><a href="/yamamoto/comp/graph/web_gnuplot/help/x_data.php" class="help">xデータ</a></TD>
200       <TD><?PHP
201             if(isset($_COOKIE['webgp_data']['x_row'])){
202                 set_select("x_row",$x_low,$_COOKIE['webgp_data']['x_row']);
203             }else{
204                 set_select("x_row",$x_low,0);
205             }
206             ?>
207       </TD>
208       </TR>
209   
210       <!-- ---------- yデータ ------------- -->
211       <TR>
212       <TD><a href="/yamamoto/comp/graph/web_gnuplot/help/y_data.php" class="help">yデータ</a></TD>
213       <TD><?PHP
214             if(isset($_COOKIE['webgp_data']['y_row'])){
215                 set_select("y_row",$y_low,$_COOKIE['webgp_data']['y_row']);
216             }else{
217                 set_select("y_row",$y_low,1);
218             }
219   
220         print "&nbsp;&nbsp;\n";
221         ?>
222         ポイントサイズ&nbsp;<INPUT size="4" type="text" name="psize" <?PHP
223                      if(isset($_COOKIE['webgp_data']['psize'])){
224                        print "value=\"".$_COOKIE['webgp_data']['psize']."\">\n";
225                      }else{
226                        print "value=1.0>\n";
227                      }
228            
229             print "&nbsp;ライン\n";
230   
231             if(isset($_COOKIE['webgp_data']['line'])){
232                 set_select("line",$line,$_COOKIE['webgp_data']['line']);
233             }else{
234                 set_select("line",$line,0);
235             }
236             ?>
237       </TD>
238       </TR>
239   
240       <!-- ---------- データエリア ------------- -->
241       <TR>
242             <TD colspan=2><a href="help/data_area.php" class="help">データエリア</a>&nbsp;<INPUT TYPE=button VALUE="データクリア" onClick="location.href='/yamamoto/comp/graph/web_gnuplot/index.php?status=clear'"></TD>
243       </TR>
244       <TR>
245       <TD colspan=2><textarea name="plot_data" cols=60 rows=20><?PHP
246                     if(isset($_COOKIE['webgp_data']['plot_data']) && $_GET['status']!="clear"){
247                         print "\n".$_COOKIE['webgp_data']['plot_data']."\n";
248                     }
249   ?></textarea></TD>
250       </TR>
251       <TR>
252   
253   
254       <!-- ---------- 描画 ------------- -->
255       <TR>
256       <TD><a href="/yamamoto/comp/graph/web_gnuplot/help/byoga.php" class="help">描画</a></TD>
257           
258       <TD>
259           <?PHP
260           print "ファイル&nbsp;";
261             if(isset($_COOKIE['webgp_data']['g_file'])){
262                 set_select("g_file",$g_file,$_COOKIE['webgp_data']['g_file']);
263             }else{
264                 set_select("g_file",$g_file,0);
265             }
266   
267             ?>
268                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
269           <INPUT TYPE="submit" value="プロット">
270           </TD>
271       </TR>
272   
273       </TBODY>
274       </TABLE>
275   </FORM>
276   
277   <!-- ---------------- 関数 ----------------------- -->
278   <?php
279                //=================================================================
280                // setting of radio button
281                //    1st argument:name
282                //    2nd argument:label
283                //    3rd argument:checked number
284                //=================================================================
285                function set_radio($name,$label,$on){
286                              for($i=0; isset($label[$i]); $i++){
287                                  if($i==$on){
288                                      print "<INPUT type=\"radio\" name=\"".$name."\" value=\"".$i.
289                                      "\" checked>".$label[$i]."\n";
290                                  }else{
291                                      print "<INPUT type=\"radio\" name=\"".$name."\" value=\"".$i.
292                                      "\">".$label[$i]."\n";
293                                  }
294                              }
295                          }
296   
297                //=================================================================
298                // setting of select
299                //    1st argument:name
300                //    2nd argument:label
301                //    3rd argument:selected number
302                //=================================================================
303                function set_select($name,$label,$on=1){
304                    print "<select name=\"".$name."\">\n";
305                              for($i=0; isset($label[$i]); $i++){
306                                  if($i==$on){
307                                      print "<option value=".$i." selected>".$label[$i]."\n";
308                                  }else{
309                                      print "<option value=".$i.">".$label[$i]."\n";
310                                  }
311                              }
312                              print "</select>\n";
313                          }
314   
315   ?>
316   
317   <!-- ---------------- 本文はここまで ---------------- -->
318   <?PHP
319    $show_counter=FALSE;
320    $show_update=TRUE;
321    include "../../../end_process.php";
322   ?>
323   
324   
325   </BODY>
326   </HTML>

mk_graph.php

mk_grpaht.php のソースリスト

001   <!-- -*- coding:euc-jp -*- -->
002   
003   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
004   <html lang="ja">
005   
006       <HEAD> 
007       <META HTTP-EQUIV = "Content-Type" CONTENT = "text/html; charset=EUC-JP">
008       <META http-equiv="Pragma" content="no-cache">
009       <META http-equiv="Cache-Control" content="no-cache">
010       <META http-equiv="Expires" content="0">
011       <meta http-equiv="Content-Script-Type" content="text/javascript">
012       <link rel="stylesheet" href="../../../stylesheet.css" type="text/css">
013       <TITLE>グラフの作成</TITLE>
014       <STYLE TYPE="text/css">
015        <!--
016        h4 {margin-left:20px;}
017        p {margin-left:40px; margin-right:40px}
018        -->
019       </STYLE>
020       </HEAD>
021   
022       <BODY class="frame">
023   
024       <?PHP
025       mb_http_output("EUC_JP");
026       mb_internal_encoding("EUC_JP");
027       ob_start("mb_output_handler");
028       include "../../../head_menu.php";
029       ob_end_flush();
030   
031       // ----------------- POST値の受け取り(デフォルト付き) ------------------
032       $plot_data  = isset($_POST["plot_data"]) ? $_POST["plot_data"] : "";
033       $psize      = isset($_POST["psize"])     ? $_POST["psize"]     : "1.0";
034       $x_row      = isset($_POST["x_row"])     ? (int)$_POST["x_row"] : 0;
035       $y_row      = isset($_POST["y_row"])     ? (int)$_POST["y_row"] : 1;
036       $line       = isset($_POST["line"])      ? (int)$_POST["line"]  : 1;
037       $g_file_opt = isset($_POST["g_file"])    ? (int)$_POST["g_file"] : 0;
038   
039       // ----------------- クッキーの設定 ----------------------------------
040       $save_time=60*60*24;
041       SET_COOKIE("webgp_data", "title",      $save_time);
042       SET_COOKIE("webgp_data", "x_min",      $save_time);
043       SET_COOKIE("webgp_data", "x_max",      $save_time);
044       SET_COOKIE("webgp_data", "x_axis",     $save_time);
045       SET_COOKIE("webgp_data", "x_label",    $save_time);
046       SET_COOKIE("webgp_data", "y_min",      $save_time);
047       SET_COOKIE("webgp_data", "y_max",      $save_time);
048       SET_COOKIE("webgp_data", "y_axis",     $save_time);
049       SET_COOKIE("webgp_data", "y_label",    $save_time);
050       SET_COOKIE("webgp_data", "x_grid",     $save_time);
051       SET_COOKIE("webgp_data", "y_grid",     $save_time);
052       SET_COOKIE("webgp_data", "color",      $save_time);
053       SET_COOKIE("webgp_data", "x_row",      $save_time);
054       SET_COOKIE("webgp_data", "y_row",      $save_time);
055       SET_COOKIE("webgp_data", "y_withline", $save_time);
056       SET_COOKIE("webgp_data", "y_spline",   $save_time);
057       SET_COOKIE("webgp_data", "y_exp",      $save_time);
058       SET_COOKIE("webgp_data", "y_log",      $save_time);
059       SET_COOKIE("webgp_data", "psize",      $save_time);
060       SET_COOKIE("webgp_data", "line",       $save_time);
061       SET_COOKIE("webgp_data", "plot_data",  $save_time);
062       SET_COOKIE("webgp_data", "g_file",     $save_time);
063       SET_COOKIE("webgp_data", "monochrome", $save_time);
064   
065       //------------- 古いファイルの削除 ---------------------------------------------
066       $tmp_dir="tmp/";
067       $handle = opendir($tmp_dir);
068       while(false !== ($file = readdir($handle))){
069           if($file != "." && $file != ".." && $file != "data.txt" && $file != "gp_error.txt"){
070           $file = $tmp_dir.$file;
071           $fst = stat($file);
072           $age = time()-$fst["mtime"];
073           if(3600<$age) unlink($file);
074           }
075       }
076       closedir($handle);
077   
078       //------------- plot_data が無ければ終了 ---------------------------------------
079       if ($plot_data === "") {
080           print "<h4>グラフ</h4>\n";
081           print "<p>プロットデータが指定されていません。</p>\n";
082           print "<p><a href=\"/yamamoto/comp/graph/web_gnuplot/index.php\">入力ページに戻る</a></p>\n";
083   
084           $show_counter=FALSE;
085           $show_update=TRUE;
086           include "../../../end_process.php";
087           exit;
088       }
089   
090       // ----------------- データファイル作成 ----------------------------------
091       $fp = fopen("tmp/data.txt", "w");
092       if($fp !== false){
093           fwrite($fp, $plot_data);
094           fclose($fp);
095       }else{
096           print "<p>tmp/data.txt を作成できませんでした。</p>\n";
097           $show_counter=FALSE;
098           $show_update=TRUE;
099           include "../../../end_process.php";
100           exit;
101       }
102   
103       $error = 0;
104       $message = array();
105   
106       $descriptorspec = array(
107           0 => array("pipe", "r"),               // stdin
108           1 => array("pipe", "w"),               // stdout
109           2 => array("file", "tmp/gp_error.txt", "a") // stderr
110       );
111   
112       $gnuplot = proc_open('gnuplot', $descriptorspec, $pipes);
113   
114       if ( ! is_resource($gnuplot) ) {
115           print "proc_open error\n";
116           $show_counter=FALSE;
117           $show_update=TRUE;
118           include "../../../end_process.php";
119           exit(1);
120       }
121   
122       // ----------------- グラフ作成 ----------------------------------
123       $stdout_file = "tmp/stdout.txt";
124   
125       fwrite($pipes[0], "reset\n");
126       fwrite($pipes[0], "set print \"".$stdout_file."\"\n");
127   
128       if(isset($_POST["monochrome"])){
129           fwrite($pipes[0], "set terminal postscript eps enhanced monochrome dashed font 'CenturySchL-Roma,18'\n");
130       }else{
131           fwrite($pipes[0], "set terminal postscript eps enhanced solid color font 'CenturySchL-Roma,18'\n");
132       }
133   
134       fwrite($pipes[0], "set output \"tmp/graph.eps\"\n");
135       fwrite($pipes[0], "unset key\n");
136       fwrite($pipes[0], "set samples 2048\n");
137       fwrite($pipes[0], "set tics scale 2,1\n");
138       fwrite($pipes[0], "set style line 1 lt 4 lw 3 pt 7 ps ".$psize."\n");
139   
140       if(isset($_POST["title"])){
141           fwrite($pipes[0], "set title \"".$_POST["title"]."\"\n");
142           fwrite($pipes[0], "show title\n");
143       }
144   
145       if(isset($_POST["x_label"])){
146           fwrite($pipes[0], "set xlabel \"".$_POST["x_label"]."\"\n");
147       }
148   
149       if(isset($_POST["y_label"])){
150           fwrite($pipes[0], "set ylabel \"".$_POST["y_label"]."\"\n");
151       }
152   
153       if(isset($_POST["x_min"]) && isset($_POST["x_max"])){
154           if($_POST["x_min"] < $_POST["x_max"]){
155           fwrite($pipes[0], "set xrange [".$_POST["x_min"].":".$_POST["x_max"]."]\n");
156           }else{
157           $message[$error] = "x軸:最大は,最小より大きくする必要があります.";
158           $error++;
159           }
160       }
161   
162       if(isset($_POST["y_min"]) && isset($_POST["y_max"])){
163           if($_POST["y_min"] < $_POST["y_max"]){
164           fwrite($pipes[0], "set yrange [".$_POST["y_min"].":".$_POST["y_max"]."]\n");
165           }else{
166           $message[$error] = "y軸:最大は,最小より大きくする必要があります.";
167           $error++;
168           }
169       }
170   
171       if(isset($_POST["x_axis"])){
172           if(isset($_POST["x_min"]) && $_POST["x_min"] <= 0){
173           $message[$error] = "x軸:対数目盛の場合,最小はゼロより大きくする必要があります.";
174           $error++;
175           }else{
176           fwrite($pipes[0], "set logscale x\n");
177           }
178       }
179   
180       if(isset($_POST["y_axis"])){
181           if(isset($_POST["y_min"]) && $_POST["y_min"] <= 0){
182           $message[$error] = "y軸:対数目盛の場合,最小はゼロより大きくする必要があります.";
183           $error++;
184           }else{
185           fwrite($pipes[0], "set logscale y\n");
186           }
187       }
188   
189       if(isset($_POST['x_grid']) && $_POST['x_grid'] == "checked"){
190           fwrite($pipes[0], "set grid xtics mxtics\n");
191       }
192   
193       if(isset($_POST['y_grid']) && $_POST['y_grid'] == "checked"){
194           fwrite($pipes[0], "set grid ytics mytics\n");
195       }
196   
197       //------------- 最小自乗法 ---------------------------------------------
198       $xxx = $x_row + 1;
199       $yyy = $y_row + 1;
200       $x_y = $xxx . ":" . $yyy;
201   
202       $fit_func = "";
203       $para = "";
204   
205       if(2 < $line){
206   
207           if($line == 3){
208           $fit_func = "a*exp(b*x)";
209           $para = "a,b";
210           }else if($line == 4){
211           $fit_func = "a*log(b*x)";
212           $para = "a,b";
213           }else if(4 < $line && $line < 15){
214           $fit_func = "a0";
215           $para = "a0";
216           for($i=1; $i <= $line-5; $i++){
217               if($i == 1){
218               $fit_func .= "+a".abs($i)."*x";
219               }else{
220               $fit_func .= "+a".abs($i)."*x**".abs($i);
221               }
222               $para .= ",a".abs($i);
223           }
224           }else if(14 < $line && $line < 24){
225           $fit_func = "a1*x";
226           $para = "a1";
227           for($i=2; $i <= $line-14; $i++){
228               $fit_func .= "+a".abs($i)."*x**".abs($i);
229               $para .= ",a".abs($i);
230           }
231           }
232   
233           if($fit_func != "" && $para != ""){
234           fwrite($pipes[0], "f(x)=".$fit_func."\n");
235           fwrite($pipes[0], "fit f(x) \"tmp/data.txt\" using ".$x_y." via ".$para."\n");
236           fwrite($pipes[0], "print ".$para."\n");
237           }
238       }
239   
240       //------------- グラフファイル作成 ---------------------------------------------
241       if($line != 1){
242           fwrite($pipes[0], "plot \"tmp/data.txt\" using ".$x_y." with points ls 1");
243       }else{
244           fwrite($pipes[0], "plot \"tmp/data.txt\" using ".$x_y." with linespoints ls 1");
245       }
246   
247       if($line == 2){
248           fwrite($pipes[0], ",\"tmp/data.txt\" using ".$x_y." smooth csplines with lines");
249       }else if($line == 3){
250           fwrite($pipes[0], ",f(x)");
251       }else if($line == 4){
252           fwrite($pipes[0], ",f(x)");
253       }else if(4 < $line && $line < 23){
254           fwrite($pipes[0], ",f(x)");
255       }
256   
257       fwrite($pipes[0], "\n");
258   
259       //------------- グラフファイル作成 ---------------------------------------------
260       srand((double)microtime()*1000000);
261       $gf_name = rand(100000,999999);
262   
263       $f_type = "eps";
264       $g_file = "tmp/".$gf_name;
265   
266       if(isset($_POST["monochrome"])){
267           $term_set = "postscript eps enhanced monochrome dashed font 'CenturySchL-Roma,18'";
268       }else{
269           $term_set = "postscript eps enhanced solid color font 'CenturySchL-Roma,18'";
270       }
271   
272       fwrite($pipes[0], "set terminal ".$term_set."\n");
273       fwrite($pipes[0], "set output \"".$g_file.".eps"."\"\n");
274       fwrite($pipes[0], "replot\n");
275   
276       if(isset($_POST["monochrome"])){
277           $term_set = "emf monochrome dashed enhanced font 'CenturySchL-Roma,18'";
278       }else{
279           $term_set = "emf color solid enhanced font 'CenturySchL-Roma,18'";
280       }
281   
282       fwrite($pipes[0], "set terminal ".$term_set."\n");
283       fwrite($pipes[0], "set output \"".$g_file.".emf"."\"\n");
284       fwrite($pipes[0], "replot\n");
285   
286       //------------- クローズ ---------------------------------------------
287       fclose($pipes[0]);
288       proc_close($gnuplot);
289   
290       $sys_cmd = sprintf("convert -density 100 -units PixelsPerInch %s %s", $g_file.".eps", "tmp/graph.png");
291       system($sys_cmd);
292   
293       if($g_file_opt == 0){
294           $f_type = "emf";
295           $plot_file = $g_file.".".$f_type;
296       }else if($g_file_opt == 1){
297           $f_type = "eps";
298           $plot_file = $g_file.".".$f_type;
299       }else if($g_file_opt == 2){
300           $f_type = "png";
301           $plot_file = $g_file.".".$f_type;
302           $sys_cmd = sprintf("convert -density 600 -units PixelsPerInch %s %s", $g_file.".eps", $g_file.".png");
303           system($sys_cmd);
304       }else if($g_file_opt == 3){
305           $f_type = "png";
306           $plot_file = $g_file.".".$f_type;
307           $sys_cmd = sprintf("convert -density 600 -units PixelsPerInch %s %s", $g_file.".eps", $g_file.".png");
308           system($sys_cmd);
309       }
310   
311       //------------- ディスプレイ表示 ---------------------------------------------
312       print '<h4>グラフ</h4>'."\n";
313   
314       print "<p><a href=\"".$g_file.".".$f_type."\">グラフのファイル(".$f_type.")</a>ができましたので,右クリックによりダウンロードしてください.</p>\n";
315   
316       if($error == 0){
317           print "<div style=\"width:640px;padding:10px 30px 30px 30px;margin:40px;background-color:#CEE0FF;\">\n";
318           print "<div style=\"margin-top:0px;margin-left:20px;margin-bottom:10px;\">\n";
319           print "<INPUT TYPE=button VALUE=\"グラフの修正\" onClick=\"location.href='/yamamoto/comp/graph/web_gnuplot/index.php'\">\n";
320           print "</div>\n";
321           print "<img src=\"tmp/graph.png\">\n";
322           print "</div>\n";
323       }else{
324           print $error."個の入力にエラーがあります.<BR>\n";
325           print "<ol>\n";
326           foreach($message as $txt){
327           print "<li>".$txt."</li><BR>\n";
328           }
329           print "</ol>\n";
330       }
331   
332       //------------- フィッティングの結果表示 ---------------------------------------------
333       if(2 < $line && $para != "" && $fit_func != ""){
334           $fh = fopen($stdout_file, "r");
335           if($fh !== false){
336           $fit_line = fgets($fh, 4096);
337           fclose($fh);
338   
339           $fit = preg_split("/\s+/", trim($fit_line));
340           $p = explode(",", $para);
341   
342           print '<h4>フィッティング結果</h4>'."\n";
343           print '<p>フィッティング関数は,</p>';
344           print '<p><span style="padding-left:50px;color:red;">f(x)='.$fit_func."</span></p>";
345           print "<p>です.フィッティングのパラメーターは次のようになります.</p>\n";
346   
347           $i = 0;
348           foreach($fit as $value){
349               if(isset($p[$i])){
350               print "<p style=\"padding-left:80px;color:red;\">".$p[$i]." = ".$value."</p>";
351               }
352               $i++;
353           }
354           }
355       }
356       ?>
357   
358       <!-- ---------------- 本文はここまで ---------------- -->
359       <?PHP
360       $show_counter=FALSE;
361       $show_update=TRUE;
362       include "../../../end_process.php";
363       ?>
364   
365       <!-- ---------------- 関数 ----------------------- -->
366       <?php
367       //=================================================================
368       // setting of radio button
369       //    1st argument:name
370       //    2nd argument:label
371       //    3rd argument:checked number
372       //=================================================================
373       function SET_COOKIE($cn,$arg,$time){
374           if(isset($_POST[$arg])){
375           setcookie("webgp_data[$arg]", $_POST[$arg], time()+$time);
376           }
377       }
378       ?>


no counter