Ignore:
Timestamp:
09/24/15 15:55:17 (9 years ago)
Author:
rlacroix
Message:

Append mode: Detect the correct restart point and erase some records if need be.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/io/nc4_data_output.cpp

    r706 r707  
    13931393      void CNc4DataOutput::writeFieldData_ (CField*  field) 
    13941394      { 
    1395          CContext* context = CContext::getCurrent() ; 
    1396 //          if (field->getRelFile()->isSyncTime()) SuperClassWriter::sync() ; 
    1397          CContextServer* server=context->server ; 
    1398  
    1399          CGrid* grid = field->grid ; 
    1400  
    1401          if (!grid->doGridHaveDataToWrite()) 
    1402           if (SuperClass::type==MULTI_FILE || !isCollective) return ; 
    1403  
    1404          StdString fieldid   = (!field->name.isEmpty()) 
    1405                              ? field->name.getValue() 
    1406                              : field->getBaseFieldReference()->getId(); 
    1407  
    1408          StdOStringStream oss; 
    1409          string timeAxisId ; 
    1410          if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisId="time_instant" ; 
    1411          else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisId="time_centered" ; 
    1412  
    1413          StdString timeBoundId("time_counter_bounds"); 
    1414  
    1415          StdString timeAxisBoundId; 
    1416          if (field->getOperationTimeType() == func::CFunctor::instant)  timeAxisBoundId="time_instant_bounds" ; 
    1417          else if (field->getOperationTimeType() == func::CFunctor::centered)  timeAxisBoundId="time_centered_bounds" ; 
    1418  
    1419          CArray<double,1> time_data(1) ; 
    1420          CArray<double,1> time_data_bound(2); 
    1421          CArray<double,1> time_counter(1) ; 
    1422          CArray<double,1> time_counter_bound(2); 
    1423  
    1424         bool wtime   = !(!field->operation.isEmpty() && (field->getOperationTimeType() == func::CFunctor::once)); 
     1395        CContext* context = CContext::getCurrent(); 
     1396        CContextServer* server = context->server; 
     1397        CGrid* grid = field->grid; 
     1398 
     1399        if (!grid->doGridHaveDataToWrite()) 
     1400          if (SuperClass::type == MULTI_FILE || !isCollective) return; 
     1401 
     1402        StdString fieldid = !field->name.isEmpty() 
     1403                          ? field->name.getValue() 
     1404                          : field->getBaseFieldReference()->getId(); 
     1405 
     1406        StdOStringStream oss; 
     1407        string timeAxisId; 
     1408        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisId = "time_instant"; 
     1409        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisId = "time_centered"; 
     1410 
     1411        StdString timeBoundId("time_counter_bounds"); 
     1412 
     1413        StdString timeAxisBoundId; 
     1414        if (field->getOperationTimeType() == func::CFunctor::instant) timeAxisBoundId = "time_instant_bounds"; 
     1415        else if (field->getOperationTimeType() == func::CFunctor::centered) timeAxisBoundId = "time_centered_bounds"; 
     1416 
     1417        if (!field->wasWritten()) 
     1418        { 
     1419          if (appendMode) 
     1420          { 
     1421            field->resetNStep(getRecordFromTime(field->last_Write_srv) + 1); 
     1422          } 
     1423 
     1424          field->setWritten(); 
     1425        } 
     1426 
     1427 
     1428        CArray<double,1> time_data(1); 
     1429        CArray<double,1> time_data_bound(2); 
     1430        CArray<double,1> time_counter(1); 
     1431        CArray<double,1> time_counter_bound(2); 
     1432 
     1433        bool wtime = (field->getOperationTimeType() != func::CFunctor::once); 
    14251434 
    14261435        if (wtime) 
     
    14611470        } 
    14621471 
    1463          bool isRoot ; 
    1464          if (server->intraCommRank==0) isRoot=true ; 
    1465          else isRoot=false ; 
     1472         bool isRoot = (server->intraCommRank == 0); 
    14661473 
    14671474         if (!field->scale_factor.isEmpty() || !field->add_offset.isEmpty()) 
    14681475         { 
    1469            double scaleFactor=1. ; 
    1470            double addOffset=0. ; 
    1471            if (!field->scale_factor.isEmpty()) scaleFactor=field->scale_factor ; 
    1472            if (!field->add_offset.isEmpty()) addOffset=field->add_offset ; 
    1473            field->scaleFactorAddOffset(scaleFactor,addOffset) ; 
     1476           double scaleFactor = 1.0; 
     1477           double addOffset = 0.0; 
     1478           if (!field->scale_factor.isEmpty()) scaleFactor = field->scale_factor; 
     1479           if (!field->add_offset.isEmpty()) addOffset = field->add_offset; 
     1480           field->scaleFactorAddOffset(scaleFactor, addOffset); 
    14741481         } 
    14751482 
     
    14901497             field->outputField(fieldData); 
    14911498 
    1492            if (!field->prec.isEmpty() && field->prec==2) fieldData=round(fieldData) ; 
     1499           if (!field->prec.isEmpty() && field->prec == 2) fieldData = round(fieldData); 
    14931500 
    14941501           switch (SuperClass::type) 
     
    15081515                   } 
    15091516                 } 
    1510                  break ; 
     1517                 break; 
    15111518              } 
    15121519              case (ONE_FILE) : 
     
    19711978      ///-------------------------------------------------------------- 
    19721979 
     1980      StdSize CNc4DataOutput::getRecordFromTime(Time time) 
     1981      { 
     1982        std::map<Time, StdSize>::const_iterator it = timeToRecordCache.find(time); 
     1983        if (it == timeToRecordCache.end()) 
     1984        { 
     1985          StdString timeAxisBoundsId("time_counter_bounds"); 
     1986          if (!SuperClassWriter::varExist(timeAxisBoundsId)) 
     1987            timeAxisBoundsId = "time_instant_bounds"; 
     1988 
     1989          CArray<double,2> timeAxisBounds; 
     1990          SuperClassWriter::getTimeAxisBounds(timeAxisBounds, timeAxisBoundsId, isCollective); 
     1991 
     1992          StdSize record = 0; 
     1993          double dtime(time); 
     1994          for (int n = timeAxisBounds.extent(1) - 1; n >= 0; n--) 
     1995          { 
     1996            if (timeAxisBounds(1, n) < dtime) 
     1997            { 
     1998              record = n + 1; 
     1999              break; 
     2000            } 
     2001          } 
     2002          it = timeToRecordCache.insert(std::make_pair(time, record)).first; 
     2003        } 
     2004        return it->second; 
     2005      } 
    19732006} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.