Changeset 9796d0a for python/lib
- Timestamp:
- 09/25/17 19:20:08 (7 years ago)
- Branches:
- master, pympi
- Children:
- 56b997e
- Parents:
- b02d091
- git-author:
- Hal Finkel <hfinkel@…> (09/25/17 19:20:08)
- git-committer:
- Hal Finkel <hfinkel@…> (09/25/17 19:20:08)
- Location:
- python/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/gio.cxx
rbd84570 r9796d0a 43 43 #include <iostream> 44 44 45 void read_gio_float(char* file_name, char* var_name, float* data ){46 read_gio<float>(file_name,var_name,data );45 void read_gio_float(char* file_name, char* var_name, float* data, int field_count){ 46 read_gio<float>(file_name,var_name,data,field_count); 47 47 } 48 void read_gio_double(char* file_name, char* var_name, double* data ){49 read_gio<double>(file_name,var_name,data );48 void read_gio_double(char* file_name, char* var_name, double* data, int field_count){ 49 read_gio<double>(file_name,var_name,data,field_count); 50 50 } 51 void read_gio_int32(char* file_name, char* var_name, int* data ){52 read_gio<int>(file_name,var_name,data );51 void read_gio_int32(char* file_name, char* var_name, int* data, int field_count){ 52 read_gio<int>(file_name,var_name,data,field_count); 53 53 } 54 void read_gio_int64(char* file_name, char* var_name, int64_t* data ){55 read_gio<int64_t>(file_name,var_name,data );54 void read_gio_int64(char* file_name, char* var_name, int64_t* data, int field_count){ 55 read_gio<int64_t>(file_name,var_name,data,field_count); 56 56 } 57 57 … … 77 77 gio::GenericIO::VariableInfo vinfo = VI[i]; 78 78 if(vinfo.Name == var_name){ 79 if(vinfo.IsFloat && vinfo. Size == 4)79 if(vinfo.IsFloat && vinfo.ElementSize == 4) 80 80 return float_type; 81 else if(vinfo.IsFloat && vinfo. Size == 8)81 else if(vinfo.IsFloat && vinfo.ElementSize == 8) 82 82 return double_type; 83 else if(!vinfo.IsFloat && vinfo. Size == 4)83 else if(!vinfo.IsFloat && vinfo.ElementSize == 4) 84 84 return int32_type; 85 else if(!vinfo.IsFloat && vinfo. Size == 8)85 else if(!vinfo.IsFloat && vinfo.ElementSize == 8) 86 86 return int64_type; 87 87 else … … 91 91 return var_not_found; 92 92 93 } 94 95 int get_variable_field_count(char* file_name,char* var_name){ 96 gio::GenericIO reader(file_name); 97 std::vector<gio::GenericIO::VariableInfo> VI; 98 reader.openAndReadHeader(gio::GenericIO::MismatchAllowed); 99 reader.getVariableInfo(VI); 100 101 int num =VI.size(); 102 for(int i =0;i<num;++i){ 103 gio::GenericIO::VariableInfo vinfo = VI[i]; 104 if(vinfo.Name == var_name) { 105 return vinfo.Size/vinfo.ElementSize; 106 } 107 } 108 return 0; 93 109 } 94 110 … … 110 126 else 111 127 std::cout<<"[i"; 112 std::cout<<" "<<vinfo.Size*8<<"] "; 128 int NumElements = vinfo.Size/vinfo.ElementSize; 129 std::cout<<" "<<vinfo.ElementSize*8; 130 if (NumElements > 1) 131 std::cout<<"x"<<NumElements; 132 std::cout<<"] "; 113 133 std::cout<<vinfo.Name<<std::endl; 114 134 } -
python/lib/gio.h
rbd84570 r9796d0a 46 46 47 47 template <class T> 48 void read_gio(char* file_name, std::string var_name, T*& data ){48 void read_gio(char* file_name, std::string var_name, T*& data, int field_count){ 49 49 gio::GenericIO reader(file_name); 50 50 reader.openAndReadHeader(gio::GenericIO::MismatchAllowed); … … 57 57 max_size = rank_size[i]; 58 58 } 59 T* rank_data = new T[max_size +reader.requestedExtraSpace()/sizeof(T)];59 T* rank_data = new T[max_size*field_count+reader.requestedExtraSpace()/sizeof(T)]; 60 60 int64_t offset =0; 61 reader.addVariable(var_name,rank_data,true); 61 reader.addScalarizedVariable(var_name,rank_data,field_count, 62 gio::GenericIO::VarHasExtraSpace); 62 63 for(int i=0;i<num_ranks;++i){ 63 64 reader.readData(i,false); 64 std::copy(rank_data,rank_data+rank_size[i] ,data+offset);65 offset +=rank_size[i] ;65 std::copy(rank_data,rank_data+rank_size[i]*field_count,data+offset); 66 offset +=rank_size[i]*field_count; 66 67 } 67 68 delete [] rank_data; … … 70 71 extern "C" int64_t get_elem_num(char* file_name); 71 72 72 extern "C" void read_gio_float (char* file_name, char* var_name, float* data );73 extern "C" void read_gio_double(char* file_name, char* var_name, double* data );74 extern "C" void read_gio_int32 (char* file_name, char* var_name, int* data );75 extern "C" void read_gio_int64 (char* file_name, char* var_name, int64_t* data );73 extern "C" void read_gio_float (char* file_name, char* var_name, float* data, int field_count); 74 extern "C" void read_gio_double(char* file_name, char* var_name, double* data, int field_count); 75 extern "C" void read_gio_int32 (char* file_name, char* var_name, int* data, int field_count); 76 extern "C" void read_gio_int64 (char* file_name, char* var_name, int64_t* data, int field_count); 76 77 enum var_type{ 77 78 float_type=0, … … 83 84 }; 84 85 extern "C" var_type get_variable_type(char* file_name,char* var_name); 86 extern "C" int get_variable_field_count(char* file_name,char* var_name); 85 87 extern "C" void inspect_gio(char* file_name);
Note: See TracChangeset
for help on using the changeset viewer.