コード例 #1
0
ファイル: exa_c.c プロジェクト: kastur/artificial_birds
/* >>>>>>>>>> EX14_1 <<<<<<<<<< */
void ex14_1 (void)
{ int n = 50, i, j;
  double   fpi = 3.14159 / 180., step, x, y;
  float  zlev;

  step = 360. / (n - 1);

  for (i = 0; i < n; i++)
  { xray[i] = (float) (i * step);
    yray[i] = (float) (i * step);
  }

  for (i = 0; i < n; i++)
  { for (j = 0; j < n; j++)
    { x = xray[i] * fpi;
      y = yray[j] * fpi;    
      zmat[i][j] = (float) (2 * sin (x) * sin (y));
    }
  }

  setpag ("da4p");
  disini ();
  complx ();
  pagera ();

  titlin ("Contour Plot", 1);
  titlin ("F(X,Y) = 2 * SIN(X) * SIN(Y)", 3);

  name   ("X-axis", "x");
  name   ("Y-axis", "y");

  intax  ();
  axspos (450, 2670);
  graf   (0.f, 360.f, 0.f, 90.f, 0.f, 360.f, 0.f, 90.f);

  height (30);
  for (i = 0; i < 9; i++)
  { zlev = (float) (-2. + i * 0.5);
    setclr ((i + 1) * 25);
    if (i == 4)
      labels ("none", "contur"); 
    else
      labels ("float", "contur");

    contur  (xray, n, yray, n, (float *) zmat, zlev);
  }

  height (50);
  color  ("fore");
  title  ();
  disfin ();
}
コード例 #2
0
ファイル: orbital.c プロジェクト: johannesgerer/jburkardt-c
int main ( int argc, char *argv[] )

/******************************************************************************/
/*
  Purpose:

    ORBITAL uses DISLIN to display a contour plot of Z(X,Y) data.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    20 May 2011

  Author:

    John Burkardt

  Reference:

    Helmut Michels,
    The Data Plotting Software DISLIN - version 10.4,
    Shaker Media GmbH, January 2010,
    ISBN13: 978-3-86858-517-9.
*/
{
  int i;
  int j;
  int k;
  int level;
  int level_num;
  float level_value;
  int m;
  int n;
  int nn;
  float *x;
  float xmax;
  float xmin;
  float *xyz;
  float *y;
  float ymax;
  float ymin;
  float *z;
  float zmax;
  float zmin;

  printf ( "\n" );
  printf ( "ORBITAL:\n" );
  printf ( "  C version:\n" );
  printf ( "  Use DISLIN to make a contour plot of Z(X,Y) data.\n" );
/*
  Read the data.
*/
  r4mat_header_read ( "orbital.txt", &m, &nn );

  xyz = r4mat_data_read ( "orbital.txt", m, nn );
/*
  Split the data.
  The contouring routine expects that data is along fixed X and Y coordinates,
  and so the X and Y data is to be given as vectors, not arrays.
*/
  n = 101;
  x = ( float * ) malloc ( n * sizeof ( float ) );
  y = ( float * ) malloc ( n * sizeof ( float ) );
  z = ( float * ) malloc ( n * n * sizeof ( float ) );

  k = 0;
  for ( i = 0; i < n; i++ )
  {
    x[i] = xyz[0+k*3];
    k = k + 1;
  }
  xmin = r4vec_min ( n, x );
  xmax = r4vec_max ( n, x );

  k = 0;
  for ( i = 0; i < n; i++ )
  {
    y[i] = xyz[1+k*3];
    k = k + n;
  }
  ymin = r4vec_min ( n, y );
  ymax = r4vec_max ( n, y );
/*
  Z is a table.
  The first dimension should contain values for constant Y.
*/
  k = 0;
  for ( i = 0; i < n; i++ )
  {
    for ( j = 0; j < n; j++ )
    {
      z[i+j*n] = xyz[2+k*3];
      k = k + 1;
    }
  }
  zmax = r4mat_max ( n, n, z );
  zmin = r4mat_min ( n, n, z );
/*
  Specify the format of the output file.
*/
  metafl ( "png" );
/*
  Indicate that new data overwrites old data.
*/
  filmod ( "delete" );
/*
  Specify the name of the output graphics file.
*/
  setfil ( "orbital.png" );
/*
  Choose the page size and orientation.
  'USA' is 2160 plot units wide and 2790 plot units high.
  'P' requests PORTRAIT orientation.
*/
  setpag ( "usap" );
/*
  For PNG output, reverse the default black background to white.
*/
  scrmod ( "reverse" );
/*
  Open DISLIN.
*/
  disini ( );
/*
  Plot a border around the page.
*/
  pagera ( );
/*
  Use the SIMPLX font.
*/
  simplx ( );
/*
  Set the axis origin in plot units to the right, and plot units DOWN.
*/
  axspos ( 230, 2500 );
/*
  Define the X and Y sizes of the axis system in plot units.
*/
  axslen ( 1700, 1700 );
/*
  Label the X and Y axes.
*/
  name ( "X axis", "X" );
  name ( "Y axis", "Y" );
/*
  Relate the physical coordinates to the axes, and specify tick marks.
*/
  graf ( xmin, xmax, xmin, 1.0, ymin, ymax, ymin, 1.0 );
/*
  BEGIN LEVEL 2 COMMANDS.
*/

/*
  Define the title.
*/
  titlin ( "Orbital contour plot", 1 );
  title ( );
/*
  Set color to "blue".
*/
  color ( "blue" );
/*
  Draw the contour plot.
*/
  level_num = 10;

  for ( level = 1; level <= level_num; level++ )
  {
    level_value = ( ( float ) ( level_num + 1 - level ) * zmin   
                  + ( float ) (                 level ) * zmax ) 
                  / ( float ) ( level_num + 1         );

    contur ( x, n, y, n, z, level_value );
  }
/*
  End this graph.
*/
  endgrf ( );
/*
  RETURN FROM LEVEL 2 TO LEVEL 1.
*/

/*
  Close DISLIN.
*/
  disfin ( );
/*
  Free memory.
*/
  free ( x );
  free ( xyz );
  free ( y );
  free ( z );
/*
  Terminate.
*/
  printf ( "\n" );
  printf ( "ORBITAL:\n" );
  printf ( "  Normal end of execution.\n" );

  return 0;
}