TPCCLIB
Loading...
Searching...
No Matches
elements.c File Reference

Element names and symbols. See: https://iupac.org/what-we-do/periodic-table-of-elements. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcisotope.h"

Go to the source code of this file.

Functions

char * elementName (unsigned short int z)
 
char * elementSymbol (unsigned short int z)
 
unsigned short int elementIdentify (const char *str)
 

Detailed Description

Element names and symbols. See: https://iupac.org/what-we-do/periodic-table-of-elements.

Definition in file elements.c.

Function Documentation

◆ elementIdentify()

unsigned short int elementIdentify ( const char * str)

Identify the given string representation of element name or symbol.

See also
elementName, elementSymbol, isotopeIdentify
Returns
Element atomic number Z, or 0 if not identified.
Parameters
strName or symbol of element, for example 'Carbon' or 'C'.

Definition at line 298 of file elements.c.

301 {
302 if(str==NULL || strnlen(str, 5)<1) return(0);
303
304 /* First, search string from the list of element names */
305 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
306 if(strcasecmp(str, element_name[z])==0) return(z);
307
308 /* Then, search string from the list of element symbols */
309 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
310 if(strcasecmp(str, element_symbol[z])==0) return(z);
311
312 /* Not yet successful; then try to find element name as part of the string */
313 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
314 if(strcasestr(str, element_name[z])!=NULL) return(z);
315
316 /* Then try to find two-char element symbol as part of the string */
317 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
318 if(strlen(element_symbol[z])>1 && strstr(str, element_symbol[z])!=NULL) return(z);
319 /* Desperate last step... try to find one-char element symbol as part of the string */
320 for(unsigned short int z=1; z<MAX_ATOMIC_NUMBER; z++)
321 if(strlen(element_symbol[z])==1 && strstr(str, element_symbol[z])!=NULL) return(z);
322
323 return(0);
324}
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566
char * strcasestr(const char *haystack, const char *needle)
Definition stringext.c:155
#define MAX_ATOMIC_NUMBER
Max atomic number, and the size of element_symbol and element_name lists.
Definition tpcisotope.h:33

Referenced by isotopeIdentify().

◆ elementName()

char * elementName ( unsigned short int z)

Return pointer to element name.

See also
elementSymbol, elementIdentify
Returns
pointer to the name string.
Parameters
zAtomic number (Z) of the element.

Definition at line 270 of file elements.c.

273 {
274 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
275 return(element_name[z]);
276}

◆ elementSymbol()

char * elementSymbol ( unsigned short int z)

Return pointer to element symbol.

See also
elementName, elementIdentify
Returns
pointer to the symbol string.
Parameters
zAtomic number (Z) of the element.

Definition at line 284 of file elements.c.

287 {
288 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
289 return(element_symbol[z]);
290}