Changeset 2798


Ignore:
Timestamp:
01/12/10 11:57:04 (15 years ago)
Author:
Mathieu Morlighem
Message:

removed useless code and fix crash (do not free bamgmesh in bamg)

Location:
issm/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/Bamgx/Mesh2.h

    r2797 r2798  
    6161
    6262class MeshIstream;
    63 class OFortranUnFormattedFile;
    64 class IFortranUnFormattedFile;
    6563
    6664extern int hinterpole;
  • issm/trunk/src/c/Bamgx/Meshio.cpp

    r2740 r2798  
    3333        long int verbosity=2;
    3434
    35 const char *OFortranUnFormattedFile::unkown("unkown file name");
    3635void (*MeshIstreamErrorHandler)(ios & ) =0;
    3736///////////////////////////////////////////////////////////
     
    4847 out << '"' ;
    4948}
    50 ///////////////////////////////////////////////////////////
    51 double * ReadbbFile(const char * file,long & nbsol,long & lsol,const int typesol,const int dim)
    52 {
    53 
    54   MeshIstream frbb(file);
    55   int dimlu,typesollu;
    56   long i;
    57  double *sol =0;
    58   frbb >>    dimlu >> nbsol >> lsol >> typesollu ;
    59   if(typesol != typesollu )
    60     {
    61       cerr << " incorrect type of solution (read) " << typesollu << " != (wanted) " <<  typesol << endl;
    62       cerr << "  or       dim  of solution (read) " << dimlu  << " != (wanted) " <<  dim << endl;
    63       nbsol=0;
    64       lsol=0;
    65     }
    66   else
    67     {
    68       sol = new double[lsol*nbsol];
    69       double *s=sol;
    70       for(  i=0;i<lsol;i++)
    71         for (long j=0;j<nbsol;j++)
    72           frbb >>  *s++ ;
    73       //      frbb.close();
    74     }
    75 
    76  
    77   return sol;
    78 }
    79 
    80 ///////////////////////////////////////////////////////////
    81 double * ReadBBFile(const char * file,long & nbsol,long & lsol,int *& typesols,
    82   const int dim,const int typesol)
    83 {
    84 
    85   MeshIstream frbb(file);
    86   int dimlu,typesollu;
    87   typesols = 0;
    88   long i,n=0;
    89   double *sol =0;
    90   int sizeoftype[] = { 1, dim ,dim * (dim+1) / 2, dim * dim } ;
    91   // char * charoftype[] = {  "Scalar" , "dim Vector" ,"dim x dim Sym-Matric","dim x dim Full-Matric" } ;
    92   frbb >>    dimlu >> nbsol ;
    93   typesols = new int [nbsol] ;
    94   for (i=0;i<nbsol;i++)
    95     {
    96      frbb >> typesols[i];
    97      typesols[i]--;
    98      if (typesols[i]<0 || typesols[i]>= 4)
    99        {
    100          cerr << " Error reading BBFile the type solution " << i+1 << " is " << typesols[i]+1
    101               << " is not in [1..4] " << endl;
    102            frbb.ShowIoErr(998);
    103          nbsol=0;
    104          lsol=0;
    105          delete [] typesols;
    106          typesols=0;
    107          return 0;
    108        }
    109      n += sizeoftype[ typesols[i]];
    110     }
    111   frbb >> lsol >> typesollu ;
    112   if(typesol != typesollu )
    113     {
    114       cerr << " incorrect type of solution (read) " << typesollu << " != (wanted) " <<  typesol << endl;
    115       cerr << "  or       dim  of solution (read) " << dimlu  << " != (wanted) " <<  dim << endl;
    116       frbb.ShowIoErr(999);
    117       nbsol=0;
    118       lsol=0;
    119     }
    120   else
    121     {
    122       if (verbosity> 5)
    123         cout << "     read BB file " << file << "  with nbsol " << nbsol << " total nb of field = " << n << endl;
    124       if (verbosity>9)
    125         for (i=0;i<nbsol;i++)
    126           cout << "      the type of solution " << i+1 << " is " <<  sizeoftype[ typesols[i]] 
    127                << " and  the number of sub-field are " << sizeoftype[ typesols[i]] << endl;
    128       sol = new double[lsol*n];
    129       double *s=sol;
    130       for(  i=0;i<lsol;i++)
    131         for (long j=0;j<n;j++)
    132           frbb >>  *s++ ;
    133       //      frbb.close();
    134     }
    135 
    136  
    137   return sol;
    138 }
    139 
    14049
    14150void MeshIstream::ShowIoErr(int s) {
     
    229138  return r ; 
    230139}
    231 ///////////////////////////////////////////////////////////
    232 OFortranUnFormattedFile::~OFortranUnFormattedFile()
    233 {
    234   // save the last record
    235   if (l==0) { // l rec no set --
    236     l=where();
    237   if (verbosity>9)
    238     cout << " size of last record  = "
    239          << l << " n = " << nb_rec << " i= " << i << endl;
    240    if (!f->good()) Error(3);
    241     f->seekp(i-sizeof(long));
    242    if (!f->good()) Error(3);
    243     f->write((char*)&l,sizeof(l));
    244     if (!f->good()) Error(3);
    245    n=j;
    246   }
    247 
    248   f->seekp(n);
    249   if (!f->good()) Error(3);
    250    f->write((char*) &l,sizeof(l));
    251   if (!f->good()) Error(3);
    252    
    253   if (f && to_close) {
    254     if (verbosity>9)
    255       cout << "delete OFortranUnFormattedFile " << file_name
    256            << " @end  = " << n <<  endl;
    257     delete f;} f=0;
    258 }
    259 
    260 IFortranUnFormattedFile::~IFortranUnFormattedFile()
    261 {
    262   if (f && to_close) {
    263     if (verbosity>9)
    264       cout << " delete IFortranUnFormattedFile" << file_name
    265            << "  @end = " << n <<  endl;
    266     delete f;} f=0;
    267 }
    268 
    269 long IFortranUnFormattedFile::Record()
    270 {
    271   nb_rec++;
    272   n += sizeof(long);
    273   f->seekg(n);
    274   f->read((char*)&l,sizeof(l));
    275   if (!f->good()) Error(3);
    276   i=j= n+sizeof(l);
    277   n +=   l + sizeof(l) ; // end
    278   if (verbosity>9)
    279   cout << " Read  rec end =" << n << " l=  " << l
    280        << " current= " << j << " begin= " << i << endl;
    281   return l;
    282 }
    283 
    284 long OFortranUnFormattedFile::Record(long ll) //
    285 {
    286   if (j==4 && l==0)
    287     {
    288       l=ll;
    289       f->seekp(0);
    290       f->write((char*)&ll,sizeof(l));
    291       if (!f->good()) Error(3);
    292       return 0;
    293     }
    294   if (n>=0)
    295     {
    296       if (l==0)
    297         { // l rec no set --
    298           l=where();
    299           if (verbosity>9)
    300             cout << " set len  of rec  " << nb_rec  << " = " << l
    301                  << " @ " << i-sizeof(long) << endl;
    302 
    303           f->seekp(i-sizeof(long));
    304           f->write((char*)&l,sizeof(l));
    305           n=j;
    306         }
    307       f->seekp(n);
    308       f->write((char*)&l,sizeof(l));
    309       if (!f->good()) Error(3);
    310     }
    311   else
    312     f->seekp(0);
    313   n += sizeof(long);
    314   nb_rec++;
    315   f->write((char*)&ll,sizeof(l));
    316   if (!f->good()) Error(3);
    317  
    318   l=ll;
    319   n +=  sizeof(long);
    320   j = n;
    321   i = n;
    322   n +=   l;
    323   if (verbosity>9)
    324     cout << " Write rec end =" << n << " l=  " << l
    325          << " current= " << j << " begin= " << i << endl;
    326   return l;
    327 }
    328 void OFortranUnFormattedFile::Error(int err)
    329 {
    330   cerr << "Fatal Error Output FortranUnFormattedFile " << endl;
    331   if (err==0)
    332     cerr << "-- Error openning ";
    333   else if (err==1)
    334     cerr<< "-- OverFlow write ";
    335   else if (err==2)
    336     cerr<< "-- Erreur  write " ;
    337   else if (err==3)
    338     cerr<< "-- Erreur  write record info " ;
    339   else
    340     cerr << " unkown err " << err ;
    341 
    342   cerr << " Record number = "    << nb_rec << endl
    343        << " read position  in file " << j << " < " << n
    344        << " =  end on record " << endl;
    345   cerr << " position in the record = " << where()
    346        << " length of record = " << l <<endl;
    347   cerr  << " file = " << file_name<< endl ;
    348   MeshError(900);
    349   //  throw(ErrorMesh("exit",1));
    350 }
    351 void IFortranUnFormattedFile::Error(int err)
    352 {
    353   cerr << "Fatal Error Input FortranUnFormattedFile " << endl;
    354   if (err==0)
    355     cerr << " Error openning ";
    356   else if (err==1)
    357     cerr<< " OverFlow read";
    358   else if (err==2)
    359     cerr<< " Erreur  read" ;
    360   else if (err==3)
    361     cerr<< " Erreur  read record info " ;
    362   else
    363     cerr << " unkown err " << err ;
    364 
    365   cerr << " Record number = "    << nb_rec << endl
    366        << " read position  in file " << j << " < " << n
    367        << " =  end on record " << endl;
    368   cerr << " position in the record = " << where()
    369        << " length of record = " << l <<endl;
    370   cerr  << " file = " << file_name<< endl ;
    371     MeshError(900);
    372     //  throw(ErrorMesh("exit",1));
    373 }
    374 
    375140}// end of namespace bamg
  • issm/trunk/src/c/Bamgx/Meshio.h

    r2740 r2798  
    4848
    4949void WriteStr(ostream & out,char * str);
    50 
    51 double * ReadbbFile(const char * file,long & nbsol,long & lsol,const int dim=2,const int typesol=2);
    52 double * ReadBBFile(const char * file,long & nbsol,long & lsol,int *& typesols,const int dim=2,const int typesol=2);
    53 // solution at vertex (P1)
    5450
    5551union Char4orLong {  char c[4];    long l;} ;
     
    114110
    115111};
    116 // Fortran unformatted file  interface ----------
    117 
    118 class IFortranUnFormattedFile {
    119 //  template<class T> friend IFortranUnFormattedFile & operator>>(IFortranUnFormattedFile &f,T & l);
    120   istream * f;
    121   long i,l,n,j,nb_rec;
    122   const char * file_name;
    123   int to_close;
    124  public:
    125   IFortranUnFormattedFile(char *name)
    126     : f(new ifstream(name)),i(0),l(0),n((long)-sizeof(long)),
    127       nb_rec(0),file_name(name), to_close(1)
    128     { if(!*f) Error(0);}
    129 
    130   IFortranUnFormattedFile(MeshIstream & ff)
    131     : f(&ff.in),i(0),l(0),n((long)-sizeof(long)),nb_rec(0),
    132       file_name(ff.CurrentFile), to_close(0)
    133     { if(! *f)  Error(0);}
    134  
    135  ~IFortranUnFormattedFile();
    136   long Record();
    137   long where(){return j-i;}
    138   void  read4(char *c,int );// for the fortran 77 char4
    139   void  read(char * p,const size_t lg);
    140   void Error(int);
    141 };
    142 
    143 class OFortranUnFormattedFile {
    144 //  template<class T> friend OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const T & l);
    145   ostream * f;
    146   long i,l,n,j,nb_rec;
    147   const static char * unkown;
    148   const char * file_name;
    149   int to_close;
    150  public:
    151  
    152   OFortranUnFormattedFile(const char *name,IOS_OPENMODE  mm=ios::trunc)
    153     : f(new ofstream(name,mm)),i(0),l(0),n((long) -sizeof(long)),nb_rec(0),file_name(name), to_close(1)
    154     { if(!*f) Error(0);}
    155   OFortranUnFormattedFile(ostream &ff)
    156     : f(&ff),i(0),l(0),n((long) -sizeof(long)),nb_rec(0),file_name(unkown), to_close(0)
    157     { if(!*f) Error(0);}
    158  
    159   ~OFortranUnFormattedFile();
    160 
    161   long Record(long ll=0);
    162   long where(){return j-i;}
    163   void write4(const char *c,int );// for the fortran 77 char4
    164   void write(const char * p,const size_t lg);
    165   void Error(int );
    166 };
    167112
    168113/// ---------- inline -------------------------
    169114
    170 inline void  IFortranUnFormattedFile::read(char * p,const size_t lg){ 
    171   f->read(p,lg);
    172   j+=lg;
    173   if (j>n) Error(1);
    174   else if (!f->good()) Error(2) ;
    175115}
    176 
    177 inline void  OFortranUnFormattedFile::write(const char * p,const size_t lg){ 
    178    f->write(p,lg);
    179    j+=lg;
    180    if (l && j>n)  Error(1);
    181    else if (!f->good()) Error(2);
    182 }
    183 
    184 template<class T> inline
    185 IFortranUnFormattedFile & operator>>(IFortranUnFormattedFile &f,T & l)
    186 
    187   f.read((char *) &l,sizeof(l));return f;
    188 }
    189 /*  bug sur sun 
    190 template inline
    191  OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const T & l)
    192  {
    193    f.write((char *) &l,sizeof(l));return f;
    194  }
    195 on ex les template  */
    196 
    197 inline
    198  OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const int  & l)
    199  {
    200    f.write((char *) &l,sizeof(l));return f;
    201  }
    202 inline
    203  OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const long  & l)
    204  {
    205    f.write((char *) &l,sizeof(l));return f;
    206  }
    207 inline
    208  OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const double  & l)
    209  {
    210    f.write((char *) &l,sizeof(l));return f;
    211  }
    212 inline
    213  OFortranUnFormattedFile & operator<<(OFortranUnFormattedFile &f,const float & l)
    214  {
    215    f.write((char *) &l,sizeof(l));return f;
    216  }
    217 
    218 inline void OFortranUnFormattedFile::write4(const char *c,int ll)
    219 {
    220   int i,j;
    221   Char4orLong ch4;
    222   for ( i=0;i<ll;i++)
    223     {
    224       ch4.l=0;
    225       for (j=0;j<4;j++)
    226         ch4.c[j]=*c? *c++:' ';
    227       *this << ch4.l;
    228     }
    229 }
    230 inline void IFortranUnFormattedFile::read4(char *c,int ll)
    231 {
    232   int i,j;
    233   Char4orLong ch4;
    234 
    235   for ( i=0;i<ll;i++)
    236     {
    237       *this >> ch4.l;
    238       for (j=0;j<4;j++)
    239         *c++= ch4.c[j];
    240     }
    241   *c=0;// end of string
    242 }
    243 
    244 }
  • issm/trunk/src/c/objects/BamgGeom.h

    r2794 r2798  
    3030        double* RequiredEdges;
    3131
     32        int     NumCrackedEdges;
     33        double* CrackedEdges;
     34
    3235        int     NumSubDomains;
    3336        double* SubDomains;
  • issm/trunk/src/mex/Bamg/Bamg.cpp

    r2794 r2798  
    6363        bamggeom.NumRequiredEdges=0;
    6464        bamggeom.RequiredEdges=NULL;
     65        bamggeom.NumCrackedEdges=0;
     66        bamggeom.CrackedEdges=NULL;
    6567        FetchData(&NumSubDomainsGeom,mxGetField(BAMGGEOMETRY,0,"NumSubDomains"));
    6668        bamggeom.NumSubDomains=NumSubDomainsGeom;
     
    125127
    126128        /*Free ressources: */
    127         xfree((void**)&VerticesGeom);
    128         xfree((void**)&EdgesGeom);
    129         xfree((void**)&hVerticesGeom);
    130         xfree((void**)&SubDomainsGeom);
    131         //xfree((void**)&TrianglesMesh);
    132         //xfree((void**)&VerticesMesh);
     129        //do not free any fields of bamgmesh or bamggeom as it has been freed in bamgx
    133130
    134131        /*end module: */
Note: See TracChangeset for help on using the changeset viewer.