31 #if defined(HAVE_LIBCFITSIO)
32 #if defined(HAVE_CFITSIO_FITSIO_H)
33 #include <cfitsio/fitsio.h>
34 #elif defined(HAVE_LIBCFITSIO0_FITSIO_H)
35 #include <libcfitsio0/fitsio.h>
47 #define G_SET_FILENAME "GFilename::set_filename(std::string&)"
161 if (
this != &filename) {
236 int ret = stat(
url().c_str(), &info);
239 if (ret == 0 && S_ISREG(info.st_mode)) {
267 std::string
type =
"";
273 size_t start = file.rfind(
".gz");
274 if (start != std::string::npos) {
275 file = file.substr(0, start);
277 start = file.rfind(
".Z");
278 if (start != std::string::npos) {
279 file = file.substr(0, start);
281 start = file.rfind(
".z");
282 if (start != std::string::npos) {
283 file = file.substr(0, start);
285 start = file.rfind(
".zip");
286 if (start != std::string::npos) {
287 file = file.substr(0, start);
291 start = file.rfind(
".fits");
292 if (start != std::string::npos) {
295 start = file.rfind(
".fit");
296 if (start != std::string::npos) {
321 #if defined(HAVE_LIBCFITSIO)
322 #pragma omp critical(GFilename_is_fits)
325 fitsfile* fptr = NULL;
326 status = ffopen(&fptr,
url().c_str(), 0, &status);
330 ffclos(fptr, &status);
355 std::remove(name_gz.
url().c_str());
357 else if (name_Z.
exists()) {
358 std::remove(name_Z.
url().c_str());
360 else if (name_z.
exists()) {
361 std::remove(name_z.
url().c_str());
363 else if (name_zip.
exists()) {
364 std::remove(name_zip.
url().c_str());
367 std::remove(
url().c_str());
392 extname = defaultname;
465 result.append(
"=== GFilename ===");
473 result.append(
m_url);
493 result.append(
"Not provided");
502 result.append(
"Not provided");
511 result.append(
"Not provided");
520 result.append(
"Not provided");
622 if (start != std::string::npos) {
625 size_t stop =
m_filename.find_first_of(
"]", start);
628 if (stop == std::string::npos) {
629 std::string msg =
"Missing ] symbol in file name \""+
642 if (character !=
"[") {
643 std::string msg =
"Non-bracket character \""+character+
644 "\" beyond ] symbol in file name \""+
646 "correct the file name.";
656 size_t sep = extname.find_first_of(
",");
659 if (sep != std::string::npos) {
665 if (extver.empty()) {
666 std::string msg =
"No extension version found after , "
668 "\". Please correct the file name.";
678 std::string msg =
"Non-positive extension version "
679 "encountered in file name \""+
691 if (extname.empty()) {
692 std::string msg =
"An empty extension has been specified in "
694 "correct the file name.";
700 if (extname.find_first_not_of(
"+-0123456789") == std::string::npos) {
708 std::string msg =
"Negative extension number encountered "
710 "Please correct the file name.";
724 std::string msg =
"Empty extension name encountered "
726 "Please correct the file name.";
736 size_t expr_start =
m_filename.find_first_of(
"[", stop+1);
738 if (expr_start != std::string::npos) {
741 size_t expr_stop =
m_filename.find_first_of(
"]", expr_start);
744 if (expr_stop == std::string::npos) {
745 std::string msg =
"Missing ] symbol in file name \""+
747 "correct the file name.";
753 std::string msg =
"Characters beyond ] symbol in file "
755 "Please correct the file name.";
771 size_t proto_end =
m_filename.find_first_of(
":");
772 if (proto_end != std::string::npos) {
781 size_t file_start =
m_filename.find_last_of(
"/");
782 size_t file_end = (start == std::string::npos) ?
m_filename.length() : start;
785 if (file_start != std::string::npos) {
788 size_t path_start =
m_filename.find_first_not_of(
"/", proto_end);
789 if (path_start != std::string::npos) {
790 if (path_start > 0) {
793 int length = file_start - path_start + 1;
800 int length = file_end - file_start - 1;
808 int length = file_end - proto_end;
std::string file(void) const
Return name of file.
void free_members(void)
Delete class members.
bool has_extno(void) const
Signal if filename has an extension number.
bool has_expression(void) const
Signal if filename has an expression.
bool has_extver(void) const
Signal if filename has an extension version.
void copy_members(const GFilename &filename)
Copy class members.
std::string m_protocol
Access protocol.
std::string m_expression
Selection expression ("": not set)
int m_extver
Extension version (0: not set)
std::string m_path
Access path.
int extver(const int &defaultver=0) const
Return extension version number.
bool has_extname(void) const
Signal if filename has an extension name.
int length(void) const
Return length of filename.
std::string extname(const std::string &defaultname="") const
Return extension name.
void set_filename(const std::string &filename)
Set file name.
void init_members(void)
Initialise class members.
GFilename * clone(void) const
Clone file name.
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
std::string m_filename
Full file name.
std::string m_url
File name (with stripped extension info)
GFilename & operator=(const GFilename &filename)
Assignment operator.
virtual ~GFilename(void)
Destructor.
int m_extno
Extension number (-1: not set)
GFilename(void)
Void constructor.
std::string m_extname
Extension name ("": not set)
bool exists(void) const
Checks whether file exists.
bool is_fits(void) const
Checks whether file is a FITS file.
void remove(void) const
Remove file from disk.
std::string type(void) const
Return file type.
std::string url(void) const
Return Uniform Resource Locator (URL)
void clear(void)
Clear file name.
int extno(const int &defaultno=-1) const
Return extension number.
Exception handler interface definition.
std::string toupper(const std::string &s)
Convert string to upper case.
int toint(const std::string &arg)
Convert string into integer value.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Filename class interface definition.
std::string m_file
Name of file.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
std::string print(const GChatter &chatter=NORMAL) const
Print file name information.