int dec64_to_string( dec64_string_state state, dec64 number, dec64_string_char string[] ) { /* dec64_to_string converts a dec64 number into a string. The caller provides the memory in which to deposit the string. The string must have sufficient capacity to hold 32 characters. If NULL is passed in as the string, then no characters will be deposited, but a character count will be returned. dec64_to_string returns the number of characters actually deposited in the string (not including the trailing \0). If the number is nan, then it returns 0 indicating an empty string. In standard mode, the number will be formatted conventionally unless it would require more than 17 digits, which would be due to excessive trailing zeros or zeros immediately after the decimal point. In that case scientific notation will be used instead. */ if (state == NULL || state->valid != confirmed) { return 0; } state->length = 0; state->string = string; if (dec64_is_any_nan(number) != DEC64_TRUE) { if (dec64_is_zero(number) == DEC64_TRUE) { emit(state, '0'); } else { if (number != state->number) { state->number = number; digitize(state); } if (number < 0) { emit(state, '-'); } switch (state->mode) { case engineering_mode: engineering(state); break; case scientific_mode: scientific(state); break; case standard_mode: standard(state); break; } } } emit_end(state); state->string = NULL; return state->length; }
int fits_hcompress(int *a, int ny, int nx, int scale, char *output, long *nbytes, int *status) { /* compress the input image using the H-compress algorithm a - input image array nx - size of X axis of image ny - size of Y axis of image scale - quantization scale factor. Larger values results in more (lossy) compression scale = 0 does lossless compression output - pre-allocated array to hold the output compressed stream of bytes nbyts - input value = size of the output buffer; returned value = size of the compressed byte stream, in bytes NOTE: the nx and ny dimensions as defined within this code are reversed from the usual FITS notation. ny is the fastest varying dimension, which is usually considered the X axis in the FITS image display */ int stat; if (*status > 0) return(*status); /* H-transform */ stat = htrans(a, nx, ny); if (stat) { *status = stat; return(*status); } /* digitize */ digitize(a, nx, ny, scale); /* encode and write to output array */ FFLOCK; noutmax = *nbytes; /* input value is the allocated size of the array */ *nbytes = 0; /* reset */ stat = encode(output, nbytes, a, nx, ny, scale); FFUNLOCK; *status = stat; return(*status); }
////////////////////////////////////////////////////////////// // // Some common functions // ////////////////////////////////////////////////////////////// digitList *digitize(char str[80]) { digitList* L = 0; digitList* node; int i; for(i = 0; i< strlen(str); i++) { /*if(str[i] < '0' || str[i] > '9') break; node = new digitList(str[i] - '0', L); L = node;*/ //-------------------------------------------// if ((str[i] >= '0') && (str[i] <= '9')) { node = new digitList(str[i] - '0', L); L = node; } else if (str[i] == '!') { if (((L->getDigit() == 0) && (L->getNextDigit() == NULL)) || ((L->getDigit() == 1) && (L->getNextDigit() == NULL))) return new digitList(1, NULL); Integer P(1); int j = 1, cmp = -1; while (cmp == -1) { P = P * Integer(j); cmp = compareDigitLists(digitize(j), L); ++j; } return P.digits; } else if (str[i] == '^') { while (*str != '^') str = str + 1; digitList* exp; exp = digitize(str + 1); if ((exp->getDigit() == 0) && (exp->getNextDigit() == NULL)) return new digitList(1, NULL); Integer P(1); Integer base(L); int count = 0, cmp = -1; while (cmp == -1) { P = P * base; ++count; cmp = compareDigitLists(digitize(count), exp); } return P.digits; } else { break; } } return L; }