<s> from __future__ import print_function <EOL> import sys <EOL> import numpy as np <EOL> from numpy import ma <EOL> import warnings <EOL> import getopt <EOL> import os <EOL> python3 = sys . version_info [ <NUM_LIT:0> ] > <NUM_LIT:2> <EOL> if python3 : <EOL> unicode = str <EOL> else : <EOL> range = xrange <EOL> try : <EOL> bytes <EOL> except NameError : <EOL> bytes = str <EOL> def _sortbylist ( A , B ) : <EOL> return [ A [ i ] for i in sorted ( range ( len ( A ) ) , key = B . __getitem__ ) ] <EOL> def _find_dim ( grp , dimname ) : <EOL> group = grp <EOL> dim = None <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> dim = group . dimensions [ dimname ] <EOL> break <EOL> except : <EOL> try : <EOL> group = group . parent <EOL> except : <EOL> raise ValueError ( "<STR_LIT>" % dimname ) <EOL> return dim <EOL> def _walk_grps ( topgrp ) : <EOL> """<STR_LIT>""" <EOL> grps = topgrp . groups . values ( ) <EOL> yield grps <EOL> for grp in topgrp . groups . values ( ) : <EOL> for children in _walk_grps ( grp ) : <EOL> yield children <EOL> def _quantize ( data , least_significant_digit ) : <EOL> """<STR_LIT>""" <EOL> precision = pow ( <NUM_LIT> , - least_significant_digit ) <EOL> exp = np . log10 ( precision ) <EOL> if exp < <NUM_LIT:0> : <EOL> exp = int ( np . floor ( exp ) ) <EOL> else : <EOL> exp = int ( np . ceil ( exp ) ) <EOL> bits = np . ceil ( np . log2 ( pow ( <NUM_LIT> , - exp ) ) ) <EOL> scale = pow ( <NUM_LIT> , bits ) <EOL> datout = np . around ( scale * data ) / scale <EOL> if ma . isMA ( datout ) : <EOL> datout . set_fill_value ( data . fill_value ) <EOL> return datout <EOL> else : <EOL> return datout <EOL> def _StartCountStride ( elem , shape , dimensions = None , grp = None , datashape = None , put = False ) : <EOL> """<STR_LIT>""" <EOL> nDims = len ( shape ) <EOL> if nDims == <NUM_LIT:0> : <EOL> nDims = <NUM_LIT:1> <EOL> shape = ( <NUM_LIT:1> , ) <EOL> if np . iterable ( elem ) : <EOL> if type ( elem ) == np . ndarray or ( type ( elem ) != tuple and np . array ( [ _is_int ( e ) for e in elem ] ) . all ( ) ) : <EOL> elem = [ elem ] <EOL> for n in range ( len ( elem ) + <NUM_LIT:1> , nDims + <NUM_LIT:1> ) : <EOL> elem . append ( slice ( None , None , None ) ) <EOL> else : <EOL> elem = [ elem ] <EOL> newElem = [ ] <EOL> IndexErrorMsg = "<STR_LIT>" <EOL> for i , e in enumerate ( elem ) : <EOL> if type ( e ) in [ str , bytes , unicode ] : <EOL> try : <EOL> e = int ( e ) <EOL> except : <EOL> raise IndexError ( IndexErrorMsg ) <EOL> ea = np . asarray ( e ) <EOL> if ea . ndim > <NUM_LIT:1> : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> if put and ( dimensions is not None and grp is not None ) and len ( dimensions ) : <EOL> try : <EOL> dimname = dimensions [ i ] <EOL> dim = _find_dim ( grp , dimname ) <EOL> unlim = dim . isunlimited ( ) <EOL> except IndexError : <EOL> unlim = False <EOL> else : <EOL> unlim = False <EOL> if np . iterable ( ea ) and ea . dtype . kind == '<STR_LIT:b>' : <EOL> if not unlim and shape [ i ] != len ( ea ) : <EOL> msg = """<STR_LIT>""" <EOL> raise IndexError ( msg ) <EOL> ea = np . flatnonzero ( ea ) <EOL> if np . iterable ( ea ) and ea . dtype . kind == '<STR_LIT:i>' : <EOL> ea = np . where ( ea < <NUM_LIT:0> , ea + shape [ i ] , ea ) <EOL> if np . any ( ea < <NUM_LIT:0> ) : <EOL> raise IndexErro ( "<STR_LIT>" ) <EOL> if ea . shape != ( <NUM_LIT:0> , ) : <EOL> elen = shape [ i ] <EOL> if unlim : <EOL> elen = max ( ea . max ( ) + <NUM_LIT:1> , elen ) <EOL> if ea . max ( ) + <NUM_LIT:1> > elen : <EOL> msg = "<STR_LIT>" <EOL> raise IndexError ( msg ) <EOL> newElem . append ( ea ) <EOL> elif ea . dtype . kind == '<STR_LIT:i>' : <EOL> newElem . append ( e ) <EOL> elif type ( e ) == slice or type ( e ) == type ( Ellipsis ) : <EOL> newElem . append ( e ) <EOL> else : <EOL> try : <EOL> e = int ( e ) <EOL> newElem . append ( e ) <EOL> except : <EOL> raise IndexError ( IndexErrorMsg ) <EOL> elem = newElem <EOL> hasEllipsis = False <EOL> newElem = [ ] <EOL> for e in elem : <EOL> ea = np . asarray ( e ) <EOL> if type ( e ) == type ( Ellipsis ) : <EOL> if hasEllipsis : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> newElem . extend ( ( slice ( None , None , None ) , ) * ( nDims - len ( elem ) + <NUM_LIT:1> ) ) <EOL> hasEllipsis = True <EOL> elif np . iterable ( e ) and len ( e ) > <NUM_LIT:1> : <EOL> start = e [ <NUM_LIT:0> ] <EOL> stop = e [ - <NUM_LIT:1> ] + <NUM_LIT:1> <EOL> step = e [ <NUM_LIT:1> ] - e [ <NUM_LIT:0> ] <EOL> try : <EOL> ee = range ( start , stop , step ) <EOL> except ValueError : <EOL> ee = False <EOL> if ee and len ( e ) == len ( ee ) and ( e == np . arange ( start , stop , step ) ) . all ( ) : <EOL> newElem . append ( slice ( start , stop , step ) ) <EOL> else : <EOL> newElem . append ( e ) <EOL> elif np . iterable ( e ) and len ( e ) == <NUM_LIT:1> : <EOL> newElem . append ( slice ( e [ <NUM_LIT:0> ] , e [ <NUM_LIT:0> ] + <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> else : <EOL> newElem . append ( e ) <EOL> elem = newElem <EOL> if len ( elem ) < nDims : <EOL> for n in range ( len ( elem ) + <NUM_LIT:1> , nDims + <NUM_LIT:1> ) : <EOL> elem . append ( slice ( None , None , None ) ) <EOL> if len ( elem ) > nDims : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> sdim = [ ] <EOL> for i , e in enumerate ( elem ) : <EOL> if np . iterable ( e ) : <EOL> sdim . append ( np . alen ( e ) ) <EOL> else : <EOL> sdim . append ( <NUM_LIT:1> ) <EOL> sdim . append ( max ( nDims , <NUM_LIT:1> ) ) <EOL> start = np . empty ( sdim , dtype = int ) <EOL> count = np . empty ( sdim , dtype = int ) <EOL> stride = np . empty ( sdim , dtype = int ) <EOL> indices = np . empty ( sdim , dtype = object ) <EOL> for i , e in enumerate ( elem ) : <EOL> ea = np . asarray ( e ) <EOL> if put and ( dimensions is not None and grp is not None ) and len ( dimensions ) : <EOL> dimname = dimensions [ i ] <EOL> dim = _find_dim ( grp , dimname ) <EOL> unlim = dim . isunlimited ( ) <EOL> else : <EOL> unlim = False <EOL> if type ( e ) == slice : <EOL> if unlim and e . stop is not None and e . stop > shape [ i ] : <EOL> length = e . stop <EOL> elif unlim and e . stop is None and datashape != ( ) : <EOL> if e . start is None : <EOL> length = datashape [ i ] <EOL> else : <EOL> length = e . start + datashape [ i ] <EOL> else : <EOL> if unlim and datashape == ( ) and len ( dim ) == <NUM_LIT:0> : <EOL> length = <NUM_LIT:1> <EOL> else : <EOL> length = shape [ i ] <EOL> beg , end , inc = e . indices ( length ) <EOL> n = len ( range ( beg , end , inc ) ) <EOL> start [ ... , i ] = beg <EOL> count [ ... , i ] = n <EOL> stride [ ... , i ] = inc <EOL> indices [ ... , i ] = slice ( None ) <EOL> elif np . iterable ( e ) and np . array ( e ) . dtype . kind in '<STR_LIT:i>' : <EOL> start [ ... , i ] = np . apply_along_axis ( lambda x : e * x , i , np . ones ( sdim [ : - <NUM_LIT:1> ] ) ) <EOL> indices [ ... , i ] = np . apply_along_axis ( lambda x : np . arange ( sdim [ i ] ) * x , i , np . ones ( sdim [ : - <NUM_LIT:1> ] , int ) ) <EOL> count [ ... , i ] = <NUM_LIT:1> <EOL> stride [ ... , i ] = <NUM_LIT:1> <EOL> else : <EOL> if e >= <NUM_LIT:0> : <EOL> start [ ... , i ] = e <EOL> elif e < <NUM_LIT:0> and ( - e <= shape [ i ] ) : <EOL> start [ ... , i ] = e + shape [ i ] <EOL> else : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> count [ ... , i ] = <NUM_LIT:1> <EOL> stride [ ... , i ] = <NUM_LIT:1> <EOL> indices [ ... , i ] = - <NUM_LIT:1> <EOL> return start , count , stride , indices <EOL> def _out_array_shape ( count ) : <EOL> """<STR_LIT>""" <EOL> s = list ( count . shape [ : - <NUM_LIT:1> ] ) <EOL> out = [ ] <EOL> for i , n in enumerate ( s ) : <EOL> if n == <NUM_LIT:1> : <EOL> c = count [ ... , i ] . ravel ( ) [ <NUM_LIT:0> ] <EOL> out . append ( c ) <EOL> else : <EOL> out . append ( n ) <EOL> return out <EOL> def _is_container ( a ) : <EOL> try : <NUM_LIT:1> in a <EOL> except : return False <EOL> if type ( a ) == type ( basestring ) : return False <EOL> return True <EOL> def _is_int ( a ) : <EOL> try : <EOL> return int ( a ) == a <EOL> except : <EOL> return False <EOL> def _tostr ( s ) : <EOL> try : <EOL> ss = str ( s ) <EOL> except : <EOL> ss = s <EOL> return ss <EOL> def _getgrp ( g , p ) : <EOL> import posixpath <EOL> grps = p . split ( "<STR_LIT:/>" ) <EOL> for gname in grps : <EOL> if gname == "<STR_LIT>" : continue <EOL> g = g . groups [ gname ] <EOL> return g <EOL> def ncinfo ( ) : <EOL> from netCDF4 import Dataset <EOL> usage = """<STR_LIT>""" % os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> try : <EOL> opts , pargs = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> except : <EOL> ( type , value , traceback ) = sys . exc_info ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % value ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> group = None ; var = None ; dim = None <EOL> for option in opts : <EOL> if option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' or option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> group = option [ <NUM_LIT:1> ] <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' or option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> var = option [ <NUM_LIT:1> ] <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' or option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> dim = option [ <NUM_LIT:1> ] <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" % option [ <NUM_LIT:0> ] ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> filename = pargs [ - <NUM_LIT:1> ] <EOL> f = Dataset ( filename ) <EOL> if group is None : <EOL> if var is None and dim is None : <EOL> print ( f ) <EOL> else : <EOL> if var is not None : <EOL> print ( f . variables [ var ] ) <EOL> if dim is not None : <EOL> print ( f . dimensions [ dim ] ) <EOL> else : <EOL> if var is None and dim is None : <EOL> print ( getgrp ( f , group ) ) <EOL> else : <EOL> g = getgrp ( f , group ) <EOL> if var is not None : <EOL> print ( g . variables [ var ] ) <EOL> if dim is not None : <EOL> print ( g . dimensions [ var ] ) <EOL> f . close ( ) <EOL> def _nc4tonc3 ( filename4 , filename3 , clobber = False , nchunk = <NUM_LIT:10> , quiet = False , format = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from netCDF4 import Dataset <EOL> ncfile4 = Dataset ( filename4 , '<STR_LIT:r>' ) <EOL> if ncfile4 . file_format != '<STR_LIT>' : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> ncfile3 = Dataset ( filename3 , '<STR_LIT:w>' , clobber = clobber , format = format ) <EOL> unlimdimname = False <EOL> unlimdim = None <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' ) <EOL> ncfile3 . setncatts ( ncfile4 . __dict__ ) <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' ) <EOL> for dimname , dim in ncfile4 . dimensions . items ( ) : <EOL> if dim . isunlimited ( ) : <EOL> unlimdimname = dimname <EOL> unlimdim = dim <EOL> ncfile3 . createDimension ( dimname , None ) <EOL> else : <EOL> ncfile3 . createDimension ( dimname , len ( dim ) ) <EOL> for varname , ncvar in ncfile4 . variables . items ( ) : <EOL> if not quiet : <EOL> sys . stdout . write ( '<STR_LIT>' % varname ) <EOL> if unlimdimname and unlimdimname in ncvar . dimensions : <EOL> hasunlimdim = True <EOL> else : <EOL> hasunlimdim = False <EOL> if hasattr ( ncvar , '<STR_LIT>' ) : <EOL> FillValue = ncvar . _FillValue <EOL> else : <EOL> FillValue = None <EOL> var = ncfile3 . createVariable ( varname , ncvar . dtype , ncvar . dimensions , fill_value = FillValue ) <EOL> attdict = ncvar . __dict__ <EOL> if '<STR_LIT>' in attdict : <EOL> del attdict [ '<STR_LIT>' ] <EOL> var . setncatts ( attdict ) <EOL> if hasunlimdim : <EOL> if nchunk : <EOL> start = <NUM_LIT:0> ; stop = len ( unlimdim ) ; step = nchunk <EOL> if step < <NUM_LIT:1> : <EOL> step = <NUM_LIT:1> <EOL> for n in range ( start , stop , step ) : <EOL> nmax = n + nchunk <EOL> if nmax > len ( unlimdim ) : <EOL> nmax = len ( unlimdim ) <EOL> var [ n : nmax ] = ncvar [ n : nmax ] <EOL> else : <EOL> var [ <NUM_LIT:0> : len ( unlimdim ) ] = ncvar [ : ] <EOL> else : <EOL> var [ : ] = ncvar [ : ] <EOL> ncfile3 . sync ( ) <EOL> ncfile3 . close ( ) <EOL> ncfile4 . close ( ) <EOL> def nc4tonc3 ( ) : <EOL> usage = """<STR_LIT>""" % os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> try : <EOL> opts , pargs = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except : <EOL> ( type , value , traceback ) = sys . exc_info ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % value ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> quiet = <NUM_LIT:0> <EOL> chunk = <NUM_LIT:1000> <EOL> format = '<STR_LIT>' <EOL> overwritefile = <NUM_LIT:0> <EOL> for option in opts : <EOL> if option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> overwritefile = <NUM_LIT:1> <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> quiet = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> format = option [ <NUM_LIT:1> ] <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> chunk = int ( option [ <NUM_LIT:1> ] ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" % options [ <NUM_LIT:0> ] ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if len ( pargs ) < <NUM_LIT:2> or len ( pargs ) > <NUM_LIT:2> : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> filename4 = pargs [ <NUM_LIT:0> ] <EOL> filename3 = pargs [ <NUM_LIT:1> ] <EOL> _nc4tonc3 ( filename4 , filename3 , clobber = overwritefile , quiet = quiet , format = format ) <EOL> def _nc3tonc4 ( filename3 , filename4 , unpackshort = True , <EOL> zlib = True , complevel = <NUM_LIT:6> , shuffle = True , fletcher32 = False , <EOL> clobber = False , lsd_dict = None , nchunk = <NUM_LIT:10> , quiet = False , classic = <NUM_LIT:0> , <EOL> vars = None , istart = <NUM_LIT:0> , istop = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> from netCDF4 import Dataset <EOL> ncfile3 = Dataset ( filename3 , '<STR_LIT:r>' ) <EOL> if classic : <EOL> ncfile4 = Dataset ( filename4 , '<STR_LIT:w>' , clobber = clobber , format = '<STR_LIT>' ) <EOL> else : <EOL> ncfile4 = Dataset ( filename4 , '<STR_LIT:w>' , clobber = clobber , format = '<STR_LIT>' ) <EOL> mval = <NUM_LIT> <EOL> unlimdimname = False <EOL> unlimdim = None <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' ) <EOL> ncfile4 . setncatts ( ncfile3 . __dict__ ) <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' ) <EOL> for dimname , dim in ncfile3 . dimensions . items ( ) : <EOL> if dim . isunlimited ( ) : <EOL> unlimdimname = dimname <EOL> unlimdim = dim <EOL> ncfile4 . createDimension ( dimname , None ) <EOL> if istop == - <NUM_LIT:1> : istop = len ( unlimdim ) <EOL> else : <EOL> ncfile4 . createDimension ( dimname , len ( dim ) ) <EOL> if vars is None : <EOL> varnames = ncfile3 . variables . keys ( ) <EOL> else : <EOL> varnames = vars <EOL> for dimname in ncfile3 . dimensions . keys ( ) : <EOL> if dimname in ncfile3 . variables . keys ( ) and dimname not in varnames : <EOL> varnames . append ( dimname ) <EOL> for varname in varnames : <EOL> ncvar = ncfile3 . variables [ varname ] <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' % varname ) <EOL> if lsd_dict is not None and lsd_dict . has_key ( varname ) : <EOL> lsd = lsd_dict [ varname ] <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' % lsd ) <EOL> else : <EOL> lsd = None <EOL> if unpackshort and hasattr ( ncvar , '<STR_LIT>' ) and hasattr ( ncvar , '<STR_LIT>' ) : <EOL> dounpackshort = True <EOL> datatype = '<STR_LIT>' <EOL> else : <EOL> dounpackshort = False <EOL> datatype = ncvar . dtype <EOL> if unlimdimname and unlimdimname in ncvar . dimensions : <EOL> hasunlimdim = True <EOL> else : <EOL> hasunlimdim = False <EOL> if dounpackshort : <EOL> if not quiet : sys . stdout . write ( '<STR_LIT>' ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> if hasattr ( ncvar , '<STR_LIT>' ) : <EOL> FillValue = ncvar . _FillValue <EOL> else : <EOL> FillValue = None <EOL> var = ncfile4 . createVariable ( varname , datatype , ncvar . dimensions , fill_value = FillValue , least_significant_digit = lsd , zlib = zlib , complevel = complevel , shuffle = shuffle , fletcher32 = fletcher32 ) <EOL> attdict = ncvar . __dict__ <EOL> if '<STR_LIT>' in attdict : del attdict [ '<STR_LIT>' ] <EOL> if dounpackshort and '<STR_LIT>' in attdict : <EOL> del attdict [ '<STR_LIT>' ] <EOL> if dounpackshort and '<STR_LIT>' in attdict : <EOL> del attdict [ '<STR_LIT>' ] <EOL> if dounpackshort and '<STR_LIT>' in attdict : <EOL> attdict [ '<STR_LIT>' ] = mval <EOL> var . setncatts ( attdict ) <EOL> if hasunlimdim : <EOL> if nchunk : <EOL> start = istart ; stop = istop ; step = nchunk <EOL> if step < <NUM_LIT:1> : step = <NUM_LIT:1> <EOL> for n in range ( start , stop , step ) : <EOL> nmax = n + nchunk <EOL> if nmax > istop : nmax = istop <EOL> idata = ncvar [ n : nmax ] <EOL> if dounpackshort : <EOL> tmpdata = ( ncvar . scale_factor * idata . astype ( '<STR_LIT:f>' ) + ncvar . add_offset ) . astype ( '<STR_LIT:f>' ) <EOL> if hasattr ( ncvar , '<STR_LIT>' ) : <EOL> tmpdata = np . where ( idata == ncvar . missing_value , mval , tmpdata ) <EOL> else : <EOL> tmpdata = idata <EOL> var [ n - istart : nmax - istart ] = tmpdata <EOL> else : <EOL> idata = ncvar [ : ] <EOL> if dounpackshort : <EOL> tmpdata = ( ncvar . scale_factor * idata . astype ( '<STR_LIT:f>' ) + ncvar . add_offset ) . astype ( '<STR_LIT:f>' ) <EOL> if hasattr ( ncvar , '<STR_LIT>' ) : <EOL> tmpdata = np . where ( idata == ncvar . missing_value , mval , tmpdata ) <EOL> else : <EOL> tmpdata = idata <EOL> var [ <NUM_LIT:0> : len ( unlimdim ) ] = tmpdata <EOL> else : <EOL> idata = ncvar [ : ] <EOL> if dounpackshort : <EOL> tmpdata = ( ncvar . scale_factor * idata . astype ( '<STR_LIT:f>' ) + ncvar . add_offset ) . astype ( '<STR_LIT:f>' ) <EOL> if hasattr ( ncvar , '<STR_LIT>' ) : <EOL> tmpdata = np . where ( idata == ncvar . missing_value , mval , tmpdata ) <EOL> else : <EOL> tmpdata = idata <EOL> var [ : ] = tmpdata <EOL> ncfile4 . sync ( ) <EOL> ncfile3 . close ( ) <EOL> ncfile4 . close ( ) <EOL> def nc3tonc4 ( ) : <EOL> usage = """<STR_LIT>""" % os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> try : <EOL> opts , pargs = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> except : <EOL> ( type , value , traceback ) = sys . exc_info ( ) <EOL> sys . stdout . write ( "<STR_LIT>" % value ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> overwritefile = <NUM_LIT:0> <EOL> complevel = <NUM_LIT:6> <EOL> classic = <NUM_LIT:1> <EOL> zlib = <NUM_LIT:1> <EOL> shuffle = <NUM_LIT:1> <EOL> fletcher32 = <NUM_LIT:0> <EOL> unpackshort = <NUM_LIT:1> <EOL> vars = None <EOL> quantize = None <EOL> quiet = <NUM_LIT:0> <EOL> chunk = <NUM_LIT:1000> <EOL> istart = <NUM_LIT:0> <EOL> istop = - <NUM_LIT:1> <EOL> for option in opts : <EOL> if option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> overwritefile = <NUM_LIT:1> <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> classic = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> zlib = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> quiet = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> complevel = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> shuffle = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> fletcher32 = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> unpackshort = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> chunk = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> vars = option [ <NUM_LIT:1> ] <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> quantize = option [ <NUM_LIT:1> ] <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> istart = int ( option [ <NUM_LIT:1> ] ) <EOL> elif option [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> istop = int ( option [ <NUM_LIT:1> ] ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" % option [ <NUM_LIT:0> ] ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if len ( pargs ) < <NUM_LIT:2> or len ( pargs ) > <NUM_LIT:2> : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> sys . stderr . write ( usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> filename3 = pargs [ <NUM_LIT:0> ] <EOL> filename4 = pargs [ <NUM_LIT:1> ] <EOL> if quantize is not None : <EOL> lsd_dict = { } <EOL> for p in quantize . split ( '<STR_LIT:U+002C>' ) : <EOL> kv = p . split ( '<STR_LIT:=>' ) <EOL> lsd_dict [ kv [ <NUM_LIT:0> ] ] = int ( kv [ <NUM_LIT:1> ] ) <EOL> else : <EOL> lsd_dict = None <EOL> if vars is not None : <EOL> vars = vars . split ( '<STR_LIT:U+002C>' ) <EOL> _nc3tonc4 ( filename3 , filename4 , unpackshort = unpackshort , <EOL> zlib = zlib , complevel = complevel , shuffle = shuffle , <EOL> fletcher32 = fletcher32 , clobber = overwritefile , lsd_dict = lsd_dict , <EOL> nchunk = chunk , quiet = quiet , vars = vars , classic = classic , <EOL> istart = istart , istop = istop ) </s>
