Changeset 565 in lmdz_wrf for trunk/tools
- Timestamp:
- Jul 6, 2015, 1:28:00 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r557 r565 16307 16307 #TimeSplitmat(fileobj, 'time', 'time', 'all', 'd,H') 16308 16308 16309 #quit() 16309 def rmNOnum(string): 16310 """ Removing from a string all that characters which are not numbers 16311 # From: http://stackoverflow.com/questions/4289331/python-extract-numbers-from-a-string 16312 """ 16313 fname = 'rmNOnum' 16314 16315 newstr = str(re.findall("[-+]?\d+[\.]?\d*", string)[0]) 16316 16317 return newstr 16318 16319 def values_fortran_fmt(lin,fFMT): 16320 """ Function to give back the values of an ASCII line according to its fortran printing format 16321 lin= ASCII line 16322 fFMT= list with the fortran FORMAT formats 16323 forline = 'Natchitoches (RGNL) 1 11 0011 ( 31.733, -93.100) ( 28, 157) ( 31.761, -93.113) 41.2 meters' 16324 formats = ['A26', 'I2', 'I3', 'A6', 'A2', 'F7.3', 'A1', 'F8.3', 'A3', 'I4', 'A1', 'I4', 16325 'A3', 'F7.3', 'A1', 'F8.3', 'A2', 'F6.1', 'A7'] 16326 >>> values_fortran_fmt(forline, formats) 16327 ['Natchitoches (RGNL) ', 1, 11, ' 0011 ', ' ( ', 31.733, ', ', -93.1, ') ( ', 28, ', ', 157, ') 16328 ( ', 31.761, ', ', -93.113, ') ', 41.2, ' meters'] 16329 """ 16330 fname = 'values_fortran_fmt' 16331 16332 afmts = ['A', 'D', 'F', 'I'] 16333 16334 if lin == 'h': 16335 print fname + '_____________________________________________________________' 16336 print values_fortran_fmt.__doc__ 16337 quit() 16338 16339 fvalues = [] 16340 ichar=0 16341 ival = 0 16342 for ft in formats: 16343 Lft = len(ft) 16344 print ft, Lft 16345 16346 if ft[0:1] == 'A' or ft[0:1] == 'a': 16347 Lfmt = int(ft[1:Lft+1]) 16348 fvalues.append(lin[ichar:ichar+Lfmt+1]) 16349 ichar = ichar + Lfmt 16350 elif ft[0:1] == 'F' or ft[0:1] == 'f': 16351 if ft.find('.') != -1: 16352 Lft = len(ft.split('.')[0]) 16353 Lfmt = int(ft[1:Lft]) 16354 fvalues.append(np.float(rmNOnum(lin[ichar:ichar+Lfmt+1]))) 16355 ichar = ichar + Lfmt 16356 elif ft[0:1] == 'D' or ft[0:1] == 'd': 16357 if ft.find('.') != -1: 16358 Lft = len(ft.split('.')[0]) 16359 Lfmt = int(ft[1:Lft]) 16360 fvalues.append(np.float64(rmNOnum(lin[ichar:ichar+Lfmt+1]))) 16361 ichar = ichar + Lfmt 16362 elif ft[0:1] == 'I' or ft[0:1] == 'i': 16363 Lfmt = int(ft[1:Lft+1]) 16364 fvalues.append(int(rmNOnum(lin[ichar:ichar+Lfmt+1]))) 16365 ichar = ichar + Lfmt 16366 elif ft.find('X') != -1 or ft.find('x') != -1: 16367 print ' ' + fname + ': skipping space' 16368 ichar = ichar + len(ft) 16369 else: 16370 print errormsg 16371 print ' ' + fname + ": format '" + ft[0:1] + "' not ready!!" 16372 print ' Available formats:',afmts 16373 quit(-1) 16374 16375 print ' ', ichar, fvalues[ival-1] 16376 ival = ival + 1 16377 16378 print fvalues 16379 16380 return fvalues 16381 16382 forline = 'Natchitoches (RGNL) 1 11 0011 ( 31.733, -93.100) ( 28, 157) ( 31.761, -93.113) 41.2 meters' 16383 formats = ['A26', 'I2', 'I3', 'A6', 'A2', 'F7.3', 'A1', 'F8.3', 'A3', 'I4', 'A1', 'I4', \ 16384 'A3', 'F7.3', 'A1', 'F8.3', 'A2', 'F6.1', 'A7'] 16385 16386 values_fortran_fmt(forline, formats) 16387 16388 quit() 16310 16389 16311 16390 """operation to make:
Note: See TracChangeset
for help on using the changeset viewer.