Ignore:
Timestamp:
06/23/20 15:42:10 (5 years ago)
Author:
jdquinn
Message:

CHG: Saving progress on MATLAB -> Python translations; cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/io/loadvars.py

    r25092 r25125  
     1from collections import OrderedDict
     2from netCDF4 import Dataset
     3import numpy as np
     4from re import findall
    15import shelve
    2 import numpy as np
    3 from netCDF4 import Dataset
    4 from re import findall
    5 from collections import OrderedDict
     6
    67from model import *
    78#hack to keep python 2 compatibility
     
    1516
    1617def loadvars(*args, OL):
    17     """
    18     LOADVARS - function to load variables to a file.
    19 
    20     This function loads one or more variables from a file.  The names of the variables
    21     must be supplied.  If more than one variable is specified, it may be done with
    22     a list of names or a dictionary of name as keys.  The output type will correspond
    23     to the input type.  All the variables in the file may be loaded by specifying only
    24     the file name.
     18    '''
     19    LOADVARS - function to load variables from a file.
     20
     21    This function loads one or more variables from a file. The names of the
     22    variables must be supplied. If more than one variable is specified, it may
     23    be done with a list of names or a dictionary of name as keys. The output
     24    type will correspond to the input type. All the variables in the file may
     25    be loaded by specifying only the file name.
    2526
    2627    Usage:
     
    2930        nvdict = loadvars('shelve.dat', {'a':None, 'b':None})
    3031        nvdict = loadvars('shelve.dat')
    31 
    32     """
     32    '''
    3333
    3434    filename = ''
     
    4040        if not filename:
    4141            filename = '/tmp/shelve.dat'
    42 
    4342    else:
    4443        raise TypeError("Missing file name.")
     
    4746        for name in args[1:]:
    4847            nvdict[name] = None
    49 
    5048    elif len(args) == 2 and isinstance(args[1], list):  # (filename, [names])
    5149        for name in args[1]:
    5250            nvdict[name] = None
    53 
    5451    elif len(args) == 2 and isinstance(args[1], dict):  # (filename, {names:values})
    5552        nvdict = args[1]
    56 
    5753    elif len(args) == 1:  #  (filename)
    5854        pass
    59 
    6055    else:
    6156        raise TypeError("Unrecognized input arguments.")
     
    7873                print(("Variable '%s' loaded." % name))
    7974        my_shelf.close()
    80 
    8175    else:  #We used netcdf for the save
    8276        try:
Note: See TracChangeset for help on using the changeset viewer.