aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-19 19:26:56 +0100
committerThomas White <taw@physics.org>2009-11-19 19:26:56 +0100
commitda1167955e843460414cc6caa2af0979f36caf4c (patch)
tree6db15ed6e64f327b9520770b828af4d41389f9ce /src/main.c
parent377810c338e2f84d0ebc4b44086eb8ecf5f6741d (diff)
Add rotation based on quaternions
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 86cf93d6..e4b826b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,9 +40,11 @@ static void main_show_help(const char *s)
int main(int argc, char *argv[])
{
- int c;
+ int c, done;
UnitCell *cell;
struct image image;
+ char filename[1024];
+ int number = 1;
while ((c = getopt(argc, argv, "h")) != -1) {
@@ -65,11 +67,44 @@ int main(int argc, char *argv[])
deg2rad(90.0),
deg2rad(120.0));
+again:
+
+ /* Read quaternion from stdin */
+ done = 0;
+ do {
+
+ int r;
+ float w, x, y, z;
+ char line[1024];
+ char *rval;
+
+ printf("Please input quaternion: w x y z\n");
+ rval = fgets(line, 1023, stdin);
+ if ( rval == NULL ) return 0;
+ chomp(line);
+
+ r = sscanf(line, "%f %f %f %f", &w, &x, &y, &z);
+ if ( r == 4 ) {
+
+ printf("Rotation is: %f %f %f %f (modulus=%f)\n",
+ w, x, y, z, sqrtf(w*w + x*x + y*y + z*z));
+
+ image.orientation.w = w;
+ image.orientation.x = x;
+ image.orientation.y = y;
+ image.orientation.z = z;
+
+ done = 1;
+
+ } else {
+ fprintf(stderr, "Invalid rotation '%s'\n", line);
+ }
+
+ } while ( !done );
+
/* Define image parameters */
image.width = 512;
image.height = 512;
- image.omega = deg2rad(40.0);
- image.tilt = deg2rad(0.0);
image.fmode = FORMULATION_CLEN;
image.x_centre = 255.5;
image.y_centre = 255.5;
@@ -88,8 +123,11 @@ int main(int argc, char *argv[])
get_diffraction(&image, cell);
record_image(&image);
- /* Write the output file */
- hdf5_write("results/sim.h5", image.data, image.width, image.height);
+ snprintf(filename, 1023, "results/sim-%i.h5", number);
+ number++;
- return 0;
+ /* Write the output file */
+ hdf5_write(filename, image.data, image.width, image.height);
+ printf("Mock write: %i\n", number-1);
+ goto again;
}