Changeset 51daf97 in tol


Ignore:
Timestamp:
May 10, 2010, 9:53:24 AM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
b86788c
Parents:
dd538db
Message:

Fixes #546

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2139 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    rdd538db r51daf97  
    210210  BInt rows, cols, rows2w, cols2w;
    211211  FILE *fil;
    212 
    213   /* check number of columns */
    214   if(!(fil = fopen(fileName.String(), "rb"))) {
    215     BBM_BinWrite(fileName,M);
    216     return;
    217   }
    218  
     212  BDir dir = fileName;
     213  if(!dir.Exist())
     214  {
     215    BBM_BinWrite(fileName, M);
     216    return;
     217  }
     218  else if(dir.IsDir())
     219  {
     220    Error(I2("Cannot open BBM file ",
     221       "No se pudo abrir el fichero BBM ") +
     222    fileName+I2(" due to it's a directory"," porque es un directorio"));
     223    return;
     224  }
     225 
     226  /* open for overwrite */
     227  if(!(fil = fopen(fileName.String(), "r+b"))) {
     228    Error(I2("Cannot open (rewrite mode) BBM file ",
     229       "No se pudo abrir (modo de sobreescritura) el fichero BBM ") +
     230    fileName);
     231    return;
     232  }
     233  fpos_t pos = 0;
     234  fsetpos(fil, &pos);
    219235  fread(&rows,sizeof(BInt),1,fil);
    220236  fread(&cols,sizeof(BInt),1,fil);
    … …  
    226242    return;
    227243  }
    228   fclose(fil);
    229 
    230   /* open for overwrite */
    231   if(!(fil = fopen(fileName.String(), "r+b"))) {
    232     Error(I2("Cannot open (rewrite mode) BBM file ",
    233        "No se pudo abrir (modo de sobreescritura) el fichero BBM ") +
    234     fileName);
    235     return;
    236   }
    237  
    238   if(fseek(fil, 0L, SEEK_SET)) {
    239     Error(I2("Cannot access BBM file ", "No se pudo acceder al fichero BBM ") +
    240     fileName);
    241     fclose(fil);
    242     return;
    243   }
     244  pos = 0;
     245  fsetpos(fil, &pos);
    244246  rows += rows2w;
    245247  fwrite(&rows, sizeof(BInt), 1, fil);
    246   fclose(fil); 
    247 
     248  fflush(fil);
     249  fclose(fil);
     250  fil = NULL;
     251  for(int tryNum = 0; !fil && (tryNum < 1000); tryNum++)
     252  {
     253    fil = fopen(fileName.String(), "ab");
     254  }
    248255  /* open for append */
    249   if(!(fil = fopen(fileName.String(), "ab"))) {
     256  if(!fil) {
    250257    Error(I2("Cannot open (append mode) BBM file ",
    251258       "No se pudo abrir (modo de insercion) el fichero BBM ") +
    … …  
    254261  }
    255262  fwrite(M.Data().Buffer(), sizeof(BDat), rows2w*cols2w, fil);
     263  fflush(fil);
    256264  if(fclose(fil))
    257265  {
Note: See TracChangeset for help on using the changeset viewer.