source: trunk/UTIL/PYTHON/mcd/examples/test_mcd.py @ 1007

Last change on this file since 1007 was 943, checked in by aslmd, 12 years ago

clean and organized UTIL/PYTHON folder

  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#! /usr/bin/env python
2
3# This python program illustrates how the Mars Climate Database
4# fortran routines can be called interactively from python
5
6from fmcd import call_mcd,julian
7import numpy as np
8
9# 1. Inputs:
10dset = '' # default to 'MCD_DATA'
11perturkey = 1 # default to no perturbation
12seedin = 0 # perturbation seed (unused if perturkey=1)
13gwlength = 0 # Gravity Wave length for perturbations (unused if perturkey=1)
14
15# 1.1 Dates
16choice_date=raw_input('Use Earth date (e) or Mars date (m)?')
17if (choice_date == "e") :
18  datekey=0 # Earth date
19  loct=0 # local time must then also be set to zero
20  day,month,year,hour,minute,second = \
21  raw_input("Enter date: day/month/year/hour/minute/second: ").split('/')
22  day=int(day)
23  month=int(month)
24  year=int(year)
25  hour=int(hour)
26  minute=int(minute)
27  second=int(second)
28  # now call Julian routine to convert to julian date
29  (ier,xdate)=julian(month,day,year,hour,minute,second)
30  print " Julian date %16.8f" % xdate
31else :
32  datekey=1 # Mars date
33  xdate=float(raw_input("Enter solar longitude Ls (deg.):"))
34  loct=float(raw_input("Local time (0 < time < 24)?"))
35
36# 1.2 Vertical coordinate
37zkey=int(raw_input("Select verical coordinate type (1: distance to center of planet, 2: height above areoid, 3: height above surface, 4: Pressure) "))
38if (zkey == 1) :
39  xz=float(raw_input("Enter distance to planet center (m) "))
40if (zkey == 2) :
41  xz=float(raw_input("Enter altitude above areoid (m) "))
42if (zkey == 3) :
43  xz=float(raw_input("Enter altitude above surface (m) "))
44if (zkey == 4) :
45  xz=float(raw_input("Enter pressure value (Pa) "))
46
47# high resolution mode
48hrkey=int(raw_input("High resolution? (1: yes, 0: no) "))
49
50# 1.3 Position
51lat = float(raw_input('Latitude (deg)?'))
52lon = float(raw_input('Longitude (deg)?'))
53
54# 1.4 Dust and solar scenario
55print "Dust scenario?"
56print "1= Climatology       typical Mars year dust scenario"
57print "                     average solar EUV conditions"
58print "2= Climatology       typical Mars year dust scenario"
59print "                     minimum solar EUV conditions"
60print "3= Climatology       typical Mars year dust scenario"
61print "                     maximum solar EUV conditions"
62print "4= dust storm        constant dust opacity = 5 (dark dust)"
63print "                     minimum solar EUV conditions"
64print "5= dust storm        constant dust opacity = 5 (dark dust)"
65print "                     average solar EUV conditions"
66print "6= dust storm        constant dust opacity = 5 (dark dust)"
67print "                     maximum solar EUV conditions"
68print "7= warm scenario     dustier than Climatology scenario"
69print "                     maximum solar EUV conditions"
70print "8= cold scenario     clearer than Climatology scenario"
71print "                     minimum solar EUV conditions"
72dust=int(raw_input(''))
73
74# 1.5 perturbations
75perturkey=int(raw_input("Perturbation? (1:none, 2: large scale, 3: small scale, 4: small+large, 5: n sigmas) "))
76if (perturkey > 1) :
77  seedin=int(raw_input("seedin? (only matters if adding perturbations) "))
78if ((perturkey == 3) or (perturkey == 4)) :
79  gwlength=float(raw_input("Gravity wave length? (for small scale perturbations) "))
80
81# 1.6 extra outputs
82# here we only implement an all-or-nothing case
83extvarkey=int(raw_input("Output the extra variables? (yes==1; no==0) "))
84if (extvarkey == 0) :
85  extvarkeys = np.zeros(100)
86else :
87  extvarkeys = np.ones(100)
88
89# 2. Call MCD
90(pres, dens, temp, zonwind, merwind, \
91 meanvar, extvar, seedout, ierr) \
92 = \
93call_mcd(zkey,xz,lon,lat,hrkey, \
94 datekey,xdate,loct,dset,dust, \
95 perturkey,seedin,gwlength,extvarkeys )
96
97# 3. Write outputs
98print "temperature is %.0f K, pressure is %.0f Pa, density is %5.3e kg/m3, zonal wind is %.1f m/s, meridional wind is %.1f m/s" % (temp,pres,dens,zonwind,merwind)
99
Note: See TracBrowser for help on using the repository browser.