New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 4128 – NEMO

Changeset 4128


Ignore:
Timestamp:
2013-10-24T22:45:19+02:00 (11 years ago)
Author:
andrewryan
Message:

some minor changes to namelist parser and c4comb.F90

Location:
branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/nml.py

    r4126 r4128  
    154154__version__ = "0.1.0" 
    155155import re 
     156from numbers import Number 
    156157 
    157158def reader(path): 
     
    341342    """ 
    342343    if isinstance(data, list): 
    343         if same_type(data): 
     344        if all_numeric(data): 
    344345            delim = " " 
    345346        else: 
     
    350351    return text 
    351352 
     353def all_numeric(inputs): 
     354    # Checks all list entries are numbers 
     355    flag = True 
     356    for input in inputs: 
     357        if not isinstance(input, Number): 
     358            flag = False 
     359            break 
     360    return flag 
     361 
    352362def numeric(word): 
    353363    # Tests input string is numeric data 
     
    375385        flag = False 
    376386    return flag 
     387 
     388def quote(word): 
     389    if not quoted(word): 
     390        word = "'%s'" % (word,) 
     391    return word 
    377392 
    378393def convert(word): 
     
    383398            result = "%s" % (word,) 
    384399        else: 
    385             result = "'%s'" % (word,) 
     400            result = quote(word) 
    386401    elif isinstance(word, bool): 
    387402        if word: 
  • branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py

    r4126 r4128  
    173173        self.num = 10 
    174174        self.mixed_list = ["foo.nc", -1, True] 
     175        self.mixed_str_list = map(nml.quote, ["foo.nc", "-1", ".TRUE."]) 
    175176 
    176177    def test_should_format_mixed_list(self): 
     
    186187    def test_should_format_character_list(self): 
    187188        data = nml.tostring(self.char_list) 
    188         result = "'a.nc' 'b.nc' 'c.nc'" 
     189        result = "'a.nc', 'b.nc', 'c.nc'" 
    189190        self.assertEqual(data, result) 
    190191 
     
    213214            self.assertEqual(case, input) 
    214215 
     216    def test_should_treat_mixed_numeric_character_data_as_character(self): 
     217        case = nml.tostring(self.mixed_str_list) 
     218        result = "'foo.nc', '-1', '.TRUE.'" 
     219        self.assertEqual(case, result) 
     220 
    215221class TestUpdateNamelist(unittest.TestCase): 
    216222    def setUp(self): 
  • branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/src/c4comb.F90

    r4124 r4128  
    465465      CALL chkerr( nf90_put_att(ncid, nf90_global,'institution',    trim(ins_str)),cpname, __LINE__) 
    466466      CALL chkerr( nf90_put_att(ncid, nf90_global,'validity_time',  trim(val_str)),cpname, __LINE__) 
    467       CALL chkerr( nf90_put_att(ncid, nf90_global,'best_estimate_description', 'analysis produced 2 days behind real time'),cpname, __LINE__) 
     467      CALL chkerr( nf90_put_att(ncid, nf90_global,'best_estimate_description', & 
     468                              &       'analysis produced 2 days behind real time'),cpname, __LINE__) 
    468469      CALL chkerr( nf90_put_att(ncid, nf90_global,'time_interp', 'daily average fields'),cpname, __LINE__) 
    469470      WRITE(*,*) 'Succesfully put global attributes ' 
Note: See TracChangeset for help on using the changeset viewer.