diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-11-18 15:22:25 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2009-11-18 15:22:25 +0100 |
commit | 7f004b45f39c9207a6a233217f983c9b269bca45 (patch) | |
tree | 7a03f7d670eae4f6e62498686901afac6071171f | |
parent | 99569f2f6cf574e88441d3de888f825b6d7b2ed7 (diff) |
Add progress bar
-rw-r--r-- | src/diffraction.c | 2 | ||||
-rw-r--r-- | src/utils.c | 18 | ||||
-rw-r--r-- | src/utils.h | 3 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/diffraction.c b/src/diffraction.c index 8d26dc7c..25b8c3b4 100644 --- a/src/diffraction.c +++ b/src/diffraction.c @@ -136,6 +136,6 @@ void get_diffraction(struct image *image, UnitCell *cell) image->sfacs[x + image->width*y] = f_lattice * f_molecule; } - printf("x=%i\n", x); + progress_bar(x, image->width-1); } } diff --git a/src/utils.c b/src/utils.c index fa239f90..d58f4db8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -156,3 +156,21 @@ void mapping_rotate(double x, double y, double z, *ddy = ny; *ddz = nz; } + + +void progress_bar(int val, int total) +{ + double frac; + int n, i; + char s[1024]; + + frac = (double)val/total; + n = frac*80; + + for ( i=0; i<n; i++ ) s[i] = '='; + for ( i=n; i<80; i++ ) s[i] = '.'; + s[n] = '\0'; + printf("\r|%s|", s); + + if ( val == total ) printf("\n"); +} diff --git a/src/utils.h b/src/utils.h index 1de0ea09..7940d77f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -50,7 +50,8 @@ extern int sign(double a); extern void mapping_rotate(double x, double y, double z, double *ddx, double *ddy, double *ddz, double omega, double tilt); - +extern void progress_bar(int val, int total); + #define rad2deg(a) ((a)*180/M_PI) #define deg2rad(a) ((a)*M_PI/180) |