#include <dm3io.h>
Collaboration diagram for EMAN::Gatan::TagData:
Public Types | |
enum | Type { UNKNOWN = 0, SHORT = 2, INT = 3, USHORT = 4, UINT = 5, FLOAT = 6, DOUBLE = 7, BOOLEAN = 8, CHAR = 9, OCTET = 10, STRUCT = 15, STRING = 18, ARRAY = 20 } |
Public Member Functions | |
TagData (FILE *data_file, TagTable *tagtable, const string &tagname) | |
~TagData () | |
int | read (bool nodata=false) |
Private Member Functions | |
size_t | typesize () const |
size_t | typesize (int type) const |
int | read_any (bool nodata=false) |
vector< int > | read_array_types () |
int | read_array_data (vector< int >item_types, bool nodata=false) |
vector< int > | read_struct_types () |
string | read_native (bool is_value_stored) |
string | read_string (int size) |
Private Attributes | |
FILE * | in |
TagTable * | tagtable |
string | name |
Type | tag_type |
|
Definition at line 100 of file dm3io.h. Referenced by read_any(), read_array_types(), read_struct_types(), and typesize(). 00101 { 00102 UNKNOWN = 0, 00103 SHORT = 2, 00104 INT = 3, 00105 USHORT = 4, 00106 UINT = 5, 00107 FLOAT = 6, 00108 DOUBLE = 7, 00109 BOOLEAN = 8, 00110 CHAR = 9, 00111 OCTET = 10, 00112 STRUCT = 15, 00113 STRING = 18, 00114 ARRAY = 20 00115 };
|
|
Definition at line 163 of file dm3io.cpp. References in.
|
|
Definition at line 168 of file dm3io.cpp. 00169 { 00170 }
|
|
Definition at line 443 of file dm3io.cpp. References in, LOGERR, LOGVAR, and read_any(). Referenced by EMAN::Gatan::TagEntry::read(). 00444 { 00445 LOGVAR("TagData::read()"); 00446 int err = 0; 00447 00448 const char *DATA_TYPE_MARK = "%%%%"; 00449 const size_t mark_sz = strlen(DATA_TYPE_MARK); 00450 char *mark = new char[mark_sz + 1]; 00451 fread(mark, mark_sz, 1, in); 00452 mark[mark_sz] = '\0'; 00453 00454 if (strcmp(mark, DATA_TYPE_MARK) != 0) { 00455 LOGERR("data type label has been changed from '%s' to '%s'", 00456 DATA_TYPE_MARK, mark); 00457 return 1; 00458 } 00459 00460 if( mark ) 00461 { 00462 delete[]mark; 00463 mark = 0; 00464 } 00465 00466 int encoded_types_size = 0; 00467 fread(&encoded_types_size, sizeof(int), 1, in); 00468 ByteOrder::become_big_endian(&encoded_types_size); 00469 00470 LOGVAR("encoded types size = %d\n", encoded_types_size); 00471 00472 err = read_any(nodata); 00473 00474 return err; 00475 }
|
|
Definition at line 395 of file dm3io.cpp. References EMAN::Gatan::TagTable::add(), in, LOGVAR, name, read_array_data(), read_array_types(), read_native(), read_struct_types(), tag_type, tagtable, and Type. Referenced by read(). 00396 { 00397 int err = 0; 00398 00399 fread(&tag_type, sizeof(tag_type), 1, in); 00400 ByteOrder::become_big_endian(&tag_type); 00401 LOGVAR("tag type = '%s'\n", Gatan::to_str((Type) tag_type)); 00402 00403 if (tag_type == ARRAY) { 00404 vector < int >item_types = read_array_types(); 00405 err = read_array_data(item_types, nodata); 00406 } 00407 else if (tag_type == STRUCT) { 00408 vector < int >field_types = read_struct_types(); 00409 00410 for (unsigned int i = 0; i < field_types.size(); i++) { 00411 tag_type = static_cast < Type > (field_types[i]); 00412 string val = read_native(false); 00413 char int_str[32]; 00414 sprintf(int_str, " #%d", i); 00415 string fieldname = name + string(int_str); 00416 tagtable->add(fieldname, val); 00417 } 00418 } 00419 else if (tag_type == STRING) { 00420 int str_sz = 0; 00421 fread(&str_sz, sizeof(str_sz), 1, in); 00422 ByteOrder::become_big_endian(&str_sz); 00423 00424 char *val = new char[str_sz + 1]; 00425 fread(val, str_sz, 1, in); 00426 val[str_sz] = '\0'; 00427 string val_str = string(val); 00428 if( val ) 00429 { 00430 delete[]val; 00431 val = 0; 00432 } 00433 00434 tagtable->add(name, val_str); 00435 } 00436 else { 00437 read_native(true); 00438 } 00439 00440 return err; 00441 }
|
|
Definition at line 302 of file dm3io.cpp. References EMAN::Gatan::TagTable::add(), EMAN::Gatan::TagTable::add_data(), EMAN::Gatan::TagTable::become_host_endian(), data, in, LOGERR, LOGVAR, name, portable_fseek(), read_string(), tagtable, typesize(), and USHORT. Referenced by read_any(). 00303 { 00304 ENTERFUNC; 00305 if (item_types.size() == 0) { 00306 LOGERR("DM3 item types cannot be empty"); 00307 return 1; 00308 } 00309 00310 int err = 0; 00311 int array_size = 0; 00312 00313 fread(&array_size, sizeof(array_size), 1, in); 00314 ByteOrder::become_big_endian(&array_size); 00315 00316 LOGVAR("array size = %d\n", array_size); 00317 00318 size_t item_size = 0; 00319 for (size_t i = 0; i < item_types.size(); i++) { 00320 item_size += typesize(item_types[i]); 00321 } 00322 00323 LOGVAR("%s array item size = %d\n", name.c_str(), item_size); 00324 00325 size_t buf_size = item_size * array_size; 00326 00327 if (item_types.size() == 1 && item_types[0] == USHORT && nodata) { 00328 string val = read_string(array_size); 00329 tagtable->add(name, val); 00330 LOGVAR("value: %s", val.c_str()); 00331 } 00332 else if (!nodata && name == "Data") { 00333 char *data = new char[buf_size]; 00334 fread(data, buf_size, 1, in); 00335 00336 if (item_size == sizeof(short)) { 00337 tagtable->become_host_endian((short *) data, array_size); 00338 } 00339 else if (item_size == sizeof(int)) { 00340 tagtable->become_host_endian((int *) data, array_size); 00341 } 00342 else if (item_size == sizeof(double)) { 00343 tagtable->become_host_endian((double *) data, array_size); 00344 } 00345 else { 00346 LOGERR("cannot handle this type of DM3 image data"); 00347 return 1; 00348 } 00349 00350 tagtable->add_data(data); 00351 } 00352 else { 00353 portable_fseek(in, buf_size, SEEK_CUR); 00354 } 00355 EXITFUNC; 00356 return err; 00357 }
|
|
Definition at line 239 of file dm3io.cpp. References in, LOGERR, LOGVAR, read_struct_types(), and Type. Referenced by read_any(). 00240 { 00241 LOGVAR("TagData::read_array_types()"); 00242 00243 int array_type = 0; 00244 fread(&array_type, sizeof(array_type), 1, in); 00245 00246 ByteOrder::become_big_endian(&array_type); 00247 00248 LOGVAR("array data type = '%s'", Gatan::to_str((Type) array_type)); 00249 00250 vector < int >item_types; 00251 00252 if (array_type == STRUCT) { 00253 item_types = read_struct_types(); 00254 } 00255 else if (array_type == ARRAY) { 00256 item_types = read_array_types(); 00257 LOGERR("DM3: don't know how to handle this array type"); 00258 } 00259 else { 00260 item_types.push_back(array_type); 00261 } 00262 00263 return item_types; 00264 }
|
|
Definition at line 172 of file dm3io.cpp. References EMAN::Gatan::TagTable::add(), EMAN::Gatan::TagTable::become_host_endian(), CHAR, in, LOGERR, LOGVAR, name, tag_type, tagtable, and typesize(). Referenced by read_any(). 00173 { 00174 size_t sz = typesize(); 00175 char val_str[32]; 00176 00177 if (tag_type == SHORT) { 00178 short val = 0; 00179 fread(&val, sz, 1, in); 00180 tagtable->become_host_endian(&val); 00181 sprintf(val_str, "%d", val); 00182 } 00183 else if (tag_type == USHORT) { 00184 unsigned short val = 0; 00185 fread(&val, sz, 1, in); 00186 tagtable->become_host_endian(&val); 00187 sprintf(val_str, "%d", val); 00188 } 00189 else if (tag_type == INT) { 00190 int val = 0; 00191 fread(&val, sz, 1, in); 00192 tagtable->become_host_endian(&val); 00193 sprintf(val_str, "%d", val); 00194 } 00195 else if (tag_type == CHAR || tag_type == OCTET) { 00196 char val = 0; 00197 fread(&val, sz, 1, in); 00198 sprintf(val_str, "%d", val); 00199 } 00200 else if (tag_type == BOOLEAN) { 00201 bool val = false; 00202 fread(&val, sz, 1, in); 00203 tagtable->become_host_endian(&val); 00204 sprintf(val_str, "%d", val); 00205 } 00206 else if (tag_type == UINT) { 00207 unsigned int val = 0; 00208 fread(&val, sz, 1, in); 00209 tagtable->become_host_endian(&val); 00210 sprintf(val_str, "%d", (int) val); 00211 } 00212 else if (tag_type == FLOAT) { 00213 float val = 0; 00214 fread(&val, sz, 1, in); 00215 tagtable->become_host_endian(&val); 00216 sprintf(val_str, "%f", val); 00217 } 00218 else if (tag_type == DOUBLE) { 00219 double val = 0; 00220 fread(&val, sz, 1, in); 00221 tagtable->become_host_endian(&val); 00222 sprintf(val_str, "%10e", val); 00223 } 00224 else { 00225 LOGERR("invalid tag type: '%d'", tag_type); 00226 exit(1); 00227 } 00228 00229 if (is_value_stored) { 00230 tagtable->add(name, val_str); 00231 } 00232 00233 LOGVAR("value = '%s'", val_str); 00234 00235 return string(val_str); 00236 }
|
|
Definition at line 268 of file dm3io.cpp. References EMAN::Gatan::TagTable::become_host_endian(), in, and tagtable. Referenced by read_array_data(). 00269 { 00270 if (size <= 0) { 00271 return string(""); 00272 } 00273 00274 unsigned short *buf = new unsigned short[size]; 00275 char *str = new char[size + 1]; 00276 00277 fread(buf, size * sizeof(unsigned short), 1, in); 00278 tagtable->become_host_endian < unsigned short >(buf, size); 00279 00280 for (int i = 0; i < size; i++) { 00281 str[i] = static_cast < char >(buf[i]); 00282 } 00283 00284 str[size] = '\0'; 00285 string str1 = string(str); 00286 00287 if( str ) 00288 { 00289 delete[]str; 00290 str = 0; 00291 } 00292 if( buf ) 00293 { 00294 delete[]buf; 00295 buf = 0; 00296 } 00297 00298 return str1; 00299 }
|
|
Definition at line 359 of file dm3io.cpp. References in, LOGVAR, and Type. Referenced by read_any(), and read_array_types(). 00360 { 00361 LOGVAR("TagData::read_struct_types()"); 00362 00363 unsigned int namelength = 0; 00364 unsigned int nfields = 0; 00365 00366 fread(&namelength, sizeof(namelength), 1, in); 00367 ByteOrder::become_big_endian(&namelength); 00368 00369 fread(&nfields, sizeof(nfields), 1, in); 00370 ByteOrder::become_big_endian(&nfields); 00371 00372 LOGVAR("namelength = %d\n", namelength); 00373 LOGVAR("num fields = %d\n", nfields); 00374 00375 vector < int >field_types; 00376 00377 for (unsigned int i = 0; i < nfields; i++) { 00378 fread(&namelength, sizeof(namelength), 1, in); 00379 ByteOrder::become_big_endian(&namelength); 00380 00381 int field_type = 0; 00382 fread(&field_type, sizeof(field_type), 1, in); 00383 ByteOrder::become_big_endian(&field_type); 00384 00385 LOGVAR("%dth namelength = %d, type = '%s'", 00386 i, namelength, Gatan::to_str((Type) field_type)); 00387 field_types.push_back(field_type); 00388 } 00389 00390 return field_types; 00391 }
|
|
Definition at line 483 of file dm3io.cpp. References BOOLEAN, CHAR, DOUBLE, FLOAT, INT, LOGERR, OCTET, SHORT, Type, UINT, and USHORT. 00484 { 00485 size_t size = 0; 00486 Type type = static_cast < Type > (t); 00487 00488 switch (type) { 00489 case SHORT: 00490 size = sizeof(short); 00491 break; 00492 case USHORT: 00493 size = sizeof(unsigned short); 00494 break; 00495 case INT: 00496 size = sizeof(int); 00497 break; 00498 case UINT: 00499 size = sizeof(unsigned int); 00500 break; 00501 case FLOAT: 00502 size = sizeof(float); 00503 break; 00504 case DOUBLE: 00505 size = sizeof(double); 00506 break; 00507 case BOOLEAN: 00508 size = sizeof(bool); 00509 break; 00510 case CHAR: 00511 case OCTET: 00512 size = sizeof(char); 00513 break; 00514 default: 00515 LOGERR("no such type: '%d'\n", type); 00516 break; 00517 } 00518 00519 return size; 00520 }
|
|
Definition at line 478 of file dm3io.cpp. References tag_type. Referenced by read_array_data(), and read_native(). 00479 { 00480 return typesize((int) tag_type); 00481 }
|
|
Definition at line 134 of file dm3io.h. Referenced by read(), read_any(), read_array_data(), read_array_types(), read_native(), read_string(), and read_struct_types(). |
|
Definition at line 136 of file dm3io.h. Referenced by read_any(), read_array_data(), and read_native(). |
|
Definition at line 137 of file dm3io.h. Referenced by read_any(), read_native(), and typesize(). |
|
Definition at line 135 of file dm3io.h. Referenced by read_any(), read_array_data(), read_native(), and read_string(). |