Bsoft 2.1.4
Bernard's software package
file_util.h File Reference

Header file for file checking functions. More...

#include "Bstring.h"
#include <fstream>

Macros

#define _filetype_
 

Enumerations

enum  FileType {
  Unknown_FileType = 0 , Image = 1 , Micrograph = 2 , Molecule = 3 ,
  Model = 4 , MgRelion = 11
}
 File type enumeration. More...
 

Functions

int fread_large (unsigned char *aptr, size_t pagesize, size_t offset, ifstream *fimg)
 Reads blocks of memeory no larger than 1Gb. More...
 
int fread_large (unsigned char *aptr, size_t pagesize, size_t offset, ifstream &fimg)
 
Bstring find_file (Bstring filename, Bstring path, int flag=0)
 Searches for a file within or without the given path. More...
 
string find_file (string filename, string path, int flag=0)
 
vector< string > file_list (string path)
 Returns a list of files in the requested directory. More...
 
vector< string > file_list (string path, string ext)
 Returns a list of files in the requested directory. More...
 
FileType file_type (const char *filename)
 Checks the file type using the extension and contents. More...
 
FileType file_type (Bstring &filename)
 
int detect_and_fix_carriage_return (const char *filename)
 Detects carriage returns in text files and converts them to new-lines. More...
 

Detailed Description

Header file for file checking functions.

Author
Bernard Heymann
Date
Created: 20010601
Modified: 20210413

Macro Definition Documentation

◆ _filetype_

#define _filetype_

Enumeration Type Documentation

◆ FileType

enum FileType

File type enumeration.

The types are mostly based on Bsoft objects. Additional types enumerated above 10 are for other packages.

Enumerator
Unknown_FileType 
Image 
Micrograph 
Molecule 
Model 
MgRelion 

Function Documentation

◆ detect_and_fix_carriage_return()

int detect_and_fix_carriage_return ( const char *  filename)

Detects carriage returns in text files and converts them to new-lines.

Parameters
*filenamefile name.
Returns
int 0, <0 if error.
The first line is read and if any carriage returns are found, the whole
file is scanned and carriage returns converted to new-lines.

◆ file_list() [1/2]

vector< string > file_list ( string  path)

Returns a list of files in the requested directory.

Parameters
&pathdirectory path.
Returns
vector<string> list of file names.

◆ file_list() [2/2]

vector< string > file_list ( string  path,
string  ext 
)

Returns a list of files in the requested directory.

Parameters
&pathdirectory path.
&extfile name extension.
Returns
vector<string> list of file names.

◆ file_type() [1/2]

FileType file_type ( Bstring filename)

◆ file_type() [2/2]

FileType file_type ( const char *  filename)

Checks the file type using the extension and contents.

Parameters
*filenamefile name.
Returns
FileType enumerated file type.
The file extension is the main determinant of the file type.
File formats with multiple types (such as the STAR and PDB formats)
are distinguished based on content.

◆ find_file() [1/2]

Bstring find_file ( Bstring  filename,
Bstring  path,
int  flag 
)

Searches for a file within or without the given path.

Parameters
filenamefile name to search for.
pathpath to search in.
flagif not found: bit 4 = warn; bit 5 = delete file name.
Returns
Bstring found file, empty if not found and delete_flag set.
The input filename is first tested for access.
If not found, the filename without its original path is tested.
If not found, the filename with the given path is tested.
If not found, an error is reported and the original filename returned 
unless the delete flag is set.

◆ find_file() [2/2]

string find_file ( string  filename,
string  path,
int  flag = 0 
)

◆ fread_large() [1/2]

int fread_large ( unsigned char *  aptr,
size_t  pagesize,
size_t  offset,
ifstream &  fimg 
)

◆ fread_large() [2/2]

int fread_large ( unsigned char *  aptr,
size_t  pagesize,
size_t  offset,
ifstream *  fimg 
)

Reads blocks of memeory no larger than 1Gb.

Parameters
*aptrpointer to pre-allocated memory.
pagesizesize of pre-allocated memory.
offsetoffset in file.
*fimgfile pointer.
Returns
int 0, <0 if error.
Each block is packed in sequence into the pre-allocated memory provided.