Changeset 1441


Ignore:
Timestamp:
02/23/18 14:35:39 (3 years ago)
Author:
oabramkina
Message:

Properly terminating a string on writing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/XIOS_DEV_CMIP6/src/io/onetcdf4_impl.hpp

    r1435 r1441  
    6060    CTimer::get("CONetCDF4::writeData getWriteDataInfos").suspend(); 
    6161  
     62    int dimArrayLen; 
     63    for (int i=0; i<scount.size(); i++) 
     64      if (scount[i] == stringArrayLen) 
     65        dimArrayLen = i; 
     66 
    6267    if (data.numElements()*stringArrayLen != array_size) 
    6368    { 
     
    6772      << " ] Invalid input data !" ); 
    6873    } 
    69     char* ArrayStr ; 
    7074    char *PtrArrayStr ; 
    71     PtrArrayStr=ArrayStr=new char[data.numElements()*stringArrayLen] ; 
     75    PtrArrayStr=new char[stringArrayLen] ; 
    7276    Array<StdString,1>::const_iterator it, itb=data.begin(), ite=data.end() ; 
    73     for(it=itb;it!=ite;++it,PtrArrayStr+=stringArrayLen) 
     77    int lineNb; 
     78    for(it=itb;it!=ite;++it) 
    7479    { 
    7580      it->copy(PtrArrayStr,it->size()) ; 
    7681      PtrArrayStr[it->size()]='\0' ; 
     82      sstart[0] = lineNb; 
     83      sstart[dimArrayLen] = 0; 
     84      scount[0] = 1; 
     85      scount[dimArrayLen] = it->size() + 1; 
     86      CTimer::get("CONetCDF4::writeData writeData_").resume(); 
     87      this->writeData_(grpid, varid, sstart, scount, PtrArrayStr); 
     88      CTimer::get("CONetCDF4::writeData writeData_").suspend(); 
     89      ++lineNb; 
    7790    } 
    78     CTimer::get("CONetCDF4::writeData writeData_").resume(); 
    79     this->writeData_(grpid, varid, sstart, scount, ArrayStr); 
    80     CTimer::get("CONetCDF4::writeData writeData_").suspend(); 
    81     delete [] ArrayStr ; 
     91    delete []  PtrArrayStr; 
    8292  } 
    8393 
Note: See TracChangeset for help on using the changeset viewer.