#include "trs5-inc.mm" #include "tincas2_inc.mm" // ****** テンキーによって増減操作されるパラメータを指定 ******* #define PRM1 TdoD1 #define PRM1STR "TdoD1" /* #define PRM1 Pms1 #define PRM1STR "Pms1" */ #define PRM2 TV1 #define PRM2STR "TV1" Func void print_prm() { printf("TdoD1: %g TV1: %g GV1: %g Pms1: %g UlV1: %g\n",TdoD1,TV1,GV1,Pms1,UlV1); } Func void print_help() { printf("P:\tパラメータ Pms1 の値を設定\n"); printf("G:\tパラメータ GV1 の値を設定\n"); printf("t:\tパラメータ TV1 の値を設定\n"); printf("T:\tパラメータ TdoD1 の値を設定\n"); printf("U:\tパラメータ UlV1 の値を設定\n"); printf("A:\t画面の範囲を適当に調節\n"); printf("h:\tルンゲクッタ法の時間刻を設定\n"); printf("u:\ttincas canvas の更新時間間隔設定\n"); printf("5:\t%s_step,%s_step の値を設定\n",PRM1STR,PRM2STR); printf("4:\t%s を %s_step だけ減少\n",PRM1STR,PRM1STR); printf("6:\t%s を %s_step だけ増加\n",PRM1STR,PRM1STR); printf("2:\t%s を %s_step だけ減少\n",PRM2STR,PRM2STR); printf("8:\t%s を %s_step だけ増加\n",PRM2STR,PRM2STR); printf("x:\txmin xmax の値を設定\n"); printf("y:\tymin ymax の値を設定\n"); printf("m:\t現在の %s, %s の値をファイル bifu-m.mat に追加\n",PRM1STR,PRM2STR); printf("M:\tbifu-m.mat のプロット図を更新\n"); printf("n:\t現在の %s, %s の値をファイル bifu-n.mat に追加\n",PRM1STR,PRM2STR); printf("N:\tbifu-n.mat のプロット図を更新\n"); printf("p:\t現在の状態を表示\n"); printf("r:\t状態変数の値をファイルに保存\n"); printf("l:\t状態変数の値をファイルから読み込み\n"); printf("C:\tauto-clear のトグル\n"); printf("c:\ttincas 画面のクリア\n"); printf("q:\t終了\n"); printf("?:\tこのヘルプの表示\n"); } Func List kbd_event(t, x) Real t; Matrix x; { // シミュレーション中にキーボードを押したときの処理 static Real prm1step, prm2step; String buf; Matrix xyr; Matrix tmpp, tmppa, tmpp1, tmpp2; Index idx; Real tmp1, tmp2, tmp_eps; tmp1= 0.0; tmp2= 0.0; if (kbhit()) { switch (getch()) { // ************* trs5 に特有なコマンド ここから ********************* case 0x50: // P ... Pms printf("\n Pms1 (%g) : ",Pms1); buf= gets(); if (buf!=""){ {Pms1} = sscanf(buf,"%g"); } break; case 0x47: // G printf("\n GV1 (%g) : ",GV1); buf= gets(); if (buf!=""){ {GV1} = sscanf(buf,"%g"); } break; case 0x74: // t printf("\n TdoD1 (%g) : ",TdoD1); buf= gets(); if (buf!=""){ {TdoD1} = sscanf(buf,"%g"); } break; case 0x54: // T printf("\n TV1 (%g) : ",TV1); buf= gets(); if (buf!=""){ {TV1} = sscanf(buf,"%g"); } break; case 0x55: // U printf("\n UlV1 (%g) : ",UlV1); buf= gets(); if (buf!=""){ {UlV1} = sscanf(buf,"%g"); } break; // ************* trs5 に特有なコマンド ここまで ********************* case 0x41: // A print "\n"; set_canvas_xyrange(adjust_xyrange(_mes_xyrange)); break; case 0x68: // h printf("\n h (%g) : ",h); buf= gets(); if (buf!=""){ {h} = sscanf(buf,"%g"); } break; case 0x75: // u printf("\n update_interval (%d) : ",update_interval); buf= gets(); if (buf!=""){ {update_interval} = sscanf(buf,"%d"); set_tincas_update_interval(pid, update_interval); } break; case 0x34: // 4 print "\n"; PRM1 = PRM1 - prm1step; print_prm(); // 加減の反復で誤差が蓄積するので,適当に丸める tmp_eps= max(prm1step,sqrt(EPS)); tmp_eps= 10.0^( Integer(log10(tmp_eps))-2 ); PRM1= round(PRM1/tmp_eps)*tmp_eps; break; case 0x36: // 6 print "\n"; PRM1 = PRM1 + prm1step; print_prm(); // 加減の反復で誤差が蓄積するので,適当に丸める tmp_eps= max(prm1step,sqrt(EPS)); tmp_eps= 10.0^( Integer(log10(tmp_eps))-2 ); PRM1= round(PRM1/tmp_eps)*tmp_eps; break; case 0x35: // 5 printf("\n %s_step (%g) : ",PRM1STR,prm1step); buf= gets(); if (buf!=""){ {prm1step} = sscanf(buf,"%g"); } printf("\n %s_step (%g) : ",PRM2STR,prm2step); buf= gets(); if (buf!=""){ {prm2step} = sscanf(buf,"%g"); } break; case 0x32: // 2 print "\n"; PRM2 = PRM2 - prm2step; print_prm(); // 加減の反復で誤差が蓄積するので,適当に丸める tmp_eps= max(prm2step,sqrt(EPS)); tmp_eps= 10.0^( Integer(log10(tmp_eps))-2 ); PRM2= round(PRM2/tmp_eps)*tmp_eps; break; case 0x38: // 8 print "\n"; PRM2 = PRM2 + prm2step; print_prm(); // 加減の反復で誤差が蓄積するので,適当に丸める tmp_eps= max(prm2step,sqrt(EPS)); tmp_eps= 10.0^( Integer(log10(tmp_eps))-2 ); PRM2= round(PRM2/tmp_eps)*tmp_eps; break; case 0x78: // x xyr= get_canvas_xyrange(); printf("\n xmin xmax (%g %g) : ",xyr(1),xyr(2)); buf= gets(); if (buf!=""){ {tmp1,tmp2} = sscanf(buf,"%g %g"); set_canvas_xyrange([tmp1, tmp2, xyr(3), xyr(4)]); } break; case 0x79: // y xyr= get_canvas_xyrange(); printf("\n ymin ymax (%g %g) : ",xyr(3),xyr(4)); buf= gets(); if (buf!=""){ {tmp1,tmp2} = sscanf(buf,"%g %g"); set_canvas_xyrange([xyr(1), xyr(2), tmp1, tmp2]); } break; case 0x6d: // m print "\n"; if (access("./bifu-m.mat")==0){ read tmpp << "./bifu-m.mat"; }else{ tmpp=Z(0); } tmpp= [ tmpp, [[PRM1][PRM2]] ]; // 追加 // {tmpp1, idx}= sort(tmpp(1,:)); // 横軸でソート // tmpp2= tmpp(2,:); tmpp2= tmpp2(idx); // 縦軸も同じ順番で。 {tmpp2, idx}= sort(tmpp(2,:)); // 縦軸でソート tmpp1= tmpp(1,:); tmpp1= tmpp1(idx); // 横軸も同じ順番で。 tmpp= [ [tmpp1] [tmpp2] ]; // ソート済を戻す print tmpp >> "./bifu-m.mat"; gplot_title("bifu-m"); gplot_cmd("set pointsize 3\nset gri\nset nokey"); gplot(tmpp(1,:), tmpp(2,:), {"bifu-m"}, {"w linesp"}); break; case 0x4d: // M // 表示更新のみ print "\n"; if (access("./bifu-m.mat")==0){ read tmpp << "./bifu-m.mat"; gplot_title("bifu-m"); gplot_cmd("set pointsize 3\nset gri\nset nokey"); gplot(tmpp(1,:), tmpp(2,:), {"bifu-m"}, {"w linesp"}); } break; case 0x6e: // n print "\n"; if (access("./bifu-n.mat")==0){ read tmpp << "./bifu-n.mat"; }else{ tmpp=Z(0); } tmpp= [ tmpp, [[PRM1][PRM2]] ]; // 追加 //{tmpp1, idx}= sort(tmpp(1,:)); // 横軸でソート //tmpp2= tmpp(2,:); tmpp2= tmpp2(idx); // 縦軸も同じ順番で。 {tmpp2, idx}= sort(tmpp(2,:)); // 縦軸でソート tmpp1= tmpp(1,:); tmpp1= tmpp1(idx); // 横軸も同じ順番で。 tmpp= [ [tmpp1] [tmpp2] ]; // ソート済を戻す print tmpp >> "./bifu-n.mat"; gplot_title("bifu-n"); gplot_cmd("set pointsize 3\nset gri\nset nokey"); gplot(tmpp(1,:), tmpp(2,:), {"bifu-n"}, {"w linesp"}); break; case 0x4e: // N // 表示更新のみ print "\n"; if (access("./bifu-n.mat")==0){ read tmpp << "./bifu-n.mat"; gplot_title("bifu-n"); gplot_cmd("set pointsize 3\nset gri\nset nokey"); gplot(tmpp(1,:), tmpp(2,:), {"bifu-n"}, {"w linesp"}); if (access("./bifu-m.mat")==0){ read tmppa << "./bifu-m.mat"; gplot_cmd("set pointsize 3\nset gri\nset key"); greplot(tmppa(1,:), tmppa(2,:), {"bifu-m"}, {"w linesp"}); } } break; case 0x70: // p print "\n"; print_prm(); printf("t : %g (CPU time : %g)\n",t,gettimer()); print x; break; case 0x72: // r .. record x() to file print x >> "./xini.mat"; print "\nrecorded x to file :\n"; print x; break; case 0x6c: // l .. load x() from file print "\n"; if (access("./xini.mat")==0){ read x << "./xini.mat"; print "\nloaded x from file :\n"; print x; } break; case 0x52: // R .. record x() to file2 print x >> "./xini2.mat"; print "\nrecorded x to file2 :\n"; print x; break; case 0x4c: // L .. load x() from file2 print "\n"; if (access("./xini2.mat")==0){ read x << "./xini2.mat"; print "\nloaded x from file2 :\n"; print x; } break; case 0x43: // C .. toggle for auto-clear print "\n"; auto_clear= !auto_clear; if (auto_clear){ printf("\n auto_clear_interval (%d) : ",auto_clear_interval); buf= gets(); if (buf!=""){ { auto_clear_interval} = sscanf(buf,"%d"); } print "auto clear を有効にしました。\n"; }else{ print "auto clear を無効にしました。\n"; } break; case 0x63: // c print "\n"; clear_canvas(pid); break; case 0x71: // q print "\n"; close_canvas(pid); exit; break; case 0x3f: // ? print "\n"; rem_prm_output(); // 全globalパラメータの値を出す print "\n"; print_help(); break; default: break; } } return {t, x}; }