ColPack
|
00001 /************************************************************************************ 00002 Copyright (C) 2005-2008 Assefaw H. Gebremedhin, Arijit Tarafdar, Duc Nguyen, 00003 Alex Pothen 00004 00005 This file is part of ColPack. 00006 00007 ColPack is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published 00009 by the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ColPack is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with ColPack. If not, see <http://www.gnu.org/licenses/>. 00019 ************************************************************************************/ 00020 00021 #include <string> 00022 00023 #include "Definitions.h" 00024 00025 #include "File.h" 00026 00027 using namespace std; 00028 00029 namespace ColPack 00030 { 00031 File::File() 00032 { 00033 path = ""; 00034 name = ""; 00035 fileExtension = ""; 00036 } 00037 00038 File::File(string fileName) 00039 { 00040 path = ""; 00041 name = ""; 00042 fileExtension = ""; 00043 Parse(fileName); 00044 } 00045 00046 string File::GetPath() const {return path;} 00047 00048 string File::GetName() const {return name;} 00049 00050 string File::GetFileExtension() const {return fileExtension;} 00051 00052 string File::GetFullName() const {return name+"."+fileExtension;} 00053 00054 void File::SetPath(string newPath) {path = newPath;} 00055 00056 void File::SetName(string newName) {name = newName;} 00057 00058 void File::SetFileExtension(string newFileExtension) {fileExtension = newFileExtension;} 00059 00060 void File::Parse(string fileName) { 00061 string::size_type result; 00062 00063 //1. see if the fileName is given in full path 00064 result = fileName.rfind(DIR_SEPARATOR, fileName.size() - 1); 00065 if(result != string::npos) {//found the path (file prefix) 00066 //get the path, including the last DIR_SEPARATOR 00067 path = fileName.substr(0,result+1); 00068 //remove the path from the fileName 00069 fileName = fileName.substr(result+1); 00070 } 00071 00072 //2. see if the fileName has file extension. For example ".mtx" 00073 result = fileName.rfind('.', fileName.size() - 1); 00074 if(result != string::npos) {//found the fileExtension 00075 //get the fileExtension excluding the '.' 00076 fileExtension = fileName.substr(result+1); 00077 //remove the fileExtension from the fileName 00078 fileName = fileName.substr(0,result); 00079 } 00080 00081 //3. get the name of the input file 00082 name = fileName; 00083 } 00084 00085 bool isMatrixMarketFormat(string s_fileExtension) { 00086 if (s_fileExtension == "mtx") 00087 return true; 00088 return false; 00089 } 00090 00091 bool isHarwellBoeingFormat(string s_fileExtension){ 00092 if (s_fileExtension == "hb" || ( 00093 s_fileExtension.size()==3 && ( 00094 // First Character of the Extension 00095 s_fileExtension[0] == 'r' || // Real matrix 00096 s_fileExtension[0] == 'c' || // Complex matrix 00097 s_fileExtension[0] == 'p' // Pattern only (no numerical values supplied) 00098 ) && ( 00099 // Second Character of the Extension 00100 s_fileExtension[1] == 's' || // Symmetric 00101 s_fileExtension[1] == 'u' || // Unsymmetric 00102 s_fileExtension[1] == 'h' || // Hermitian 00103 s_fileExtension[1] == 'g' || // Skew symmetric 00104 s_fileExtension[1] == 'r' // Rectangular 00105 ) && ( 00106 // Third Character of the Extension 00107 s_fileExtension[2] == 'a' || // Assembled 00108 s_fileExtension[2] == 'e' // Elemental matrices (unassembled) 00109 )) 00110 ) 00111 return true; 00112 return false; 00113 } 00114 00115 bool isMeTiSFormat(string s_fileExtension){ 00116 if (s_fileExtension == "graph") 00117 return true; 00118 return false; 00119 } 00120 00121 }