Changeset 800


Ignore:
Timestamp:
01/08/06 16:35:04 (6 years ago)
Author:
pfp
Message:

Added ability to do compression.

Location:
trunk/applications/NXtranslate
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/applications/NXtranslate/nexus_util.cpp

    r416 r800  
    8181 
    8282      // create the data 
    83       if(node.compress_type()==Node::COMP_NONE){ 
     83      int comp_type=node.compress_type(); 
     84      if(comp_type==Node::COMP_NONE){ 
    8485        //std::cout << "in open: " << node.type() << " " << *(node.dims().begin()) << std::endl; // REMOVE 
    8586        if(NXmakedata(*handle,name,type,rank,dims)!=NX_OK){ 
     
    8889        } 
    8990      }else{ 
    90         int comp_type=node.compress_type(); 
    91         // warn that this is not supported 
    92         std::cout << "WARN: do not currently support compression (type=" << comp_type << ")" << std::endl; 
    93         return; 
    94         /* TAKEN FROM <napi.h> 
    95            NX_EXTERNAL  NXstatus CALLING_STYLE NXcompmakedata (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int dim[], int comp_typ, int bufsize[]); 
    96         */ 
     91        vector<int> buff_size_vec=node.comp_buffer_dims(); 
     92        int *buff_size=new int[rank]; 
     93        for( size_t i=0 ; i<rank ; i++ ){ 
     94          buff_size[i]=buff_size_vec[i]; 
     95        } 
     96 
     97        buff_size[rank-1]=dims[rank-1]; 
     98        if(NXcompmakedata(*handle,name,type,rank,dims,comp_type,buff_size)!=NX_OK){ 
     99          std::cout << "NXcompmakedata failed" << std::endl; 
     100          throw runtime_error("NXcompmakedata failed"); 
     101        } 
     102        delete buff_size; // FIXME - is this the correct form? 
    97103      } 
    98104    } 
  • trunk/applications/NXtranslate/node.cpp

    r683 r800  
    167167} 
    168168 
     169const std::vector<int> Node::comp_buffer_dims() const{ 
     170  return __comp_buffer_dims; 
     171} 
     172 
    169173void* Node::data() const{ 
    170174  return __value; 
     
    202206    throw out_of_range("asked for attribute with higher index than size"); 
    203207  return (*(__attrs.begin()+attr_num)); 
     208} 
     209 
     210const void Node::set_comp(const string &comp_type){ 
     211  if(string_util::starts_with(comp_type,"NONE")){ 
     212    __comp_type=COMP_NONE; 
     213  }else if(string_util::starts_with(comp_type,"LZW")){ 
     214    __comp_type=COMP_LZW; 
     215  }else if(string_util::starts_with(comp_type,"RLE")){ 
     216    __comp_type=COMP_RLE; 
     217  }else if(string_util::starts_with(comp_type,"HUF")){ 
     218    __comp_type=COMP_HUF; 
     219  }else{ 
     220    throw invalid_argument("Do not understand compression type: "+comp_type); 
     221  } 
     222 
     223  // work with user specified dimension information 
     224  vector<string> temp=string_util::split(comp_type,":"); 
     225  if(temp.size()==2){ 
     226    __comp_buffer_dims=string_util::str_to_intVec(*(temp.rbegin())); 
     227  } 
     228 
     229  // use default if anything is wrong 
     230  if(__comp_buffer_dims.size()!=__dims.size()){ 
     231    __comp_buffer_dims=__dims; 
     232    for( size_t i=0 ; i<__comp_buffer_dims.size()-1 ; ++i ){ 
     233      __comp_buffer_dims[i]=1; 
     234    } 
     235  } 
    204236} 
    205237 
  • trunk/applications/NXtranslate/node.h

    r772 r800  
    3232  const int rank() const; 
    3333  const std::vector<int> dims() const; 
     34  const std::vector<int> comp_buffer_dims() const; 
    3435  const NXtype int_type() const; 
    3536  const NXcompress compress_type() const; 
     
    4041 
    4142  // mutator methods 
     43  const void set_comp(const std::string &comp_type); 
    4244  const void set_name(const std::string &name); 
    4345  const void set_data(void *&data,const int rank,const int* dims,const int type); 
     
    5355  bool __is_data; 
    5456  std::vector<int> __dims; 
     57  std::vector<int> __comp_buffer_dims; 
    5558  void *__value; 
    5659  std::vector<Attr> __attrs; 
  • trunk/applications/NXtranslate/xml_parser.cpp

    r783 r800  
    4040typedef NodeVector* NodeVectorP; 
    4141typedef Ptr<Retriever> RetrieverPtr; 
     42typedef tree<Node> NodeTree; 
    4243 
    4344static const int    GROUP_STRING_LEN  = 128; 
     
    4748static const string SOURCE            = "NXS:source"; 
    4849static const string LOCATION          = "NXS:location"; 
     50static const string COMPRESSION       = "NXS:compression"; 
    4951static const string LINK              = "NAPIlink"; 
    5052static const string TARGET            = "target"; 
     
    190192 
    191193  // check for "name", "type", "source", "mime_type", "location", 
    192   // "target" attributes 
     194  // "target", "compression" attributes 
    193195  string source; 
    194196  string mime_type; 
    195197  string location; 
     198  string compression; 
    196199  string type; 
    197200  bool update_dims=false; 
     
    199202  for( StrVector::iterator it=str_attrs.begin() ; it!=str_attrs.end() ; it+=2){ 
    200203    if( (*it==SOURCE) || (*it==MIME_TYPE) || (*it==LOCATION) || (*it==TYPE) 
    201              || ((*it==TARGET) && (is_link)) || (*it==NAME) ){ 
     204        || ((*it==TARGET) && (is_link)) || (*it==NAME) || (*it==COMPRESSION) ){ 
    202205      if(*it==SOURCE){ 
    203206        source=*(it+1); 
     
    206209      }else if(*it==LOCATION){ 
    207210        location=*(it+1); 
     211      }else if(*it==COMPRESSION){ 
     212        compression=*(it+1); 
    208213      }else if(*it==NAME){ 
    209214        type=str_name; 
     
    316321  } 
    317322 
     323  // set the compression flag 
     324  if(!compression.empty()){ 
     325    if(node_from_retriever){ 
     326      for( NodeTree::iterator it=tree.begin() ; it!=tree.end() ; ++it ){ 
     327        it->set_comp(compression); 
     328      } 
     329    }else{ 
     330      node.set_comp(compression); 
     331    } 
     332  } 
     333 
    318334  // mutate the attributes if necessary 
    319335  if(node_attrs.size()>0) 
Note: See TracChangeset for help on using the changeset viewer.