SDA (SDA flex)  7.2
Simulation of Diffusional Association
DTGrid3Dex.hpp
Go to the documentation of this file.
1 
57 #ifndef DTGRID3DEX_HPP_
58 #define DTGRID3DEX_HPP_
59 //
60 #include <stdlib.h>
61 #include <string.h>
62 #include <cstring>
63 #include <iostream>
64 #include <fstream>
65 #include <sstream>
66 #include <typeinfo>
67 //
68 #include "ArrayReg.hpp"
69 #include "ArrayPtr.hpp"
70 #include "ArrayPrs.hpp"
71 #include "DTGrid2D.hpp"
72 
73 class DTGrid3Dex {
74 public:
75  DTGrid3Dex(char *);
76  ~DTGrid3Dex();
77 
78 private:
79 
83 
85 
89 
91  int iform;
92 
94  int grid_type;
95 
96  float scale;
97  float spacing;
98 
100  struct {
101  int i;
102  int j;
103  int k;
105 
107  struct {
108  float x;
109  float y;
110  float z;
112 
113  //
114  void set_zcoord_list(int*,int);
115  void set_projection2D(int*, int*, int*, int*, int*, int*, int, int, int, int, int, int);
116  void set_uhbd_parameters(float, float, float, float, float, int, int, int);
117  void Reset_pointers_3D(void);
118 
119  //
120  void test_format_dtgrid(char *);
121  void size_ds(unsigned int);
122  void format_ascii(char *);
123  void format_binary(char *);
124 
125 public:
127  struct {
128  char * Title;
129  int grdflag;
130  int one;
131  int idummy1;
132  int idummy2;
133  int idummy3;
134  int idummy4;
135  int idummy5;
136  float scale;
137  float spacing;
138  float dummy1;
139  float dummy2;
140  float dummy3;
141  float dummy4;
142  float dummy5;
143  float dummy6;
144  float dummy7;
145  struct dimensions
146  {
147  int i;
148  int j;
149  int k;
150  }dim;
151  struct origin
152  {
153  float x;
154  float y;
155  float z;
156  }o;
158 
159  bool accessxyz(int, int, int);
160  bool * getCell(bool *, int, int, int);
161  bool * getCell2(bool *, int, int, int);
162 
163 protected:
164  void getCellz(bool *, int, int, int, typename ArrayPrs <int>::PairArray *);
165  void getCellyz(bool *, int, int, int, typename ArrayPrs <int>::PairArray *);
166 
167 };
168 
171  delete proj2D;
172  delete Zcoord_List;
173 }
174 
176 
179 DTGrid3Dex::DTGrid3Dex(char * file_name){
180 
183 
184  test_format_dtgrid(file_name);
185  if (iform == 0)
186  format_binary(file_name);
187  else if (iform == 1)
188  format_ascii(file_name);
189  else{
190  std::cout << "Error: Unknown file format" << std::endl;
191  exit(0);
192  }
193 }
194 
196 
201 void DTGrid3Dex::set_zcoord_list(int* values, int length){
202  Zcoord_List = new (std::nothrow) ArrayPrs <int>;
203  Zcoord_List->Set_Pair_Array_Values(values,length);
204  Length_of_Zcoord_List = length;
205 }
206 
208 
223 void DTGrid3Dex::set_projection2D(int* values1, int* values2, int* values3, \
224  int* values4, int* values5, int* values6, int length1, int length2, \
225  int length3, int length4, int length5, int length6){
226 
227  proj2D = new (std::nothrow) DTGrid2D <bool,int>;
228  proj2D->set_value_list_2D(values1,length1);
229  proj2D->set_ycoord_list(values2,length2);
230  proj2D->set_ptr_list_2D(values3,length3);
231  proj2D->set_projection1D(values4, values5, values6, length4, length5, length6);
232 }
233 
235 
246 void DTGrid3Dex::set_uhbd_parameters(float sc, float sp, float ox, float oy, float oz, int dimi, int dimj, int dimk){
247  scale = sc;
248  spacing = sp;
249 
250  origin.x = ox;
251  origin.y = oy;
252  origin.z = oz;
253 
254  dimensions.i = dimi;
255  dimensions.j = dimk;
256  dimensions.k = dimk;
257 }
258 
260 
273 bool DTGrid3Dex::accessxyz(int a, int b, int c){
274 
275  // Call the random access function in the DTGrid2D.
276  typename ArrayPrs <int>::PairArray * coord3 = proj2D->accessxy(a,b);
277 
278  // Return the default value if recursive function call returns NULL.
279  if (coord3 == NULL) return false;
280 
281  bool key3 = false; // a local logical operation variable.
282 
283  int checkpoint_31 = coord3->v2; // the index of the first connected component in a tubular grid in the zCoord array.
284  int checkpoint_32 = (coord3+1)->v2; // the index of the last connected component in a tubular grid in the zCoord array.
285  int countdown_3 = checkpoint_32 - checkpoint_31; // Determine how many connected components are there in the corresponding tubular grid (3D).
286 
287  // Return when no connected component found
288  if (countdown_3 == 0) return false;
289 
290  typename ArrayPrs <int>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31; // a temporary pointer to store an zCoord array pair.
291 
292  // iterate over the connected components in DTGrid3Dex
293  for (; countdown_3 >= 1; countdown_3--){
294 
295  // check whether index c is inside one of the connected components using the zCoord index array.
296  key3 = c>=coo3->v1 ? (c<=coo3->v2 ? true : false) : false;
297  if (key3 == true){
298  return true;
299  }
300  else {
301  ++coo3;
302  continue;
303  }
304  }
305  return false;
306 }
307 
309 
317 void DTGrid3Dex::getCellz(bool * Cell, int x, int y, int c, typename ArrayPrs <int>::PairArray * coord3){
318 
319  short skey3;
320  int cinc = c+1;
321 
322  int checkpoint_31 = coord3->v2;
323  int checkpoint_32 = (coord3+1)->v2;
324  int countdown_3 = checkpoint_32 - checkpoint_31;
325 
326  typename ArrayPrs <int>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31;
327 
328  for (; countdown_3 >= 1; countdown_3--){
329  skey3 = c>=coo3->v1 ? (cinc<=coo3->v2 ? 1 : (c<=coo3->v2 ? 2 : 0) ) : (cinc>=coo3->v1 ? (cinc<=coo3->v2 ? 3 : 0) : 0);
330  //key3 = c>=coo3->v1 ? (c<=coo3->v2 ? true : false) : false;
331  switch (skey3)
332  {
333  case 0:
334  ++coo3;
335  break;
336  case 1:
337  Cell[4*x+2*y] = true;
338  Cell[4*x+2*y+1] = true;
339  return;
340  case 2:
341  Cell[4*x+2*y] = true;
342  return;
343  case 3:
344  Cell[4*x+2*y+1] = true;
345  return;
346  }
347  }
348  return;
349 }
350 
352 
360 void DTGrid3Dex::getCellyz(bool * Cell, int x, int b, int c, typename ArrayPrs <int>::PairArray * coord2){
361 
362  short skey2;
363  int binc = b+1;
364 
365  int checkpoint_21 = coord2->v2;
366  int checkpoint_22 = (coord2+1)->v2;
367  int countdown_2 = checkpoint_22 - checkpoint_21;
368 
369  if (countdown_2 == 0){ return;}
370 
371  typename ArrayPrs <int>::PairArray ** ptt2 = proj2D->Ptr_List_2D->PtrArray+checkpoint_21;
372  typename ArrayPrs <int>::PairArray * coo2 = proj2D->Ycoord_List->PArray+checkpoint_21;
373 
374  for (; countdown_2 >= 1; countdown_2--){
375  skey2 = b>=coo2->v1 ? (binc<=coo2->v2 ? 1 : (b<=coo2->v2 ? 2 : 0) ) : (binc>=coo2->v1 ? (binc<=coo2->v2 ? 3 : 0) : 0);
376 
377  switch (skey2)
378  {
379  case 0:
380  ++ptt2;
381  ++coo2;
382  break;
383  case 1:
384  getCellz(Cell, x,0,c, *(ptt2)+b-coo2->v1);
385  //++b;
386  getCellz(Cell, x,1,c, *(ptt2)+binc-coo2->v1);
387  return;
388  case 2:
389  //printf("%d %d %d %d\n",b,b+1,coo2->v1,coo2->v2);
390  getCellz(Cell, x,0,c, *(ptt2)+b-coo2->v1);
391  return;
392  case 3:
393  getCellz(Cell, x,1,c, *(ptt2)+binc-coo2->v1);
394  return;
395  }
396  }
397  return;
398 }
399 
401 
412 bool * DTGrid3Dex::getCell(bool * Cell, int a, int b, int c){
413 
414  short skey1;
415  int ainc = a+1;
416  int countdown_1 = proj2D->proj1D->set_countdown_1;
417 
418  typename ArrayPrs <int>::PairArray ** ptt1 = proj2D->proj1D->Ptr_List_1D->PtrArray;
419  typename ArrayPrs <int>::PairArray * coo1 = proj2D->proj1D->Xcoord_List->PArray;
420 
421  for (;countdown_1>0;countdown_1--){
422  skey1 = a>=coo1->v1 ? (ainc<=coo1->v2 ? 1 : (a<=coo1->v2 ? 2 : 0) ) : (ainc>=coo1->v1 ? (ainc<=coo1->v2 ? 3 : 0) : 0);
423  switch (skey1)
424  {
425  case 0:
426  ++ptt1;
427  ++coo1;
428  break;
429  case 1:
430  getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
431  getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
432  return Cell;
433  case 2:
434  getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
435  return Cell;
436  case 3:
437  getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
438  return Cell;
439  }
440  }
441  return Cell;
442 }
443 
445 
454 bool * DTGrid3Dex::getCell2(bool * Cell, int a, int b, int c){
455 
456  short skey1;
457  int ainc = a+1;
458 
459  typename ArrayPrs <int>::PairArray ** ptt1 = proj2D->proj1D->Ptr_List_1D->PtrArray;
460  typename ArrayPrs <int>::PairArray * coo1 = proj2D->proj1D->Xcoord_List->PArray;
461 
462  skey1 = a>=coo1->v1 ? (ainc<=coo1->v2 ? 1 : (a<=coo1->v2 ? 2 : 0) ) : (ainc>=coo1->v1 ? (ainc<=coo1->v2 ? 3 : 0) : 0);
463  switch (skey1)
464  {
465  case 1:
466  getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
467  getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
468  return Cell;
469  case 2:
470  getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
471  return Cell;
472  case 3:
473  getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
474  return Cell;
475  default:
476  return Cell;
477  }
478 }
479 
481 
486 {
487  std::ifstream file_bt;
488  file_bt.open(Input, std::ifstream::in | std::ifstream::binary);
489 
490  int flag;
491  file_bt.read((char *) &flag, sizeof(int));
492 
493  //Read the first 120 characters
494  char * buffer = new char [120];
495  file_bt.read(buffer, 120);
496 
497  char * binary_test;
498  binary_test = (char*) memchr (buffer, '\n', 120);
499 
500  if (flag == 160){
501  //Binary file
502  std::cout << "Test format dtgrid: No return statement, binary zeros found" << std::endl;
503  std::cout << "The file was detected to be of type binary" << std::endl;
504  iform = 0;
505  }
506  else{
507  if (binary_test == NULL) { // NO return statement
508  binary_test = (char*) memchr (buffer, '\0', 120);
509  if (binary_test == NULL) {
510  //ASCII file
511  std::cout << "Test format dtgrid: No return statement, no binary zeros" << std::endl;
512  std::cout << "The file was detected to be of type ASCII" << std::endl;
513  iform = 1;
514  }
515  else{
516  //Binary file
517  std::cout << "Test format dtgrid: No return statement, binary zeros found" << std::endl;
518  std::cout << "The file was detected to be of type binary" << std::endl;
519  iform = 0;
520  }
521  }
522  else{
523  //ASCII file
524  std::cout << "Test format dtgrid: Return statement found" << std::endl;
525  std::cout << "The file was detected to be of type ASCII" << std::endl;
526  iform = 1;
527  }
528  }
529  file_bt.close();
530  delete[] buffer;
531 }
532 
534 
542 void DTGrid3Dex::format_binary(char * file_binary)
543 {
544  std::ifstream dtgrid_file;
545  dtgrid_file.open(file_binary, std::ifstream::in | std::ifstream::binary);
546 
547  float sc, sp, ox, oy, oz, fval;
548  int dimi, dimj, dimk, ival, flag_binary, flag_grid_type;
549 
550  //uhbd header parameters
551  dtgrid_file.read((char *) &flag_binary, sizeof(int));
552  uhbd.Title = new char [72];
553  dtgrid_file.read(uhbd.Title, 72);
554  dtgrid_file.read((char *) &uhbd.scale, sizeof(float));
555  dtgrid_file.read((char *) &uhbd.dummy1, sizeof(float));
556  dtgrid_file.read((char *) &uhbd.grdflag, sizeof(int));
557  dtgrid_file.read((char *) &uhbd.idummy1, sizeof(int));
558  dtgrid_file.read((char *) &uhbd.idummy2, sizeof(int));
559  dtgrid_file.read((char *) &uhbd.one, sizeof(int));
560  dtgrid_file.read((char *) &uhbd.idummy3, sizeof(int));
561  dtgrid_file.read((char *) &uhbd.dim.i, sizeof(int));
562  dtgrid_file.read((char *) &uhbd.dim.j, sizeof(int));
563  dtgrid_file.read((char *) &uhbd.dim.k, sizeof(int));
564  dtgrid_file.read((char *) &uhbd.spacing, sizeof(float));
565  dtgrid_file.read((char *) &uhbd.o.x, sizeof(float));
566  dtgrid_file.read((char *) &uhbd.o.y, sizeof(float));
567  dtgrid_file.read((char *) &uhbd.o.z, sizeof(float));
568  dtgrid_file.read((char *) &uhbd.dummy2, sizeof(float));
569  dtgrid_file.read((char *) &uhbd.dummy3, sizeof(float));
570  dtgrid_file.read((char *) &uhbd.dummy4, sizeof(float));
571  dtgrid_file.read((char *) &uhbd.dummy5, sizeof(float));
572  dtgrid_file.read((char *) &uhbd.dummy6, sizeof(float));
573  dtgrid_file.read((char *) &uhbd.dummy7, sizeof(float));
574  dtgrid_file.read((char *) &uhbd.idummy4, sizeof(int));
575  dtgrid_file.read((char *) &uhbd.idummy5, sizeof(int));
576 
577  //DT-Grid header parameters
578  int len_Value, len_xcoord, len_ycoord, len_zcoord;
579  int len_acc, len_acc2, len_acc3, len_projection, len_projection2;
580 
581  dtgrid_file.read((char *) &flag_grid_type, sizeof(int));
582  dtgrid_file.read((char *) &len_Value, sizeof(int));
583  dtgrid_file.read((char *) &len_xcoord, sizeof(int));
584  dtgrid_file.read((char *) &len_ycoord, sizeof(int));
585  dtgrid_file.read((char *) &len_zcoord, sizeof(int));
586  dtgrid_file.read((char *) &len_acc, sizeof(int));
587  dtgrid_file.read((char *) &len_acc2, sizeof(int));
588  dtgrid_file.read((char *) &len_acc3, sizeof(int));
589  dtgrid_file.read((char *) &len_projection, sizeof(int));
590  dtgrid_file.read((char *) &len_projection2, sizeof(int));
591 
592  grid_type = flag_grid_type;
593  if (grid_type == 0)
594  std::cout << "Type of grid: Excluded volume" << std::endl;
595  else if (grid_type == 1)
596  std::cout << "Type of grid: Potential/Energy" << std::endl;
597  else
598  std::cout << "Type of grid: Unknown/Not-Set" << std::endl;
599 
600  std::cout << "DT-Grid Header information: " << std::endl;
601  std::cout << "Length of Value array:\t" << len_Value << std::endl;
602  std::cout << "Length of xCoord array:\t" << len_xcoord<< std::endl;
603  std::cout << "Length of yCoord array:\t" << len_ycoord << std::endl;
604  std::cout << "Length of zCoord array:\t" << len_zcoord << std::endl;
605  std::cout << "Length of acc1D array:\t" << len_acc << std::endl;
606  std::cout << "Length of acc2D array:\t" << len_acc2 << std::endl;
607  std::cout << "Length of acc3D array:\t" << len_acc3 << std::endl;
608  std::cout << "Length of proj1D array:\t" << len_projection << std::endl;
609  std::cout << "Length of proj2D array:\t" << len_projection2 << std::endl << std::endl;
610 
611  int dtgrid_size;
612  dtgrid_size = sizeof(int) * (len_xcoord + len_ycoord + len_zcoord + \
613  len_acc + len_acc2 + len_acc3) + sizeof(int *) * (len_projection + len_projection2);
614  size_ds(dtgrid_size);
615 
616  //dtgrid main body
617  int * zcoord;
618  zcoord = new int [len_zcoord];
619  for (int i=0;i<len_zcoord;i++){
620  dtgrid_file.read((char *) &ival, sizeof(int));
621  zcoord[i] = (int) ival;
622  }
623 
624  int * acc;
625  acc = new int [len_acc];
626  for (int i=0;i<len_acc;i++){
627  dtgrid_file.read((char *) &ival, sizeof(int));
628  acc[i] = (int) ival;
629  }
630 
631  int * projection;
632  projection = new int [len_projection];
633  for (int i=0;i<len_projection;i++){
634  dtgrid_file.read((char *) &ival, sizeof(int));
635  projection[i] = (int) ival;
636  }
637 
638  int * ycoord;
639  ycoord = new int [len_ycoord];
640  for (int i=0;i<len_ycoord;i++){
641  dtgrid_file.read((char *) &ival, sizeof(int));
642  ycoord[i] = (int) ival;
643  }
644 
645  int * acc2;
646  acc2 = new int [len_acc2];
647  for (int i=0;i<len_acc2;i++){
648  dtgrid_file.read((char *) &ival, sizeof(int));
649  acc2[i] = (int) ival;
650  }
651 
652  int * projection2;
653  projection2 = new int [len_projection2];
654  for (int i=0;i<len_projection2;i++){
655  dtgrid_file.read((char *) &ival, sizeof(int));
656  projection2[i] = (int) ival;
657  }
658 
659  int * xcoord;
660  xcoord = new int [len_xcoord];
661  for (int i=0;i<len_xcoord;i++){
662  dtgrid_file.read((char *) &ival, sizeof(int));
663  xcoord[i] = (int) ival;
664  }
665 
666  int * acc3;
667  acc3 = new int [len_acc3];
668  for (int i=0;i<len_acc3;i++){
669  dtgrid_file.read((char *) &ival, sizeof(int));
670  acc3[i] = (int) ival;
671  }
672 
673  // Initialization of the grid object
674  set_uhbd_parameters(uhbd.scale, uhbd.spacing, uhbd.o.x, uhbd.o.y, \
675  uhbd.o.z, uhbd.dim.i, uhbd.dim.j, uhbd.dim.k);
676  set_zcoord_list(zcoord,len_zcoord);
677  set_projection2D(projection,ycoord,acc2,projection2,xcoord,acc3,len_projection, \
678  len_ycoord,len_acc2,len_projection2,len_xcoord,len_acc3);
679 
680  delete[] zcoord;
681  delete[] acc;
682  delete[] projection;
683  delete[] ycoord;
684  delete[] acc2;
685  delete[] projection2;
686  delete[] xcoord;
687  delete[] acc3;
688 
689  dtgrid_file.close();
690 }
691 
693 
699 void DTGrid3Dex::format_ascii(char * file_ascii)
700 {
701  std::ifstream dtgrid_file;
702  dtgrid_file.open(file_ascii, std::ifstream::in);
703 
704  std::string title_str, line;
705  std::string scale_str, dum1_str, grdflag_str, idum1_str, idum2_str, one_str, idum3_str;
706  std::string i_str, j_str, k_str;
707  std::string spacing_str, ox_str, oy_str, oz_str;
708  std::string dum2_str, dum3_str, dum4_str, dum5_str;
709  std::string dum6_str, dum7_str, idum4_str, idum5_str;
710 
711  bool fval;
712  int ival;
713  int flag_grid_type;
714  int len_Value, len_xcoord, len_ycoord, len_zcoord;
715  int len_acc, len_acc2, len_acc3, len_projection, len_projection2;
716 
717  //DTGrid (UHBD) Title
718  getline(dtgrid_file,line);
719  title_str = line.substr(0,72);
720 
721  //uhbd header parameters
722  getline(dtgrid_file,line);
723  scale_str = line.substr(0,12);
724  dum1_str = line.substr(12,12);
725  grdflag_str = line.substr(24,7);
726  idum1_str = line.substr(31,7);
727  idum2_str = line.substr(38,7);
728  one_str = line.substr(45,7);
729  idum3_str = line.substr(52,7);
730  getline(dtgrid_file,line);
731  i_str = line.substr(0,7);
732  j_str = line.substr(7,7);
733  k_str = line.substr(14,7);
734  spacing_str = line.substr(21,12);
735  ox_str = line.substr(33,12);
736  oy_str = line.substr(45,12);
737  oz_str = line.substr(57,12);
738  getline(dtgrid_file,line);
739  dum2_str = line.substr(0,12);
740  dum3_str = line.substr(12,12);
741  dum4_str = line.substr(24,12);
742  dum5_str = line.substr(36,12);
743  getline(dtgrid_file,line);
744  dum6_str = line.substr(0,12);
745  dum7_str = line.substr(12,12);
746  idum4_str = line.substr(24,7);
747  idum5_str = line.substr(31,7);
748 
749  //
750  uhbd.Title = new char [72];
751  std::strncpy (uhbd.Title, title_str.c_str(), 72);
752 
753  std::stringstream (scale_str) >> uhbd.scale;
754  std::stringstream (dum1_str) >> uhbd.dummy1;
755  std::stringstream (grdflag_str) >> uhbd.grdflag;
756  std::stringstream (idum1_str) >> uhbd.idummy1;
757  std::stringstream (idum2_str) >> uhbd.idummy2;
758  std::stringstream (one_str) >> uhbd.one;
759  std::stringstream (idum3_str) >> uhbd.idummy3;
760  std::stringstream (i_str) >> uhbd.dim.i;
761  std::stringstream (j_str) >> uhbd.dim.j;
762  std::stringstream (k_str) >> uhbd.dim.k;
763  std::stringstream (spacing_str) >> uhbd.spacing;
764  std::stringstream (ox_str) >> uhbd.o.x;
765  std::stringstream (oy_str) >> uhbd.o.y;
766  std::stringstream (oz_str) >> uhbd.o.z;
767  std::stringstream (dum2_str) >> uhbd.dummy2;
768  std::stringstream (dum3_str) >> uhbd.dummy3;
769  std::stringstream (dum4_str) >> uhbd.dummy4;
770  std::stringstream (dum5_str) >> uhbd.dummy5;
771  std::stringstream (dum6_str) >> uhbd.dummy6;
772  std::stringstream (dum7_str) >> uhbd.dummy7;
773  std::stringstream (idum4_str) >> uhbd.idummy4;
774  std::stringstream (idum5_str) >> uhbd.idummy5;
775 
776 
777  //dtgrid header parameters
778  dtgrid_file >> flag_grid_type;
779  dtgrid_file >> len_Value;
780  dtgrid_file >> len_xcoord;
781  dtgrid_file >> len_ycoord;
782  dtgrid_file >> len_zcoord;
783  dtgrid_file >> len_acc;
784  dtgrid_file >> len_acc2;
785  dtgrid_file >> len_acc3;
786  dtgrid_file >> len_projection;
787  dtgrid_file >> len_projection2;
788 
789  grid_type = flag_grid_type;
790  if (grid_type == 0)
791  std::cout << "Type of grid: Excluded volume" << std::endl;
792  else if (grid_type == 1)
793  std::cout << "Type of grid: Potential/Energy" << std::endl;
794  else
795  std::cout << "Type of grid: Unknown/Not-Set" << std::endl;
796 
797  std::cout << "DT-Grid Header information: " << std::endl;
798  std::cout << "Length of Value array:\t" << len_Value << std::endl;
799  std::cout << "Length of xCoord array:\t" << len_xcoord<< std::endl;
800  std::cout << "Length of yCoord array:\t" << len_ycoord << std::endl;
801  std::cout << "Length of zCoord array:\t" << len_zcoord << std::endl;
802  std::cout << "Length of acc1D array:\t" << len_acc << std::endl;
803  std::cout << "Length of acc2D array:\t" << len_acc2 << std::endl;
804  std::cout << "Length of acc3D array:\t" << len_acc3 << std::endl;
805  std::cout << "Length of proj1D array:\t" << len_projection << std::endl;
806  std::cout << "Length of proj2D array:\t" << len_projection2 << std::endl << std::endl;
807 
808  unsigned int dtgrid_size;
809  dtgrid_size = sizeof(int) * (len_xcoord + len_ycoord + len_zcoord + \
810  len_acc + len_acc2 + len_acc3) + sizeof(int *) * (len_projection + len_projection2);
811  size_ds(dtgrid_size);
812 
813  //dtgrid main body
814  int * zcoord;
815  zcoord = new int [len_zcoord];
816  for (int i=0;i<len_zcoord;i++){
817  dtgrid_file >> ival;
818  zcoord[i] = ival;
819  }
820 
821  int * acc;
822  acc = new int [len_acc];
823  for (int i=0;i<len_acc;i++){
824  dtgrid_file >> ival;
825  acc[i] = ival;
826  }
827 
828  int * projection;
829  projection = new int [len_projection];
830  for (int i=0;i<len_projection;i++){
831  dtgrid_file >> ival;
832  projection[i] = ival;
833  }
834 
835  int * ycoord;
836  ycoord = new int [len_ycoord];
837  for (int i=0;i<len_ycoord;i++){
838  dtgrid_file >> ival;
839  ycoord[i] = ival;
840  }
841 
842  int * acc2;
843  acc2 = new int [len_acc2];
844  for (int i=0;i<len_acc2;i++){
845  dtgrid_file >> ival;
846  acc2[i] = ival;
847  }
848 
849  int * projection2;
850  projection2 = new int [len_projection2];
851  for (int i=0;i<len_projection2;i++){
852  dtgrid_file >> ival;
853  projection2[i] = ival;
854  }
855 
856  int * xcoord;
857  xcoord = new int [len_xcoord];
858  for (int i=0;i<len_xcoord;i++){
859  dtgrid_file >> ival;
860  xcoord[i] = ival;
861  }
862 
863  int * acc3;
864  acc3 = new int [len_acc3];
865  for (int i=0;i<len_acc3;i++){
866  dtgrid_file >> ival;
867  acc3[i] = ival;
868  }
869 
870  // Initialization of the grid object
871  set_uhbd_parameters(uhbd.scale, uhbd.spacing, uhbd.o.x, uhbd.o.y, \
872  uhbd.o.z, uhbd.dim.i, uhbd.dim.j, uhbd.dim.k);
873  set_zcoord_list(zcoord,len_zcoord);
874  set_projection2D(projection,ycoord,acc2,projection2,xcoord,acc3,len_projection, \
875  len_ycoord,len_acc2,len_projection2,len_xcoord,len_acc3);
876  delete[] zcoord;
877  delete[] acc;
878  delete[] projection;
879  delete[] ycoord;
880  delete[] acc2;
881  delete[] projection2;
882  delete[] xcoord;
883  delete[] acc3;
884 
885  dtgrid_file.close();
886 }
887 
889 
892 void DTGrid3Dex::size_ds(unsigned int val)
893 {
894  float dtgrid_size;
895  int kb, mb, gb;
896 
897  kb = 1024;
898  mb = 1024 * 1024;
899  gb = 1024 * 1024 * 1024;
900 
901  if ((val / gb) > 1) {
902  dtgrid_size = (float) val / (float) gb;
903  std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " GB" << std::endl;
904  }
905  else {
906  if ((val / mb) > 1) {
907  dtgrid_size = (float) val / (float) mb;
908  std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " MB" << std::endl;
909  }
910  else {
911  dtgrid_size = (float) val / (float) kb;
912  std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " KB" << std::endl;
913  }
914  }
915 }
916 
917 #endif /* DTGRID3DEX_HPP_ */
Define the array for storing pairs of indices.
Define the array for storing pointers into ArrayPrs.
Define arrays of regular type used in any of the DT-Grid layers.
Define 2D DT-Grid class and group its functions.
PairArray * PArray
Definition: ArrayPrs.hpp:51
void Set_Pair_Array_Values(K *, int)
Setup the array that stores the complete icoord values.
Definition: ArrayPrs.hpp:74
ArrayPrs< K >::PairArray ** PtrArray
Definition: ArrayPtr.hpp:45
void set_projection1D(K *, K *, K *, int, int, int)
proj2D setup
Definition: DTGrid2D.hpp:126
ArrayPrs< K >::PairArray * accessxy(int, int)
Reset pointers that temporarily store addresses for random access. Similar to that for DT-Grid3D.
Definition: DTGrid2D.hpp:153
ArrayPrs< K > * Ycoord_List
Definition: DTGrid2D.hpp:24
ArrayPtr< T, K > * Ptr_List_2D
Definition: DTGrid2D.hpp:25
DTGrid1D< T, K > * proj1D
Definition: DTGrid2D.hpp:27
void set_ptr_list_2D(K *, int)
acc (2D) array setup
Definition: DTGrid2D.hpp:109
void set_ycoord_list(K *, int)
yCoord array setup
Definition: DTGrid2D.hpp:96
void set_value_list_2D(K *, int)
DTGrid2D 'value' array setup.
Definition: DTGrid2D.hpp:83
Definition: DTGrid3Dex.hpp:73
int one
Definition: DTGrid3Dex.hpp:130
float z
Definition: DTGrid3Dex.hpp:110
~DTGrid3Dex()
DTGrid3Dex destructor.
Definition: DTGrid3Dex.hpp:170
struct DTGrid3Dex::@5::origin o
bool * getCell2(bool *, int, int, int)
Random access to grid cells. (2nd version)
Definition: DTGrid3Dex.hpp:454
struct DTGrid3Dex::@5 uhbd
UHBD header information.
void format_binary(char *)
Open and Read the binary grid file.
Definition: DTGrid3Dex.hpp:542
int idummy5
Definition: DTGrid3Dex.hpp:135
void set_zcoord_list(int *, int)
zCoord array setup
Definition: DTGrid3Dex.hpp:201
float dummy7
Definition: DTGrid3Dex.hpp:144
char * Title
Definition: DTGrid3Dex.hpp:128
int idummy1
Definition: DTGrid3Dex.hpp:131
struct DTGrid3Dex::@5::dimensions dim
DTGrid3Dex(char *)
DTGrid3Dex constructor.
Definition: DTGrid3Dex.hpp:179
float spacing
not used for data scaling
Definition: DTGrid3Dex.hpp:97
float y
Definition: DTGrid3Dex.hpp:109
int idummy4
Definition: DTGrid3Dex.hpp:134
int i
Definition: DTGrid3Dex.hpp:101
void getCellyz(bool *, int, int, int, typename ArrayPrs< int >::PairArray *)
Random access function for grid cells (y direction, DTGrid2D).
Definition: DTGrid3Dex.hpp:360
int Length_of_Value_List_3D
Definition: DTGrid3Dex.hpp:86
int grdflag
Definition: DTGrid3Dex.hpp:129
void size_ds(unsigned int)
Estimate the grid file size.
Definition: DTGrid3Dex.hpp:892
int idummy3
Definition: DTGrid3Dex.hpp:133
struct DTGrid3Dex::@4 origin
hold the coordinates (in x, y and z) of the grid origin.
void set_uhbd_parameters(float, float, float, float, float, int, int, int)
Read and set the grid parameters.
Definition: DTGrid3Dex.hpp:246
int iform
grid file format: binary = 0; ascii = 1
Definition: DTGrid3Dex.hpp:91
void Reset_pointers_3D(void)
void set_projection2D(int *, int *, int *, int *, int *, int *, int, int, int, int, int, int)
proj2D setup
Definition: DTGrid3Dex.hpp:223
int k
Definition: DTGrid3Dex.hpp:103
float dummy6
Definition: DTGrid3Dex.hpp:143
struct DTGrid3Dex::@3 dimensions
grid resolution
float dummy2
Definition: DTGrid3Dex.hpp:139
void getCellz(bool *, int, int, int, typename ArrayPrs< int >::PairArray *)
Random access to grid cells in z direction.
Definition: DTGrid3Dex.hpp:317
int Length_of_Ptr_List_3D
Definition: DTGrid3Dex.hpp:88
void format_ascii(char *)
Open and Read the ascii grid file.
Definition: DTGrid3Dex.hpp:699
int idummy2
Definition: DTGrid3Dex.hpp:132
float dummy3
Definition: DTGrid3Dex.hpp:140
float scale
Definition: DTGrid3Dex.hpp:96
void test_format_dtgrid(char *)
Determine the DT-Grid file format.
Definition: DTGrid3Dex.hpp:485
float dummy5
Definition: DTGrid3Dex.hpp:142
float dummy1
Definition: DTGrid3Dex.hpp:138
bool * getCell(bool *, int, int, int)
Random access to grid cells.
Definition: DTGrid3Dex.hpp:412
int grid_type
grid type: exclusion grid = 0; normal grid = 1
Definition: DTGrid3Dex.hpp:94
ArrayReg< bool > * Value_List_3D
Definition: DTGrid3Dex.hpp:80
int Length_of_Zcoord_List
Definition: DTGrid3Dex.hpp:87
int j
Definition: DTGrid3Dex.hpp:102
bool accessxyz(int, int, int)
Random access function.
Definition: DTGrid3Dex.hpp:273
float dummy4
Definition: DTGrid3Dex.hpp:141
float x
Definition: DTGrid3Dex.hpp:108
ArrayPrs< int > * Zcoord_List
Definition: DTGrid3Dex.hpp:81
DTGrid2D< bool, int > * proj2D
Definition: DTGrid3Dex.hpp:84
ArrayPtr< bool, int > * Ptr_List_3D
Definition: DTGrid3Dex.hpp:82
real(kind=8), parameter c
Definition: mod_gouy_chapman.f90:39
Imprint/Privacy