StaticModelLoader::StaticModelLoader(char* path, char *mpath) { m_infile.open(mpath); if (!m_infile) { cout << "Cannot open material file!\n"; throw 1; } infile.open(path); //"res/car.obj" if (!infile) { cout << "Cannot open file!\n"; throw 1; } mload(); vload(); infile.clear(); infile.seekg(0, ios::beg); fload(); infile.close(); m_infile.close(); //debug models std::cout << " verticies " << v_num << " textures " << vt_num << " normals " << vn_num << " polygones " << f_num << std::endl; }
unint load_shader(const char *fname, GLenum type) { int size=0; void *data=NULL; if(fload(fname,&size,&data)) { const unint s=glCreateShader(type); int val=0; glShaderSource(s,1,(const char**)&data,&size); free(data); glCompileShader(s); glGetShaderiv(s,GL_INFO_LOG_LENGTH,&val); if(val>1) { char *log=(char*)malloc(val); glGetShaderInfoLog(s,val,NULL,log); info("Shader \"%s\" info:\n%s\n",fname,log); free((void*)log); } glGetShaderiv(s,GL_COMPILE_STATUS,&val); if(!val) info("Shader \"%s\" compiling failed\n",fname); return s; } else return 0; }
static int i82563reset(Ctlr* ctlr) { int i, r; detach(ctlr); if(ctlr->type == i82566 || ctlr->type == i82567) r = fload(ctlr); else r = eeload(ctlr); if (r != 0 && r != 0xBABA){ print("%s: bad EEPROM checksum - 0x%4.4ux\n", tname[ctlr->type], r); return -1; } for(i = Ea; i < Eaddrlen/2; i++){ ctlr->ra[2*i] = ctlr->eeprom[i]; ctlr->ra[2*i+1] = ctlr->eeprom[i]>>8; } r = (csr32r(ctlr, Status) & Lanid) >> 2; ctlr->ra[5] += r; /* ea ctlr[1] = ea ctlr[0]+1 */ r = ctlr->ra[3]<<24 | ctlr->ra[2]<<16 | ctlr->ra[1]<<8 | ctlr->ra[0]; csr32w(ctlr, Ral, r); r = 0x80000000 | ctlr->ra[5]<<8 | ctlr->ra[4]; csr32w(ctlr, Rah, r); for(i = 1; i < 16; i++){ csr32w(ctlr, Ral+i*8, 0); csr32w(ctlr, Rah+i*8, 0); } for(i = 0; i < 128; i++) csr32w(ctlr, Mta+i*4, 0); csr32w(ctlr, Fcal, 0x00C28001); csr32w(ctlr, Fcah, 0x00000100); csr32w(ctlr, Fct, 0x00008808); csr32w(ctlr, Fcttv, 0x00000100); csr32w(ctlr, Fcrtl, ctlr->fcrtl); csr32w(ctlr, Fcrth, ctlr->fcrth); ilock(&ctlr->imlock); csr32w(ctlr, Imc, ~0); ctlr->im = 0; /* was = Lsc, which hangs some controllers */ csr32w(ctlr, Ims, ctlr->im); iunlock(&ctlr->imlock); return 0; }
byte load_tex(unint t, const char *fname, unshort w, unshort h, GLenum fmt, tex_filter tf) { int size=0; void *data=NULL; if(fload(fname,&size,&data)) { use_tex(t); glTexImage2D(GL_TEXTURE_2D,0,fmt,w,h,0,fmt,GL_UNSIGNED_BYTE,data); free(data); filter_tex(tf); return 1; } else return 0; }
void BytecodeAssembler::load(BasicType bt, u4 index) { switch (bt) { case T_BOOLEAN: case T_CHAR: case T_BYTE: case T_SHORT: case T_INT: iload(index); break; case T_FLOAT: fload(index); break; case T_DOUBLE: dload(index); break; case T_LONG: lload(index); break; case T_OBJECT: case T_ARRAY: aload(index); break; default: ShouldNotReachHere(); } }
void rl_test(void) { uchar *in, *out; size_t inlen; size_t outlen; while (1) { char *line = readline(">> "); in = (uchar*)fload(line, NULL, &inlen); printf("inlen: %zd\n", inlen); out = malloc(inlen); outlen = rl_encode1(out, in, inlen); printf("outlen: %zd\n", outlen); free(line); free(in); free(out); } }
int main(int argc, char * argv[]) { //-o-o-o-o-o-o-o-o Declaring Variables o-o-o-o-o-o-o-o-o-// FILE * pmass , * phess , * pEqCrd , * poutDXDR , * poutFreq ; //, *pmo2ao; char massFileName[ 100 ] , hessFileName[ 100 ] , EqCrdFileName[ 100 ] ; char outDXDRFileName[ 100 ] , outFreqFileName[ 100 ] ; char massunit[ 100 ] , hessunit[ 100 ] , crdunit[ 100 ] ; int sdouble = sizeof(double); int natom , ncart , nmode ; int iatom , icart , imode ; int natomselect , natomprovide , ncartselect , ncartprovide ; int len_hess_cart, len_tri_hess_cart; int j,k,m; int itmp; double dtmp; char * keyword; int debuggingMode = NO ; //char gessname[ 100 ] ; double * hess_cart , * hess_cart_select ; double * freq , * vib_freq , * dxdr , * vib_dxdr ; double hessconvert , crdconvert , massconvert ; double * mass_provide , * mass; char ** pcmd ; pcmd = argv ; int icmd = 1 ; int iline , iload ; int irow , icol ; int blank_signal , groinfo ; char buffer[ MAXCHARINLINE ] ; char cache[ MAXCHARINLINE ] ; char tmpString[ MAXCHARINLINE ] ; // ---> For debugging output FILE * debug; //-o-o-o-o-o-o-o-o Recording cmd-line and time stamp o-o-o-o-o-o-o-o-o-// time_t current_time; time( ¤t_time ); char now[ 300 ] ; strcpy( now , ctime( ¤t_time ) ); int lennow = strlen( now ) ; *( now + lennow - 1 ) = ' '; printf("\n**********************************************************************\n"); printf("* G_GMXFREQ_D : Stand-Alone Utility to Calculate Normal Modes *\n"); printf("* From Hessian File and Mass File. *\n"); printf("* *\n"); printf("* "); for( icmd = 0 ; icmd < argc ; icmd ++ ) { printf("%s " , *( pcmd + icmd ) ); } printf("\n"); printf("* *\n"); printf("* *\n"); printf("* Current Time : %s *\n" , now ); printf("* *\n"); printf("* *\n"); printf("**********************************************************************\n"); //-o-o-o-o-o-o-o Read input command-line arguments and input files while deciding some parameters ...o-o-o-o-o-o-o-o-o-o-// // -------> Parsing the Command Line Arguments ... pcmd = argv ; //int exn = 10 ; int exr = 16 ; int exR = 18 ; int exH = 22 ; int exM = 28 ; int exL = 30 ; int exc = 20 ; int exs = 18 ; int exm = 88 ; int exH = 70 ; int exo = 22 , exw = 26 ; char * flag ; int internalOrNot = NO ; icmd = 1 ; printf("\n%d command-line arguments provided ...\n" , argc ); if( argc == 1 ) { printf("\n\nNo command-line arguments provided ... Mission aborting ...\n\n"); printf("\nPlease refer to the usage by typing ' %s -h '\n\n" , * argv ); exit(1); } while( icmd < argc ) { pcmd ++ ; flag = * pcmd ; printf("\nNo.%d argument , Currently @ flag = %s ...\n\n" , icmd , flag ); if( ( * flag == '-' ) && ( strlen( flag ) == 2 ) ) { switch ( *( flag + 1 ) ) { case 'c' : strcpy( tmpString , *( ++ pcmd ) ); strcpy( buffer , *( ++ pcmd ) ); if( strcmp( tmpString , "none" ) == 0 ) { strcpy( EqCrdFileName , "dirtroad.anthem" ) ; internalOrNot = NO ; printf("\nCommand-line argument indicates : NO INPUT Eq. Coordinate ... Hence NO Internal Coordinate Transformation \n" ); } else { strcpy( EqCrdFileName , tmpString ) ; strcpy( crdunit , buffer ) ; if( * crdunit == '-' ) { printf("\nHey, you did not specify the unit of you Coordinate file ... !\n"); exit( 11 ) ; } internalOrNot = YES ; printf("\nCommand-line argument indicates : Input Eq. Coordinate File name : %s . Format is %s ...\n" , EqCrdFileName , crdunit ); } exc = 21 ; icmd = icmd + 3 ; break ; case 'H' : strcpy( hessFileName , *( ++ pcmd ) ); strcpy( hessunit , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input Hessian File name : %s . Unit is %s ...\n" , hessFileName , hessunit ); if( * hessunit == '-' ) { printf("\nHey, you did not specify the unit of you Hessian file ... !\n"); exit( 11 ); } exH = 71 ; icmd = icmd + 3 ; break ; case 'm' : strcpy( massFileName , *( ++ pcmd ) ); strcpy( massunit , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input Mass File name : %s . Unit is %s ...\n" , massFileName , massunit ); if( * crdunit == '-' ) { printf("\nHey, you did not specify the unit of you Coordinate file ... !\n"); exit( 11 ); } exm = 89 ; icmd = icmd + 3 ; break ; case 's' : strcpy( tmpString , *( ++ pcmd ) ) ; if( strcmp( tmpString , "all" ) == 0 || strcmp( tmpString , "All" ) == 0 ) { exs = 20 ; printf("\nCommand-line argument indicates : All atoms will be chosen as solute ...\n" ); } else { printf("\nReceived information : %s ...\n" , tmpString ) ; natomselect = atoi( tmpString ); exs = 19 ; printf("\nCommand-line argument indicates : First %d atoms will be chosen as solute ...\n" , natomselect ); } icmd = icmd + 2 ; break ; case 'o' : strcpy( outDXDRFileName , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output Normal Mode file name : %s ...\n" , outDXDRFileName ); exo = 23 ; icmd = icmd + 2 ; break ; case 'w' : strcpy( outFreqFileName , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output frequency file name : %s ...\n" , outFreqFileName ); exw = 27 ; icmd = icmd + 2 ; break ; case 'g' : strcpy( cache , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Debugging Mode Invoking : %s ...\n" , cache ); if( strcmp( cache , "YES" ) == 0 || strcmp( cache , "Yes" ) == 0 || strcmp( cache , "yes" ) == 0 || strcmp( cache , "Y" ) == 0 || strcmp( cache , "y" ) == 0 ) { debuggingMode = YES ; } else if( strcmp( cache , "NO" ) == 0 || strcmp( cache , "No" ) == 0 || strcmp( cache , "no" ) == 0 || strcmp( cache , "N" ) == 0 || strcmp( cache , "n" ) == 0 ) { debuggingMode = NO ; } else { printf("\nInvalid choice of debugging mode ... Mission Aborted ...\n\n") ; exit( 21 ) ; } icmd = icmd + 2 ; break ; case 'h' : printf("\nUsage: % 15s [ -c 'input Equilibrium Geometry' ( gro / gmxcrd / g09crd )] [ -H 'Hessian file name' ' unit : au or gmx' ] [ -s # of atoms chosen as the solute ]" , * argv) ; printf("\n [ -m Mass file name & unit ( au or amu ) ] [ -w output frequency file name ] [ -o output dxdr file name ]\n\n"); //printf("\n [ -c 'input EqMD gro file of solvent' ][ -p P Group Name ][ -q Q Group Name ][ -N atom number of L-Shape reference atom ]"); //printf("\n [ -w whether to perform van der Waals contacting check ( YES / Yes / yes ) or ( NO / No / no ) or floating point number to indicate scaling factor ]"); //printf("\n [ -s # of atoms in solute molecule ] [ -t distance threshold to accept one alignment , unit = Angstrom ]\n\n" ); //printf("\nNote : 1) For \"-w\" option, YES/Yes/yes will cause the vdw-check to perform with default scaling 1.00 while NO/No/no will shut down the vdw-check.\n"); //printf("\n Specifying a floating number will also cause the vdw-check to perform but the floating number will be the user-defined scaling factor (vdwFactor).\n"); //printf("\n 2) For \"-t\" option, YES/Yes/yes will cause the universal-distance-check to perform with default threshold 1.20Å while NO/No/no will shut down the unidist-check.\n"); //printf("\n Specifying a floating number will also cause the unidist-check to perform but the floating number will be the user-defined distance threshold (vdwFactor).\n"); printf("\nNote : 1) For \"-s\" option, [ -s all ] or [ -s All ] indicates all atoms chosen as solute;\n"); printf("\n Default for -s is all atoms when nresidue = 1 or natom in 1st residue when nresidue != 1 \n"); printf("\n 2) For \"-c\" option, [ -c none none ] will turn off the internal coordinate transformation and perform regular Cartesian coordinate normal mode analysis ... \n\n\n"); icmd = icmd + 1 ; exit( 1 ) ; break ; default : printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); icmd = argc ; exit(1); } } else { printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); exit(1); } } // -------> Default File Names if( internalOrNot == YES && exc == 20 ) { strcpy( crdunit , "gro" ) ; strcpy( EqCrdFileName , "system.gro" ) ; printf("\nNo input .gro file provided, default \"system.gro\" in play ...\n") ; } int lenEqGROFileName = strlen( EqCrdFileName ) ; if( exo == 22 ) { strncpy( outDXDRFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( outDXDRFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( outDXDRFileName , ".dxdr" ) ; printf("\nBy default , output DXDR file name will be [ %s ] ...\n\n" , outDXDRFileName ) ; } if( exw == 26 ) { strncpy( outFreqFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( outFreqFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( outFreqFileName , ".freq" ) ; printf("\nBy default , output DXDR file name will be [ %s ] ...\n\n" , outFreqFileName ) ; } if( exH == 70 ) { strncpy( hessFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( hessFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( hessFileName , ".gess" ) ; printf("\nBy default , searching for Hessian file with the name %s ...\n\n" , hessFileName ) ; strcpy( hessunit , "gmx" ) ; } if( exm == 88 ) { strncpy( massFileName , EqCrdFileName , lenEqGROFileName - 4 ) ; *( massFileName + lenEqGROFileName - 4 ) = '\0' ; strcat( massFileName , ".mass" ) ; printf("\nBy default , searching for Mass file with the name %s ...\n\n" , massFileName ) ; strcpy( massunit , "amu" ) ; } if( strcmp( hessunit , "au" ) == 0 ) { printf("\nThe unit this Hessian file in is ATOMIC UNIT : Hartree/(Bohr^2) ... \n"); hessconvert = 1.0000 ; } else if( strcmp( hessunit , "gmx" ) == 0 ) { printf("\nThe unit this Hessian file in is GMX-Unit : kJ/mol/(nm^2) ... \n"); hessconvert = HESSAU2GMX ; } else { printf("\nWhat did you say about the unit of you frequency again ??? \n"); exit( 107 ); } printf("\n===> Done Defining Default Fila Names <===\n\n\n") ; // -------> Confirming File Access ... if( ( pmass = fopen( massFileName ,"r" ) ) == NULL ) { printf("\nUser defined mass-file [ %s ] does not exist...\n" , massFileName ); exit( 63 ); } if( ( pEqCrd = fopen( EqCrdFileName ,"r" ) ) == NULL && internalOrNot == YES ) { printf("\nUser defined Equilibrium Coordinate File [ %s ] does not exist...\n" , EqCrdFileName ); exit( 63 ); } if( ( phess = fopen( hessFileName ,"r" ) ) == NULL ) { printf("\nUser defined Hessian-file [ %s ] does not exist...\n" , hessFileName ); exit( 63 ); } printf("\n===> Done Confirming File Access <===\n\n\n") ; //-o-o-o-o-o-o-o Loading Eq. Coordinate , Hessian & Mass ...o-o-o-o-o-o-o-o-o-o-// //-----> Pre-Loading Equilibrium Geometry ... char grotitlestring[MAXLINE]; iline = 3 ; iload = 0 ; int natomgroline , natomgrotitle ; int exVelocity = NO ; if( internalOrNot == YES && ( strcmp( crdunit , "gro" ) ) == 0 ) { rewind( pEqCrd ); //printf("\nCurrent character is %c ... \n" , fgetc( pEqGRO ) ); fskip( pEqCrd , 1 ); fscanf( pEqCrd , "%d" , &natomgrotitle ); fskip( pEqCrd , 1 ); printf("\n Second line of .gro file says it is describing %d atoms ... \n\n" , natomgrotitle ); while( ( groinfo = freadline( buffer , MAXCHARINLINE , pEqCrd , ';' ) ) != 0 ) { itmp = inLineWC( buffer ) ; break ; } if( itmp == 6 ) { exVelocity = NO ; printf("\nI see there is no velocity information in .gro file ...\n\n") ; } else if( itmp == 9 ) { exVelocity = YES ; printf("\nI see velocity information is also included in .gro file ...\n\n") ; } else { printf("\nPlease check the format of you .gro file ... There are %d words in one line of your molecular specification ... \n" , itmp ) ; exit( 456 ); } printf("\nNow let's pre-load the .gro file ans see how many atoms it is describing ... \n"); natomgroline = preLoadGRO( pEqCrd ) ; printf("\nIt can be seen that this .gro file is describing %d atoms ...\n" , natomgroline ); if( natomgrotitle > natomgroline ) { printf("\nYour .gro file is self-contradictory ... While the second line of your .gro file says there will be %d atoms, there are actually only %d atoms being described ... \n" , natomgrotitle , natomgroline ); printf("\nWe will take all the atoms we can to procede ... \n"); natom = natomgroline ; } else if( natomgrotitle == natomgroline ) { printf("\nOkay ... Your .gro file is fine ... NAtom will be %d ... \n" , natomgrotitle ); natom = natomgrotitle ; } else if( natomgrotitle < natomgroline ) { printf("\nThe second line of your .gro file indicates there are %d atoms in this file but there are more atoms ( %d atoms ) being described insided ... We will take the first %d atoms ... \n" , natomgrotitle , natomgroline , natomgrotitle ); natom = natomgrotitle ; } else { printf("\nSomething is wrong with checking the .gro file ... Please take a look at it ... \n"); exit( 81 ); } ncart = 3 * natom ; itmp = 0 ; if( exs == 18 ) { natomselect = natom ; } else if( exs == 19 && natomselect > natom ) // Will be dead ... { printf("\nThere are only %d atoms in this system ... you cannot select more than that ... \n" , natom ); if( natomgrotitle > natomgroline && natomselect <= natomgrotitle ) { printf("\nAlthough ... the second line of your initial .gro file did indicate there were supposed to be %d atoms in system ... So go back and make sure what you are trying to do ... \n" , natomgrotitle ); } else if( natomgrotitle < natomgroline && natomselect <= natomgroline ) { printf("\nAlthough ... your initial .gro file did describe %d atoms in system ... So go back and make sure what you are trying to do ... \n" , natomgroline ); } exit( 78 ); } else if( exs == 19 && natomselect <= natom ) { printf("\nYou have selected %d atoms as solute ... There are %d atoms en toto in this system ... \n" , natomselect , natom ); } else if( exs == 20 ) { natomselect = natom ; } else { printf("\nSomething is wrong with the atom selection process ... NAtom = %d , NAtomSelect = %d ... \n" , natom , natomselect ); exit( 78 ); } ncartselect = 3 * natomselect ; } else if( internalOrNot == YES && ( ( strcmp( crdunit , "gmxcrd" ) ) == 0 || ( strcmp( crdunit , "g09crd" ) ) == 0 ) ) { rewind( pEqCrd ); itmp = flength( pEqCrd ) ; natom = itmp / 3 ; ncart = itmp ; if( exs == 18 ) { natomselect = natom ; } else if( exs == 19 && natomselect > natom ) // Will be dead ... { printf("\nThere are only %d atoms in this system ... you cannot select more than that ... \n" , natom ); exit( 78 ); } else if( exs == 19 && natomselect <= natom ) { printf("\nYou have selected %d atoms as solute ... There are %d atoms en toto in this system ... \n" , natomselect , natom ); } else if( exs == 20 ) { natomselect = natom ; } else { printf("\nSomething is wrong with the atom selection process ... NAtom = %d , NAtomSelect = %d ... \n" , natom , natomselect ); exit( 78 ); } ncartselect = 3 * natomselect ; } //-----> Pre-Loading Mass ... itmp = flength( pmass ) ; rewind( pmass ) ; if( internalOrNot == NO ) { natom = itmp ; ncart = 3 * natom ; if( exs == 18 ) { natomselect = natom ; printf("\nBy default, all available atoms will be chosen as solute ...\n\n") ; } else if( exs == 20 ) { natomselect = natom ; printf("\nPer user's request, all available atoms will be chosen as solute ...\n\n") ; } else if( exs == 19 ) { if( natomselect == natom ) { printf("\nOKay ... I see you provided the mass for all the atom in this system ... \n"); } else if( natomselect > natom ) // will be dead { printf("\nERROR : There are only %d atoms according to mass file, I cannot select that many atoms as solute ...\n\n" , natomselect ) ; exit( 89 ) ; } else if( natomselect < natom ) { printf("\nOKay ... you provided %d floating-point numbers for mass so the total NAtom in system is %d while %d atoms are selected ...\n" , itmp , natom , natomselect ); printf("\nSo ... I will assume the first %d numbers in your mass file correspond to the selected atoms ...\n" , natomselect ); } else { printf("\nSomething is wrong with the mass file ... There are %d atomic mass in the file while the total NAtom in this system is %d and %d atoms are selected ... \n" , itmp , natom , natomselect ); exit( 81 ); } } ncartselect = natomselect * 3 ; } else if( internalOrNot == YES ) { if( itmp == natomselect ) { printf("\nOKay ... I see you provided the mass info for just the selected atoms ... \n"); } else if( itmp == natom ) { printf("\nOKay ... I see you provided the mass for all the atom in this system ... \n"); } else if( itmp > natom ) { printf("\nOKay ... you provided %d numbers for mass. The total NAtom in system is %d while %d atoms are selected ...\n" , itmp , natom , natomselect ); printf("\nSo ... I will assume the first %d numbers in your mass file correspond to the selected atoms ...\n" , natomselect ); } else { printf("\nSomething is wrong with the mass file ... There are %d atomic mass in the file while the total NAtom in this system is %d and %d atoms are selected ... \n" , itmp , natom , natomselect ); exit( 81 ); } } // ---> Loading Equilibrium Geometry ... GRO EqAtomList[ natomselect ] ; double * EqCrd = calloc( ncartselect , sizeof( double ) ) ; dzeros( ncartselect , 1 , EqCrd ) ; double boxvector[ 3 ]; dzeros( 3 , 1 , boxvector ) ; char tmp_char ; if( internalOrNot == YES && ( strcmp( crdunit , "gro" ) ) == 0 ) // We want every coordinate to be in BOHR unit { crdconvert = NM2BOHR ; rewind( pEqCrd ); fskip( pEqCrd , 1 ); fskip( pEqCrd , 1 ); printf("\nNow let's read the actual .gro file ... \n"); iload = 0 ; iline = 0 ; while( ( groinfo = freadline( buffer , MAXCHARINLINE , pEqCrd , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); blank_signal = stellblank( buffer ) ; if( blank_signal == 0 ) { //printf("\nNo.%d line is a blank line ... Moving on ...\n" , iline ) ; continue ; } else if( blank_signal == 1 ) { //printf("\nNo.%d line is NOT a blank line ... loading ...\n" , iline ); if( ( tmp_char = getfirst( buffer ) ) == ';' ) { //printf("\nThis is a comment line ... So nothing will be loaded ...\n"); //fskip( pinputfile , 1 ); continue ; } else { //printf("\nLine reads : %s ...\n" , buffer ); sscanf( buffer , "%5d%5s" , &EqAtomList[ iload ].resnumber , EqAtomList[ iload ].resname ); //printf( "%s\t" , EqAtomList[ iatom ].resname ); //sscanf( pEqGRO , "%s" , EqAtomList[ iload ].atomname ); strpickword( buffer , 2 , cache ) ; strcpy( EqAtomList[ iload ].atomname , cache ) ; //printf( "%s" , EqAtomList[ iatom ].atomname ); //sscanf( pEqGRO , "%d" , &EqAtomList[ iload ].atomnumber ); strpickword( buffer , 3 , cache ) ; EqAtomList[ iload ].atomnumber = atoi( cache ) ; //printf( "\nWorking on No. %d atom ...\n" , EqAtomList[ iatom ].atomnumber ); //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cx ); //printf("\n Cx is %lf ...\t" , EqAtomList[ iatom ].cx); strpickword( buffer , 4 , cache ) ; EqAtomList[ iload ].cx = atof( cache ) ; *( EqCrd + 3 * iload + 0 ) = EqAtomList[ iload ].cx / crdconvert ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cy ); //printf("\n Cy is %lf ...\t" , EqAtomList[ iatom ].cy); strpickword( buffer , 5 , cache ) ; EqAtomList[ iload ].cy = atof( cache ) ; *( EqCrd + 3 * iload + 1 ) = EqAtomList[ iload ].cy / crdconvert ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cz ); //printf("\n Cz is %lf ...\n\n" , EqAtomList[ iatom ].cz); strpickword( buffer , 6 , cache ) ; EqAtomList[ iload ].cz = atof( cache ) ; *( EqCrd + 3 * iload + 2 ) = EqAtomList[ iload ].cz / crdconvert ; if( exVelocity == YES ) { strpickword( buffer , 7 , cache ) ; EqAtomList[ iload ].vx = atof( cache ) ; strpickword( buffer , 8 , cache ) ; EqAtomList[ iload ].vy = atof( cache ) ; strpickword( buffer , 9 , cache ) ; EqAtomList[ iload ].vz = atof( cache ) ; } //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vx ); //printf("\n Vx is %lf ...\t" , EqAtomList[ iatom ].cx); //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vy ); //printf("\n Vy is %lf ...\t" , EqAtomList[ iatom ].cy); //fscanf( pgroinput , "%lf" , &EqAtomList[ iatom ].vz ); //printf("\n Vz is %lf ...\n\n" , EqAtomList[ iatom ].cz); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; if( iload == natomselect ) break ; } /* if( iline < natomgroline ) { fskip( pEqCrd , natomgroline - iline ) ; } fscanf( pgroinput , "%lf" , boxvector + 0 ); fscanf( pgroinput , "%lf" , boxvector + 1 ); fscanf( pgroinput , "%lf" , boxvector + 2 ); */ } else if( internalOrNot == YES && ( strcmp( crdunit , "grocrd" ) ) == 0 ) { crdconvert = NM2BOHR ; rewind( pEqCrd ) ; for( icart = 0 ; icart < ncartselect ; icart ++ ) { fscanf( pEqCrd , "%lf" , &dtmp ) ; *( EqCrd + icart ) = dtmp / crdconvert ; } } else if( internalOrNot == YES && ( strcmp( crdunit , "g09crd" ) ) == 0 ) { crdconvert = 1.0000 ; rewind( pEqCrd ) ; for( icart = 0 ; icart < ncartselect ; icart ++ ) { fscanf( pEqCrd , "%lf" , &dtmp ) ; *( EqCrd + icart ) = dtmp / crdconvert ; } } else if( internalOrNot == NO ) { printf("\nAlready told you ... NO INTERNAL COORDINATE BUSINESS ...\n\n") ; } else { printf("\nUNKOWN ERROR : INVALID COORDINATE FILE FORMAT ...\n\n"); exit( 73 ) ; } printf("\n===> Finished Loading Equilibrium Geometry <===\n\n\n") ; //dtranspose_nonsquare( natomselect , 3 , EqCrd , EqCrd ) ; /* debug = fopen("transposed_eqgeom.deb" , "wb+") ; doutput( debug , 3 , natomselect , EqCrd ) ; fclose( debug ) ; printf("\n===> Done Transposing Equilibrium Geometry <===\n\n\n") ; */ // -------> Loading Mass ... mass = calloc( natomselect , sizeof( double ) ); dzeros( natomselect , 1 , mass ); if( strcmp( massunit , "au" ) == 0 ) { massconvert = AMU2AU ; } else if( strcmp( massunit , "amu" ) == 0 ) { massconvert = 1.000 ; } else { printf("\nUNKOWN ERROR : INVALID MASS FILE FORMAT ...\n\n"); exit( 75 ) ; } for( iatom = 0 ; iatom < natomselect ; iatom ++ ) { fscanf( pmass , "%lf" , &dtmp ) ; *( mass + iatom ) = dtmp / massconvert ; } printf("\n===> Done Loading Mass ( in %s ) <===\n\n\n" , massunit ) ; //------> Hessian File : fskip( phess , 2 ); len_hess_cart = flength( phess ); if( len_hess_cart == ncart * ncart ) { printf("\nOKay ... I see you provided the Hessian for all %d atom in system ... \n" , natom ); } else if( len_hess_cart == ncartselect * ncartselect ) { printf("\nOKay ... I see you only provided the Hessian for the %d selected atoms ... \n" , natomselect ); } else if( len_hess_cart < ncart * ncart && len_hess_cart > ncartselect * ncartselect ) { printf("\nThere are %d numbers in the Hessian file which is less than the square of total %d Cartesian coordinates in system but more than that of %d Cartesian coordinates of selected atoms ... \n" , len_hess_cart , ncart , ncartselect ); printf("\nSo I am taking the first %d number ( %d * %d ) as the Hessian for selected atoms ...\n" , ncartselect * ncartselect , ncartselect , ncartselect ); } else { printf("\nSomething is wrong with the Hessian file ... There are %d numbers in the Hessian file ... \n" , len_hess_cart ); exit( 77 ); } rewind( phess ); //-------> Allocating space for Hessian and Diagonalization Process ... ncartprovide = sqrt( len_hess_cart ); printf("\nWell ... the Hessian file you provided is a %d * %d square matrix ...\n" , ncartprovide , ncartprovide ); hess_cart = calloc( len_hess_cart , sizeof(double)); dzeros( len_hess_cart , 1, hess_cart ); hess_cart_select = calloc( ncartselect * ncartselect , sizeof(double) ) ; dzeros( ncartselect , ncartselect , hess_cart_select ); double * DMatrix = calloc( ncartselect * ncartselect , sizeof( double ) ) ; dzeros( ncartselect , ncartselect , DMatrix ) ; double * tmp_hessian = calloc( ncartselect * ncartselect , sizeof(double) ) ; dzeros( ncartselect , ncartselect , tmp_hessian ); //tri_hess_cart = calloc( ncart*(ncart+1)/2 , sizeof(double)); //dzeros(ncart*(ncart+1)/2, 1, tri_hess_cart); //-------> Loading Hessian Matrix ... rewind( phess ); fskip( phess , 2 ); fload( phess , hess_cart ); for( j = 0 ; j < len_hess_cart ; j ++ ) { *( hess_cart + j ) = *( hess_cart + j ) / hessconvert ; } printf("\n===> Done Loading Whole Provided Hessian <===\n\n\n") ; //-------> Selecting the desired part of Hessian matrix for( j = 0 ; j < ncartselect ; j ++ ) { for( k = 0 ; k < ncartselect ; k ++ ) { *( hess_cart_select + j * ncartselect + k ) = *( hess_cart + j * ncartprovide + k ); } } printf("\n===> Done Picking The Selected Hessian <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("hess_cart.deb", "wb+"); doutput( debug , ncart , ncart , hess_cart); fclose(debug); debug = fopen("hess_cart_select.deb", "wb+"); doutput( debug , ncartselect , ncartselect , hess_cart_select ); fclose(debug); } //-------> Transpose Hessian_cart_select to pass into gausvib_ ... dtranspose( ncartselect , hess_cart_select , hess_cart_select ) ; printf("\n===> Done Transposing Selected Hessian <===\n\n\n") ; //void gausvib_( int * , double * , double * , double * , double * , double * ) ; // ( natom, mass, coordxyzinp, hessianinp, Dmatrix ) //-------> Generate D-Matrix and transform into internal coord ... if( internalOrNot == YES ) { gausvib_( &natomselect , mass , EqCrd , hess_cart_select , DMatrix ) ; dtranspose( ncartselect , DMatrix , DMatrix ) ; printf("\n===> Done Generating D-Matrix ... Currently in C-Fashion <===\n\n\n") ; } else if( internalOrNot == NO ) { for( icart = 0 ; icart < ncartselect ; icart ++ ) { *( DMatrix + icart * ncartselect + icart ) = 1.000 ; } } else { printf("\nUNKNOWN ERROR : [ internalOrNot ] = %d \n\n" , internalOrNot ) ; exit( 15 ) ; } if( debuggingMode == YES ) { debug = fopen( "DMatrix.deb" , "wb+") ; doutput( debug , ncartselect , ncartselect , DMatrix ) ; fclose( debug ) ; } for( j = 0 ; j < natomselect ; j ++ ) *( mass + j ) = ( *( mass + j ) ) * AMU2AU; printf("\n===> Done Putting Mass In AU <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("mass_au.deb", "wb+"); doutput( debug , natomselect , 1 , mass ); fclose(debug); } //-------> Performing mass-weighting for the Force constant matrix dtranspose( ncartselect , hess_cart_select , hess_cart_select ) ; //transpose back to C-Fashion masswt( natomselect , mass , hess_cart_select , hess_cart_select ); printf("\n===> Done Mass-Weighting Selected Hessian <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen("hess_masswt_select.deb", "wb+"); doutput( debug , ncartselect , ncartselect , hess_cart_select ); fclose(debug); } //-------> Calculating f_int = (D.') * f_mwc * D ; double done = 1.0000 ; double dzero = 0.0000 ; int nmode_trans_rot , nvibmodes ; if( natom == 2 ) { nmode_trans_rot = 5 ; } else if( natom >= 3 ) { nmode_trans_rot = 6 ; } nvibmodes = ncartselect - nmode_trans_rot ; double * hess_int_mwc = calloc( ncartselect * ncartselect , sizeof( double ) ) ; dzeros( ncartselect , ncartselect , hess_int_mwc ) ; double * vib_hess_int_mwc = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , vib_hess_int_mwc ) ; dgemm_( "N" , "T" , &ncartselect , &ncartselect , &ncartselect , &done , DMatrix , &ncartselect , hess_cart_select , &ncartselect , &dzero , tmp_hessian , &ncartselect ) ; dgemm_( "N" , "T" , &ncartselect , &ncartselect , &ncartselect , &done , tmp_hessian , &ncartselect , DMatrix , &ncartselect , &dzero , hess_int_mwc , &ncartselect ) ; //dtransopose // SUBROUTINE DGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC ) printf("\n===> Done Calculating f_int = (D.') * f_mwc * D <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen( "hess_int_mwc.deb" , "wb+") ; doutput( debug , ncartselect , ncartselect , hess_int_mwc ) ; fclose( debug ) ; } //-------> Performing matrix-diagonalization for Hess_Cart and l=D*L ( for internalOrNot == YES ) freq = calloc( ncartselect , sizeof( double ) ) ; dzeros( ncartselect , 1 , freq ); vib_freq = calloc( nvibmodes , sizeof(double)); dzeros( nvibmodes , 1 , vib_freq ); dxdr = calloc( ncartselect * ncartselect , sizeof(double)); dzeros( ncartselect * ncartselect , 1 , dxdr ); vib_dxdr = calloc( ncartselect * nvibmodes , sizeof( double ) ); dzeros( ncartselect * nvibmodes , 1 , vib_dxdr ) ; double * tmp_dxdr = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , tmp_dxdr ) ; double * tmp_dxdr_2 = calloc( nvibmodes * nvibmodes , sizeof( double ) ) ; dzeros( nvibmodes , nvibmodes , tmp_dxdr_2 ) ; if( internalOrNot == YES ) { // ---> Taking the vibrational ( 3N - 6 )-by-( 3N - 6 ) block for( icart = nmode_trans_rot ; icart < ncartselect ; icart ++ ) { for( itmp = nmode_trans_rot ; itmp < ncartselect ; itmp ++ ) { *( vib_hess_int_mwc + ( icart - nmode_trans_rot ) * nvibmodes + ( itmp - nmode_trans_rot ) ) = *( hess_int_mwc + icart * ncartselect + itmp ) ; } } if( debuggingMode == YES ) { debug = fopen( "vib_hess_int_mwc.deb" , "wb+" ) ; doutput( debug , nvibmodes , nvibmodes , vib_hess_int_mwc ) ; fclose( debug ) ; } // ---> Diagonalization dsyev_f2c( nvibmodes , vib_hess_int_mwc , tmp_dxdr, vib_freq ); dtranspose( nvibmodes , tmp_dxdr , tmp_dxdr ); if( debuggingMode == YES ) { /* debug = fopen( "vib_dxdr_internal.deb" , "wb+" ) ; doutput( debug , nvibmodes , nvibmodes , tmp_dxdr ) ; fclose( debug ) ; */ debug = fopen( "vib_freq_internal.deb" , "wb+" ) ; doutput( debug , nvibmodes , 1 , vib_freq ) ; fclose( debug ) ; } printf("\n===> Done Diagonalizing ( 3N - 6 )-by-( 3N - 6 ) internal coordinate mass-weighted Hessian and transpose 3N-6 normal modes back to C <===\n\n\n") ; // ---> Putting ( 3N - 6 )-by-( 3N - 6 ) dxdr into vib_dxdr which is 3N-by-( 3N - 6 ) for( icart = nmode_trans_rot ; icart < ncartselect ; icart ++ ) { for( imode = 0 ; imode < nvibmodes ; imode ++ ) { *( vib_dxdr + icart * nvibmodes + imode ) = *( tmp_dxdr + ( icart - nmode_trans_rot ) * nvibmodes + imode ) ; } } printf("\n===> Done Putting ( 3N - 6 )-by-( 3N - 6 ) dxdr into vib_dxdr which is 3N-by-( 3N - 6 ) <===\n\n\n") ; if( debuggingMode == YES ) { debug = fopen( "vib_dxdr_internal.deb" , "wb+" ) ; doutput( debug , ncartselect , nvibmodes , vib_dxdr ) ; printf("\n[===> Debug <===] [\t%lf\t%lf\t%lf\t]" , *( vib_dxdr + 10 ) , *( vib_dxdr + 19 ) , *( vib_dxdr + 38 ) ) ; fclose( debug ) ; } //---> Performing l = D*L dtranspose_nonsquare( ncartselect , nvibmodes , vib_dxdr , vib_dxdr ) ; dgemm_( "T" , "N" , &ncartselect , &nvibmodes , &ncartselect , &done , DMatrix , &ncartselect , vib_dxdr , &ncartselect , &dzero , tmp_dxdr_2 , &ncartselect ) ; dtranspose_nonsquare( nvibmodes , ncartselect , tmp_dxdr_2 , tmp_dxdr_2 ) ; if( debuggingMode == YES ) { debug = fopen( "vib_dxdr_Cartesian.deb" , "wb+" ) ; doutput( debug , ncartselect , nvibmodes , tmp_dxdr_2 ) ; fclose( debug ) ; } // ---> Putting l into the 3N-by-3N dxdr matrix ... for( icart = 0 ; icart < ncartselect ; icart ++ ) { for( imode = nmode_trans_rot ; imode < ncartselect ; imode ++ ) { *( dxdr + icart * ncartselect + imode ) = *( tmp_dxdr_2 + icart * nvibmodes + ( imode - nmode_trans_rot ) ) ; } } printf("\n===> Done Calculating l = D * L <===\n\n\n") ; // ---> Assemble variable "freq" from "vib_freq" for( imode = nmode_trans_rot ; imode < ncartselect ; imode ++ ) { *( freq + imode ) = *( vib_freq + imode - nmode_trans_rot ) ; } } else if( internalOrNot == NO ) { dsyev_f2c( ncartselect , hess_int_mwc , dxdr, freq ); dtranspose( ncartselect , dxdr , dxdr ); } ////////// ________________________ ////////// if( debuggingMode == YES ) { /* debug = fopen( "dxdr.deb" , "wb+" ) ; doutput( debug , ncartselect , ncartselect , dxdr ) ; fclose( debug ) ; */ debug = fopen("allfrequency.deb", "wb+"); doutput( debug , ncartselect , 1 , freq ); fclose( debug ); } //-------> Arranging frequencies and w=sqrt(lambda) ... if( natomselect == 1 ) { printf("\nSeriously? Only one atom ? NO WAYYYYYY ... \n"); exit( 90 ); } else if( natomselect == 2 ) { *( freq + 5 ) = sqrt( *( freq + 5 ) ) * 219474.6313705 ; } else { for( j = 0 ; j < ncartselect ; j ++ ) { if( *( freq + j ) >= 0.000 ) *( freq + j ) = sqrt( *( freq + j ) ) * 219474.6313705 ; else //*( freq + j ) = -1.000 * sqrt( -1.0000 * ( *( freq + j ) ) ) * 219474.6313705 ; *( freq + j ) = 0.0000 ; } } // Here, no matter it is internal or not, after unit change, we will need to assign freq into vib_freq again ... for( imode = 0 ; imode < nvibmodes ; imode ++ ) { *( vib_freq + imode ) = *( freq + imode + nmode_trans_rot ) ; } printf("\n===> Done Putting Vib-Frequencies Together <===\n\n\n") ; poutDXDR = fopen( outDXDRFileName , "wb+" ) ; doutput( poutDXDR , ncartselect , ncartselect , dxdr ) ; fclose( poutDXDR ) ; poutFreq = fopen( outFreqFileName, "wb+"); doutput( poutFreq , ncartselect , 1 , freq ); fclose( poutFreq ); printf("\n\nI assume it's Allllllll Done ...\n\n"); /* FILE * pmass , * phess , * pEqCrd , * poutDXDR , * poutFreq ; //, *pmo2ao; char massFileName[ 100 ] , hessFileName[ 100 ] , EqCrdFileName[ 100 ] ; char outDXDRFileName[ 100 ] , outFreqFileName[ 100 ] ; */ return( 0 ) ; }
void system::read_binary(const char *filename, const int n_files) { #if 1 assert(n_files == 1); vec3 rmin, rmax; if (myproc == 0) { FILE *fin; if (!(fin = fopen(filename, "r"))) { std::cerr << "Cannot open file " << filename << std::endl; exit(-1); } std::cerr << "proc= " << myproc << " read snapshot: " << filename << std::endl; int ival; float fval; #define fload(x) { myfread(&fval, sizeof(float), 1, fin); x = fval; } #define iload(x) { myfread(&ival, sizeof(int), 1, fin); x = ival;} float ftmp; int itmp, np0, npx, npy, npz; iload(itmp); // 20*4 assert(itmp == 20*4); iload(itmp); // myid iload(np0); iload(npx); union { unsigned long long uint_long; unsigned int uint[2]; } data; iload(data.uint[0]); iload(data.uint[1]); scheduler.tsysU = data.uint_long; float courant_No; int nglob, nloc, ndim; iload(nglob); iload(nloc); iload(ndim); assert(ndim == 3); fload(t_global); fload(dt_global); iload(iteration); fload(courant_No); fload(gamma_gas); int periodic_on; iload(periodic_on); assert(periodic_on == -1); fload(rmin.x); fload(rmin.y); fload(rmin.z); fload(rmax.x); fload(rmax.y); fload(rmax.z); iload(itmp); // 20*4 assert(itmp == 20*4); ptcl_local.resize(nglob); U_local.resize(nglob); dU_local.resize(nglob); fprintf(stderr, "np =%d nglob= %d \n", np0, nglob); int pc = 0; for (int pr = 0; pr < np0; pr++) { fprintf(stderr, " p= %d out of %d; nloc= %d\n", pr, np0, nloc); for (int i = 0; i < nloc; i++) { Particle p; p.tend = t_global; p.rung = 0.0; p.new_dt = 0.0; p.local_id = i; Fluid W(0.0); iload(ival); assert(ival == 26*4); iload(ival); p.idx = ival; fload(p.pos.x); fload(p.pos.y); fload(p.pos.z); p.pos = periodic(p.pos); assert(rmin.x <= p.pos.x); assert(rmax.x >= p.pos.x); assert(rmin.y <= p.pos.y); assert(rmax.y >= p.pos.y); assert(rmin.z <= p.pos.z); assert(rmax.z >= p.pos.z); p.orig_pos = p.pos; p.pot = 0; fload(p.vel.x); fload(p.vel.y); fload(p.vel.z); p.orig_vel = p.vel; fload(W[Fluid::DENS]); fload(W[Fluid::ETHM]); fload(ftmp); // compute_pressure(m.dens, m.ethm)); fload(p.rmax); //dump( (sqr(m.B.x ) + sqr(m.B.y ) + sqr(m.B.z ))*0.5f); iload(p.boundary); // fload(ftmp); //dump(sqrt(sqr(m.vel.x) + sqr(m.vel.y) + sqr(m.vel.z))); fload(W[Fluid::VELX]); fload(W[Fluid::VELY]); fload(W[Fluid::VELZ]); fload(W[Fluid::BX]); fload(W[Fluid::BY]); fload(W[Fluid::BZ]); float h; fload(h); fload(p.volume); p.volume_new = p.volume; fload(W[Fluid::PSI]); fload(ftmp); //L*divB_i[i]); fload(W[Fluid::ENTR]); fload(ftmp); // Jx fload(ftmp); // Jy fload(ftmp); // Jz iload(ival); assert(ival == 26*4); p.tlast = t_global; ptcl_local[pc] = p; U_local [pc] = W; dU_local [pc] = 0.0; dU_local [pc] = 0.0; pc++; } fprintf(stderr, "p= %d np0= %d size= %d %d\n", pr, np0, (int)U_local.size(), (int)ptcl_local.size()); if (!(pr < np0-1)) break; iload(itmp); // 20*4 assert(itmp == 20*4); iload(itmp); // myid iload(np0); iload(npx); iload(npy); iload(npz); int nglob1; iload(nglob1); if (nglob != nglob1) { fprintf(stderr, "np; npx, npy, npz = %d; %d %d %d \n", np0, npx, npy, npz); fprintf(stderr, "nglob= %d nglob1= %d\n", nglob, nglob1); } assert(nglob == nglob1); iload(nloc); iload(ndim); fload(t_global); fload(dt_global); iload(iteration); fload(courant_No); fload(gamma_gas); iload(periodic_on); fload(rmin.x); fload(rmin.y); fload(rmin.z); fload(rmax.x); fload(rmax.y); fload(rmax.z); iload(itmp); // 20*4 } assert(pc == nglob); assert(nglob == (int)U_local.size()); fclose(fin); local_n = U_local.size(); } global_n = U_local.size(); local_n = global_n; MPI_Bcast(&global_n, 1, MPI_UNSIGNED_LONG_LONG, 0, MPI_COMM_WORLD); MPI_Bcast(&iteration, 1, MPI_INT, 0, MPI_COMM_WORLD); double dt_glob = dt_global; double t_glob = t_global; MPI_Bcast(& t_glob, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(&dt_glob, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(&scheduler.tsysU, 1, MPI_UNSIGNED_LONG_LONG, 0, MPI_COMM_WORLD); dt_global = dt_glob; t_global = t_glob; scheduler.set_tsys(t_global); assert(t_global == scheduler.get_tsys()); // scheduler.tsysU = (unsigned long long)(t_global / scheduler.dt_tick); scheduler.min_rung = 0; dt_global = 0.0f; distribute_data(true, false, true); #if 1 fit_vec(ptcl_local); fit_vec(U_local); fit_vec(dU_local); fit_vec(Wrec_local); #endif all_active = true; MPI_Barrier(MPI_COMM_WORLD); for (int i = 0; i < (int)local_n; i++) { ptcl_local[i].tlast = t_global; // ptcl_local[i].volume = cell_local[i].Volume; Wrec_local[i] = Fluid_rec(U_local[i]); U_local[i] = U_local[i].to_conservative(ptcl_local[i].volume); dU_local[i] = 0.0; } MPI_Barrier(MPI_COMM_WORLD); if (myproc == 0) fprintf(stderr , " pvel ... \n"); get_active_ptcl(true); MPI_Barrier(MPI_COMM_WORLD); if (myproc == 0) fprintf(stderr , " pvel ... \n"); cell_list.swap(cell_local); ptcl_import.swap(ptcl_local); U_import.swap(U_local); site_active_list.swap(active_ptcl); compute_pvel(); compute_timesteps(true); cell_list.swap(cell_local); ptcl_import.swap(ptcl_local); U_import.swap(U_local); site_active_list.swap(active_ptcl); for (int i = 0; i < (int)local_n; i++) { ptcl_local[i].rung += 1; ptcl_local[i].tend = ptcl_local[i].tlast + scheduler.get_dt(ptcl_local[i].rung); ptcl_local[i].orig_vel = ptcl_local[i].vel; ptcl_local[i].unset_active(); } all_active = true; scheduler.flush_list(); boundary_n = 0; for (int i = 0; i < (int)local_n; i++) { scheduler.push_particle(i, (int)ptcl_local[i].rung); if (ptcl_local[i].is_boundary()) boundary_n++; } unsigned long long boundary_glb; MPI_Allreduce(&boundary_n, &boundary_glb, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, MPI_COMM_WORLD); if (myproc == 0) fprintf(stderr, "boundary_glb= %lld\n", boundary_glb); clear_mesh(true); MPI_Barrier(MPI_COMM_WORLD); if (myproc == 0) fprintf(stderr, " proc= %d: complete read_binary \n", myproc); #endif }
int main( int argc , char * argv[ ] ) { FILE * pndx , * pdxdr , * pfreq , * patomlist , * passgn ; FILE * debug ; char dxdrname [ 50 ] , ndxname [ 50 ] , atomlistname [ 50 ] , freqname [ 50 ], outassgnname [ 50 ] ; char ** pcmd ; pcmd = argv ; int icmd , itmp ; int ncart , natom , nmode , nfreqprovide; int icart , iatom , imode , ifreq ; int exfreq , exatomlist ; int fakeOrNot = 0 ; time_t current_time; time( ¤t_time ); char now[ 300 ] ; strcpy( now , ctime( ¤t_time ) ); int lennow = strlen( now ) ; *( now + lennow - 1 ) = ' '; // ========> Recording Command-Line Arguments ... printf("\n**********************************************************************\n"); printf("* G_NMASSGN_D : Listing the localization of all vibrational modes. *\n"); printf("* *\n"); printf("* "); for( icmd = 0 ; icmd < argc ; icmd ++ ) { printf("%s " , *( pcmd + icmd ) ); } printf("\n"); printf("* *\n"); printf("* *\n"); printf("* Current Time : %s *\n" , now ); printf("* *\n"); printf("* *\n"); printf("**********************************************************************\n"); // =====> Setting up default file names ... strcpy( dxdrname , "dxdr.deb" ); strcpy( ndxname , "system.index" ); strcpy( freqname , "vibfrequency.deb" ); strcpy( outassgnname , "system.assgn" ); strcpy( atomlistname , "atom.list" ); // =====> Parsing command line input arguments ... if( argc == 1 ) { printf("\n\nNo command-line arguments provided ... Mission aborting ...\n\n"); printf("\nPlease refer to the usage by typing ' %s -h '\n\n" , * argv ); exit(1); } char * flag ; icmd = 1 ; while( icmd < argc ) { pcmd ++ ; flag = * pcmd ; printf("\nNo.%d argument , Currently @ flag = %s ...\n\n" , icmd , flag ); if( ( * flag == '-' ) && ( strlen( flag ) == 2 ) ) { switch ( *( flag + 1 ) ) { case 'f' : strcpy( dxdrname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Input dxdr File name : %s ...\n" , dxdrname ); icmd = icmd + 2 ; break ; case 'o' : strcpy( outassgnname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output File name : %s ...\n" , outassgnname ); icmd = icmd + 2 ; break ; case 'w' : strcpy( freqname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input frequency File name : %s ...\n" , freqname ); icmd = icmd + 2 ; break ; case 'n' : strcpy( ndxname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input index File name : %s ...\n" , ndxname ); icmd = icmd + 2 ; break ; case 'l' : strcpy( atomlistname , *( ++ pcmd ) ); if( ( strcmp( atomlistname , "none" ) ) == 0 ) { printf("\nCommand-line argument indicates : No AtomList needed ... Will not produce fake frequency file ...\n" ); fakeOrNot = 0 ; } else { printf("\nCommand-line argument indicates : Input atom list File name : %s ...\n" , atomlistname ); fakeOrNot = 1 ; } icmd = icmd + 2 ; break ; case 'h' : printf("\nUsage: %s [ -f 'input dxdr file name' ] [ -n 'input index file name (in GROMACS .ndx format)' ] [(optional) -o 'output NM assignment file name' ] [ -l atom list file (listing the atomic number of all atoms in system ; \"none\" if no frequency file desired)][ -w 'input vibrational frequency file ; best case length = nmode' ]\n\n" , * argv ); printf("\n\n==> NOTE : In order to be fool-proof , if there is mis-match on the NAtom between dxdr file and any other file , this code will set NAtom to be the number from dxdr automatically ...\n\n"); //printf("\nUsage: %s [ -t G09 calculation type : 1=ONIOM ; 2=Point Charge ] [ -f 'input gro file name' ] [(optional) -o 'output g09 file name' ] [ -n # of layers (integer) ] [ (optional) -r radius of middle layer (real) ] [-R radius of lower layer (real) ] [ -H method for Highest layer (string) ] [ (optional) -M method for Middle layer (string) ] [ -L method for Lower layer (string) ] [ -x input GMX .itp file ]\n\n" , * argv ); //exh = 9 ; icmd = icmd + 1 ; exit(1) ; default : printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); icmd = argc ; exit(1); } } else { printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); exit(1); } } // =====> Open the files ... if( ( pndx = fopen( ndxname , "r" ) ) == NULL ) { printf("\nUser-defined index file %s does not exist ...\n\n" , ndxname ); exit( 1 ); } if( ( pdxdr = fopen( dxdrname , "r" ) ) == NULL ) { printf("\nUser-defined dxdr file %s does not exist ...\n\n" , dxdrname ); exit( 1 ); } double * freq ; if( ( pfreq = fopen( freqname , "r" ) ) == NULL ) { printf("\nUser-defined frequency file %s does not exist ...\n\n" , freqname ); printf("\nBut it's OK , we will procede without frequency information ... \n"); exfreq = 0 ; } else { nfreqprovide = flength( pfreq ); rewind( pfreq ) ; freq = ( double * ) calloc( nfreqprovide , sizeof( double ) ) ; fload( pfreq , freq ); rewind( pfreq ); exfreq = 1 ; } int * atomlist , natomlistprovide ; if( fakeOrNot == 1 ) { if( ( patomlist = fopen( atomlistname , "r" ) ) == NULL ) { printf("\nUser-defined atom list file %s does not exist ...\n\n" , atomlistname ); printf("\nMeaning ... All of your atoms will be carbon ...\n"); exatomlist = 0 ; } else { natomlistprovide = flength( patomlist ); rewind( patomlist ); atomlist = ( int * ) calloc( natomlistprovide , sizeof( int ) ) ; int_fload( patomlist , atomlist ); exatomlist = 1 ; } } // =====> Read the index file (*****.ndx) ... int countlrb , countrrb ; int ngroup ; int ilrb , irrb , igroup ; char c ; char ** groupnames ; char tmpstring[ 100 ] ; char tmpchar ; // -----> Finding out how many groups are defined in index file ... ilrb = 0 ; irrb = 0 ; //fsearch( pndx , "begin" ); //fscanf( pndx , "%s" , tmpstring ); //if( strcmp( tmpstring , "]" ) != 0 ) //{ // printf("\nSomething is wrong with the ndx file format at the beginning ... Mission Aborting ... \n") ; // // exit(3); // //} //fskip( pndx , 1 ) ; rewind( pndx ) ; while( ( c = fgetc( pndx ) ) != EOF ) { if( c == '[' ) { ilrb ++ ; } else if( c == ']') { irrb ++ ; } else { continue ; } } if( ilrb == irrb ) { ngroup = ilrb ; printf("\nThere are %d defined groups in the index file ...\n" , ngroup ); } else { printf("\nSomething is wrong in the index file ... There are unmatched brackets or broken entries ...\n"); exit( 2 ); } if( ngroup == 0 ) { printf("\nThis index file is an empty file ... Mission Aborting ...\n"); exit(4); } // -----> Finding out how many atoms are in each group int * natom_in_each_group = calloc( ngroup , sizeof( int ) ) ; int current_atom_index , next_atom_index ; int info ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ) ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\n--------------------------> GROUP #%d <----------------------------" , igroup + 1 ); //itmp = 0 ; fsearch( pndx , "]" ) ; //fskip( pndx , 1 ) ; //printf("\nHere we are ... : %c " , fgetc( pndx ) ); fscanf( pndx , "%s" , tmpstring ); //printf("\nFor this group , the 1st grabbed tmpstring is %s ... \n" , tmpstring ); //while( strcmp( tmpstring , "[") != 0 ) for( itmp = 0 ; strcmp( tmpstring , "[" ) != 0 && info != EOF ; ) { //printf("\nGrabbed tmpstring is %s ... \n" , tmpstring ) ; if( strcmp( tmpstring , "-" ) == 0 ) { //printf("\nThe '-' situation happened ... before '-' we are at No.%d atom ... \n" , current_atom_index ); fscanf( pndx , "%d" , &next_atom_index ); //printf("\nAnd after '-' we are at No.%d atom ... \n" , next_atom_index ); itmp = itmp + ( next_atom_index - current_atom_index ); *( natom_in_each_group + igroup ) = itmp ; current_atom_index = next_atom_index ; info = fscanf( pndx , "%s" , tmpstring ) ; } else { itmp ++ ; *( natom_in_each_group + igroup ) = itmp ; current_atom_index = atoi( tmpstring ); //printf("\nNormal situation ... current_atom_index is %d ... \n" , current_atom_index ); info = fscanf( pndx , "%s" , tmpstring ); } } if( info == EOF ) { printf("\nHit the bottom of file ...\n\n") ; break ; } printf("\nDone with #%d group ... \n" , igroup + 1 ); } printf("\n--------------------------> Done checking up groups <----------------------------"); /* Debugging output for this part ... */ printf("\n== Group Information Summary ==\n"); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\nNo.%d Group Has %d atoms ...\n" , igroup + 1 , *( natom_in_each_group + igroup ) ); } // -----> Recording the name of each group ... groupnames = ( char ** ) calloc( ngroup , sizeof( char * ) ) ; int tmp_groupname_length ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fsearch( pndx , "[" ) ; fscanf( pndx , "%s" , tmpstring ); tmp_groupname_length = strlen( tmpstring ) ; *( groupnames + igroup ) = ( char * ) calloc( tmp_groupname_length + 3 , sizeof( char ) ) ; strcpy( *( groupnames + igroup ) , tmpstring ) ; printf("\nName of %d group is %s ...\n" , igroup + 1 , *( groupnames + igroup ) ); } // =====> Loading the eigenvectors ( dxdr file ) ... printf("\n--------------------------> Begin reading dxdr file ... <----------------------------" ); int len_dxdr = flength( pdxdr ) ; printf("\nThere are %d numbers in eigenvectors file ... \n" , len_dxdr ); ncart = sqrt( len_dxdr ); natom = ncart / 3 ; double * dxdr = calloc( len_dxdr , sizeof( double ) ) ; rewind( pdxdr ); fload( pdxdr , dxdr ) ; rewind( pdxdr ) ; printf("\nDone with loading dxdr file ... \n"); switch( natom ) { case 1 : printf("\nSeriously? Only ONE atom? ...\n") ; exit( 9 ) ; break ; case 2 : nmode = 6 ; break ; default : nmode = ncart - 0 ; break ; } if( exfreq == 0 ) { freq = ( double * ) calloc( nmode , sizeof( double ) ) ; dzeros( nmode , 1 , freq ) ; } else { if( nfreqprovide > nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is more than the normal mode we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_eigenvectors frequencies from the file you provided ...\n"); } else if( nfreqprovide < nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is less than the normal mode we have from eigenvectors ...\n"); printf("\nThe rest will be padded with zeros ... Sorry, I really don't want to do the diagonalization ...\n"); free( freq ) ; freq = ( double * ) calloc( nmode , sizeof( double ) ) ; rewind( pfreq ); fload( pfreq , freq ) ; dzeros( nmode - nfreqprovide , 1 , freq + nfreqprovide ) ; } } if( exatomlist == 0 ) { if( fakeOrNot == 1 ) { for( iatom = 0 ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } } else { if( natomlistprovide > natom ) { printf("\nOkay ... The number of atom you provided is more than the NAtom we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_atoms from the file you provided ...\n"); } else if( natomlistprovide < natom ) { printf("\nOkay ... The number of atom you provided is less than the NAtom we have from eigenvectors ...\n"); printf("\nSo all the rest will be automatically set as Carbon ... \n"); free( atomlist ); atomlist = ( int * ) calloc( natom , sizeof( int ) ) ; rewind( patomlist ); int_fload( patomlist , atomlist ); for( iatom = natom - natomlistprovide ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } } // =====> Loading the eigenvectors ( dxdr file ) ... // -----> Based on group information, prepare the recording structures (array) ... printf("\n=================================> _ <=====================================\n"); printf("\nStarting from here, we will actually read index file and give the assignment ... \n"); double * assgninfo = calloc( ngroup * nmode , sizeof( double ) ) ; rewind( pndx ) ; //fsearch( pndx , "begin" ); //fskip( pndx , 1 ) ; double tmp_xcomponent , tmp_ycomponent , tmp_zcomponent , tmp_magnitude ; //printf("\nDebugging ... Debugging ... % 12.8E\t% 12.8E\t% 12.8E\n\n" , *( dxdr + 3 ) , *( dxdr + 4 ) , *( dxdr + 5 ) ); info = 9 ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { printf("\n--------------------------> GROUP #%d : %s <----------------------------" , igroup + 1 , *( groupnames + igroup ) ); fsearch( pndx , "]" ) ; fscanf( pndx , "%s" , tmpstring ); //printf("\nFor this group , the 1st grabbed tmpstring is %s ... \n" , tmpstring ); for( itmp = 0 ; strcmp( tmpstring , "[" ) != 0 && info != EOF ; ) { //printf("\nGrabbed tmpstring is %s ... \n" , tmpstring ) ; if( strcmp( tmpstring , "-" ) == 0 ) { //printf("\nThe '-' situation happened ... before '-' we are at No.%d atom ... \n" , current_atom_index ); fscanf( pndx , "%d" , &next_atom_index ); //printf("\nAnd after '-' we are at No.%d atom ... \n" , next_atom_index ); itmp = itmp + ( next_atom_index - current_atom_index ); for( iatom = current_atom_index ; iatom < next_atom_index ; iatom ++ ) { //tmp_xcomponent = 0.0000 ; tmp_ycomponent = 0.0000 ; tmp_zcomponent = 0.0000 ; //tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; printf("\nWorking on No.%d atom ... in No.%d group ...\n" , iatom + 1 , igroup + 1 ); for( imode = 0 ; imode < nmode ; imode ++ ) { tmp_xcomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 0 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom X ... \n" , imode + 1 , tmp_xcomponent , iatom + 1 ); tmp_ycomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 1 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Y ... \n" , imode + 1 , tmp_ycomponent , iatom + 1 ); tmp_zcomponent = *( dxdr + ( 3 * ( iatom - 0 ) + 2 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Z ... \n" , imode + 1 , tmp_zcomponent , iatom + 1 ); tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; //printf("\nNO.%d mode has % 12.8E on #%d atom ... \n" , imode + 1 , tmp_magnitude , iatom + 1 ) ; *( assgninfo + igroup * nmode + imode ) = *( assgninfo + igroup * nmode + imode ) + tmp_magnitude ; printf("\nUp to No.%d atom , No.%d mode has % 12.8E on #%d group ...\n" , iatom + 1 , imode + 1 , *( assgninfo + igroup * nmode + imode ) , igroup + 1 ); } } current_atom_index = next_atom_index ; info = fscanf( pndx , "%s" , tmpstring ) ; } else { itmp ++ ; current_atom_index = atoi( tmpstring ); //printf("\nNormal situation ... current_atom_index is %d ... \n" , current_atom_index ); printf("\nWorking on No.%d atom ... in No.%d group ...\n" , current_atom_index , igroup + 1 ); for( imode = 0 ; imode < nmode ; imode ++ ) { tmp_xcomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 0 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom X ... \n" , imode + 1 , tmp_xcomponent , current_atom_index ); tmp_ycomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 1 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Y ... \n" , imode + 1 , tmp_ycomponent , current_atom_index ); tmp_zcomponent = *( dxdr + ( 3 * ( current_atom_index - 1 ) + 2 ) * nmode + imode ) ; //printf("\nNO.%d mode has % 12.8E on #%d atom Z ... \n" , imode + 1 , tmp_zcomponent , current_atom_index ); tmp_magnitude = tmp_xcomponent * tmp_xcomponent + tmp_ycomponent * tmp_ycomponent + tmp_zcomponent * tmp_zcomponent ; //printf("\nNO.%d mode has % 12.8E on #%d atom ... \n" , imode + 1 , tmp_magnitude , current_atom_index ) ; *( assgninfo + igroup * nmode + imode ) = *( assgninfo + igroup * nmode + imode ) + tmp_magnitude ; printf("\nUp to No.%d atom , No.%d mode has % 12.8E on #%d group ...\n" , current_atom_index , imode + 1 , *( assgninfo + igroup * nmode + imode ) , igroup + 1 ); } info = fscanf( pndx , "%s" , tmpstring ); } } if( info == EOF ) { printf("\nHit the bottom of file ...\n\n") ; break ; } printf("\nDone Loading Information of [ % 5d ] group ... \n" , igroup + 1 ); } /* Debugging output ... */ debug = fopen( "assgnfull.info" , "wb+" ); fprintf( debug , "Mode#\t" ) ; for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( debug , "% 12s\t" , *( groupnames + igroup ) ) ; } fprintf( debug , "vib-Frequencies" ); fprintf( debug , "\n\n" ); for( imode = 0 ; imode < nmode ; imode ++ ) { fprintf( debug , "%d\t" , imode + 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( debug , "% 12.8E\t" , *( assgninfo + igroup * nmode + imode ) ); } fprintf( debug , "% 12.8E\n\n" , *( freq + imode ) ) ; } // =====> Writing the output file ( MATLAB loadable pure number array file ) ... passgn = fopen( outassgnname , "wb+" ) ; fprintf( passgn , "\n\n" ); for( imode = 0 ; imode < nmode ; imode ++ ) { fprintf( passgn , "%d\t" , imode + 1 ); for( igroup = 0 ; igroup < ngroup ; igroup ++ ) { fprintf( passgn , "% 12.8E\t" , *( assgninfo + igroup * nmode + imode ) ); } fprintf( passgn , "% 12.8E\n\n" , *( freq + imode ) ) ; } // =====> Writing the output file ( MATLAB loadable pure number array file ) ... FILE * pfakefreq ; int ibatch = 0 ; int nbatch = nmode / 3 ; if( fakeOrNot == 1 ) { pfakefreq = fopen( "fakeg09.freq" , "wb+" ); if( natom == 1 ) { printf("\nReally? Really?? Really???\n\n"); exit( 1 ) ; } else if( natom == 2 ) { fprintf( pfakefreq , " 1\n A\nFrequencies -- %10.4f\n" , *( freq + 5 ) ) ; fprintf( pfakefreq , "Red. masses -- %10.4f\nFrc consts -- %10.4f\nIR Inten -- %10.4f\n Atom AN X Y Z \n" , 1.00 , 1.00 , 1.00 ); for( iatom = 0 ; iatom < natom ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d % 8.4f % 8.4f %8.4f\n" , iatom + 1 , *( atomlist + iatom ) , *( dxdr + 3 * iatom + 0 ) , *( dxdr + 3 * iatom + 1 ) , *( dxdr + 3 * iatom + 2 ) ); } } else { for( ibatch = 2 ; ibatch < nbatch ; ibatch ++ ) { fprintf( pfakefreq , " %5d %5d %5d\n" , 3 * ( ibatch - 2 ) + 1 , 3 * ( ibatch - 2 ) + 2 , 3 * ( ibatch - 2 ) + 3 ); fprintf( pfakefreq , " %5c %5c %5c\n" , 'A' , 'A', 'A' ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frequencies" , *( freq + 3 * ibatch + 0 ) , *( freq + 3 * ibatch + 1 ) , *( freq + 3 * ibatch + 2 ) ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Red. masses" , 1.00 , 1.00 , 1.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frc consts" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " IR Inten" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , " Atom AN X Y Z X Y Z X Y Z\n"); for( iatom = 0 ; iatom < natom ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d" , iatom + 1 , *( atomlist + iatom ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f\n" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) ) ; } } } } return( 0 ); } // The End ...
void init(void) { if(init_mblur() && init_vig() && init_quad()) { int size=0; void *data=NULL; /*glClearColor(1.0f,1.0f,1.0f,1.0f);*/ glClearColor(0.04f,0.0f,0.04f,1.0f); use_mblur(); send_mblur_samples(16.0f); /* adjust motion blur samples here */ use_vig(); send_vig_size((float)sw(),(float)sh()); vigmode(0); use_basic(); persp(proj,75.0f,asp(),0.1f,24.0f); if(fload("data/area-model.bin",&size,&data)) { add_to_vbo(&area_mod,data,size); free(data); update_vbo(); gen_texs(1,&area_tex); //if(load_tex_compressed(area_tex,"data/area-ao-texture.bin",tf_mipmap)) if(load_tex_compressed(area_tex,"data/area-texture.bin",tf_mipmap)) { const int downsample=1; /* adjust fb down-sizing here */ texmode(1); nsw=sw()/downsample; nsh=sh()/downsample; gen_texs(4,texs); gen_rbs(3,rbs); gen_fbs(4,fbos); use_fb(fbos[0]); add_fb_rb(0,rbs[0],nsw,nsh,GL_RGB8,4); /* adjust renderbuffer samples here */ add_fb_rb(0,rbs[1],nsw,nsh,GL_DEPTH_COMPONENT24,4); /* adjust renderbuffer samples here */ use_fb(fbos[1]); add_fb_tex(0,texs[0],nsw,nsh,GL_RGB8,tf_linear); add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0); use_fb(fbos[2]); add_fb_tex(0,texs[1],nsw,nsh,GL_RGB8,tf_linear); add_fb_tex(1,texs[2],nsw,nsh,GL_RGBA32F,tf_linear); add_fb_rb(0,rbs[2],nsw,nsh,GL_DEPTH_COMPONENT24,0); use_fb(fbos[3]); add_fb_tex(0,texs[3],nsw,nsh,GL_RGB8,tf_linear); use_fb(0); use_rb(0); use_tex(0); } else quit(); } else quit(); } else quit(); }
void vsmcreate(int argc, char *argv[]) { TVSMHeader head; // VSM file header TVSMResource res; // resource char *fdir = NULL; // working directory char *fn = NULL; // target file name TCRC csum; // checksum int i; FILE *f; char *tmp, *tmp2; char ch; // command line parameters int vendor_id = -1; bool dont_load_header = false; bool dont_incl_footer = false; int ins_version = 0; unsigned short int version[4]; // process arguments passed by command line for (i=2; i<argc; i++) { // -vid if (strcasecmp(argv[i], "-vid") == 0) { // there is no argument after -vid if (i+1 >= argc) errexit("Wrong parameter format '-vid'"); sscanf(argv[++i], "%u", &vendor_id); } // -dh else if (strcasecmp(argv[i], "-dh") == 0) dont_load_header = true; // -df else if (strcasecmp(argv[i], "-df") == 0) dont_incl_footer = true; // -v else if (strcasecmp(argv[i], "-v") == 0) { if (i+1 >= argc) errexit("Wrong parameter format '-v'"); ins_version = 1; if (sscanf(argv[++i], "%hd.%hd.%hd.%hd", &version[3], &version[2], &version[1], &version[0]) != 4) errexit("Wrong parameter format '-v'\nShould be '-v a.b.c.d'"); } // File or directory name else if (i+2 >= argc) { if (fdir == NULL) fdir = argv[i]; else fn = argv[i]; } // Incorrect parameter else { printf("Unknown argument: %s\n", argv[i]); errexit("Wrong parameter format"); } } // Directory not specified if (fdir == NULL) errexit("Input folder not specified"); // Target file not specified - generating filename from input folder if (fn == NULL) { fn = new char[strlen(fdir) + 5]; strcpy(fn, fdir); if (isSlash(fn)) fn[strlen(fn) -1] = '\0'; strcat(fn, ".vsm"); } // End directory path by '\' char: if (isSlash(fdir) == 0) { tmp = new char[strlen(fdir) + 2]; strcpy(tmp, fdir); strcat(tmp, "\\"); fdir = tmp; } // File information printf("Input folder: %s\n", fdir); printf("Output file: %s\n", fn); // Load header if (dont_load_header == false) { // open file tmp = new char[strlen(fdir) + 12]; strcpy(tmp, fdir); strcat(tmp, "header.bin"); i = fload(tmp, &head, sizeof(head)); delete [] tmp; // file doesn't exists if (i < 0) errexit("\nCan't open file 'header.bin'.\n" "Use '-dh' switch to generate default header"); else if (i != sizeof(head)) errexit("\nIncorrect file 'header.bin'.\n" "Use '-dh' switch to generate default header"); } // generate header else { memset(&head, 0, sizeof(head)); head.signature = VSMSignature; } // change vendor id if (vendor_id >= 0) head.vendor_id = vendor_id; // change version number if (ins_version) { for (i=0; i<4; i++) head.version[i] = version[i]; } // Show header info printf("Vendor ID: %d\n\n", head.vendor_id); // Check if output file already exists if (FileExist(fn)) { printf("File %s already exist. Overwrite? (y/N)\n\n", fn); ch = getch(); if ((ch != 'y') && (ch != 'Y')) exit(0); } // Open output file f = fopen(fn, "wb"); if (f == NULL) errexit("Can't create output file!"); // Write header puts("writing header"); if (fwrite(&head, sizeof(head), 1, f) <= 0) { fclose(f); errexit("Write error!"); } // Prepare to listing files tmp = new char[8192]; strcpy(tmp, fdir); tmp2 = tmp + strlen(tmp); strcat(tmp, "res*"); TFileList fl; char *fname = FLFindFirst(&fl, tmp); res.data = new char[VSMMaxResSize+1]; csum.newCRC32(); head.ressize = 0; // Write file while (fname) { i = ParseResName(fname); // given file is not a resource file - skip if (i < 0) continue; res.id = i; printf("writing resource 0x%04x from %s\n", res.id, fname); // read resource file strcpy(tmp2, fname); i = fload(tmp, res.data, VSMMaxResSize+1); if (i < 0) errexit("Can't read resource file!"); res.size = i; if (i >= VSMMaxResSize+1) errexit("Resource file is too big!"); // write to output file if (fwrite(&res, RHSIZE, 1, f) <= 0) errexit("Write error!"); if (fwrite(res.data, res.size, 1, f) <= 0) errexit("Write error!"); csum.add(&res, RHSIZE); csum.add(res.data, res.size); head.ressize += RHSIZE + res.size; // make sure that file end up with even address if (head.ressize & 1) { if (fwrite("\0", 1, 1, f) <= 0) errexit("Write error!"); head.ressize++; csum.add(0); } fname = FLFind(&fl); } // Writing footer if (dont_incl_footer == false) { // footer address (divided by 4) i = head.ressize & 3; if (i) { i = 4 - i; if (fwrite("\0\0\0", i, 1, f) <= 0) errexit("Write error!"); } // load footer strcpy(tmp2, "footer.bin"); i = fload(tmp, res.data, VSMMaxResSize); // if footer exists if (i != -1) { puts("writing footer"); // can't read footer.bin if (i < 0) errexit("\nCan't open file 'footer.bin'.\n" "Use '-df' switch if you don't need footer"); // footer.bin length is 0 if (i == 0) printf("\nFile 'footer.bin' is empty."); // write footer and check for errors else if (fwrite(res.data, i, 1, f) <= 0) errexit("Write error!"); } } // Update header checksum head.checksum = csum.getCRC32() ^ 0xffffffff; puts("updating header (checksum and resources size)\n"); fseek(f, 0, SEEK_SET); if (fwrite(&head, sizeof(head), 1, f) <= 0) errexit("Write error!"); fclose(f); fileinfo(&head, head.checksum); delete [] tmp; delete [] res.data; } // void vsmcreate(int argc, char *argv[])
int main( int argc , char * argv[ ] ) { FILE * pdxdr , * pfreq , * patomlist , * pfakefreq ; FILE * debug ; char dxdrname [ 50 ] , atomlistname [ 50 ] , freqname [ 50 ], outfreqname [ 50 ] ; char ** pcmd ; pcmd = argv ; int icmd , itmp ; int natom , ncart , nmode , nfreqprovide; int natomSelect , ncartSelect , nmodeSelect ; int icart , iatom , imode , ifreq ; int exfreq , exatomlist , exselect ; char buffer[ MAXCHARINLINE ] ; int lenBuff ; char cache[ MAXCHARINLINE ] ; char stmp[ 150 ] , stmp2[ 150 ] , tmpString[ 150 ]; time_t current_time; time( ¤t_time ); char now[ 300 ] ; strcpy( now , ctime( ¤t_time ) ); int lennow = strlen( now ) ; *( now + lennow - 1 ) = ' '; // ========> Recording Command-Line Arguments ... printf("\n**********************************************************************\n"); printf("* G_FAKEFREQ_D : Organize (DX/DR) into G09 Format for visualization. *\n"); printf("* *\n"); printf("* "); for( icmd = 0 ; icmd < argc ; icmd ++ ) { printf("%s " , *( pcmd + icmd ) ); } printf("\n"); printf("* *\n"); printf("* *\n"); printf("* Current Time : %s *\n" , now ); printf("* *\n"); printf("* *\n"); printf("**********************************************************************\n"); // =====> Setting up default file names ... strcpy( dxdrname , "dxdr.deb" ); strcpy( freqname , "vibfrequency.deb" ); strcpy( outfreqname , "fakeg09.freq" ); strcpy( atomlistname , "atom.list" ); // =====> Parsing command line input arguments ... exselect = 20 ; if( argc == 1 ) { printf("\n\nNo command-line arguments provided ... Mission aborting ...\n\n"); printf("\nPlease refer to the usage by typing ' %s -h '\n\n" , * argv ); exit(1); } char * flag ; icmd = 1 ; while( icmd < argc ) { pcmd ++ ; flag = * pcmd ; printf("\nNo.%d argument , Currently @ flag = %s ...\n\n" , icmd , flag ); if( ( * flag == '-' ) && ( strlen( flag ) == 2 ) ) { switch ( *( flag + 1 ) ) { case 'f' : strcpy( dxdrname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Input dxdr File name : %s ...\n" , dxdrname ); icmd = icmd + 2 ; break ; case 'o' : strcpy( outfreqname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Output File name : %s ...\n" , outfreqname ); icmd = icmd + 2 ; break ; case 'w' : strcpy( freqname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input frequency File name : %s ...\n" , freqname ); icmd = icmd + 2 ; break ; case 'l' : strcpy( atomlistname , *( ++ pcmd ) ); printf("\nCommand-line argument indicates : Input atom list File name : %s ...\n" , atomlistname ); icmd = icmd + 2 ; break ; case 's' : strcpy( tmpString , *( ++ pcmd ) ) ; if( strcmp( tmpString , "all" ) == 0 || strcmp( tmpString , "All" ) == 0 ) { exselect = 22 ; printf("\nCommand-line argument indicates : All atoms will be chosen as solute ...\n" ); } else { printf("\nReceived information : %s ...\n" , tmpString ) ; natomSelect = atoi( tmpString ); exselect = 21 ; printf("\nCommand-line argument indicates : First %d atoms will be chosen as solute ...\n" , natomSelect ); } icmd = icmd + 2 ; break ; case 'h' : printf("\nUsage: %s [ -f 'input dxdr file name' ] [(optional) -o 'output NM assignment file name' ] [ -l atom list file (listing the atomic number of all atoms in system)] [ -s # of atom selected to output ] [ -w 'input vibrational frequency file' ]\n\n" , * argv ); printf("\n\n==> NOTE : In order to be fool-proof , if there is mis-match on the NAtom between dxdr file and any other file , this code will set NAtom to be the number from dxdr automatically ...\n\n"); //printf("\nUsage: %s [ -t G09 calculation type : 1=ONIOM ; 2=Point Charge ] [ -f 'input gro file name' ] [(optional) -o 'output g09 file name' ] [ -n # of layers (integer) ] [ (optional) -r radius of middle layer (real) ] [-R radius of lower layer (real) ] [ -H method for Highest layer (string) ] [ (optional) -M method for Middle layer (string) ] [ -L method for Lower layer (string) ] [ -x input GMX .itp file ]\n\n" , * argv ); //exh = 9 ; icmd = icmd + 1 ; exit(1) ; default : printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); icmd = argc ; exit(1); } } else { printf("\n\nInvalid option ' %s ' ... Please refer to the usage by typing ' %s -h '\n\n" , flag , * argv ); exit(1); } } // =====> Open the files ... if( ( pdxdr = fopen( dxdrname , "r" ) ) == NULL ) { printf("\nUser-defined dxdr file %s does not exist ...\n\n" , dxdrname ); exit( 1 ); } double * freq ; if( ( pfreq = fopen( freqname , "r" ) ) == NULL ) { printf("\nUser-defined frequency file %s does not exist ...\n\n" , freqname ); printf("\nBut it's OK , we will procede without frequency information ... \n"); exfreq = 0 ; } else { nfreqprovide = flength( pfreq ); rewind( pfreq ) ; freq = ( double * ) calloc( nfreqprovide , sizeof( double ) ) ; fload( pfreq , freq ); rewind( pfreq ); exfreq = 1 ; } int * atomlist , natomlistprovide ; if( ( patomlist = fopen( atomlistname , "r" ) ) == NULL ) { printf("\nUser-defined atom list file %s does not exist ...\n\n" , atomlistname ); printf("\nMeaning ... All of your atoms will be carbon ...\n"); exatomlist = 0 ; } else { natomlistprovide = flength( patomlist ); rewind( patomlist ); atomlist = ( int * ) calloc( natomlistprovide , sizeof( int ) ) ; int_fload( patomlist , atomlist ); exatomlist = 1 ; } // =====> Loading the eigenvectors ( dxdr file ) ... printf("\n--------------------------> Begin reading dxdr file ... <----------------------------" ); int len_dxdr = flength( pdxdr ) ; printf("\nThere are %d numbers in eigenvectors file ... \n" , len_dxdr ); ncart = sqrt( len_dxdr ); natom = ncart / 3 ; double * dxdr = calloc( len_dxdr , sizeof( double ) ) ; rewind( pdxdr ); fload( pdxdr , dxdr ) ; rewind( pdxdr ) ; printf("\nDone with loading dxdr file ... \n"); switch( natom ) { case 1 : printf("\nSeriously? Only ONE atom? ...\n") ; exit( 9 ) ; break ; case 2 : nmode = 6 ; break ; default : nmode = ncart - 0 ; break ; } if( exfreq == 0 ) { freq = ( double * ) calloc( nmode , sizeof( double ) ) ; dzeros( nmode , 1 , freq ) ; } else { if( nfreqprovide > nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is more than the normal mode we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_eigenvectors frequencies from the file you provided ...\n"); } else if( nfreqprovide < nmode ) { printf("\nOkay ... The number of vibrational frequency you provided is less than the normal mode we have from eigenvectors ...\n"); printf("\nThe rest will be padded with zeros ... Sorry, I really don't want to do the diagonalization ...\n"); free( freq ) ; freq = ( double * ) calloc( nmode , sizeof( double ) ) ; rewind( pfreq ); fload( pfreq , freq ) ; dzeros( nmode - nfreqprovide , 1 , freq + nfreqprovide ) ; } } if( exatomlist == 0 ) { for( iatom = 0 ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } else { if( natomlistprovide > natom ) { printf("\nOkay ... The number of atom you provided is more than the NAtom we have from eigenvectors ...\n"); printf("\nSo I will take only the first #_of_atoms from the file you provided ...\n"); } else if( natomlistprovide < natom ) { printf("\nOkay ... The number of atom you provided is less than the NAtom we have from eigenvectors ...\n"); printf("\nSo all the rest will be automatically set as Carbon ... \n"); free( atomlist ); atomlist = ( int * ) calloc( natom , sizeof( int ) ) ; rewind( patomlist ); int_fload( patomlist , atomlist ); for( iatom = natom - natomlistprovide ; iatom < natom ; iatom ++ ) { *( atomlist + iatom ) = 6 ; } } } if( exselect == 20 ) { printf("\nBy default , all %d atoms are selected as solute ... \n\n" , natom ) ; natomSelect = natom ; } else if( exselect == 22 ) { printf("\nPer user's request , all %d atoms are selected as solute ... \n\n" , natom ) ; natomSelect = natom ; } else if( exselect == 21 ) { if( natomSelect > natom ) { printf("\nOops ... you requested %d atoms as solute but we only have %d atoms in G09 .inp file ... By default , all atoms are selected as solute ... \n\n" , natomSelect , natom ) ; natomSelect = natom ; } else if( natomSelect <= natom && natomSelect > 0 ) { printf("\nPer user's request , the first %d atoms are selected as solute ... \n\n" , natomSelect ) ; } else if( natomSelect <= 0 ) { printf("\n# of solute atom must be a positive integer!!!\n\n") ; exit( 52 ) ; } } ncartSelect = natomSelect * 3 ; switch( natomSelect ) { case 1 : printf("\nSeriously? Only ONE atom selected ? ...\n") ; exit( 9 ) ; break ; case 2 : nmodeSelect = 6 ; break ; default : nmodeSelect = ncartSelect - 0 ; break ; } // =====> Writing the output file ( MATLAB loadable pure number array file ) ... printf("\n--------------------------> Begin organizing dxdr file into G09 format... <----------------------------\n\n\n" ); pfakefreq = fopen( outfreqname , "wb+" ); int ibatch = 0 ; int nbatch = nmodeSelect / 3 ; if( natomSelect == 1 ) { printf("\nReally? Really?? Really???\n\n"); exit( 1 ) ; } else if( natomSelect == 2 ) { fprintf( pfakefreq , " 1\n A\nFrequencies -- %10.4f\n" , *( freq + 5 ) ) ; fprintf( pfakefreq , "Red. masses -- %10.4f\nFrc consts -- %10.4f\nIR Inten -- %10.4f\n Atom AN X Y Z \n" , 1.00 , 1.00 , 1.00 ); for( iatom = 0 ; iatom < natomSelect ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d % 8.4f % 8.4f %8.4f\n" , iatom + 1 , *( atomlist + iatom ) , *( dxdr + 3 * iatom + 0 ) , *( dxdr + 3 * iatom + 1 ) , *( dxdr + 3 * iatom + 2 ) ); } } else { for( ibatch = 2 ; ibatch < nbatch ; ibatch ++ ) { fprintf( pfakefreq , " %5d %5d %5d\n" , 3 * ( ibatch - 2 ) + 1 , 3 * ( ibatch - 2 ) + 2 , 3 * ( ibatch - 2 ) + 3 ); fprintf( pfakefreq , " %5c %5c %5c\n" , 'A' , 'A', 'A' ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frequencies" , *( freq + 3 * ibatch + 0 ) , *( freq + 3 * ibatch + 1 ) , *( freq + 3 * ibatch + 2 ) ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Red. masses" , 1.00 , 1.00 , 1.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " Frc consts" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , "%-12s -- %10.4f %10.4f %10.4f\n" , " IR Inten" , 10.00 , 10.00 , 10.00 ); fprintf( pfakefreq , " Atom AN X Y Z X Y Z X Y Z\n"); for( iatom = 0 ; iatom < natomSelect ; iatom ++ ) { fprintf( pfakefreq , "%5d%4d" , iatom + 1 , *( atomlist + iatom ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 0 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 1 ) ) ) ; fprintf( pfakefreq , " % 8.4f % 8.4f %8.4f\n" , *( dxdr + nmode * ( 3 * iatom + 0 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 1 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) , *( dxdr + nmode * ( 3 * iatom + 2 ) + ( 3 * ( ibatch + 0 ) + 2 ) ) ) ; } } } printf("\n==============> ALL DONE !!! ^-^ !!! <===============\n\n\n\n\n\n"); return( 0 ); } // The End ...