Newer
Older
else
{
unsigned char *bufdata = (unsigned char *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
Emmanuel Bertin
committed
*(bufdata++) = (unsigned char)((*(ptr++)-bz)/bs+0.49999);;
}
break;
case BP_SHORT:
if (tab->bitsgn)
{
short *bufdata = (short *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (short)((*(ptr++)-bz)/bs+0.49999);
}
else
{
unsigned short *bufdata = (unsigned short *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (unsigned short)((*(ptr++)-bz)/bs+0.49999);
}
if (bswapflag)
swapbytes(cbufdata0, 2, spoonful);
break;
case BP_LONG:
if (tab->bitsgn)
{
int *bufdata = (int *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (int)((*(ptr++)-bz)/bs+0.49999);
}
else
{
unsigned int *bufdata = (unsigned int *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(bufdata++) = (unsigned int)((*(ptr++)-bz)/bs+0.49999);
}
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
for (i=spoonful; i--;)
Emmanuel Bertin
committed
*(bufdata++) = (SLONGLONG)((*(ptr++)-bz)/bs+0.49999);
}
else
{
ULONGLONG *bufdata = (ULONGLONG *)cbufdata0;
Emmanuel Bertin
committed
#pragma ivdep
for (i=spoonful; i--;)
*(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
#ifdef HAVE_CFITSIO
if (!tab->infptr && bswapflag)
#else
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
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
#ifdef HAVE_CFITSIO
// if cfitsio output file has been set up, then proceed to write
if (tab->infptr) {
// now read section of image
int datatype;
switch(tab->bitpix) {
case BYTE_IMG:
datatype = TBYTE;
break;
case SHORT_IMG:
datatype = TSHORT;
break;
case LONG_IMG:
datatype = TLONG;
break;
case FLOAT_IMG:
datatype = TFLOAT;
break;
case DOUBLE_IMG:
datatype = TDOUBLE;
break;
default:
datatype = TFLOAT;
break;
}
// turn off any scaling so that we copy the raw pixel values
double *array,
bscale = 1.0,
bzero = 0.0,
nulval = 0.0;
int status = 0;
fits_set_bscale(tab->infptr, bscale, bzero, &status);
status = 0;
fits_write_img(tab->infptr, datatype, tab->currentElement, spoonful,
cbufdata0, &status);
if (status) {
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;
} else
// otherwise, continue with usual AstrOmatic fits writing routine
QFWRITE(cbufdata0, spoonful*tab->bytepix, cat->file, cat->filename);
#else
QFWRITE(cbufdata0, spoonful*tab->bytepix, cat->file, cat->filename);
#endif // HAVE_CFITSIO
Emmanuel Bertin
committed
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
}
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)
VERSION 11/02/2020
Emmanuel Bertin
committed
***/
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;
unsigned short ashort = 1;
Emmanuel Bertin
committed
double bs,bz;
int bswapflag;
bswapflag = *((char *)&ashort); // Byte-swapping flag
Emmanuel Bertin
committed
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
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:
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
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;
}