public void drawArray(double[] a,double min,double max,long[] col,int size,int ncol)
{
 int MARGIN;
 double mag;
 int wi,he,x,y,column,x0,y0,nrow;
 int R,G,B;
 boolean first;
 long v;
 Color c;
 Graphics  g=canvas.getGraphics();
 Dimension d=canvas.size();
 
 //if (col==null) col=def_color;
 first=false; 

 if (old_he==null) 
 { old_he=new int[size]; 
   first=true;
 }

 MARGIN = d.width / 50;
 if ((d.height / 50) <MARGIN) MARGIN=d.height/50;

 double yy=1.0*size/ncol;
 nrow=(int)(yy+0.9999);
 wi=(d.width/2-MARGIN-ncol)/ncol;
 
 if (wi>((d.height/2-MARGIN-nrow)/nrow)) wi=(d.height/2-MARGIN-nrow)/nrow;
 //wi-=1;
 wi=wi*2+1;
 
 column=0;
 x0=(d.width-(wi+1)*ncol)/2;
 y0=(d.height-(wi+1)*nrow)/2;
 //x0=MARGIN; y0=MARGIN;
 x=x0; y=y0; 

 Lastncol=ncol;
 Lastnrow=nrow;
 Lastx0  =x0; 
 Lasty0  =y0; 
 Lastwi  =wi;
 Lastsize=size;
 Lastdrawn=true;

 for (int i=0;i<size;i++)
  {
   mag=((a[i])/(max-min))*wi;   
   he=(int)mag;
   
   //if (i>=def_col_count) v=col[i%def_col_count];
   //else
   if (col==null) c=Color.white;
   else {
       v=col[i];
       R=(int)(v>>16); v=v%(1<<16);
       G=(int)(v>>8) ; v=v%(1<<8);
       B=(int)v;
       //System.out.println(R+" "+G+" "+B);
       c=new Color(R,G,B);
   }
   //drawBar(g,x,y,wi,he,c);
   if (old_he[i]!=he || first) 
     drawSArea(g,x,y,wi,he,c);
   //else old_he[i]=he;
   //if (first) old_he[i]=he;
   old_he[i]=he;
   x+=wi+1; column++;
   if (column>=ncol) {column=0; y+=wi+1; x=x0;}
  } 
}