-
Notifications
You must be signed in to change notification settings - Fork 17
/
radrate_xdr.c
129 lines (96 loc) · 3.55 KB
/
radrate_xdr.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
127
128
129
/* ------- file: -------------------------- radrate_xdr.c -----------
Version: rh2.0
Author: Han Uitenbroek ([email protected])
Last modified: Tue Sep 17 14:19:48 2002 --
-------------------------- ----------RH-- */
/* --- Routines for writing radiative rates to file.
XDR (external data representation) version. -- -------------- */
#include <string.h>
#include "rh.h"
#include "atom.h"
#include "atmos.h"
#include "error.h"
#include "inputs.h"
#include "xdr.h"
/* --- Function prototypes -- -------------- */
bool_t xdr_radrate(XDR *xdrs, Atom *atom);
/* --- Global variables -- -------------- */
extern Atmosphere atmos;
extern InputData input;
extern char messageStr[];
/* ------- begin -------------------------- writeRadRate.c - -------- */
bool_t writeRadRate(Atom *atom)
{
const char routineName[] = "writeRadRate";
char ratesfile[15];
FILE *fp;
XDR xdrs;
/* --- Write radiatve rates for transitions treated in detail.-- -- */
if (!strcmp(input.radrateFile, "none")) return FALSE;
sprintf(ratesfile, (atom->ID[1] == ' ') ?
"radrate.%.1s.out" : "radrate.%.2s.out", atom->ID);
if ((fp = fopen(ratesfile, "w" )) == NULL) {
sprintf(messageStr, "Unable to open output file %s", ratesfile);
Error(ERROR_LEVEL_1, routineName, messageStr);
return FALSE;
}
xdrstdio_create(&xdrs, fp, XDR_ENCODE);
if (!xdr_radrate(&xdrs, atom)) {
sprintf(messageStr, "Unable to write to output file %s", ratesfile);
Error(WARNING, routineName, messageStr);
}
xdr_destroy(&xdrs);
fclose(fp);
return TRUE;
}
/* ------- end ---------------------------- writeRadRate.c ---------- */
/* ------- begin -------------------------- readRadRate.c ----------- */
bool_t readRadRate(Atom *atom)
{
const char routineName[] = "readRadRate";
char ratesfile[15];
FILE *fp;
XDR xdrs;
if (!strcmp(input.radrateFile, "none")) return FALSE;
sprintf(ratesfile, (atom->ID[1] == ' ') ?
"radrate.%.1s.out" : "radrate.%.2s.out", atom->ID);
/* --- Read radiative rates for transitions treated in detail. -- - */
if ((fp = fopen(ratesfile, "r" )) == NULL) {
sprintf(messageStr, "Unable to open input file %s", ratesfile);
Error(ERROR_LEVEL_2, routineName, messageStr);
return FALSE;
}
xdrstdio_create(&xdrs, fp, XDR_DECODE);
if (!xdr_radrate(&xdrs, atom)) {
sprintf(messageStr, "Unable to read from input file %s", ratesfile);
Error(ERROR_LEVEL_2, routineName, messageStr);
}
xdr_destroy(&xdrs);
fclose(fp);
return TRUE;
}
/* ------- end ---------------------------- readRadRate.c ----------- */
/* ------- begin -------------------------- xdr_radrate.c ----------- */
bool_t xdr_radrate(XDR *xdrs, Atom *atom)
{
register int kr;
bool_t result = TRUE;
AtomicLine *line;
AtomicContinuum *continuum;
for (kr = 0; kr < atom->Nline; kr++) {
line = &atom->line[kr];
result &= xdr_vector(xdrs, (char *) line->Rij, atmos.Nspace,
sizeof(double), (xdrproc_t) xdr_double);
result &= xdr_vector(xdrs, (char *) line->Rji, atmos.Nspace,
sizeof(double), (xdrproc_t) xdr_double);
}
for (kr = 0; kr < atom->Ncont; kr++) {
continuum = &atom->continuum[kr];
result &= xdr_vector(xdrs, (char *) continuum->Rij, atmos.Nspace,
sizeof(double), (xdrproc_t) xdr_double);
result &= xdr_vector(xdrs, (char *) continuum->Rji, atmos.Nspace,
sizeof(double), (xdrproc_t) xdr_double);
}
return result;
}
/* ------- end ---------------------------- xdr_radrate.c ----------- */