IMP
2.0.0
The Integrative Modeling Platform
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
filenames_manipulation.h
Go to the documentation of this file.
1
/**
2
* \file filenames_manipulation.h
3
* \brief Generation of projections using the central section theorem
4
* Copyright 2007-2013 IMP Inventors. All rights reserved.
5
*/
6
7
#ifndef IMPEM2D_FILENAMES_MANIPULATION_H
8
#define IMPEM2D_FILENAMES_MANIPULATION_H
9
10
#include "
IMP/exception.h
"
11
#include "
IMP/base_types.h
"
12
#include <iostream>
13
#include <fstream>
14
15
#include <boost/filesystem/path.hpp>
16
#include <boost/filesystem/exception.hpp>
17
#include <boost/version.hpp>
18
19
IMPEM2D_BEGIN_NAMESPACE
20
21
//! Reads a selection file
22
/*!
23
\param[in] fn Name of the selection file. First column is are file names
24
and second are 1 (file is selected) or 0 (file ignored)
25
\param[out] List of the selected names.
26
*/
27
inline
Strings
read_selection_file
(
String
fn) {
28
String
name;
29
Strings
names;
30
std::ifstream in;
31
int
not_ignored;
32
in.open(fn.c_str(), std::ios::in);
33
if
(!in) {
34
IMP_THROW
(
"Unable to read file "
<< fn,
35
IOException);
36
}
37
38
while
(in >> name >> not_ignored) {
39
if
(not_ignored) {
40
names.push_back(name);
41
}
42
}
43
in.close();
44
return
names;
45
}
46
47
//! generates consecutive filenames: basic_name-i.extension
48
//! Adds zeros at the front of the number when neccessary
49
inline
Strings
create_filenames
(
unsigned
long
number,
50
String
basic_name,
String
extension) {
51
// Number of digits to use
52
int
digits=0;
53
unsigned
long
count=1;
54
while
(count <= number) {
55
digits+=1;
56
count*=10;
57
}
58
Strings
proj_names(number);
59
60
for
(
unsigned
int
i=0;i<number;++i) {
61
std::ostringstream strm;
62
strm << basic_name <<
"-"
;
63
strm.fill(
'0'
);
64
strm.width(digits);
65
strm << i;
66
strm <<
"."
<< extension;
67
proj_names[i]=strm.str();
68
}
69
return
proj_names;
70
}
71
72
73
IMPEM2D_END_NAMESPACE
74
75
#endif
/* IMPEM2D_FILENAMES_MANIPULATION_H */