SDA (SDA flex)  7.2
Simulation of Diffusional Association
Loading...
Searching...
No Matches
DTGrid3D.hpp
Go to the documentation of this file.
1
48#ifndef DTGRID3D_HPP_
49#define DTGRID3D_HPP_
50//
51#include <stdlib.h>
52#include <string.h>
53#include <cstring>
54#include <iostream>
55#include <fstream>
56#include <sstream>
57#include <typeinfo>
58//
59#include "ArrayReg.hpp"
60#include "ArrayPtr.hpp"
61#include "ArrayPrs.hpp"
62#include "DTGrid2D.hpp"
63
64template<typename T,typename K>
65class DTGrid3D {
66public:
67 DTGrid3D(char *, T, T);
68 ~DTGrid3D();
69
70private:
71
75
77
81
84
86 int iform;
87
90
92 float scale;
93 float spacing;
94
97
98 /*
99 typename ArrayPrs <K>::PairArray * coord3;
100 T ** ptt3;
101 typename ArrayPrs <K>::PairArray * coo3;
102 bool key3;
103 short skey1;
104 short skey2;
105 short skey3;
106 K checkpoint_31;
107 K checkpoint_32;
108 K countdown_3;
109 */
110
112 struct {
113 int i;
114 int j;
115 int k;
117
119 struct {
120 float x;
121 float y;
122 float z;
124
125 //
126 void set_value_list_3D(T*,int);
127 void set_zcoord_list(K*,int);
128 void set_ptr_list_3D(K*,int);
129 void set_gamma_values(T, T);
130 void set_projection2D(K*, K*, K*, K*, K*, K*, int, int, int, int, int, int);
131 void set_uhbd_parameters(float, float, float, float, float, int, int, int);
133
134 //
135 void test_format_dtgrid(char *);
136 void size_ds(unsigned int);
137 void format_ascii(char *);
138 void format_binary(char *);
139
140public:
142 struct {
143 char * Title;
145 int one;
151 float scale;
152 float spacing;
153 float dummy1;
154 float dummy2;
155 float dummy3;
156 float dummy4;
157 float dummy5;
158 float dummy6;
159 float dummy7;
160 struct dimensions
161 {
162 int i;
163 int j;
164 int k;
166 struct origin
167 {
168 float x;
169 float y;
170 float z;
173 T accessxyz(int, int, int);
174 bool excl_accessxyz(int, int, int);
175 T access_fast(int, int, int);
176 T * getCell(T *, int, int, int);
177 T * getCell2(T *, int, int, int);
178
179 int type_of_grid (void) {return grid_type;}
180protected:
181
182 //template <class M, class H>
183 //friend class DTGrid2D;
184 //template <class M, class H>
185 //friend class DTGrid1D;
186
187 void getCellz(T *, int, int, int, typename ArrayPrs <K>::PairArray *);
188 void getCellyz(T *, int, int, int, typename ArrayPrs <K>::PairArray *);
189
190 T access_fast_z(int, typename ArrayPrs <K>::PairArray *);
191 T access_fast_yz(int, int, typename ArrayPrs <K>::PairArray *);
192
193};
195template <typename T, typename K>
197
198 if (grid_type == 0){
199 delete proj2D;
200 delete Zcoord_List;
201 }
202 else if (grid_type == 1){
203 delete proj2D;
204 delete Value_List_3D;
205 delete Zcoord_List;
206 delete Ptr_List_3D;
207 }
208 else{
209 // Undefined
210 }
211
212}
213
215
220template <typename T, typename K>
222 scfct = scfct_i;
225 if (iform == 0)
227 else if (iform == 1)
229 else{
230 std::cout << "Error: Unknown file format" << std::endl;
231 exit(0);
232 }
233}
234
236
242template <typename T, typename K>
244 if (grid_type == 0){
245 // No values. All True if grid_type = 0
247 }
248 else if (grid_type == 1){
249 Value_List_3D = new (std::nothrow) ArrayReg <T>;
250 Value_List_3D->Set_Regular_Array_Values(values,length);
252 }
253 else{
254 // Undefined
255 }
256}
257
259
264template <typename T, typename K>
266 Zcoord_List = new (std::nothrow) ArrayPrs <K>;
267 Zcoord_List->Set_Pair_Array_Values(values,length);
268 Length_of_Zcoord_List = length;
269}
270
272
277template <typename T, typename K>
279 if (grid_type == 0){
280 // No values. All True if grid_type = 0
282 }
283 else if (grid_type == 1){
284 Ptr_List_3D = new (std::nothrow) ArrayPtr <T,K>;
285 Ptr_List_3D->Set_Pointer_Array_Values(Value_List_3D->Array,values,Length_of_Value_List_3D,length);
286 Length_of_Ptr_List_3D = length;
287 }
288 else{
289 // Undefined
290 }
291}
292
294
309template <typename T, typename K>
311 K* values4, K* values5, K* values6, int length1, int length2, \
312 int length3, int length4, int length5, int length6){
313
314 proj2D = new (std::nothrow) DTGrid2D <T,K>;
315 proj2D->set_value_list_2D(values1,length1);
316 proj2D->set_ycoord_list(values2,length2);
317 proj2D->set_ptr_list_2D(values3,length3);
318 proj2D->set_projection1D(values4, values5, values6, length4, length5, length6);
319}
320
322
325/*template <typename T, typename K>
326void DTGrid3D<T,K>::Reset_pointers_3D(void){
327 Value_List_3D->Reset_Regular_Array_Values();
328 Zcoord_List->Reset_Set_Pair_Array_Values();
329 Ptr_List_3D->Reset_Set_Pointer_Array_Values();
330 proj2D->Reset_pointers_2D();
331}*/
332
334
345template <typename T, typename K>
346void DTGrid3D<T,K>::set_uhbd_parameters(float sc, float sp, float ox, float oy, float oz, int dimi, int dimj, int dimk){
347 scale = sc;
348 spacing = sp;
349
350 origin.x = ox;
351 origin.y = oy;
352 origin.z = oz;
353
354 dimensions.i = dimi;
355 dimensions.j = dimk;
356 dimensions.k = dimk;
357}
358
360
370template <typename T, typename K>
375
377
390template <typename T, typename K>
391T DTGrid3D<T,K>::access_fast(int a, int b, int c){
392
393 bool key1 = false; // a local logical operation variable.
394
395 int countdown_1 = proj2D->proj1D->set_countdown_1; // a local counter to iterate over the connected components in a tubular grid.
396 typename ArrayPrs <K>::PairArray ** ptt1 = proj2D->proj1D->Ptr_List_1D->PtrArray; // a temporary pointer to store an acc array member.
397 typename ArrayPrs <K>::PairArray * coo1 = proj2D->proj1D->Xcoord_List->PArray; // a temporary pointer to store an xCoord array pair.
398
399 // iterate over the connected components in DTGrid1D
400 for (;countdown_1>0;countdown_1--){
401 // check whether index a is in one of the connected components using the xCoord index array.
402 key1 = a>=coo1->v1 ? (a<=coo1->v2 ? true : false) : false;
403 if (key1 == true){
404 return access_fast_yz(b, c, *(ptt1) + a - coo1->v1);
405 }
406 else {
407 ++ptt1;
408 ++coo1;
409 continue;
410 }
411 }
412 return gamma_o;
413}
414
416
423template <typename T, typename K>
425
426 bool key2 = false; // a local logical operation variable.
427
428 K checkpoint_21 = coord2->v2; // the index of the first connected component in a tubular grid in the yCoord array.
429 K checkpoint_22 = (coord2+1)->v2; // the index of the last connected component in a tubular grid in the yCoord array.
430 K countdown_2 = checkpoint_22 - checkpoint_21; // Determine how many connected components are there in the corresponding tubular grid.
431
432 // Return when no connected component found
433 if (countdown_2 == 0){ return gamma_o;}
434
435 typename ArrayPrs <K>::PairArray ** ptt2 = proj2D->Ptr_List_2D->PtrArray+checkpoint_21; // a temporary pointer to store an acc array member.
436 typename ArrayPrs <K>::PairArray * coo2 = proj2D->Ycoord_List->PArray+checkpoint_21; // a temporary pointer to store an yCoord array pair.
437
438 // iterate over the connected components in DTGrid2D
439 for (; countdown_2 >= 1; countdown_2--){
440 // check whether index b is inside one of the connected components using the yCoord index array.
441 key2 = b>=coo2->v1 ? (b<=coo2->v2 ? true : false) : false;
442 if (key2 == true){
443 return access_fast_z(c, *(ptt2) + b - coo2->v1);
444 }
445 else {
446 ++ptt2;
447 ++coo2;
448 continue;
449 }
450 }
451 // Return if nothing found
452 return gamma_o;
453}
454
456
463template <typename T, typename K>
465
466 bool key3 = false; // a local logical operation variable.
467
468 K checkpoint_31 = coord3->v2; // the index of the first connected component in a tubular grid in the zCoord array.
469 K checkpoint_32 = (coord3+1)->v2; // the index of the last connected component in a tubular grid in the zCoord array.
470 K countdown_3 = checkpoint_32 - checkpoint_31; // Determine how many connected components are there in the corresponding tubular grid (3D).
471
472 if (countdown_3 == 0) return gamma_o;
473
474 T ** ptt3 = Ptr_List_3D->PtrArrayReg+checkpoint_31; // a temporary pointer to store an acc array member.
475 typename ArrayPrs <K>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31; // a temporary pointer to store an zCoord array pair.
476
477 //int count = check;
478 // iterate over the connected components in DTGrid3D
479 for (; countdown_3 >= 1; countdown_3--){
480 // check whether index c is inside one of the connected components using the zCoord index array.
481 key3 = c>=coo3->v1 ? (c<=coo3->v2 ? true : false) : false;
482 if (key3 == true){
483 return *(*(ptt3)+c-coo3->v1);
484 }
485 else {
486 //if (count != 1) {return_type = c<coo3->v1 ? (c>(coo3-1)->v2 ? gamma_i : gamma_o) : gamma_o;}
487 ++ptt3;
488 ++coo3;
489 continue;
490 }
491 }
492 return gamma_o;
493}
494
496
509template <typename T, typename K>
510T DTGrid3D<T,K>::accessxyz(int a, int b, int c){
511
512 // Call the random access function in the DTGrid2D.
513 typename ArrayPrs <K>::PairArray * coord3 = proj2D->accessxy(a,b); // the index of the first connected component in a tubular grid in the zCoord array.
514
515 // Return the default value if recursive function call returns NULL.
516 if (coord3 == NULL) return gamma_o;
517
518 bool key3 = false; // a local logical operation variable.
519 //K return_type = gamma_o;
520
521 K checkpoint_31 = coord3->v2; // the index of the first connected component in a tubular grid in the zCoord array.
522 K checkpoint_32 = (coord3+1)->v2; // the index of the last connected component in a tubular grid in the zCoord array.
523 K countdown_3 = checkpoint_32 - checkpoint_31; // Determine how many connected components are there in the corresponding tubular grid (3D).
524
525 // Return when no connected component found
526 if (countdown_3 == 0) return gamma_o;
527
528 T ** ptt3 = Ptr_List_3D->PtrArrayReg+checkpoint_31; // a temporary pointer to store an acc array member.
529 typename ArrayPrs <K>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31; // a temporary pointer to store an zCoord array pair.
530
531 //int count = check;
532 // iterate over the connected components in DTGrid3D
533 for (; countdown_3 >= 1; countdown_3--){
534 // check whether index c is inside one of the connected components using the zCoord index array.
535 key3 = c>=coo3->v1 ? (c<=coo3->v2 ? true : false) : false;
536 if (key3 == true){
537 return *(*(ptt3)+c-coo3->v1);
538 }
539 else {
540 //if (count != 1) {return_type = c<coo3->v1 ? (c>(coo3-1)->v2 ? gamma_i : gamma_o) : gamma_o;}
541 ++ptt3;
542 ++coo3;
543 continue;
544 }
545 }
546 return gamma_o;
547}
548
550
559/*template <typename T, typename K>
560bool DTGrid3D<T,K>::excl_accessxyz(int a, int b, int c){
561 typename ArrayPrs <K>::PairArray * coord3 = proj2D->accessxy(a,b);
562 if (coord3 == NULL) return false;
563 bool key3 = false;
564 K checkpoint_31 = coord3->v2;
565 K checkpoint_32 = (coord3+1)->v2;
566 K countdown_3 = checkpoint_32 - checkpoint_31;
567 if (countdown_3 == 0) return false;
568 typename ArrayPrs <K>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31;
569 for (; countdown_3 >= 1; countdown_3--){
570 key3 = c>=coo3->v1 ? (c<=coo3->v2 ? true : false) : false;
571 if (key3 == true){
572 return true;
573 }
574 else {
575 ++coo3;
576 continue;
577 }
578 }
579 return false;
580}*/
581
583
591template <typename T, typename K>
592void DTGrid3D<T,K>::getCellz(T * Cell, int x, int y, int c, typename ArrayPrs <K>::PairArray * coord3){
593
594 short skey3; // a local integer variable to identify the grid cell type.
595 int cinc = c+1; // the index of the origin's neighbor in z direction.
596
597 K checkpoint_31 = coord3->v2; // the index of the first connected component in a tubular grid in the zCoord array.
598 K checkpoint_32 = (coord3+1)->v2; // the index of the last connected component in a tubular grid in the zCoord array.
599 K countdown_3 = checkpoint_32 - checkpoint_31; // Determine how many connected components are there in the corresponding tubular grid (3D).
600
601 T ** ptt3 = Ptr_List_3D->PtrArrayReg+checkpoint_31; // a temporary pointer to store an acc array member.
602 typename ArrayPrs <K>::PairArray * coo3 = Zcoord_List->PArray+checkpoint_31; // a temporary pointer to store an zCoord array pair.
603
604 // iterate over the connected components in DTGrid3D
605 for (; countdown_3 >= 1; countdown_3--){
606 // check whether index c (and/or c+1) is inside one of the connected components using the zCoord index array.
607 skey3 = c>=coo3->v1 ? (cinc<=coo3->v2 ? 1 : (c<=coo3->v2 ? 2 : 0) ) : (cinc>=coo3->v1 ? (cinc<=coo3->v2 ? 3 : 0) : 0);
608 switch (skey3)
609 {
610 // Neither c, nor c+1 is inside the connected component.
611 case 0:
612 ++ptt3;
613 ++coo3;
614 break;
615 // Both c and c+1 are inside the connected component.
616 case 1:
617 Cell[4*x+2*y] = *(*(ptt3)+c-coo3->v1);
618 Cell[4*x+2*y+1] = *(*(ptt3)+cinc-coo3->v1);
619 return;
620 // Only c is inside the connected component
621 case 2:
622 Cell[4*x+2*y] = *(*(ptt3)+c-coo3->v1);
623 return;
624 // Only c+1 is inside the connected component
625 case 3:
626 Cell[4*x+2*y+1] = *(*(ptt3)+cinc-coo3->v1);
627 return;
628 }
629 }
630 return;
631}
632
634
642template <typename T, typename K>
643void DTGrid3D<T,K>::getCellyz(T * Cell, int x, int b, int c, typename ArrayPrs <K>::PairArray * coord2){
644
645 short skey2; // a local integer variable to identify the grid cell type.
646 int binc = b+1; // the index of the origin's neighbor in y direction.
647
648 K checkpoint_21 = coord2->v2; // the index of the first connected component in a tubular grid in the yCoord array.
649 K checkpoint_22 = (coord2+1)->v2; // the index of the last connected component in a tubular grid in the yCoord array.
650 K countdown_2 = checkpoint_22 - checkpoint_21; // Determine how many connected components are there in the corresponding tubular grid (2D).
651
652 if (countdown_2 == 0){ return;}
653
654 typename ArrayPrs <K>::PairArray ** ptt2 = proj2D->Ptr_List_2D->PtrArray+checkpoint_21; // a temporary pointer to store an acc array member.
655 typename ArrayPrs <K>::PairArray * coo2 = proj2D->Ycoord_List->PArray+checkpoint_21; // a temporary pointer to store an yCoord array pair.
656
657 // iterate over the connected components in DTGrid2D
658 for (; countdown_2 >= 1; countdown_2--){
659 // check whether index b (and/or b+1) is inside one of the connected components using the yCoord index array.
660 skey2 = b>=coo2->v1 ? (binc<=coo2->v2 ? 1 : (b<=coo2->v2 ? 2 : 0) ) : (binc>=coo2->v1 ? (binc<=coo2->v2 ? 3 : 0) : 0);
661 switch (skey2)
662 {
663 // Neither b, nor b+1 is inside the current connected component.
664 case 0:
665 ++ptt2;
666 ++coo2;
667 break;
668 // Both b and b+1 are inside the connected component.
669 case 1:
670 getCellz(Cell, x,0,c, *(ptt2)+b-coo2->v1);
671 //++b;
672 getCellz(Cell, x,1,c, *(ptt2)+binc-coo2->v1);
673 return;
675 case 2:
676 getCellz(Cell, x,0,c, *(ptt2)+b-coo2->v1);
677 return;
679 case 3:
680 getCellz(Cell, x,1,c, *(ptt2)+binc-coo2->v1);
681 return;
682 }
683 }
684 return;
685}
686
688
699template <typename T, typename K>
700T * DTGrid3D<T,K>::getCell(T * Cell, int a, int b, int c){
701
702 short skey1; // a local integer variable to identify the grid cell type.
703 int ainc = a+1; // the index of the origin's neighbor in x direction.
704 int countdown_1 = proj2D->proj1D->set_countdown_1; // Determine how many connected components are there in the corresponding tubular grid (1D).
705
706 typename ArrayPrs <K>::PairArray ** ptt1 = proj2D->proj1D->Ptr_List_1D->PtrArray; // a temporary pointer to store an acc array member.
707 typename ArrayPrs <K>::PairArray * coo1 = proj2D->proj1D->Xcoord_List->PArray; // a temporary pointer to store an xCoord array pair.
708
709 // iterate over the connected components in DTGrid1D
710 for (;countdown_1>0;countdown_1--){
711 // check whether index a (and/or a+1) is inside one of the connected components using the xCoord index array.
712 skey1 = a>=coo1->v1 ? (ainc<=coo1->v2 ? 1 : (a<=coo1->v2 ? 2 : 0) ) : (ainc>=coo1->v1 ? (ainc<=coo1->v2 ? 3 : 0) : 0);
713 switch (skey1)
714 {
715 // Neither a, nor a+1 is inside the connected component.
716 case 0:
717 ++ptt1;
718 ++coo1;
719 break;
720 // Both a and a+1 are inside the connected component.
721 case 1:
722 getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
723 getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
724 return Cell;
725 // Only a is inside the connected component
726 case 2:
727 getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
728 return Cell;
729 // Only a+1 is inside the connected component
730 case 3:
731 getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
732 return Cell;
733 }
734 }
735 return Cell;
736}
737
739
748template <typename T, typename K>
749T * DTGrid3D<T,K>::getCell2(T * Cell, int a, int b, int c){
750
751 short skey1; // a local integer variable to identify the grid cell type.
752 int ainc = a+1; // the index of the origin's neighbor in x direction.
753
754 typename ArrayPrs <K>::PairArray ** ptt1 = proj2D->proj1D->Ptr_List_1D->PtrArray; // a temporary pointer to store an acc array member.
755 typename ArrayPrs <K>::PairArray * coo1 = proj2D->proj1D->Xcoord_List->PArray; // a temporary pointer to store an xCoord array pair.
756
757 // check whether index a (and/or a+1) is inside one of the connected components using the xCoord index array.
758 skey1 = a>=coo1->v1 ? (ainc<=coo1->v2 ? 1 : (a<=coo1->v2 ? 2 : 0) ) : (ainc>=coo1->v1 ? (ainc<=coo1->v2 ? 3 : 0) : 0);
759 switch (skey1)
760 {
761 // Both a and a+1 are inside the connected component.
762 case 1:
763 getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
764 getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
765 return Cell;
766 // Only a is inside the connected component
767 case 2:
768 getCellyz(Cell, 0,b,c, *(ptt1) + a - coo1->v1);
769 return Cell;
770 // Only a+1 is inside the connected component
771 case 3:
772 getCellyz(Cell, 1,b,c, *(ptt1) + ainc - coo1->v1);
773 return Cell;
774 default:
775 return Cell;
776 }
777}
778
780
784template <typename T, typename K>
786{
787 std::ifstream file_bt;
788 file_bt.open(Input, std::ifstream::in | std::ifstream::binary);
789
790 int flag; // flag variable, binary or ASCII?
791 file_bt.read((char *) &flag, sizeof(int));
792
793 char * buffer = new char [120]; // Read the first 120 characters
794 file_bt.read(buffer, 120);
795
796 char * binary_test; // check if buffer contains a return character
797 binary_test = (char*) memchr (buffer, '\n', 120);
798
800 if (flag == 160){
801 iform = 0; // Binary file
802 std::cout << "Test format DT-Grid: No return statement, binary zeros found" << std::endl;
803 std::cout << "The file was detected to be of type binary" << std::endl;
804 }
805 else{
806 if (binary_test == NULL) { // NO return statement found in the buffer
807 binary_test = (char*) memchr (buffer, '\0', 120); // check if there is a null termination character.
808 if (binary_test == NULL){
809 iform = 1; // ASCII file
810 std::cout << "Test format DT-Grid: No return statement, no binary zeros" << std::endl;
811 std::cout << "The file was detected to be of type ASCII" << std::endl;
812 }
813 else{
814 iform = 0; // Binary file
815 std::cout << "Test format DT-Grid: No return statement, binary zeros found" << std::endl;
816 std::cout << "The file was detected to be of type binary" << std::endl;
817 }
818 }
819 else{
820 iform = 1; // ASCII file
821 std::cout << "Test format DT-Grid: Return statement found" << std::endl;
822 std::cout << "The file was detected to be of type ASCII" << std::endl;
823 }
824 }
825 file_bt.close();
826 delete[] buffer;
827}
828
830
838template <typename T, typename K>
840{
841 std::ifstream dtgrid_file;
842 dtgrid_file.open(file_binary, std::ifstream::in | std::ifstream::binary);
843
844 float sc; // scaling factor
845 float sp; // grid spacing
846 float ox, oy, oz; // origin coordinates
847 float fval; // local variable to store float values temporarily
848 int dimi, dimj, dimk; // grid dimensions
849 int ival; // local variable to store int values temporarily
850 int flag_binary; // the first integer stored in a dt-grid (or UHBD) binary file.
851 int flag_grid_type; // excluded volume (0) / potential (1)
852
853 // DT-Grid/UHBD header parameters
854 //
855 dtgrid_file.read((char *) &flag_binary, sizeof(int));
856 uhbd.Title = new char [72];
857 dtgrid_file.read(uhbd.Title, 72); // content description upto 72 characters.
858 dtgrid_file.read((char *) &uhbd.scale, sizeof(float));
859 dtgrid_file.read((char *) &uhbd.dummy1, sizeof(float)); // float dummy. value type not assigned.
860 dtgrid_file.read((char *) &uhbd.grdflag, sizeof(int));
861 dtgrid_file.read((char *) &uhbd.idummy1, sizeof(int)); // integer dummy. value type not assigned.
862 dtgrid_file.read((char *) &uhbd.idummy2, sizeof(int));
863 dtgrid_file.read((char *) &uhbd.one, sizeof(int));
864 dtgrid_file.read((char *) &uhbd.idummy3, sizeof(int));
865 dtgrid_file.read((char *) &uhbd.dim.i, sizeof(int));
866 dtgrid_file.read((char *) &uhbd.dim.j, sizeof(int));
867 dtgrid_file.read((char *) &uhbd.dim.k, sizeof(int));
868 dtgrid_file.read((char *) &uhbd.spacing, sizeof(float));
869 dtgrid_file.read((char *) &uhbd.o.x, sizeof(float));
870 dtgrid_file.read((char *) &uhbd.o.y, sizeof(float));
871 dtgrid_file.read((char *) &uhbd.o.z, sizeof(float));
872 dtgrid_file.read((char *) &uhbd.dummy2, sizeof(float));
873 dtgrid_file.read((char *) &uhbd.dummy3, sizeof(float));
874 dtgrid_file.read((char *) &uhbd.dummy4, sizeof(float));
875 dtgrid_file.read((char *) &uhbd.dummy5, sizeof(float));
876 dtgrid_file.read((char *) &uhbd.dummy6, sizeof(float));
877 dtgrid_file.read((char *) &uhbd.dummy7, sizeof(float));
878 dtgrid_file.read((char *) &uhbd.idummy4, sizeof(int));
879 dtgrid_file.read((char *) &uhbd.idummy5, sizeof(int));
880
881 // DT-Grid header parameters
882 // Length of each of the DT-Grid data structure arrays
885
886 // Read the array size from DT-Grid file
887 dtgrid_file.read((char *) &flag_grid_type, sizeof(int));
888 dtgrid_file.read((char *) &len_Value, sizeof(int));
889 dtgrid_file.read((char *) &len_xcoord, sizeof(int));
890 dtgrid_file.read((char *) &len_ycoord, sizeof(int));
891 dtgrid_file.read((char *) &len_zcoord, sizeof(int));
892 dtgrid_file.read((char *) &len_acc, sizeof(int));
893 dtgrid_file.read((char *) &len_acc2, sizeof(int));
894 dtgrid_file.read((char *) &len_acc3, sizeof(int));
895 dtgrid_file.read((char *) &len_projection, sizeof(int));
896 dtgrid_file.read((char *) &len_projection2, sizeof(int));
897
899 if (grid_type == 0)
900 std::cout << "Type of grid: Excluded volume" << std::endl;
901 else if (grid_type == 1)
902 std::cout << "Type of grid: Potential/Energy" << std::endl;
903 else
904 std::cout << "Type of grid: Unknown/Not-Set" << std::endl;
905
906 // The following block verbose. Informative but necessary to print every time?
907 std::cout << "DT-Grid Header information: " << std::endl;
908 std::cout << "Length of Value array:\t" << len_Value << std::endl;
909 std::cout << "Length of xCoord array:\t" << len_xcoord<< std::endl;
910 std::cout << "Length of yCoord array:\t" << len_ycoord << std::endl;
911 std::cout << "Length of zCoord array:\t" << len_zcoord << std::endl;
912 std::cout << "Length of acc1D array:\t" << len_acc << std::endl;
913 std::cout << "Length of acc2D array:\t" << len_acc2 << std::endl;
914 std::cout << "Length of acc3D array:\t" << len_acc3 << std::endl;
915 std::cout << "Length of proj1D array:\t" << len_projection << std::endl;
916 std::cout << "Length of proj2D array:\t" << len_projection2 << std::endl << std::endl;
917
918 // DT-Grid file size. Estimate from the array size given above.
919 int dtgrid_size;
920 dtgrid_size = sizeof(T) * len_Value + sizeof(K) * (len_xcoord + len_ycoord + len_zcoord + \
922 size_ds(dtgrid_size); // convert to human-readable form
923
924 //DT-Grid main body.
925
926 // read the 'value' array from the file
927 T * Value;
928 if (grid_type == 0){
929 // excluded volume grid
930 Value = new T;
931 }
932 else if (grid_type == 1){
933 // potential/energy grid
934 Value = new T [len_Value];
935 for (int i=0;i<len_Value;i++){
936 dtgrid_file.read((char *) &fval, sizeof(float));
937 if (typeid(T) == typeid(bool))
938 Value[i] = fval;
939 else
940 Value[i] = (T) fval * scfct;
941 }
942 }
943 else{
944 // Grid types other than excluded volume and potential/energy. Perhaps in the future.
945 Value = new T;
946 }
947
948 // Read the zcoord array from file
949 K * zcoord;
950 zcoord = new K [len_zcoord];
951 for (int i=0;i<len_zcoord;i++){
952 dtgrid_file.read((char *) &ival, sizeof(int));
953 zcoord[i] = (K) ival;
954 }
955
956 // Read the proj1D acc array from file
957 K * acc;
958 acc = new K [len_acc];
959 for (int i=0;i<len_acc;i++){
960 dtgrid_file.read((char *) &ival, sizeof(int));
961 acc[i] = (K) ival;
962 }
963
964 // Read the proj1D 'value' array
965 K * projection;
967 for (int i=0;i<len_projection;i++){
968 dtgrid_file.read((char *) &ival, sizeof(int));
969 projection[i] = (K) ival;
970 }
971
972 // Read the ycoord array
973 K * ycoord;
974 ycoord = new K [len_ycoord];
975 for (int i=0;i<len_ycoord;i++){
976 dtgrid_file.read((char *) &ival, sizeof(int));
977 ycoord[i] = (K) ival;
978 }
979
980 // Read the proj2D acc array
981 K * acc2;
982 acc2 = new K [len_acc2];
983 for (int i=0;i<len_acc2;i++){
984 dtgrid_file.read((char *) &ival, sizeof(int));
985 acc2[i] = (K) ival;
986 }
987
988 // Read the proj2D 'value' array
989 K * projection2;
991 for (int i=0;i<len_projection2;i++){
992 dtgrid_file.read((char *) &ival, sizeof(int));
993 projection2[i] = (K) ival;
994 }
995
996 // Read the xcoord array
997 K * xcoord;
998 xcoord = new K [len_xcoord];
999 for (int i=0;i<len_xcoord;i++){
1000 dtgrid_file.read((char *) &ival, sizeof(int));
1001 xcoord[i] = (K) ival;
1002 }
1003
1004 // Read the acc array that points into DTGrid3D 'value' array
1005 K * acc3;
1006 acc3 = new K [len_acc3];
1007 for (int i=0;i<len_acc3;i++){
1008 dtgrid_file.read((char *) &ival, sizeof(int));
1009 acc3[i] = (K) ival;
1010 }
1011
1012 // Initialize the DT-Grid data structure arrays.
1019
1020 // deallocate the arrays generated for temporarily use.
1021 if (grid_type == 0){
1022 delete Value;
1023 }
1024 else if (grid_type == 1){
1025 delete[] Value;
1026 }
1027 else{
1028 delete Value;
1029 }
1030 delete[] zcoord;
1031 delete[] acc;
1032 delete[] projection;
1033 delete[] ycoord;
1034 delete[] acc2;
1035 delete[] projection2;
1036 delete[] xcoord;
1037 delete[] acc3;
1038
1039 dtgrid_file.close();
1040}
1041
1043
1049template <typename T, typename K>
1051{
1052 std::ifstream dtgrid_file;
1053 dtgrid_file.open(file_ascii, std::ifstream::in);
1054
1055 std::string title_str, line;
1057 std::string i_str, j_str, k_str;
1058 std::string spacing_str, ox_str, oy_str, oz_str;
1059 std::string dum2_str, dum3_str, dum4_str, dum5_str;
1060 std::string dum6_str, dum7_str, idum4_str, idum5_str;
1061
1062 T fval;
1063 K ival;
1064 int flag_grid_type;
1067
1068 // DT-Grid (UHBD) Title
1070 title_str = line.substr(0,72);
1071
1072 // DT-Grid/UHBD header parameters
1073 //
1075 scale_str = line.substr(0,12);
1076 dum1_str = line.substr(12,12);
1077 grdflag_str = line.substr(24,7);
1078 idum1_str = line.substr(31,7);
1079 idum2_str = line.substr(38,7);
1080 one_str = line.substr(45,7);
1081 idum3_str = line.substr(52,7);
1083 i_str = line.substr(0,7);
1084 j_str = line.substr(7,7);
1085 k_str = line.substr(14,7);
1086 spacing_str = line.substr(21,12);
1087 ox_str = line.substr(33,12);
1088 oy_str = line.substr(45,12);
1089 oz_str = line.substr(57,12);
1091 dum2_str = line.substr(0,12);
1092 dum3_str = line.substr(12,12);
1093 dum4_str = line.substr(24,12);
1094 dum5_str = line.substr(36,12);
1096 dum6_str = line.substr(0,12);
1097 dum7_str = line.substr(12,12);
1098 idum4_str = line.substr(24,7);
1099 idum5_str = line.substr(31,7);
1100
1101 // assign the grid parameters from the UHBD file header
1102 uhbd.Title = new char [72];
1103 std::strncpy (uhbd.Title, title_str.c_str(), 72);
1104
1105 std::stringstream (scale_str) >> uhbd.scale;
1106 std::stringstream (dum1_str) >> uhbd.dummy1;
1107 std::stringstream (grdflag_str) >> uhbd.grdflag;
1108 std::stringstream (idum1_str) >> uhbd.idummy1;
1109 std::stringstream (idum2_str) >> uhbd.idummy2;
1110 std::stringstream (one_str) >> uhbd.one;
1111 std::stringstream (idum3_str) >> uhbd.idummy3;
1112 std::stringstream (i_str) >> uhbd.dim.i;
1113 std::stringstream (j_str) >> uhbd.dim.j;
1114 std::stringstream (k_str) >> uhbd.dim.k;
1115 std::stringstream (spacing_str) >> uhbd.spacing;
1116 std::stringstream (ox_str) >> uhbd.o.x;
1117 std::stringstream (oy_str) >> uhbd.o.y;
1118 std::stringstream (oz_str) >> uhbd.o.z;
1119 std::stringstream (dum2_str) >> uhbd.dummy2;
1120 std::stringstream (dum3_str) >> uhbd.dummy3;
1121 std::stringstream (dum4_str) >> uhbd.dummy4;
1122 std::stringstream (dum5_str) >> uhbd.dummy5;
1123 std::stringstream (dum6_str) >> uhbd.dummy6;
1124 std::stringstream (dum7_str) >> uhbd.dummy7;
1125 std::stringstream (idum4_str) >> uhbd.idummy4;
1126 std::stringstream (idum5_str) >> uhbd.idummy5;
1127
1128
1129 // DT-Grid header parameters
1130 // Length of each of the DT-Grid data structure arrays
1141
1143 if (grid_type == 0)
1144 std::cout << "Type of grid: Excluded volume" << std::endl;
1145 else if (grid_type == 1)
1146 std::cout << "Type of grid: Potential/Energy" << std::endl;
1147 else
1148 std::cout << "Type of grid: Unknown/Not-Set" << std::endl;
1149
1150 // The following block verbose. Informative but necessary to print every time?
1151 std::cout << "DT-Grid Header information: " << std::endl;
1152 std::cout << "Length of Value array:\t" << len_Value << std::endl;
1153 std::cout << "Length of xCoord array:\t" << len_xcoord<< std::endl;
1154 std::cout << "Length of yCoord array:\t" << len_ycoord << std::endl;
1155 std::cout << "Length of zCoord array:\t" << len_zcoord << std::endl;
1156 std::cout << "Length of acc1D array:\t" << len_acc << std::endl;
1157 std::cout << "Length of acc2D array:\t" << len_acc2 << std::endl;
1158 std::cout << "Length of acc3D array:\t" << len_acc3 << std::endl;
1159 std::cout << "Length of proj1D array:\t" << len_projection << std::endl;
1160 std::cout << "Length of proj2D array:\t" << len_projection2 << std::endl << std::endl;
1161
1162 unsigned int dtgrid_size;
1163 dtgrid_size = sizeof(T) * len_Value + sizeof(K) * (len_xcoord + len_ycoord + len_zcoord + \
1165 size_ds(dtgrid_size); // convert to human-readable form
1166
1167 // DT-Grid file main body
1168 //
1169 T * Value;
1170 if (grid_type == 0){
1171 // excluded volume grid
1172 Value = new T;
1173 }
1174 else if (grid_type == 1){
1175 // potential grid
1176 Value = new T [len_Value];
1177 for (int i=0;i<len_Value;i++){
1178 dtgrid_file >> fval;
1179 if (typeid(T) == typeid(bool))
1180 Value[i] = fval;
1181 else
1182 Value[i] = fval * scfct;
1183 }
1184 }
1185 else{
1186 // Grid types other than excluded volume and potential/energy. Perhaps in the future.
1187 Value = new T;
1188 }
1189
1190 // Read the zcoord array
1191 K * zcoord;
1192 zcoord = new K [len_zcoord];
1193 for (int i=0;i<len_zcoord;i++){
1194 dtgrid_file >> ival;
1195 zcoord[i] = ival;
1196 }
1197
1198 // Read the proj1D acc array
1199 K * acc;
1200 acc = new K [len_acc];
1201 for (int i=0;i<len_acc;i++){
1202 dtgrid_file >> ival;
1203 acc[i] = ival;
1204 }
1205
1206 // Read the proj1D 'value' array
1207 K * projection;
1208 projection = new K [len_projection];
1209 for (int i=0;i<len_projection;i++){
1210 dtgrid_file >> ival;
1211 projection[i] = ival;
1212 }
1213
1214 // Read the ycoord array
1215 K * ycoord;
1216 ycoord = new K [len_ycoord];
1217 for (int i=0;i<len_ycoord;i++){
1218 dtgrid_file >> ival;
1219 ycoord[i] = ival;
1220 }
1221
1222 // Read the proj2D acc array
1223 K * acc2;
1224 acc2 = new K [len_acc2];
1225 for (int i=0;i<len_acc2;i++){
1226 dtgrid_file >> ival;
1227 acc2[i] = ival;
1228 }
1229 // Read the proj2D 'value' array
1230 K * projection2;
1232 for (int i=0;i<len_projection2;i++){
1233 dtgrid_file >> ival;
1234 projection2[i] = ival;
1235 }
1236
1237 // Read the xcoord array
1238 K * xcoord;
1239 xcoord = new K [len_xcoord];
1240 for (int i=0;i<len_xcoord;i++){
1241 dtgrid_file >> ival;
1242 xcoord[i] = ival;
1243 }
1244
1245 // Read the acc array that points into DTGrid3D 'value' array
1246 K * acc3;
1247 acc3 = new K [len_acc3];
1248 for (int i=0;i<len_acc3;i++){
1249 dtgrid_file >> ival;
1250 acc3[i] = ival;
1251 }
1252
1253 // Initialize the DT-Grid data structure arrays.
1260
1261 if (grid_type == 0){
1262 delete Value;
1263 }
1264 else if (grid_type == 1){
1265 delete[] Value;
1266 }
1267 else{
1268 delete Value;
1269 }
1270 delete[] zcoord;
1271 delete[] acc;
1272 delete[] projection;
1273 delete[] ycoord;
1274 delete[] acc2;
1275 delete[] projection2;
1276 delete[] xcoord;
1277 delete[] acc3;
1278
1279 dtgrid_file.close();
1280}
1281
1283
1286template <typename T, typename K>
1287void DTGrid3D<T,K>::size_ds(unsigned int val)
1288{
1289 float dtgrid_size;
1290 int kb, mb, gb;
1291
1292 kb = 1024; // kilobyte
1293 mb = 1024 * 1024; // megabyte
1294 gb = 1024 * 1024 * 1024; // gigabyte
1295
1296 if (((float)val / (float) gb) >= 1.0) {
1297 dtgrid_size = (float) val / (float) gb;
1298 std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " GB" << std::endl;
1299 }
1300 else {
1301 if (((float)val / (float) mb) >= 1.0) {
1302 dtgrid_size = (float) val / (float) mb;
1303 std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " MB" << std::endl;
1304 }
1305 else {
1306 dtgrid_size = (float) val / (float) kb;
1307 std::cout << "Size of DT-Grid data structure is " << dtgrid_size << " KB" << std::endl;
1308 }
1309 }
1310}
1311
1312#endif /* DTGRID3D_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.
Definition DTGrid3D.hpp:65
int idummy3
Definition DTGrid3D.hpp:148
int Length_of_Ptr_List_3D
Definition DTGrid3D.hpp:80
struct DTGrid3D::@1 origin
hold the coordinates (in x, y and z) of the grid origin.
int grdflag
Definition DTGrid3D.hpp:144
float dummy5
Definition DTGrid3D.hpp:157
T access_fast(int, int, int)
Random access function.
Definition DTGrid3D.hpp:391
float dummy7
Definition DTGrid3D.hpp:159
float z
Definition DTGrid3D.hpp:122
DTGrid3D(char *, T, T)
DTGrid3D constructor.
Definition DTGrid3D.hpp:221
T gamma_o
Definition DTGrid3D.hpp:83
void getCellyz(T *, int, int, int, typename ArrayPrs< K >::PairArray *)
Random access function for grid cells (y direction, DTGrid2D).
Definition DTGrid3D.hpp:643
float dummy3
Definition DTGrid3D.hpp:155
float dummy6
Definition DTGrid3D.hpp:158
char * Title
Definition DTGrid3D.hpp:143
float x
Definition DTGrid3D.hpp:120
ArrayReg< T > * Value_List_3D
Definition DTGrid3D.hpp:72
void format_ascii(char *)
Open and Read the ascii grid file.
Definition DTGrid3D.hpp:1050
int iform
grid file format: binary = 0; ascii = 1
Definition DTGrid3D.hpp:86
struct DTGrid3D::@2::origin o
void test_format_dtgrid(char *)
Determine the DT-Grid file format.
Definition DTGrid3D.hpp:785
int grid_type
grid type: exclusion grid = 0; normal grid = 1
Definition DTGrid3D.hpp:89
float y
Definition DTGrid3D.hpp:121
void format_binary(char *)
Open and Read the binary grid file.
Definition DTGrid3D.hpp:839
~DTGrid3D()
DTGrid3D destructor.
Definition DTGrid3D.hpp:196
void set_gamma_values(T, T)
Set the default gamma value.
Definition DTGrid3D.hpp:371
float scale
scaling factor
Definition DTGrid3D.hpp:92
struct DTGrid3D::@0 dimensions
grid dimensions in x, y and z directions given by i, j and k, respectively
int j
Definition DTGrid3D.hpp:114
T access_fast_z(int, typename ArrayPrs< K >::PairArray *)
Random access function for DTGrid3D.
Definition DTGrid3D.hpp:464
float dummy1
Definition DTGrid3D.hpp:153
DTGrid2D< T, K > * proj2D
Definition DTGrid3D.hpp:76
T gamma_i
Definition DTGrid3D.hpp:82
void set_zcoord_list(K *, int)
zCoord array setup
Definition DTGrid3D.hpp:265
void size_ds(unsigned int)
Estimate the grid file size.
Definition DTGrid3D.hpp:1287
void Reset_pointers_3D(void)
void set_value_list_3D(T *, int)
DTGrid3D 'value' array setup.
Definition DTGrid3D.hpp:243
ArrayPtr< T, K > * Ptr_List_3D
Definition DTGrid3D.hpp:74
T access_fast_yz(int, int, typename ArrayPrs< K >::PairArray *)
Random access function for DTGrid2D.
Definition DTGrid3D.hpp:424
int Length_of_Zcoord_List
Definition DTGrid3D.hpp:79
float spacing
Definition DTGrid3D.hpp:93
int i
Definition DTGrid3D.hpp:113
void set_projection2D(K *, K *, K *, K *, K *, K *, int, int, int, int, int, int)
proj2D setup
Definition DTGrid3D.hpp:310
int idummy2
Definition DTGrid3D.hpp:147
void set_uhbd_parameters(float, float, float, float, float, int, int, int)
Reset pointers that temporarily store addresses for random access.
Definition DTGrid3D.hpp:346
bool excl_accessxyz(int, int, int)
int idummy4
Definition DTGrid3D.hpp:149
int Length_of_Value_List_3D
Definition DTGrid3D.hpp:78
ArrayPrs< K > * Zcoord_List
Definition DTGrid3D.hpp:73
T * getCell2(T *, int, int, int)
Random access to grid cells. (2nd version)
Definition DTGrid3D.hpp:749
int type_of_grid(void)
Definition DTGrid3D.hpp:179
float dummy4
Definition DTGrid3D.hpp:156
struct DTGrid3D::@2 uhbd
UHBD header information.
T scfct
Definition DTGrid3D.hpp:91
void getCellz(T *, int, int, int, typename ArrayPrs< K >::PairArray *)
A random access function suited for excluded volume grids, based on the function.
Definition DTGrid3D.hpp:592
void set_ptr_list_3D(K *, int)
acc (3D) array setup
Definition DTGrid3D.hpp:278
int k
Definition DTGrid3D.hpp:115
int idummy5
Definition DTGrid3D.hpp:150
struct DTGrid3D::@2::dimensions dim
int idummy1
Definition DTGrid3D.hpp:146
T * getCell(T *, int, int, int)
Random access to grid cells.
Definition DTGrid3D.hpp:700
int one
Definition DTGrid3D.hpp:145
T accessxyz(int, int, int)
Random access function.
Definition DTGrid3D.hpp:510
float dummy2
Definition DTGrid3D.hpp:154
Imprint/Privacy