Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sepin.C
Go to the documentation of this file.
1 #include <unistd.h>
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <cassert>
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 #include <iomanip>
11 
12 std::string
13 CWD()
14 {
15  char buf[1024];
16  return(std::string(getcwd(buf,1024)));
17 }
18 
19 int
20 ChangeDirectory(const std::string &path)
21 {
22  return(chdir(path.c_str()));
23 }
24 
25 int
26 CreateDirectory(const std::string &fname)
27 {
28  return(mkdir(fname.c_str(),S_IRGRP | S_IXGRP | S_IRWXU));
29 }
30 
31 bool
32 FILEEXISTS(const std::string &fname)
33 {
34  struct stat fstat;
35  if(lstat(fname.c_str(),&fstat))
36  return false;
37  return true;
38 }
39 
40 int main(int argc,char *argv[])
41 {
42  if(argc < 2)
43  return 1;
44  std::string numproc_s(argv[1]);
45  std::istringstream Istr(numproc_s);
46  std::ofstream RocinSurfFile;
47  std::ofstream RocinVolFile;
48  std::ifstream OrigSurfFile;
49  std::ifstream OrigVolFile;
50  OrigSurfFile.open("ifluid_in_00.000000.txt");
51  OrigVolFile.open("fluid_in_00.000000.txt");
52  std::string surfpanes;
53  std::string surffiles;
54  std::string volpanes;
55  std::string volfiles;
56  std::string junk;
57  OrigSurfFile >> junk >> junk >> junk
58  >> surffiles >> junk;
59  std::getline(OrigSurfFile,surfpanes);
60  OrigVolFile >> junk >> junk >> junk
61  >> volfiles >> junk;
62  std::getline(OrigVolFile,volpanes);
63  OrigSurfFile.close();
64  OrigVolFile.close();
65  rename("ifluid_in_00.000000.txt","ifluid_in_00.000000.txt.orig");
66  rename("fluid_in_00.000000.txt","fluid_in_00.000000.txt.orig");
67  RocinSurfFile.open("ifluid_in_00.000000.txt");
68  RocinVolFile.open("fluid_in_00.000000.txt");
69  int np = 0;
70  Istr >> np;
71  for(int i = 0; i < np; i++){
72  RocinSurfFile << "@Proc: " << i << std::endl;
73  RocinVolFile << "@Proc: " << i << std::endl;
74  int fileid = i+1;
75  std::ostringstream Ostr;
76  std::ostringstream Ostr2;
77  Ostr2 << i;
78  int nchar = Ostr2.str().length();
79  nchar = 4 - nchar;
80  while(nchar--)
81  Ostr << "0";
82  Ostr << Ostr2.str();
83  RocinSurfFile << "@Files: " << Ostr.str() << "/" << surffiles << std::endl
84  << "@Panes: " << surfpanes << std::endl << std::endl;
85  RocinVolFile << "@Files: " << Ostr.str() << "/" << volfiles << std::endl
86  << "@Panes: " << volpanes << std::endl << std::endl;
87  CreateDirectory(Ostr.str());
88  ChangeDirectory(Ostr.str());
89  Ostr2.clear();
90  Ostr2.str("");
91  Ostr2 << fileid;
92  nchar = 5 - Ostr2.str().length();
93  Ostr.clear();
94  Ostr.str("");
95  while(nchar--)
96  Ostr << "0";
97  Ostr << fileid;
98  std::ostringstream FNout;
99  std::ostringstream FNout2;
100  FNout << "fluid_" << Ostr.str() << ".hdf";
101  FNout2 << "../fluid_" << Ostr.str() << ".hdf";
102  symlink(FNout2.str().c_str(),FNout.str().c_str());
103  FNout.clear();
104  FNout2.clear();
105  FNout.str("");
106  FNout2.str("");
107  FNout << "ifluid_" << Ostr.str() << ".hdf";
108  FNout2 << "../ifluid_" << Ostr.str() << ".hdf";
109  if(FILEEXISTS(FNout2.str()))
110  symlink(FNout2.str().c_str(),FNout.str().c_str());
111  ChangeDirectory(std::string(".."));
112  }
113  RocinSurfFile.close();
114  RocinVolFile.close();
115  return 0;
116 }
bool FILEEXISTS(const std::string &fname)
Definition: sepin.C:32
blockLoc i
Definition: read.cpp:79
int ChangeDirectory(const std::string &path)
Definition: sepin.C:20
int main(int argc, char *argv[])
Definition: blastest.C:94
std::string CWD()
Definition: Rocin.C:2762
int CreateDirectory(const std::string &fname)
Definition: sepin.C:26