dcdread.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2021 NVIDIA Corporation. All rights reserved.
  2. using namespace std;
  3. void dcdreadhead(int *natom, int *nframes, std::istream &infile)
  4. {
  5. infile.seekg(8, ios::beg);
  6. infile.read((char *)nframes, sizeof(int));
  7. infile.seekg(64 * 4, ios::cur);
  8. infile.read((char *)natom, sizeof(int));
  9. infile.seekg(1 * 8, ios::cur);
  10. return;
  11. }
  12. void dcdreadframe(double *x, double *y, double *z, std::istream &infile,
  13. int natom, double &xbox, double &ybox, double &zbox)
  14. {
  15. double d[6];
  16. for (int i = 0; i < 6; i++)
  17. {
  18. infile.read((char *)&d[i], sizeof(double));
  19. }
  20. xbox = d[0];
  21. ybox = d[2];
  22. zbox = d[5];
  23. float a, b, c;
  24. infile.seekg(1 * 8, ios::cur);
  25. for (int i = 0; i < natom; i++)
  26. {
  27. infile.read((char *)&a, sizeof(float));
  28. x[i] = a;
  29. }
  30. infile.seekg(1 * 8, ios::cur);
  31. for (int i = 0; i < natom; i++)
  32. {
  33. infile.read((char *)&b, sizeof(float));
  34. y[i] = b;
  35. }
  36. infile.seekg(1 * 8, ios::cur);
  37. for (int i = 0; i < natom; i++)
  38. {
  39. infile.read((char *)&c, sizeof(float));
  40. z[i] = c;
  41. }
  42. infile.seekg(1 * 8, ios::cur);
  43. return;
  44. }