Changeset 986 in lmdz_wrf for trunk/tools/generic_tools.py
- Timestamp:
- Aug 9, 2016, 12:40:25 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r985 r986 37 37 # dictionary_key_list: Function to provide the first key in a dictionay of lists with a given value 38 38 # files_folder_HMT: Function to retrieve a list of files from a folder [fold] and files with [head]*[middle]*[tail] 39 # get_configuration: Function to get the configuration from an ASCII external file 39 40 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box 40 41 # incomming_flow: Function to determine if a fgrid-flow inflows to the central grid point … … 8072 8073 return newdatev, newtunits 8073 8074 8075 def get_configuration(configfile,glob): 8076 """ Function to get the configuration from an ASCII external file with [arg] = [value] 8077 returned as a dictionay as configuration[arg] = [value] 8078 '#' for comentaries in the ASCII file 8079 configfile= ASCII file to read 8080 glob= do we want vairables as global ones? (True/False) 8081 """ 8082 fname = 'get_configuration' 8083 8084 if not os.path.isfile(configfile): 8085 print errormsg 8086 print ' ' + fmsg + ': configuratio file "' + filen + '" does not exist !!' 8087 quit(-1) 8088 8089 of = open(configfile, 'r') 8090 8091 config = {} 8092 for line in of: 8093 if line[0:1] != '#' and len(line) > 1: 8094 arg = line.replace('\n','').split('=')[0].replace(' ','') 8095 val = line.replace('\n','').split('=')[1].replace(' ','') 8096 config[arg] = val 8097 # From: http://stackoverflow.com/questions/11553721/using-a-string-variable-as-a-variable-name 8098 #exec( "pyHOME = '" + conf['pyHOME'] + "'") 8099 8100 # From: http://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables-in-python 8101 if glob: globals()[arg] = val 8102 8103 return config 8104 8105 #conf = get_configuration('model_graphics.dat',False) 8106 #print pyHOME 8107 8074 8108 #quit() 8075 8109
Note: See TracChangeset
for help on using the changeset viewer.