aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-27 17:44:19 +0100
committerThomas White <taw@physics.org>2009-11-27 17:44:19 +0100
commitc253b180f8970b380345e900f17d799e97de5d93 (patch)
tree17682243ca381b51bae40b3cb65bff0a4c791792 /src
parentef92cb3eebfb74c865cf0e10266ba8c46ffc8a9a (diff)
Macros for status and error messages
Diffstat (limited to 'src')
-rw-r--r--src/cell.c7
-rw-r--r--src/detector.c2
-rw-r--r--src/ewald.c4
-rw-r--r--src/hdf5-file.c18
-rw-r--r--src/pattern_sim.c6
-rw-r--r--src/relrod.c8
-rw-r--r--src/sfac.c39
-rw-r--r--src/utils.c4
-rw-r--r--src/utils.h7
9 files changed, 46 insertions, 49 deletions
diff --git a/src/cell.c b/src/cell.c
index 6fc29e56..49eb4b49 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -76,13 +76,6 @@ static void cell_update_crystallographic(UnitCell *cell)
cell->cx, cell->cy, cell->cz);
cell->gamma = angle_between(cell->ax, cell->ay, cell->az,
cell->bx, cell->by, cell->bz);
-
- printf("a=%f nm\n", cell->a/1e9);
- printf("b=%f nm\n", cell->b/1e9);
- printf("c=%f nm\n", cell->c/1e9);
- printf("alpha = %f deg\n", rad2deg(cell->alpha));
- printf(" beta = %f deg\n", rad2deg(cell->beta));
- printf("gamma = %f deg\n", rad2deg(cell->gamma));
}
diff --git a/src/detector.c b/src/detector.c
index fd84a9c5..a39e50d9 100644
--- a/src/detector.c
+++ b/src/detector.c
@@ -155,7 +155,7 @@ void record_image(struct image *image)
total_energy = FLUENCE * image->xray_energy;
energy_density = total_energy / area;
ph_per_e = (FLUENCE/area) * pow(THOMSON_LENGTH, 2.0);
- printf("Fluence = %8.2e photons, "
+ STATUS("Fluence = %8.2e photons, "
"Energy density = %5.3f kJ/cm^2, "
"Total energy = %5.3f microJ\n",
FLUENCE, energy_density/1e7, total_energy*1e6);
diff --git a/src/ewald.c b/src/ewald.c
index 9749f73c..d2352b33 100644
--- a/src/ewald.c
+++ b/src/ewald.c
@@ -94,7 +94,7 @@ void get_ewald(struct image *image)
if ( (x==0) && (y==(int)image->y_centre) ) {
double s;
s = 1.0e-9*modulus(qx, qy, qz)/2.0;
- printf("At left edge: 2theta = %5.3f deg,"
+ STATUS("At left edge: 2theta = %5.3f deg,"
" sin(theta)/lambda = %5.3f nm^-1,"
" d = %5.3f nm\n",
rad2deg(twotheta), s, 1.0/(2.0*s));
@@ -102,7 +102,7 @@ void get_ewald(struct image *image)
if ( (x==0) && (y==0) ) {
double s;
s = 1.0e-9*modulus(qx, qy, qz)/2.0;
- printf(" At corner: 2theta = %5.3f deg,"
+ STATUS(" At corner: 2theta = %5.3f deg,"
" sin(theta)/lambda = %5.3f nm^-1,"
" d = %5.3f nm\n",
rad2deg(twotheta), s, 1.0/(2.0*s));
diff --git a/src/hdf5-file.c b/src/hdf5-file.c
index 0d090281..c29191f4 100644
--- a/src/hdf5-file.c
+++ b/src/hdf5-file.c
@@ -33,13 +33,13 @@ int hdf5_write(const char *filename, const uint16_t *data,
fh = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if ( fh < 0 ) {
- fprintf(stderr, "Couldn't create file: %s\n", filename);
+ ERROR("Couldn't create file: %s\n", filename);
return 1;
}
gh = H5Gcreate(fh, "data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if ( gh < 0 ) {
- fprintf(stderr, "Couldn't create group\n");
+ ERROR("Couldn't create group\n");
H5Fclose(fh);
return 1;
}
@@ -53,18 +53,18 @@ int hdf5_write(const char *filename, const uint16_t *data,
dh = H5Dcreate(gh, "data", H5T_NATIVE_UINT16, sh,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if ( dh < 0 ) {
- fprintf(stderr, "Couldn't create dataset\n");
+ ERROR("Couldn't create dataset\n");
H5Fclose(fh);
return 1;
}
/* Muppet check */
H5Sget_simple_extent_dims(sh, size, max_size);
-
+
r = H5Dwrite(dh, H5T_NATIVE_UINT16, H5S_ALL,
H5S_ALL, H5P_DEFAULT, data);
if ( r < 0 ) {
- fprintf(stderr, "Couldn't write data\n");
+ ERROR("Couldn't write data\n");
H5Dclose(dh);
H5Fclose(fh);
return 1;
@@ -89,20 +89,20 @@ int hdf5_read(struct image *image, const char *filename)
fh = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
if ( fh < 0 ) {
/* TODO: Try other formats here. */
- fprintf(stderr, "Couldn't open file: %s\n", filename);
+ ERROR("Couldn't open file: %s\n", filename);
return 1;
}
dh = H5Dopen(fh, "/data/data", H5P_DEFAULT);
if ( dh < 0 ) {
- fprintf(stderr, "Couldn't open dataset\n");
+ ERROR("Couldn't open dataset\n");
H5Fclose(fh);
return 1;
}
sh = H5Dget_space(dh);
if ( H5Sget_simple_extent_ndims(sh) != 2 ) {
- fprintf(stderr, "Dataset is not two-dimensional\n");
+ ERROR("Dataset is not two-dimensional\n");
H5Fclose(fh);
return 1;
}
@@ -113,7 +113,7 @@ int hdf5_read(struct image *image, const char *filename)
r = H5Dread(dh, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
if ( r < 0 ) {
- fprintf(stderr, "Couldn't read data\n");
+ ERROR("Couldn't read data\n");
H5Dclose(dh);
H5Fclose(fh);
return 1;
diff --git a/src/pattern_sim.c b/src/pattern_sim.c
index 377dfa79..f449b9c1 100644
--- a/src/pattern_sim.c
+++ b/src/pattern_sim.c
@@ -121,7 +121,7 @@ static struct quaternion read_quaternion()
return quat;
} else {
- fprintf(stderr, "Invalid rotation '%s'\n", line);
+ ERROR("Invalid rotation '%s'\n", line);
}
} while ( 1 );
@@ -198,7 +198,7 @@ int main(int argc, char *argv[])
image.molecule = NULL;
/* Splurge a few useful numbers */
- printf("Wavelength is %f nm\n", image.lambda/1.0e-9);
+ STATUS("Wavelength is %f nm\n", image.lambda/1.0e-9);
do {
@@ -210,7 +210,7 @@ int main(int argc, char *argv[])
}
if ( quaternion_valid(image.orientation) ) {
- fprintf(stderr, "Orientation modulus is not zero!\n");
+ ERROR("Orientation modulus is not zero!\n");
return 1;
}
diff --git a/src/relrod.c b/src/relrod.c
index 7ee4dfe3..058075e9 100644
--- a/src/relrod.c
+++ b/src/relrod.c
@@ -86,8 +86,7 @@ void get_reflections(struct image *image, UnitCell *cell, double smax)
res_max = sqrt(w2 + h2) / image->resolution;
res_max *= (wavenumber / image->camera_len);
} else {
- fprintf(stderr,
- "Unrecognised formulation mode in get_reflections"
+ ERROR("Unrecognised formulation mode in get_reflections"
" (resolution cutoff calculation)\n");
return;
}
@@ -172,9 +171,8 @@ void get_reflections(struct image *image, UnitCell *cell, double smax)
x /= image->pixel_size;
y /= image->pixel_size;
} else {
- fprintf(stderr,
- "Unrecognised formulation mode "
- "in get_reflections\n");
+ ERROR("Unrecognised formulation mode "
+ "in get_reflections\n");
return;
}
diff --git a/src/sfac.c b/src/sfac.c
index cd76407f..ac1546e4 100644
--- a/src/sfac.c
+++ b/src/sfac.c
@@ -49,7 +49,7 @@ static double complex get_f1f2(const char *n, double en)
snprintf(filename, 63, "scattering-factors/%s.nff", n);
fh = fopen(filename, "r");
if ( fh == NULL ) {
- fprintf(stderr, "Couldn't open file '%s'\n", filename);
+ ERROR("Couldn't open file '%s'\n", filename);
return 0.0;
}
@@ -71,7 +71,7 @@ static double complex get_f1f2(const char *n, double en)
r = sscanf(line, "%f %f %f", &E_f, &f1_f, &f2_f);
if ( r != 3 ) {
- fprintf(stderr, "WTF?\n");
+ ERROR("WTF?\n");
abort();
}
/* Promote to double precision */
@@ -112,8 +112,7 @@ static double complex get_f1f2(const char *n, double en)
fclose(fh);
- fprintf(stderr, "Couldn't find scattering factors for '%s' at %f eV!\n",
- n, en);
+ ERROR("Couldn't find scattering factors for '%s' at %f eV!\n", n, en);
return 0.0;
}
@@ -173,7 +172,7 @@ static double get_waas_kirf(const char *n, double s)
fh = fopen("scattering-factors/f0_WaasKirf.dat", "r");
if ( fh == NULL ) {
- fprintf(stderr, "Couldn't open f0_WaasKirf.dat\n");
+ ERROR("Couldn't open f0_WaasKirf.dat\n");
return 0.0;
}
@@ -202,8 +201,8 @@ static double get_waas_kirf(const char *n, double s)
&a1, &a2, &a3, &a4, &a5, &c,
&b1, &b2, &b3, &b4, &b5);
if ( r != 11 ) {
- fprintf(stderr, "Couldn't read scattering "
- "factors (WaasKirf)\n");
+ ERROR("Couldn't read scattering "
+ "factors (WaasKirf)\n");
return 0.0;
}
@@ -304,7 +303,7 @@ static void centre_molecule(struct molecule *mol)
}
- printf("Molecule was shifted by %5.3f, %5.3f, %5.3f nm\n",
+ STATUS("Molecule was shifted by %5.3f, %5.3f, %5.3f nm\n",
mol->xc*1e9, mol->yc*1e9, mol->zc*1e9);
}
@@ -334,7 +333,7 @@ struct molecule *load_molecule()
fh = fopen("molecule.pdb", "r");
if ( fh == NULL ) {
- fprintf(stderr, "Couldn't open file\n");
+ ERROR("Couldn't open file\n");
return NULL;
}
@@ -366,7 +365,7 @@ struct molecule *load_molecule()
coords = line + 29;
r = sscanf(coords, "%f %f %f %f %f", &xf, &yf, &zf, &occf, &Bf);
if ( r != 5 ) {
- fprintf(stderr, "WTF?\n");
+ ERROR("WTF?\n");
abort();
}
/* Promote to double precision */
@@ -421,9 +420,9 @@ struct molecule *load_molecule()
centre_molecule(mol);
- printf("There are %i species\n", mol->n_species);
+ STATUS("There are %i species\n", mol->n_species);
for ( i=0; i<mol->n_species; i++ ) {
- printf("%3s : %6i\n", mol->species[i]->species,
+ STATUS("%3s : %6i\n", mol->species[i]->species,
mol->species[i]->n_atoms);
}
@@ -504,7 +503,7 @@ double complex *get_reflections(struct molecule *mol, double en)
"Calculating structure factors");
}
}
- //printf("Total scattered = %f, F000 = %f\n", tscat, F00);
+ //STATUS("Total scattered = %f, F000 = %f\n", tscat, F00);
return reflections;
}
@@ -520,37 +519,37 @@ void get_reflections_cached(struct molecule *mol, double en)
snprintf(s, 1023, "reflections-%ieV.cache", (int)(J_to_eV(en)+0.5));
fh = fopen(s, "rb");
if ( fh == NULL ) {
- printf("No cache file found (looked for %s)\n", s);
+ STATUS("No cache file found (looked for %s)\n", s);
goto calc;
}
mol->reflections = new_list_sfac();
r = fread(mol->reflections, sizeof(double complex), IDIM*IDIM*IDIM, fh);
if ( r < IDIM*IDIM*IDIM ) {
- printf("Found cache file (%s), but failed to read.\n", s);
+ STATUS("Found cache file (%s), but failed to read.\n", s);
goto calc;
}
- printf("Read structure factors (at Bragg positions) from %s\n", s);
+ STATUS("Read structure factors (at Bragg positions) from %s\n", s);
return;
calc:
- printf("Calculating structure factors at Bragg positions...\n");
+ STATUS("Calculating structure factors at Bragg positions...\n");
mol->reflections = get_reflections(mol, en);
fh = fopen(s, "wb");
if ( fh == NULL ) {
- printf("Failed to write cache file (%s)\n", s);
+ STATUS("Failed to write cache file (%s)\n", s);
return;
}
r = fwrite(mol->reflections, sizeof(double complex),
IDIM*IDIM*IDIM, fh);
if ( r < IDIM*IDIM*IDIM ) {
- printf("Failed to write cache file (%s)\n", s);
+ STATUS("Failed to write cache file (%s)\n", s);
return;
}
fclose(fh);
- printf("Successfully saved structure factors at Bragg positions to"
+ STATUS("Successfully saved structure factors at Bragg positions to"
" file %s\n", s);
}
diff --git a/src/utils.c b/src/utils.c
index 36ae533e..9fd6ed4e 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -66,9 +66,9 @@ void progress_bar(int val, int total, const char *text)
for ( i=0; i<n; i++ ) s[i] = '=';
for ( i=n; i<width; i++ ) s[i] = '.';
s[width] = '\0';
- printf("\r%s: |%s|", text, s);
+ STATUS("\r%s: |%s|", text, s);
- if ( val == total ) printf("\n");
+ if ( val == total ) STATUS("\n");
fflush(stdout);
}
diff --git a/src/utils.h b/src/utils.h
index 31ecdf7b..1de206bf 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -146,4 +146,11 @@ static inline double distance3d(double x1, double y1, double z1,
#define TYPE unsigned int
#include "list_tmp.h"
+
+/* ------------------------------ Message macros ---------------------------- */
+
+#define ERROR(...) fprintf(stderr, __VA_ARGS__)
+#define STATUS(...) fprintf(stderr, __VA_ARGS__)
+
+
#endif /* UTILS_H */