| 1 |
// for gestion of FreeFem++ argument and in version 3.10-1 FH |
| 2 |
// F. Hecht |
| 3 |
// Usage: getARGV(n,defaultvalue) // get the fist used default valeu |
| 4 |
// or getARGV(after,defaultvalue) // get the arg after after |
| 5 |
// the type of delfaut value given the return type: int,double, string |
| 6 |
// Modif version 3.54-2 Jan 2018 (add ones include) |
| 7 |
IFMACRO(!getARGVidp) |
| 8 |
NewMacro getARGVidp 1 EndMacro |
| 9 |
/* Warning the // comment do not work if some windows macro F. Hecht |
| 10 |
no end !!! */ |
| 11 |
func int usedARGV(int n) |
| 12 |
{ |
| 13 |
int k=1,ii=1,kk=1,ret=-1; |
| 14 |
for(int i=1;i<ARGV.n;++i) |
| 15 |
{ |
| 16 |
/* cout <<i<< " "<< ARGV[i] << " " <<(ARGV[i]=="-v") << " " << kk << "==" |
| 17 |
<< n << " " << ARGV[i].rfind("dp") << " " <<ARGV[i].length-2 << endl;*/ |
| 18 |
if(ARGV[i]=="-v") i++; |
| 19 |
else if(ARGV[i]=="-fglut") i++; |
| 20 |
else if(ARGV[i]=="-ffg") i++; |
| 21 |
else if(ARGV[i]=="-glut") i++; |
| 22 |
else if(ARGV[i]=="-f") i++; |
| 23 |
else if(ARGV[i]=="-nw") ii; |
| 24 |
else if(ARGV[i]=="-wait") ii; |
| 25 |
else if(ARGV[i]=="-ne") ii; |
| 26 |
else if(ARGV[i]=="-cd") ii; |
| 27 |
/*else if(ARGV[i].rfind(".edp")==ARGV[i].length-4 ) ii;*/ |
| 28 |
else if(i==1) ii; |
| 29 |
else if(kk++==n) {ret=i;} |
| 30 |
/* else cout << " +++ \n";*/ |
| 31 |
} |
| 32 |
/* cout << ret << endl;*/ |
| 33 |
return ret; |
| 34 |
} |
| 35 |
|
| 36 |
func int usedARGV(string after) |
| 37 |
{ |
| 38 |
int ret=-1; |
| 39 |
for(int i=ARGV.n-1;i>=0;--i) |
| 40 |
if(ARGV[i]==after) { ret=++i; break;} |
| 41 |
if(ARGV.n<ret) ret=-1; |
| 42 |
return ret; |
| 43 |
} |
| 44 |
|
| 45 |
func int getARGV(int n,int default) |
| 46 |
{ |
| 47 |
int d=default; |
| 48 |
int k=usedARGV(n); |
| 49 |
if(k>0) d=strtol(ARGV[k]); |
| 50 |
return d; |
| 51 |
} |
| 52 |
func real getARGV(int n,real default) |
| 53 |
{ |
| 54 |
real d=default; |
| 55 |
int k=usedARGV(n); |
| 56 |
if(k>0) d=strtod(ARGV[k]); |
| 57 |
return d; |
| 58 |
} |
| 59 |
func string getARGV(int n,string default) |
| 60 |
{ |
| 61 |
string d=default; |
| 62 |
int k=usedARGV(n); |
| 63 |
if(k>0) d=ARGV[k]; |
| 64 |
return d; |
| 65 |
} |
| 66 |
|
| 67 |
func int getARGV(string after,int default) |
| 68 |
{ |
| 69 |
int d=default; |
| 70 |
int k=usedARGV(after); |
| 71 |
if(k>0) d=strtol(ARGV[k]); |
| 72 |
return d; |
| 73 |
} |
| 74 |
func real getARGV(string after,real default) |
| 75 |
{ |
| 76 |
real d=default; |
| 77 |
int k=usedARGV(after); |
| 78 |
if(k>0) d=strtod(ARGV[k]); |
| 79 |
return d; |
| 80 |
} |
| 81 |
func string getARGV(string after,string default) |
| 82 |
{ |
| 83 |
string d=default; |
| 84 |
int k=usedARGV(after); |
| 85 |
if(k>0) d=ARGV[k]; |
| 86 |
return d; |
| 87 |
} |
| 88 |
|
| 89 |
/* |
| 90 |
cout << getARGV(1,100) << endl; |
| 91 |
cout << getARGV(2,200.) << endl; |
| 92 |
cout << getARGV(3,"300.000") << endl; |
| 93 |
cout << getARGV("-n"," xxx") << endl; |
| 94 |
*/ |
| 95 |
ENDIFMACRO |
| 96 |
// |