Newer
Older
rhenders
committed
// CFITSIO - if cfitsio output file has been set up, then proceed to write using cfitsio
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
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
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
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
***/
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:
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
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
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
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;
}