|
| bool | CheckFolderPaths (std::string &top_level_string, std::string &starting_string) |
| | Validates and resolves folder paths, ensuring the starting directory is within the top-level directory.
|
| |
| bool | IsSubdirectory (std::string folder, std::string top_folder) |
| | Determines whether a given folder is a subdirectory of a specified top-level folder.
|
| |
| CARTA::FileType | GuessImageType (const std::string &path_string, bool check_content) |
| | Determines the image file type based on its content or extension.
|
| |
| CARTA::FileType | GuessRegionType (const std::string &path_string, bool check_content) |
| | Determines the region file type based on its content or extension.
|
| |
| CARTA::CatalogFileType | GuessTableType (const std::string &path_string, bool check_content) |
| | Determines the catalog table file type based on its content or file extension.
|
| |
| uint32_t | GetMagicNumber (const std::string &filename) |
| | Reads the magic number from the beginning of a file.
|
| |
| bool | IsCompressedFits (const std::string &filename) |
| | Checks whether a given file is a compressed FITS file.
|
| |
| bool | IsGzMagicNumber (uint32_t magic_number) |
| | Determines if a given magic number corresponds to a gzip-compressed file.
|
| |
| bool | IsRemoteHttpFile (const std::string &filename) |
| | Checks whether a given filename represents a remote HTTP or HTTPS URL.
|
| |
| int | GetNumItems (const std::string &path) |
| | Counts the number of items in a given directory.
|
| |
| fs::path | SearchPath (std::string filename) |
| | Searches for a file in the system's PATH environment variable.
|
| |
| bool CheckFolderPaths |
( |
std::string & |
top_level_string, |
|
|
std::string & |
starting_string |
|
) |
| |
Validates and resolves folder paths, ensuring the starting directory is within the top-level directory.
- Parameters
-
| [in,out] | top_level_string | Reference to the top-level directory path. It is updated to its resolved absolute path. |
| [in,out] | starting_string | Reference to the starting directory path. It is updated to its resolved absolute path. |
- Returns
true if the paths are valid and the starting directory is within the top-level directory, otherwise false.
This function checks and resolves the given top-level and starting directories. If default placeholder values ("base" or "root") are found, they are replaced accordingly. The function verifies that both directories exist and are accessible, and ensures that the starting directory is a valid subdirectory of the top-level directory.
- Note
- If
starting_string is invalid, it is replaced with top_level_string.
-
If
starting_string is not a subdirectory of top_level_string, the function logs a critical error and returns false.
- Warning
- If both
top_level_string and starting_string are set to their default placeholders ("base" and "root"), the function logs a critical error and returns false.
| CARTA::FileType GuessRegionType |
( |
const std::string & |
path_string, |
|
|
bool |
check_content |
|
) |
| |
Determines the region file type based on its content or extension.
- Parameters
-
| [in] | path_string | The path to the region file to be identified. |
| [in] | check_content | If true, the function checks the file's header; otherwise, it relies on the file extension. |
- Returns
- The detected file type as a
CARTA::FileType enumeration:
CARTA::CRTF for CASA Region Text Format (CRTF) files.
CARTA::DS9_REG for DS9 region files.
CARTA::UNKNOWN if the file type cannot be determined.
This function attempts to identify the type of a region file used in astronomical imaging analysis by either checking its file content or examining its file extension. If check_content is true, it reads the first line of the file to identify known headers (e.g., #CRTF or # Region file format: DS9). Otherwise, it determines the file type based on its extension.
- Note
- CRTF files typically start with
#CRTF, while DS9 region files may include # Region file format: DS9 as an optional header.
- Warning
- Checking file content requires reading the first line, which may introduce a slight I/O overhead.
| CARTA::CatalogFileType GuessTableType |
( |
const std::string & |
path_string, |
|
|
bool |
check_content |
|
) |
| |
Determines the catalog table file type based on its content or file extension.
- Parameters
-
| path_string | The file path as a string. |
| check_content | If true, the function checks the file's magic number for type detection. If false, it relies on the file extension. |
- Returns
- CARTA::CatalogFileType The detected file type, which can be:
CARTA::CatalogFileType::FITSTable for FITS table files.
CARTA::CatalogFileType::VOTable for XML-based VOTable files.
CARTA::CatalogFileType::Unknown if the type cannot be determined.
This function attempts to classify the type of a catalog table file (e.g., FITS table or VOTable) either by checking its magic number (if check_content is true) or, if content checking is disabled, by inspecting the file extension.
- Note
- If
check_content is enabled, the function may attempt to read the file's magic number. Ensure the file is accessible to avoid potential I/O errors.
- Warning
- This function does not validate file integrity; it only determines type based on basic signature matching or filename extensions.
| fs::path SearchPath |
( |
std::string |
filename | ) |
|
Searches for a file in the system's PATH environment variable.
- Parameters
-
| [in] | filename | The name of the file to search for. |
- Returns
- The full path to the located file, or an empty
fs::path if not found.
This function retrieves the PATH environment variable, splits it into individual directory paths, and searches for the specified file within those directories. If the file is found, its full path is returned. If not found or if an error occurs, an empty fs::path is returned.
- Note
- This function assumes that path entries in
PATH are separated by colons (:), which is standard on UNIX-like systems.
- Warning
- If the
PATH environment variable is not set, this function may behave unexpectedly.