Index: /trunk/SophyaLib/HiStats/hisprof.cc
===================================================================
--- /trunk/SophyaLib/HiStats/hisprof.cc	(revision 3056)
+++ /trunk/SophyaLib/HiStats/hisprof.cc	(revision 3057)
@@ -19,5 +19,5 @@
 HProf::HProf()
 : Histo(), mSumY(NULL), mSumY2(NULL), mSumW(NULL)
-, Ok(false), YMin(1.), YMax(-1.), Opt(0)
+, mOk(false), mYMin(1.), mYMax(-1.), mOpt(0)
 {
 }
@@ -56,5 +56,5 @@
 , mSumY2((H.mBins>0) ? new r_8[H.mBins] : NULL)
 , mSumW((H.mBins>0)  ? new r_8[H.mBins] : NULL)
-, Ok(H.Ok), YMin(H.YMin), YMax(H.YMax), Opt(H.Opt)
+, mOk(H.mOk), mYMin(H.mYMin), mYMax(H.mYMax), mOpt(H.mOpt)
 {
   if(mBins>0) {
@@ -73,17 +73,25 @@
 {
   //cout<<"HProf::CreateOrResize()"<<endl;
+  bool samelen = (nBin==mBins)? true: false;
   Histo::CreateOrResize(xMin,xMax,nBin);
   Histo::Errors();
-  if(mSumY !=NULL) {delete[] mSumY;  mSumY = NULL;}
-  if(mSumY2!=NULL) {delete[] mSumY2; mSumY2= NULL;}
-  if(mSumW !=NULL) {delete[] mSumW;  mSumW = NULL;}
-  if(nBin>0) {
-    mSumY  = new r_8[nBin]; memset(mSumY, 0, nBin*sizeof(r_8));
-    mSumY2 = new r_8[nBin]; memset(mSumY2,0, nBin*sizeof(r_8));
-    mSumW  = new r_8[nBin]; memset(mSumW, 0, nBin*sizeof(r_8));
-  }
-  YMin = yMin; YMax = yMax;
-  Ok = false;
-  Opt = 0;
+  if(mSumW!=NULL && !samelen) { //si un est alloue alors les autres aussi
+    delete[] mSumY;  mSumY = NULL;
+    delete[] mSumY2; mSumY2= NULL;
+    delete[] mSumW;  mSumW = NULL;
+  }
+  if(nBin>0 && mSumW==NULL) {
+    mSumY  = new r_8[nBin];
+    mSumY2 = new r_8[nBin];
+    mSumW  = new r_8[nBin];
+  }
+  if(mSumW) {
+    memset(mSumY, 0, nBin*sizeof(r_8));
+    memset(mSumY2,0, nBin*sizeof(r_8));
+    memset(mSumW, 0, nBin*sizeof(r_8));
+  }
+  mYMin = yMin; mYMax = yMax;
+  mOk = false;
+  mOpt = 0;
 }
 
@@ -99,5 +107,5 @@
   if(mSumY2!= NULL) {delete[] mSumY2; mSumY2 = NULL;}
   if(mSumW != NULL) {delete[] mSumW;  mSumW = NULL;}
-  Ok = false;
+  mOk = false;
 }
 
@@ -117,5 +125,5 @@
 void HProf::UpdateHisto(bool force) const
 {
-if(!Ok || force) updatehisto();
+if(!mOk || force) updatehisto();
 }
 
@@ -130,5 +138,5 @@
   memset(mSumY2, 0, mBins*sizeof(r_8));
   memset(mSumW,  0, mBins*sizeof(r_8));
-  Ok = false;
+  mOk = false;
 }
 
@@ -153,5 +161,5 @@
 {
 uint_2 opt = (spread) ? 0 : 1;
-if(opt!=Opt) {Opt=opt; Ok=false;}
+if(opt!=mOpt) {mOpt=opt; mOk=false;}
 }
 
@@ -177,14 +185,14 @@
     m  = mSumY[i]/mSumW[i];
     e2 = mSumY2[i]/mSumW[i] - m*m;
-    if(Opt) e2 /= mSumW[i];
+    if(mOpt) e2 /= mSumW[i];
   }
   mData[i] = m;
   mErr2[i] = e2;
 }
-Ok = true;
+mOk = true;
 // Attention, a cause de "WriteSelf const" updatehisto doit etre "const".
-// Comme on veut modifier Ok, on est oblige de faire cette entourloupe:
+// Comme on veut modifier mOk, on est oblige de faire cette entourloupe:
 HProf *buff = (HProf *) this;
-buff->Ok = true;
+buff->mOk = true;
 }
 
@@ -195,10 +203,10 @@
 void HProf::Add(r_8 x, r_8 y, r_8 w)
 {
-  if(YMax>YMin && (y<YMin || YMax<y)) return;
+  if(mYMax>mYMin && (y<mYMin || mYMax<y)) return;
   int_4 numBin = FindBin(x);
   if (numBin<0) mUnder += w;
   else if (numBin>=mBins) mOver += w;
   else {
-    Ok = false;
+    mOk = false;
     mSumY[numBin]  += y*w;
     mSumY2[numBin] += y*y*w;
@@ -215,9 +223,9 @@
 void HProf::AddBin(int_4 numBin, r_8 y, r_8 w)
 {
-  if(YMax>YMin && (y<YMin || YMax<y)) return;
+  if(mYMax>mYMin && (y<mYMin || mYMax<y)) return;
   if (numBin<0) mUnder += w;
   else if (numBin>=mBins) mOver += w;
   else {
-    Ok = false;
+    mOk = false;
     mSumY[numBin]  += y*w;
     mSumY2[numBin] += y*y*w;
@@ -234,20 +242,17 @@
 HProf& HProf::operator = (const HProf& h)
 {
-if(this == &h) return *this;
-if( h.mBins > mBins ) Delete();
-Histo *hthis = (Histo *) this;
-*hthis = (Histo) h;
-if(!mSumY)  mSumY  = new r_8[mBins];
-if(!mSumY2) mSumY2 = new r_8[mBins];
-if(!mSumW)  mSumW  = new r_8[mBins];
-memcpy(mSumY,  h.mSumY,  mBins*sizeof(r_8));
-memcpy(mSumY2, h.mSumY2, mBins*sizeof(r_8));
-memcpy(mSumW,  h.mSumW,  mBins*sizeof(r_8));
-Ok = h.Ok;
-YMin = h.YMin;
-YMax = h.YMax;
-Opt = h.Opt;
-
-return *this;
+ if(this == &h) return *this;
+ CreateOrResize(h.mMin,h.mMax,h.mBins,h.mYMin,h.mYMax);
+ if(mData) memcpy(mData,h.mData,mBins*sizeof(r_8));
+ if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
+ mUnder = h.mUnder; mOver = h.mOver;
+ nHist = h.nHist; nEntries = h.nEntries;
+ if(mSumY)  memcpy(mSumY,  h.mSumY,  mBins*sizeof(r_8));
+ if(mSumY2) memcpy(mSumY2, h.mSumY2, mBins*sizeof(r_8));
+ if(mSumW)  memcpy(mSumW,  h.mSumW,  mBins*sizeof(r_8));
+ mOk = h.mOk;
+ mOpt = h.mOpt;
+
+ return *this;
 }
 
@@ -331,5 +336,5 @@
   UpdateHisto();
   Histo::Show(os);
-  os <<"       ymin="<<YMin<<" ymax="<<YMax<<"  opt="<<Opt<< endl;
+  os <<"       ymin="<<mYMin<<" ymax="<<mYMax<<"  opt="<<mOpt<< endl;
 }
 
@@ -354,14 +359,16 @@
 // Lecture des valeurs
 is.Get(dobj->mBins);
-is.Get(dobj->YMin);
-is.Get(dobj->YMax);
-is.Get(dobj->Opt);
-dobj->Ok = true;
+is.Get(dobj->mYMin);
+is.Get(dobj->mYMax);
+is.Get(dobj->mOpt);
+dobj->mOk = true;
 
 // Lecture des donnees propres a l'histogramme de profil.
 is.GetLine(strg,255);
-dobj->mSumY  = new r_8[dobj->mBins];
-dobj->mSumY2 = new r_8[dobj->mBins];
-dobj->mSumW  = new r_8[dobj->mBins];
+if(dobj->mBins>0) {
+  dobj->mSumY  = new r_8[dobj->mBins];
+  dobj->mSumY2 = new r_8[dobj->mBins];
+  dobj->mSumW  = new r_8[dobj->mBins];
+}
 is.Get(dobj->mSumY,  dobj->mBins);
 is.Get(dobj->mSumY2, dobj->mBins);
@@ -383,12 +390,12 @@
 
 // Ecriture entete pour identifier facilement
-sprintf(strg,"HProf: YMin=%f  YMax=%f  Opt=%1d",dobj->YMin,dobj->YMax,dobj->Opt);
+sprintf(strg,"HProf: YMin=%f  YMax=%f  Opt=%1d",dobj->mYMin,dobj->mYMax,dobj->mOpt);
 os.PutLine(strg);
 
 // Ecriture des valeurs
 os.Put(dobj->mBins);
-os.Put(dobj->YMin);
-os.Put(dobj->YMax);
-os.Put(dobj->Opt);
+os.Put(dobj->mYMin);
+os.Put(dobj->mYMax);
+os.Put(dobj->mOpt);
 
 // Ecriture des donnees propres a l'histogramme de profil.
Index: /trunk/SophyaLib/HiStats/hisprof.h
===================================================================
--- /trunk/SophyaLib/HiStats/hisprof.h	(revision 3056)
+++ /trunk/SophyaLib/HiStats/hisprof.h	(revision 3057)
@@ -81,8 +81,8 @@
   r_8*         mSumY2; //!< somme des carres
   r_8*         mSumW;  //!< somme des poids
-  mutable bool Ok;    //!< true if update fait
-  r_8          YMin;  //!< limite minimum Y pour somme
-  r_8          YMax;  //!< limite maximum Y pour somme
-  uint_2       Opt;   //!< options pour les erreurs
+  mutable bool mOk;    //!< true if update fait
+  r_8          mYMin;  //!< limite minimum Y pour somme
+  r_8          mYMax;  //!< limite maximum Y pour somme
+  uint_2       mOpt;   //!< options pour les erreurs
 };
 
Index: /trunk/SophyaLib/HiStats/histerr.cc
===================================================================
--- /trunk/SophyaLib/HiStats/histerr.cc	(revision 3056)
+++ /trunk/SophyaLib/HiStats/histerr.cc	(revision 3057)
@@ -49,18 +49,11 @@
 {
   //cout<<"HistoErr::CreateOrResize()"<<endl;
+  bool samelen = (nBin==mBins)? true: false;
   Histo::CreateOrResize(xMin,xMax,nBin);
   Histo::Errors();
-  allocate_mNData(nBin);
+  if(mNData!=NULL && !samelen) {delete [] mNData; mNData=NULL;}
+  if(nBin>0 && mNData==NULL) mNData = new r_8[nBin];
+  if(mNData) memset(mNData,0,nBin*sizeof(r_8));
   mCorrel = 0;
-}
-
-/********* Methode *********/
-/*! Allocation du tableau mNData */
-void HistoErr::allocate_mNData(int nbin)
-{
-  if(mNData) {delete [] mNData; mNData=NULL;}
-  if(nbin<=0) return;
-  mNData = new r_8[nbin];
-  memset(mNData,0,nbin*sizeof(r_8));
 }
 
@@ -199,12 +192,10 @@
 {
   if(this==&h) return *this;
-  Delete();
-  if(h.mBins<=0) return *this;
-
-  // Copy the "Histo" part
-  (Histo)(*this) = Histo::operator=(h);
-  // Copy the "entries by bin" table
-  allocate_mNData(h.mBins);
-  memcpy(mNData,h.mNData,mBins*sizeof(r_8));
+  CreateOrResize(h.mMin,h.mMax,h.mBins);
+  if(mData) memcpy(mData,h.mData,mBins*sizeof(r_8));
+  if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
+  mUnder = h.mUnder; mOver = h.mOver;
+  nHist = h.nHist; nEntries = h.nEntries;
+  if(mNData) memcpy(mNData,h.mNData,mBins*sizeof(r_8));
   mCorrel = h.mCorrel;
 
@@ -244,5 +235,5 @@
 // Lecture des donnees HistoErr
 is.Get(dobj->mBins);
-  dobj->allocate_mNData(dobj->mBins);
+if(dobj->mBins>0) dobj->mNData = new r_8[dobj->mBins];
 is.Get(dobj->mNData, dobj->mBins);
 
Index: /trunk/SophyaLib/HiStats/histerr.h
===================================================================
--- /trunk/SophyaLib/HiStats/histerr.h	(revision 3056)
+++ /trunk/SophyaLib/HiStats/histerr.h	(revision 3057)
@@ -83,5 +83,4 @@
 
 protected:
-  void allocate_mNData(int nbin);
   void CreateOrResize(r_8 xMin, r_8 xMax, int_4 nBin);
   void Delete(void);
Index: /trunk/SophyaLib/HiStats/histos.cc
===================================================================
--- /trunk/SophyaLib/HiStats/histos.cc	(revision 3056)
+++ /trunk/SophyaLib/HiStats/histos.cc	(revision 3057)
@@ -1,4 +1,4 @@
 //
-// $Id: histos.cc,v 1.23 2006-08-12 17:29:29 cmv Exp $
+// $Id: histos.cc,v 1.24 2006-08-12 22:41:08 cmv Exp $
 //
 
@@ -70,7 +70,9 @@
 {
   //cout<<"Histo::CreateOrResize()"<<endl;
-  if(mData != NULL) {delete[] mData; mData = NULL;}
-  if(mErr2 != NULL) {delete[] mErr2; mErr2 = NULL;}
-  if(nBin>0) {mData = new r_8[nBin]; memset(mData,0,nBin*sizeof(r_8));}
+  bool samelen = (nBin==mBins)? true: false;
+  if(mData!=NULL && !samelen) {delete[] mData; mData = NULL;}
+  if(mErr2!=NULL) {delete[] mErr2; mErr2 = NULL;} // On des-alloue toujours
+  if(nBin>0 && mData==NULL) mData = new r_8[nBin];
+  if(mData) memset(mData,0,nBin*sizeof(r_8));
   mBins = nBin;
   mMin = xMin; mMax = xMax;
@@ -142,19 +144,10 @@
 {
   if(this == &h) return *this;
-  Delete();
-  if(h.mBins<=0 || h.mData==NULL) return *this;
-
-  mData = new r_8[h.mBins];
-  if(h.mErr2) mErr2 = new r_8[h.mBins];
+  CreateOrResize(h.mMin,h.mMax,h.mBins);
+  if(h.mErr2) Errors();
+  if(mData) memcpy(mData,h.mData,mBins*sizeof(r_8));
+  if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
   mUnder = h.mUnder; mOver = h.mOver;
-  nHist = h.nHist;
-  nEntries = h.nEntries;
-  mBins = h.mBins;
-  mMin = h.mMin; mMax = h.mMax;
-  binWidth = h.binWidth;
-  
-  memcpy(mData,h.mData,mBins*sizeof(r_8));
-  if(mErr2) memcpy(mErr2,h.mErr2,mBins*sizeof(r_8));
-
+  nHist = h.nHist; nEntries = h.nEntries;
   return *this;
 }
@@ -532,4 +525,5 @@
 int_4 Histo::IMax() const
 {
+  if(mBins<=0)  return 0;
   int_4 imx=0;
   if(mBins==1) return imx;
@@ -546,4 +540,5 @@
 int_4 Histo::IMin() const
 {
+  if(mBins<=0)  return 0;
   int_4 imx=0;
   if(mBins==1) return imx;
@@ -560,4 +555,5 @@
 r_8 Histo::VMax() const
 {
+  if(mBins<=0)  return 0.;
   r_8 mx=mData[0];
   if(mBins==1) return mx;
@@ -572,4 +568,5 @@
 r_8 Histo::VMin() const
 {
+  if(mBins<=0)  return 0.;
   r_8 mx=mData[0];
   if(mBins==1) return mx;
@@ -584,4 +581,5 @@
 r_8 Histo::Mean() const
 {
+  if(mBins<=0)  return 0.;
   r_8 n = 0;
   r_8 sx = 0;
@@ -600,4 +598,5 @@
 r_8 Histo::Sigma() const
 {
+  if(mBins<=0)  return 0.;
   r_8 n = 0;
   r_8 sx = 0;
@@ -622,4 +621,5 @@
 r_8 Histo::MeanLH(int_4 il,int_4 ih) const
 {
+  if(mBins<=0)  return 0.;
   if( ih < il ) { il = 0; ih = mBins-1; }
   if( il < 0 ) il = 0;
@@ -641,4 +641,5 @@
 r_8 Histo::SigmaLH(int_4 il,int_4 ih) const
 {
+  if(mBins<=0)  return 0.;
   if( ih < il ) { il = 0; ih = mBins - 1; }
   if( il < 0 ) il = 0;
@@ -665,4 +666,5 @@
 r_8 Histo::Mean(r_8 x0, r_8 dx) const
 {
+  if(mBins<=0)  return 0.;
   r_8 sdata = 0;
   r_8 sx = 0;
@@ -685,4 +687,5 @@
 r_8 Histo::Sigma(r_8 x0, r_8 dx) const
 {
+  if(mBins<=0)  return 0.;
   r_8 sx = 0;
   r_8 sx2= 0;
@@ -708,4 +711,5 @@
 r_8 Histo::CleanedMean(r_8& sigma) const
 {
+  if(mBins<=0)  return 0.;
   if (!nHist) return 0;
   // on fait ca de facon bete, on pourra raffiner apres...
@@ -728,4 +732,5 @@
 r_8 Histo::CleanedMean() const
 {
+  if(mBins<=0)  return 0.;
   if (!nHist) return 0;
   r_8 s=0;
@@ -739,4 +744,5 @@
 int_4 Histo::BinNonNul() const
 {
+if(mBins<=0)  return -1;
 int_4 non=0;
 for (int_4 i=0;i<mBins;i++) if( mData[i] != 0. ) non++;
@@ -763,4 +769,5 @@
 int_4 Histo::BinPercent(r_8 per) const
 {
+if(mBins<=0)  return -1;
 r_8 n = nHist*per;
 r_8 s = 0.;
@@ -789,4 +796,5 @@
 int_4 Histo::BinPercent(r_8 x,r_8 per,int_4& imin,int_4& imax) const
 {
+if(mBins<=0)  return -3;
 imin = imax = -1;
 if( per <= 0. ) return -1;
@@ -926,4 +934,5 @@
 int_4 Histo::MaxiLocal(r_8& maxi,int_4& imax,r_8& maxn,int_4& imaxn) const
 {
+if(mBins<=0)  return -1;
 int_4 nml = 0;
 imax = imaxn = -1;
@@ -964,4 +973,5 @@
 r_8 Histo::FitMax(int_4 degree, r_8 frac, int_4 debug) const
 {
+  if(mBins<=0)  return mMin;
   if (degree < 2 || degree > 3) degree = 3;
   if (frac <= 0. || frac >= 1.) frac = 0.5;
@@ -1099,4 +1109,5 @@
 r_8 Histo::FindWidth(r_8 frac, int_4 debug) const
 {
+  if(mBins<=0)  return 0;
   r_8 xmax = BinCenter( IMax() );
   return FindWidth(xmax,frac,debug);
@@ -1110,4 +1121,5 @@
 r_8 Histo::FindWidth(r_8 xmax,r_8 frac, int_4 debug) const
 {
+  if(mBins<=0)  return 0;
   if (frac <= 0 || frac >= 1.) frac = 0.5;
 
@@ -1205,4 +1217,5 @@
 int_4 Histo::EstimeMax(int_4& im,r_8& xm,int_4 SzPav) const
 {
+if(mBins<=0)  return -1;
 xm = 0;
 if( SzPav <= 0 ) return -1;
@@ -1237,4 +1250,5 @@
 void Histo::EstimeWidthS(r_8 frac,r_8& widthG,r_8& widthD) const
 {
+if(mBins<=0) {frac=0.; return;}
 int_4 i;
 widthG = widthD = -1.;
@@ -1308,4 +1322,5 @@
 {
  
+ if(mBins<=0) return;
  if( il > ih ) { il = 0; ih = mBins-1; }
  if( il < 0 ) il = 0;
@@ -1490,6 +1505,6 @@
 
 // Lecture des donnees Histo 1D
-dobj->mData = new r_8[dobj->mBins];
 is.GetLine(strg, 255);
+if(dobj->mBins>0) dobj->mData = new r_8[dobj->mBins];
 is.Get(dobj->mData, dobj->mBins);
 
@@ -1497,5 +1512,5 @@
 if(errok) {
   is.GetLine(strg, 255);
-  dobj->mErr2 = new r_8[dobj->mBins];
+  if(dobj->mBins>0) dobj->mErr2 = new r_8[dobj->mBins];
   is.Get(dobj->mErr2, dobj->mBins);
 }
Index: /trunk/SophyaLib/HiStats/histos.h
===================================================================
--- /trunk/SophyaLib/HiStats/histos.h	(revision 3056)
+++ /trunk/SophyaLib/HiStats/histos.h	(revision 3057)
@@ -1,5 +1,5 @@
 // This may look like C code, but it is really -*- C++ -*-
 //
-// $Id: histos.h,v 1.23 2006-08-12 17:29:29 cmv Exp $
+// $Id: histos.h,v 1.24 2006-08-12 22:41:08 cmv Exp $
 //
 
Index: /trunk/SophyaLib/HiStats/histos2.cc
===================================================================
--- /trunk/SophyaLib/HiStats/histos2.cc	(revision 3056)
+++ /trunk/SophyaLib/HiStats/histos2.cc	(revision 3057)
@@ -153,14 +153,17 @@
 void Histo2D::CreateOrResize(r_8 xMin,r_8 xMax,int_4 nxBin,r_8 yMin,r_8 yMax,int_4 nyBin)
 {
- int_8 n = nxBin*nyBin;
- if(mData!=NULL) {delete[] mData; mData = NULL;}
- if(n>0) {mData = new r_8[n]; memset(mData, 0, n*sizeof(r_8));}
- mNx = nxBin; mNy = nyBin; mNxy = nxBin*nyBin;
- mXmin = xMin; mXmax = xMax; mYmin = yMin; mYmax = yMax;
- mWBinx = (nxBin>0) ? (xMax - xMin)/nxBin: 0.;
- mWBiny = (nyBin>0) ? (yMax - yMin)/nyBin: 0.;
- nHist = 0; nEntries = 0;
- for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
- mB_s.H = NULL;
+  int_8 n = nxBin*nyBin;
+  bool samelen = (n==mNx*mNy)? true: false;
+  if(mData!=NULL && !samelen) {delete[] mData; mData=NULL;}
+  if(mErr2!=NULL) {delete[] mErr2; mErr2=NULL;} // On des-alloue toujours
+  if(n>0 && mData==NULL) mData = new r_8[n];
+  if(mData) memset(mData, 0, n*sizeof(r_8));
+  mNx = nxBin; mNy = nyBin; mNxy = nxBin*nyBin;
+  mXmin = xMin; mXmax = xMax; mYmin = yMin; mYmax = yMax;
+  mWBinx = (nxBin>0) ? (xMax - xMin)/nxBin: 0.;
+  mWBiny = (nyBin>0) ? (yMax - yMin)/nyBin: 0.;
+  nHist = 0; nEntries = 0;
+  for(int_4 i=0;i<3;i++) for(int_4 j=0;j<3;j++) mOver[i][j]=0.;
+  mB_s.H = NULL;
 }
 
@@ -230,22 +233,12 @@
 Histo2D& Histo2D::operator = (const Histo2D& h)
 {
-  int_4 i,j,nb;
-  r_8 min,max;
-
   if(this == &h) return *this;
-  if( h.mNxy > mNxy ) Delete();
-  if(!mData) mData = new r_8[h.mNxy];
-  if( !h.mErr2 && mErr2 ) { delete [] mErr2; mErr2=NULL;}
-  if( h.mErr2 && !mErr2 ) mErr2 = new r_8[h.mNxy];
-
-  for(i=0;i<3;i++) for(j=0;j<3;j++) mOver[i][j] = h.mOver[i][j];
-  nHist = h.nHist;
-  nEntries = h.nEntries;
-  mNx = h.mNx;  mNy = h.mNy;  mNxy = h.mNxy;
-  mXmin = h.mXmin; mXmax = h.mXmax; mWBinx = h.mWBinx;
-  mYmin = h.mYmin; mYmax = h.mYmax; mWBiny = h.mWBiny;
-  
-  memcpy(mData, h.mData, mNxy*sizeof(r_8));
+  CreateOrResize(h.mXmin,h.mXmax,h.mNx,h.mYmin,h.mYmax,h.mNy);
+  if(h.mErr2) Errors();
+  if(mData) memcpy(mData, h.mData, mNxy*sizeof(r_8));
   if(mErr2) memcpy(mErr2, h.mErr2, mNxy*sizeof(r_8));
+
+  for(int i=0;i<3;i++) for(int j=0;j<3;j++) mOver[i][j] = h.mOver[i][j];
+  nHist = h.nHist;  nEntries = h.nEntries;  
 
   DelProjX();
@@ -260,9 +253,10 @@
   }
 
+  int_4 nb;
   DelSliX();
   nb = h.NSliX();
   if(nb>0) {
     SetSliX(nb);
-    for(i=0; i<NSliX();i++) *HSliX(i) = *(h.HSliX(i));
+    for(int i=0; i<NSliX();i++) *HSliX(i) = *(h.HSliX(i));
   }
   DelSliY();
@@ -270,5 +264,5 @@
   if(nb>0) {
     SetSliY(nb);
-    for(i=0; i<NSliY();i++) *HSliY(i) = *(h.HSliY(i));
+    for(int i=0; i<NSliY();i++) *HSliY(i) = *(h.HSliY(i));
   }
 
@@ -276,20 +270,22 @@
   nb = h.NBandX();
   if(nb>0) {
-    for(i=0; i<nb;i++) {
+    for(int i=0; i<nb;i++) {
+      r_8 min,max;
       h.GetBandX(i,min,max);
       SetBandX(min,max);
       *HBandX(i) = *(h.HBandX(i));
     }
-    for(i=0; i<NBandX();i++) *HBandX(i) = *(h.HBandX(i));
+    for(int i=0; i<NBandX();i++) *HBandX(i) = *(h.HBandX(i));
   }
   DelBandY();
   nb = h.NBandY();
   if(nb>0) {
-    for(i=0; i<nb;i++) {
+    for(int i=0; i<nb;i++) {
+      r_8 min,max;
       h.GetBandY(i,min,max);
       SetBandY(min,max);
       *HBandY(i) = *(h.HBandY(i));
     }
-    for(i=0; i<NBandY();i++) *HBandY(i) = *(h.HBandY(i));
+    for(int i=0; i<NBandY();i++) *HBandY(i) = *(h.HBandY(i));
   }
 
@@ -695,4 +691,5 @@
 void Histo2D::IJMax(int_4& imax,int_4& jmax,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) {imax = jmax = -1; return;}
 if( il > ih ) { il = 0; ih = mNx-1; }
 if( jl > jh ) { jl = 0; jh = mNy-1; }
@@ -716,4 +713,5 @@
 void Histo2D::IJMin(int_4& imax,int_4& jmax,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) {imax = jmax = -1; return;}
 if( il > ih ) { il = 0; ih = mNx-1; }
 if( jl > jh ) { jl = 0; jh = mNy-1; }
@@ -738,4 +736,5 @@
 r_8 Histo2D::VMax(int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) return 0.;
 if( il > ih ) { il = 0; ih = mNx-1; }
 if( jl > jh ) { jl = 0; jh = mNy-1; }
@@ -758,4 +757,5 @@
 r_8 Histo2D::VMin(int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) return 0.;
 if( il > ih ) { il = 0; ih = mNx-1; }
 if( jl > jh ) { jl = 0; jh = mNy-1; }
@@ -801,4 +801,5 @@
 int_4 Histo2D::BinNonNul() const
 {
+if(mNxy<=0) return -1;
 int_4 non=0;
 for (int_4 i=0;i<mNxy;i++) if( mData[i] != 0. ) non++;
@@ -899,4 +900,5 @@
                     ,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) return -1;
 if( il > ih ) { il = 0; ih = mNx-1; }
 if( jl > jh ) { jl = 0; jh = mNy-1; }
@@ -969,4 +971,5 @@
                    ,int_4 il,int_4 ih,int_4 jl,int_4 jh) const
 {
+if(mNxy<=0) return;
 int_4 ns = 35;
 const char *s =    "+23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
