TECA
The Toolkit for Extreme Climate Analysis
teca_file_util Namespace Reference

Codes dealing with low level file system API's. More...

Classes

struct  line_buffer
 

Functions

TECA_EXPORT int read_stream (const char *file_name, const char *header, teca_binary_stream &stream, bool verbose=true)
 
TECA_EXPORT int write_stream (const char *file_name, int flags, const char *header, const teca_binary_stream &stream, bool verbose=true)
 
TECA_EXPORT void replace_timestep (std::string &file_name, unsigned long time_step, int width=6)
 replace t% with the given value More...
 
TECA_EXPORT int replace_time (std::string &file_name, double t, const std::string &calendar, const std::string &units, const std::string &format)
 replace t% with the time t in calendar with units in the strftime format More...
 
TECA_EXPORT void replace_extension (std::string &file_name, const std::string &ext)
 replace e% with the given string More...
 
TECA_EXPORT void replace_identifier (std::string &file_name, const std::string &id)
 replace s% with the given string More...
 
TECA_EXPORT void to_lower (std::string &in)
 return string converted to lower case More...
 
TECA_EXPORT int file_exists (const char *path)
 return 0 if the file does not exist More...
 
TECA_EXPORT int file_writable (const char *path)
 return 0 if the file/directory is not writeable More...
 
TECA_EXPORT std::string path (const std::string &filename)
 
TECA_EXPORT std::string base_filename (const std::string &filename)
 
TECA_EXPORT std::string filename (const std::string &filename)
 
TECA_EXPORT std::string extension (const std::string &filename)
 Returns the extension from the given filename. More...
 
TECA_EXPORT size_t load_lines (const char *filename, std::vector< std::string > &lines)
 read the lines of the ascii file into a vector More...
 
TECA_EXPORT size_t load_text (const std::string &filename, std::string &text)
 read the file into a string More...
 
TECA_EXPORT int write_text (std::string &filename, std::string &text)
 write the string to the named file More...
 
TECA_EXPORT int search_and_replace (const std::string &search_for, const std::string &replace_with, std::string &in_text)
 Search and replace with in a string of text. More...
 
TECA_EXPORT int locate_files (const std::string &path, const std::string &re, std::vector< std::string > &file_list)
 Locate files in path that match a regular expression. More...
 
template<typename T >
TECA_EXPORT size_t load_bin (const char *filename, size_t dlen, T *buffer)
 Load a binary file into memory. More...
 
template<typename T >
TECA_EXPORT int name_value (std::vector< std::string > &lines, std::string name, T &value)
 extract a name-value pair from the given set of lines. More...
 
template<typename T >
TECA_EXPORT size_t parse_value (std::string &in, size_t at, std::string key, T &value)
 

Detailed Description

Codes dealing with low level file system API's.

Function Documentation

◆ base_filename()

TECA_EXPORT std::string teca_file_util::base_filename ( const std::string &  filename)

Returns the file name not including the extension (ie what ever is after the last ".". If there is no "." then the filename is returned unmodified.

◆ extension()

TECA_EXPORT std::string teca_file_util::extension ( const std::string &  filename)

Returns the extension from the given filename.

◆ file_exists()

TECA_EXPORT int teca_file_util::file_exists ( const char *  path)

return 0 if the file does not exist

◆ file_writable()

TECA_EXPORT int teca_file_util::file_writable ( const char *  path)

return 0 if the file/directory is not writeable

◆ filename()

TECA_EXPORT std::string teca_file_util::filename ( const std::string &  filename)

Returns the file name from the given path. If PATH_SEP isn't found then the filename is returned unmodified.

◆ load_bin()

template<typename T >
TECA_EXPORT size_t teca_file_util::load_bin ( const char *  filename,
size_t  dlen,
T *  buffer 
)

Load a binary file into memory.

◆ load_lines()

TECA_EXPORT size_t teca_file_util::load_lines ( const char *  filename,
std::vector< std::string > &  lines 
)

read the lines of the ascii file into a vector

◆ load_text()

TECA_EXPORT size_t teca_file_util::load_text ( const std::string &  filename,
std::string &  text 
)

read the file into a string

◆ locate_files()

TECA_EXPORT int teca_file_util::locate_files ( const std::string &  path,
const std::string &  re,
std::vector< std::string > &  file_list 
)

Locate files in path that match a regular expression.

◆ name_value()

template<typename T >
TECA_EXPORT int teca_file_util::name_value ( std::vector< std::string > &  lines,
std::string  name,
T &  value 
)

extract a name-value pair from the given set of lines.

◆ parse_value()

template<typename T >
TECA_EXPORT size_t teca_file_util::parse_value ( std::string &  in,
size_t  at,
std::string  key,
T &  value 
)

Parse a string for a "key", starting at offset "at" then advance past the key and attempt to convert what follows in to a value of type "T". If the key isn't found, then npos is returned otherwise the position imediately following the key is returned.

◆ path()

TECA_EXPORT std::string teca_file_util::path ( const std::string &  filename)

Returns the path not including the file name and not including the final PATH_SEP. If PATH_SEP isn't found then ".PATH_SEP" is returned.

◆ read_stream()

TECA_EXPORT int teca_file_util::read_stream ( const char *  file_name,
const char *  header,
teca_binary_stream stream,
bool  verbose = true 
)

read the file into a stream. if header is not null the call will fail if the given string is not found. return zero upon success. The verbose flag indicates whether or not an error is reported if opening the file fails. All other errors are always reported.

◆ replace_extension()

TECA_EXPORT void teca_file_util::replace_extension ( std::string &  file_name,
const std::string &  ext 
)

replace e% with the given string

◆ replace_identifier()

TECA_EXPORT void teca_file_util::replace_identifier ( std::string &  file_name,
const std::string &  id 
)

replace s% with the given string

◆ replace_time()

TECA_EXPORT int teca_file_util::replace_time ( std::string &  file_name,
double  t,
const std::string &  calendar,
const std::string &  units,
const std::string &  format 
)

replace t% with the time t in calendar with units in the strftime format

◆ replace_timestep()

TECA_EXPORT void teca_file_util::replace_timestep ( std::string &  file_name,
unsigned long  time_step,
int  width = 6 
)

replace t% with the given value

◆ search_and_replace()

TECA_EXPORT int teca_file_util::search_and_replace ( const std::string &  search_for,
const std::string &  replace_with,
std::string &  in_text 
)

Search and replace with in a string of text.

◆ to_lower()

TECA_EXPORT void teca_file_util::to_lower ( std::string &  in)

return string converted to lower case

◆ write_stream()

TECA_EXPORT int teca_file_util::write_stream ( const char *  file_name,
int  flags,
const char *  header,
const teca_binary_stream stream,
bool  verbose = true 
)

write the stream to the file. the passed in flags control file access, a reasonable value is S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH. if header is not null the given string is prepended to the file. return zero upon success. The verbose flag indicates whether or not an error is reported if creating the file fails. All other errors are reported.

◆ write_text()

TECA_EXPORT int teca_file_util::write_text ( std::string &  filename,
std::string &  text 
)

write the string to the named file