⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.c

📁 GESPI 2.0动态系统模拟工具  
💻 C
📖 第 1 页 / 共 2 页
字号:
      for( i=0; i<nsteps; i++ )
      {
       wsprintf( (LPSTR) auxstr, "J(%s)", (LPSTR) stepname[i] );
       AddXYZLst( hX, (LPSTR) auxstr );
       AddXYZLst( hY, (LPSTR) auxstr );
       AddXYZLst( hZ, (LPSTR) auxstr );
      }
     }
     return TRUE;

    case IDC_HELP:            /* Help on this Dialog Box				*/
  	 WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Plot" );
   	 return TRUE;

    case IDOK:
     /* save type and file */
     plot.file = file;
     plot.type = type;
     /* get x, y and z */
     plot.x = (int) SendMessage( hX, LB_GETCURSEL, 0, 0 );
     plot.ny = (int) SendMessage( hY, LB_GETSELITEMS, (WORD) 10, (DWORD) (int huge *) plot.y );
     plot.z = (int) SendMessage( hZ, LB_GETCURSEL, 0, 0 );
     /* get lines, xlog, ylog and zlog */
     plot.logx = (int) SendDlgItemMessage( hDlg, IDRB_2E, BM_GETCHECK, 0, 0 );
     plot.logy = (int) SendDlgItemMessage( hDlg, IDRB_2I, BM_GETCHECK, 0, 0 );
     plot.logz = (int) SendDlgItemMessage( hDlg, IDRB_3E, BM_GETCHECK, 0, 0 );
     plot.lines = (int) SendDlgItemMessage( hDlg, IDRB_4E, BM_GETCHECK, 0, 0 );
     plot.colour = (int) SendDlgItemMessage( hDlg, IDRB_4I, BM_GETCHECK, 0, 0 );
     plot.contour = (int) SendDlgItemMessage( hDlg, IDRB_5E, BM_GETCHECK, 0, 0 );
     plot.hidden = (int) SendDlgItemMessage( hDlg, IDRB_5I, BM_GETCHECK, 0, 0 );
     /* close this dialog box */
     EndDialog(hDlg, IDOK);
     return TRUE;

    case IDCANCEL:
     EndDialog(hDlg, IDCANCEL);
     return TRUE;
   }    /* End of WM_COMMAND                                 */
   return FALSE;

  default:
   return FALSE;
 }
}

/* Function of dialog box to point GnuplotExe	*/

int FAR PASCAL EdGnuplot(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
{
 switch(Message)
 {
  case WM_INITDIALOG:
   return TRUE;

  case WM_COMMAND:
   switch(wParam)
   {
    case IDC_HELP:            /* Help on this Dialog Box				*/
   	 WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Plot" );
   	 return TRUE;

    case IDOK:
     /* close this dialog box */
     EndDialog(hDlg, IDOK);
     return TRUE;

    case IDCANCEL:
     EndDialog(hDlg, IDCANCEL);
     return TRUE;
   }    /* End of WM_COMMAND                                 */
   return FALSE;

  default:
   return FALSE;
 }
}


/* sets the labels for a plot of the dynamics */

void label_dyn( int idx, LPSTR str )
{
 if( idx == 0 )
  wsprintf( (LPSTR) str, "'time'" );
 else
  if( idx <= nmetab )
   wsprintf( (LPSTR) str, "'[%s]'", (LPSTR) metname[idx-1] );
   else
    if( idx > nmetab )
     wsprintf( (LPSTR) str, "'J(%s)'", (LPSTR) stepname[idx-1-nmetab] );
}

void label_dat( int idx, LPSTR str )
{
 int i;

 for( i=0; i<noutpel; i++ )
  if( outpel[i].idx-1 == (unsigned int) idx ) break;
 wsprintf( (LPSTR) str, "'%s'", outpel[i].title );
}


/* builds the commands for gnuplot to draw the plot */

void plot_text( LPSTR Buff )
{
 char File[256];
 char auxstr[128];
 char *p;
 int i, j;

 *Buff = '\0';
 if( plot.ny == 1 ) lstrcat( (LPSTR) Buff, (LPSTR) "set nokey\n" );
 if( plot.type != 0 )
 {
  lstrcat( (LPSTR) Buff, (LPSTR) "set parametric\nset ticslevel 0\n" );
  lstrcat( (LPSTR) Buff, (LPSTR) "set nopolar\nset surface\n" );
  lstrcat( (LPSTR) Buff, (LPSTR) "set urange [1e-20:]\nset vrange[1e-20:]\n" );
  if( plot.hidden )
   lstrcat( (LPSTR) Buff, (LPSTR) "set hidden3d\n" );
  else
   lstrcat( (LPSTR) Buff, (LPSTR) "set nohidden3d\n" );
  if( plot.contour )
   lstrcat( (LPSTR) Buff, (LPSTR) "set contour base\nset cntrparam bspline\n" );
  else
   lstrcat( (LPSTR) Buff, (LPSTR) "set nocontour\n" );
 }
 if( plot.logx ) lstrcat( (LPSTR) Buff, (LPSTR) "set logscale x\n" );
 if( plot.logy ) lstrcat( (LPSTR) Buff, (LPSTR) "set logscale y\n" );
 if( plot.logz ) lstrcat( (LPSTR) Buff, (LPSTR) "set logscale z\n" );
 if( plot.file==0 )
 {
  lstrcpy( (LPSTR) File, (LPSTR) FileName );
  if ( p = strrchr( File, '.' ) ) strcpy( p, ".dyn" );
  else strcat( File, ".dyn" );
  wsprintf( (LPSTR) auxstr, (LPSTR) "set title '%s'\n", (LPSTR) FileTitle );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  wsprintf( (LPSTR) auxstr, (LPSTR) "set xlabel " );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  label_dyn( plot.x, (LPSTR) auxstr );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  if( plot.ny==1 )
  {
   wsprintf( (LPSTR) auxstr, (LPSTR) "set ylabel " );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   label_dyn( plot.y[0], (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  }
  if( plot.type==1 )
  {
   wsprintf( (LPSTR) auxstr, (LPSTR) "set zlabel " );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   label_dyn( plot.z, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  }
 }
 else
 {
  lstrcpy( (LPSTR) File, (LPSTR) DatName );
  wsprintf( (LPSTR) auxstr, (LPSTR) "set title '%s'\n", (LPSTR) DatTitle );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  wsprintf( (LPSTR) auxstr, (LPSTR) "set xlabel " );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  label_dat( plot.x, (LPSTR) auxstr );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
  lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  if( plot.type != 0 )
  {
   wsprintf( (LPSTR) auxstr, (LPSTR) "set zlabel " );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   label_dat( plot.z, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  }
  if( plot.ny==1 )
  {
   wsprintf( (LPSTR) auxstr, (LPSTR) "set ylabel " );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   label_dat( plot.y[0], (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
   lstrcat( (LPSTR) Buff, (LPSTR) "\n" );
  }
 }
 if( plot.type != 0 )  lstrcat( (LPSTR) Buff, (LPSTR) "s" );
 wsprintf( (LPSTR) auxstr, (LPSTR) "plot '%s' using %d:%d", (LPSTR) File, plot.x+1, plot.y[0]+1 );
 lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
 if( plot.ny > 1 )
 {
  lstrcat( (LPSTR) Buff, (LPSTR) " title " );
  if( plot.file==0 ) label_dyn( plot.y[0], (LPSTR) auxstr );
  else label_dat( plot.y[0], (LPSTR) auxstr );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
 }
 if( plot.type != 0 )
 {
  wsprintf( (LPSTR) auxstr, (LPSTR) ":%d", plot.z+1 );
  lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
 }
 if( plot.lines ) lstrcat( (LPSTR) Buff, (LPSTR) " with lines" );
 else lstrcat( (LPSTR) Buff, (LPSTR) " with dots" );
 if( plot.type==0 )
 {
  if( plot.ny > 1 )
   for( i=1; i<plot.ny; i++ )
   {
    wsprintf( (LPSTR) auxstr, (LPSTR) ", '%s' using %d:%d",
              (LPSTR) File, plot.x+1, plot.y[i]+1 );
    lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
    lstrcat( (LPSTR) Buff, (LPSTR) " title " );
    if( plot.file==0 ) label_dyn( plot.y[i], (LPSTR) auxstr );
    else label_dat( plot.y[i], (LPSTR) auxstr );
    lstrcat( (LPSTR) Buff, (LPSTR) auxstr );
    if( plot.lines ) lstrcat( (LPSTR) Buff, (LPSTR) " with lines" );
   }
 }
 lstrcat( (LPSTR) Buff, (LPSTR) "\npause -1 \"Press button to close\"\n" );
}


/* launches gnuplot to draw a plot (2D or 3D) */

int GnuPlot( HWND hWnd )
{
 OFSTRUCT OfStruct;
 int hFile, nRc;
 GLOBALHANDLE hBuff;
 LPSTR Buff;
 char szString[256];
 char GnuplotFile[256];

 hBuff = GlobalAlloc( GMEM_MOVEABLE | GMEM_DISCARDABLE, 1024 );
 Buff = GlobalLock( hBuff );

 /* generate a name for temporary file	*/
 GetTempFileName( 0, (LPSTR) "GPL", 0, (LPSTR) GnuplotFile );
 /* and add it to the list of files to delete in the end */
 GlobalUnlock( hTmpF );
 hTmpF = GlobalReAlloc( hTmpF, lstrlen( TmpFiles ) + lstrlen( GnuplotFile ) + 2, 0 );
 TmpFiles = GlobalLock( hTmpF );
 lstrcat( TmpFiles, GnuplotFile );
 lstrcat( TmpFiles, (LPSTR) "+" );
 /* put the gnuplot commands in Buff */
 plot_text( Buff );
 /* open the temporary file */
 hFile = OpenFile( (LPSTR) GnuplotFile, &OfStruct, OF_CREATE | OF_WRITE | OF_SHARE_COMPAT );
 {
  /* write the buffer to the file and close it							*/
  nRc = _lwrite( hFile, (LPSTR) Buff, (WORD) lstrlen( (LPSTR) Buff ) );
  _lclose( hFile );
 }
 if( nRc < lstrlen( Buff ) )
 {
  LoadString(hInst, IDS_ERR_NO_TEMP, szString, sizeof(szString));
  MessageBeep( MB_OK );
  MessageBox( hWnd, szString, FileTitle, MB_ICONINFORMATION );
  return IDS_ERR_NO_TEMP;
 }
 wsprintf( (LPSTR) szString, (LPSTR) "%s %s", (LPSTR) GnuplotExe, (LPSTR) GnuplotFile );
 if( options.debug )
 {
  lstrcat( (LPSTR) Buff, "\n\n" );
  lstrcat( (LPSTR) Buff, (LPSTR) szString );
  MessageBox( hWnd, Buff, (LPSTR) GnuplotFile, MB_ICONINFORMATION );
 }
 nRc = WinExec( (LPSTR) szString, SW_MINIMIZE );
 if( nRc<32 )
 {
  if( (nRc==2) || (nRc==3) )
   *GnuplotExe = '\0';
  else
   ErrorHandler( hInst, nRc );
  return nRc;
 }
 return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -