diff --git a/data-access/engine/src/vlkb/Makefile b/data-access/engine/src/vlkb/Makefile index 5b954a816bff911ecf3ca83efd8ad9e84ba274c9..8511125527db3cbcfbee5231de5e71c5f9e2ddf3 100644 --- a/data-access/engine/src/vlkb/Makefile +++ b/data-access/engine/src/vlkb/Makefile @@ -11,10 +11,11 @@ DEPS_INC := $(foreach d, $(DEPS_DIR), $d/include) DEPS_LIB := $(foreach d, $(DEPS_DIR), $d/lib) #================================================================================ INC_DIR = $(DEPS_INC) \ + /usr/include/davix \ /usr/include/cfitsio \ + /usr/local/include \ /usr/local/cfitsio/include LIB_DIR = $(DEPS_LIB) \ - /usr/lib64/ast \ /usr/local/lib \ /usr/local/cfitsio/lib #================================================================================ @@ -27,7 +28,7 @@ CFLAGS_COMMON = -c -Wstrict-prototypes $(FLAGS_COMMON) CXX_DEBUG_FLAGS = -g -DVERBOSE_DEBUG -DFDB_DEBUG CXX_RELEASE_FLAGS = -O3 CXX_DEFAULT_FLAGS = -c -std=c++11 $(FLAGS_COMMON) -LDFLAGS = -Wall -lvlkbcommon -lcfitsio -lcsv -last -last_grf_2.0 -last_grf_3.2 -last_grf_5.6 -last_grf3d -last_err -lstdc++ -lm +LDFLAGS = -Wall -lvlkbcommon -ldavix -lcfitsio -lcsv -last -last_pal -last_cminpack -last_grf_2.0 -last_grf_3.2 -last_grf_5.6 -last_grf3d -last_err -lstdc++ -lm INC_PARM=$(foreach d, $(INC_DIR), -I$d) LIB_PARM=$(foreach d, $(LIB_DIR), -L$d) #================================================================================ diff --git a/data-access/engine/src/vlkb/src/imcopy.cpp b/data-access/engine/src/vlkb/src/imcopy.cpp index a1c210308ea3a9527685a7be92d4b5d652d0e78c..ac45274f37b616ef88f3924f39073317599fef6b 100644 --- a/data-access/engine/src/vlkb/src/imcopy.cpp +++ b/data-access/engine/src/vlkb/src/imcopy.cpp @@ -31,7 +31,7 @@ int stream_cutout(string pathname, int extnum, string region) { string pixfilter{ to_cfitsio_format(bnds) }; - imcopy(pathname, extnum, pixfilter, "dummy"); + imcopy(pathname, extnum, pixfilter); return EXIT_SUCCESS; } @@ -59,13 +59,12 @@ int fits_copy_image_section2( -void imcopy(std::string filename, int extnum, std::string pixfilter, std::string temp_root) +void imcopy(std::string filename, int extnum, std::string pixfilter) { LOG_trace(__func__); LOG_STREAM << filename << " EXT: " << extnum << endl; LOG_STREAM << "pixfilter: " << pixfilter << endl; - LOG_STREAM << "temp_root: " << temp_root << endl; int status = 0; diff --git a/data-access/engine/src/vlkb/src/imcopy.hpp b/data-access/engine/src/vlkb/src/imcopy.hpp index f973ad9e4ad4b695070d0bced42263238c491297..2b595a0952d4f89de846504f26e10d454b08c086 100644 --- a/data-access/engine/src/vlkb/src/imcopy.hpp +++ b/data-access/engine/src/vlkb/src/imcopy.hpp @@ -3,7 +3,7 @@ #include <string> -void imcopy(std::string filename, int extnum, std::string pixfilter, std::string temp_root); +void imcopy(std::string filename, int extnum, std::string pixfilter); int stream_cutout(std::string pathname, int extnum, std::string region); #endif diff --git a/data-access/engine/src/vlkb/src/imcopydav.cpp b/data-access/engine/src/vlkb/src/imcopydav.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1979dbb0bacce28a4c843506fd2f86cec8c81941 --- /dev/null +++ b/data-access/engine/src/vlkb/src/imcopydav.cpp @@ -0,0 +1,674 @@ + +#include <davix/davix.hpp> +#include <fitsio.h> +#include <cstring> +#include <iomanip> + +#include "fitsfiles.hpp" +#include "io.hpp" + +using namespace Davix; +using namespace std; + +class dav +{ + public: + + dav(string uri_str):file(this->c,Uri(uri_str)) + { + const char END_CARD[] + ="END "; + + this->file.readPartial(NULL, this->buffer, dav::NCARDS*80, 0, &err); + // FIXME what if all file is shorter then 1400 cards -> read by 2880 until END-card? + for(int i=0; i<NCARDS; i++) + { + char card[80+1]; + card[80]=0; + strncpy(card, &(buffer[i*80]), 80); + if(0 == string{card}.compare(string{END_CARD})) + { + endcard_cix = i; + break; + } + } + + long n_blocks = (endcard_cix+1) / 36; + long n_cardslots = (endcard_cix+1) % 36; + + long n_blocks_with_padding = (n_cardslots==0) ? n_blocks : (n_blocks+1); + + this->du_firstbyte_cix = (2880)*n_blocks_with_padding; + + cout << "du_firstbyte_cix: " << this->du_firstbyte_cix << endl; + } + + + int fits_get_img_type(int *bitpix, int *status) + { + string value{get_card_value(1, status)}; + if(! (*status)) + { + *bitpix = stoi(value);; + } + return *status; + } + + + int fits_get_img_dim(int *naxis, int *status) + { + string value{get_card_value(2, status)}; + if(! (*status)) + { + *naxis = stoi(value);; + } + return *status; + } + + + // there is also LONLONG *naxes version: fits_et_img_sizell + int fits_get_img_size(int maxdim, long *naxes, int *status) + { + for(int i=0; i<maxdim; i++) + { + string value{get_card_value(3+i, status)}; + if(! (*status)) + { + naxes[i] = stol(value);; + } + } + + int naxis = maxdim; + // prepare volume[] for coord -> offset calcs + for(int i=1; i<naxis; i++) this->volume[i] = this->volume[i-1] * naxes[i-1]; + cout << "volume: [ "; + for(int i=0; i<naxis; i++) cout << this->volume[i] << " "; + cout << "]" << endl; + + return *status; + } + + +// Manual 5.4.1 Keyword Reading Routines +// 'Return the number of existing keywords (not counting the END keyword) and the amount of +// space currently available for more keywords. It returns morekeys = -1 if the header has not +// yet been closed.' + int fits_get_hdrspace(int *numkeys, int *morekeys, int *status) + { + *numkeys = endcard_cix; + + long rem = (endcard_cix+1) % 36; + *morekeys = (rem==0) ? 0 : (36-rem); + return *status; + } + + + // keynum=1..numkeys + int fits_read_record(int keynum, char *card, int *status) + { + strncpy(card, &(buffer[(keynum-1)*80]), 80); + card[80]=0; + + return *status; + } + + + int fits_read_key(int datatype, char *keyname, void *value, char *comment,int *status) + { + char lkeyname[8+1]; + char lvalue[16+1]; + int keylength; + + for(int i=0; i<(endcard_cix+1); i++) + { + char card[80+1]; card[80]=0; + fits_read_record(i+1, card, status); + fits_get_keyname(card, lkeyname, &keylength, status); + lkeyname[keylength] = 0; + + if(0 == string(lkeyname).compare(string{keyname})) + { + fits_parse_value(card, lvalue, comment, status); + if((lvalue!=NULL) && (*status==0)) + { + switch(datatype) + { + case TDOUBLE: *((double*)value) = stod(lvalue); break; + default: + break; + } + } + } + } + + return *status; + } + +// cfitsio manual[9.5 Specialized FITS Primary Array or IMAGE Extension I/O Routines]: +// 'The fpixel and lpixel parameters are integer arrays which specify the starting +// and ending pixel coordinate in each dimension (starting with 1, not 0) of the FITS image' + int ffgsv(int bitpix, + int naxis, long *naxes, + long *fpixel, /*long *lpixel, long *inc,*/ long arraylen, + char nulval, char *array, int *anynul, int *status ) + { + //assert( fpixel[0] <= lpixel[0] ); + + dav_off_t pixels_off = 0; + for(int i=(naxis-1); i>=0; i--) + { + pixels_off += (fpixel[i]-1) * volume[i]; + } + //cout << "pixels_off: " << pixels_off << endl; + + dav_off_t doff = du_firstbyte_cix + (abs(bitpix)/8) * pixels_off; + + //cout << "file offset: " << doff << endl; + + this->file.readPartial(NULL, array, arraylen, doff, &err); + + return *status; + } + /* + dav_ssize_t readPartial(const RequestParams* params, + void* buff, + dav_size_t count, + dav_off_t offset, + DavixError** err) throw(); + */ + + private: + + string get_card_value(int card_ix, int *status) + { + char card[80+1]; card[80]=0; + char value[16+1]; + + fits_read_record(card_ix+1, card, status); + fits_parse_value(card, value, NULL, status); + if((value!=NULL) && (*status==0)) + { + return string{value}; + } + else + { + return string(); + } + } +/* + string get_card_key(int card_ix, int *status) + { + char card[80+1]; card[80]=0; + char keyname[8+1]; + int keylength; + + fits_read_record(card_ix+1, card, status); + fits_get_keyname(card, keyname, &keylength, status); + keyname[keylength] = 0; + if((keyname!=NULL) && (*status==0)) + { + return string{keyname}; + } + else + { + return string(); + } + } +*/ + + + DavixError* err=NULL; + Context c; + DavFile file; + + static const int NCARDS=1400; + char buffer[NCARDS*80]; + long endcard_cix; + long du_firstbyte_cix; + + dav_off_t volume[9] = {1,1,1,1,1,1,1,1,1}; +}; + +///////////////////////////////////////////////////////////////////////////// +#define HEADER_TOO_LONG (10000) +#define MAX_CARD_COUNT (1400) + +/* +namespace fitsfiles { +string cfitsio_errmsg(const char * filename, int line_num, int status) +{ + char errmsg[32]; // cfitsio doc says errmsg is "30 chars max" + errmsg[0] = 0; + fits_get_errstatus(status, errmsg); + string msg{"ERR["+to_string(status)+"] " + string{filename} + "." + to_string(line_num) + ":" + string{errmsg}}; + + return msg; +} +} + +#define LOG_STREAM cerr +#define LOG_trace(a) {LOG_STREAM << a << endl;} +*/ +void endianess(int bitpix, long buffsize, char* buffer) +{ + const int bytepix = abs(bitpix)/8; + char pixbuffer[bytepix]; + + for(int ii=0; ii<buffsize; ii+=bytepix) + { + for(int kk=0; kk<bytepix; kk++) + { + pixbuffer[kk] = buffer[ii+kk]; + } + for(int kk=0; kk<bytepix; kk++) + { + buffer[ii+bytepix-1-kk] = pixbuffer[kk]; + } + } +} + +int fits_copy_image_section3( + dav fdav, /* I - dav handle to FITS-file */ + fitsfile *newptr, /* I - pointer to output image */ + char *expr, /* I - Image section expression */ + int *status) +{ + int bitpix, naxis, numkeys, morekeys, nkey; + long naxes[] = {1,1,1,1,1,1,1,1,1}, smin, smax, sinc; + long fpixels[] = {1,1,1,1,1,1,1,1,1}; + long lpixels[] = {1,1,1,1,1,1,1,1,1}; + long incs[] = {1,1,1,1,1,1,1,1,1}; + char *cptr, keyname[FLEN_KEYWORD], card[FLEN_CARD]; + int ii, tstatus, anynull; + long minrow, maxrow, minslice, maxslice, mincube, maxcube; + long firstpix; + long ncubeiter, nsliceiter, nrowiter, kiter, jiter, iiter; + int klen, kk, jj; + long outnaxes[9], outsize, buffsize; + double *buffer, crpix, cdelt; + + if (*status > 0) + return(*status); + + /* get the size of the input image */ + fdav.fits_get_img_type(&bitpix, status); + fdav.fits_get_img_dim(&naxis, status); + if (fdav.fits_get_img_size(naxis, naxes, status) > 0) + return(*status); + + if (naxis < 1 || naxis > 4) + { + ffpmsg( + "Input image either had NAXIS = 0 (NULL image) or has > 4 dimensions"); + return(*status = BAD_NAXIS); + } + + /* create output image with same size and type as the input image */ + /* Will update the size later */ + fits_create_img(newptr, bitpix, naxis, naxes, status); + + /* copy all other non-structural keywords from the input to output file */ + fdav.fits_get_hdrspace(&numkeys, &morekeys, status); + + int cards_written = 4; + for (nkey = 4; nkey <= numkeys; nkey++) /* skip the first few keywords */ + { + fdav.fits_read_record(nkey, card, status); + + /* cfitsio(v4.2.0) manual: 10.2.3 Notes about the stream filetype driver + * stream:// driver has internal buffer NIOBUF=40 blocks e.g. 1400 cards + * TYP_COMM_KEY: skip HISTORY COMMENT and empty keys */ + if(numkeys > MAX_CARD_COUNT) + if (fits_get_keyclass(card) == TYP_COMM_KEY) continue; + + if (fits_get_keyclass(card) > TYP_CMPRS_KEY) + { + if(++cards_written > MAX_CARD_COUNT) return(HEADER_TOO_LONG); + + /* write the record to the output file */ + fits_write_record(newptr, card, status); + } + } + + if (*status > 0) + { + ffpmsg("error copying header from input image to output image"); + return(*status); + } + + /* parse the section specifier to get min, max, and inc for each axis */ + /* and the size of each output image axis */ + + LOG_STREAM << "expr: " << string{expr} << endl; + LOG_STREAM << "naxis: " << to_string(naxis) << endl; + + cptr = expr; + for (ii=0; ii < naxis; ii++) + { + if (fits_get_section_range(&cptr, &smin, &smax, &sinc, status) > 0) + { + ffpmsg("error parsing the following image section specifier:"); + ffpmsg(expr); + return(*status); + } + + if (smax == 0) + smax = naxes[ii]; /* use whole axis by default */ + else if (smin == 0) + smin = naxes[ii]; /* use inverted whole axis */ + + if (smin > naxes[ii] || smax > naxes[ii]) + { + ffpmsg("image section exceeds dimensions of input image:"); + ffpmsg(expr); + return(*status = BAD_NAXIS); + } + + fpixels[ii] = smin; + lpixels[ii] = smax; + incs[ii] = sinc; + + if (smin <= smax) + outnaxes[ii] = (smax - smin + sinc) / sinc; + else + outnaxes[ii] = (smin - smax + sinc) / sinc; + + /* modify the NAXISn keyword */ + fits_make_keyn("NAXIS", ii + 1, keyname, status); + LOG_STREAM << "modifkey: " << keyname << " " << outnaxes[ii] << " / " << *status <<endl; + fits_modify_key_lng(newptr, keyname, outnaxes[ii], NULL, status); + + /* modify the WCS keywords if necessary */ + + if (fpixels[ii] != 1 || incs[ii] != 1) + { + for (kk=-1;kk<26; kk++) /* modify any alternate WCS keywords */ + { + /* read the CRPIXn keyword if it exists in the input file */ + fits_make_keyn("CRPIX", ii + 1, keyname, status); + + if (kk != -1) { + klen = (int)strlen(keyname); + keyname[klen]= (char)((int)'A' + kk); + keyname[klen + 1] = '\0'; + } + + LOG_STREAM << "read key: " << string{keyname} << " / " << *status << endl; + + tstatus = 0; + if (fdav.fits_read_key(TDOUBLE, keyname, + &crpix, NULL, &tstatus) == 0) + { + + /* calculate the new CRPIXn value */ + if (fpixels[ii] <= lpixels[ii]) { + crpix = (crpix - double(fpixels[ii])) / double(incs[ii]) + 1.0; + /* crpix = (crpix - (fpixels[ii] - 1.0) - .5) / incs[ii] + 0.5; */ + } else { + crpix = (double(fpixels[ii]) - crpix) / double(incs[ii]) + 1.0; + /* crpix = (fpixels[ii] - (crpix - 1.0) - .5) / incs[ii] + 0.5; */ + } + + /* modify the value in the output file */ + fits_modify_key_dbl(newptr, keyname, crpix, 15, NULL, status); + + LOG_STREAM << "modifkey: " << string{keyname} << " / " << *status << endl; + + if (incs[ii] != 1 || fpixels[ii] > lpixels[ii]) + { + /* read the CDELTn keyword if it exists in the input file */ + fits_make_keyn("CDELT", ii + 1, keyname, status); + + if (kk != -1) { + klen = (int)strlen(keyname); + keyname[klen]=(char)((int)'A' + kk); + keyname[klen + 1] = '\0'; + } + + LOG_STREAM << "modifkey: " << string{keyname} << " / " << *status << endl; + + tstatus = 0; + if (fdav.fits_read_key(TDOUBLE, keyname, + &cdelt, NULL, &tstatus) == 0) + { + /* calculate the new CDELTn value */ + if (fpixels[ii] <= lpixels[ii]) + cdelt = cdelt * double(incs[ii]); + else + cdelt = cdelt * double(-incs[ii]); + + /* modify the value in the output file */ + fits_modify_key_dbl(newptr, keyname, cdelt, 15, NULL, status); + } + + /* modify the CDi_j keywords if they exist in the input file */ + + fits_make_keyn("CD1_", ii + 1, keyname, status); + + LOG_STREAM << "modifkey: " << string{keyname} << endl; + + if (kk != -1) { + klen = (int)strlen(keyname); + keyname[klen]=(char)((int)'A' + kk); + keyname[klen + 1] = '\0'; + } + + for (jj=0; jj < 9; jj++) /* look for up to 9 dimensions */ + { + keyname[2] = (char)((int)'1' + jj); + + LOG_STREAM << "modifkey: " << string{keyname} <<" / " << *status << endl; + tstatus = 0; + if (fdav.fits_read_key(TDOUBLE, keyname, + &cdelt, NULL, &tstatus) == 0) + { + /* calculate the new CDi_j value */ + if (fpixels[ii] <= lpixels[ii]) + cdelt = cdelt * double(incs[ii]); + else + cdelt = cdelt * double(-incs[ii]); + + /* modify the value in the output file */ + fits_modify_key_dbl(newptr, keyname, cdelt, 15, NULL, status); + } + } + + } /* end of if (incs[ii]... loop */ + } /* end of fits_read_key loop */ + } /* end of for (kk loop */ + } + *status=0; // FIXME I had to add this to force continue because it exited for CRPIXiA + } /* end of main NAXIS loop */ + + if (ffrdef(newptr, status) > 0) /* force the header to be scanned */ + { + return(*status); + } + + /* turn off any scaling of the pixel values */ + // NOTE not needed: we just copy data unchanged fits_set_bscale(fptr, 1.0, 0.0, status); + fits_set_bscale(newptr, 1.0, 0.0, status); + + /* to reduce memory foot print, just read/write image 1 row at a time */ + + outsize = outnaxes[0]; + buffsize = (abs(bitpix) / 8) * outsize; + + LOG_STREAM << "outsize / buffsize : " << outsize << " / " << buffsize << endl; + + buffer = (double *) malloc(buffsize); /* allocate memory for the image row */ + if (!buffer) + { + ffpmsg("fits_copy_image_section: no memory for image section"); + return(*status = MEMORY_ALLOCATION); + } + /* read the image section then write it to the output file */ + + minrow = fpixels[1]; + maxrow = lpixels[1]; + if (minrow > maxrow) { + nrowiter = (minrow - maxrow + incs[1]) / incs[1]; + } else { + nrowiter = (maxrow - minrow + incs[1]) / incs[1]; + } + + minslice = fpixels[2]; + maxslice = lpixels[2]; + if (minslice > maxslice) { + nsliceiter = (minslice - maxslice + incs[2]) / incs[2]; + } else { + nsliceiter = (maxslice - minslice + incs[2]) / incs[2]; + } + + mincube = fpixels[3]; + maxcube = lpixels[3]; + if (mincube > maxcube) { + ncubeiter = (mincube - maxcube + incs[3]) / incs[3]; + } else { + ncubeiter = (maxcube - mincube + incs[3]) / incs[3]; + } + + firstpix = 1; + for (kiter = 0; kiter < ncubeiter; kiter++) + { + if (mincube > maxcube) { + fpixels[3] = mincube - (kiter * incs[3]); + } else { + fpixels[3] = mincube + (kiter * incs[3]); + } + + lpixels[3] = fpixels[3]; + + for (jiter = 0; jiter < nsliceiter; jiter++) + { + if (minslice > maxslice) { + fpixels[2] = minslice - (jiter * incs[2]); + } else { + fpixels[2] = minslice + (jiter * incs[2]); + } + + lpixels[2] = fpixels[2]; + + for (iiter = 0; iiter < nrowiter; iiter++) + { + if (minrow > maxrow) { + fpixels[1] = minrow - (iiter * incs[1]); + } else { + fpixels[1] = minrow + (iiter * incs[1]); + } + + lpixels[1] = fpixels[1]; + + // + fdav.ffgsv(bitpix, naxis, naxes, + fpixels, buffsize, 0, (char*)buffer, NULL, status); + + endianess(bitpix, buffsize, (char*)buffer); + + if (bitpix == 8) + { + ffpprb(newptr, 1, firstpix, outsize, (unsigned char *) buffer, status); + } + else if (bitpix == 16) + { + ffppri(newptr, 1, firstpix, outsize, (short *) buffer, status); + } + else if (bitpix == 32) + { + ffpprk(newptr, 1, firstpix, outsize, (int *) buffer, status); + } + else if (bitpix == -32) + { + ffppne(newptr, 1, firstpix, outsize, (float *) buffer, FLOATNULLVALUE, status); + } + else if (bitpix == -64) + { + ffppnd(newptr, 1, firstpix, outsize, (double *) buffer, DOUBLENULLVALUE, + status); + } + else if (bitpix == 64) + { + ffpprjj(newptr, 1, firstpix, outsize, (LONGLONG *) buffer, status); + } + + firstpix += outsize; + } + } + } + + free(buffer); /* finished with the memory */ + + if (*status > 0) + { + ffpmsg("fits_copy_image_section: error copying image section"); + return(*status); + } + + return *status; +} + +void imcopydav(std::string url, int extnum, std::string pixfilter) +{ + LOG_trace(__func__); + LOG_STREAM << url << " EXT: " << extnum << endl; + LOG_STREAM << "pixfilter: " << pixfilter << endl; + + int status = 0; + + pixfilter.erase( remove(pixfilter.begin(), pixfilter.end(), '['), pixfilter.end() ); + pixfilter.erase( remove(pixfilter.begin(), pixfilter.end(), ']'), pixfilter.end() ); + + LOG_STREAM << "filter expr: " << pixfilter << endl; + + char *expr = (char*)pixfilter.c_str(); /* I - Image section expression */ + + dav fdav(url); /* I - input image */ + fitsfile *newfptr; /* I - pointer to output image */ + + fits_create_file(&newfptr, "cut.fits", &status); + //fits_create_file(&newfptr, "stream://", &status); + if (status) + { + string errmsg{ fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, status) }; + + int tstatus = 0; + //fits_close_file(fptr, &tstatus); + if(tstatus) LOG_STREAM << fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, tstatus) << tstatus<< endl; + + throw runtime_error("fits_open_file to stream failed: " + errmsg); + } + + + fits_copy_image_section3(fdav, newfptr, expr, &status); + if (status) + { + int tstatus = 0; + //fits_close_file(fptr, &tstatus); + //if(tstatus) LOG_STREAM << fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, tstatus) << tstatus<< endl; + tstatus = 0; + fits_close_file(newfptr, &tstatus); + if(tstatus) LOG_STREAM << fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, tstatus) << tstatus<< endl; + + if(status == HEADER_TOO_LONG) + { + throw runtime_error("Cutout from " + url + + " failed: header is too long. Direct streaming in current build support max " + + to_string(MAX_CARD_COUNT) + " cards in header."); + } + else + { + string errmsg{fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, status)}; + throw runtime_error("fits_copy_image_section " + url + + " to cut-file with " + string{expr} + " failed: " + errmsg); + } + } + + + fits_close_file(newfptr, &status); + if (status) + { + string errmsg{fitsfiles::cfitsio_errmsg(__FILE__, __LINE__, status)}; + throw runtime_error("fits_close_file cut failed: " + errmsg); + } +} + diff --git a/data-access/engine/src/vlkb/src/imcopydav.hpp b/data-access/engine/src/vlkb/src/imcopydav.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2147a68f4c3c06202c24a436d4b534ebfe2444b8 --- /dev/null +++ b/data-access/engine/src/vlkb/src/imcopydav.hpp @@ -0,0 +1,10 @@ +#ifndef IMCOPYDAV_HPP +#define IMCOPYDAV_HPP + +#include <string> + +void imcopydav(std::string url, int extnum, std::string pixfilter); +int stream_cutout_dav(std::string url, int extnum, std::string region); + +#endif + diff --git a/data-access/engine/src/vlkb/src/main.cpp b/data-access/engine/src/vlkb/src/main.cpp index ccc7e759e3588a797350e7f47f7274e723dd43d9..dd39f234319d3803e8cbaa48762574b9c4ac58f1 100644 --- a/data-access/engine/src/vlkb/src/main.cpp +++ b/data-access/engine/src/vlkb/src/main.cpp @@ -5,6 +5,7 @@ #include "multicutout.hpp" #include "ast.hpp" #include "imcopy.hpp" // imcopy() vlkb_cutout() +#include "imcopydav.hpp" // imcopydav() #include "ast4vl.hpp" // uint_bounds needed #include "fitsfiles.hpp" #include "service_string.hpp" // to_cftsio_format() needed @@ -42,7 +43,7 @@ namespace vlkb std::cerr << "Usage: " << progname << " <command> [cmd-options] [cmd-args]" << endl << "\n where commands are:\n " - << "\n\t cutout imcopy cutpixels multicutout mergefiles\n" + << "\n\t cutout imcopy imcopydav cutpixels multicutout mergefiles\n" << "\n\t listbounds header headermodif headerwcs skyvertices overlap\n" << "\n\t nullvals dropdegen checkcard addcard modcard rawdelcard\n" << std::endl @@ -54,7 +55,7 @@ namespace vlkb // program recognizes following commands enum cmd_set { - multicutout, mergefiles, cutout, imcopy, cutpixels, + multicutout, mergefiles, cutout, imcopy, imcopydav, cutpixels, listbounds, header, headermodif, headerwcs, overlap, skyvertices, nullvals, dropdegen, checkcard, addcard, modcard, rawdelcard}; @@ -69,6 +70,7 @@ namespace vlkb else if(cmdstr.compare("mergefiles") == 0) cmd = mergefiles; else if(cmdstr.compare("cutout") == 0) cmd = cutout; else if(cmdstr.compare("imcopy") == 0) cmd = imcopy; + else if(cmdstr.compare("imcopydav") == 0) cmd = imcopydav; else if(cmdstr.compare("cutpixels") == 0) cmd = cutpixels; else if(cmdstr.compare("listbounds") == 0) cmd = listbounds; else if(cmdstr.compare("header") == 0) cmd = header; @@ -187,15 +189,47 @@ int cmd_mergefiles(int argc, char * argv[]) int cmd_imcopy(int argc, char * argv[]) { - if((argc == 4) || (argc == 5)) + if((argc == 4)) { std::string infilename{argv[1]}; int extnum = std::stoi(std::string{argv[2]}); std::string pixfilter{argv[3]}; + try + { + imcopy(infilename, extnum, pixfilter); + } + catch(const std::exception & ex) + { + std::cerr << ex.what() << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + else + { + std::cerr + << "Usage: imcopy filename.fits extnum [a:b c:d ...]\n" + << "\n" + << "Send to stdout a subimage of N-dimesional FITS-file HDU with N-element pixel filter.\n" + << "HDU is given by extension number (0=Primary HDU, 1=Ext1, ...)" + << "Examples: \n" + << " vlkb imcopy /rootvialactea/CHaMP/region7.fits 0 [1:100,1:100,1:100]\n"; + return EXIT_FAILURE; + } +} + + +int cmd_imcopydav(int argc, char * argv[]) +{ + if((argc == 4) || (argc == 5)) + { + std::string url{argv[1]}; + int extnum = std::stoi(std::string{argv[2]}); + std::string pixfilter{argv[3]}; std::string temp_root = ((argc == 5) ? argv[4] : "/tmp" ); try { - imcopy(infilename, extnum, pixfilter, temp_root); + imcopydav(url, extnum, pixfilter); } catch(const std::exception & ex) { @@ -207,19 +241,20 @@ int cmd_imcopy(int argc, char * argv[]) else { std::cerr - << "Usage: imcopy filename.fits extnum [a:b c:d ...] <temp-root>\n" + << "Usage: imcopydav url extnum [a:b c:d ...] <temp-root>\n" << "\n" << "Send to stdout a subimage of N-dimesional FITS-file HDU with N-element pixel filter.\n" << "HDU is given by extension number (0=Primary HDU, 1=Ext1, ...)" << "<temp-root> is rw storage to hold the fits-cut while streaming (optional, default is '/tmp')" << "Examples: \n" - << " vlkb imcopy /rootvialactea/CHaMP/region7.fits 0 [1:100,1:100,1:100]\n"; + << " vlkb imcopydav http://localhost:80/tmp/testfile.fits 0 [1:100,1:100,1:100]\n"; return EXIT_FAILURE; } } + int cmd_cutout(int argc, char * argv[]) { if (argc != 4) @@ -707,6 +742,7 @@ int main (int argc, char * argv[]) { case vlkb::cutout: rc = cmd_cutout(cmd_argc, cmd_argv); break; case vlkb::imcopy: rc = cmd_imcopy(cmd_argc, cmd_argv); break; + case vlkb::imcopydav: rc = cmd_imcopydav(cmd_argc, cmd_argv); break; case vlkb::cutpixels: rc = cmd_cutpixels(cmd_argc, cmd_argv); break; case vlkb::multicutout: rc = cmd_multicutout(cmd_argc, cmd_argv); break; case vlkb::mergefiles: rc = cmd_mergefiles(cmd_argc, cmd_argv); break; diff --git a/data-access/servlet/src/main/java/cutout/SodaImpl.java b/data-access/servlet/src/main/java/cutout/SodaImpl.java index a0c8561f0207ca4379665dca21b7fbe6905954d3..07e4fad89c924585ad99f62a558705f97800e168 100644 --- a/data-access/servlet/src/main/java/cutout/SodaImpl.java +++ b/data-access/servlet/src/main/java/cutout/SodaImpl.java @@ -114,13 +114,12 @@ class SodaImpl implements Soda String pixFilterString = pixels_valid ? pixels : boundsString; - String[] cmdCut = new String[6]; + String[] cmdCut = new String[5]; cmdCut[0] = "/usr/local/bin/vlkb"; cmdCut[1] = "imcopy"; cmdCut[2] = absPathname; cmdCut[3] = String.valueOf(hdunum-1); cmdCut[4] = pixFilterString; - cmdCut[5] = fitsPaths.cutouts(); if(outputStream == null) LOGGER.finest("supplied outputStream for cut-file is null");