diff --git a/stim/math/matrix.h b/stim/math/matrix.h index 0aca681..4c3977f 100644 --- a/stim/math/matrix.h +++ b/stim/math/matrix.h @@ -21,7 +21,7 @@ namespace stim{ mat4_float //floating point type, determined automatically }; - size_t mat4Format_size(mat4Format f){ + static size_t mat4Format_size(mat4Format f){ switch(f){ case mat4_float64: return 8; case mat4_float32: @@ -33,7 +33,7 @@ namespace stim{ } } - void save_mat4(char* data, std::string filename, std::string varname, size_t sx, size_t sy, mat4Format format){ + static void save_mat4(char* data, std::string filename, std::string varname, size_t sx, size_t sy, mat4Format format){ //save the matrix file here (use the mat4 function above) //data format: https://maxwell.ict.griffith.edu.au/spl/matlab-page/matfile_format.pdf (page 32) @@ -43,11 +43,11 @@ namespace stim{ int p = format; int t = 0; MOPT = m * 1000 + o * 100 + p * 10 + t; //calculate the type value - int mrows = sx; - int ncols = sy; + int mrows = (int)sx; + int ncols = (int)sy; int imagf = 0; //assume real (for now) varname.push_back('\0'); //add a null to the string - int namlen = varname.size(); //calculate the name size + int namlen = (int)varname.size(); //calculate the name size size_t bytes = sx * sy * mat4Format_size(format); std::ofstream outfile(filename, std::ios::binary); @@ -59,7 +59,6 @@ namespace stim{ outfile.write((char*)&varname[0], namlen); outfile.write((char*)data, bytes); //write the matrix data outfile.close(); - } template @@ -421,35 +420,6 @@ public: } } stim::save_mat4((char*)M, filename, name, rows(), cols(), format); - /*int MOPT = 0; //initialize the MOPT type value to zero - int m = 0; //little endian - int o = 0; //reserved, always 0 - int p = mat4_float; - if (mat4_float) { - if (sizeof(T) == 4) p = mat4_float32; - else if (sizeof(T) == 8) p = mat4_float64; - else { - std::cout << "stim::matrix ERROR - incorrect format specified" << std::endl; - exit(1); - } - } - int t = 0; - MOPT = m * 1000 + o * 100 + p * 10 + t; //calculate the type value - int mrows = rows(); - int ncols = cols(); - int imagf = 0; //assume real (for now) - name += "\0"; //add a null to the string - int namlen = name.size(); //calculate the name size - - std::ofstream outfile(filename, std::ios::binary); - outfile.write((char*)&MOPT, 4); - outfile.write((char*)&mrows, 4); - outfile.write((char*)&ncols, 4); - outfile.write((char*)&imagf, 4); - outfile.write((char*)&namlen, 4); - outfile.write((char*)&name[0], namlen); - outfile.write((char*)M, bytes()); //write the matrix data - outfile.close();*/ } }; diff --git a/stim/parser/filename.h b/stim/parser/filename.h index 9987c22..c3573c2 100644 --- a/stim/parser/filename.h +++ b/stim/parser/filename.h @@ -65,44 +65,46 @@ protected: std::string current_drive; std::vector current_dir; parse_path(current_drive, current_dir, current); //get the current drive and directories + if (current_dir.size() > 0) { + + // step through each directory in the relative path, adjusting the current directory + // index depending on whether the relative path is specified with '.' or '..' + int current_i = (int)current_dir.size() - 1; + int relative_i; + for (relative_i = 0; relative_i < relative.size(); relative_i++) { + if (relative[relative_i] == "..") current_i--; + else if (relative[relative_i] != ".") break; + } + if (current_i < 0) { + std::cerr << "ERROR stim::filepath - relative path is incompatible with working directory" << std::endl; + exit(1); + } - // step through each directory in the relative path, adjusting the current directory - // index depending on whether the relative path is specified with '.' or '..' - int current_i = (int)current_dir.size() - 1; - int relative_i; - for(relative_i = 0; relative_i < relative.size(); relative_i++){ - if(relative[relative_i] == "..") current_i--; - else if(relative[relative_i] != ".") break; - } - if(current_i < 0){ - std::cerr<<"ERROR stim::filepath - relative path is incompatible with working directory"< &absolute, std::string dir){ - drive = ""; //initialize the drive to NULL (it will stay that way for Windows) + drive = ""; //initialize the drive to NULL (it will stay that way for Windows) std::vector path; - bool relative = true; //the default path is relative + bool relative = true; //the default path is relative - if(dir.length() == 0) return; //return if the file locator is empty + if(dir.length() == 0) return; //return if the file locator is empty std::string unix_dir = unix_div(dir); //replace any Windows division characters with Unix if(unix_dir.length() > 1 && unix_dir[1] == ':'){ //if a drive identifier is given if(unix_dir[0] > 64 && unix_dir[0] < 91) //if the drive letter is upper case - _drive = unix_dir[0] + 32; //convert it to lower case + drive = unix_dir[0] + 32; //convert it to lower case else if(unix_dir[0] > 96 && unix_dir[0] < 123) //if the drive character is lower case - _drive = unix_dir[0]; //store it as-is + drive = unix_dir[0]; //store it as-is else{ //otherwise throw an error std::cerr<<"ERROR stim::filename - drive letter is invalid: "< 0){ //if there is a directory specified, remove surrounding slashes - if(unix_dir[0] == '/'){ //if there is a leading slash + if (unix_dir.size() > 0) { //if there is a directory specified, remove surrounding slashes + if (unix_dir[0] == '/') { //if there is a leading slash relative = false; //the path is not relative unix_dir = unix_dir.substr(1, unix_dir.length() - 1); //remove the slash } + } + if(unix_dir.size() > 0){ if(unix_dir[unix_dir.size()-1] == '/') unix_dir = unix_dir.substr(0, unix_dir.length() - 1); } @@ -266,6 +270,13 @@ public: return result; } + std::string fname(){ + std::string result = prefix(); + result += "."; + result += extension(); + return result; + } + /// create a matching file locator with the path changed to s stim::filename path(std::string s){ stim::filename result = *this; -- libgit2 0.21.4