/[escript]/branches/RW_WIN32/bruce/src/Bruce.cpp
ViewVC logotype

Diff of /branches/RW_WIN32/bruce/src/Bruce.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 209 by robwdcock, Wed Nov 23 06:32:25 2005 UTC revision 210 by robwdcock, Wed Nov 23 09:54:02 2005 UTC
# Line 13  Line 13 
13   ******************************************************************************   ******************************************************************************
14  */  */
15    
 #include "Paso/Common.h"  
   
16  #include "Bruce.h"  #include "Bruce.h"
17  #include "BruceException.h"  #include "BruceException.h"
18    
19    #include "Paso/Common.h"
20    
21  #include "vtkCellType.h"  #include "vtkCellType.h"
22  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
23  #include <vector>  #include <vector>
# Line 897  Bruce::saveVTK(const std::string& filena Line 897  Bruce::saveVTK(const std::string& filena
897    const int num_data=boost::python::extract<int>(dataDict.attr("__len__")());    const int num_data=boost::python::extract<int>(dataDict.attr("__len__")());
898    
899    int MAX_namelength=256;    int MAX_namelength=256;
900    
901   // MSVC Refactor: MS VC++ Can't cope with C99 array allocations    /* win32 refactor */
902    std::vector<std::string> names(num_data); // refactored from char names[num_data][MAX_namelength];    char* *names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
903    std::vector<escriptDataC> data(num_data); //refactored from  escriptDataC data[num_data];    for(int i=0;i<num_data;i++)
904    std::vector<escriptDataC*> ptr_data(num_data); // refactored from escriptDataC* ptr_data[num_data];    {
905        names[i] = (MAX_namelength>0) ? TMPMEMALLOC(MAX_namelength,char) : (char*)NULL;
906      }
907    
908      char* *c_names = (num_data>0) ? TMPMEMALLOC(num_data,char*) : (char**)NULL;
909      escriptDataC *data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC) : (escriptDataC*)NULL;
910      escriptDataC* *ptr_data = (num_data>0) ? TMPMEMALLOC(num_data,escriptDataC*) : (escriptDataC**)NULL;
911    
912    boost::python::list keys=dataDict.keys();    boost::python::list keys=dataDict.keys();
913    for (int i=0; i<num_data; i++) {    for (int i=0; i<num_data; i++) {
# Line 912  Bruce::saveVTK(const std::string& filena Line 918  Bruce::saveVTK(const std::string& filena
918      data[i]=d.getDataC();      data[i]=d.getDataC();
919      ptr_data[i]=&(data[i]);      ptr_data[i]=&(data[i]);
920      std::string n=boost::python::extract<std::string>(keys[i]);      std::string n=boost::python::extract<std::string>(keys[i]);
921      names[i]=n;      c_names[i]=&(names[i][0]);
922        if (n.length()>MAX_namelength-1) {
923           strncpy(c_names[i],n.c_str(),MAX_namelength-1);
924           c_names[i][MAX_namelength-1]='\0';
925        } else {
926           strcpy(c_names[i],n.c_str());
927        }
928    }    }
929    
930    //    //
# Line 1318  Bruce::saveVTK(const std::string& filena Line 1330  Bruce::saveVTK(const std::string& filena
1330    // Close archive file    // Close archive file
1331    archiveFile.close();    archiveFile.close();
1332    
1333      /* win32 refactor */
1334      TMPMEMFREE(c_names);
1335      TMPMEMFREE(data);
1336      TMPMEMFREE(ptr_data);
1337      for(int i=0;i<num_data;i++)
1338      {
1339        TMPMEMFREE(names[i]);
1340      }
1341      TMPMEMFREE(names);
1342      
1343    if (!archiveFile.good()) {    if (!archiveFile.good()) {
1344      throw BruceException("Error in Bruce::saveVTK: problem closing file");      throw BruceException("Error in Bruce::saveVTK: problem closing file");
1345    }    }

Legend:
Removed from v.209  
changed lines
  Added in v.210

  ViewVC Help
Powered by ViewVC 1.1.26