BOOL ui_load_onmov_file(void) { partition_t *p_partition = NULL; u32 partition_cnt = 0; u16 file_name[MAX_FILE_PATH] = {0}; hfile_t file = NULL; u8 identify[3] = {0}; u16 *p_line = NULL; partition_cnt = file_list_get_partition(&p_partition); if (partition_cnt > 0) { file_name[0] = p_partition[0].letter[0]; str_asc2uni(":\\onmov.txt", file_name + 1); } #ifdef WIN32 str_asc2uni("C:\\onmov.txt", file_name); #endif file = vfs_open(file_name, VFS_READ); if(file == NULL) { return FALSE; } vfs_read((void *)identify, 1, 2, file); if (strcmp(identify, "\xFF\xFE") && strcmp(identify, "\xFE\xFF")) { vfs_close(file); return FALSE; } p_line = freadline(file); if (p_line != NULL) { mtos_free(p_line); p_line = NULL; } while (TRUE) { p_line = freadline(file); if (p_line == NULL) { break; } parse(p_line); mtos_free(p_line); p_line = NULL; } vfs_close(file); return TRUE; }
bool LoadObjFile(U8 * model_file, VertexArray & varray) { U8 buffer[128]; FILE * f = fopen((const char *)model_file,"r"); if (f==NULL) return false; while (freadline(f,buffer,128)==0) { LoadObjFileStateMachine(buffer,varray); } return true; }
void socket_loadbans() { FILE *fp = fopen(DATA_DIR "/banned.txt", "r"); if (!fp) return; while (!feof(fp)){ char ip[24]; size_t len = freadline(fp, ip, 24); if (len < 10) //Minimum length an IP should be, including newline and null byte. break; ip[len - 1] = 0; //Strip newline. socket_ban(ip); } fclose(fp); }
int read_file_prop_uid(char* source, char *filename, char *uid, char* defaultvalue) { FILE *fd; char buffer[MAXLINESIZE] = {'\0'}; char temp_uid[PROPERTY_VALUE_MAX]; if ((source && filename && uid && defaultvalue) == 0) return -1; strncpy(uid, defaultvalue, PROPERTY_VALUE_MAX); fd = fopen(filename, "r"); if (fd!=NULL){ freadline(fd, buffer); strncpy(uid, buffer, PROPERTY_VALUE_MAX); fclose(fd); } if (property_get(source, temp_uid, "") <= 0) { LOGV("Property %s not readable\n", source); return -1; } strncpy(uid, temp_uid, PROPERTY_VALUE_MAX); if (strncmp(uid, buffer, PROPERTY_VALUE_MAX) != 0){ /*need to reopen file in w mode and write the property in the file*/ fd = fopen(filename, "w"); if (fd!=NULL){ fprintf(fd, "%s", uid); do_chown(filename, PERM_USER, PERM_GROUP); fclose(fd); }else{ LOGV("Can't open file %s \n", filename); return -1; } /*Success + the file was updated*/ return 1; } return 0; }
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 ) ; }
int main(void) { FILE* f; char str[MS]; int k; struct mylist* head=NULL, *head1 = NULL, *headr=NULL, *headr1=NULL, *kwn, *cir, *cir1; struct anime* mas=NULL, *mas1=NULL, *masr = NULL, *masr1 = NULL; setlocale(0, "russian"); printf("Тестирование функции readline из mystruct.c\n"); f = fopen("testread/test1.txt","r"); k = freadline(f, str, MS); if (strcmp(str, "bbbb") == 0 && k == 4) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); fclose(f); f = fopen("testread/test2.txt","r"); k = freadline(f, str, MS); if (strcmp(str, "bbbbb") == 0 && k == 5) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); fclose(f); f = fopen("testread/test3.txt","r"); k = freadline(f, str, MS); if (strcmp(str, "aba aba b") == 0 && k == 9) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); fclose(f); f = fopen("testread/test4.txt","r"); k = freadline(f, str, MS); if (strcmp(str, "trata trata") == 0 && k == 11) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED!"); fclose(f); f = fopen("testread/test5.txt","r"); k = freadline(f, str, MS); if (strcmp(str, "") == 0 && k == 0) printf("\nTest 5 - OK!"); else printf("\nTest 5 - FAILED!"); fclose(f); f = fopen("testread/test6.txt","r"); k = freadline(f, str, 3); if (strcmp(str, "AA") == 0 && k == 2) printf("\nTest 6 - OK!"); else printf("\nTest 6 - FAILED!"); fclose(f); printf("\n\nТестирование функции readdate из mystruct.c\n"); mas = malloc(sizeof(struct anime)); f = fopen("testread/test_d.txt","r"); readdate(f, mas); if (strcmp(mas->name, "One Punch Man") == 0 && strcmp(mas->stud, "Madhouse") == 0 && mas->year==2015) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); readdate(f, mas); if (strcmp(mas->name, "Overlord") == 0 && strcmp(mas->stud, "Mad House") == 0 && mas->year==2014) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); fclose(f); free(mas); mas = NULL; printf("\n\nТестирование функции readfile из mystruct.c\n"); mas = NULL; f = fopen("testread/test_d.txt","r"); mas = readfile(f, &k); if (strcmp(mas->name, "One Punch Man") == 0 && strcmp(mas->stud, "Madhouse") == 0 && mas->year==2015 && k == 2 && strcmp((mas+1)->name, "Overlord") == 0 && strcmp((mas+1)->stud, "Mad House") == 0 && (mas+1)->year==2014) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free(mas); mas = NULL; fclose(f); mas = NULL; f = fopen("testread/test_de.txt","r"); mas = readfile(f, &k); if (mas == NULL && k == 0) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free(mas); mas = NULL; fclose(f); printf("\n\nТестирование функции formlist из mystruct.c\n"); mas = NULL; f = fopen("testread/test_d.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (strcmp(((struct anime*) head->date)->name, "One Punch Man") == 0 && strcmp(((struct anime*) head->date)->stud, "Madhouse") == 0 && ((struct anime*) head->date)->year==2015 && k == 2 && strcmp(((struct anime*) head->next->date)->name, "Overlord") == 0 && strcmp(((struct anime*) head->next->date)->stud, "Mad House") == 0 && ((struct anime*) head->next->date)->year==2014) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free_list(head); head = NULL; free(mas); mas = NULL; fclose(f); mas = NULL; head = NULL; f = fopen("testread/test_de.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (head == NULL) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free_list(head); head = NULL; free(mas); mas = NULL; fclose(f); printf("\n\nТестирование функции namecmp из mystruct.c\n"); mas = malloc(2*sizeof(struct anime)); snprintf(mas->name, MS, "AAA"); snprintf(mas->stud, MS, "A"); mas->year = 0; snprintf((mas+1)->name, MS, "BBB"); snprintf((mas+1)->stud, MS, "A"); mas->year = 0; head = create_mylist(mas); head1 = create_mylist(mas+1); if (namecmp(head, head1) < 0) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); snprintf(mas->name, MS, "CCC"); if (namecmp(head, head1) > 0) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); snprintf((mas+1)->name, MS, "CCC"); if (namecmp(head, head1) == 0) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); free(mas); mas = NULL; mas = NULL; free(head); head = NULL; free(head1); head1 = NULL; printf("\n\nТестирование функции lookup из exfunclo.c\n"); mas1 = malloc(sizeof(struct anime)); snprintf(mas1->name, MS, "AAABBB"); snprintf(mas1->stud, MS, "AAA"); mas1->year = 24; head1 = create_mylist(mas1); f = fopen("testlook/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (lookup(head, head1, namecmp) != NULL) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free_list(head); head = NULL; head = NULL; free(mas); mas = NULL; mas = NULL; fclose(f); free(head1); head1 = create_mylist(mas1); f = fopen("testlook/test2.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (lookup(head, head1, namecmp) != NULL) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free_list(head); head = NULL; head = NULL; free(mas); mas = NULL; mas = NULL; fclose(f); f = fopen("testlook/test3.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (lookup(head, head1, namecmp) != NULL) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); free_list(head); head = NULL; head = NULL; free(mas); mas = NULL; mas = NULL; fclose(f); f = fopen("testlook/test4.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (lookup(head, head1, namecmp) == NULL) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED!"); free_list(head); head = NULL; head = NULL; free(mas); mas = NULL; mas = NULL; fclose(f); f = fopen("testlook/test5.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); if (lookup(head, head1, namecmp) == NULL) printf("\nTest 5 - OK!"); else printf("\nTest 5 - FAILED!"); free_list(head); head = NULL; head = NULL; free(mas); mas = NULL; mas = NULL; fclose(f); printf("\n\nТестирование функции insert из exfunclo.c\n"); f = fopen("testins/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testins/test11.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); insert(&head, head1); int s = 0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free_list(head); head = NULL; free(mas); mas = NULL; free_list(headr); headr = NULL; free(masr); masr = NULL; free(mas1); mas1 = NULL; mas1 = malloc(sizeof(struct anime)); snprintf(mas1->name, MS, "AAABBB"); snprintf(mas1->stud, MS, "AAA"); mas1->year = 24; head1 = create_mylist(mas1); f = fopen("testins/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testins/test12.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); kwn = head->next->next->next; insert(&kwn, head1); s = 0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free_list(head); head = NULL; free(mas); mas = NULL; free_list(headr); headr = NULL; free(masr); masr = NULL; free(mas1); mas1 = NULL; f = fopen("testins/test2.txt","r"); mas1 = malloc(sizeof(struct anime)); snprintf(mas1->name, MS, "AAABBB"); snprintf(mas1->stud, MS, "AAA"); mas1->year = 24; head1 = create_mylist(mas1); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); insert(&head, head1); if (allcmp(head, head1) == 0 && head->next == NULL) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); free(mas1); mas1 = NULL; free(mas); mas = NULL; free(head); head = NULL; printf("\n\nТестирование функции remove_duplicates из exfunclo.c\n"); f = fopen("testrmd/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testrmd/test1r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); remove_duplicates(head, namecmp); s=0; if (head == headr && head == NULL) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testrmd/test2.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testrmd/test2r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); remove_duplicates(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testrmd/test3.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testrmd/test3r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); remove_duplicates(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testrmd/test4.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testrmd/test4r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); remove_duplicates(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; printf("\n\nТестирование функции front_back_split из exfunclo.c\n"); headr = front_back_split(head); if (head == NULL && headr == NULL) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); f = fopen("testfbs/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testfbs/test1r1.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); f = fopen("testfbs/test1r2.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); head1 = front_back_split(head); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; for (cir = head1, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testfbs/test2.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testfbs/test2r1.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); f = fopen("testfbs/test2r2.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); head1 = front_back_split(head); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; for (cir = head1, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testfbs/test3.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testfbs/test3r1.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); f = fopen("testfbs/test3r2.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); head1 = front_back_split(head); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; for (cir = head1, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; printf("\n\nТестирование функции sorted_merge из exfunclo.c"); f = fopen("testmerge/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test1a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test1r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 1 - OK!"); else printf("\nTest 1 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test2.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test2a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test2r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; free_list(head1); head1 = NULL; free(masr); masr = NULL; //free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test3.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test3a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test3r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED"); free(mas); mas = NULL; free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test4.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test4a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test4r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED"); free(mas); mas = NULL; //free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test5.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test5a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test5r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 5 - OK!"); else printf("\nTest 5 - FAILED"); free(mas); mas = NULL; //free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test6.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test6a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test6r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 6 - OK!"); else printf("\nTest 6 - FAILED"); free(mas); mas = NULL; //free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test7.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test7a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test7r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 7 - OK!"); else printf("\nTest 7 - FAILED"); free(mas); mas = NULL; //free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; f = fopen("testmerge/test8.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testmerge/test8a.txt", "r"); mas1 = readfile(f, &k); head1 = formlist(head1, mas1, k); fclose(f); f = fopen("testmerge/test8r.txt", "r"); masr1 = readfile(f, &k); headr1 = formlist(headr1, masr1, k); fclose(f); headr = sorted_merge(head, head1, namecmp); s=0; for (cir = headr, cir1 = headr1; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); s += cir || cir1; if (s == 0) printf("\nTest 8 - OK!"); else printf("\nTest 8 - FAILED"); free(mas); mas = NULL; //free_list(head); head = NULL; free(mas1); mas1 = NULL; //free_list(head1); head1 = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; free(masr1); masr1 = NULL; free_list(headr1); headr1 = NULL; printf("\n\nТестирование функции merge_sort из exfunclo.c\n"); f = fopen("testbacisort/test1.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testbacisort/test1r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); head = merge_sort(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("Test 1 - OK!"); else printf("Test 1 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testbacisort/test2.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testbacisort/test2r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); head = merge_sort(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 2 - OK!"); else printf("\nTest 2 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testbacisort/test3.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testbacisort/test3r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); head = merge_sort(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 3 - OK!"); else printf("\nTest 3 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testbacisort/test4.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testbacisort/test4r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); head = merge_sort(head, namecmp); s=0; if (head == headr && head == NULL) printf("\nTest 4 - OK!"); else printf("\nTest 4 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; f = fopen("testbacisort/test5.txt","r"); mas = readfile(f, &k); head = formlist(head, mas, k); fclose(f); f = fopen("testbacisort/test5r.txt", "r"); masr = readfile(f, &k); headr = formlist(headr, masr, k); fclose(f); head = merge_sort(head, namecmp); s=0; for (cir = head, cir1 = headr; cir && cir1; cir = cir->next, cir1 = cir1->next) s += allcmp(cir, cir1); if (s == 0 && cir == NULL && cir1 == NULL) printf("\nTest 5 - OK!"); else printf("\nTest 5 - FAILED!"); free(mas); mas = NULL; free_list(head); head = NULL; free(masr); masr = NULL; free_list(headr); headr = NULL; return 0; }
int main( int argc, char * argv[] ) { FILE * pgroinput , * pitpinput , * pCNDOoutput ; char inpgroname[ MAXCHARINLINE ] , inpitpname[ MAXCHARINLINE ] , outCNDOname[ MAXCHARINLINE ] ; int multiplicity , charge ; int natom , ncart , natomselect , natomDump ; int iatom ; double dtmp ; double dtmpArray[ MAXCHARINLINE ] ; int itmp ; char tmpString[ MAXCHARINLINE ] ; // --------> Declaring utility functions ... double tellmass( char * atomMDname ) ; int tellatom( char * atomMDname ) ; void dzeros( int dimrow, int dimcol, double *p ) ; void izeros( int dimrow, int dimcol, int *p ) ; // --------> Some default values ... multiplicity = 1 ; charge = 0 ; // ==============> Handling the file names and Charge & Multiplicity ... <========= // // -------> Parsing the Command Line Arguments ... char ** pcmd ; pcmd = argv ; //pcmd ++ ; int icmd = 1 ; //int exn = 10 ; int exr = 16 ; int exR = 18 ; int exH = 22 ; int exM = 28 ; int exL = 30 ; int exf = 1 ; int exo = 3 ; int exx = 36 ; int exs = 18 ; int exD = 28 ; char * flag ; 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 'f' : strcpy( inpgroname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Input File name : %s ...\n" , inpgroname ); exf = 7 ; icmd = icmd + 2 ; break ; case 'o' : strcpy( outCNDOname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Output File name : %s ...\n" , outCNDOname ); exo = 9 ; icmd = icmd + 2 ; break ; case 'x' : strcpy( inpitpname , *( ++ pcmd ) ) ; if( strcmp( inpitpname , "dummy") == 0 || strcmp( inpitpname , "none") == 0 || strcmp( inpitpname , "None") == 0 ) { exx = 99 ; printf("\nLooks like we are not using point charge here ... \n") ; } else { printf("\nCommand-line argument indicates : Input .itp File name : %s ...\n" , inpitpname ); exx = 37 ; } icmd = icmd + 2 ; break ; case 's' : strcpy( tmpString , *( ++ pcmd ) ) ; if( strcmp( tmpString , "all" ) == 0 || 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 'D' : strcpy( tmpString , *( ++ pcmd ) ) ; if( strcmp( tmpString , "all" ) == 0 || strcmp( tmpString , "All" ) == 0 || strcmp( tmpString , "ALL" ) == 0 ) { exD = 30 ; printf("\nCommand-line argument indicates : All atoms will be chosen to be dumped in output file ...\n" ); } else if( strcmp( tmpString , "solute" ) == 0 || strcmp( tmpString , "Solute" ) == 0 || strcmp( tmpString , "SOLUTE" ) == 0 ) { exD = 31 ; printf("\nCommand-line argument indicates : Only selected solute atoms will be chosen to be dumped in output file ...\n" ); } else { printf("\nReceived information : %s ...\n" , tmpString ) ; natomDump = atoi( tmpString ); exD = 29 ; printf("\nCommand-line argument indicates : First %d atoms will be dumped into output file ...\n" , natomDump ); } icmd = icmd + 2 ; break ; /* case 'r' : radiusM = atof( *( ++ pcmd ) ); exr = 17 ; printf("\nCommand-line argument indicates : User defined radius for middle layer : %12.8f ...\n" , radiusM ); icmd = icmd + 2 ; break ; case 'R' : radiusL = atof( *( ++ pcmd ) ); exR = 19 ; printf("\nCommand-line argument indicates : User defined radius for lower layer : %12.8f ...\n" , radiusL ); icmd = icmd + 2 ; break ; case 'H' : strcpy( highest_method , *( ++ pcmd ) ); exH = 23 ; printf("\nCommand-line argument indicates : User defined method for Highest layer : %s ...\n" , highest_method ); icmd = icmd + 2 ; break ; case 'M' : strcpy( middle_method , *( ++ pcmd ) ); exM = 29 ; printf("\nCommand-line argument indicates : User defined method for Middle layer : %s ...\n" , middle_method ); icmd = icmd + 2 ; break ; case 'L' : strcpy( lower_method , *( ++ pcmd ) ); exL = 31 ; printf("\nCommand-line argument indicates : User defined method for Lower layer : %s ...\n" , lower_method ); icmd = icmd + 2 ; break ; */ case 'h' : printf("\nUsage: %s [ -f 'input gro file name' ] [(optional) -o 'output CNDO input file name' ] [ -x input GMX .itp file ] [ -s # of atoms chosen as the solute ] [ -D # of atoms chosen to be Dumped in output file ]\n\n" , * argv ); printf("\nNOTE : 1) [ -s all ] or [ -s All ] indicates all atoms chosen as solute;\n\n 2) Default for -s is all atoms when nresidue = 1 or natom in 1st residue when nresidue != 1 \n"); printf("\n 3) User can use [ -x none / None / dummy ] to indicate all selected atoms ( may be less than total number of atoms ) will be treated as solute \n\n"); //printf("\m 3) ") ; //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); } } // --------> Setting DEFAULT value for important variables ... char defoutname[ MAXCHARINLINE ] , definpname[ MAXCHARINLINE ] , defitpname[ MAXCHARINLINE ]; int inputnamelength , outputnamelength , inputitpnamelength; printf("\nID = %d ...\n" , exo * exf * exx ); switch( exo * exf * exx ) // File Names ... int exf = 1 / 7 ; int exo = 3 / 9; int exx = 36 / 37 - 99 ; { case 108 : strcpy( inpgroname , "sys.gro" ); strcpy( inpitpname , "sys.itp" ); strcpy( outCNDOname , "sys.dat" ); break ; case 1*3*99 : strcpy( inpgroname , "sys.gro" ); //strcpy( inpitpname , "sys.itp" ); strcpy( outCNDOname , "sys.dat" ); break ; case 756 : inputnamelength = strlen( inpgroname ) ; strncpy( defoutname, inpgroname , inputnamelength - 4 ) ; *( defoutname + inputnamelength - 4 ) = '\0' ; strcat( defoutname, ".dat") ; strcpy( outCNDOname , defoutname ) ; strncpy( defitpname , inpgroname , inputnamelength - 4 ); *( defitpname + inputnamelength - 4 ) = '\0' ; strcat( defitpname , ".itp" ); strcpy( inpitpname , defitpname ); break ; case 3*7*99 : inputnamelength = strlen( inpgroname ) ; strncpy( defoutname, inpgroname , inputnamelength - 4 ) ; *( defoutname + inputnamelength - 4 ) = '\0' ; strcat( defoutname, ".dat") ; strcpy( outCNDOname , defoutname ) ; break ; case 7*9*99 : printf("\n\nHoorayyyyyyyy ... Both input and output name are specified !!!\n\n"); printf("\nAnd ... We don't need itp file ! \n"); break ; case 324 : outputnamelength = strlen( outCNDOname ) ; strncpy( definpname, outCNDOname , outputnamelength - 4 ) ; *( definpname + outputnamelength - 4 ) = '\0' ; strcat( definpname, ".gro") ; strcpy( inpgroname , definpname ); strncpy( defitpname , outCNDOname , outputnamelength - 4 ); *( defitpname + outputnamelength - 4 ) = '\0' ; strcat( defitpname , ".itp" ); strcpy( inpitpname , defitpname ); break ; case 1*9*99 : outputnamelength = strlen( outCNDOname ) ; strncpy( definpname, outCNDOname , outputnamelength - 4 ) ; *( definpname + outputnamelength - 4 ) = '\0' ; strcat( definpname, ".gro") ; strcpy( inpgroname , definpname ); break ; case 111 : strcpy( inpgroname , "sys.gro" ); strcpy( outCNDOname , "sys.inp" ); break ; case 777 : inputnamelength = strlen( inpgroname ) ; strncpy( defoutname, inpgroname , inputnamelength - 4 ) ; *( defoutname + inputnamelength - 4 ) = '\0' ; strcat( defoutname, ".dat") ; strcpy( outCNDOname , defoutname ) ; break ; case 2331 : printf("\n\nHoorayyyyyyyy ... All file names are specified !!!\n\n"); break ; case 333 : outputnamelength = strlen( outCNDOname ) ; strncpy( definpname, outCNDOname , outputnamelength - 4 ) ; *( definpname + outputnamelength - 4 ) = '\0' ; strcat( definpname, ".gro") ; strcpy( inpgroname , definpname ); break ; } // --------------> Summarizing and File Access ... printf("\n\nInput GMX .gro file name is : %s ...\n" , inpgroname ); printf("\nOutput CNDO dat file name is %s ...\n" , outCNDOname ); if( ( pitpinput = fopen( inpitpname , "r" ) ) == NULL && exx != 99 ) { printf("\nUser defined .itp file %s does not exist ... \n" , inpitpname ); exit( 3 ); } // ==============> Reading information from GMX .gro file ... <========= // char grotitlestring[MAXLINE]; int iline = 3 ; int iload = 0 ; int blank_signal , groinfo ; char buffer[ MAXCHARINLINE ] ; char cache[ MAXCHARINLINE ] ; char tmp_char ; int natomgroline , natomgrotitle ; int exVelocity = 0 ; if( ( pgroinput = fopen( inpgroname , "r" ) ) == NULL ) { printf("\nUser defined .gro file %s does not exist ... \n" , inpgroname ); exit( 3 ); } else { rewind( pgroinput ); //printf("\nCurrent character is %c ... \n" , fgetc( pEqGRO ) ); fskip( pgroinput , 1 ); fscanf( pgroinput , "%d" , &natomgrotitle ); fskip( pgroinput , 1 ); printf("\n Second line of .gro file says it is describing %d atoms ... \n\n" , natomgrotitle ); while( ( groinfo = freadline( buffer , MAXCHARINLINE , pgroinput , ';' ) ) != 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"); rewind( pgroinput ) ; fskip( pgroinput , 2 ) ; while( ( groinfo = freadline( buffer , MAXCHARINLINE , pgroinput , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); //info = freadline( buffer , MAXCHARINLINE , pinputfile , ';' ); //printf("\nNow we are at : %s\n" , buffer ); //printf("\n INFO is %d ...\n" , info ); 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 ); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; }//while( info != 0 ); natomgroline = iload - 1 ; // Because the last line is boxvector line . 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 ; // =====> Actually Reading the GRO File ... GRO atomlist[ natom ] ; rewind( pgroinput ); fskip( pgroinput , 1 ); fskip( pgroinput , 1 ); printf("\nNow let's read the actual .gro file ... \n"); iload = 0 ; iline = 0 ; while( ( groinfo = freadline( buffer , MAXCHARINLINE , pgroinput , ';' ) ) != 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" , &atomlist[ iload ].resnumber , atomlist[ iload ].resname ); //printf( "%s\t" , atomlist[ iatom ].resname ); //sscanf( pEqGRO , "%s" , EqAtomList[ iload ].atomname ); strpickword( buffer , 2 , cache ) ; strcpy( atomlist[ iload ].atomname , cache ) ; //printf( "%s" , atomlist[ iatom ].atomname ); //sscanf( pEqGRO , "%d" , &EqAtomList[ iload ].atomnumber ); strpickword( buffer , 3 , cache ) ; atomlist[ 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 ) ; atomlist[ iload ].cx = atof( cache ) ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cy ); //printf("\n Cy is %lf ...\t" , EqAtomList[ iatom ].cy); strpickword( buffer , 5 , cache ) ; atomlist[ iload ].cy = atof( cache ) ; //sscanf( pEqGRO , "%lf" , &EqAtomList[ iload ].cz ); //printf("\n Cz is %lf ...\n\n" , EqAtomList[ iatom ].cz); strpickword( buffer , 6 , cache ) ; atomlist[ iload ].cz = atof( cache ) ; if( exVelocity == YES ) { strpickword( buffer , 7 , cache ) ; atomlist[ iload ].vx = atof( cache ) ; strpickword( buffer , 8 , cache ) ; atomlist[ iload ].vy = atof( cache ) ; strpickword( buffer , 9 , cache ) ; atomlist[ 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); } if( iload == natom ) break ; iline ++ ; } if( natomgrotitle < natomgroline ) { fskip( pgroinput , natomgroline - natomgrotitle ) ; } double boxvector[ 3 ]; fscanf( pgroinput , "%lf" , boxvector + 0 ); fscanf( pgroinput , "%lf" , boxvector + 1 ); fscanf( pgroinput , "%lf" , boxvector + 2 ); // ---------------> Figuring out how many solvent molecules (residues) are in the system ... int nresidue = atomlist[ natom - 1 ].resnumber ; // ---------------> Figuring out how many atoms are in each residue ... int * n_of_atom_in_residues = calloc( nresidue , sizeof( int ) ) ; izeros( nresidue , 1 , n_of_atom_in_residues ); //double * molecularmass = calloc( nresidue , sizeof( double ) ) ; //dzeros( nresidue , 1 , molecularmass ); int iresidue = 1 ; for( iatom = 0 ; iatom < natom ; iatom ++ ) { if( atomlist[ iatom ].resnumber == ( iresidue + 1 ) ) { //printf("\n#%d residue has %d atoms ...\n" , iresidue , *( n_of_atom_in_residues + iresidue - 1 ) ); iresidue ++ ; //printf("\n\nStarting ... # %d residue (molecule) ... \n\n" , iresidue ); } else if( atomlist[ iatom ].resnumber == iresidue ) { //printf("\nStill in this residue ... \n"); //continue ; } else { printf("\nSomething is wrong with the atomlist or atomcast ... Mission Aborting ...\n\n"); exit(1); } *( n_of_atom_in_residues + iresidue - 1 ) = *( n_of_atom_in_residues + iresidue - 1 ) + 1 ; ///*( molecularmass + iresidue - 1 ) = *( molecularmass + iresidue - 1 ) + atomcast[ iatom ].atommass ; } //Just debugging ... for( iresidue = 1 ; ( iresidue - 1 ) < nresidue ; iresidue ++ ) { printf("\nThere are %d atoms in No. %d residue ... \n" , *( n_of_atom_in_residues + iresidue - 1 ) , iresidue ); //printf("\nThe molecular mass of No. %d residue is %lf ...\n" , iresidue , *( molecularmass + iresidue - 1 ) ); } //---> Dealing with the "Default senario " of Chosen Atoms ... if( exs == 18 && nresidue == 1 ) { natomselect = natom ; } else if( exs == 18 && nresidue > 1 ) { natomselect = *( n_of_atom_in_residues + 0 ) ; } 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 for rotation ... 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 ); } if( exD == 28 ) { natomDump = natom ; } else if( exD == 30 ) { natomDump = natom ; } else if( exD == 31 ) { natomDump = natomselect ; printf("\nBased on command-line input , only [ %d ] solute atoms will be dumped ...\n\n" , natomselect ) ; } else if( exD == 29 ) { if( natomDump <= natom && natomDump > natomselect ) { printf("\nBased on command-line input , besides solute , [ %d ] atoms from solvent will be dumped ...\n\n" , natomDump - natomselect ) ; } else if( natomDump == natomselect ) { printf("\nBased on command-line input , only [ %d ] solute atoms will be dumped ...\n\n" , natomselect ) ; } else if( natomDump < natomselect && natomDump >= 0 ) { printf("\nWARNING : You chose to dump ONLY PART OF SOLUTE atoms [ %d ] into your cndo .dat file ...\n\n" , natomDump ) ; } else if( natomDump < 0 ) { natomDump = natomselect ; printf("\nBased on command-line input , only [ %d ] solute atoms will be dumped ...\n\n" , natomselect ) ; } else if( natomDump > natom ) { printf("\nWARNING : There are in total only [ %d ] atoms in the system , so you cannot request more than [ %d ] atoms dumped ...\n\n" , natom , natom ) ; printf("\nNow we re-set the natomDump to be natom ...\n\n" ) ; natomDump = natom ; } } // -------------------------------> Reading ITP File ... <---------------------------------- // int itpinfo , natomITP ; if( exx != 99 ) { // =====> Pre-Loading ... printf("\nNow let's pre-load the .itp file and see how many atoms it is describing ... \n"); iline = 1 ; iload = 0 ; fsearch( pitpinput , "atoms" ) ; fskip( pitpinput , 1 ); while( ( itpinfo = freadline( buffer , MAXCHARINLINE , pitpinput , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); //info = freadline( buffer , MAXCHARINLINE , pinputfile , ';' ); //printf("\nNow we are at : %s\n" , buffer ); //printf("\n INFO is %d ...\n" , info ); blank_signal = stellblank( buffer ) ; if( blank_signal == 0 ) { printf("\nNo.%d line is a blank line ... Moving on ...\n" , iline ) ; } 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 ); } else if( ( tmp_char = getfirst( buffer ) ) == '[' ) { printf("\nSTARTING OF NEW DIRECTIVE ... END READING ... \n\n"); break ; } else { //printf("\nLine reads : %s ...\n" , buffer ); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; }//while( info != 0 ); natomITP = iload ; printf("\nThere are %d atoms described in itp file ...\n" , natomITP ); /* if( natomITP != natomselect ) { printf("\nWhile you specified you wanted %d atoms as the solute, in your itp file, there are only %d atoms being described ...\n" , natomsoluteSelect , natomITP ); printf("\nPlease check your itp file and make sure the # of atoms match ...\n"); printf("\nWe will continue anyway but once we find any required info does not exist in your itp file , we will terminate this process immediately ...\n\n") ; } */ } else { natomITP = natom ; natomselect = natom ; } ITP atomdatabase[ natomITP ]; if( exx != 99 ) { // =====> Loading ... printf("\nNow let's actually load the .itp file ... \n"); iline = 1 ; iload = 0 ; //ITP atomdatabase[ natomITP ]; rewind( pitpinput ) ; fsearch( pitpinput , "atoms" ) ; fskip( pitpinput , 1 ); while( ( itpinfo = freadline( buffer , MAXCHARINLINE , pitpinput , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); //info = freadline( buffer , MAXCHARINLINE , pinputfile , ';' ); //printf("\nNow we are at : %s\n" , buffer ); //printf("\n INFO is %d ...\n" , info ); blank_signal = stellblank( buffer ) ; if( blank_signal == 0 ) { //printf("\nNo.%d line is a blank line ... Moving on ...\n" , iline ) ; } 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 ); } else if( ( tmp_char = getfirst( buffer ) ) == '[' ) { //printf("\nSTARTING OF NEW DIRECTIVE ... END READING ... \n\n"); break ; } else { //printf("\nLine reads : %s ...\n" , buffer ); iload ++ ; strpickword( buffer , 1 , cache ); atomdatabase[ iload -1 ].nr = atoi( cache ) ; strpickword( buffer , 2 , cache ); strcpy( atomdatabase[ iload -1 ].type , cache ); strpickword( buffer , 3 , cache ); atomdatabase[ iload -1 ].resnr = atoi( cache ) ; strpickword( buffer , 4 , cache ); strcpy( atomdatabase[ iload -1 ].residue , cache ); strpickword( buffer , 5 , cache ); strcpy( atomdatabase[ iload -1 ].atomname , cache ); strpickword( buffer , 6 , cache ); atomdatabase[ iload -1 ].cgnr = atoi( cache ) ; strpickword( buffer , 7 , cache ); atomdatabase[ iload -1 ].charge = atof( cache ) ; strpickword( buffer , 8 , cache ); atomdatabase[ iload -1 ].mass = atof( cache ) ; printf("\nCharge of this atom is %lf ...\n" , atomdatabase[ iload -1 ].charge ) ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; } } // ==============> Organizing Info and Defining Layers ... <========= // // ---------------> Allocating mem for dat array ... DAT atomcast[ natom ]; for( iatom = 0 ; iatom < natom ; iatom ++ ) { atomcast[ iatom ].cx = atomlist[ iatom ].cx * 10.00 ; atomcast[ iatom ].cy = atomlist[ iatom ].cy * 10.00 ; atomcast[ iatom ].cz = atomlist[ iatom ].cz * 10.00 ; atomcast[ iatom ].atomlabel = tellatom( atomlist[ iatom ].atomname ); //atomcast[ iatom ].atommass = tellmass( atomlist[ iatom ].atomname ); atomcast[ iatom ].atomcharge = 0.00 ; //printf("\nNo. %d atom ; X = %lf ; Y = %lf ; Z = %lf ; Atom = %d Mass = %lf ...\n" , iatom+1 , atomcast[ iatom ].cx , atomcast[ iatom ].cy , atomcast[ iatom ].cz , atomcast[ iatom ].atomlabel , atomcast[ iatom ].atommass ); } // ==============> Loading information into atomcast ... <========= // int itype = 0 ; /* FILE * debug ; debug = fopen( "atomnames.deb" , "wb+" ); for( iatom = 0 ; iatom < natom ; iatom ++ ) { fprintf( debug , "\n%d\t%s\n" , iatom + 1 , atomlist[ iatom ].atomname ); } fclose( debug ); debug = fopen( "atomtypes.deb" , "wb+"); for( itype = 0 ; itype < ntype ; itype ++ ) { fprintf( debug , "%8d %s %lf\t\n" , atomdatabase[ itype ].nr , atomdatabase[ itype ].atomname , atomdatabase[ itype ].charge ); } fclose( debug ); */ int info_res , info_atomname ; int ntype ; if( exx != 99 ) { ntype = natomITP ; for( iatom = natomselect ; iatom < natom ; iatom ++ ) { for( itype = 0 ; itype < ntype ; itype ++ ) { if( ( info_res = strcmp( atomlist[ iatom ].resname , atomdatabase[ itype ].residue ) ) == 0 && ( info_atomname = strcmp( atomlist[ iatom ].atomname , atomdatabase[ itype ].atomname ) ) == 0 ) { atomcast[ iatom ].atomcharge = atomdatabase[ itype ].charge ; //printf("\nNo.%d atom , charge is %lf ...\n" , iatom + 1 , atomcast[ iatom ].atomcharge ); break ; } } } } // ---------------> Outputing ... pCNDOoutput = fopen( outCNDOname , "wb+" ); fprintf( pCNDOoutput , "%s\n" , inpgroname ); fprintf( pCNDOoutput , "%s\n" , "HAMILT= INDO" ); fprintf( pCNDOoutput , "%s\n" , "STOP= CI" ); fprintf( pCNDOoutput , "%s\n" , "ROTINV= YES" ); //fprintf( pCNDOoutput , "%s\n" , "SHIFT= 20" ); fprintf( pCNDOoutput , "%s\n" , "BETA= INDO/S" ); fprintf( pCNDOoutput , "%s\n" , "POINTGRP= C1" ); fprintf( pCNDOoutput , "%s\n" , "EX_FROM= 60" ); fprintf( pCNDOoutput , "%s\n" , "MAX_CI= 60" ); fprintf( pCNDOoutput , "%s\n" , "CI_DUMP= 60" ); //fprintf( pCNDOoutput , "%s\n" , "DUMP= MAX" ); fprintf( pCNDOoutput , "%s%d\n" , "CHARGE= " , charge ); fprintf( pCNDOoutput , "%s%d\n" , "MULT_CI= " , multiplicity ); fprintf( pCNDOoutput , "%s\n" , "MAX_ITS= 300" ); fprintf( pCNDOoutput , "%s\n\n" , "RESTART= MO" ); if( natomDump >= natomselect ) { for( iatom = 0 ; iatom < natomselect ; iatom ++ ) { fprintf( pCNDOoutput , "%7.3f %7.3f %7.3f %5d\n" , atomcast[ iatom ].cx , atomcast[ iatom ].cy , atomcast[ iatom ].cz , atomcast[ iatom ].atomlabel ); } } else { for( iatom = 0 ; iatom < natomDump ; iatom ++ ) { fprintf( pCNDOoutput , "%7.3f %7.3f %7.3f %5d\n" , atomcast[ iatom ].cx , atomcast[ iatom ].cy , atomcast[ iatom ].cz , atomcast[ iatom ].atomlabel ); } } //fprintf( pCNDOoutput , "\n\n\n" ); if( exx != 99 ) { if( natomDump > natomselect && natomDump <= natom ) { for( iatom = natomselect ; iatom < natomDump ; iatom ++ ) { //printf("\nPrinting out No.%d atom which is in residue : %s into CNDO input file ... \n\n" , iatom + 1 , atomlist[ iatom ].resname ); fprintf( pCNDOoutput , "%7.3f %7.3f %7.3f %5d %10.6f\n" , atomcast[ iatom ].cx , atomcast[ iatom ].cy , atomcast[ iatom ].cz , -1*atomcast[ iatom ].atomlabel , atomcast[ iatom ].atomcharge ); } } } fprintf( pCNDOoutput , "\n\n\n\n\n" ) ; /* */ // -----------------> The End ... Really??? return(0); }
bool LoadObjFile(U8 * model_file, Mesh & mesh) { static VertexArray::iterator i; U8 buffer[128]; FILE * f = fopen((const char *)model_file,"r"); if (f==NULL) return false; while (freadline(f,buffer,128)==0) { LoadObjFileStateMachine(buffer,mesh); } /* Bounding sphere building */ Vector3 mean; for (i=mesh.vertices.begin();i!=mesh.vertices.end();i++) mean += *i; mean /= (REAL)mesh.vertices.size(); mesh.boundingsphere.center = mean; REAL max_dist=0; REAL d; Vector3 dist_to_point; for (i=mesh.vertices.begin();i!=mesh.vertices.end();i++) { dist_to_point = (*i)-mean; d = dist_to_point.Length2(); if (d>=max_dist) max_dist = d; } mesh.boundingsphere.radius = sqrt_real(max_dist); /* AABB Computing */ Vector3 maxs, mins; maxs = mesh.vertices[0]; mins = mesh.vertices[0]; for (i=mesh.vertices.begin();i!=mesh.vertices.end();i++) { if (i->x > maxs.x) maxs.x = i->x; if (i->y > maxs.y) maxs.y = i->y; if (i->z > maxs.z) maxs.z = i->z; if (i->x < mins.x) mins.x = i->x; if (i->y < mins.y) mins.y = i->y; if (i->z < mins.z) mins.z = i->z; } mesh.aabb.center = (maxs+mins)/2; mesh.aabb.widths = maxs-mins; return true; }
static int is_dsakey_in_keyfile(DSA *dsa_1, char *host, char *filename) { FILE *fp = NULL; char *line_buf = NULL; char *str = NULL; char *str_base64 = NULL; Buffer keyfile_buf; BIGNUM *bn_p = NULL; BIGNUM *bn_q = NULL; BIGNUM *bn_g = NULL; BIGNUM *bn_pub_key = NULL; int ret = 1; size_t str_size = 0; int i; if (!dsa_1 || !host || !filename) return 0; memset(&keyfile_buf, 0, sizeof(keyfile_buf)); /* Open the keyfile */ if ( (fp = fopen(filename, "r")) == NULL) { /* no key file */ ret = 1; goto is_dsakey_in_keyfile_cleanup; } /* Get memory for a line buffer */ if ( (line_buf = pal_malloc(sizeof(char) * 4096)) == NULL) { ret = 0; goto is_dsakey_in_keyfile_cleanup; } while (freadline(line_buf, 4095, fp) != EOF) { int len; str_base64 = strtok(line_buf, " "); if (strcmp(host, str_base64) != 0) continue; /* We got a match on the hostname * Now we assemble a DSA object * with what we have in the buffer */ str_base64 = strtok(NULL, " "); if (strcmp("ssh-dss", str_base64) != 0) continue; /* We got a match on the key type as well, going on */ str_base64 = strtok(NULL, " "); /* * Get the base64 data * and discard ssh-dss first */ str_size = pal_strlen(str_base64) * sizeof(char); if ( (str = pal_malloc(str_size)) == NULL) { ret = 0; goto is_dsakey_in_keyfile_cleanup; } if ( (len = base64decode(str, str_base64)) < 1) { ret = 0; goto is_dsakey_in_keyfile_cleanup; } /* Fill a buffer structure with this data */ buffer_init(&keyfile_buf); if (keyfile_buf.buf == NULL) { ret = 0; goto is_dsakey_in_keyfile_cleanup; } buffer_append(&keyfile_buf, str, str_size); /* Now get some BN filled with the data * from the buffer and compare * those with what we got in the incoming * dsa object. */ bn_p = BN_new(); bn_q = BN_new(); bn_g = BN_new(); bn_pub_key = BN_new(); if (bn_p == NULL || bn_q == NULL || bn_g == NULL || bn_pub_key == NULL) { ret = 0; goto is_dsakey_in_keyfile_cleanup; } /* String is skipped XXX */ buffer_get_string(&keyfile_buf, (unsigned int*)&i); // Bogus i returns the string length, not used buffer_get_bignum(&keyfile_buf, bn_p); buffer_get_bignum(&keyfile_buf, bn_q); buffer_get_bignum(&keyfile_buf, bn_g); buffer_get_bignum(&keyfile_buf, bn_pub_key); if ( !BN_cmp(dsa_1->p, bn_p) && !BN_cmp(dsa_1->q, bn_q) && !BN_cmp(dsa_1->g, bn_g) && !BN_cmp(dsa_1->pub_key, bn_pub_key) ) ret = 2; else ret = 3; } is_dsakey_in_keyfile_cleanup: if (str) pal_free(str); if (line_buf) pal_free(line_buf); if (fp) fclose(fp); if (bn_p) BN_clear_free(bn_p); if (bn_q) BN_clear_free(bn_q); if (bn_g) BN_clear_free(bn_g); if (bn_pub_key) BN_clear_free(bn_pub_key); if (keyfile_buf.buf) buffer_free(&keyfile_buf); return ret; }
/** * Load configuration from file. * @param config Configuration to load * @param filename File name to load configuration from * @return Non-zero value on success */ int config_load(struct config_t *config, char *filename) { FILE *file = fopen(filename, "r"); if (file != NULL) { for (;;) { char *line; if (freaduntil(fileno(file), &line, '=') == 0) break; if (!strcmp(line, "document_root")) { char *document_root; freadline(fileno(file), &document_root); if (config->document_root) free(config->document_root); config->document_root = realpath(document_root, NULL); free(document_root); } else if (!strcmp(line, "mode")) { char *mode; freadline(fileno(file), &mode); config->mode = mode; } else if (!strcmp(line, "inetd_service")) { char *inetd_service; freadline(fileno(file), &inetd_service); config->inetd_service = inetd_service; } else if (!strcmp(line, "cgi_enabled")) { char *cgi_enabled; freadline(fileno(file), &cgi_enabled); config->cgi_enabled = atoi(cgi_enabled); free(cgi_enabled); } else if (!strcmp(line, "port")) { char *port; freadline(fileno(file), &port); config->port = atoi(port); free(port); } free(line); } } else { return 0; } return 1; }
int preLoadGRO( FILE * pgroinput ) { int groinfo ; int iline = 0 ; int iload = 0 ; int natomgroline = 0 ; int blank_signal , info ; char buffer[ MAXCHARINLINE ] ; //char cache[ MAXCHARINLINE ] ; char tmp_char ; rewind( pgroinput ) ; fskip( pgroinput , 2 ) ; while( ( groinfo = freadline( buffer , MAXCHARINLINE , pgroinput , ';' ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); //info = freadline( buffer , MAXCHARINLINE , pinputfile , ';' ); //printf("\nNow we are at : %s\n" , buffer ); //printf("\n INFO is %d ...\n" , info ); 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 ); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; }//while( info != 0 ); natomgroline = iload - 1 ; return( natomgroline ) ; }
int preLoadEntry( FILE * pfile , char entryName[] , char commentSymbol ) { int iline = 0 ; int iload = 0 ; int blank_signal , info ; char buffer[ MAXCHARINLINE ] ; //char cache[ MAXCHARINLINE ] ; char tmp_char ; rewind( pfile ) ; info = fsearch( pfile , entryName ) ; if( info == NO ) { printf("\nNo Entry Name [ %s ] Found !\n\n" , entryName ) ; exit( 179 ) ; } fskip( pfile , 1 ) ; while( ( info = freadline( buffer , MAXCHARINLINE , pfile , commentSymbol ) ) != 0 ) { //printf("\n//--------------> WORKING ON NO. %d LINE ... <-------------//\n" , iline ); //info = freadline( buffer , MAXCHARINLINE , pinputfile , ';' ); //printf("\nNow we are at : %s\n" , buffer ); //printf("\n INFO is %d ...\n" , info ); 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 ) ) == commentSymbol ) { //printf("\nThis is a comment line ... So nothing will be loaded ...\n"); //fskip( pinputfile , 1 ); continue ; } else { //printf("\nLine reads : %s ...\n" , buffer ); iload ++ ; } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iline ++ ; }//while( info != 0 ); return( iload ) ; }
static int _file_put_printer(const char *file, const ns_printer_t *printer) { FILE *ifp, *ofp; char *tmpfile; int fd; int exit_status = 0; int size; size = strlen(file) + 1 + 20; if ((tmpfile = malloc(size)) == NULL) return (-1); if (snprintf(tmpfile, size, "%sXXXXXX", file) >= size) { syslog(LOG_ERR, "_file_put_printer:buffer overflow:tmpfile"); return (-1); } /* LINTED */ while (1) { /* syncronize writes */ fd = open(file, O_RDWR|O_CREAT|O_EXCL, 0644); if ((fd < 0) && (errno == EEXIST)) fd = open(file, O_RDWR); if (fd < 0) { if (errno == EAGAIN) continue; free(tmpfile); return (-1); } if (lockf(fd, F_TLOCK, 0) == 0) break; (void) close(fd); } if ((ifp = fdopen(fd, "r")) == NULL) { (void) close(fd); free(tmpfile); return (-1); } if ((fd = mkstemp(tmpfile)) < 0) { (void) fclose(ifp); free(tmpfile); return (-1); } (void) fchmod(fd, 0644); if ((ofp = fdopen(fd, "wb+")) != NULL) { char buf[4096]; (void) fprintf(ofp, "#\n#\tIf you hand edit this file, comments and structure may change.\n" "#\tThe preferred method of modifying this file is through the use of\n" "#\tlpset(1M)\n#\n"); /* * Handle the special case of lpset -x all * This deletes all entries in the file * In this case, just don't write any entries to the tmpfile */ if (!((strcmp(printer->name, "all") == 0) && (printer->attributes == NULL))) { char *t, *entry, *pentry; (void) _cvt_printer_to_entry((ns_printer_t *)printer, buf, sizeof (buf)); t = pentry = strdup(buf); while (freadline(ifp, buf, sizeof (buf)) != NULL) { ns_printer_t *tmp = (ns_printer_t *) _cvt_nss_entry_to_printer(buf, ""); if (ns_printer_match_name(tmp, printer->name) == 0) { entry = pentry; pentry = NULL; } else entry = buf; (void) fprintf(ofp, "%s\n", entry); } if (pentry != NULL) (void) fprintf(ofp, "%s\n", pentry); free(t); } (void) fclose(ofp); (void) rename(tmpfile, file); } else { (void) close(fd); (void) unlink(tmpfile); exit_status = -1; } (void) fclose(ifp); /* releases the lock, after rename on purpose */ (void) free(tmpfile); return (exit_status); }
int main( int argc, char * argv[] ) { FILE * pDATinput , * pGJFoutput ; char inpDATname[ 100 ] , outGJFname[ 100 ] ; char method[ 200 ] ; int multiplicity , charge ; int natom , ncart , natomselect , natomPrint ; int iatom ; double dtmp ; double dtmpArray[ 100 ] ; char buffer[ MAXCHARINLINE ] ; char cache[ MAXCHARINLINE ] ; char tmpString[ 150 ] ; char tmp_char ; int itmp , itmp2 ; // --------> Declaring utility functions ... // --------> Some default values ... multiplicity = 1 ; charge = 0 ; strcpy( method , "#P ZIndo( Singlets , NStates = 15 ) NoSymm Pop=Full Test" ) ; // ==============> Handling the file names and Charge & Multiplicity ... <========= // // -------> Parsing the Command Line Arguments ... char ** pcmd ; pcmd = argv ; //pcmd ++ ; int icmd = 1 ; //int exn = 10 ; int exr = 16 ; int exR = 18 ; int exH = 22 ; int exM = 28 ; int exL = 30 ; int exf = 1 ; int exo = 3 ; int exs = 18 ; int exmethod = 28 ; char * flag ; 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 'f' : strcpy( inpDATname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Input File name : %s ...\n" , inpDATname ); exf = 7 ; icmd = icmd + 2 ; break ; case 'o' : strcpy( outGJFname , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : Output File name : %s ...\n" , outGJFname ); exo = 9 ; icmd = icmd + 2 ; break ; case 'L' : strcpy( method , *( ++ pcmd ) ) ; printf("\nCommand-line argument indicates : G09 Method is : %s ...\n" , method ); exmethod = 29 ; icmd = icmd + 2 ; 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 'h' : printf("\nUsage: %s [ -f 'input dat file name' ] [(optional) -o 'generated g09 input file name' ] [ -s # of atoms chosen as the solute ] [ -L Method for G09 Calculations ]\n\n" , * argv ); printf("\nNOTE : 1) [ -s all ] or [ -s All ] indicates all atoms chosen as solute;\n\n 2) Default for -s is all atoms when nresidue = 1 or natom in 1st residue when nresidue != 1 \n"); //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); } } // --------> Setting DEFAULT value for important variables ... char defGJFname[100] , defDATname[100] ; int inputnamelength , outputnamelength ; switch( exf * exo ) // File Names ... int exf = 1 / 7 ; int exo = 3 / 9; { case 1 * 3 : strcpy( inpDATname , "sys.dat" ); strcpy( outGJFname , "sys.inp" ) ; break ; case 1 * 9 : outputnamelength = strlen( outGJFname ) ; strncpy( defDATname, outGJFname , outputnamelength - 4 ) ; *( defDATname + outputnamelength - 4 ) = '\0' ; strcat( defDATname, ".dat") ; strcpy( inpDATname , defDATname ); break ; case 7 * 3 : inputnamelength = strlen( inpDATname ) ; strncpy( defGJFname, inpDATname , inputnamelength - 4 ) ; *( defGJFname + inputnamelength - 4 ) = '\0' ; strcat( defGJFname, ".inp") ; strcpy( outGJFname , defGJFname ) ; break ; case 7 * 9 : printf("\n\nHoorayyyyyyyy ... All file names are specified !!!\n\n"); break ; } // --------------> Summarizing and File Access ... printf("\n\nInput CNDO .dat file name is : %s ...\n" , inpDATname ); printf("\nOutput G09 inp file name is %s ...\n" , outGJFname ); if( ( pDATinput = fopen( inpDATname , "r" ) ) == NULL ) { printf("\nUser defined .dat file %s does not exist ... \n" , inpDATname ); exit( 3 ); } // pGJFoutput = fopen( outGJFname , "wb+" ) ; // --------------> Reading information from CNDO .dat file ... int iline = 0 , nRouteLines ; int iload = 0 , nload ; int blank_signal , info ; int isoluteAtom = 0 , nsoluteAtom = 0 ; int ipointCharge = 0 , npointCharge = 0 ; double * molecularSpecification ; if( fsearch( pDATinput , "CHARGE=" ) == 1 ) { fscanf( pDATinput , "%s" , cache ) ; charge = atoi( cache ) ; } rewind( pDATinput ) ; if( fsearch( pDATinput , "MULT_CI=" ) == 1 ) { fscanf( pDATinput , "%s" , cache ) ; multiplicity = atoi( cache ) ; } printf("\nCharge is %d , Multiplicity is %d ...\n" , charge , multiplicity ) ; rewind( pDATinput ) ; while( ( info = freadline( buffer , MAXCHARINLINE , pDATinput , '$' ) ) != 0 ) { blank_signal = stellblank( buffer ) ; printf("\nLine reads : %s ...\n" , buffer ); if( blank_signal == 0 ) { break ; } else { iline ++ ; } } nRouteLines = iline ; while( ( info = freadline( buffer , MAXCHARINLINE , pDATinput , '$' ) ) != 0 ) { 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 ); itmp = inLineWC( buffer ) ; if( itmp == 4 ) { isoluteAtom ++ ; } else if( itmp == 5 ) { ipointCharge ++ ; } else { continue ; } } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iload ++ ; } nload = iload ; nsoluteAtom = isoluteAtom ; npointCharge = ipointCharge ; printf("\n En TOTO %d coordinates and other specifications loaded ... %d are atoms and %d are point charges ... \n" , nload , isoluteAtom , ipointCharge ) ; DAT atomlist[ nsoluteAtom + npointCharge ] ; rewind( pDATinput ) ; fskip( pDATinput , nRouteLines ) ; iload = 0 ; isoluteAtom = 0 ; ipointCharge = 0 ; while( ( info = freadline( buffer , MAXCHARINLINE , pDATinput , '$' ) ) != 0 ) { 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 ); itmp = inLineWC( buffer ) ; if( itmp == 4 ) { strpickword( buffer , 1 , cache ) ; atomlist[ isoluteAtom ].cx = atof( cache ) ; strpickword( buffer , 2 , cache ) ; atomlist[ isoluteAtom ].cy = atof( cache ) ; strpickword( buffer , 3 , cache ) ; atomlist[ isoluteAtom ].cz = atof( cache ) ; strpickword( buffer , 4 , cache ) ; atomlist[ isoluteAtom ].atomlabel = atoi( cache ) ; printf("\n No. %d atom ...\n" , isoluteAtom ) ; isoluteAtom ++ ; } else if( itmp == 5 ) { strpickword( buffer , 1 , cache ) ; atomlist[ nsoluteAtom + ipointCharge ].cx = atof( cache ) ; strpickword( buffer , 2 , cache ) ; atomlist[ nsoluteAtom + ipointCharge ].cy = atof( cache ) ; strpickword( buffer , 3 , cache ) ; atomlist[ nsoluteAtom + ipointCharge ].cz = atof( cache ) ; strpickword( buffer , 4 , cache ) ; atomlist[ nsoluteAtom + ipointCharge ].atomlabel = -1 * atoi( cache ) ; strpickword( buffer , 5 , cache ) ; atomlist[ nsoluteAtom + ipointCharge ].atomcharge = atof( cache ) ; printf("\n No. %d atom ...\n" , nsoluteAtom + ipointCharge ) ; ipointCharge ++ ; } else { continue ; } } //printf("\n%s\n" , buffer ); } else { printf("\nSomething is wrong with the reading file part ...\n"); exit(1); } iload ++ ; } if( iload == nload && ipointCharge == npointCharge && isoluteAtom == nsoluteAtom ) { printf("\n En TOTO %d coordinates and other specifications loaded ... %d are atoms and %d are point charges ... \n" , nload , nsoluteAtom , npointCharge ) ; } else { printf("\nEh...oh... Something is wrong during the loading ... \n"); printf("\n En TOTO %d coordinates and other specifications loaded ... %d are atoms and %d are point charges ... \n" , nload , nsoluteAtom , npointCharge ) ; exit( 515 ) ; } natom = nsoluteAtom + npointCharge ; switch ( exs ) { case 19 : natomPrint = natomselect ; break ; case 18 : natomPrint = nsoluteAtom ; break ; case 20 : natomPrint = natom ; break ; default : printf("\nSomething is wrong during the printing-out ...\n") ; exit( 538 ) ; } // --------------> Outputing ... char chkname[ 100 ] , rwfname[ 100 ] ; outputnamelength = strlen( outGJFname ) ; strncpy( chkname , outGJFname , outputnamelength - 4 ) ; *( chkname + outputnamelength - 4 ) = '\0' ; strcat( chkname, ".chk") ; strncpy( rwfname , outGJFname , outputnamelength - 4 ) ; *( rwfname + outputnamelength - 4 ) = '\0' ; strcat( rwfname, ".rwf") ; if( exmethod == 28 ) { printf("\nNo QC method specified in command-line , go with ===> %s <===\n" , method ); } pGJFoutput = fopen( outGJFname , "wb+" ); fprintf( pGJFoutput , "%%chk=%s\n%%rwf=%s\n%%mem=4GB\n%%nprocshared=2\n\n" , chkname , rwfname ); fprintf( pGJFoutput , "%s\n\n" , method ); fprintf( pGJFoutput , "%s corresponding QC\n\n" , inpDATname ); fprintf( pGJFoutput , "%d\t%d\t\n" , charge , multiplicity ); for( iatom = 0 ; iatom < natomPrint ; iatom ++ ) { fprintf( pGJFoutput , "%d\t% 16.12f\t% 16.12f\t% 16.12f\n" , atomlist[ iatom ].atomlabel , atomlist[ iatom ].cx , atomlist[ iatom ].cy , atomlist[ iatom ].cz ); } int nwords , signal ; nwords = inLineWC( method ) ; signal = 0 ; for( itmp = 0 ; itmp < nwords ; itmp ++ ) { strpickword( method , itmp + 1 , buffer ) ; if( strcmp( buffer , "dftba") == 0 || strcmp( buffer , "DFTBA") == 0 ) { signal = 1 ; break ; } } if( signal == 1 ) { fprintf( pGJFoutput , "\n@GAUSS_EXEDIR:dftba.prm\n\n" ); } fprintf( pGJFoutput , "\n" ) ; fclose( pGJFoutput ); }
int main (int argc, char *argv[]) { struct pollfd pfd; char line[4096], *p; char *name, *id, *polname, *filters; int nfilters, res; time_t curtime; GList *items = NULL; GtkWidget *systracewin; GtkWidget *processname; GtkWidget *policyname; GtkWidget *processid; GtkWidget *syscallinfo; GtkWidget *statusline; GtkWidget *timeline; GtkWidget *reviewbutton; GtkWidget *detachlabel; GtkWidget *filterentry; GtkStyle *default_style, *red_style; /* Set up required parameters */ parameters(); gtk_set_locale (); gtk_init (&argc, &argv); add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps"); add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps"); /* * The following code was added by Glade to create one of each component * (except popup menus), just so that you see something after building * the project. Delete any components that you don't want shown initially. */ systracewin = create_systracewin (); filterreview = create_filterreview(); wizard = create_wizard(); processname = lookup_widget(GTK_WIDGET(systracewin), "processname"); processid = lookup_widget(GTK_WIDGET(systracewin), "processid"); policyname = lookup_widget(GTK_WIDGET(systracewin), "policyname"); syscallinfo = lookup_widget(GTK_WIDGET(systracewin), "syscallinfo"); statusline = lookup_widget(GTK_WIDGET(systracewin), "statusline"); timeline = lookup_widget(GTK_WIDGET(systracewin), "timeline"); reviewbutton = lookup_widget(GTK_WIDGET(systracewin), "reviewbutton"); wizardbutton = lookup_widget(GTK_WIDGET(systracewin), "wizardbutton"); detachlabel = lookup_widget(GTK_WIDGET(systracewin), "detachlabel"); filterentry = lookup_widget(GTK_WIDGET(systracewin), "filterentry"); default_style = gtk_widget_get_style(processname); red_style = make_color(default_style, 0xd000, 0x1000, 0); red_style->private_font = gdk_font_load("-*-helvetica-bold-r-normal--*-140-*-*-*-*-iso8859-1"); gtk_widget_set_style(processname, red_style); gtk_widget_set_style(processid, red_style); gtk_widget_set_style(policyname, red_style); gtk_widget_set_style(syscallinfo, red_style); /* Return key is not supposed to pop it up */ gtk_combo_disable_activate(GTK_COMBO(filterentry)); /* Connect to cradle server if requested */ if (argc == 2 && strcmp(argv[1], "-C") == 0) { struct sockaddr_un sun; int s; char path[MAXPATHLEN]; snprintf(path, sizeof(path), "/tmp/systrace-%d/%s", getuid(), CRADLE_UI); if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) err(1, "socket()"); memset(&sun, 0, sizeof (sun)); sun.sun_family = AF_UNIX; if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) errx(1, "Path too long: %s", path); if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) == -1) err(1, "connect()"); if (dup2(s, fileno(stdin)) == -1) err(1, "dup2"); if (dup2(s, fileno(stdout)) == -1) err(1, "dup2"); } /* Make IO line buffered */ setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); while (1) { /* See if we can read from the file descriptor */ memset(&pfd, 0, sizeof(pfd)); pfd.fd = fileno(stdin); pfd.events = POLLIN; res = poll(&pfd, 1, 1000); if (res == -1) { if (errno == EINTR || errno == EAGAIN) break; } else if (res == 0) { while (gtk_events_pending()) gtk_main_iteration(); continue; } if (freadline(line, sizeof(line), stdin) == NULL) break; p = line; name = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; strsep(&p, " "); if (p == NULL || *p == '\0') errx(1, "Bad input line"); id = strsep(&p, "("); if (p == NULL || *p == '\0') errx(1, "Bad input line"); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; polname = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; filters = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); nfilters = atoi(filters); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; gtk_label_set_text(GTK_LABEL(processname), name); gtk_label_set_text(GTK_LABEL(processid), id); gtk_label_set_text(GTK_LABEL(policyname), polname); gtk_label_set_text(GTK_LABEL(syscallinfo), p); gtk_label_set_text(GTK_LABEL(statusline), ""); items = make_policy_suggestion(p); curtime = time(NULL); snprintf(line, sizeof(line), "%.25s", ctime(&curtime)); gtk_label_set_text(GTK_LABEL(timeline), line); if (nfilters) { gtk_widget_set_sensitive(wizardbutton, 0); gtk_widget_set_sensitive(reviewbutton, 1); gtk_label_set_text(GTK_LABEL(detachlabel), "Automatic"); } else { gtk_widget_set_sensitive(wizardbutton, 1); gtk_widget_set_sensitive(reviewbutton, 0); gtk_label_set_text(GTK_LABEL(detachlabel), "Detach"); } gtk_widget_show (systracewin); gtk_combo_set_popdown_strings (GTK_COMBO(filterentry), items); g_list_foreach(items, free_list, NULL); g_list_free(items); do { gtk_main (); while (freadline(line, sizeof(line), stdin)) { if (!strcmp(line, "OKAY")) goto done; if (!strcmp(line, "WRONG")) break; gtk_label_set_text(GTK_LABEL(statusline), line); } } while (1); done: gtk_widget_hide (systracewin); while (gtk_events_pending()) gtk_main_iteration(); } return 0; }
int ccstree_main(int argc, char *argv[]) { const char *policy_file = proc_policy_process_status; static _Bool show_all = false; int i; for (i = 1; i < argc; i++) { char *ptr = argv[i]; char *cp = strchr(ptr, ':'); if (cp) { *cp++ = '\0'; if (network_mode) goto usage; network_ip = inet_addr(ptr); network_port = htons(atoi(cp)); network_mode = true; if (!check_remote_host()) return 1; } else if (!strcmp(ptr, "-a")) { show_all = true; } else { usage: fprintf(stderr, "Usage: %s " "[-a] [remote_ip:remote_port]\n", argv[0]); return 0; } } if (network_mode) { FILE *fp = open_write(show_all ? "proc:all_process_status" : "proc:process_status"); if (!fp) { fprintf(stderr, "Can't connect.\n"); return 1; } get(); while (freadline(fp)) { unsigned int pid = 0; unsigned int ppid = 0; int profile = -1; char *name; char *domain; sscanf(shared_buffer, "PID=%u PPID=%u", &pid, &ppid); name = strstr(shared_buffer, "NAME="); if (name) name = strdup(name + 5); if (!name) name = "<UNKNOWN>"; if (!freadline(fp)) break; sscanf(shared_buffer, "%u %u", &pid, &profile); domain = strchr(shared_buffer, '<'); if (domain) domain = strdup(domain); if (!domain) domain = "<UNKNOWN>"; task_list = realloc(task_list, (task_list_len + 1) * sizeof(struct task_entry)); if (!task_list) out_of_memory(); task_list[task_list_len].pid = pid; task_list[task_list_len].ppid = ppid; task_list[task_list_len].profile = profile; task_list[task_list_len].name = name; task_list[task_list_len].domain = domain; task_list[task_list_len].done = false; task_list_len++; } put(); fclose(fp); } else { struct dirent **namelist; int i; int n; int status_fd; if (access(proc_policy_dir, F_OK)) { fprintf(stderr, "You can't use this command " "for this kernel.\n"); return 1; } status_fd = open(policy_file, O_RDWR); if (status_fd == EOF) { fprintf(stderr, "Can't open %s\n", policy_file); return 1; } n = scandir("/proc/", &namelist, 0, 0); for (i = 0; i < n; i++) { char *name; char *domain; int profile = -1; unsigned int pid = 0; char buffer[128]; char test[16]; if (sscanf(namelist[i]->d_name, "%u", &pid) != 1) goto skip; memset(buffer, 0, sizeof(buffer)); snprintf(buffer, sizeof(buffer) - 1, "/proc/%u/exe", pid); if (!show_all && readlink(buffer, test, sizeof(test)) <= 0) goto skip; name = get_name(pid); if (!name) name = "<UNKNOWN>"; snprintf(buffer, sizeof(buffer) - 1, "%u\n", pid); write(status_fd, buffer, strlen(buffer)); get(); memset(shared_buffer, 0, sizeof(shared_buffer)); read(status_fd, shared_buffer, sizeof(shared_buffer) - 1); sscanf(shared_buffer, "%u %u", &pid, &profile); domain = strchr(shared_buffer, '<'); if (domain) domain = strdup(domain); if (!domain) domain = "<UNKNOWN>"; put(); task_list = realloc(task_list, (task_list_len + 1) * sizeof(struct task_entry)); if (!task_list) out_of_memory(); task_list[task_list_len].pid = pid; task_list[task_list_len].ppid = get_ppid(pid); task_list[task_list_len].profile = profile; task_list[task_list_len].name = name; task_list[task_list_len].domain = domain; task_list[task_list_len].done = false; task_list_len++; skip: free((void *) namelist[i]); } if (n >= 0) free((void *) namelist); close(status_fd); } dump(1, 0); dump_unprocessed(); return 0; }