Changeset 275 in lmdz_wrf


Ignore:
Timestamp:
Feb 25, 2015, 11:37:11 AM (10 years ago)
Author:
lfita
Message:

Moving check_arguments to te head of the script
Including '####### ###### ##### #### ### ## #' to distinguish between functions and operations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r274 r275  
    9898
    9999    return vals
     100
     101def check_arguments(funcname,Nargs,args,char,expectargs):
     102    """ Function to check the number of arguments if they are coincident
     103    check_arguments(funcname,Nargs,args,char)
     104      funcname= name of the function/program to check
     105      Nargs= theoretical number of arguments
     106      args= passed arguments
     107      char= character used to split the arguments
     108    """
     109
     110    fname = 'check_arguments'
     111
     112    Nvals = len(args.split(char))
     113    if Nvals != Nargs:
     114        print errormsg
     115        print '  ' + fname + ': wrong number of arguments:',Nvals," passed to  '",   \
     116          funcname, "' which requires:",Nargs,'!!'
     117        print '    given arguments:',args.split(char)
     118        print '    expected arguments:',expectargs
     119        quit(-1)
     120
     121    return
     122
     123def Str_Bool(val):
     124    """ Function to transform from a String value to a boolean one
     125    >>> Str_Bool('True')
     126    True
     127    >>> Str_Bool('0')
     128    False
     129    >>> Str_Bool('no')
     130    False
     131    """
     132
     133    fname = 'Str_Bool'
     134
     135    if val == 'True' or val == '1' or val == 'yes':
     136        boolv = True
     137    elif val == 'False' or val == '0' or val== 'no':
     138        boolv = False
     139    else:
     140        print errormsg
     141        print '  ' + fname + ": value '" + val + "' not ready!!"
     142        quit(-1)
     143
     144    return boolv
     145
     146####### ###### ##### #### ### ## #
    100147
    101148def valmodoper(varVal, valuesS):
     
    1241212459#field_stats('full', 'geo_em.d01.nc', 'HGT_M')
    1241312460
    12414 def check_arguments(funcname,Nargs,args,char,expectargs):
    12415     """ Function to check the number of arguments if they are coincident
    12416     check_arguments(funcname,Nargs,args,char)
    12417       funcname= name of the function/program to check
    12418       Nargs= theoretical number of arguments
    12419       args= passed arguments
    12420       char= character used to split the arguments
    12421     """
    12422 
    12423     fname = 'check_arguments'
    12424 
    12425     Nvals = len(args.split(char))
    12426     if Nvals != Nargs:
    12427         print errormsg
    12428         print '  ' + fname + ': wrong number of arguments:',Nvals," passed to  '",   \
    12429           funcname, "' which requires:",Nargs,'!!'
    12430         print '    given arguments:',args.split(char)
    12431         print '    expected arguments:',expectargs
    12432         quit(-1)
    12433 
    12434     return
    12435 
    12436 def Str_Bool(val):
    12437     """ Function to transform from a String value to a boolean one
    12438     >>> Str_Bool('True')
    12439     True
    12440     >>> Str_Bool('0')
    12441     False
    12442     >>> Str_Bool('no')
    12443     False
    12444     """
    12445 
    12446     fname = 'Str_Bool'
    12447 
    12448     if val == 'True' or val == '1' or val == 'yes':
    12449         boolv = True
    12450     elif val == 'False' or val == '0' or val== 'no':
    12451         boolv = False
    12452     else:
    12453         print errormsg
    12454         print '  ' + fname + ": value '" + val + "' not ready!!"
    12455         quit(-1)
    12456 
    12457     return boolv
    12458 
    1245912461def get_namelist_vars(values, namelist):
    1246012462    """ Function to get namelist-like  values ([varname] = [value])
Note: See TracChangeset for help on using the changeset viewer.