File: subset_syntax.py

package info (click to toggle)
drslib 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,596 kB
  • sloc: python: 6,119; xml: 988; makefile: 128; sh: 121
file content (39 lines) | stat: -rw-r--r-- 809 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# BSD Licence
# Copyright (c) 2011, Science & Technology Facilities Council (STFC)
# All rights reserved.
#
# See the LICENSE file in the source distribution of this software for
# the full license text.

"""
Strip subset syntax out of CMIP3 runs


Filename types

<var>_<table>_<dddd>
<var>_<table>.<dddddddddd>-<dddddddddd>
<var>_<table>.<model?>.<exp>.<dddd>
<var>_<table>_<d>
<var>_<table>.<dddd>

"""

import sys, os, re

rexp = re.compile(r'(\w+)_(\w+)(?:[._-](.*))?.nc$')

def main():
    for line in sys.stdin:
        filename, size = line.strip().split()
    
        dirname, basename = os.path.split(filename)
    
        mo = rexp.match(basename)
        if not mo:
            print '** %s' % basename
        else:
            print basename, mo.groups()

if __name__ == '__main__':
    main()