Changeset 812 for trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py
- Timestamp:
- Oct 22, 2012, 8:05:55 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py
r811 r812 26 26 from PIL import Image 27 27 28 29 30 ### a function to read HTML arguments for coordinates 31 def gethtmlcoord(userinput,defmin,defmax): 32 # accepted separators 33 separators = [":",";",",","/"] 34 # initial values 35 val = -9999. ; vals = None ; vale = None ; foundinterv = False 36 if userinput == None: userinput = "1" 37 # the main work. either all -- or an interval -- or a single value. 38 if userinput == "all": isfree = 1 ; vals = defmin ; vale = defmax ; foundinterv = True 39 else: 40 for sep in separators: 41 isfree = 1 ; ind = userinput.find(sep) 42 if ind != -1: vals = float(userinput[:ind]) ; vale = float(userinput[ind+1:]) ; foundinterv = True 43 if not foundinterv: isfree = 0 ; val = float(userinput) 44 # return values 45 return isfree, val, vals, vale 46 47 28 48 # for debugging in web browser 29 49 cgitb.enable() … … 36 56 query=mcd.mcd() #FG: import from module mcd 37 57 38 # Get data from user-defined fields and define free dimensions 39 # FG: add tests if var==None to have values in local without forms ones 40 query.lat = -9999. 41 getlat = form.getvalue("latitude") 42 if getlat == None: getlat = "1" 43 if getlat == "all": islatfree = 1 ; query.lats = -90. ; query.late = 90. 44 elif ";" in getlat: islatfree = 1 ; ind = getlat.find(";") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 45 elif "," in getlat: islatfree = 1 ; ind = getlat.find(",") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 46 elif "/" in getlat: islatfree = 1 ; ind = getlat.find("/") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:]) 47 else: islatfree = 0 ; query.lat = float(getlat) 48 49 query.lon = -9999. 50 getlon = form.getvalue("longitude") 51 if getlon == None: getlon = "1" 52 if getlon == "all": islonfree = 1 ; query.lons = -180. ; query.lone = 180. 53 elif ";" in getlon: islonfree = 1 ; ind = getlon.find(";") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 54 elif "," in getlon: islonfree = 1 ; ind = getlon.find(",") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 55 elif "/" in getlon: islonfree = 1 ; ind = getlon.find("/") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:]) 56 else: islonfree = 0 ; query.lon = float(getlon) 57 58 query.loct = -9999. 59 getloct = form.getvalue("localtime") 60 if getloct == None: getloct = "1" 61 if getloct == "all": isloctfree = 1 ; query.locts = 0. ; query.locte = 24. 62 elif ";" in getloct: isloctfree = 1 ; ind = getloct.find(";") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 63 elif "," in getloct: isloctfree = 1 ; ind = getloct.find(",") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 64 elif "/" in getloct: isloctfree = 1 ; ind = getloct.find("/") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:]) 65 else: isloctfree = 0 ; query.loct = float(getloct) 66 58 # Get the kind of vertical coordinates and choose default behavior for "all" 67 59 try: query.zkey = int(form.getvalue("zkey")) 68 60 except: query.zkey = int(3) 69 70 query.xz = -9999. 71 getalt = form.getvalue("altitude") 72 if getalt == None: getalt = "1" 73 if getalt == "all": 74 isaltfree = 1 75 if query.zkey == 2: query.xzs = -5000. ; query.xze = 100000. 76 elif query.zkey == 3: query.xzs = 0. ; query.xze = 120000. 77 elif query.zkey == 5: query.xzs = -5000. ; query.xze = 100000. 78 elif query.zkey == 4: query.xzs = 1000. ; query.xze = 0.001 79 elif query.zkey == 1: query.xzs = 3396000. ; query.xze = 3596000. 80 elif ";" in getalt: isaltfree = 1 ; ind = getalt.find(";") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 81 elif "," in getalt: isaltfree = 1 ; ind = getalt.find(",") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 82 elif "/" in getalt: isaltfree = 1 ; ind = getalt.find("/") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:]) 83 else: isaltfree = 0 ; query.xz = float(getalt) 61 if query.zkey == 2: minxz = -5000. ; maxxz = 100000. 62 elif query.zkey == 3: minxz = 0. ; maxxz = 120000. 63 elif query.zkey == 5: minxz = -5000. ; maxxz = 100000. 64 elif query.zkey == 4: minxz = 1000. ; maxxz = 0.001 65 elif query.zkey == 1: minxz = 3396000. ; maxxz = 3596000. 66 67 # Get data from user-defined fields and define free dimensions 68 islatfree, query.lat, query.lats, query.late = gethtmlcoord( form.getvalue("latitude"), -90., 90. ) 69 islonfree, query.lon, query.lons, query.lone = gethtmlcoord( form.getvalue("longitude"), -180., 180. ) 70 isloctfree, query.loct, query.locts, query.locte = gethtmlcoord( form.getvalue("localtime"), 0., 24. ) 71 isaltfree, query.xz, query.xzs, query.xze = gethtmlcoord( form.getvalue("altitude"), minxz, maxxz) 84 72 85 73 sumfree = islatfree + islonfree + isloctfree + isaltfree … … 143 131 ### getting data 144 132 if isloctfree == 1: query.diurnal(nd=24) 145 elif islonfree == 1: query.zonal( )146 elif islatfree == 1: query.meridional( )147 elif isaltfree == 1: query.profile( )133 elif islonfree == 1: query.zonal(nd=64) 134 elif islatfree == 1: query.meridional(nd=48) 135 elif isaltfree == 1: query.profile(nd=35) 148 136 else: exit() 149 137 … … 184 172 #print "<br />" 185 173 186 print "<a href='../index.html'>Click here to start a new query</a><br />" 174 175 #print "<a href='../index.html'>Click here to start a new query</a><br />" 176 #print "<hr>" 187 177 188 178 ## Now the part which differs … … 191 181 elif sumfree == 1: 192 182 print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />" 183 print "<hr>" 193 184 print "<img src='"+figname+"'><br />" 194 185 else: print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>" … … 230 221 ## Close opend file 231 222 #fo.close() 223
Note: See TracChangeset
for help on using the changeset viewer.