Ejemplo n.º 1
0
//main function
void main()
{ 
  int value;
  char res;

  //introduction
  printf("Queue Library\n");

  do
  {// loop of push elements
    
    printf("Please enter the number\n");
    scanf("%d", &value);
    
    //push each element one at a time
    enqueue(value);

    printf("Do you want continue?(y|n)\n");
    scanf(" %c",&res);

   } while (res == 'y' || res == 'Y');

  
  printf("The elements of the linked list are\n");
  display(); // display the result

  printf("first = %d\n", getfirst());
  printf("rear = %d\n",getrear());

  printf("pop from the queue %d\n", dequeue());

  printf("first = %d\n", getfirst());
  printf("rear = %d\n",getrear());

  printf("The elements of the linked list are\n");
  display(); // display the result

  printf("first = %d\n", getfirst());
  printf("rear = %d\n",getrear());
  
  printf("pop from the queue %d\n", dequeue());


  printf("The elements of the linked list are\n");
  display(); // display the result

  printf("first = %d\n", getfirst());
  printf("rear = %d\n",getrear());

}
Ejemplo n.º 2
0
void datendump(LIST *l)
{
	register struct Robot *rp;
	NODE *n;

	printf("Name            Spiele   Züge             Lebend    Kills"
		"         Panzerung             Munition\n");
	for(n=getfirst(l);n;n=getnext(l))
	{
		rp=getdata(n);
		printf("%-14.14s %4d %9d %7.0fø %4d %5.1f%% %4d %5.2fø %6d/%6d %5.1f%% %6d/%6d %5.1f%%\n",
			rp->name,
			rp->killed+rp->survived,
			rp->ticks,
			1.0*rp->ticks/(rp->killed+rp->survived),
			rp->survived,
			100.0*rp->survived/(rp->killed+rp->survived),
			rp->kills,
			1.0*rp->kills/(rp->killed+rp->survived),
			rp->armour,
			rp->startarmour,
			100.0*rp->armour/rp->startarmour,
			rp->mun,
			rp->startmun,
			100.0*rp->mun/rp->startmun
		);
	}
}
Ejemplo n.º 3
0
/*------------------------------------------------------------------------
 * signal  --  signal a semaphore, releasing one waiting process
 *------------------------------------------------------------------------
 */
SYSCALL signal(int sem)
{

//changes for incrementing count on syscall
int start_time;
if(call_active == 1) 
{
call_used[currpid] = 1;
call_frequency[currpid][3]++;//id for signal()=3
start_time = ctr1000;
}

	STATWORD ps;    
	register struct	sentry	*sptr;

	disable(ps);
	if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	if ((sptr->semcnt++) < 0)
		ready(getfirst(sptr->sqhead), RESCHYES);
	restore(ps);

if(call_active == 1) 
{
call_duration[currpid][3] += ctr1000 - start_time;
}
return(OK);
}
Ejemplo n.º 4
0
syscall semdelete(sid32 sem)
{
	intmask mask;
	struct semEntry *semptr;

	mask = disable();
	if(isbadsid(sem))
	{
		restore(mask);
		return SYSERR;
	}

	semptr = &semtab[sem];
	if(semptr->sestate == SE_FREE)
	{
		restore(mask);
		return SYSERR;
	}
	semptr->sestate = SE_FREE;

	while(semptr->secount++ < 0)
	{
		ready(getfirst(semptr->sequeue), RESCHED_NO);
	}
	resched();
	restore(mask);
	return OK;
}
Ejemplo n.º 5
0
syscall semreset(sid32 sem, int32 count)
{
	intmask mask;
	struct	semEntry * semptr;
	qid16	queue;
	pid32	proc;

	mask = disable();
	if(isbadsid(sem) || count<0 || semtab[sem].sestate==SE_FREE)
	{
		restore(mask);
		return SYSERR;
	}

	semptr = &semtab[sem];
	queue  = semptr->sequeue;
	//NOTE 这里的循环条件和semdelete里的应该是一样的
	while((proc = getfirst(queue)) != EMPTY)
	{
		ready(proc, RESCHED_NO);
	}

	semptr->secount = count;
	resched();
	restore(mask);
	return OK;
}
Ejemplo n.º 6
0
/*------------------------------------------------------------------------
 *  semreset  -  Reset a semaphore's count and release waiting processes
 *------------------------------------------------------------------------
 */
syscall	semreset(
    sid32		sem,		/* ID of semaphore to reset	*/
    int32		count		/* New count (must be >= 0)	*/
)
{
    intmask	mask;			/* Saved interrupt mask		*/
    struct	sentry *semptr;		/* Ptr to semaphore table entry */
    qid16	semqueue;		/* Semaphore's process queue ID	*/
    pid32	pid;			/* ID of a waiting process	*/

    mask = disable();

    if (count < 0 || isbadsem(sem) || semtab[sem].sstate==S_FREE) {
        restore(mask);
        return SYSERR;
    }

    semptr = &semtab[sem];
    semqueue = semptr->squeue;	/* Free any waiting processes */
    resched_cntl(DEFER_START);
    while ((pid=getfirst(semqueue)) != EMPTY)
        ready(pid);
    semptr->scount = count;		/* Reset count as specified */
    resched_cntl(DEFER_STOP);
    restore(mask);
    return OK;
}
Ejemplo n.º 7
0
/*------------------------------------------------------------------------
 *  sreset  --  reset the count and queue of a semaphore
 *------------------------------------------------------------------------
 */
SYSCALL sreset(int sem, int count)
{
        int start;
	if(activated == 1)
		start = ctr1000;
	STATWORD ps;    
	struct	sentry	*sptr;
	int	pid;
	int	slist;

	disable(ps);
	if (isbadsem(sem) || count<0 || semaph[sem].sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	sptr = &semaph[sem];
	slist = sptr->sqhead;
	while ((pid=getfirst(slist)) != EMPTY)
		ready(pid,RESCHNO);
	sptr->semcnt = count;
	resched();
	restore(ps);
	if(activated == 1)
	{
	        Info[currpid][SRESET].freq++;
	        Info[currpid][SRESET].time += (ctr1000 - start);
	}
	return(OK);
}
Ejemplo n.º 8
0
/**
 * Remove and return the first thread on a list
 * @param  q  target queue
 * @return thread id of removed thread, or EMPTY
 */
tid_typ dequeue(qid_typ q)
{
    int tid;

    if (isbadqid(q))
    {
        kprintf("%s:%d: isbadqid(%d) = TRUE!\n", __FILE__, __LINE__, q );
        kprintf("               quehead(x) < 0 -> %d\n", quehead(q) < 0 );
        kprintf("   quehead(x) != quetail(x)-1 -> %d\n", quehead(q) != ( quetail(q) - 1 ) );
        kprintf("          quetail(x) >= NQENT -> %d\n", quetail(q) >= NQENT );
    
        return SYSERR;
    }
    if (isempty(q))
    {
        return EMPTY;
    }

    tid = getfirst(q);
    if (!isbadtid(tid))
    {
        quetab[tid].prev = EMPTY;
        quetab[tid].next = EMPTY;
    }
    return tid;
}
Ejemplo n.º 9
0
Archivo: address.c Proyecto: daniw/mc
/**
 * Function to get the size of the Linkd List
 * @return size of the Linked List in number of data sets
 */
int getsize()
{
    nodePtr_t n = getfirst();
    int i = 0;
    while(n != NULL)
    {
        n = getnext(n);
        i++;
    }
    return i;
}
Ejemplo n.º 10
0
//-------------------------------------------
//removes element with number == n
bool derlist::delnum ( long d ) 
{
	list* pel = getfirst( );
	while ( ( pel != NULL ) && ( pel->num != d ) )
		pel = pel->next;
	if ( pel == NULL ) 
		return 1;
	if ( pel->num == d )
		pel = del ( pel );
	cout<<" Deleted! ";
	return 0;
}
Ejemplo n.º 11
0
/*------------------------------------------------------------------------
 * signal  --  signal a semaphore, releasing one waiting process
 *------------------------------------------------------------------------
 */
SYSCALL signal(register int sem)
{
	register struct	sentry	*sptr;
	sigset_t ps;

	disable(ps);
	if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	if ((sptr->semcnt++) < 0)
		ready(getfirst(sptr->sqhead), RESCHYES);
	restore(ps);
	return(OK);
}
Ejemplo n.º 12
0
//-------------------------------------------
//delete all numbers greater than minimal * 3
void derlist::delmin( ) 
{
	list *min = getlast( ), *pel, *temp;
	pel = getfirst( );
	while ( pel != NULL )
	{
		if( pel->num > 3*(min->num) ){
			temp = pel;
			pel = del( temp );
			cout<<"Removing...";

		}
		else
		pel = pel->next;
	}

}
Ejemplo n.º 13
0
//------------------------------------------------------------------------
// signal  --  signal a semaphore, releasing one waiting process
//------------------------------------------------------------------------
SYSCALL
signal(int sem)
{
	struct sentry *sptr;
	int ps;

	ps = disable();
	if (isbadsem(sem) || (sptr = &semaph[sem])->sstate == SFREE) {
		restore(ps);
		return SYSERR;
	}
	if ((sptr->semcnt++) < 0)
		readysched(getfirst(sptr->sqhead));
	restore(ps);

	return OK;
}
Ejemplo n.º 14
0
/*------------------------------------------------------------------------
 *  dequeue  -  Remove and return the first process on a list
 *------------------------------------------------------------------------
 */
pid32	dequeue(
	  qid16		q		/* ID queue to use		*/
	)
{
	pid32	pid;			/* ID of process removed	*/

	if (isbadqid(q)) {
		return SYSERR;
	} else if (isempty(q)) {
		return EMPTY;
	}

	pid = getfirst(q);
	queuetab[pid].qprev = EMPTY;
	queuetab[pid].qnext = EMPTY;
	return pid;
}
Ejemplo n.º 15
0
/*------------------------------------------------------------------------
 * ldelete  --  delete a lock by releasing its table entry
 *------------------------------------------------------------------------
 */
int ldelete (int lockdescriptor)
{

	STATWORD ps;
	int	pid;
	int temp,temp1;
	
	struct lentry *lptr;
	disable(ps);	
	
	if (isbadlock(lockdescriptor) || locks[lockdescriptor].lstate==DELETED || locks[lockdescriptor].lstate==LFREE) {	
		restore(ps);	
		return(SYSERR);	
	}	

	lptr = &locks[lockdescriptor];
	lptr->lstate = DELETED;	
	lptr->ltype = NONE;	
	lptr->lreaders= 0;	

	if (nonempty(lptr->lqhead)) {	
		while( (pid=getfirst(lptr->lqhead)) != EMPTY)		 
			{		   
				proctab[pid].plockwaitret = DELETED;		
				proctab[pid].locktype[lockdescriptor] = DELETED;	
				dequeue(pid);		  
				ready(pid,RESCHNO);	
	
				//kprintf("\n\t\t[LDELETE.C: 37] Proc '%s' deleted from waitqueue of Lock %d\n",proctab[pid].pname,lockdescriptor);		
			}		
			resched();
		}	


	for(pid=1;pid<NPROC;pid++)	{	
		if(locks[lockdescriptor].lprocs[pid] == READ || locks[lockdescriptor].lprocs[pid] == WRITE)		
			{		
				locks[lockdescriptor].lprocs[pid] = DELETED;	
			}	
	}	

	restore(ps);	
	return(OK);


}
Ejemplo n.º 16
0
Archivo: address.c Proyecto: daniw/mc
/**
 * Function to sort the Linked List
 * This function sorts accorting to the getter function given
 * @param n Pointer to the first element
 * @param getter Function pointer to the function to get the field to sort for
 */
void sortaddress(nodePtr_t n, char* (*getter)(nodePtr_t n))
{
    int s = getsize();
    int i = 0;
    int j = 0;
    nodePtr_t t = getfirst();
    nodePtr_t* a = (nodePtr_t) malloc(s * sizeof(nodePtr_t));
    
    // Preparing array to sort
    for(i = 0; i < s; i++)
    {
        a[i] = t;
        t = getnext(t);
    }
    
    // Sorting the prepared array
    for(i = 0; i < (s); i++)
    {
        for(j = 0; j < (s - i - 1); j++)
        {
            if(strcmp(getter(a[j]), getter(a[j+1])))
            {
                t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
    
    // Order data according to sorted array
    head = a[0];
    tail = a[s-1];
    a[0]->prev = NULL;
    a[0]->next = a[1];
    a[s-1]->next = NULL;
    a[s-1]->prev = a[s-2];
    for(i = 1; i < (s - 1); i++)
    {
        a[i]->next = a[i+1];
        a[i]->prev = a[i-1];
    }

    return;
}
int ldelete(int lock_value)
{
        STATWORD ps;
        int     pid, i;
        struct  lentry  *lptr;
		int lock_index;
		int lock_version;
		
        disable(ps);
		lock_index = lock_value/MAXVERSION;
		lock_version = lock_value%MAXVERSION;
		lptr=&locks[lock_index];
		
        if (locks[lock_index].lstate==LFREE) 
			{
            restore(ps);
            return(SYSERR);
        	}
		
		if(locks[lock_index].version != lock_version)
			{
            restore(ps);
            return(SYSERR);
        	}

        locks[lock_index].lstate = LFREE;
        if(nonempty(lptr->lqhead)) 
			{
            while( (pid=getfirst(lptr->lqhead)) != EMPTY)
                {
                proctab[pid].plwaitret = DELETED;
                ready(pid,RESCHNO);
                }
                resched();
        	}
		locks[lock_index].nreaders = 0;
		locks[lock_index].nwriters = 0;

		for(i = 0; i < NPROC; i++)
			lockholdtab[i][lock_index] = 0;

        restore(ps);
        return(OK);
}
Ejemplo n.º 18
0
pid32	dequeue(qid16 qid)
{
	if(isbadqid(qid))
	{
		return SYSERR;
	}
	else if (isqueue(qid))
	{
		return EMPTY;
	}

	pid32 pid;

	pid = getfirst(qid);
	queuetab[pid].qprev = EMPTY;
	queuetab[pid].qnext = EMPTY;

	return pid;
}
Ejemplo n.º 19
0
/*------------------------------------------------------------------------
 * signal  --  signal a semaphore, releasing one waiting process
 *------------------------------------------------------------------------
 */
SYSCALL signal(int sem)
{
	STATWORD ps;    
	register struct	sentry	*sptr;
	int curridx = 3;
        if(syscalltrace == 1) {
                syscallused[currpid] = 1;
                syscallcnt[currpid][curridx]++;}


	disable(ps);
	if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	if ((sptr->semcnt++) < 0)
		ready(getfirst(sptr->sqhead), RESCHYES);
	restore(ps);
	return(OK);
}
Ejemplo n.º 20
0
/*------------------------------------------------------------------------
 * signal  --  signal a semaphore, releasing one waiting process
 *------------------------------------------------------------------------
 */
SYSCALL signal(int sem)
{
	STATWORD ps;    
	register struct	sentry	*sptr;

	disable(ps);
	if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	if ((sptr->semcnt++) < 0)
		ready(getfirst(sptr->sqhead), RESCHYES);
	restore(ps);

	if( syscalls_trace )
        {
                signal_freq[currpid]++;
        }

	return(OK);
}
Ejemplo n.º 21
0
SYSCALL sreset(int sem, int count)
{
	STATWORD ps;    
	struct sentry *sptr;
	int	pid;
	int	slist;

	disable(ps);
	if (isbadsem(sem) || count<0 || semaph[sem].sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	sptr = &semaph[sem];
	slist = sptr->sqhead;
	while ((pid=getfirst(slist)) != EMPTY)
		ready(pid,RESCHNO);
	sptr->semcnt = count;
	resched();
	restore(ps);
	return(OK);
}
Ejemplo n.º 22
0
int ldelete (int lockdescriptor)
{
        STATWORD ps;
        int     pid;
        struct  lentry  *lptr;

        disable(ps);
        if (isbadlock(lockdescriptor%100) || lockarr[lockdescriptor%100].lstate==LFREE) {
                restore(ps);
                return(SYSERR);
        }
        lptr = &lockarr[lockdescriptor%100];
        lptr->lstate = LFREE;
        if (nonempty(lptr->lqhead)) {
                while( (pid=getfirst(lptr->lqhead)) != EMPTY)
                  {
                    proctab[pid].pwaitret = DELETED;
                    ready(pid,RESCHNO);
                  }
                resched();
        }
        restore(ps);
        return(OK);
}
Ejemplo n.º 23
0
/*------------------------------------------------------------------------
 * signal  --  signal a semaphore, releasing one waiting process
 *------------------------------------------------------------------------
 */
SYSCALL signal(int sem)
{

        // added for PA0 tracing
        int start_time;
        int curridx = 16;
        if(syscall_trace_on == 1) {
                syscall_used[currpid] = 1;
                syscall_cnt[currpid][curridx]++;
                start_time = ctr1000;
        }


	STATWORD ps;    
	register struct	sentry	*sptr;

	disable(ps);
	if (isbadsem(sem) || (sptr= &semaph[sem])->sstate==SFREE) {
		restore(ps);
        // added for PA0 tracing
        if(syscall_trace_on == 1) {
                syscall_time[currpid][curridx] += ctr1000 - start_time;
        }
		return(SYSERR);
	}
	if ((sptr->semcnt++) < 0)
		ready(getfirst(sptr->sqhead), RESCHYES);
	restore(ps);

        // added for PA0 tracing
        if(syscall_trace_on == 1) {
                syscall_time[currpid][curridx] += ctr1000 - start_time;
        }

	return(OK);
}
Ejemplo n.º 24
0
/*------------------------------------------------------------------------
 * sdelete  --  delete a semaphore by releasing its table entry
 *------------------------------------------------------------------------
 */
SYSCALL sdelete(int sem)
{
	STATWORD ps;    
	int	pid;
	struct	sentry	*sptr;

	disable(ps);
	if (isbadsem(sem) || semaph[sem].sstate==SFREE) {
		restore(ps);
		return(SYSERR);
	}
	sptr = &semaph[sem];
	sptr->sstate = SFREE;
	if (nonempty(sptr->sqhead)) {
		while( (pid=getfirst(sptr->sqhead)) != EMPTY)
		  {
		    proctab[pid].pwaitret = DELETED;
		    ready(pid,RESCHNO);
		  }
		resched();
	}
	restore(ps);
	return(OK);
}
Ejemplo n.º 25
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 ) ;

}
Ejemplo n.º 26
0
/*-----------------------------------------------------------------------
 * resched  --  reschedule processor to highest priority ready process
 *
 * Notes:	Upon entry, currpid gives current process id.
 *		Proctab[currpid].pstate gives correct NEXT state for
 *			current process if other than PRREADY.
 *------------------------------------------------------------------------
 */
int resched()
{
	register struct	pentry	*optr;	/* pointer to old process entry */
	register struct	pentry	*nptr;	/* pointer to new process entry */
	int itemA, itemB, itemC,proc;
	int num, i;
	//STATWORD ps;
	optr = &proctab[currpid];
	
	if(sched_type==RANDOMSCHED)
	{
		/*if(count_random==0)
		{
			count_random++;
			enqueue(dequeue(0),queueC_tail);
		}*/
		
		if((!nonempty(queueC_head)) && (!nonempty(queueC_head)) && (!nonempty(queueC_head)))
		{
			return OK;
		}
		
		proctab[currpid].quantumLeft = preempt;	//quantum used in last execution
		if(switched_to_randomsched==1)
		{
			switched_to_randomsched=0;
			proctab[currpid].procCpuTicks += (proctab[currpid].assignedQuantum - preempt);
		}
		else
		{
			proctab[currpid].procCpuTicks += (QUANTUM - preempt);
		}
		//proctab[currpid].procCpuTicks += (QUANTUM - preempt);
		
		/*Make current process as ready*/
		if (optr->pstate == PRCURR) 
		{
			//kprintf("\nen inside ");

			optr->pstate = PRREADY;
			if(((optr->pprio)>=66) && ((optr->pprio)<=99))
			{
				//kprintf("\nReady Queue A, %s", optr->pname);
				enqueue(currpid, queueA_tail);
			}
		
			else if(optr->pprio>=33 && optr->pprio<=65)
			{
				//kprintf("\nReady Queue b, %s", optr->pname);
				enqueue(currpid, queueB_tail);
			}
		
			else if(optr->pprio>=0 && optr->pprio<=32)
			{
				//kprintf("\nReady Queue c, %s", optr->pname);
				enqueue(currpid, queueC_tail);
				//enqueue(0,queueC_tail);
			}
		}
		
		//srand(1);
		generate_random:
			num = rand();
			//kprintf("\n rand 1: %d", num);
			num = (num%97);
			//kprintf("\n normalized rand 1: %d", num);
		
		
		if(num>=50)
		{
		
			if(nonempty(queueA_head))
			{	
				itemA = getfirst(queueA_head);
				//kprintf("\nresched Queue A, %d",itemA);

				nptr = &proctab[ (currpid = itemA)];//getfirst(queueA_head)) ];
				nptr->pstate = PRCURR;		/* mark it currently running	*/
				#ifdef	RTCLOCK
					preempt = QUANTUM;		/* reset preemption counter	*/
				#endif
		
				ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
		
				/* The OLD process returns here when resumed. */
				return OK;

			}
			else
				goto generate_random;//resched();
		}
		
		else if(num>20 && num <50)
		{
		
			if(nonempty(queueB_head))
			{
				itemB = getfirst(queueB_head);
				//kprintf("\nresched Queue B, %d, %s",itemB, proctab[itemB].pname);

				nptr = &proctab[ (currpid = itemB)];//getfirst(queueB_head)) ];
				nptr->pstate = PRCURR;		/* mark it currently running	*/
				#ifdef	RTCLOCK
					preempt = QUANTUM;		/* reset preemption counter	*/
				#endif
		
				ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
		
				/* The OLD process returns here when resumed. */
				return OK;

			}
			else
				goto generate_random;//resched();
		}
		
		else if(num<=20)
		{
			
			if(nonempty(queueC_head))
			{
				itemC = getfirst(queueC_head);
				//kprintf("\nresched Queue C, %d, %s",itemC, proctab[itemC].pname);

				nptr = &proctab[ (currpid = itemC)];//getfirst(queueC_head)) ];
				nptr->pstate = PRCURR;		/* mark it currently running	*/
				#ifdef	RTCLOCK
					preempt = QUANTUM;		/* reset preemption counter	*/
				#endif
		
				ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
		
				/* The OLD process returns here when resumed. */
				return OK;

			}
			else
				goto generate_random;//resched();
		}
	}



	
	
	else if(sched_type == LINUXSCHED)
	{
		//int usedPreempt = preempt;
		int highProc;
		int oldPriority = proctab[currpid].pprio;	//save the current process' priority so that the effect of chprio() or change in priority to the quantum
													// or goodness is reflected in new epoch
		//int procGoodness = 0;
		int startNewEpoch = 1;
		//disable(ps);
		proctab[currpid].quantumLeft = preempt;
		if(switched_to_linuxsched==1)
		{
			proctab[currpid].runnableProc = 1;
			switched_to_linuxsched=0;
			proctab[currpid].procCpuTicks += (QUANTUM - preempt);
			proctab[currpid].assignedQuantum = proctab[currpid].assignedQuantum -(QUANTUM - preempt);
		}
		else
		{
			proctab[currpid].procCpuTicks += (proctab[currpid].assignedQuantum - preempt);
			proctab[currpid].assignedQuantum = proctab[currpid].quantumLeft;
		}
		
		
		if(optr->pstate == PRCURR)
		{
			optr->pstate = PRREADY;
			insert(currpid, rdyhead, proctab[currpid].procGoodness);
		}
		
		
			highProc = rdytail;

			while(q[highProc].qprev!=rdyhead  && q[highProc].qprev>=0 && q[highProc].qprev<NPROC)				//q[temp].qnext!=rdytail && q[temp].qnext>=0 && q[temp].qnext<NPROC
			{
				//kprintf("\t pbdsf%s",proctab[q[highProc].qprev].pname);
				
				
				if((proctab[q[highProc].qprev].runnableProc == 1) && (proctab[q[highProc].qprev].assignedQuantum > 0 ) )	//q[highProc].qnext!=0 && 
				{
					//kprintf("\n bacha hai : %d, %s",q[highProc].qprev, proctab[q[highProc].qprev].pname);
					startNewEpoch = 0;
					break;
				}
						
				highProc = q[highProc].qprev;
			}

		
		
		if(startNewEpoch == 1)
		{
			//kprintf("\nNew Epoch started---*******");
			for(i=0; i<NPROC; i++)
			{
				if(proctab[i].pstate != PRFREE)
				{
					oldPriority = proctab[i].pprio;	//prevent priority change effect in calculation of quantum
					//proctab[i].runnableProc = 1;
					
					//calculate quantum of each process either sleeping/waiting or ready
					if(proctab[i].runnableProc == 1)
					{
						if(proctab[i].assignedQuantum > 0)
						{
							proctab[i].assignedQuantum = (oldPriority + (proctab[i].assignedQuantum /2));
							
							proctab[i].procGoodness = (oldPriority + proctab[i].quantumLeft);
							//kprintf("\nNew quantum and goodness %d, %d, %s",proctab[i].assignedQuantum, proctab[i].procGoodness, proctab[i].pname);
						}
						else
						{
							proctab[i].assignedQuantum = oldPriority;
							
							proctab[i].procGoodness = 0;//(oldPriority);
							//kprintf("\nused up quantum %d, %d, %s",proctab[i].assignedQuantum, proctab[i].procGoodness, proctab[i].pname);
						}
					}
					proctab[i].runnableProc = 1;
					//kprintf("\nFinal values of quantum and goodness %d, %d, %s",proctab[i].assignedQuantum, proctab[i].procGoodness, proctab[i].pname);
					
					dequeue(i);
					insert(i, rdyhead, proctab[i].procGoodness);
					
					
				}
			}
			
			
		}
		
		//goodness is to be calculated for process in same epoch also ? -> no
	
		highProc = rdytail;
		
		
		while(q[highProc].qprev!=rdyhead && q[highProc].qprev>=0 && q[highProc].qprev<NPROC)
		{
			
			/*kprintf("\n Highest proc based on goodness %d, %d, %d", q[highProc].qprev, proctab[q[highProc].qprev].procGoodness, proctab[q[highProc].qprev].assignedQuantum);
			if(proctab[q[highProc].qprev].pstate == PRREADY)
			{
				kprintf("\nstate: PRREADY, %d", proctab[q[highProc].qprev].runnableProc);
				
			}*/
			if( (proctab[q[highProc].qprev].runnableProc == 1) && (proctab[q[highProc].qprev].assignedQuantum > 0 ) )//&& (proctab[q[highProc].qprev].pstate==PRREADY) && q[highProc].qprev!=0 )
			{
				//kprintf(" \ninside----------- %d", currpid);
				currpid = dequeue(q[highProc].qprev);
				//kprintf(" \nnew pid----------- %d", currpid);
				//if(currpid != 0)
				//{
					nptr = &proctab[currpid];
					nptr->pstate = PRCURR;		/* mark it currently running	*/
				#ifdef	RTCLOCK
					preempt = nptr->assignedQuantum;		/* reset preemption counter	*/
				#endif
	
					ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
		
					/* The OLD process returns here when resumed. */
					return ;// OK;
					break;
				}
			
			else if( (q[rdyhead].qnext == 0) && (q[rdytail].qprev== 0))
				{
					//proctab[currpid].assignedQuantum = QUANTUM;
			//	kprintf(" \ninside----------- %d", currpid);
					nptr = &proctab[(currpid=0)];
					nptr->pstate = PRCURR;		/* mark it currently running	*/
				#ifdef	RTCLOCK
					preempt = QUANTUM;		/* reset preemption counter	*/
				#endif
					ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
		
					/* The OLD process returns here when resumed. */
					return;// OK;
					break;
				}
				highProc = q[highProc].qprev;
			}
	
	}

	
	
	

	else if(sched_type!=RANDOMSCHED && sched_type!=LINUXSCHED)
	{

		/* no switch needed if current process priority higher than next*/
	
	
		if ( ( optr->pstate == PRCURR) && (lastkey(rdytail)<optr->pprio)) 
		{
			return(OK);
		}
	
		/* force context switch */

		if (optr->pstate == PRCURR) {
			optr->pstate = PRREADY;
			insert(currpid,rdyhead,optr->pprio);
		}

		proctab[currpid].quantumLeft = preempt;
		proctab[currpid].procCpuTicks += (QUANTUM - preempt);
		/* remove highest priority process at end of ready list */

		nptr = &proctab[ (currpid = getlast(rdytail)) ];
		nptr->pstate = PRCURR;		/* mark it currently running	*/
	#ifdef	RTCLOCK
		preempt = QUANTUM;		/* reset preemption counter	*/
	#endif
	
		ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask);
	
		/* The OLD process returns here when resumed. */
		return OK;
	}
}
Ejemplo n.º 27
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);
  
  
  
  }
Ejemplo n.º 28
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 );
  









}
Ejemplo n.º 29
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 ) ;


}
Ejemplo n.º 30
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 ) ;


}