Hello everybody,
I'm new to python and I'm trying to build up a script...
When I run the script the only commands that are executed are
cmdargs1= ["elevation=%s" %dtm]
cmdargs2=["slope=slope1", "format=percent", "--overwrite"]
os.execvp("r.slope.aspect", ["r.slope.aspect"] + cmdargs1 + cmdargs2)
The other commands are ignored...What can be the issue?
thanks,
Monia
------------------------
Here is my script:
-----------------------
#!/usr/bin/python
# -*- coding:utf-8 -*-
#%Module
#% description:
#% keywords: keyword1, keyword2
#%End
#%option
#% key: dtm
#% type: string
#% gisprompt: old,cell,raster
#% description: Modello Digitale del Terreno
#% required : yes
#%end
#%option
#% key: h
#% type: double
#% description: Profondità del mare in prossimità della costa h
#% required : yes
#%end
#%option
#% key: ho
#% type: double
#% description: Profondità del mare in corrispondenza dell'epicentro
#% required : yes
#%end
#%option
#% key: Ho
#% type: double
#% description: Altezza d'onda nel punto di generazione dello tsunami
#% required : yes
#%end
import os,sys,subprocess,string,random,math
def main():
#### add your code here ####
print ""
print "Value of GIS_OPT_h: %s" % os.getenv("GIS_OPT_h")
print "Value of GIS_OPT_ho: %s" % os.getenv("GIS_OPT_ho")
print "Value of GIS_OPT_Ho: %s" % os.getenv("GIS_OPT_Ho")
print "Name of GIS_OPT_dtm: %s" % os.getenv("GIS_OPT_dtm")
h = float(os.getenv('GIS_OPT_h'))
ho = float(os.getenv('GIS_OPT_ho'))
Ho = float(os.getenv('GIS_OPT_Ho'))
dtm = os.getenv('GIS_OPT_dtm')
Co=math.sqrt(9.8 * h)
print "Celerità dell'onda=",Co
H= Ho * ((ho/h)**(0.25))
print "Altezza d'onda a riva=",H
U=Co * math.sqrt((1+H/h))
print "Velocità d'onda a riva=",U
L= 4 * 2.415 *h /(math.sqrt(3*H/h))
print "Lunghezza di un'onda solitaria=",L
k1=U**2 * L/(19.6)
print "k1=",k1
k2= U**2 * H/(39.2)
print "k2=",k2
cmdargs1= ["elevation=%s" %dtm]
cmdargs2=["slope=slope1", "format=percent", "--overwrite"]
os.execvp("r.slope.aspect", ["r.slope.aspect"] + cmdargs1 + cmdargs2)
cmdargs3=["input=slope1", "output=slope_prova1", "method=average", "size=9"]
os.execvp("r.neighbors",["r.neighbors"] + cmdargs3)
#### end of your code ####
return
if __name__ == "__main__":
if ( len(sys.argv) <= 1 or sys.argv[1] != "@ARGS_PARSED@" ):
os.execvp("g.parser", [sys.argv[0]] + sys.argv)
else:
main();