forked from ITA-Solar/rh
/
writeinput_xdr.c
103 lines (70 loc) · 2.7 KB
/
writeinput_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
/* ------- file: -------------------------- writeinput_xdr.c --------
Version: rh2.0
Author: Han Uitenbroek (huitenbroek@nso.edu)
Last modified: Wed Apr 1 09:43:12 2009 --
-------------------------- ----------RH-- */
/* --- XDR (external data representation) version. -- -------------- */
#include <string.h>
#include "rh.h"
#include "atom.h"
#include "atmos.h"
#include "spectrum.h"
#include "error.h"
#include "inputs.h"
#include "xdr.h"
#define INPUT_DOT_OUT "input.out"
/* --- Function prototypes -- -------------- */
int is_big_endian(void);
/* --- Global variables -- -------------- */
extern Atmosphere atmos;
extern Spectrum spectrum;
extern InputData input;
extern char messageStr[];
/* ------- begin -------------------------- writeInput.c ------------ */
void writeInput(void)
{
const char routineName[] = "writeInput";
bool_t result=TRUE, PRD_angle_dep, XRD, big_endian;
FILE *fp_out;
XDR xdrs;
if (!strcmp(INPUT_DOT_OUT, "none")) return;
if ((fp_out = fopen(INPUT_DOT_OUT, "w")) == NULL) {
sprintf(messageStr, "Unable to open output file %s",
INPUT_DOT_OUT);
Error(ERROR_LEVEL_1, routineName, messageStr);
return;
}
xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);
PRD_angle_dep = (input.PRD_angle_dep != PRD_ANGLE_INDEP && atmos.NPRDactive > 0);
XRD = (input.XRD && atmos.NPRDactive > 0);
/* --- Write various input parameters to file -- -------------- */
result &= xdr_bool(&xdrs, &input.magneto_optical);
result &= xdr_bool(&xdrs, &PRD_angle_dep);
result &= xdr_bool(&xdrs, &XRD);
result &= xdr_enum(&xdrs, (enum_t *) &input.startJ);
result &= xdr_enum(&xdrs, (enum_t *) &input.StokesMode);
result &= xdr_double(&xdrs, &input.metallicity);
result &= xdr_bool(&xdrs, &input.backgr_pol);
/* --- Write Endianness of compute architecture so that J can be
read properly in the analysis -- -------------- */
big_endian = is_big_endian();
result &= xdr_bool(&xdrs, &big_endian);
if (!result) {
sprintf(messageStr, "Unable to write proper amount to output file %s",
INPUT_DOT_OUT);
Error(ERROR_LEVEL_1, routineName, messageStr);
}
xdr_destroy(&xdrs);
fclose(fp_out);
}
/* ------- end ---------------------------- writeInput.c ------------ */
/* ------- begin -------------------------- is_big_endian.c --------- */
int is_big_endian(void)
{
unsigned char *b;
short i[1] = {1};
/* --- Returns 1 if host machine is big endian, 0 otherwise -- ---- */
b = (unsigned char *) i;
return (b[0]) ? 0 : 1;
}
/* ------- end ---------------------------- is_big_endian.c --------- */