;ň
Ră?c           @   s   d  Z  d k l Z d k l Z l Z l Z l Z d k Z d e f d     YZ	 d e f d     YZ
 e e
  Z e e	  Z d S(   sí  This module provides parallel acces to netCDF files. One netCDF dimension
is defined for splitting the data among processors such that each processor
is responsible for one slice of the file along that dimension.

Since netCDF files can be very big, the distribution algorithm gives
priority to memory efficiency over CPU time efficiency. The processor
that handles the file treats only one slice per superstep, which means
that at no time more than one slice must be stored in any processor.
(   s
   NetCDFFile(   s   ParClasss   ParBases
   ParInvalids
   is_invalidNs   _ParNetCDFFilec           B   sY   t  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z d	   Z	 e	 Z
 RS(
   s  Distributed netCDF file

    Constructor: ParNetCDFFile(|filename|, |split_dimension|, |mode|='r',
                               |local_access| = 0)

    Arguments:

    |filename| -- the name of the netCDF file

    |split_dimension| -- the name of the dimension along which the data
                         is distributed over the processors

    |mode| -- read ('r'), write ('w'), or append ('a'). Default is 'r'.

    |local_access| -- if 0 (default), processor 0 is the only one to access
                      the file, all others communicate with processor 0. If
                      1 (only for reading), each processor accesses the
                      file directly. In the latter case, the file must be
                      accessible on all processors under the same name.
                      A third mode is 'auto', which uses some heuristics
                      to decide if the file is accessible everywhere:
                      it checks for existence of the file, then compares
                      the size on all processors, and finally verifies
                      that the same variables exist everywhere, with
                      identical names, types, and sizes.

    A ParNetCDFFile object acts as much as possible like a NetCDFFile object.
    Variables become ParNetCDFVariable objects, which behave like
    distributed sequences. Variables that use the dimension named by
    |split_dimension| are automatically distributed among the processors
    such that each treats only one slice of the whole file.
    s   ri    c         C   sú  | d j o
 d } n | |  _ | |  _ | |  _ | |  _ | |  _ | d j |  _ | p
 | d j oß t	 | |  |  _
 y+ |  i
 i | }
 |
 t j o
 d }
 n Wn t j
 o t }
 n Xh  }	 x |  i
 i i   D]e \ } } | | i f |	 | <|
 d j  o | | i j o) t | i  i |  } | i | }
 qŮ qŮ Wn t |  _
 | |  _ t }
 t }	 | o" |  i |
  }
 |  i |	  }	 n |
 t j	 o |  i |
  n h  |  _ x> |	 i   D]0 \ } } t |  | d | d |  |  i | <qÂWd  S(   Ns   ri    i˙˙˙˙i   (   s   modes   local_accesss   pids   selfs   nprocss   filenames   split_dimensions   splits	   read_onlys
   NetCDFFiles   files
   dimensionss   lengths   Nones   KeyErrors   varss	   variabless   itemss   names   vars   lists   indexs   shapes	   broadcasts   _divideDatas   _ParNetCDFVariable(   s   selfs   pids   nprocss   filenames   split_dimensions   modes   local_accesss   indexs   names   varss   lengths   var(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __parinit__8   sJ     
					 			 c         C   s   t  |  i  Sd  S(   N(   s   reprs   selfs   filename(   s   self(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __repr__^   s    c         C   s/   |  i p |  i d j o |  i i   n d  S(   Ni    (   s   selfs   local_accesss   pids   files   close(   s   self(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   closea   s    c         C   sf   | |  i j o+ | t j o t d  n |  i |  n |  i d j o |  i i	 | |  n d  S(   Ns#   Split dimension cannot be unlimitedi    (
   s   names   selfs   splits   lengths   Nones
   ValueErrors   _divideDatas   pids   files   createDimension(   s   selfs   names   length(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   createDimensione   s    c         C   s   |  i d j o% |  i i | | |  } | i } n d } |  i	 | | f  \ } } t
 |  | | |  i  |  i | <|  i | Sd  S(   Ni    (   s   selfs   pids   files   createVariables   names   typecodes
   dimensionss   vars   dims	   broadcasts   _ParNetCDFVariables   splits	   variables(   s   selfs   names   typecodes
   dimensionss   dims   var(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   createVariablem   s    c         C   sĂ   | |  i d |  i } t |  i | |  |  _ t |  i | |  |  _ |  i o |  i d j oZ g  |  _	 xN t
 |  i  D]9 } | | } t | | |  } |  i	 i | | f  q~ Wn d  S(   Ni   i    (   s   lengths   selfs   nprocss   chunks   mins   pids   firsts   lasts   local_accesss   partss   ranges   append(   s   selfs   lengths   lasts   pids   chunks   first(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   _divideDataw   s    	 
c         C   s%   |  i d j o |  i i   n d  S(   Ni    (   s   selfs   pids   files   sync(   s   self(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   sync   s    (   s   __name__s
   __module__s   __doc__s   __parinit__s   __repr__s   closes   createDimensions   createVariables   _divideDatas   syncs   flush(    (    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   _ParNetCDFFile   s   ! &				
		s   _ParNetCDFVariablec           B   st   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z RS(   Nc         C   s   | |  _  | i |  _ | i |  _ | |  _ | |  _ |  |  _ h  |  _ y t |  i	 |  |  _	 Wn t j
 o t |  _	 n Xd  S(   N(   s   files   selfs   pids   nprocss   names
   dimensionss   values
   attributess   lists   indexs   split_dimensions
   ValueErrors   None(   s   selfs   files   names
   dimensionss   split_dimension(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __init__   s    					c         C   s   t  |  i  Sd  S(   N(   s   reprs   selfs   name(   s   self(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __repr__   s    c         C   s2  |  i |  } |  i i o% |  i | |  i i |  i i  } nŐ |  i	 d j o xX t
 d |  i  D]D } |  i i | \ } } |  i | | |  } |  i | | g  qd W|  i | |  i i |  i i  } nE xA t
 d |  i  D]- } |  i t g   } | o | d } qä qä W| t j o t Sn | Sd  S(   Ni    i   (   s   selfs   _prepareIndicess   items   files   local_accesss	   _readDatas   firsts   lasts   datas   pids   ranges   nprocss   partss   puts   Nones   messagess
   ParInvalid(   s   selfs   items   lasts   messagess   pids   datas   first(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __getitem__   s$    % % c         C   s   |  i t | |   Sd  S(   N(   s   selfs   __getitem__s   slices   firsts   last(   s   selfs   firsts   last(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __getslice__­   s    c         C   sh  |  i |  } t |  o
 t } n |  i d j oĆ | t j	 o& |  i | | |  i i	 |  i i
  n |  i t j	 o x| t d |  i  D]d } |  i i | \ } } |  i t g   } | o | d t j	 o |  i | | d | |  q q Wqdni |  i t j	 oX xU t d |  i  D]= } | |  i j o |  i | d g  q|  i t g   qWn d  S(   Ni    i   (   s   selfs   _prepareIndicess   items
   is_invalids   values   Nones   pids
   _writeDatas   files   firsts   lasts   indexs   ranges   nprocss   partss   puts   data(   s   selfs   items   values   lasts   pids   datas   first(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __setitem__°   s&    
& * c         C   s   |  i t | |  |  d  S(   N(   s   selfs   __setitem__s   slices   firsts   lasts   value(   s   selfs   firsts   lasts   value(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __setslice__Ĺ   s    c         C   sm   t  | d  oT t |  t f   j o | f } n | t |  i  t |  t t  f } n | Sd  S(   Ns   is_parindex(   s   hasattrs   items   types   lens   selfs
   dimensionss   slices   None(   s   selfs   item(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   _prepareIndicesČ   s
    .c         C   sF   |  i | | |  } | t j o t Sn |  i i i |  i | Sd  S(   N(	   s   selfs   _indicess   items
   part_firsts	   part_lasts   Nones   files	   variabless   name(   s   selfs   items
   part_firsts	   part_last(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys	   _readDataĎ   s    c         C   sÁ   y t  |  d j o d  Sn Wn t j
 o n X|  i | | |  } | t j	 of y' t	 i
 |  |  i i i |  i | <Wq˝ |  i i i |  i i GH| GHt	 i
 |  i GH  q˝ Xn d  S(   Ni    (   s   lens   datas	   TypeErrors   selfs   _indicess   items
   part_firsts	   part_lasts   Nones   Numerics   arrays   files	   variabless   names   shape(   s   selfs   items   datas
   part_firsts	   part_last(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys
   _writeDataÖ   s    'c   	      C   s  t  | d  oW | i o t Sn | i d j o | i | Sqg t | i | | i | | i  Sn |  i
 t j	 o| |  i
 } t |  t d  j o t d  n | i | i | i f \ } } } | t j o
 d } n | t j o
 d } n t d | | | d |  } | | | } | t j o
 | } n t | |  } | |  i
  t | | |  f | |  i
 d } n | Sd  S(   Ns   is_parindexi    s$   Must use slice along split dimensioni   (   s   hasattrs   items   valids   Nones   skips   starts
   part_firsts   slices   stops   selfs   indexs   splits   types
   ValueErrors   steps   firsts   lasts   maxs   n1s	   part_lasts   min(	   s   selfs   items
   part_firsts	   part_lasts   lasts   skips   splits   n1s   first(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   _indicesć   s.    ! 
 

3c         C   sÁ   |  i i o! t |  i i i |  i |  Sn y |  i | SWn t j
 o n X|  i	 d j o# t |  i i i |  i |  } n t } |  i |  } |  i i o | |  i | <n | Sd  S(   Ni    (   s   selfs   files   local_accesss   getattrs	   variabless   names   attrs
   attributess   KeyErrors   pids   values   Nones	   broadcasts	   read_only(   s   selfs   attrs   value(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __getattr__˙   s    !#c         C   s   |  i i |  i i Sd  S(   N(   s   selfs   files   lasts   first(   s   self(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   __len__  s    (   s   __name__s
   __module__s   __init__s   __repr__s   __getitem__s   __getslice__s   __setitem__s   __setslice__s   _prepareIndicess	   _readDatas
   _writeDatas   _indicess   __getattr__s   __len__(    (    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   _ParNetCDFVariable   s   											(   s   __doc__s   Scientific.IO.NetCDFs
   NetCDFFiles   cores   ParClasss   ParBases
   ParInvalids
   is_invalids   Numerics   _ParNetCDFFiles   _ParNetCDFVariables   ParNetCDFVariables   ParNetCDFFile(
   s   ParNetCDFFiles
   is_invalids
   ParInvalids   Numerics   ParClasss   _ParNetCDFVariables   ParNetCDFVariables
   NetCDFFiles   ParBases   _ParNetCDFFile(    (    s<   /mit/python/lib/python2.3/site-packages/Scientific/BSP/IO.pys   ?   s   	r