void write_xpm(FILE *out,unsigned int flags,
	       char *title,char *legend,char *label_x,char *label_y,
	       int n_x,int n_y,real axis_x[],real axis_y[],
	       real *matrix[],real lo,real hi,
	       t_rgb rlo,t_rgb rhi,int *nlevels)
{
  /* out        xpm file
   * title      matrix title
   * legend     label for the continuous legend
   * label_x    label for the x-axis
   * label_y    label for the y-axis
   * n_x, n_y   size of the matrix
   * axis_x[]   the x-ticklabels
   * axis_y[]   the y-ticklables
   * *matrix[]  element x,y is matrix[x][y]
   * lo         output lower than lo is set to lo
   * hi         output higher than hi is set to hi
   * rlo        rgb value for level lo
   * rhi        rgb value for level hi
   * nlevels    number of color levels for the output
   */

  if (hi <= lo) 
    gmx_fatal(FARGS,"hi (%f) <= lo (%f)",hi,lo);

  write_xpm_header(out,title,legend,label_x,label_y,FALSE);
  write_xpm_map(out,n_x,n_y,nlevels,lo,hi,rlo,rhi);
  write_xpm_axis(out,"x",flags & MAT_SPATIAL_X,n_x,axis_x);
  write_xpm_axis(out,"y",flags & MAT_SPATIAL_Y,n_y,axis_y);
  write_xpm_data(out,n_x,n_y,matrix,lo,hi,*nlevels);
}
void write_xpm_split(FILE *out,unsigned int flags,
		     char *title,char *legend,char *label_x,char *label_y,
		     int n_x,int n_y,real axis_x[],real axis_y[],
		     real *matrix[],
		     real lo_top,real hi_top,int *nlevel_top,
		     t_rgb rlo_top,t_rgb rhi_top,
		     real lo_bot,real hi_bot,int *nlevel_bot,
		     bool bDiscreteColor,
		     t_rgb rlo_bot,t_rgb rhi_bot)
{
  /* See write_xpm.
   * Writes a colormap varying as rlo -> rmid -> rhi.
   */

  if (hi_top <= lo_top) 
    gmx_fatal(FARGS,"hi_top (%g) <= lo_top (%g)",hi_top,lo_top);
  if (hi_bot <= lo_bot) 
    gmx_fatal(FARGS,"hi_bot (%g) <= lo_bot (%g)",hi_bot,lo_bot);
  if (bDiscreteColor && (*nlevel_bot >= 16)) 
    gmx_impl("Can not plot more than 16 discrete colors");
    
  write_xpm_header(out,title,legend,label_x,label_y,FALSE);
  write_xpm_map_split(out,n_x,n_y,nlevel_top,lo_top,hi_top,rlo_top,rhi_top,
		      bDiscreteColor,nlevel_bot,lo_bot,hi_bot,rlo_bot,rhi_bot);
  write_xpm_axis(out,"x",flags & MAT_SPATIAL_X,n_x,axis_x);
  write_xpm_axis(out,"y",flags & MAT_SPATIAL_Y,n_y,axis_y);
  write_xpm_data_split(out,n_x,n_y,matrix,lo_top,hi_top,*nlevel_top,
		       lo_bot,hi_bot,*nlevel_bot);
}
void
create_piece_xpm (char *outname, FILE *fpin, int W, int H)
{
  FILE *fpout;
  int w, h, i, j, c;
  unsigned char *lump, *p, *line;
  long size;
  z2xpm *cv;
  
  fpout = fopen( outname, "wb" );
  if ( !fpout )
	fatal( "Can't create output file.");

  /* Header is two ints -- Width then Height, x86 format */
  c = fgetc( fpin );
  w = (fgetc(fpin) << 8) | c;

  c = fgetc( fpin );
  h = (fgetc(fpin) << 8) | c;
  
  ++w; ++h;

  if ( w != W || h != H )
	fatal( "Bad header." );	  

  size = vga_imagesize( w, h ) - 4;
  lump = (unsigned char*)malloc( size );
  line = (unsigned char*)malloc( w );

  if ( !lump || !line )
	fatal( "Out of memory." );

  fread( lump, 1, size, fpin );

  /* Write XPM header */
  write_xpm_header( fpout, w, h );

  p = lump;
  
  /* Write XPM data */
  for( i=0; i<h; ++i )
	{
	  p = decode_line( line, p, w );
	  
	  fprintf( fpout, "\"" );
	  for( j=0; j<w; ++j )
		{
		  cv = lookup_xpm_color( line[j] );
		  fprintf( fpout, "%c", cv->xchar );
		}
	  fprintf( fpout, "\",\n" );
	}

  fprintf( fpout, "};\n" );
  
  free( lump );
  free( line );
  fclose( fpout );
}
void write_xpm3(FILE *out,unsigned int flags,
		char *title,char *legend,char *label_x,char *label_y,
		int n_x,int n_y,real axis_x[],real axis_y[],
		real *matrix[],real lo,real mid,real hi,
		t_rgb rlo,t_rgb rmid,t_rgb rhi,int *nlevels)
{
  /* See write_xpm.
   * Writes a colormap varying as rlo -> rmid -> rhi.
   */

  if (hi <= lo) 
    gmx_fatal(FARGS,"hi (%g) <= lo (%g)",hi,lo);

  write_xpm_header(out,title,legend,label_x,label_y,FALSE);
  write_xpm_map3(out,n_x,n_y,nlevels,lo,mid,hi,rlo,rmid,rhi);
  write_xpm_axis(out,"x",flags & MAT_SPATIAL_X,n_x,axis_x);
  write_xpm_axis(out,"y",flags & MAT_SPATIAL_Y,n_y,axis_y);
  write_xpm_data3(out,n_x,n_y,matrix,lo,mid,hi,*nlevels);
}
Exemple #5
0
int main(void) {
#else
int main(int argc, char **argv) {
#endif

  write_xpm_header();

  int x, y;
  for (y = YSTART; y < YEND; y += YSTEP_SIZE) {
    WRITE("\"", 1);
    for (x = XSTART; x < XEND; x += XSTEP_SIZE) {
      int val = do_iter(x, y, MAX_SQUARE, MAX_ITER);
      WRITE(&(map[val & 0x3f]), 1);
    }
    WRITE("\",\n", 3);
  }
  WRITE("};\n", 3);

  return 0;
}
void write_xpm_m(FILE *out, t_matrix m)
{
  /* Writes a t_matrix struct to .xpm file */ 
     
  int       i,j;
  bool      bOneChar;
  t_xpmelmt c;
  
  bOneChar=(m.map[0].code.c2 == 0);
  write_xpm_header(out,m.title,m.legend,m.label_x,m.label_y,
		   m.bDiscrete);
  fprintf(out,"static char *gromacs_xpm[] = {\n");
  fprintf(out,"\"%d %d   %d %d\",\n",m.nx,m.ny,m.nmap,bOneChar ? 1 : 2);
  for(i=0; (i<m.nmap); i++) 
    fprintf(out,"\"%c%c c #%02X%02X%02X \" /* \"%s\" */,\n",
	    m.map[i].code.c1,
	    bOneChar ? ' ' : m.map[i].code.c2,
	    (unsigned int)round(m.map[i].rgb.r*255),
	    (unsigned int)round(m.map[i].rgb.g*255),
	    (unsigned int)round(m.map[i].rgb.b*255),m.map[i].desc);
  write_xpm_axis(out,"x",m.flags & MAT_SPATIAL_X,m.nx,m.axis_x);
  write_xpm_axis(out,"y",m.flags & MAT_SPATIAL_Y,m.ny,m.axis_y);
  for(j=m.ny-1; (j>=0); j--) {
    if(j%(1+m.ny/100)==0) 
      fprintf(stderr,"%3d%%\b\b\b\b",(100*(m.ny-j))/m.ny);
    fprintf(out,"\"");
    if (bOneChar)
      for(i=0; (i<m.nx); i++)
	fprintf(out,"%c",m.map[m.matrix[i][j]].code.c1);
    else
      for(i=0; (i<m.nx); i++) {
	c=m.map[m.matrix[i][j]].code;
	fprintf(out,"%c%c",c.c1,c.c2);
      }
    if (j > 0)
      fprintf(out,"\",\n");
    else
      fprintf(out,"\"\n");
  }
}
Exemple #7
0
static void master(void) {
  unsigned i;

  write_xpm_header();

  /* clear response fields */
  for (i = 0; i < SLAVES; i++) {
    shm_master_mpb->slave[i].row.cmd = CMD_STOP;
  }
  /* send start packets */
  for (i = 0; i < SLAVES; i++) {
    shm_master_mpb->slave[i].packet.cmd = CMD_START;
    dma(&(shm_slave_mpb[i]->packet),
        &(shm_master_mpb->slave[i].packet),
        sizeof(struct packet_t));
  }
  /* wait for acknowledgement */
  for (i = 0; i < SLAVES; i++) {
    while (shm_master_mpb->slave[i].row.cmd != CMD_START) {
      /* spin until start reponse */
    }
  }
  /* clear response fields */
  for (i = 0; i < SLAVES; i++) {
    shm_master_mpb->slave[i].row.cmd = CMD_NULL;
  }

  int row[SLAVES];
  int received_row;
    
  /* send first packets to slaves */
  for (i = 0; i < SLAVES && i < ROWS; i++) {
    row[i] = i*(ROWS/SLAVES);   
    shm_master_mpb->slave[i].packet.cmd    = row[i];
    shm_master_mpb->slave[i].packet.yval   = YSTART + row[i]*YSTEP_SIZE;
    shm_master_mpb->slave[i].packet.xstart = XSTART;
    shm_master_mpb->slave[i].packet.xend   = XEND;
    shm_master_mpb->slave[i].packet.xstep  = XSTEP_SIZE;      
    dma(&(shm_slave_mpb[i]->packet),
        &(shm_master_mpb->slave[i].packet),
        sizeof(struct packet_t));

    row[i]++;
  }
  /* receive rows and send next packets */
  for (received_row = 0; received_row < ROWS; ) {
    for (i = 0; i < SLAVES; i++) {
      if (shm_master_mpb->slave[i].row.cmd != CMD_NULL) {
        received_row++;

        static char buf[10];
        itoa(buf, shm_master_mpb->slave[i].row.cmd);
        WRITE(buf, 10);

        /* write out data */
        WRITE(" 68c\n\"", 6);
        WRITE((char *)shm_master_mpb->slave[i].row.data, COLS);
        WRITE("\",\n.\nw\n", 7);

        /* clear response field */
        shm_master_mpb->slave[i].row.cmd = CMD_NULL;

        /* send next packet */
        if (row[i] < (i+1)*(ROWS/SLAVES)) {
          shm_master_mpb->slave[i].packet.cmd    = row[i];
          shm_master_mpb->slave[i].packet.yval   = YSTART + row[i]*YSTEP_SIZE;
          shm_master_mpb->slave[i].packet.xstart = XSTART;
          shm_master_mpb->slave[i].packet.xend   = XEND;
          shm_master_mpb->slave[i].packet.xstep  = XSTEP_SIZE;    
          dma(&(shm_slave_mpb[i]->packet),
              &(shm_master_mpb->slave[i].packet),
              sizeof(struct packet_t));

          row[i]++;
        }
      }
    }
  }

  /* send stop packets */
  for (i = 0; i < SLAVES; i++) {
    shm_master_mpb->slave[i].packet.cmd = CMD_STOP;
    dma(&(shm_slave_mpb[i]->packet),
        &(shm_master_mpb->slave[i].packet),
        sizeof(struct packet_t));
  }
}