NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/pyglider/trunk/pyglider/dbd2asc.py

Revision 477 (checked in by haines, 12 years ago)

added file date to outfile for raw2proc

  • Property svn:executable set to
Line 
1 """Run dbd2asc on latest glider binary data ({?}bd) files.
2
3    Usage: python sbd2asc.py glidername filetype
4
5    Inputs:
6      glidername [ramses | pelagia]
7      filetype [sbd | tbd | dbd | ...]
8
9       input path
10          /home/localuser/realtime/{glider}/{filetype}/*.{filetype}
11       output path
12          /home/localuser/realtime/{glider}/{filetype}asc/*.{filetype}asc
13
14    Example usage:   python dbd2asc.py ramses sbd
15          /home/localuser/realtime/ramses/sbd/*.sbd
16          all new *.sbd will be processed to 
17          /home/localuser/realtime/ramses/sbdasc/*.sbdasc
18       
19         
20 """
21
22 import sys
23 import os
24 import glob
25 import errno
26 import datetime
27
28 if __name__ == "__main__":
29     try:
30         debug = 0
31         glider = sys.argv[1]
32         filetype = sys.argv[2]
33
34         local_dir = "/home/localuser/realtime"
35         # localuser realtime {glider} (sbd)
36         bd_dir = os.path.join(local_dir, glider, filetype)
37         bd_files = glob.glob1(bd_dir, "*." + filetype)
38         for idx,f in enumerate(bd_files):
39             bd_files[idx] = os.path.splitext(f)[0]
40         # localuser realtime {glider} (sbdasc)
41         asc_dir = os.path.join(local_dir, glider, filetype + "asc")
42         asc_files = glob.glob1(asc_dir, "*." + filetype + "asc")
43
44         for idx,f in enumerate(asc_files):
45             asc_files[idx] = os.path.splitext(f)[0]
46
47        
48        
49         s = set(bd_files) - set(asc_files)
50         files = list(s)
51         files.sort()
52         if files:
53             for f in files:
54                 infile = os.path.join(bd_dir, f + '.' + filetype)
55                 dt = datetime.datetime.fromtimestamp(os.stat(infile).st_ctime)
56                 dt_str = dt.strftime("_%Y_%m_%d_%H%M")
57                 # datetime string added to outfile name for raw2proc
58                 outfile = os.path.join(asc_dir, f + dt_str + '.' + filetype + 'asc')
59                 cache_dir = os.path.join(asc_dir, "cache")
60                 if debug:
61                     print infile
62                     print outfile
63                    
64                 try:
65                     command = "/home/localuser/bin/dbd2asc -c " + cache_dir + " " + infile + " > " + outfile
66                     rc = os.system(command)
67                     print " ... Processed", outfile
68                 except OSError:
69                     print "dbd2asc return code: " + str(rc)
70         else:
71             print "Nothing to convert"
72     except:
73         print __doc__
Note: See TracBrowser for help on using the browser.