def ncdump_info(f): ''' List of dimensions, variables and attributes from ncdump Works with netcdf files version <= 4 ''' ncdump=cbt.search('ncdump') if ncdump: #try : out=cbt.run(ncdump+' -h '+f+' 2>/dev/null') #except: out=cbt.run(ncdump+' -h '+f) out=cbt.run(ncdump,'-h',f) else: return if not out: res=cbt.odict() res['groups'] = cbt.odict() res['name'] = f res['dimensions'] = cbt.odict() res['variables'] = cbt.odict() res['attributes'] = cbt.odict() else: res=parse_once(out,True) return res
def ncdump_info(f): ''' List of dimensions, variables and attributes from ncdump Works with netcdf files version <= 4 ''' ncdump = cbt.search('ncdump') if ncdump: #try : out=cbt.run(ncdump+' -h '+f+' 2>/dev/null') #except: out=cbt.run(ncdump+' -h '+f) out = cbt.run(ncdump, '-h', f) else: return if not out: res = cbt.odict() res['groups'] = cbt.odict() res['name'] = f res['dimensions'] = cbt.odict() res['variables'] = cbt.odict() res['attributes'] = cbt.odict() else: res = parse_once(out, True) return res
def ncdump_info3(f): ''' List of dimensions, variables and attributes from ncdump Works with netcdf files version < 4 ''' ncdump = cbt.search('ncdump') if ncdump: #try : out=cbt.run(ncdump+' -h '+f+' 2>/dev/null') #except: out=cbt.run(ncdump+' -h '+f) out = cbt.run(ncdump, '-h', f) else: return dims = [] vars = [] varatts = {} atts = [] i1 = i2 = i3 = -1 hasdims = hasvars = hasatts = False if len(out) > 1: i1 = i2 = i3 = -1 for n in range(len(out)): if out[n].find('dimensions') == 0: i1 = n + 1 if out[n].find('variables') == 0: i2 = n + 1 if out[n].find('// global attributes') == 0: i3 = n + 1 if i1 != -1: hasdims = True if hasdims: if i2 == -1: i2 = i3 - 1 if i3 == -1: i2 = len(out) - 1 if i2 != -1: hasvars = True if hasvars: if i3 == -1: i3 = len(out) - 1 if i3 != -1: hasatts = True if hasdims: for i in range(i1, i2 - 1): dims += [out[i].split('=')[0].strip()] if hasvars: for i in range(i2, i3 - 2): if out[i].find('=') == -1: vars += [out[i][:-2].strip().split()[1].split('(')[0]] varatts[vars[-1]] = [] else: name = out[i].split(':')[0].strip() vatt = out[i].split(':')[1].split('=')[0].strip() varatts[name] += [vatt] if hasatts: for i in range(i3, len(out) - 1): s = out[i] if s.strip()[0] == ':': atts += [s[s.index(':') + 1:s.index('=')].strip()] return { 'dimensions': dims, 'variables': vars, 'attributes': atts, 'vattributes': varatts }
def ncdump_info3(f): ''' List of dimensions, variables and attributes from ncdump Works with netcdf files version < 4 ''' ncdump=cbt.search('ncdump') if ncdump: #try : out=cbt.run(ncdump+' -h '+f+' 2>/dev/null') #except: out=cbt.run(ncdump+' -h '+f) out=cbt.run(ncdump,'-h',f) else: return dims=[] vars=[] varatts={} atts=[] i1=i2=i3=-1; hasdims=hasvars=hasatts=False if len(out)>1: i1=i2=i3=-1; for n in range(len(out)): if out[n].find('dimensions')==0: i1=n+1 if out[n].find('variables')==0: i2=n+1 if out[n].find('// global attributes')==0: i3=n+1 if i1!=-1: hasdims=True if hasdims: if i2==-1: i2=i3-1 if i3==-1: i2=len(out)-1 if i2!=-1: hasvars=True if hasvars: if i3==-1: i3=len(out)-1 if i3!=-1: hasatts=True if hasdims: for i in range(i1,i2-1): dims+=[out[i].split('=')[0].strip()] if hasvars: for i in range(i2,i3-2): if out[i].find('=')==-1: vars+=[out[i][:-2].strip().split()[1].split('(')[0]] varatts[vars[-1]]=[] else: name=out[i].split(':')[0].strip() vatt=out[i].split(':')[1].split('=')[0].strip() varatts[name]+=[vatt] if hasatts: for i in range(i3,len(out)-1): s=out[i] if s.strip()[0]==':': atts+=[s[s.index(':')+1:s.index('=')].strip()] return {'dimensions':dims,'variables':vars,'attributes':atts,'vattributes':varatts}