00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 string tostring(int k) {
00014 char buf[128];
00015 sprintf(buf,"%.5i",k);
00016 return string(buf);
00017 }
00018
00019 vector<string> glob(string pattern) {
00020 vector<string> v;
00021 glob_t pglob;
00022 pglob.gl_offs=2;
00023 if(glob(pattern.c_str(),0,0,&pglob)!=0) v.push_back("?");
00024 else
00025 for(int i=0; i<pglob.gl_pathc; i++)
00026 v.push_back(string(pglob.gl_pathv[i]));
00027 globfree(&pglob);
00028 return v;
00029 }
00030
00031 string latest_file(string pattern) {
00032 vector<string> v=glob(pattern);
00033 return v[v.size()-1];
00034 }
00035
00036
00037 string next_to_latest_file(string pattern) {
00038 int i=pattern.find("*");
00039 if(i<0) return pattern;
00040 vector<string> v=glob(pattern);
00041 string latest=v[v.size()-1];
00042 if(latest=="?") return pattern.replace(i,1,tostring(0));
00043 int k;
00044 latest=latest.substr(i,5);
00045 k=atoi(latest.c_str());
00046 k++;
00047 return pattern.replace(i,1,tostring(k).c_str());
00048 }
00049
00050
00051 string tostring(float k) {
00052 char buf[128];
00053 sprintf(buf,"%f",k);
00054 return string(buf);
00055 }
00056
00057 int is_file(string filename, char permission[]="r") {
00058 FILE *fp=fopen(filename.c_str(), permission);
00059 if(fp>0) {
00060 fclose(fp);
00061 return true;
00062 }
00063 return false;
00064 }
00065
00066 mdp_field_file_header get_info(string filename, int proc=0) {
00067 mdp_field_file_header myheader;
00068 if(ME==proc) {
00069 FILE *fp=fopen(filename.c_str(), "r");
00070 if(fp==0) error("Unable to open file");
00071 fread(&myheader, sizeof(char),
00072 sizeof(mdp_field_file_header)/sizeof(char), fp);
00073 switch_header_endianess(myheader);
00074 fclose(fp);
00075 }
00076 mpi.broadcast(myheader,proc);
00077 return myheader;
00078 }
00079
00080 int mail(string email, string message) {
00081 string s;
00082 static int ret;
00083 if(ME==0) {
00084 s = "echo '"+message+"' | mail -s 'MDP MESSAGE' " +email;
00085 ret=system(s.c_str());
00086 }
00087 mpi.broadcast(ret,0);
00088 return ret;
00089 }
00090
00091 int mail_file(string email, string filename) {
00092 string s;
00093 static int ret;
00094 if(ME==0) {
00095 s = "more "+filename+" | mail -s 'MDP MESSAGE' "+email;
00096 ret=system(s.c_str());
00097 }
00098 mpi.broadcast(ret,0);
00099 return ret;
00100 }
00101
00102
00103
00104
00105