57 #ifndef DTGRID3DEX_HPP_
58 #define DTGRID3DEX_HPP_
115 void set_projection2D(
int*,
int*,
int*,
int*,
int*,
int*,
int,
int,
int,
int,
int,
int);
160 bool *
getCell(
bool *,
int,
int,
int);
161 bool *
getCell2(
bool *,
int,
int,
int);
190 std::cout <<
"Error: Unknown file format" << std::endl;
224 int* values4,
int* values5,
int* values6,
int length1,
int length2, \
225 int length3,
int length4,
int length5,
int length6){
279 if (coord3 == NULL)
return false;
283 int checkpoint_31 = coord3->v2;
284 int checkpoint_32 = (coord3+1)->v2;
285 int countdown_3 = checkpoint_32 - checkpoint_31;
288 if (countdown_3 == 0)
return false;
293 for (; countdown_3 >= 1; countdown_3--){
296 key3 =
c>=coo3->v1 ? (
c<=coo3->v2 ? true :
false) :
false;
322 int checkpoint_31 = coord3->v2;
323 int checkpoint_32 = (coord3+1)->v2;
324 int countdown_3 = checkpoint_32 - checkpoint_31;
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);
337 Cell[4*
x+2*
y] =
true;
338 Cell[4*
x+2*
y+1] =
true;
341 Cell[4*
x+2*
y] =
true;
344 Cell[4*
x+2*
y+1] =
true;
365 int checkpoint_21 = coord2->v2;
366 int checkpoint_22 = (coord2+1)->v2;
367 int countdown_2 = checkpoint_22 - checkpoint_21;
369 if (countdown_2 == 0){
return;}
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);
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);
430 getCellyz(Cell, 0,b,
c, *(ptt1) + a - coo1->v1);
431 getCellyz(Cell, 1,b,
c, *(ptt1) + ainc - coo1->v1);
434 getCellyz(Cell, 0,b,
c, *(ptt1) + a - coo1->v1);
437 getCellyz(Cell, 1,b,
c, *(ptt1) + ainc - coo1->v1);
462 skey1 = a>=coo1->v1 ? (ainc<=coo1->v2 ? 1 : (a<=coo1->v2 ? 2 : 0) ) : (ainc>=coo1->v1 ? (ainc<=coo1->v2 ? 3 : 0) : 0);
466 getCellyz(Cell, 0,b,
c, *(ptt1) + a - coo1->v1);
467 getCellyz(Cell, 1,b,
c, *(ptt1) + ainc - coo1->v1);
470 getCellyz(Cell, 0,b,
c, *(ptt1) + a - coo1->v1);
473 getCellyz(Cell, 1,b,
c, *(ptt1) + ainc - coo1->v1);
487 std::ifstream file_bt;
488 file_bt.open(Input, std::ifstream::in | std::ifstream::binary);
491 file_bt.read((
char *) &flag,
sizeof(
int));
494 char * buffer =
new char [120];
495 file_bt.read(buffer, 120);
498 binary_test = (
char*) memchr (buffer,
'\n', 120);
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;
507 if (binary_test == NULL) {
508 binary_test = (
char*) memchr (buffer,
'\0', 120);
509 if (binary_test == NULL) {
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;
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;
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;
544 std::ifstream dtgrid_file;
545 dtgrid_file.open(file_binary, std::ifstream::in | std::ifstream::binary);
547 float sc, sp, ox, oy, oz, fval;
548 int dimi, dimj, dimk, ival, flag_binary, flag_grid_type;
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));
578 int len_Value, len_xcoord, len_ycoord, len_zcoord;
579 int len_acc, len_acc2, len_acc3, len_projection, len_projection2;
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));
594 std::cout <<
"Type of grid: Excluded volume" << std::endl;
596 std::cout <<
"Type of grid: Potential/Energy" << std::endl;
598 std::cout <<
"Type of grid: Unknown/Not-Set" << std::endl;
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;
612 dtgrid_size =
sizeof(int) * (len_xcoord + len_ycoord + len_zcoord + \
613 len_acc + len_acc2 + len_acc3) +
sizeof(
int *) * (len_projection + len_projection2);
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;
625 acc =
new int [len_acc];
626 for (
int i=0;
i<len_acc;
i++){
627 dtgrid_file.read((
char *) &ival,
sizeof(int));
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;
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;
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;
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;
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;
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;
677 set_projection2D(projection,ycoord,acc2,projection2,xcoord,acc3,len_projection, \
678 len_ycoord,len_acc2,len_projection2,len_xcoord,len_acc3);
685 delete[] projection2;
701 std::ifstream dtgrid_file;
702 dtgrid_file.open(file_ascii, std::ifstream::in);
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;
714 int len_Value, len_xcoord, len_ycoord, len_zcoord;
715 int len_acc, len_acc2, len_acc3, len_projection, len_projection2;
718 getline(dtgrid_file,line);
719 title_str = line.substr(0,72);
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);
750 uhbd.Title =
new char [72];
751 std::strncpy (
uhbd.Title, title_str.c_str(), 72);
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;
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;
791 std::cout <<
"Type of grid: Excluded volume" << std::endl;
793 std::cout <<
"Type of grid: Potential/Energy" << std::endl;
795 std::cout <<
"Type of grid: Unknown/Not-Set" << std::endl;
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;
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);
815 zcoord =
new int [len_zcoord];
816 for (
int i=0;
i<len_zcoord;
i++){
822 acc =
new int [len_acc];
823 for (
int i=0;
i<len_acc;
i++){
829 projection =
new int [len_projection];
830 for (
int i=0;
i<len_projection;
i++){
832 projection[
i] = ival;
836 ycoord =
new int [len_ycoord];
837 for (
int i=0;
i<len_ycoord;
i++){
843 acc2 =
new int [len_acc2];
844 for (
int i=0;
i<len_acc2;
i++){
850 projection2 =
new int [len_projection2];
851 for (
int i=0;
i<len_projection2;
i++){
853 projection2[
i] = ival;
857 xcoord =
new int [len_xcoord];
858 for (
int i=0;
i<len_xcoord;
i++){
864 acc3 =
new int [len_acc3];
865 for (
int i=0;
i<len_acc3;
i++){
874 set_projection2D(projection,ycoord,acc2,projection2,xcoord,acc3,len_projection, \
875 len_ycoord,len_acc2,len_projection2,len_xcoord,len_acc3);
881 delete[] projection2;
899 gb = 1024 * 1024 * 1024;
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;
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;
911 dtgrid_size = (float) val / (
float) kb;
912 std::cout <<
"Size of DT-Grid data structure is " << dtgrid_size <<
" KB" << std::endl;
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