64 *
this += (
String)
"." + ext;
78 std::vector<String> prefixes;
79 int nPref =
splitString(str.substr(0, first),
",",prefixes,
false);
81 if (isalpha(prefixes[nPref-1].at(0)))
99 str.c_str(), ext.c_str());
107 if (blockName.empty())
118 *
this += (
String)
"." + ext;
124 return find(
AT) != String::npos;
131 unsigned long int auxNo;
132 int ok = sscanf(c_str(),
"%lu@%s", &auxNo, buffer);
159 size_t skip_directories = find_last_of(
"/") + 1;
160 size_t point = find_first_of(
".", skip_directories);
163 size_t root_end = find_last_not_of(
"0123456789", point - 1);
164 if (root_end + 1 != point)
167 return substr(0, root_end + 1);
174 for (
size_t i = 0;
i < result.length();
i++)
175 result[
i] = tolower(result[
i]);
183 for (
size_t i = 0;
i < result.length();
i++)
184 result[
i] = toupper(result[
i]);
191 return find(str) != npos;
198 size_t point = find_first_of(str);
199 return (point != npos ? (
FileName)substr(0, point) : *
this);
206 size_t point = find_last_of(str);
207 return point != npos ? (
FileName)substr(0, point) : *
this;
214 size_t point = find_first_of(str);
215 return point != npos ? (
FileName)substr(point + 1) : *
this;
222 size_t point = find_last_of(str);
223 return point != npos ? (
FileName)substr(point + 1) : *
this;
237 size_t pos = find_last_of(
"/");
238 return (
FileName)( pos != npos ? substr(0, pos+1) :
"");
244 size_t posA = find_last_of(
"/");
245 size_t posB = find_last_of(
".");
249 return substr(posB+1);
251 return substr(posB+1);
259 return (ext==
"img" || ext==
"hed" || ext==
"inf" || ext==
"raw" || ext==
"mrc" ||
260 ext==
"map" || ext==
"spi" || ext==
"xmp" || ext==
"tif" || ext==
"dm3" ||
261 ext==
"spe" || ext==
"em" || ext==
"pif" || ext==
"ser" || ext==
"stk" ||
262 ext==
"mrcs"|| ext==
"jpg" || ext==
"dm4");
269 return (ext==
"stk" || ext==
"spi" || ext==
"xmp" || ext==
"mrcs" || ext==
"mrc" ||
270 ext==
"img" || ext==
"hed" || ext==
"pif" || ext==
"tif" || ext==
"dm3" ||
271 ext==
"ser" || ext==
"st" || ext==
"dm4");
278 return (ext==
"vol" || ext==
"spi" || ext==
"xmp" || ext==
"mrc" || ext==
"map" ||
279 ext==
"em" || ext==
"pif" || ext==
"inf" || ext==
"raw");
286 return (ext ==
"sel" || ext ==
"xmd" || ext ==
"doc" ||
287 ext ==
"ctfdat" || ext ==
"ctfparam" || ext ==
"pos" ||
288 ext ==
"sqlite" || ext ==
"xml" || ext ==
"star");
308 strcpy(filename,(fnDir+
"/").c_str());
311 strcat(filename, templateStr);
312 filename[len - 1] = 0;
313 if ((fd = mkstemp(filename)) == -1)
315 perror(
"FileName::Error generating tmp lock file");
327 int skip_directories = find_last_of(
"/") + 1;
328 return retval.insert(skip_directories, prefix);
339 retval = retval.append((
String)
"." + ext);
348 return retval.substr(0, rfind(
"."));
361 size_t pos = find_last_of(
'.');
362 return pos != npos ? retval.insert(pos, str) : retval.append(str);
370 return (first == npos) ? retval: retval.erase(first, 1 + ext.length());
377 size_t first = find_last_of(
'.');
378 return (first == npos) ? retval : retval.substr(0, first);
385 size_t first = find_last_of(
'/');
386 first = find_first_of(
'.', first + 1);
387 return (first == npos) ? retval: retval.substr(0, first);
392 size_t first = find_last_of(
'/');
393 return (first == npos) ?
"" : substr(0, first);
400 if ((first = rfind(
COLON)) != npos)
401 result = substr(first + 1);
402 else if ((first = rfind(
".")) != npos)
406 result = substr(first + 1);
407 result = result.substr(0, result.find(
NUM));
417 if (stat(c_str(), &info))
420 char *success=getcwd(cCurrentPath,
sizeof(cCurrentPath));
422 cCurrentPath[0]=
'\0';
437 size_t found = rfind(
NUM);
438 if (found != String::npos)
439 return substr(0, found);
440 found = rfind(
COLON);
441 if (found != String::npos)
442 return substr(0, found);
449 size_t skip_directories = find_last_of(
"/") + 1;
450 size_t point = find_first_of(
".", skip_directories);
453 size_t root_end = find_last_not_of(
"0123456789", point - 1);
454 if (root_end + 1 != point)
458 String aux = substr(root_end + 1, point - root_end + 1);
459 return atoi(aux.c_str());
472 std::vector<String> prefixes;
473 size_t nPref =
splitString(substr(0, first),
",",prefixes,
false);
477 " detected in %s filename.",pos+1, nPref, this->c_str()));
479 if (isdigit(prefixes[pos].at(0)))
491 result = substr(0, first);
492 if ((first = result.find(
COMMA)) != npos)
493 result = result.substr(first+1);
498 if (result.empty() || isdigit(result[0]))
511 String block = substr(0, first);
512 size_t second = block.find(
COMMA);
516 if (!isdigit(block[0])){
517 return substr(first + 1);
522 String prefix = block.substr(0, second);
523 block = block.substr(second + 1);
524 if (!isdigit(block[0]))
525 return prefix + substr(first);
537 std::vector<String> prefixes;
538 int nPref =
splitString(substr(0, first),
",",prefixes,
false);
540 if (isdigit(prefixes[nPref-1].at(0)))
541 return substr(first + 1);
543 return substr(first - prefixes[nPref-1].size());
552 return substr(first + 1);
563 if (find_first_of(
":#") != npos)
591 infile.getline(cline, 128);
595 return (pos != npos);
601 size_t pos =
find(subOld);
606 result.replace(pos, subOld.length(), subNew);
614 std::replace(result.begin(), result.end(), oldChar, newChar);
633 size_t pos =
find(prefix);
637 return result.erase(0, pos + prefix.length());
643 size_t last_slash = rfind(
"/");
647 last_slash = rfind(
"/", last_slash - 1);
650 if (last_slash == npos)
653 return substr(last_slash + 1,
length() - last_slash);
658 std::ifstream f1(this->c_str(), std::fstream::binary);
674 unlink(temp.c_str());
680 size_t found = find_first_of(
AT);
682 if (found != String::npos)
683 auxF = substr(found+1);
685 found = auxF.find_first_of(
NUM);
687 if ( found != String::npos)
688 auxF = auxF.substr(0, found);
689 found = auxF.find_first_of(
COLON);
691 if (found != String::npos)
692 auxF = auxF.substr(0, found);
703 if ((dp = opendir(c_str())) == NULL)
706 while ((dirp = readdir(dp)) != NULL)
707 if (strcmp(dirp->d_name,
".")!=0 && strcmp(dirp->d_name,
"..")!=0)
708 files.push_back(
FileName(dirp->d_name));
717 if (stat (c_str(), &st_buf) != 0)
719 return (S_ISDIR (st_buf.st_mode));
732 if (stat(basicName.c_str(), &info1))
734 (
String)
"FileName::waitUntilStableSize: Cannot get size of file " + *
this);
735 off_t size1 = info1.st_size;
739 if (stat(basicName.c_str(), &info2))
741 (
String)
"FileName::waitUntilStableSize: Cannot get size of file " + *
this);
742 off_t size2 = info2.st_size;
754 unsigned char *
buffer = (
unsigned char*) calloc(
sizeof(
unsigned char),
758 FILE * fd = fopen(c_str(),
"w");
761 for (
size_t i = 0;
i < size / block_size;
i++)
762 fwrite(buffer,
sizeof(
unsigned char), block_size, fd);
763 fwrite(buffer,
sizeof(
unsigned char), size % block_size, fd);
770 FILE* fMap = fopen(c_str(),
"wb");
776 if ((fseek(fMap, length-1, SEEK_SET) == -1) || (fwrite(&c,1,1,fMap) != 1))
790 if (stat(path, &st) != 0)
794 if (mkdir(path, mode) != 0)
797 if (mkdir(path) != 0)
802 else if (!S_ISDIR(st.st_mode))
816 char *copypath = strdup(c_str());
817 if (copypath == NULL)
822 while (status == 0 && (sp = strchr(pp,
'/')) != 0)
842 if (!empty() && !
exists())
844 std::cerr <<
"FileName::assertExists: control file" << *
this 845 <<
" doesn't exist, exiting..." << std::endl;
855 char* path = getenv(
"XMIPP_HOME");
865 char* path = getenv(
"XMIPP_SRC");
893 fcntl(filenum, F_SETLKW, &fl);
905 this->filenum = fileno(hdlFile);
909 HANDLE hFile = (HANDLE)_get_osfhandle(filenum);
910 DWORD dwLastPos = SetFilePointer(hFile, 0, NULL, FILE_END);
911 if (LockFile(hFile, 0, 0, dwLastPos, 0) != NULL)
916 fcntl(filenum, F_SETLKW, &fl);
928 HANDLE hFile = (HANDLE)_get_osfhandle(filenum);
929 DWORD dwLastPos = SetFilePointer(hFile, 0, NULL, FILE_END);
930 if (UnlockFile(hFile, 0, 0, dwLastPos, 0) != NULL)
935 fcntl(filenum, F_SETLK, &fl);
Just to locate unclassified errors.
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
int do_mkdir(const char *path, mode_t mode)
FileName removeLastExtension() const
void waitUntilStableSize(size_t time_step=250000)
String getBlockName() const
Just an error for debugging purpose.
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
FileName replaceExtension(const String &newExt) const
void copyImage(const FileName &source, const FileName &target)
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
void setMetadataVersion(String version)
Couldn't write to file.
FileName removePrefixNumber() const
FileName addExtension(const String &ext) const
FileName insertBeforeExtension(const String &str) const
There is not enough memory for allocation.
void createEmptyFileWithGivenLength(size_t length=0) const
void compose(const String &str, const size_t no, const String &ext="")
String getMetadataVersion(void)
FileName removeDirectories(int keep=0) const
FileName beforeLastOf(const String &str) const
void initUniqueName(const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="")
bool hasImageExtension() const
FileName removeAllExtensions() const
void decompose(size_t &no, String &str) const
Bad amount of memory requested.
void getFiles(std::vector< FileName > &files) const
FileName afterLastOf(const String &str) const
String getExtension() const
FileName removeAllPrefixes() const
FileName afterFirstOf(const String &str) const
FileName replaceSubstring(const String &subOld, const String &subNew) const
FileName addPrefix(const String &prefix) const
FileName removeFilename() const
FileName beforeFirstOf(const String &str) const
int splitString(const String &input, const String &delimiter, StringVector &results, bool includeEmpties)
size_t getPrefixNumber(size_t pos=0) const
Incorrect argument received.
void composeBlock(const String &blockName, size_t no, const String &str, const String &ext="")
bool isStar1(bool failIfNotExists) const
int makePath(mode_t mode=0755) const
__host__ __device__ float length(float2 v)
File or directory does not exist.
FileName replaceCharacter(char oldChar, char newChar) const
bool contains(const String &str) const
FileName withoutRoot() const
FileName removeUntilPrefix(const String &prefix) const
void sort(struct DCEL_T *dcel)
FileName toLowercase() const
void createEmptyFile(size_t size, size_t block_size=102400)
void lock(int fileno=0)
Lock file.
bool isMetaData(bool failIfNotExists=true) const
FileName removeBlockName() const
FileName withoutExtension() const
bool fileExists(const char *filename)
String formatString(const char *format,...)
Error when locking/unloking a file.
String getFileFormat() const
#define FILENAMENUMBERLENGTH
FileName removeSubstring(const String &sub) const
bool hasVolumeExtension() const
FileName toUppercase() const
#define METADATA_XMIPP_STAR
void copyFile(const FileName &target) const
unsigned int randomize_random_generator()
bool hasStackExtension() const
FileName getBaseName() const
bool hasMetadataExtension() const
size_t textToSizeT(const char *str)
FileName removeExtension(const String &ext) const
size_t getFileSize() const
void formatStringFast(String &str, const char *format,...)
FileName getDecomposedFileName() const
void initRandom(int length)