CCL Home Page
Up Directory CCL valid_atom
#include "utility.h"

int valid_atom(atom_name,atom_number,flag)
/*============================================================================*/
/* AUTHOR:    John R. Hurst, Data Management, 072088
/* This routine either looks up the atom name provided to make sure that
/* it is valid, or if passed an atomic number, insures that the number is
/* valid.  In either case, both the atomic number and the atom name are returned.
/*
/* CALLING SEQUENCE:
/*
/*	CALL BY:    int = valid_atom(atom_name,atom_number,flag);
/*
/* 	WHERE:      Return value: 1 indicates successful completion
/*		    0 indicates error
/*
/*		    atom_name is the address of a two character atom name
/*		    atom_number is the address of a longword.
/*		    flag is the value 1 (name is supplied) or 2 (number is
/*			supplied).
/*
/*	ON ENTRY:   if flag is 1, atom_name contains the atom name to validate.
/*	            if flag is 2, atom_number contains the atomic number to 
/*			  look up.
/*
/*	ON EXIT:    If successful, atom_name and atom_number contain valid
/*		      name and atomic number.
/*
/* ERROR CONDITIONS:
/*   If an error is encountered, 0 is returned
/* LAST MODIFICATION: 11 JUNE 1991 MVG
/*============================================================================*/
char *atom_name;
int *atom_number;
int flag;
{
  static char valid_atoms[][3] =	    /* list of valid atoms */
      {
"H ",                                                                      "He",
"Li","Be",                                        "B ","C ","N ","O ","F ","Ne",
"Na","Mg",                                        "Al","Si","P ","S ","Cl","Ar",
"K ","Ca","Sc","Ti","V ","Cr","Mn","Fe","Co",
                                   "Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
"Rb","Sr","Y ","Zr","Nb","Mo","Tc","Ru","Rh",
				   "Pd","Ag","Cd","In","Sn","Sb","Te","I ","Xe",
"Cs","Ba","La",
     "Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu",
               "Hf","Ta","W ","Re","Os","Ir",
				   "Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
"Fr","Ra","Ac",
     "Th","Pa","U ","Np","Pu","Am","Bk","Cf","Es","Fm","Md","No","Lw" 
      };
  static valid_atom_cnt = sizeof valid_atoms/sizeof valid_atoms[0];

  int i;				    /* loop variable */

/* Check for atom name in list if flag is 1. */

  if(flag == 1)
  {
    for(i=0 ; i < valid_atom_cnt; i++)
    {
      *atom_name = toupper(*atom_name);
      *(atom_name+ 1) = tolower(*(atom_name+1));
      if(strncmp(atom_name,valid_atoms[i],2) == 0)
      {
        *atom_number = i+1;
	return(1);
      }
    }
    return(0);
  }
  else
  {
    if(*atom_number < 1 || *atom_number >= valid_atom_cnt)
      return(0);
    strncpy(atom_name,valid_atoms[*atom_number-1],2);
    return(1);
  }
}
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4852 times since Sat Apr 17 21:58:50 1999 GMT