ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/EAM_FF.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/EAM_FF.cpp (file contents):
Revision 499 by chuckv, Tue Apr 15 16:37:59 2003 UTC vs.
Revision 976 by chrisfen, Thu Jan 22 17:34:20 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
2 < #include <cstdio>
3 < #include <cstring>
1 > #include <stdlib.h>
2 > #include <stdio.h>
3 > #include <string.h>
4  
5   #include <iostream>
6   using namespace std;
# Line 28 | Line 28 | namespace EAM_NS{
28    typedef struct{
29      char name[15];
30      double mass;
31 <    double epslon;
32 <    double sigma;
31 >    double lattice_constant;
32 >    double eam_drho;  // The distance between each of the points indexed by rho.
33 >    double eam_rcut;  // The cutoff radius for eam.
34 >    double eam_dr;    // The distance between each of the rho points.    
35 >    int eam_nrho;  // Number of points indexed by rho
36 >    int eam_nr;    // The number of points based on r (Both Phi(r) and Rho(r)).
37 >    int eam_ident; // Atomic number
38      int ident;
39      int last;      //  0  -> default
40                     //  1  -> in MPI: tells nodes to stop listening
41    } atomStruct;
42  
43 <  int parseAtom( char *lineBuffer, int lineNum, atomStruct &info );
44 <  
43 >  int parseAtom( char *lineBuffer, int lineNum, atomStruct &info, char *eamPotFile );
44 >  int parseEAM( atomStruct &info, char *eamPotFile, double **eam_rvals,
45 >                double **eam_rhovals, double **eam_Frhovals);
46   #ifdef IS_MPI
47    
48    MPI_Datatype mpiAtomStructType;
# Line 48 | Line 54 | namespace EAM_NS{
54      LinkedAtomType(){
55        next = NULL;
56        name[0] = '\0';
57 +      eam_rvals    = NULL;
58 +      eam_rhovals  = NULL;
59 +      eam_Frhovals = NULL;
60      }
52    ~LinkedAtomType(){ if( next != NULL ) delete next; }
61  
62 +    ~LinkedAtomType(){
63 +      if( next != NULL ) delete next;
64 +      if( eam_rvals != NULL ) delete[] eam_rvals;
65 +      if( eam_rhovals != NULL ) delete[] eam_rhovals;
66 +      if( eam_Frhovals != NULL ) delete[] eam_Frhovals;
67 +    }
68 +
69      LinkedAtomType* find(char* key){
70        if( !strcmp(name, key) ) return this;
71        if( next != NULL ) return next->find(key);
# Line 58 | Line 73 | namespace EAM_NS{
73      }
74      
75  
76 <    void add( atomStruct &info ){
77 <    
76 >    void add( atomStruct &info, double *the_eam_rvals,
77 >              double *the_eam_rhovals,double *the_eam_Frhovals ){
78 >
79        // check for duplicates
80        
81        if( !strcmp( info.name, name ) ){
# Line 71 | Line 87 | namespace EAM_NS{
87          simError();
88        }
89        
90 <      if( next != NULL ) next->add(info);
90 >      if( next != NULL ) next->add(info, the_eam_rvals, the_eam_rhovals, the_eam_Frhovals);
91        else{
92          next = new LinkedAtomType();
93          strcpy(next->name, info.name);
94 <        next->mass     = info.mass;
95 <        next->epslon   = info.epslon;
96 <        next->sigma    = info.sigma;
97 <        next->ident    = info.ident;
94 >        next->mass             = info.mass;
95 >        next->lattice_constant = info.lattice_constant;
96 >        next->eam_nrho         = info.eam_nrho;
97 >        next->eam_drho         = info.eam_drho;
98 >        next->eam_nr           = info.eam_nr;
99 >        next->eam_dr           = info.eam_dr;
100 >        next->eam_rcut         = info.eam_rcut;
101 >        next->eam_ident        = info.eam_ident;
102 >        next->ident            = info.ident;
103 >
104 >        next->eam_rvals    = the_eam_rvals;
105 >        next->eam_rhovals  = the_eam_rhovals;
106 >        next->eam_Frhovals = the_eam_Frhovals;
107        }
108      }
109      
# Line 87 | Line 112 | namespace EAM_NS{
112      
113      void duplicate( atomStruct &info ){
114        strcpy(info.name, name);
115 <      info.mass     = mass;
116 <      info.epslon   = epslon;
117 <      info.sigma    = sigma;
118 <      info.ident    = ident;
119 <      info.last     = 0;
115 >      info.mass             = mass;
116 >      info.lattice_constant = lattice_constant;
117 >      info.eam_nrho         = eam_nrho;
118 >      info.eam_drho         = eam_drho;
119 >      info.eam_nr           = eam_nr;
120 >      info.eam_dr           = eam_dr;
121 >      info.eam_rcut         = eam_rcut;
122 >      info.eam_ident        = eam_ident;
123 >      info.ident            = ident;
124 >      info.last             = 0;
125      }
126  
127  
# Line 99 | Line 129 | namespace EAM_NS{
129  
130      char name[15];
131      double mass;
132 <    double epslon;
133 <    double sigma;
132 >    double lattice_constant;
133 >    int eam_nrho; // Number of points indexed by rho
134 >    double eam_drho; // The distance between each of the points indexed by rho.
135 >    int eam_nr;   // The number of points based on r (Both Phi(r) and Rho(r)).
136 >    double eam_dr;   // The distance between each of the rho points.
137 >    double eam_rcut; // The cutoff radius for eam.
138 >
139 >    double *eam_rvals;    // Z of r values
140 >    double *eam_rhovals;  // rho of r values
141 >    double *eam_Frhovals; // F of rho values
142 >    int eam_ident;        // eam identity (atomic number)
143      int ident;
144      LinkedAtomType* next;
145    };
# Line 110 | Line 149 | using namespace LJ_NS;
149  
150   }
151  
152 < using namespace LJ_NS;
152 > using namespace EAM_NS;
153  
154   //****************************************************************
155   // begins the actual forcefield stuff.  
# Line 123 | Line 162 | EAM_FF::EAM_FF(){
162    char* ffPath_env = "FORCE_PARAM_PATH";
163    char* ffPath;
164    char temp[200];
126  char errMsg[1000];
165  
166    headAtomType = NULL;
167    currentAtomType = NULL;
168  
169 +  // Set eamRcut to 0.0
170 +  eamRcut = 0.0;
171 +
172    // do the funtion wrapping
173    wrapMeFF( this );
174  
# Line 138 | Line 179 | EAM_FF::EAM_FF(){
179    // Init the atomStruct mpi type
180  
181    atomStruct atomProto; // mpiPrototype
182 <  int atomBC[3] = {15,3,2};  // block counts
182 >  int atomBC[3] = {15,5,5};  // block counts
183    MPI_Aint atomDspls[3];           // displacements
184    MPI_Datatype atomMbrTypes[3];    // member mpi types
185  
186    MPI_Address(&atomProto.name, &atomDspls[0]);
187    MPI_Address(&atomProto.mass, &atomDspls[1]);
188 <  MPI_Address(&atomProto.ident, &atomDspls[2]);
188 >  MPI_Address(&atomProto.eam_nrho, &atomDspls[2]);
189    
190    atomMbrTypes[0] = MPI_CHAR;
191    atomMbrTypes[1] = MPI_DOUBLE;
# Line 201 | Line 242 | EAM_FF::EAM_FF(){
242   #ifdef IS_MPI
243    }
244    
245 <  sprintf( checkPointMsg, "LJ_FF file opened sucessfully." );
245 >  sprintf( checkPointMsg, "EAM_FF file opened sucessfully." );
246    MPIcheckPoint();
247    
248   #endif // is_mpi
# Line 223 | Line 264 | void EAM_FF::initForceField( int ljMixRule ){
264   #endif // is_mpi
265   }
266  
267 < void EAM_FF::initForceField( int ljMixRule ){
267 >
268 > void EAM_FF::calcRcut( void ){
269    
270 + #ifdef IS_MPI
271 +  double tempEamRcut = eamRcut;
272 +  MPI_Allreduce( &tempEamRcut, &eamRcut, 1, MPI_DOUBLE, MPI_MAX,
273 +                 MPI_COMM_WORLD);
274 + #endif  //is_mpi
275 +  entry_plug->setDefaultRcut(eamRcut);
276 + }
277 +
278 +
279 + void EAM_FF::initForceField( int ljMixRule ){
280    initFortran( ljMixRule, 0 );
281   }
282  
# Line 243 | Line 295 | void EAM_FF::readParams( void ){
295   #endif // is_mpi
296   }
297  
298 +
299   void EAM_FF::readParams( void ){
300  
301    atomStruct info;
302    info.last = 1; // initialize last to have the last set.
303                   // if things go well, last will be set to 0
304  
252  int i;
305    int identNum;
306 +  double *eam_rvals;    // Z of r values
307 +  double *eam_rhovals;  // rho of r values
308 +  double *eam_Frhovals; // F of rho values
309 +  char eamPotFile[1000];
310    
311  
312    bigSigma = 0.0;
# Line 262 | Line 318 | void EAM_FF::readParams( void ){
318  
319      headAtomType = new LinkedAtomType;
320      
321 <    fastForward( "AtomTypes", "initializeAtoms" );
321 >    fastForward( "AtomTypes", "eam atom readParams" );
322  
323      // we are now at the AtomTypes section.
324      
# Line 282 | Line 338 | void EAM_FF::readParams( void ){
338      
339      identNum = 1;
340      // stop reading at end of file, or at next section
341 +
342      while( readLine[0] != '#' && eof_test != NULL ){
343  
344        // toss comment lines
345        if( readLine[0] != '!' ){
346          
347          // the parser returns 0 if the line was blank
348 <        if( parseAtom( readLine, lineNum, info ) ){
348 >        if( parseAtom( readLine, lineNum, info, eamPotFile ) ){
349 >          parseEAM(info,eamPotFile, &eam_rvals,
350 >                   &eam_rhovals, &eam_Frhovals);
351            info.ident = identNum;
352 <          headAtomType->add( info );;
352 >          headAtomType->add( info, eam_rvals,
353 >                             eam_rhovals,eam_Frhovals );
354            identNum++;
355          }
356        }
357        eof_test = fgets( readLine, sizeof(readLine), frcFile );
358        lineNum++;
359      }
360 +    
361 +    
362  
363   #ifdef IS_MPI
364 +  
365      
366      // send out the linked list to all the other processes
367  
368      sprintf( checkPointMsg,
369 <             "LJ_FF atom structures read successfully." );
369 >             "EAM_FF atom structures read successfully." );
370      MPIcheckPoint();
371  
372      currentAtomType = headAtomType->next; //skip the first element who is a place holder.
# Line 314 | Line 377 | void EAM_FF::readParams( void ){
377  
378        sendFrcStruct( &info, mpiAtomStructType );
379  
380 +      // We have to now broadcast the Arrays
381 +      MPI_Bcast(currentAtomType->eam_rvals,
382 +                currentAtomType->eam_nr,
383 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
384 +      MPI_Bcast(currentAtomType->eam_rhovals,
385 +                currentAtomType->eam_nr,
386 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
387 +      MPI_Bcast(currentAtomType->eam_Frhovals,
388 +                currentAtomType->eam_nrho,
389 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
390 +
391        sprintf( checkPointMsg,
392 <               "successfully sent lJ force type: \"%s\"\n",
392 >               "successfully sent EAM force type: \"%s\"\n",
393                 info.name );
394        MPIcheckPoint();
395  
# Line 333 | Line 407 | void EAM_FF::readParams( void ){
407      MPIcheckPoint();
408  
409      headAtomType = new LinkedAtomType;
410 <    recieveFrcStruct( &info, mpiAtomStructType );
411 <    
410 >    receiveFrcStruct( &info, mpiAtomStructType );
411 >
412      while( !info.last ){
413 +      
414 +      // allocate the arrays
415  
416 +      eam_rvals    = new double[info.eam_nr];
417 +      eam_rhovals  = new double[info.eam_nr];
418 +      eam_Frhovals = new double[info.eam_nrho];
419  
420 +      // We have to now broadcast the Arrays
421 +      MPI_Bcast(eam_rvals,
422 +                info.eam_nr,
423 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
424 +      MPI_Bcast(eam_rhovals,
425 +                info.eam_nr,
426 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
427 +      MPI_Bcast(eam_Frhovals,
428 +                info.eam_nrho,
429 +                MPI_DOUBLE,0,MPI_COMM_WORLD);
430 +      
431  
432 <      headAtomType->add( info );
432 >      headAtomType->add( info, eam_rvals, eam_rhovals, eam_Frhovals );
433        
434        MPIcheckPoint();
435  
436 <      recieveFrcStruct( &info, mpiAtomStructType );
436 >      receiveFrcStruct( &info, mpiAtomStructType );
437 >
438 >
439      }
440    }
441   #endif // is_mpi
# Line 353 | Line 445 | void EAM_FF::readParams( void ){
445    int isError;
446  
447    // dummy variables
448 <  int isLJ = 1;
448 >  int isLJ = 0;
449    int isDipole = 0;
450    int isSSD = 0;
451    int isGB = 0;
452 +  int isEAM = 1;
453 +  int isCharge = 0;
454    double dipole = 0.0;
455 +  double charge = 0.0;
456 +  double eamSigma = 0.0;
457 +  double eamEpslon = 0.0;
458    
459 <  currentAtomType = headAtomType;
459 >  currentAtomType = headAtomType->next;
460    while( currentAtomType != NULL ){
461      
462      if( currentAtomType->name[0] != '\0' ){
# Line 369 | Line 466 | void EAM_FF::readParams( void ){
466                   &isSSD,
467                   &isDipole,
468                   &isGB,
469 <                 &(currentAtomType->epslon),
470 <                 &(currentAtomType->sigma),
469 >                 &isEAM,
470 >                 &isCharge,
471 >                 &eamEpslon,
472 >                 &eamSigma,
473 >                 &charge,
474                   &dipole,
475                   &isError );
476        if( isError ){
# Line 384 | Line 484 | void EAM_FF::readParams( void ){
484      currentAtomType = currentAtomType->next;
485    }
486        
487 <  entry_plug->useLJ = 1;
487 >  entry_plug->useLJ = 0;
488 >  entry_plug->useEAM = 1;
489 >  // Walk down again and send out EAM type
490 >  currentAtomType = headAtomType->next;
491 >  while( currentAtomType != NULL ){
492 >    
493 >    if( currentAtomType->name[0] != '\0' ){
494 >      isError = 0;
495  
496 +      newEAMtype( &(currentAtomType->lattice_constant),
497 +                  &(currentAtomType->eam_nrho),
498 +                  &(currentAtomType->eam_drho),
499 +                  &(currentAtomType->eam_nr),
500 +                  &(currentAtomType->eam_dr),
501 +                  &(currentAtomType->eam_rcut),
502 +                  currentAtomType->eam_rvals,
503 +                  currentAtomType->eam_rhovals,
504 +                  currentAtomType->eam_Frhovals,
505 +                  &(currentAtomType->eam_ident),
506 +                  &isError);
507 +
508 +      if( isError ){
509 +        sprintf( painCave.errMsg,
510 +                 "Error initializing the \"%s\" atom type in fortran EAM\n",
511 +                 currentAtomType->name );
512 +        painCave.isFatal = 1;
513 +        simError();
514 +      }
515 +    }
516 +    currentAtomType = currentAtomType->next;
517 +  }
518 +
519 +
520 +
521   #ifdef IS_MPI
522    sprintf( checkPointMsg,
523 <           "LJ_FF atom structures successfully sent to fortran\n" );
523 >           "EAM_FF atom structures successfully sent to fortran\n" );
524    MPIcheckPoint();
525   #endif // is_mpi
526  
527 +
528 +
529   }
530  
531  
532   void EAM_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){
533    
534    int i;
535 <
535 >  
536    // initialize the atoms
537    
404
405  Atom* thisAtom;
406
538    for( i=0; i<nAtoms; i++ ){
539      
540      currentAtomType = headAtomType->find( the_atoms[i]->getType() );
# Line 416 | Line 547 | void EAM_FF::initializeAtoms( int nAtoms, Atom** the_a
547      }
548      
549      the_atoms[i]->setMass( currentAtomType->mass );
419    the_atoms[i]->setEpslon( currentAtomType->epslon );
420    the_atoms[i]->setSigma( currentAtomType->sigma );
550      the_atoms[i]->setIdent( currentAtomType->ident );
551 <    the_atoms[i]->setLJ();
551 >    the_atoms[i]->setEAM();
552 >    the_atoms[i]->setEamRcut( currentAtomType->eam_rcut);
553  
554 <    if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
554 >    if (eamRcut < currentAtomType->eam_rcut) eamRcut = currentAtomType->eam_rcut;
555 >
556    }
557   }
558  
559 < void LJ_FF::initializeBonds( int nBonds, Bond** BondArray,
559 > void EAM_FF::initializeBonds( int nBonds, Bond** BondArray,
560                               bond_pair* the_bonds ){
561    
562      if( nBonds ){
# Line 514 | Line 645 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
645  
646  
647  
648 < int EAM_NS::parseAtom( char *lineBuffer, int lineNum,  atomStruct &info ){
648 > int EAM_NS::parseAtom( char *lineBuffer, int lineNum,   atomStruct &info, char *eamPotFile ){
649  
650    char* the_token;
651    
# Line 539 | Line 670 | int EAM_NS::parseAtom( char *lineBuffer, int lineNum,
670        simError();
671      }
672          
673 <    info.epslon = atof( the_token );
674 <          
675 <    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
676 <      sprintf( painCave.errMsg,
677 <               "Error parseing AtomTypes: line %d\n", lineNum );
673 >    strcpy( eamPotFile, the_token );
674 >    return 1;
675 >  }
676 >  else return 0;
677 > }
678 >
679 > int EAM_NS::parseEAM(atomStruct &info, char *eamPotFile,
680 >                     double **eam_rvals,
681 >                     double **eam_rhovals,
682 >                     double **eam_Frhovals){
683 >  double* myEam_rvals;
684 >  double* myEam_rhovals;
685 >  double* myEam_Frhovals;
686 >
687 >  char* ffPath_env = "FORCE_PARAM_PATH";
688 >  char* ffPath;
689 >  char* the_token;
690 >  char* eam_eof_test;
691 >  FILE *eamFile;
692 >  const int BUFFERSIZE = 3000;
693 >
694 >  char temp[200];
695 >  int linenumber;
696 >  int nReadLines;
697 >  char eam_read_buffer[BUFFERSIZE];
698 >
699 >
700 >  int i,j;
701 >
702 >  linenumber = 0;
703 >
704 >  // Open eam file
705 >  eamFile = fopen( eamPotFile, "r" );
706 >  
707 >  
708 >  if( eamFile == NULL ){
709 >    
710 >      // next see if the force path enviorment variable is set
711 >    
712 >    ffPath = getenv( ffPath_env );
713 >    if( ffPath == NULL ) {
714 >      STR_DEFINE(ffPath, FRC_PATH );
715 >    }
716 >    
717 >    
718 >    strcpy( temp, ffPath );
719 >    strcat( temp, "/" );
720 >    strcat( temp, eamPotFile );
721 >    strcpy( eamPotFile, temp );
722 >    
723 >    eamFile = fopen( eamPotFile, "r" );
724 >
725 >    
726 >    
727 >    if( eamFile == NULL ){
728 >      
729 >      sprintf( painCave.errMsg,
730 >               "Error opening the EAM force parameter file: %s\n"
731 >               "Have you tried setting the FORCE_PARAM_PATH environment "
732 >               "vairable?\n",
733 >               eamPotFile );
734        painCave.isFatal = 1;
735        simError();
736      }
550        
551    info.sigma = atof( the_token );
552    
553    return 1;
737    }
738 <  else return 0;
738 >
739 >  // First line is a comment line, read and toss it....
740 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
741 >  linenumber++;
742 >  if(eam_eof_test == NULL){
743 >    sprintf( painCave.errMsg,
744 >             "error in reading commment in %s\n", eamPotFile);
745 >    painCave.isFatal = 1;
746 >    simError();
747 >  }
748 >
749 >
750 >
751 >  // The Second line contains atomic number, atomic mass and a lattice constant
752 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
753 >  linenumber++;
754 >  if(eam_eof_test == NULL){
755 >    sprintf( painCave.errMsg,
756 >             "error in reading Identifier line in %s\n", eamPotFile);
757 >    painCave.isFatal = 1;
758 >    simError();
759 >  }
760 >
761 >
762 >
763 >    
764 >  if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
765 >    sprintf( painCave.errMsg,
766 >             "Error parseing EAM ident  line in %s\n", eamPotFile );
767 >    painCave.isFatal = 1;
768 >    simError();
769 >  }
770 >  
771 >  info.eam_ident = atoi( the_token );
772 >
773 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
774 >    sprintf( painCave.errMsg,
775 >             "Error parseing EAM mass in %s\n", eamPotFile );
776 >    painCave.isFatal = 1;
777 >    simError();
778 >  }
779 >  info.mass = atof( the_token);
780 >
781 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
782 >    sprintf( painCave.errMsg,
783 >             "Error parseing EAM Lattice Constant %s\n", eamPotFile );
784 >    painCave.isFatal = 1;
785 >    simError();
786 >  }
787 >  info.lattice_constant = atof( the_token);
788 >
789 >  // Next line is nrho, drho, nr, dr and rcut
790 >  eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
791 >  if(eam_eof_test == NULL){
792 >    sprintf( painCave.errMsg,
793 >             "error in reading number of points line in %s\n", eamPotFile);
794 >    painCave.isFatal = 1;
795 >    simError();
796 >  }
797 >
798 >  if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
799 >    sprintf( painCave.errMsg,
800 >             "Error parseing EAM nrho: line in %s\n", eamPotFile );
801 >    painCave.isFatal = 1;
802 >    simError();
803 >  }
804 >  
805 >  info.eam_nrho = atoi( the_token );
806 >  
807 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
808 >    sprintf( painCave.errMsg,
809 >             "Error parseing EAM drho in %s\n", eamPotFile );
810 >    painCave.isFatal = 1;
811 >    simError();
812 >  }
813 >  info.eam_drho = atof( the_token);
814 >
815 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
816 >    sprintf( painCave.errMsg,
817 >             "Error parseing EAM # r in %s\n", eamPotFile );
818 >    painCave.isFatal = 1;
819 >    simError();
820 >  }
821 >  info.eam_nr = atoi( the_token);
822 >  
823 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
824 >    sprintf( painCave.errMsg,
825 >             "Error parseing EAM dr in %s\n", eamPotFile );
826 >    painCave.isFatal = 1;
827 >    simError();
828 >  }
829 >  info.eam_dr = atof( the_token);
830 >
831 >  if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
832 >    sprintf( painCave.errMsg,
833 >             "Error parseing EAM rcut in %s\n", eamPotFile );
834 >    painCave.isFatal = 1;
835 >    simError();
836 >  }
837 >  info.eam_rcut = atof( the_token);
838 >
839 >
840 >
841 >
842 >
843 >  // Ok now we have to allocate point arrays and read in number of points
844 >  // Index the arrays for fortran, starting at 1
845 >  myEam_Frhovals = new double[info.eam_nrho];
846 >  myEam_rvals    = new double[info.eam_nr];
847 >  myEam_rhovals  = new double[info.eam_nr];
848 >
849 >  // Parse F of rho vals.
850 >
851 >  // Assume for now that we have a complete number of lines
852 >  nReadLines = int(info.eam_nrho/5);
853 >  
854 >
855 >
856 >  for (i=0;i<nReadLines;i++){
857 >    j = i*5;
858 >
859 >    // Read next line
860 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
861 >    linenumber++;
862 >    if(eam_eof_test == NULL){
863 >      sprintf( painCave.errMsg,
864 >               "error in reading EAM file %s at line %d\n",
865 >               eamPotFile,linenumber);
866 >      painCave.isFatal = 1;
867 >      simError();
868 >    }
869 >    
870 >    // Parse 5 values on each line into array
871 >    // Value 1
872 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
873 >      sprintf( painCave.errMsg,
874 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
875 >      painCave.isFatal = 1;
876 >      simError();
877 >    }
878 >
879 >    myEam_Frhovals[j+0] = atof( the_token );
880 >    
881 >    // Value 2
882 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
883 >      sprintf( painCave.errMsg,
884 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
885 >      painCave.isFatal = 1;
886 >      simError();
887 >    }
888 >
889 >    myEam_Frhovals[j+1] = atof( the_token );
890 >    
891 >    // Value 3
892 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
893 >      sprintf( painCave.errMsg,
894 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
895 >      painCave.isFatal = 1;
896 >      simError();
897 >    }
898 >
899 >    myEam_Frhovals[j+2] = atof( the_token );
900 >    
901 >    // Value 4
902 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
903 >      sprintf( painCave.errMsg,
904 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
905 >      painCave.isFatal = 1;
906 >      simError();
907 >    }
908 >
909 >    myEam_Frhovals[j+3] = atof( the_token );
910 >
911 >    // Value 5
912 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
913 >      sprintf( painCave.errMsg,
914 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
915 >      painCave.isFatal = 1;
916 >      simError();
917 >    }
918 >
919 >    myEam_Frhovals[j+4] = atof( the_token );
920 >    
921 >  }
922 >  // Parse Z of r vals
923 >  
924 >  // Assume for now that we have a complete number of lines
925 >  nReadLines = int(info.eam_nr/5);
926 >
927 >  for (i=0;i<nReadLines;i++){
928 >    j = i*5;
929 >
930 >    // Read next line
931 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
932 >    linenumber++;
933 >    if(eam_eof_test == NULL){
934 >      sprintf( painCave.errMsg,
935 >               "error in reading EAM file %s at line %d\n",
936 >               eamPotFile,linenumber);
937 >      painCave.isFatal = 1;
938 >      simError();
939 >    }
940 >    
941 >    // Parse 5 values on each line into array
942 >    // Value 1
943 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
944 >      sprintf( painCave.errMsg,
945 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
946 >      painCave.isFatal = 1;
947 >      simError();
948 >    }
949 >    
950 >    myEam_rvals[j+0] = atof( the_token );
951 >
952 >    // Value 2
953 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
954 >      sprintf( painCave.errMsg,
955 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
956 >      painCave.isFatal = 1;
957 >      simError();
958 >    }
959 >  
960 >    myEam_rvals[j+1] = atof( the_token );
961 >
962 >    // Value 3
963 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
964 >      sprintf( painCave.errMsg,
965 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
966 >      painCave.isFatal = 1;
967 >      simError();
968 >    }
969 >  
970 >    myEam_rvals[j+2] = atof( the_token );
971 >
972 >    // Value 4
973 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
974 >      sprintf( painCave.errMsg,
975 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
976 >      painCave.isFatal = 1;
977 >      simError();
978 >    }
979 >  
980 >    myEam_rvals[j+3] = atof( the_token );
981 >
982 >    // Value 5
983 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
984 >      sprintf( painCave.errMsg,
985 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
986 >      painCave.isFatal = 1;
987 >      simError();
988 >    }
989 >  
990 >    myEam_rvals[j+4] = atof( the_token );
991 >
992 >  }
993 >  // Parse rho of r vals
994 >
995 >  // Assume for now that we have a complete number of lines
996 >
997 >  for (i=0;i<nReadLines;i++){
998 >    j = i*5;
999 >
1000 >    // Read next line
1001 >    eam_eof_test = fgets(eam_read_buffer, sizeof(eam_read_buffer),eamFile);
1002 >    linenumber++;
1003 >    if(eam_eof_test == NULL){
1004 >      sprintf( painCave.errMsg,
1005 >               "error in reading EAM file %s at line %d\n",
1006 >               eamPotFile,linenumber);
1007 >      painCave.isFatal = 1;
1008 >      simError();
1009 >    }
1010 >  
1011 >    // Parse 5 values on each line into array
1012 >    // Value 1
1013 >    if ( (the_token = strtok( eam_read_buffer, " \n\t,;")) == NULL){
1014 >      sprintf( painCave.errMsg,
1015 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
1016 >      painCave.isFatal = 1;
1017 >      simError();
1018 >    }
1019 >  
1020 >    myEam_rhovals[j+0] = atof( the_token );
1021 >
1022 >    // Value 2
1023 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1024 >      sprintf( painCave.errMsg,
1025 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
1026 >      painCave.isFatal = 1;
1027 >      simError();
1028 >    }
1029 >  
1030 >    myEam_rhovals[j+1] = atof( the_token );
1031 >
1032 >    // Value 3
1033 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1034 >      sprintf( painCave.errMsg,
1035 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
1036 >      painCave.isFatal = 1;
1037 >      simError();
1038 >    }
1039 >  
1040 >    myEam_rhovals[j+2] = atof( the_token );
1041 >
1042 >    // Value 4
1043 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1044 >      sprintf( painCave.errMsg,
1045 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
1046 >      painCave.isFatal = 1;
1047 >      simError();
1048 >    }
1049 >  
1050 >    myEam_rhovals[j+3] = atof( the_token );
1051 >
1052 >    // Value 5
1053 >    if ( (the_token = strtok( NULL, " \n\t,;")) == NULL){
1054 >      sprintf( painCave.errMsg,
1055 >               "Error parseing EAM nrho: line in %s\n", eamPotFile );
1056 >      painCave.isFatal = 1;
1057 >      simError();
1058 >    }
1059 >  
1060 >    myEam_rhovals[j+4] = atof( the_token );
1061 >
1062 >  }
1063 >  *eam_rvals = myEam_rvals;
1064 >  *eam_rhovals = myEam_rhovals;
1065 >  *eam_Frhovals = myEam_Frhovals;
1066 >
1067 >  fclose(eamFile);
1068 >  return 0;
1069   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines