예제 #1
0
파일: tok.c 프로젝트: litcave/neateqn
/* return nonzero if current token chops the equation */
int tok_chops(int soft)
{
	if (!tok_get() || tok_curtype == T_KEYWORD)
		return 1;
	if (soft)
		return strchr(T_SOFTSEP, (unsigned char) tok_get()[0]) != NULL ;
	return def_chopped((unsigned char) tok_get()[0]);
}
예제 #2
0
파일: tok.c 프로젝트: litcave/neateqn
/* if the next token is s, return zero and skip it */
int tok_jmp(char *s)
{
	tok_blanks();
	if (tok_get() && !s[1] && strchr("{}~^\t", s[0]) && !strcmp(s, tok_get())) {
		tok_pop();
		return 0;
	}
	if (tok_type() != T_KEYWORD || !tok_get() || strcmp(s, tok_get()))
		return 1;
	tok_pop();
	return 0;
}
예제 #3
0
int get_integer( FILE *input_fp, int skip_lines, int *p_error )
{
  int answer;
  char *tok;

  tok= tok_get(input_fp, skip_lines, FALSE);

/*******************************************************************/
/**** Check all is well, tok will give FALSE if it is NULL *********/
/**** If there is a string there check the first character *********/
/**** to see if it is a valid decimal number               *********/
/**** Dave Willock March 1997 **************************************/
/*******************************************************************/

  if (tok)
    {
       if ((*tok >= '0' && *tok <= '9') || *tok == '-')
          {
             answer = atoi(tok);
             *p_error = FALSE;
          }
       else
          {
             answer= 0;
             *p_error = TRUE;
          }
    }
  else
    {
       answer= 0;
       *p_error = TRUE;
    }
  return (answer);

}
예제 #4
0
int
PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
{
	int result = tok_get(tok, p_start, p_end);
	if (tok->decoding_erred) {
		result = ERRORTOKEN;
		tok->done = E_DECODE;
	}
	return result;
}
예제 #5
0
void read_force_block( FILE *fp, e_vec *p_forces, int num_atoms)
{
  int iloop, jloop, iatom;
  int noskip=FALSE, skip=TRUE;

  char *tok;
/******** skip dotted lines *****************************/

  tok= tok_get( fp, skip, FALSE);

  printf("Reading forces for %d atoms\n", num_atoms);
  printf("throwing >>%s<<\n",tok);
  for (iatom = 0; iatom <= num_atoms; iatom++)
    {
      tok_get( fp, skip, FALSE);
      for ( jloop = 0; jloop <= 1; jloop++ ) tok= tok_get( fp, noskip, FALSE);

      p_forces->dx[iatom] = atof( tok_get( fp, noskip, FALSE ));
      p_forces->dy[iatom] = atof( tok_get( fp, noskip, FALSE ));
      p_forces->dz[iatom] = atof( tok_get( fp, noskip, FALSE ));

      printf("Just read %10.6f %10.6f %10.6f\n", p_forces->dx[iatom]
                                               , p_forces->dy[iatom]
                                               , p_forces->dz[iatom]);
    }
  return;
}
예제 #6
0
int read_xdatcar(FILE *fp, int *p_num_frames, atom *p_molecule, int num_atoms,
                 coord_flags *p_fix_flags, int *p_iconf, int *p_is_fract, int *p_is_cart )
{
  int ichar[LINESIZ];
  int iatom,idummy;
  int skip, lower_case=FALSE;
  int error, good_line;

  char *p_key;
  char *tok;

/* assume xdatcar file is just a read after atoms have been sorted out */
/* On first call the number of frames is assumed to be negative        */

   printf("Trying to read XDATCAR file format\n");

   if (*p_num_frames < 0)
     {
        
/*** Skip title line ****/
        skip = TRUE;
        tok= tok_get(fp, skip, lower_case);
        printf("Read: %s\n", tok);

/*** Skip the integer and the lattice vectors ****/
        idummy = get_integer( fp, skip, &error ); 
        printf("The integer = %d\n",idummy);

/*** Jump lines to set up for first frame read next time in here ***/
        skip=TRUE;
        tok= tok_get(fp, skip, lower_case);
        printf("TOK: %s\n",tok);
        tok= tok_get(fp, skip, lower_case);
        printf("TOK: %s\n",tok);
        tok= tok_get(fp, skip, lower_case);
        printf("TOK: %s\n",tok);
        tok= tok_get(fp, skip, lower_case);
        printf("TOK: %s\n",tok);   
        tok= tok_get(fp, skip, lower_case);
        printf("TOK: %s\n",tok);   

        return 0;
    }
  else
    {
      printf("Back in read_xdatcar to get another frame\n");

/*** Should be left with a line to skip between frames ***/
/*** If this moves to end of file we can stop....      ***/

     skip=TRUE;
     tok= tok_get(fp, skip, lower_case);
     printf("TOK: %s",tok);   

     if (strcmp(tok, END_OF_INPUT) == 0) return FALSE;

     skip=FALSE; 
     tok= tok_get(fp, skip, lower_case);
     printf("  TOK: %s",tok);   
     if (strcmp(tok, "Direct"))
     {
	printf("This is a direct lattice fractional coordinates.\n");
	*p_is_fract=TRUE;
	*p_is_cart=FALSE;
     }
     else
     {
	printf("This is a direct lattice fractional coordinates.\n");
	*p_is_cart=TRUE;
        *p_is_fract=FALSE;
     }
     tok= tok_get(fp, skip, lower_case);
     printf("  TOK: %s\n",tok);   

     *p_iconf= atoi(tok);
     printf("XDATCAR says configuration %d\n", *p_iconf);
     

 /**** Must already have number of frames and am now just reading one in ****/
      skip = TRUE;    
 /**** First skip blank line ***/
/*      while (!(tok= tok_get(fp, skip, lower_case))); */

/*      fscanf(fp,"\n"); */
/*      printf("TOK: %s\n",tok);  */

      for (iatom=0; iatom < num_atoms; iatom++)
        {
          good_line = read_atom_data_vasp( fp, p_molecule, &idummy, p_fix_flags );

          printf("Read: %10.6f  %10.6f  %10.6f good= %d\n", p_molecule->x,
                                                            p_molecule->y,
                                                            p_molecule->z, good_line);
          p_molecule++;
        }
     printf("Frame read so off back to main.....\n");
    }

  return good_line;
}
예제 #7
0
int read_doscar( FILE *fp, dos *p_ndos, int need_pdos, int *p_part_dos_list,
                 int num_atoms_pdos, dos *p_pdos, int *p_spd, int num_columns )
{
    int iloop, jloop, iatom, iorb;
    int found, sep;
    int skip=TRUE;
    int noskip=FALSE;
    int num_to_skip;
    int error, good_read;
    int num_dos, this_num_dos;
    int pdos_atom;

    dos *p_this_pdos;

    double e_min, e_max;
    double this_e_min, this_e_max;
    double pop, pop2;

    char *p_key, *p_key2, *p_key3;
    char *tok, *tok2, *p_letter;

    printf("Entered read_dos\n");
    p_key= "none";
    p_key2= "system";
    sep = 0;
    num_dos = -1;

    tok= tok_get( fp, skip, FALSE);

    find_line( fp, p_key, p_key2, sep, &found, -1 );

    if (found)
    {
        if (strcmp(p_key,"none") != 0 )
            printf("Found >>%s<< in DOSCAR file\n", p_key);
        else
            printf("Found >>%s<< in DOSCAR file\n", p_key2);

        tok= tok_get( fp, skip, FALSE);
        e_max = atof(tok);
        printf("got e_max as %10.6f\n", e_max);

        tok= tok_get( fp, noskip, FALSE);
        e_min = atof(tok);
        printf("got e_min as %10.6f\n", e_min);

        tok= tok_get( fp, noskip, FALSE);
        num_dos = atoi(tok);
        printf("got num_dos as %d\n", num_dos);

        if (num_dos > MAX_DOS)
        {
            printf("ERROR : Number of points in DOSCAR file (%d) exceeds MAX_DOS (%d).\n",
                   num_dos, MAX_DOS);
            exit(0);
        }

        printf("File e_min = %10.6f, e_max = %10.6f, num_dos = %d\n",
               e_min, e_max, num_dos);
        printf("Number of columns = %d\n", num_columns);

        if (num_dos > 0)
        {
            for(iloop=0; iloop < num_dos; iloop++)
            {
                /*** If spin restricted ... ***/
                if (num_columns == 2 || num_columns == 5 || num_columns == 11)
                {
                    p_ndos->energy = atof(tok_get( fp, skip, FALSE));

                    p_ndos->up_dos = atof(tok_get( fp, noskip, FALSE));
                    p_ndos->up_totdos = atof(tok_get( fp, noskip, FALSE));

                    printf("Read from doscar: %10.6f  %10.6f  %10.6f\n",
                           p_ndos->energy,
                           p_ndos->up_dos,
                           p_ndos->up_totdos);
                }
                /*** If spin unrestricted ... ***/
                else if (num_columns == 4 || num_columns == 10 || num_columns == 22)
                {
                    p_ndos->energy = atof(tok_get( fp, skip, FALSE));

                    p_ndos->up_dos = atof(tok_get( fp, noskip, FALSE));
                    p_ndos->down_dos = atof(tok_get( fp, noskip, FALSE));
                    p_ndos->up_totdos = atof(tok_get( fp, noskip, FALSE));
                    p_ndos->down_totdos = atof(tok_get( fp, noskip, FALSE));

                    printf("Read from doscar: %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n",
                           p_ndos->energy,
                           p_ndos->up_dos,
                           p_ndos->down_dos,
                           p_ndos->up_totdos,
                           p_ndos->down_totdos);
                }

                p_ndos++;
            }
        }
        else
        {
            printf("ERROR: Bad num_dos read in DOSCAR file\n");
            exit(0);
        }
    }
    else
    {
        printf("Keyword >>%s<< not found when reading DOSCAR file\n", p_key);
        exit(0);
    }

    if ( need_pdos )
    {
        printf("Building pdos\n");

        iatom=1;
        pdos_atom=0;
        while (iatom <= *(p_part_dos_list+num_atoms_pdos))
        {
            /**** Next line should be pdos header line ****/

            tok= tok_get( fp, skip, FALSE);
            /**** Alert the user if this fails to check that PDOS was created ****/
            if (!tok || strcmp(tok, "Thatsit") == 0)
            {
                printf("ERROR: Failure while reading PDOS data, did you ask for PDOS (LORBIT = 12) in INCAR?\n");
                exit(0);
            }
            this_e_max = atof(tok);

            tok= tok_get( fp, noskip, FALSE);
            this_e_min = atof(tok);

            tok= tok_get( fp, noskip, FALSE);
            this_num_dos = atoi(tok);

            /**** Test consistency of this pdos header line with the original information from the dos ****/
            if (fabs(e_min-this_e_min) > 0.0001)
            {
                printf("ERROR: Minimum energy given in PDOS title is inconsistent with DOSCAR header\n");
                printf("ERROR: Read %10.6f DOSCAR header %10.6f\n", this_e_min, e_min);
                exit(0);
            }
            if (fabs(e_max-this_e_max) > 0.0001)
            {
                printf("ERROR: Maximum energy given in PDOS title is inconsistent with DOSCAR header\n");
                printf("ERROR: Read %10.6f DOSCAR header %10.6f\n", this_e_max, e_max);
                exit(0);
            }
            if ( num_dos - this_num_dos != 0 )
            {
                printf("ERROR: Number of entries reported in PDOS title is inconsistent with DOSCAR header\n");
                printf("ERROR: Read %d DOSCAR header %d\n", this_num_dos, num_dos);
                exit(0);
            }

            /**** See if we need this atoms data ****/
            printf("iatom = %d\n", iatom);
            if (iatom == *(p_part_dos_list+pdos_atom))
            {
                printf("Reading this pdos contribution\n");
                p_this_pdos = p_pdos;

                printf("Entered first atom in PDOS list\n");
                for(iloop=0; iloop < num_dos; iloop++)
                {

                    tok=tok_get( fp, skip, FALSE);

                    if (pdos_atom == 0)
                    {
                        /**** First acceptable contribution to pdos ****/
                        p_this_pdos->energy = atof(tok);
                        /**** Second or higher acceptable contribution to pdos ****/
                    }
                    else
                    {
                        if (fabs(atof(tok)-p_this_pdos->energy) > 0.0001)
                        {
                            printf("ERROR: Energy scale changed during PDOS read\n");
                            printf("ERROR: Read %10.6f reference is %10.6f\n", atof(tok),
                                   p_this_pdos->energy);
                            exit(0);
                        }
                    }

                    if (pdos_atom == 0) p_this_pdos->up_dos =0.0;
                    iorb = 0;

                    while ( (tok = tok_get( fp, noskip, FALSE)) )
                    {
                        /**** s, p, d orbitals ****/
                        if (num_columns == 5)
                        {
                            if (*(p_spd+iorb)) p_this_pdos->up_dos += atof(tok);
                            iorb++;
                        }
                        /**** s, px, py, pz, dxy, dyz, dxz, dx2-y2, dz2 orbitals ****/
                        else if (num_columns == 11)
                        {

                            if (iorb == 0)
                            {
                                pop = atof(tok);
                            }
                            else if (iorb == 1)
                            {
                                pop = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                            }
                            else if (iorb == 2)
                            {
                                pop = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                            }
                            else if (iorb > 2)
                            {
                                printf("ERROR: Too many orbitals in PDOS entries of DOSCAR file.\n");
                                printf("ERROR: Only expecting spd level but iorb = %d.\n", iorb);
                                exit(0);
                            }
                            if (*(p_spd+iorb)) p_this_pdos->up_dos += pop;
                            iorb++;
                        }
                        /**** s, p, d orbitals, spin unrestricted ****/
                        else if (num_columns == 10)
                        {
                            if (*(p_spd+iorb))
                            {
                                p_this_pdos->up_dos += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                p_this_pdos->down_dos += atof(tok);
                            }
                            iorb++;
                        }
                        /**** s, px, py, pz, dxy, dyz, dxz, dx2-y2, dz2 orbitals, spin unrestricted ****/
                        else if (num_columns == 22)
                        {
                            if (iorb == 0)
                            {
                                pop = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 = atof(tok);
                            }
                            else if (iorb == 1)
                            {
                                pop = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                            }
                            else if (iorb == 2)
                            {
                                pop = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 = atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop += atof(tok);
                                tok = tok_get( fp, noskip, FALSE);
                                pop2 += atof(tok);
                            }
                            else if (iorb > 2)
                            {
                                printf("ERROR: Too many orbitals in PDOS entries of DOSCAR file.\n");
                                printf("ERROR: Only expecting spd level but iorb = %d.\n", iorb);
                                exit(0);
                            }

                            if (*(p_spd+iorb))
                            {
                                p_this_pdos->up_dos += pop;
                                p_this_pdos->down_dos += pop2;
                            }
                            iorb++;
                        }
                        else
                        {
                            printf("ERROR: Unrecognised number of columns in pdos section of DOSCAR file\n");
                            exit(0);
                        }
                    }
                    p_this_pdos++;

                }
                pdos_atom++;
            }

            else
            {
                /**** If not needed read in the lines to ensure proper skipping *****/

                for(iloop=0; iloop < num_dos; iloop++) tok=tok_get( fp, skip, FALSE);
            }

            iatom++;
        }
    }

    return num_dos;
}
예제 #8
0
파일: tok.c 프로젝트: gaoxiaojun/neatcc
int tok_see(void)
{
	if (next == -1)
		next = tok_get();
	return next;
}
예제 #9
0
int read_xdatcar( FILE *fp, int *p_num_frames, atom *p_molecule, int num_atoms,
                  coord_flags *p_fix_flags )
{
    int ichar[LINESIZ];
    int iatom,idummy;
    int skip, lower_case=FALSE;
    int error;

    char *p_key;
    char *tok;

    /* assume xdatcar file is just a read after atoms have been sorted out */

    printf("Trying to read XDATCAR file format\n");

    if (*p_num_frames < 0)
    {
        /* get number of frames */
        skip = TRUE;
        idummy = get_integer( fp, skip, &error );
        printf("%d\n",idummy);
        skip = FALSE;
        idummy = get_integer( fp, skip, &error );
        printf("%d\n",idummy);
        *p_num_frames = get_integer( fp, skip, &error );
        printf("%d\n",*p_num_frames);

        if (error)
        {
            printf("ERROR: Bad file format on first line of XDATCAR\n");
            exit(0);
        }
        else
        {
            /*** Jump lines to set up for first frame read next time in here ***/
            skip=TRUE;
            tok= tok_get(fp, skip, lower_case);
            printf("TOK: %s\n",tok);
            tok= tok_get(fp, skip, lower_case);
            printf("TOK: %s\n",tok);
            tok= tok_get(fp, skip, lower_case);
            printf("TOK: %s\n",tok);
            tok= tok_get(fp, skip, lower_case);
            printf("TOK: %s\n",tok);

            return 0;
        }
    }
    else
    {
        /**** Must already have number of frames and am now just reading one in ****/
        skip = TRUE;
        printf("Back in read_xdatcar for another frame\n");
        /**** First skip blank line ***/
        /*      while (!(tok= tok_get(fp, skip, lower_case))); */
        /*      printf("TOK: %s\n",tok);  */

        for (iatom=0; iatom < num_atoms; iatom++)
        {
            read_atom_data_vasp( fp, p_molecule, &idummy, p_fix_flags );

            printf("Read: %10.6f  %10.6f  %10.6f\n", p_molecule->x,
                   p_molecule->y,
                   p_molecule->z);
            p_molecule++;
        }
    }

    printf("Frame read back to main.....\n") ;

    return 0;
}
예제 #10
0
  void find_line_with_stopper(FILE *fp, char *p_key, char *p_key2, char *p_stopper, int sep, int *p_found, int max_lines)
    {
      int skip = TRUE;
      int noskip = FALSE;
      int num_read;
      int iloop, done;
      int hit_stopper;

      char *tok, *tok2;

      printf("In find_line_with_stopper looking for %s and %s %d apart, will watch for stopper: %s\n", p_key, p_key2, sep, p_stopper);
      done = FALSE;

/****************************************************/
/*** If p_key is not "none" then read a new tok for */
/*** testing. Otherwise we must be only testing on  */
/*** p_key2, so tok can be anything and read in a   */
/*** new tok2.                                      */
/****************************************************/
      if (strcmp(p_key, "none") != 0) 
        {
          tok = tok_get( fp, skip, FALSE);
        }
      else
        {
           tok2 = tok_get( fp, skip, FALSE);
           tok = "none";
        }
          
      num_read=1;

/****************************************************/
/*** If we are testing on p_key2 need to get the ****/
/*** right position (sep) on the line            ****/
/****************************************************/
      if ( strcmp(p_key2, "none") != 0) 
         {
           for (iloop=0; iloop <= sep; iloop++) tok2= tok_get( fp, noskip, FALSE);
         }
      else
         {
           tok2 = "none";
         }
/****************************************************/
/*** See if first line has hit the spot *************/
/****************************************************/
     if (strcmp(p_key, "none") != 0 && strcmp(p_key2, "none") != 0)   
       {
          printf("Testing first line >>%s<< >>%s<<\n", tok, tok2);
          if (tok && strcmp(p_key, tok) == 0 && tok2 && strcmp(p_key2, tok2) == 0) done=TRUE;

          if (tok && strcmp(p_stopper, tok) == 0)
            {
               done=TRUE;
               hit_stopper=TRUE;
            }
       }
/****************************************************/
/** Case where p_key is not "none" but p_key2 is  ***/
/****************************************************/
     else if (strcmp(p_key, "none") != 0)
       {
          if (tok && strcmp(p_key, tok) == 0) done=TRUE;

          if (tok && strcmp(p_stopper, tok) == 0)
            {
               done=TRUE;
               hit_stopper=TRUE;
            }
       }
/****************************************************/
/** Case where p_key2 is not "none" but p_key is  ***/
/****************************************************/
     else if (strcmp(p_key2, "none") != 0)
       {
          if (tok2 && strcmp(p_key2, tok2) == 0) done=TRUE;

          if (tok2 && strcmp(p_stopper, tok2) == 0)
            {
               done=TRUE;
               hit_stopper=TRUE;
            }
       }


      if (done) printf("Returning after first line\n");
/****************************************************/
/*** Loop to test remaining lines *******************/
/****************************************************/

      while (!done)
         {
            if (num_read > 1 ) 
              {
                if (strcmp(p_key, "none") != 0) 
                   {
                        tok= tok_get( fp, skip, FALSE);
                   }
                else
                   {
                        tok2= tok_get( fp, skip, FALSE);
                   }
              }

            num_read++;
/****************************************************/
/*** If requested only go forward max_lines *********/
/****************************************************/
            if ( max_lines > 0 && num_read > max_lines ) 
              {
                done = TRUE;
                printf("find_line checked %d lines returning\n", num_read);
                *p_found= FALSE;
                return;
              }
            if (debug) printf(".....................Testing >>%s<< >>%s<<\n", tok, tok2);

            if ( tok && strcmp(tok,"none") != 0 && strcmp(tok,p_key) == 0 && strcmp(p_key2, "none") != 0) 
              {
                 if (num_read > 0) 
                            for (iloop=0; iloop <= sep; iloop++) tok2= tok_get( fp, noskip, FALSE);

                 done = done || strcmp(p_key2, tok2) == 0;      
                 printf("Read >>%s<< and >>%s<<\n", tok, tok2);
                 if ( done ) printf("Happy with that!\n");

              }
            else if ( tok2 && strcmp(p_key,"none") == 0) 
              {

                 if (num_read > 0) 
                            for (iloop=0; iloop <= sep; iloop++) if (tok2) tok2= tok_get( fp, noskip, FALSE);

                 done = done || (tok2 && strcmp(p_key2, tok2) == 0);      
                 if (tok2) printf("Read >>%s<<\n", tok2);
                 if ( done ) 
                   {
                      printf("Happy with that!\n");
                      *p_found = TRUE;
                      return;
                   }

/*** Check for stopper ***/
                 if (tok2 && strcmp(p_stopper, tok) == 0)
                   {
                      done=TRUE;
                      hit_stopper=TRUE;
                   }

              }
/*** Check for stopper ***/
            else if (tok && strcmp(p_stopper, tok) == 0)
              {
                done=TRUE;
                hit_stopper=TRUE;
              }
            else if ( tok && strcmp(tok,"none") != 0 && strcmp(tok,p_key) == 0) 
              {
                 done = TRUE;
                 *p_found = TRUE;
                 return;
              }

            if ( (tok && strcmp(tok,END_OF_INPUT) == 0) || (tok2 && strcmp(tok2,END_OF_INPUT) == 0) ) 
              {
		 if (!*p_found)
	           {
                     if ( strcmp(p_key2, "none") == 0) 
                       {
                         printf("ERROR the key >>%s<< not found in file\n",
                                    p_key);
                       }
                     else if ( strcmp(p_key, "none") == 0) 
                       {
                         printf("ERROR the key >>%s<< not found in position %d in file\n",
                                    p_key2, sep);
                       }
                     else
                       {
                         if (max_lines > 0)
                           {
                              printf("WARNING the keys >>%s<< and >>%s<< not found %d words apart in file\n",
                                                 p_key, p_key2, sep); 
                              return;
                           }
                         else
                           {
                              printf("ERROR the keys >>%s<< and >>%s<< not found %d words apart in file\n",
                                                 p_key, p_key2, sep); 
                           }
                       }
		   }
		 else
	           {
                      *p_found=FALSE;
		      return;
	           }
                 exit(0);
              }
         }
     if (done && !hit_stopper)
       {
         *p_found=TRUE;
       }
     else
       {
         printf("Hit stopper in find_line\n");
         *p_found=FALSE;
       }
     return;
    }
예제 #11
0
int read_poscar( FILE *fp, int *p_title_line, 
                 atom *p_molecule, int *p_date_line, int *p_pbc, int *p_num_atoms, 
                 int *p_num_of_mols, int *p_num_mol_members, int *p_mol_number, 
                 double *p_latt_vec, double *p_recip_latt_vec, double *p_abc, int *p_been_before, 
		 int *p_is_fract, int *p_is_cart, int *p_ion_number, int *p_num_types, 
                 double *p_scale_factor, coord_flags *p_fix_flags)

{
  int ichar[LINESIZ];
  int place,itsanum;
  int idave,num_of_chars,is_biosym,idummy,iloop;
  int at_end, skip, lower_case;
  int start,start2,start3,start4;
  int error, good_read;
  int *p_this_ion_number;

  double dot, cell_volume;
  double a_cross_b[3], b_cross_c[3], c_cross_a[3];

  char *p_key;
  char *tok;

  atom *p_atom;

/* assume poscar file only ever contains one molecule */

     *p_num_of_mols=1;

/* get title line */

     num_of_chars= read_line ( fp, p_title_line);
     printf("Read title line: \n");
     put_string(stdout, p_title_line, num_of_chars);
     printf("\n");

/* get scale factor */

     skip= TRUE;
     lower_case= TRUE;
     
     *p_scale_factor = get_double( fp, skip, &error);

     if (!error)
       printf("Scale factor %10.6f\n", *p_scale_factor);
     else
       printf("Error while reading scale factor from POSCAR\n");

/* VASP POSCAR is always periodic, work out cell vectors and angles */
/* VASP POSCAR has lattice vectors in array as:   ax ay az          */
/* VASP POSCAR                                    bx by bz          */
/* VASP POSCAR                                    cx cy cz          */

     skip= TRUE;
     *p_latt_vec        = get_double(fp, skip, &error);
     skip= FALSE;
     *(p_latt_vec+1)    = get_double(fp, skip, &error);
     *(p_latt_vec+2)    = get_double(fp, skip, &error);

     skip= TRUE;
     *(p_latt_vec+3)    = get_double(fp, skip, &error);
     skip= FALSE;
     *(p_latt_vec+4)    = get_double(fp, skip, &error);
     *(p_latt_vec+5)    = get_double(fp, skip, &error);

     skip= TRUE;
     *(p_latt_vec+6)    = get_double(fp, skip, &error);
     skip= FALSE;
     *(p_latt_vec+7)    = get_double(fp, skip, &error);
     *(p_latt_vec+8)    = get_double(fp, skip, &error);

    latt_vecs_from_cart( p_latt_vec, p_recip_latt_vec, p_abc );

/* Read in the ion number flags */

      skip = TRUE;
	      
      error = FALSE;
      *p_num_types=0;
      p_this_ion_number =p_ion_number;
      while (!error)
	{
          *p_this_ion_number=get_integer( fp, skip, &error );

          skip = FALSE;
          ++*p_num_types;
          if (*p_num_types < MAXTYPES)
            {
               p_this_ion_number++;
            }
          else
            {
               printf("ERROR: MAXTYPES exceeded while reading VASP POSCAR file\n");
               exit(0);
            }
        }

      --*p_num_types;

      printf("Have %d types of ion with ",*p_num_types);

      *p_num_atoms=0;
      p_this_ion_number =p_ion_number;
      for (iloop=0; iloop < *p_num_types; iloop++)
	{
	   printf("%d, ", *p_this_ion_number);
	   *p_num_atoms += *p_this_ion_number;
           p_this_ion_number++;
	}

      printf(" instances of each, totaling %d\n", *p_num_atoms);

/* Read in the direct/cartesian flag data */

    skip=TRUE;
    tok = tok_get( fp, skip, TRUE);
    printf("Next read >>%s<<\n",tok);

/* Ignore Selective Dynamics line if present */

    if (!strncmp(tok,"sel",3))
      {
        tok = tok_get( fp, skip, TRUE);
        printf("Trying to skip Selective Dynamics, read >>%s<<\n",tok);
      }

    if (!strcmp(tok,"direct"))
    {
       printf("We have fractionals\n");
       *p_is_fract = TRUE;
    }
    else
    {
       printf("We have cartesians\n");
       *p_is_fract = FALSE;
    }

/* Read in the atomic data */

      for (iloop=0; iloop < *p_num_atoms; iloop++)
       {
        good_read= read_atom_data_vasp( fp, p_molecule+iloop, p_mol_number,  
                                                  p_fix_flags );
        p_fix_flags++;
       }

      printf("Co-ordinates read in:\n");
      for (iloop=0; iloop < *p_num_atoms; iloop++)
	      printf("%10.6f %10.6f %10.6f\n", (p_molecule+iloop)->x,
			                       (p_molecule+iloop)->y,
					       (p_molecule+iloop)->z);

  return 0;
}