forked from ITA-Solar/rh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicate.c
126 lines (99 loc) · 3.67 KB
/
duplicate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ------- file: -------------------------- duplicate.c -------------
Version: rh2.0
Author: Han Uitenbroek ([email protected])
Last modified: Tue Jan 25 16:17:47 2000 --
-------------------------- ----------RH-- */
/* --- Routine duplicateLevel checks whether the multiplet level
designated by label is present in the atomic model atom.
Routine duplicateLine checks whether line transition between
levels designated by labeli and labelj is present in the
atomic model atom.
Note: Ambiguity due to fine-splitting is prevented by cutting the label
off at the term designation (ie. by comparing up till the odd or
even designation). This requires consistent naming of the levels
in active and background models of the same species of course!
-- -------------- */
#include <string.h>
#include "rh.h"
#include "atom.h"
#include "background.h"
#include "error.h"
/* --- Function prototypes -- -------------- */
/* --- Global variables -- -------------- */
extern char messageStr[];
/* ------- begin -------------------------- duplicateLevel.c -------- */
bool_t duplicateLevel(Atom *atom, char *label)
{
const char routineName[] = "duplicateLevel";
register int i;
char multiplet[ATOM_LABEL_WIDTH+1], *ptr;
bool_t duplicate;
int length;
if (atom == NULL) return FALSE;
strcpy(multiplet, label);
ptr = multiplet + (strlen(multiplet) - 1);
while ((*ptr != 'E') && (*ptr != 'O') && (ptr > multiplet)) ptr--;
if (ptr > multiplet)
*(ptr + 1) = '\0';
else {
sprintf(messageStr, "Cannot determine parity of atomic level %s", label);
Error(ERROR_LEVEL_1, routineName, messageStr);
return FALSE;
}
length = strlen(multiplet);
duplicate = FALSE;
for (i = 0; i < atom->Nlevel; i++) {
/* --- Compare up to the length of the multiplet -- ------------- */
if (strncmp(atom->label[i], multiplet, length) == 0) {
duplicate = TRUE;
break;
}
}
return duplicate;
}
/* ------- end ---------------------------- duplicateLevel.c -------- */
/* ------- begin -------------------------- duplicateLine.c --------- */
bool_t duplicateLine(struct Atom *atom, char *labeli, char *labelj)
{
const char routineName[] = "duplicateLine";
register int kr;
char multipleti[ATOM_LABEL_WIDTH+1], multipletj[ATOM_LABEL_WIDTH+1],
*ptr;
bool_t duplicate;
int i, j, lengthi, lengthj;
if (atom == NULL) return FALSE;
strcpy(multipleti, labeli);
ptr = multipleti + (strlen(multipleti) - 1);
while ((*ptr != 'E') && (*ptr != 'O') && (ptr > multipleti)) ptr--;
if (ptr > multipleti)
*(ptr + 1) = '\0';
else {
sprintf(messageStr,
"Cannot determine parity of atomic level %s", labeli);
Error(ERROR_LEVEL_1, routineName, messageStr);
}
lengthi = strlen(multipleti);
strcpy(multipletj, labelj);
ptr = multipletj + (strlen(multipletj) - 1);
while ((*ptr != 'E') && (*ptr != 'O') && (ptr > multipletj)) ptr--;
if (ptr > multipletj)
*(ptr + 1) = '\0';
else {
sprintf(messageStr,
"Cannot determine parity of atomic level %s", labelj);
Error(ERROR_LEVEL_1, routineName, messageStr);
}
lengthj = strlen(multipletj);
duplicate = FALSE;
for (kr = 0; kr < atom->Nline; kr++) {
i = atom->line[kr].i;
j = atom->line[kr].j;
if (strncmp(atom->label[i], multipleti, lengthi) == 0 &&
strncmp(atom->label[j], multipletj, lengthj) == 0) {
duplicate = TRUE;
break;
}
}
return duplicate;
}
/* ------- end ---------------------------- duplicateLine.c --------- */