Newer
Older
*(bufdata++) = (ULONGLONG)((*(ptr++)-bz)/bs+0.49999);
}
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
break;
#endif
case BP_FLOAT:
{
float *bufdata = (float *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (*(ptr++)-bz)/bs;
rhenders
committed
// TODO not yet writing CFitsIO from SExtractor. CFITSIO - only perform byte-swap if we are NOT writing a tile-compressed format using cfitsio
rhenders
committed
// if (tab->infptr == NULL) // TODO
if (bswapflag)
swapbytes(cbufdata0, 4, spoonful);
}
break;
case BP_DOUBLE:
{
double *bufdata = (double *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (double)(*(ptr++)-bz)/bs;
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
}
break;
default:
Emmanuel Bertin
committed
error(EXIT_FAILURE,"*FATAL ERROR*: unknown BITPIX type in ",
"read_body()");
break;
}
rhenders
committed
// CFITSIO - if cfitsio output file has been set up, then proceed to write using cfitsio
rhenders
committed
if (0 && tab->infptr != NULL) { // TODO
int status = 0; fits_write_img(tab->infptr, TFLOAT, tab->currentElement, spoonful, cbufdata0, &status);
if (status != 0) {
printf("CFITSIO ERROR writing start=%d end=%d absolute end=%d\n", tab->currentElement, (tab->currentElement + spoonful) , (tab->naxisn[0]*tab->naxisn[1]));
fits_report_error(stderr, status);
}
tab->currentElement = tab->currentElement + spoonful;
}
// otherwise, continue with usual AstrOmatic fits writing routine
else
Emmanuel Bertin
committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
QFWRITE(cbufdata0, spoonful*tab->bytepix, cat->file, cat->filename);
}
break;
/*-- Compressed image */
case COMPRESS_BASEBYTE:
break;
case COMPRESS_PREVPIX:
break;
default:
error(EXIT_FAILURE,"*Internal Error*: unknown compression mode in ",
"read_body()");
}
return;
}
/******* write_ibody ***********************************************************
PROTO write_ibody(tabstruct *tab, FLAGTYPE *ptr, long size)
PURPOSE Write integer values to a FITS body.
INPUT A pointer to the tab structure,
a pointer to the array in memory,
the number of elements to be written.
OUTPUT -.
NOTES .
AUTHOR E. Bertin (IAP)
Emmanuel Bertin
committed
VERSION 28/03/2013
Emmanuel Bertin
committed
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
***/
void write_ibody(tabstruct *tab, FLAGTYPE *ptr, size_t size)
{
static FLAGTYPE bufdata0[DATA_BUFSIZE/sizeof(FLAGTYPE)];
catstruct *cat;
char *cbufdata0;
size_t i, bowl, spoonful;
double bs,bz;
bs = tab->bscale;
bz = tab->bzero;
cat = tab->cat;
if (!cat)
error(EXIT_FAILURE, "*Internal Error*: no parent cat structure for table ",
tab->extname);
cbufdata0 = (char *)bufdata0; /* A trick to remove gcc aliasing warnings */
switch(tab->compress_type)
{
/*-- Uncompressed image */
case COMPRESS_NONE:
bowl = DATA_BUFSIZE/tab->bytepix;
spoonful = size<bowl?size:bowl;
for(; size>0; size -= spoonful)
{
if (spoonful>size)
spoonful = size;
switch(tab->bitpix)
{
case BP_BYTE:
if (tab->bitsgn)
{
char *bufdata = (char *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (char)*(ptr++);
}
else
{
unsigned char *bufdata = (unsigned char *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (unsigned char)*(ptr++);
}
break;
case BP_SHORT:
if (tab->bitsgn)
{
short *bufdata = (short *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (short)*(ptr++);
}
else
{
unsigned short *bufdata = (unsigned short *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (unsigned short)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 2, spoonful);
break;
case BP_LONG:
if (tab->bitsgn)
{
int *bufdata = (int *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (int)*(ptr++);
}
else
{
unsigned int *bufdata = (unsigned int *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (unsigned int)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 4, spoonful);
break;
#ifdef HAVE_LONG_LONG_INT
case BP_LONGLONG:
if (tab->bitsgn)
{
Emmanuel Bertin
committed
SLONGLONG *bufdata = (SLONGLONG *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
Emmanuel Bertin
committed
*(bufdata++) = (SLONGLONG)*(ptr++);
Emmanuel Bertin
committed
}
else
{
ULONGLONG *bufdata = (ULONGLONG *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (ULONGLONG)*(ptr++);
}
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
break;
#endif
case BP_FLOAT:
{
float *bufdata = (float *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = (float)((double)*(ptr++)-bz)/bs;
if (bswapflag)
swapbytes(cbufdata0, 4, spoonful);
}
break;
case BP_DOUBLE:
{
double *bufdata = (double *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
for (i=spoonful; i--;)
*(bufdata++) = ((double)*(ptr++)-bz)/bs;
if (bswapflag)
swapbytes(cbufdata0, 8, spoonful);
}
break;
default:
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
error(EXIT_FAILURE,"*FATAL ERROR*: unknown BITPIX type in ",
"read_body()");
break;
}
QFWRITE(cbufdata0, spoonful*tab->bytepix, cat->file, cat->filename);
}
break;
/*-- Compressed image */
case COMPRESS_BASEBYTE:
break;
case COMPRESS_PREVPIX:
break;
default:
error(EXIT_FAILURE,"*Internal Error*: unknown compression mode in ",
"read_body()");
}
return;
}
/******* set_maxram ***********************************************************
PROTO int set_maxram(size_t maxram)
PURPOSE Set the maximum amount of silicon memory that can be allocated for
storing FITS body data.
INPUT The maximum amount of RAM (in bytes).
OUTPUT RETURN_OK if within limits, RETURN_ERROR otherwise.
NOTES .
AUTHOR E. Bertin (IAP)
VERSION 19/12/99
***/
int set_maxram(size_t maxram)
{
if (maxram<1)
return RETURN_ERROR;
body_maxram = maxram;
return RETURN_OK;
}
/******* set_maxvram **********************************************************
PROTO int set_maxvram(size_t maxram)
PURPOSE Set the maximum amount of total virtual memory that can be used for
storing FITS body data.
INPUT The maximum amount of VRAM (in bytes).
OUTPUT RETURN_OK if within limits, RETURN_ERROR otherwise.
NOTES .
AUTHOR E. Bertin (IAP)
VERSION 08/02/2000
***/
int set_maxvram(size_t maxvram)
{
if (maxvram<1)
return RETURN_ERROR;
body_maxvram = maxvram;
return RETURN_OK;
}
/******* set_swapdir **********************************************************
PROTO int set_swapdir(char *dirname)
PURPOSE Set the path name of the directory that will be used for storing
memory swap files.
INPUT The pointer to the path string.
OUTPUT RETURN_OK if path appropriate, RETURN_ERROR otherwise.
NOTES .
AUTHOR E. Bertin (IAP)
VERSION 19/12/99
***/
int set_swapdir(char *dirname)
{
if (!dirname)
return RETURN_ERROR;
strcpy(body_swapdirname, dirname);
return RETURN_OK;
}