IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30602


Ignore:
Timestamp:
Feb 13, 2011, 11:09:40 AM (15 years ago)
Author:
eugene
Message:

fix ALLOCATE to accept large sizes; add utilities ohana_normalize_angle_to_midpoint, ToShortPixels, etc

Location:
trunk/Ohana/src/libohana
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana.h

    r29537 r30602  
    283283int     ohana_str_to_radec     PROTO((double *ra, double *dec, char *str1, char *str2));
    284284double  ohana_normalize_angle  PROTO((double angle));
     285double  ohana_normalize_angle_to_midpoint  PROTO((double angle, double Rmid));
    285286
    286287int     hstgsc_hms_to_deg      PROTO((double *h0, double *h1, double *d0, double *d1, char *string));
     288
     289short   ToShortPixels          PROTO((float pixels));
     290short   ToShortDegrees         PROTO((float degrees));
     291float   FromShortPixels        PROTO((short value));
     292float   FromShortDegrees       PROTO((float value));
    287293
    288294/* IO Buffer functions */
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r12332 r30602  
    1717
    1818# define ALLOCATE(PTR,TYPE,SIZE) \
    19   PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE))
     19  { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)) }
     20# define ALLOCATE_ZERO(PTR,TYPE,SIZE)                                   \
     21  { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); }
    2022# define REALLOCATE(PTR,TYPE,SIZE) \
    21   PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE));
    22 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \
    23   if ((NCURR) >= (SIZE)) { SIZE += DELTA; \
    24   PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); }
    25 # define FREE(PTR) if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); }
    26 # define free(PTR) ohana_free(__FILE__, __LINE__, PTR)
     23  { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); }
     24# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) {                  \
     25  if ((NCURR) >= (SIZE)) { SIZE += DELTA;                               \
     26    PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } }
     27# define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); } }
     28# define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); }
    2729
    2830# else
     
    3335
    3436# ifndef ALLOCATE
    35 # define ALLOCATE(PTR,TYPE,SIZE)  \
    36   PTR = (TYPE *) malloc ((unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
    37   if (PTR == NULL) { \
    38     fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);\
    39     exit (10); }
    40 # define REALLOCATE(PTR,TYPE,SIZE) \
     37# define ALLOCATE(PTR,TYPE,SIZE) {                                      \
     38  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
     39  if (PTR == NULL) {                                                    \
     40    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);  \
     41    exit (10); } }             
     42
     43# define ALLOCATE_ZERO(PTR,TYPE,SIZE) {                                 \
     44  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
     45  if (PTR == NULL) {                                                    \
     46    fprintf(stderr,"failed malloc at %d in %s\n", __LINE__, __FILE__);  \
     47    exit (10); \
     48  } memset (PTR, 0, (SIZE)*sizeof(TYPE)); }
     49
     50# define REALLOCATE(PTR,TYPE,SIZE) {                                    \
    4151  PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
    42   if (PTR == NULL) { \
    43     fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__);\
    44     exit (10); }
    45 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) \
    46   if ((NCURR) >= (SIZE)) { \
    47     SIZE += DELTA; \
     52  if (PTR == NULL) {                                                    \
     53    fprintf(stderr,"failed realloc at %d in %s\n", __LINE__, __FILE__); \
     54    exit (10); } }
     55
     56# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) {  \
     57  if ((NCURR) >= (SIZE)) {                              \
     58    SIZE += DELTA;                                                      \
    4859    PTR = (TYPE *) realloc(PTR,(unsigned)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
    49     if (PTR == NULL) { \
    50       fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__);\
    51       exit (10); } }
    52 # define FREE(PTR) if (PTR != NULL) { free (PTR); }
     60    if (PTR == NULL) {                                                  \
     61      fprintf(stderr,"failed realloc increment at %d in %s\n", __LINE__, __FILE__); \
     62      exit (10); } } }
     63
     64# define FREE(PTR) { if (PTR != NULL) { free (PTR); } }
    5365# endif /* ALLOCATE */
    5466
  • trunk/Ohana/src/libohana/src/time.c

    r19935 r30602  
    468468    return (result);
    469469}
     470
     471double ohana_normalize_angle_to_midpoint (double angle, double Rmid) {
     472
     473    double result;
     474
     475    // take an input angle and force the domain to be 0.0 - 360.0
     476    // there are a few ways to do this: 
     477
     478    // option 1: This is a potentially very slow method, also subject to round off errors
     479# if (0)
     480    while (angle > 360.0) angle -= 360.0;
     481    while (angle <   0.0) angle += 360.0;
     482# endif
     483   
     484    // option 2: take sin & cos, apply atan2 (y, x)
     485# if (1)   
     486    double x, y;
     487
     488    x = cos(angle*RAD_DEG);
     489    y = sin(angle*RAD_DEG);
     490
     491    result = DEG_RAD*atan2 (y, x);
     492    if (result < Rmid - 180.0) result += 360.0;
     493    if (result > Rmid + 180.0) result -= 360.0;
     494# endif
     495
     496# if (0)
     497    // option 3:
     498    int nCircle = angle / 360.0;
     499    result -= 360.0*nCircle;
     500    if (result < 0.0) result += 360.0;
     501# endif
     502
     503    return (result);
     504}
     505
     506short ToShortPixels (float pixels) {
     507
     508    short value;
     509
     510    value = 100*pixels;
     511
     512    return value;
     513}
     514
     515short ToShortDegrees (float degrees) {
     516
     517    short value;
     518
     519    value = ((float)0xffff/360.0) * degrees;
     520
     521    return value;
     522}
     523
     524float FromShortPixels (short value) {
     525
     526    float pixels;
     527
     528    pixels = value / 100.0;
     529
     530    return pixels;
     531}
     532
     533float FromShortDegrees (float value) {
     534
     535    float degrees;
     536
     537    degrees = (360.0 / (float)0xffff) * value;
     538
     539    return degrees;
     540}
Note: See TracChangeset for help on using the changeset viewer.