Beispiel #1
0
/*
	Returns the size of a BMP
*/
bmp_ret_t bmp_readSize(const char* file, uint16_t* width, uint16_t* height)
{
  FILE *fp;

  /* open the file */
  if ((fp = fopen(file,"rb")) == NULL) {
    return BMP_ERR_OPEN;
  }

  /* check to see if it is a valid bitmap file */
  if (fgetc(fp)!='B' || fgetc(fp)!='M')
  {
    fclose(fp);
	return BMP_ERR_INVALID;
  }

  fskip(fp,16);
  fread(width, sizeof(uint16_t), 1, fp);  
  fskip(fp,2);
  fread(height,sizeof(uint16_t), 1, fp);
  
#ifndef _WIN32
  *width = flipOrder(*width);
  *height = flipOrder(*height);
#endif

  fclose(fp);
  return BMP_OK;
}
Beispiel #2
0
void load_bmp(char *file,BITMAP *b)
{
  FILE *fp;
  long index;
  word num_colors;
  int x;

  /* open the file */
  if ((fp = fopen(file,"rb")) == NULL)
  {
    printf("Error opening file %s.\n",file);
    exit(1);
  }

  /* check to see if it is a valid bitmap file */
  if (fgetc(fp)!='B' || fgetc(fp)!='M')
  {
    fclose(fp);
    printf("%s is not a bitmap file.\n",file);
    exit(1);
  }

  /* read in the width and height of the image, and the
     number of colors used; ignore the rest */
  fskip(fp,16);
  fread(&b->width, sizeof(word), 1, fp);
  fskip(fp,2);
  fread(&b->height,sizeof(word), 1, fp);
  fskip(fp,22);
  fread(&num_colors,sizeof(word), 1, fp);
  fskip(fp,6);

  /* assume we are working with an 8-bit file */
  if (num_colors==0) num_colors=256;

  /* try to allocate memory */
  if ((b->data = (byte *) malloc((word)(b->width*b->height))) == NULL)
  {
    fclose(fp);
    printf("Error allocating memory for file %s.\n",file);
    exit(1);
  }

  /* read the palette information */
  for(index=0;index<num_colors;index++)
  {
    b->palette[(int)(index*3+2)] = fgetc(fp) >> 2;
    b->palette[(int)(index*3+1)] = fgetc(fp) >> 2;
    b->palette[(int)(index*3+0)] = fgetc(fp) >> 2;
    x=fgetc(fp);
  }

  /* read the bitmap */
  for(index=(b->height-1)*b->width;index>=0;index-=b->width)
    for(x=0;x<b->width;x++)
      b->data[(word)(index+x)]=(byte)fgetc(fp);

  fclose(fp);
}
Beispiel #3
0
/*-------------------------------------------------------------------
* CTReadCTF - read a slice from a ctf file
*-------------------------------------------------------------------
*/
static int CTReadCTF(FILE *fp, CTSlice slice, int x1, int y1, int x2, int y2)
{
	unsigned short delta[512], row[512];
	int i, del, left, right;
	long off;
	
	/*
	CTSliceXSize(slice) = 512;
	CTSliceYSize(slice) = 512;
	*/
	
	if (x1==-1) 
	{
		slice->x1=slice->y1=x1=y1=0;
		slice->x2=slice->y2=x2=y2=511;
		slice->data = (unsigned short *)malloc(sizeof(unsigned short)*(x2-x1+1)*
			(y2-y1+1));
	
		memset(slice->data, '\0', sizeof(short)*(x2-x1+1)*(y2-y1+1));
		CTSliceWidth(slice) = CTSliceHeight(slice) = 512;
	}
	
	/* skip past the 2048 byte header */
	fskip(fp, 2048);
	
	/* read the number of data values for each line */
	fread(delta, 2, 512, fp);
	
	/* compute offset for rows up to y1 */
	for (off=0, i=0; i<x1; i++)
		off+=delta[i]*2*2;
	
#ifdef DEBUG
	printf("skipping %ld values\n", off);
#endif
	
	/* skip to the x1'th row of data */
	if (off != 0)
		fskip(fp, off);

	for (; x1<=x2; x1++) 
	{
		/* skip to y1'th column of data in this row */
		del=delta[x1];
		
		/* compute how much data is present */
		left = (512)/2 - del;
		right = (512)/2 + del- 1;
		
		memset(row, '\0', 512*sizeof(short));
		fread(&row[left], 2, 2*del, fp);
		memcpy(&CTSliceShortData(slice, x1, y1), &row[y1],
            sizeof(short)*(y2-y1+1));
	}
	
	CTSliceCompMinMaxD(slice);
	return(0);
}
Beispiel #4
0
/*-------------------------------------------------------------------
* CTReadVol - read a slice from a volume file
*-------------------------------------------------------------------
*/
static int CTReadVol(FILE *fp, CTSlice slice, int num, int x1, int y1,
                     int x2, int y2)
{
	
	/*
	CTSliceXSize(slice) = 256;
	CTSliceYSize(slice) = 256;
	*/
	CTSliceWidth(slice) = 256;
	CTSliceHeight(slice) = 256;
	
	if (x1==-1) 
	{
		slice->x1=slice->y1=x1=y1=0;
		slice->x2=x2=CTSliceXSize(slice)-1;
		slice->y2=y2=CTSliceYSize(slice)-1;
		slice->data=(unsigned short *)malloc(sizeof(short)*(x2-x1+1)*(y2-y1+1));
		memset(slice->data, '\0', sizeof(short)*(x2-x1+1)*(y2-y1+1));
	}
	
	fskip(fp, 256*256*2*(num-1));
	fread(slice->data, 2, 256*256, fp);
	CTSliceCompMinMaxD(slice);
	return(0);
}
Beispiel #5
0
int fread_byte(FILE * f, uint8_t * data)
{
  if (data != NULL)
	  return (fread((void *) data, sizeof(uint8_t), 1, f) < 1) ? -1 : 0;
  else
    return fskip(f, 1);

  return 0;
}
Beispiel #6
0
int fread_long(FILE * f, uint32_t * data)
{
  int ret = 0;

  if (data != NULL)
  {
	  ret = (fread((void *) data, sizeof(uint32_t), 1, f) < 1) ? -1 : 0;
	*data = GUINT32_FROM_LE(*data);
  }
  else
    ret = fskip(f, 4);

  return ret;
}
Beispiel #7
0
int fread_word(FILE * f, uint16_t * data)
{
  int ret = 0;

  if (data != NULL)
  {
	  ret = (fread((void *) data, sizeof(uint16_t), 1, f) < 1) ? -1 : 0;
	*data = GUINT16_FROM_LE(*data);
  }
  else
    ret = fskip(f, 2);

  return ret;
}
Beispiel #8
0
/*-------------------------------------------------------------------
* CTReadH3D - read a slice from an H3D file
*-------------------------------------------------------------------
*/
static int CTReadH3D(FILE *fp, CTSlice slice, int num, int x1, int y1,
                     int x2, int y2)
{
	if (x1==-1) 
	{
		slice->x1=slice->y1=x1=y1=0;
		slice->x2=x2=CTSliceXSize(slice)-1;
		slice->y2=y2=CTSliceYSize(slice)-1;
		slice->fdata=(float *)malloc(sizeof(float)*(x2-x1+1)*(y2-y1+1));
		memset(slice->fdata, '\0', sizeof(float)*(x2-x1+1)*(y2-y1+1));
	}
	
	CTSliceWidth(slice) = x2-x1+1;
	CTSliceHeight(slice) = y2-y1+1;
	
	fskip(fp, sizeof(int)*3 + sizeof(double)*3 +
		CTVolXSize(slice->vol)*CTVolYSize(slice->vol)*(num-1)*sizeof(float));
	fread(slice->fdata, sizeof(float), CTVolXSize(slice->vol)*
		CTVolYSize(slice->vol), fp);
	
	CTSliceCompMinMaxD(slice);
	return(0);
}
Beispiel #9
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);
  
  
  
  }
static int
parse_aiff_header(FILE *sf)
{
	int is_aiff = 0;
	long chunkSize = 0, subSize = 0;
	IFF_AIFF aiff_info;

	memset(&aiff_info, 0, sizeof(aiff_info));
	chunkSize = Read32BitsHighLow(sf);
	
	if ( Read32BitsHighLow(sf) != IFF_ID_AIFF )
		return 0;
	
	while ( chunkSize > 0 )
	{
		u_int type = 0;
		chunkSize -= 4;

		type = Read32BitsHighLow(sf);

		/* fprintf(stderr,
			"found chunk type %08x '%4.4s'\n", type, (char*)&type); */

		/* don't use a switch here to make it easier to use 'break' for SSND */
		if (type == IFF_ID_COMM) {
			subSize = Read32BitsHighLow(sf);
			chunkSize -= subSize;

			aiff_info.numChannels	  = Read16BitsHighLow(sf);
			subSize -= 2;
			aiff_info.numSampleFrames = Read32BitsHighLow(sf);
			subSize -= 4;
			aiff_info.sampleSize	  = Read16BitsHighLow(sf);
			subSize -= 2;
			aiff_info.sampleRate	  = ReadIeeeExtendedHighLow(sf);
			subSize -= 10;

			if (fskip(sf, (long) subSize, SEEK_CUR) != 0 )
				return 0;

		} else if (type == IFF_ID_SSND) {
			subSize = Read32BitsHighLow(sf);
			chunkSize -= subSize;

			aiff_info.blkAlgn.offset	= Read32BitsHighLow(sf);
			subSize -= 4;
			aiff_info.blkAlgn.blockSize = Read32BitsHighLow(sf);
			subSize -= 4;

			if (fskip(sf, aiff_info.blkAlgn.offset, SEEK_CUR) != 0 )
				return 0;

			aiff_info.sampleType = IFF_ID_SSND;
			is_aiff = 1;

			/* We've found the audio data.	Read no further! */
			break;
			
		} else {
			subSize = Read32BitsHighLow(sf);
			chunkSize -= subSize;

			if (fskip(sf, (long) subSize, SEEK_CUR) != 0 )
				return 0;
		}
	}

	/* fprintf(stderr, "Parsed AIFF %d\n", is_aiff); */
	if (is_aiff) {
		/* make sure the header is sane */
		aiff_check2("name", &aiff_info);
		num_channels  = aiff_info.numChannels;
		samp_freq     = aiff_info.sampleRate;
		num_samples   = aiff_info.numSampleFrames;
	}
	return is_aiff;
}
static int
parse_wave_header(FILE *sf)
{
	fmt_chunk_data wave_info;
	int is_wav = 0;
	long data_length = 0, file_length, subSize = 0;
	int loop_sanity = 0;

	memset(&wave_info, 0, sizeof(wave_info));

	file_length = Read32BitsHighLow(sf);

	if (Read32BitsHighLow(sf) != WAV_ID_WAVE)
		return 0;

	for (loop_sanity = 0; loop_sanity < 20; ++loop_sanity) {
		u_int type = Read32BitsHighLow(sf);

		if (type == WAV_ID_FMT) {
			subSize = Read32BitsLowHigh(sf);
			if (subSize < 16) {
			  /*fprintf(stderr,
			    "'fmt' chunk too short (only %ld bytes)!", subSize);  */
				return 0;
			}

			wave_info.format_tag		= Read16BitsLowHigh(sf);
			subSize -= 2;
			wave_info.channels			= Read16BitsLowHigh(sf);
			subSize -= 2;
			wave_info.samples_per_sec	= Read32BitsLowHigh(sf);
			subSize -= 4;
			wave_info.avg_bytes_per_sec = Read32BitsLowHigh(sf);
			subSize -= 4;
			wave_info.block_align		= Read16BitsLowHigh(sf);
			subSize -= 2;
			wave_info.bits_per_sample	= Read16BitsLowHigh(sf);
			subSize -= 2;

			/* fprintf(stderr, "   skipping %d bytes\n", subSize); */

			if (subSize > 0) {
				if (fskip(sf, (long)subSize, SEEK_CUR) != 0 )
					return 0;
			};

		} else if (type == WAV_ID_DATA) {
			subSize = Read32BitsLowHigh(sf);
			data_length = subSize;
			is_wav = 1;
			/* We've found the audio data.	Read no further! */
			break;

		} else {
			subSize = Read32BitsLowHigh(sf);
			if (fskip(sf, (long) subSize, SEEK_CUR) != 0 ) return 0;
		}
	}

	if (is_wav) {
		/* make sure the header is sane */
		wave_check("name", &wave_info);

		num_channels  = wave_info.channels;
		samp_freq     = wave_info.samples_per_sec;
		num_samples   = data_length / (wave_info.channels * wave_info.bits_per_sample / 8);
	}
	return is_wav;
}
Beispiel #12
0
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 ) ;


}
Beispiel #13
0
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 ) ;


}
Beispiel #14
0
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 );
  









}
Beispiel #15
0
/*-------------------------------------------------------------------
* CTReadRAS - read a slice from a sun raster file
*-------------------------------------------------------------------
*/
static int CTReadRAS(FILE *fp, CTSlice slice, int x1, int y1, int x2, int y2)
{
	int               linesize,lsize,csize,isize,flipit,i,j,w,h,d,rv;
	unsigned char     *line, r[256], g[256], b[256];
	struct rasterfile sunheader;
	
	rv = 0;
	
	/* read in the Sun Rasterfile picture */
	flipit = 0;
	fread(&sunheader, sizeof(struct rasterfile), 1, fp);
	
	if (sunheader.ras_magic != RAS_MAGIC) 
	{
		flipl( (unsigned char *) &sunheader.ras_magic);
		if (sunheader.ras_magic == RAS_MAGIC)
			flipit = 1;
		else
			flipl( (unsigned char *) &sunheader.ras_magic);
	}
	
	if (sunheader.ras_magic != RAS_MAGIC)
		return( SunRasError("not a Sun rasterfile") );
	
	if (flipit) {
		flipl((unsigned char *) &sunheader.ras_width);
		flipl((unsigned char *) &sunheader.ras_height);
		flipl((unsigned char *) &sunheader.ras_depth);
		flipl((unsigned char *) &sunheader.ras_length);
		flipl((unsigned char *) &sunheader.ras_type);
		flipl((unsigned char *) &sunheader.ras_maptype);
		flipl((unsigned char *) &sunheader.ras_maplength);
	}
	
	/* make sure that the input picture can be dealt with */
	if (sunheader.ras_depth != 8) 
	{
		fprintf (stderr, "Sun rasterfile image has depth %d\n",
			sunheader.ras_depth);
		fprintf (stderr, "Depths supported are 8\n");
		return 1;
	}
	
	if (sunheader.ras_type != RT_OLD && sunheader.ras_type != RT_STANDARD &&
		sunheader.ras_type != RT_BYTE_ENCODED &&
		sunheader.ras_type != RT_FORMAT_RGB) 
	{
		fprintf (stderr, "Sun rasterfile of unsupported type %d\n",
			sunheader.ras_type);
		return 1;
	}
	
	if (sunheader.ras_maptype != RMT_RAW && sunheader.ras_maptype != RMT_NONE &&
		sunheader.ras_maptype != RMT_EQUAL_RGB) 
	{
		fprintf (stderr, "Sun rasterfile colormap of unsupported type %d\n",
			sunheader.ras_maptype);
		return 1;
	}
	
	w = sunheader.ras_width;
	h = sunheader.ras_height;
	d = sunheader.ras_depth;
	isize = sunheader.ras_length ?
		sunheader.ras_length :
	(w * h * d) / 8;
	csize = (sunheader.ras_maptype == RMT_NONE) ? 0 : sunheader.ras_maplength;
	lsize = w * h * ( d == 1 ? d : d/8);
	linesize = w * d;
	/* if ((linesize % 48) && d == 24) linesize += (48 - (linesize % 48)); */
	if (linesize % 16) linesize += (16 - (linesize % 16));
	linesize /= 8;
	
#ifdef DEBUG
	fprintf(stderr,"%s: LoadSunRas() - loading a %dx%d pic, %d planes\n",
		cmd, w, h, d);
	fprintf(stderr,
		"type %d, maptype %d, isize %d, csize %d, lsize %d, linesize %d\n",
		sunheader.ras_type, sunheader.ras_maptype,
		isize, csize, lsize, linesize);
#endif
	
	
	/* read in the colormap, if any */
	if (sunheader.ras_maptype == RMT_EQUAL_RGB && csize) 
	{
		fread (r, sizeof(unsigned char), sunheader.ras_maplength/3, fp);
		fread (g, sizeof(unsigned char), sunheader.ras_maplength/3, fp);
		fread (b, sizeof(unsigned char), sunheader.ras_maplength/3, fp);
	}
	else if (sunheader.ras_maptype == RMT_RAW && csize) 
	{
		/* we don't know how to handle raw colormap, ignore */
		fskip(fp, csize);
	}
	else
	{
		/* no colormap, make one up */
		if (sunheader.ras_depth == 1) 
		{
			r[0] = g[0] = b[0] = 0;
			r[1] = g[1] = b[1] = 255;
		}
		else if (sunheader.ras_depth == 8) 
		{
			for (i = 0; i < 256; i++)
				r[i] = g[i]  = b[i] = i;
		}
	}
	
	/*
	CTSliceXSize(slice) = w;
	CTSliceYSize(slice) = h;
	*/
	
	if (x1==-1) 
	{
		slice->x1=slice->y1=x1=y1=0;
		slice->x2=x2=w-1;
		slice->y2=y2=h-1;
		slice->cdata = (unsigned char *)malloc(sizeof(unsigned char)*(x2-x1+1)*
			(y2-y1+1));
		memset(slice->cdata, '\0', sizeof(char)*(x2-x1+1)*(y2-y1+1));
		CTSliceWidth(slice) = w;
		CTSliceHeight(slice) = h;
	}
	
	/* allocate memory for picture and read it in */
	/* note we may slightly overallocate here (if image is padded) */
	line = (unsigned char *) malloc (linesize);
	if (line == NULL) 
	{
		fprintf(stderr, "Can't allocate memory for image\n");
		exit(1);
	}
	
	for (i = 0; i < h; i++) 
	{
		if (sunheader.ras_type == RT_BYTE_ENCODED) 
		{
			if (rle_read (line, 1, linesize, fp, (i==0)) != linesize) break;
		}
		else 
		{
			if (fread (line, 1, linesize, fp) != (unsigned int)linesize)
				return (SunRasError ("file read error"));
		}
		
		if (slice->y1 <= i && i <= slice->y2) 
		{
			for (j=slice->x1; j<=slice->x2; j++)
				CTSliceCharData(slice, i, j) = line[j];
		}
		/*
		switch (d) {
		case 1:  SunRas1to8 (image + w * i, line, w);       break;
		case 8:  memcpy (image + w * i, line, w);           break;
		case 24: memcpy (image + w * i * 3, line, w * 3); break;
		}
		*/
	}
	
#ifdef DEBUG
	fprintf(stderr,"Sun ras: image loaded!\n");
#endif
	
	/*
	if (d == 24) {
	if (sunheader.ras_type != RT_FORMAT_RGB) fixBGR(image,w,h);
	rv = Conv24to8 (image, w, h, nc);
	free (image);
	return (rv);
	}
	else {
	pic = image;
	pWIDE = w;
	pHIGH = h;
	return (0);
	}
	*/
	CTSliceCompMinMaxD(slice);
	return(0);
}
Beispiel #16
0
/*-------------------------------------------------------------------
* CTReadSLC - read a slice from an SLC file
*-------------------------------------------------------------------
*/
static int CTReadSLC(FILE *fp, CTSlice slice, int num, int x1, int y1,
                     int x2, int y2)
{
	int i, remaining, current_value;
	unsigned int size;
//	unsigned int xsize, ysize, zsize, bits, magic;
//	float xunit, yunit, zunit;
	unsigned char *data_ptr;
	C_CompressionType compression;
//	C_UnitType unit;
//	C_DataOrigin data;
//	C_DataModification datamod;
	
	if (x1==-1) 
	{
		slice->x1=slice->y1=x1=y1=0;
		slice->x2=x2=CTSliceXSize(slice)-1;
		slice->y2=y2=CTSliceYSize(slice)-1;
		slice->cdata=(unsigned char *)malloc(sizeof(char)*(x2-x1+1)*(y2-y1+1));
		memset(slice->cdata, '\0', sizeof(char)*(x2-x1+1)*(y2-y1+1));
	}
	
	CTSliceWidth(slice) = x2-x1+1;
	CTSliceHeight(slice) = y2-y1+1;
	
	/* skip header */
	fskip(fp, sizeof(int)*5 + sizeof(float)*3 + sizeof(C_UnitType) +
		sizeof(C_DataOrigin) + sizeof(C_DataModification));
	
	/* get compression type */
	fread(&compression, sizeof(C_CompressionType), 1, fp);
	
	/* skip (num-1) slices */
	if (compression == C_NO_COMPRESSION) 
	{
		fskip(fp, CTVolXSize(slice->vol)*CTVolYSize(slice->vol)*(num-1));
	}
	else 
	{
		for (i=0; i<num-1; i++) 
		{
			fread(&size, sizeof(int), 1, fp);
			fskip(fp, size);
		}
	}
	
	/* read slice */
	switch (compression) 
	{
		case C_NO_COMPRESSION:
			fread(slice->cdata, sizeof(char),
				CTVolXSize(slice->vol)*CTVolYSize(slice->vol), fp);
			break;

		case C_RUN_LENGTH_ENCODE:
			fread(&size, sizeof(int), 1, fp);
			data_ptr = slice->cdata;
			while (1) 
			{
				current_value = getc(fp);
				if ( !(remaining = (current_value & 0x7f)) )
					break;
				if ( current_value & 0x80 )
					while (remaining--)
						*(data_ptr++) = getc(fp);
					else 
					{
						current_value = getc(fp);
						while (remaining--)
							*(data_ptr++) = current_value;
					}
			}
			break;

		default:
			fprintf(stderr, "Error in compression type of SLC file\n");
			return(-1);
	}
	
	CTSliceCompMinMaxD(slice);
	return(0);
}
Beispiel #17
0
/**
 * ti9x_file_read_flash:
 * @filename: name of flash file to open.
 * @content: where to store the file content.
 *
 * Load the flash file into a #FlashContent structure.
 *
 * Structure content must be freed with #tifiles_content_delete_flash when
 * no longer used. If error occurs, the structure content is released for you.
 *
 * Return value: an error code, 0 otherwise.
 **/
int ti9x_file_read_flash(const char *filename, Ti9xFlash *head)
{
	FILE *f;
	Ti9xFlash *content = head;
	long cur_pos = 0;
	int tib = 0;
	char signature[9];
	int ret = ERR_FILE_IO;

	if (head == NULL)
	{
		tifiles_critical("%s: an argument is NULL", __FUNCTION__);
		return ERR_INVALID_FILE;
	}

	if (!tifiles_file_is_flash(filename) && !tifiles_file_is_tib(filename))
	{
		ret = ERR_INVALID_FILE;
		goto tfrf2;
	}

	// detect file type (old or new format)
	tib = tifiles_file_is_tib(filename);

	f = g_fopen(filename, "rb");
	if (f == NULL) 
	{
		tifiles_info("Unable to open this file: %s", filename);
		ret = ERR_FILE_OPEN;
		goto tfrf2;
	}  

	if (fseek(f, 0, SEEK_END)) goto tfrf;
	cur_pos = ftell(f);
	if (cur_pos < 0) goto tfrf;
	if (fseek(f, 0, SEEK_SET)) goto tfrf;

	// The TI-68k series' members have at best 4 MB of Flash.
	// TIB files larger than that size are insane.
	if (cur_pos >= (4L << 20))
	{
		ret = ERR_INVALID_FILE;
		goto tfrf;
	}

	if (tib) 
	{
		// tib is an old format but mainly used by developers
		memset(content, 0, sizeof(Ti9xFlash));

		content->data_length = (uint32_t)cur_pos;

		strncpy(content->name, "basecode", sizeof(content->name) - 1);
		content->name[sizeof(content->name) - 1] = 0;
		content->data_type = 0x23;	// FLASH os

		content->data_part = (uint8_t *)g_malloc0(content->data_length);
		if (content->data_part == NULL) 
		{
			ret = ERR_MALLOC;
			goto tfrf;
		}

		if (fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf;
		switch(content->data_part[8])
		{
			case 1: content->device_type = DEVICE_TYPE_92P; break;	// TI92+
			case 3: content->device_type = DEVICE_TYPE_89; break;	// TI89
			// value added by the TI community according to HWID parameter
			// doesn't have any 'legal' existence.
			case 8: content->device_type = DEVICE_TYPE_92P; break;	// V200PLT
			case 9: content->device_type = DEVICE_TYPE_89; break;	// Titanium
		}

		content->next = NULL;
	} 
	else 
	{
		for (content = head;; content = content->next) 
		{
			if (fread_8_chars(f, signature) < 0) goto tfrf;
			content->model = tifiles_file_get_model(filename);
			if (fread_byte(f, &(content->revision_major)) < 0) goto tfrf;
			if (fread_byte(f, &(content->revision_minor)) < 0) goto tfrf;
			if (fread_byte(f, &(content->flags)) < 0) goto tfrf;
			if (fread_byte(f, &(content->object_type)) < 0) goto tfrf;
			if (fread_byte(f, &(content->revision_day)) < 0) goto tfrf;
			if (fread_byte(f, &(content->revision_month)) < 0) goto tfrf;
			if (fread_word(f, &(content->revision_year)) < 0) goto tfrf;
			if (fskip(f, 1) < 0) goto tfrf;
			if (fread_8_chars(f, content->name) < 0) goto tfrf;
			if (fskip(f, 23) < 0) goto tfrf;
			if (fread_byte(f, &(content->device_type)) < 0) goto tfrf;
			if (fread_byte(f, &(content->data_type)) < 0) goto tfrf;
			if (fskip(f, 23) < 0) goto tfrf;
			if (fread_byte(f, &(content->hw_id)) < 0) goto tfrf;
			if (fread_long(f, &(content->data_length)) < 0) goto tfrf;

			if (content->data_type != TI89_LICENSE && !check_device_type(content->device_type))
			{
				ret = ERR_INVALID_FILE;
				goto tfrf;
			}
			if (!check_data_type(content->data_type))
			{
				ret = ERR_INVALID_FILE;
				goto tfrf;
			}
			// TODO: modify this code if TI ever makes a TI-eZ80 model with more than 4 MB of Flash memory...
			if (content->data_length > 4U * 1024 * 1024 - 65536U)
			{
				// Data length larger than Flash memory size - boot code sector size doesn't look right.
				ret = ERR_INVALID_FILE;
				goto tfrf;
			}

			content->data_part = (uint8_t *)g_malloc0(content->data_length);
			if (content->data_part == NULL)
			{
				ret = ERR_MALLOC;
				goto tfrf;
			}

			if (fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf;
			if (   (content->data_type == TI83p_AMS && content->data_part[0] != 0x80)
			    || (content->data_type == TI83p_APPL && content->data_part[0] != 0x81))
			{
				ret = ERR_INVALID_FILE;
				goto tfrf;
			}
			content->next = NULL;

			// check for end of file
			if (fread_8_chars(f, signature) < 0)
			{
				break;
			}
			if (strcmp(signature, "**TIFL**") || feof(f))
			{
				break;
			}
			if (fseek(f, -8, SEEK_CUR)) goto tfrf;

			content->next = (Ti9xFlash *)g_malloc0(sizeof(Ti9xFlash));
			if (content->next == NULL) 
			{
				ret = ERR_MALLOC;
				goto tfrf;
			}
		}
	}

	fclose(f);
	return 0;

tfrf:	// release on exit
	tifiles_critical("%s: error reading / understanding file %s", __FUNCTION__, filename);
	fclose(f);
tfrf2:
	tifiles_content_delete_flash(content);
	return ret;
}
Beispiel #18
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( &current_time );

  char now[ 300 ] ;

  strcpy( now , ctime( &current_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 ) ;

}
Beispiel #19
0
/**
 * ti9x_file_read_flash:
 * @filename: name of flash file to open.
 * @content: where to store the file content.
 *
 * Load the flash file into a #FlashContent structure.
 *
 * Structure content must be freed with #tifiles_content_delete_flash when
 * no longer used. If error occurs, the structure content is released for you.
 *
 * Return value: an error code, 0 otherwise.
 **/
int ti9x_file_read_flash(const char *filename, Ti9xFlash *head)
{
	FILE *f;
	Ti9xFlash *content = head;
	int tib = 0;
	char signature[9];

	if (!tifiles_file_is_flash(filename) && !tifiles_file_is_tib(filename))
	{
		return ERR_INVALID_FILE;
	}

	if (head == NULL)
	{
		tifiles_critical("%s: an argument is NULL", __FUNCTION__);
		return ERR_INVALID_FILE;
	}

	// detect file type (old or new format)
	tib = tifiles_file_is_tib(filename);

	f = g_fopen(filename, "rb");
	if (f == NULL) 
	{
		tifiles_info("Unable to open this file: %s\n", filename);
		return ERR_FILE_OPEN;
	}  

	if (tib) 
	{	// tib is an old format but mainly used by developers
		memset(content, 0, sizeof(Ti9xFlash));
		if(fseek(f, 0, SEEK_END)) goto tfrf;
		content->data_length = (uint32_t) ftell(f);
		if(fseek(f, 0, SEEK_SET)) goto tfrf;

		strcpy(content->name, "basecode");
		content->data_type = 0x23;	// FLASH os

		content->data_part = (uint8_t *)g_malloc0(content->data_length);
		if (content->data_part == NULL) 
		{
			fclose(f);
			return ERR_MALLOC;
		}

		if(fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf;
		switch(content->data_part[8])
		{
			case 1: content->device_type = DEVICE_TYPE_92P; break;	// TI92+
			case 3: content->device_type = DEVICE_TYPE_89; break;	// TI89
			// value added by the TI community according to HWID parameter
			// doesn't have any 'legal' existence.
			case 8: content->device_type = DEVICE_TYPE_92P; break;	// V200PLT
			case 9: content->device_type = DEVICE_TYPE_89; break;	// Titanium
		}

		content->next = NULL;
	} 
	else 
	{
		for (content = head;; content = content->next) 
		{
			if(fread_8_chars(f, signature) < 0) goto tfrf;
			content->model = tifiles_file_get_model(filename);
			if(fread_byte(f, &(content->revision_major)) < 0) goto tfrf;
			if(fread_byte(f, &(content->revision_minor)) < 0) goto tfrf;
			if(fread_byte(f, &(content->flags)) < 0) goto tfrf;
			if(fread_byte(f, &(content->object_type)) < 0) goto tfrf;
			if(fread_byte(f, &(content->revision_day)) < 0) goto tfrf;
			if(fread_byte(f, &(content->revision_month)) < 0) goto tfrf;
			if(fread_word(f, &(content->revision_year)) < 0) goto tfrf;
			if(fskip(f, 1) < 0) goto tfrf;
			if(fread_8_chars(f, content->name) < 0) goto tfrf;
			if(fskip(f, 23) < 0) goto tfrf;
			if(fread_byte(f, &(content->device_type)) < 0) goto tfrf;
			if(fread_byte(f, &(content->data_type)) < 0) goto tfrf;
			if(fskip(f, 23) < 0) goto tfrf;
			if(fread_byte(f, &(content->hw_id)) < 0) goto tfrf;
			if(fread_long(f, &(content->data_length)) < 0) goto tfrf;

			if(content->data_type != TI89_LICENSE && !check_device_type(content->device_type))
			{
				return ERR_INVALID_FILE;
			}
			if(!check_data_type(content->data_type))
			{
				return ERR_INVALID_FILE;
			}

			content->data_part = (uint8_t *)g_malloc0(content->data_length);
			if (content->data_part == NULL) 
			{
				fclose(f);
				tifiles_content_delete_flash(content);
				return ERR_MALLOC;
			}

			if(fread(content->data_part, 1, content->data_length, f) < content->data_length) goto tfrf;
			content->next = NULL;

			// check for end of file
			if(fread_8_chars(f, signature) < 0)
			{
				break;
			}
			if(strcmp(signature, "**TIFL**") || feof(f))
			{
				break;
			}
			if(fseek(f, -8, SEEK_CUR)) goto tfrf;

			content->next = (Ti9xFlash *)g_malloc0(sizeof(Ti9xFlash));
			if (content->next == NULL) 
			{
				fclose(f);
				tifiles_content_delete_flash(content);
				return ERR_MALLOC;
			}
		}
	}

	fclose(f);
	return 0;

tfrf:	// release on exit
	tifiles_critical("%s: error reading / understanding file %s", __FUNCTION__, filename);
	fclose(f);
	tifiles_content_delete_flash(content);
	return ERR_FILE_IO;
}