Hello,

I am working with a netcdf file and trying to remove a long string
from it e.g.
"KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH DATA
BLAH DATA BLAH"

Right now what I have works, but takes a long time to run... I think
this could be cut down to a quick 2 second run, but now takes around 5
minutes primarily because of the problem described below...

Why can't I use something like line 9 to get the entire string (which
returns [0], not
["KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH
DATA BLAH DATA BLAH"])? Rather I have to loop through it grabbing one
character at a time which drastically increases the processing time
and is very cumbersome.

Any one have any ideas or suggestions?


0 #OPEN NetCDF FILE TO READ
1                       allDimNames=file.dimensions.keys()
2                      max_string_length=file.dimensions['maxstringLen']
3                       variableNames=file.variables.keys()
4                       globalAttList=dir(file)
5                       globalAttValue=getattr(file,'filePeriod')
6
7#GRABS DATA FROM STRING (2 DIMENSIONAL ARRAY) WITH THE CHARACTERS AS
INDIVIDUAL 8ELEMENTS
9                       #YOU CAN'T JUST SPECIFY DATA VALUES 
DATA[0][0:max_string_length]
10                      data=file.variables['rawstring'].getValue()
11                      num_stations=data.shape
12                      station_id=[str(mz)]
13
14                      for m in station_id:
15                              station_id=m
16                              prec=[]
17                              temps=[]
18
19                              #Cycles through all of the stations in the file 
(LARGE ARRAY!!)
20                              for k in range(num_stations[0]):
21                                      #Finds a certain station
22                                      if data[k][6]=='K' and 
data[k][7]==station_id[0:1] and data[k]
[8]==station_id[1:2] and 23data[k][9]==station_id[2:3] and data[k]
[15]=='5' or data[k][6]=='K' and data[k][7]==station_id[0:1] and
24data[k][8]==station_id[1:2] and data[k][9]==station_id[2:3] and
data[k][15]=='4':
25
26                                                      #SEPARATES STRING 
CHARACTER BY CHARACTER ONLY WAY I'VE 27BEEN
ABLE TO FIGURE OUT HOW TO READ ENTIRE STRING INTO A STRING
28                                                      for j in 
range(max_string_length):
29                                                              
prec.append(str(data[k][j]))
30                                                      S= ''.join(prec)
31              # # #                                   ##THEN RIP OFF THE 
WHITESPACE AT THE RIGHT OF THE
STRING
32                                                      code=S.rstrip("\0")
33

Thanks for any of your help!

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to