TPCCLIB
Loading...
Searching...
No Matches
elements.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "tpcclibConfig.h"
7/*****************************************************************************/
8#include <stdio.h>
9#include <stdlib.h>
10#include <math.h>
11#include <time.h>
12#include <string.h>
13/*****************************************************************************/
14#include "tpcisotope.h"
15/*****************************************************************************/
16
17/*****************************************************************************/
19static char *element_symbol[] = {
20"Unknown",
21"H",
22"He",
23"Li",
24"Be",
25"B",
26"C",
27"N",
28"O",
29"F",
30"Ne",
31"Na",
32"Mg",
33"Al",
34"Si",
35"P",
36"S",
37"Cl",
38"Ar",
39"K",
40"Ca",
41"Sc",
42"Ti",
43"V",
44"Cr",
45"Mn",
46"Fe",
47"Co",
48"Ni",
49"Cu",
50"Zn",
51"Ga",
52"Ge",
53"As",
54"Se",
55"Br",
56"Kr",
57"Rb",
58"Sr",
59"Y",
60"Zr",
61"Nb",
62"Mo",
63"Tc",
64"Ru",
65"Rh",
66"Pd",
67"Ag",
68"Cd",
69"In",
70"Sn",
71"Sb",
72"Te",
73"I",
74"Xe",
75"Cs",
76"Ba",
77"La",
78"Ce",
79"Pr",
80"Nd",
81"Pm",
82"Sm",
83"Eu",
84"Gd",
85"Tb",
86"Dy",
87"Ho",
88"Er",
89"Tm",
90"Yb",
91"Lu",
92"Hf",
93"Ta",
94"W",
95"Re",
96"Os",
97"Ir",
98"Pt",
99"Au",
100"Hg",
101"Tl",
102"Pb",
103"Bi",
104"Po",
105"At",
106"Rn",
107"Fr",
108"Ra",
109"Ac",
110"Th",
111"Pa",
112"U",
113"Np",
114"Pu",
115"Am",
116"Cm",
117"Bk",
118"Cf",
119"Es",
120"Fm",
121"Md",
122"No",
123"Lr",
124"Rf",
125"Db",
126"Sg",
127"Bh",
128"Hs",
129"Mt",
130"Ds",
131"Rg",
132"Cn",
133"Nh",
134"Fl",
135"Mc",
136"Lv",
137"Ts",
138"Og",
1390};
140/*****************************************************************************/
142static char *element_name[] = {
143"Unknown",
144"Hydrogen",
145"Helium",
146"Lithium",
147"Beryllium",
148"Boron",
149"Carbon",
150"Nitrogen",
151"Oxygen",
152"Fluorine",
153"Neon",
154"Sodium",
155"Magnesium",
156"Aluminium",
157"Silicon",
158"Phosphorus",
159"Sulfur",
160"Chlorine",
161"Argon",
162"Potassium",
163"Calcium",
164"Scandium",
165"Titanium",
166"Vanadium",
167"Chromium",
168"Manganese",
169"Iron",
170"Cobalt",
171"Nickel",
172"Copper",
173"Zinc",
174"Gallium",
175"Germanium",
176"Arsenic",
177"Selenium",
178"Bromine",
179"Krypton",
180"Rubidium",
181"Strontium",
182"Yttrium",
183"Zirconium",
184"Niobium",
185"Molybdenum",
186"Technetium",
187"Ruthenium",
188"Rhodium",
189"Palladium",
190"Silver",
191"Cadmium",
192"Indium",
193"Tin",
194"Antimony",
195"Tellurium",
196"Iodine",
197"Xenon",
198"Caesium",
199"Barium",
200"Lanthanum",
201"Cerium",
202"Praseodymium",
203"Neodymium",
204"Promethium",
205"Samarium",
206"Europium",
207"Gadolinium",
208"Terbium",
209"Dysprosium",
210"Holmium",
211"Erbium",
212"Thulium",
213"Ytterbium",
214"Lutetium",
215"Hafnium",
216"Tantalum",
217"Tungsten",
218"Rhenium",
219"Osmium",
220"Iridium",
221"Platinum",
222"Gold",
223"Mercury",
224"Thallium",
225"Lead",
226"Bismuth",
227"Polonium",
228"Astatine",
229"Radon",
230"Francium",
231"Radium",
232"Actinium",
233"Thorium",
234"Protactinium",
235"Uranium",
236"Neptunium",
237"Plutonium",
238"Americium",
239"Curium",
240"Berkelium",
241"Californium",
242"Einsteinium",
243"Fermium",
244"Mendelevium",
245"Nobelium",
246"Lawrencium",
247"Rutherfordium",
248"Dubnium",
249"Seaborgium",
250"Bohrium",
251"Hassium",
252"Meitnerium",
253"Darmstadtium",
254"Roentgenium",
255"Copernicium",
256"Nihonium",
257"Flerovium",
258"Moscovium",
259"Livermorium",
260"Tennessine",
261"Oganesson",
2620};
263/*****************************************************************************/
264
265/*****************************************************************************/
272 unsigned short int z
273) {
274 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
275 return(element_name[z]);
276}
277/*****************************************************************************/
278
279/*****************************************************************************/
286 unsigned short int z
287) {
288 if(z>MAX_ATOMIC_NUMBER) return(element_name[0]);
289 return(element_symbol[z]);
290}
291/*****************************************************************************/
292
293/*****************************************************************************/
298unsigned short int elementIdentify(
300 const char *str
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}
325/*****************************************************************************/
326
327/*****************************************************************************/
char * elementSymbol(unsigned short int z)
Definition elements.c:284
char * elementName(unsigned short int z)
Definition elements.c:270
unsigned short int elementIdentify(const char *str)
Definition elements.c:298
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
Header file for library libtpcisotope.
#define MAX_ATOMIC_NUMBER
Max atomic number, and the size of element_symbol and element_name lists.
Definition tpcisotope.h:33