| 174 | |
| 175 | template<int bits> |
| 176 | bool writePDBHelper(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) |
| 177 | { |
| 178 | unique_ptr<ostream> output( |
| 179 | compressed ? |
| 180 | Gzip_Out(filename,ios::out|ios::binary) |
| 181 | :new ofstream(filename,ios::out|ios::binary)); |
| 182 | |
| 183 | if(!*output){ |
| 184 | if(errorStream) *errorStream<<"Partio Unable to open file "<<filename<<endl; |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | typename PDB_POLICY<bits>::HEADER h32; |
| 189 | memset(&h32,0,sizeof(typename PDB_POLICY<bits>::HEADER)); |
| 190 | h32.magic=PDB_MAGIC; |
| 191 | h32.swap=1; |
| 192 | h32.version=1.0; |
| 193 | h32.time=0.0; |
| 194 | h32.data_size=p.numParticles(); |
| 195 | h32.num_data=p.numAttributes(); |
| 196 | for(int k=0;k<32;k++) h32.padding[k]=0; |
| 197 | h32.data=0; |
| 198 | output->write((char*)&h32,sizeof(typename PDB_POLICY<bits>::HEADER)); |
| 199 | |
| 200 | for(int attrIndex=0;attrIndex<p.numAttributes();attrIndex++){ |
| 201 | ParticleAttribute attr; |
| 202 | p.attributeInfo(attrIndex,attr); |
| 203 | |
| 204 | typename PDB_POLICY<bits>::CHANNEL_IO cio; |
| 205 | typename PDB_POLICY<bits>::CHANNEL channel; |
| 206 | typename PDB_POLICY<bits>::CHANNEL_DATA data_header; |
| 207 | memset(&cio,0,sizeof(typename PDB_POLICY<bits>::CHANNEL_IO)); |
| 208 | memset(&channel,0,sizeof(typename PDB_POLICY<bits>::CHANNEL)); |
| 209 | memset(&data_header,0,sizeof(typename PDB_POLICY<bits>::CHANNEL_DATA)); |
| 210 | |
| 211 | cio.magic=0; |
| 212 | cio.swap=1; |
| 213 | cio.encoding=0; |
| 214 | cio.type=0; |
| 215 | output->write((char*)&cio,sizeof(typename PDB_POLICY<bits>::CHANNEL_IO)); |
| 216 | |
| 217 | // TODO: assert cproper count! |
| 218 | channel.name=0; |
| 219 | switch(attr.type){ |
| 220 | case INDEXEDSTR:channel.type=PDB_LONG;break; |
| 221 | case INT:channel.type=PDB_LONG;break; |
| 222 | case FLOAT:channel.type=PDB_REAL;break; |
| 223 | case VECTOR:channel.type=PDB_VECTOR;break; |
| 224 | default: assert(false); |
| 225 | } |
| 226 | channel.size=0; |
| 227 | channel.active_start=0; |
| 228 | channel.active_end=h32.data_size-1; |
| 229 | channel.hide=0; |
| 230 | channel.disconnect=0; |
| 231 | channel.data=0; |
| 232 | channel.link=0; |
| 233 | channel.next=0; |
nothing calls this directly
no test coverage detected