Index: trunk/Ohana/src/libohana/include/ohana.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana.h	(revision 30499)
+++ trunk/Ohana/src/libohana/include/ohana.h	(revision 30602)
@@ -283,6 +283,12 @@
 int     ohana_str_to_radec     PROTO((double *ra, double *dec, char *str1, char *str2));
 double  ohana_normalize_angle  PROTO((double angle));
+double  ohana_normalize_angle_to_midpoint  PROTO((double angle, double Rmid));
 
 int     hstgsc_hms_to_deg      PROTO((double *h0, double *h1, double *d0, double *d1, char *string));
+
+short 	ToShortPixels          PROTO((float pixels));
+short 	ToShortDegrees         PROTO((float degrees));
+float 	FromShortPixels        PROTO((short value));
+float 	FromShortDegrees       PROTO((float value));
 
 /* IO Buffer functions */
Index: trunk/Ohana/src/libohana/include/ohana_allocate.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana_allocate.h	(revision 30499)
+++ trunk/Ohana/src/libohana/include/ohana_allocate.h	(revision 30602)
@@ -17,12 +17,14 @@
 
 # define ALLOCATE(PTR,TYPE,SIZE) \
-  PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE))
+  { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)) }
+# define ALLOCATE_ZERO(PTR,TYPE,SIZE)					\
+  { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); }
 # define REALLOCATE(PTR,TYPE,SIZE) \
-  PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE));
-# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \
-  if ((NCURR) >= (SIZE)) { SIZE += DELTA; \
-  PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); }
-# define FREE(PTR) if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); }
-# define free(PTR) ohana_free(__FILE__, __LINE__, PTR)
+  { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); }
+# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) {			\
+  if ((NCURR) >= (SIZE)) { SIZE += DELTA;				\
+    PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } }
+# define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); } }
+# define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); }
 
 # else 
@@ -33,22 +35,32 @@
 
 # ifndef ALLOCATE
-# define ALLOCATE(PTR,TYPE,SIZE)  \
-  PTR = (TYPE *) malloc ((unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
-  if (PTR == NULL) { \
-    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);\
-    exit (10); } 
-# define REALLOCATE(PTR,TYPE,SIZE) \
+# define ALLOCATE(PTR,TYPE,SIZE) {					\
+  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
+  if (PTR == NULL) {							\
+    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);	\
+    exit (10); } } 	       
+
+# define ALLOCATE_ZERO(PTR,TYPE,SIZE) {					\
+  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
+  if (PTR == NULL) {							\
+    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);	\
+    exit (10); \
+  } memset (PTR, 0, (SIZE)*sizeof(TYPE)); }
+
+# define REALLOCATE(PTR,TYPE,SIZE) { 					\
   PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
-  if (PTR == NULL) { \
-    fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);\
-    exit (10); }
-# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \
-  if ((NCURR) >= (SIZE)) { \
-    SIZE += DELTA; \
+  if (PTR == NULL) {							\
+    fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);	\
+    exit (10); } }
+
+# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { 	\
+  if ((NCURR) >= (SIZE)) {				\
+    SIZE += DELTA;							\
     PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
-    if (PTR == NULL) { \
-      fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__);\
-      exit (10); } }
-# define FREE(PTR) if (PTR != NULL) { free (PTR); }
+    if (PTR == NULL) {							\
+      fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__); \
+      exit (10); } } }
+
+# define FREE(PTR) { if (PTR != NULL) { free (PTR); } }
 # endif /* ALLOCATE */
 
Index: trunk/Ohana/src/libohana/src/time.c
===================================================================
--- trunk/Ohana/src/libohana/src/time.c	(revision 30499)
+++ trunk/Ohana/src/libohana/src/time.c	(revision 30602)
@@ -468,2 +468,73 @@
     return (result);
 }
+
+double ohana_normalize_angle_to_midpoint (double angle, double Rmid) {
+
+    double result;
+
+    // take an input angle and force the domain to be 0.0 - 360.0
+    // there are a few ways to do this:  
+
+    // option 1: This is a potentially very slow method, also subject to round off errors
+# if (0)
+    while (angle > 360.0) angle -= 360.0;
+    while (angle <   0.0) angle += 360.0;
+# endif
+    
+    // option 2: take sin & cos, apply atan2 (y, x) 
+# if (1)    
+    double x, y;
+
+    x = cos(angle*RAD_DEG);
+    y = sin(angle*RAD_DEG);
+
+    result = DEG_RAD*atan2 (y, x);
+    if (result < Rmid - 180.0) result += 360.0;
+    if (result > Rmid + 180.0) result -= 360.0;
+# endif
+
+# if (0)
+    // option 3:
+    int nCircle = angle / 360.0;
+    result -= 360.0*nCircle;
+    if (result < 0.0) result += 360.0;
+# endif
+
+    return (result);
+}
+
+short ToShortPixels (float pixels) {
+
+    short value;
+
+    value = 100*pixels;
+
+    return value;
+}
+
+short ToShortDegrees (float degrees) {
+
+    short value;
+
+    value = ((float)0xffff/360.0) * degrees;
+
+    return value;
+}
+
+float FromShortPixels (short value) {
+
+    float pixels;
+
+    pixels = value / 100.0;
+
+    return pixels;
+}
+
+float FromShortDegrees (float value) {
+
+    float degrees;
+
+    degrees = (360.0 / (float)0xffff) * value;
+
+    return degrees;
+}
