HWRF  trunk@4391
exhwrf_wrfout_archive.py
1 #! /usr/bin/env python
2 
3 ##@namespace scripts.exhwrf_wrfout_archive
4 # Archives native wrfout files to tape via the "htar" command.
5 #
6 # To enable this script, you must set the wrfout option in the [archive]
7 # configuration section:
8 # @code[.conf]
9 # [archive]
10 # wrfout=hpss:/NCEPDEV/emc-hwrf/2year/Jane.Doe/wrfout/{out_prefix}.tar
11 # @endcode
12 #
13 # The extension must be .tar, and the only archiving method supported is
14 # hpss:/ (which uses htar)
15 
16 import os, sys
18 import hwrf.numerics
19 import hwrf_expt
20 
21 from produtil.log import jlogger
22 from produtil.run import exe, checkrun, run
23 
24 def main():
26  conf=hwrf_expt.conf
27  if not conf.getstr('archive','wrfout',''):
28  jlogger.info('No wrfout option in [archive] section. Will not make wrfout archive.')
29  sys.exit(0)
30 
31  logger=conf.log()
32 
33  files=list()
34  dt=hwrf.numerics.to_timedelta('6:00:00')
35  t0=conf.cycle
36  wrf=hwrf_expt.runwrf.wrf()
37  with produtil.cd.NamedDir(hwrf_expt.runwrf.location):
38  for i in xrange(22):
39  for dom in wrf:
40  t=t0+dt*i
41  out=dom.get_output('auxhist3',t)
42  if out is None:
43  out=dom.get_output('history',t)
44  if out is None:
45  out=dom.get_output('auxhist2',t)
46  if out is None:
47  logger.error('%s: could not determine wrfout for '
48  'domain %s'%(t.strftime('%Y%m%d%H'),
49  str(dom)))
50  if out is not None:
51  if not os.path.exists(out.path()):
52  logger.error('%s: does not exist'%(out.path(),))
53  if not produtil.fileop.isnonempty(out.path(),):
54  logger.error('%s: is empty'%(out.path(),))
55  files.append(out.path())
56 
57  thearchive=conf.timestrinterp('archive','{wrfout}',0)
58  if thearchive[0:5]!='hpss:':
59  logger.error('The wrfout archive path must begin with "hpss:": '+
60  thearchive)
61  sys.exit(1)
62  thearchive=thearchive[5:]
63  adir=os.path.dirname(thearchive)
64  mkdir=exe(conf.getexe('hsi'))['-P','mkdir','-p',adir]
65  run(mkdir,logger=logger)
66  cmd=exe(conf.getexe('htar'))['-cpf',thearchive][files]
67  checkrun(cmd,logger=logger)
68 
69 if __name__=='__main__':
70  try:
72  jlogger.info("HWRF rundir archive job starting")
73  main()
74  jlogger.info("HWRF rundir archive job completed")
75  except Exception as e:
76  jlogger.critical('HWRF rundir archive is aborting: '+str(e),
77  exc_info=True)
78  sys.exit(2)
Change directory, handle temporary directories.
Definition: cd.py:1
def to_timedelta
Converts an object to a datetime.timedelta.
Definition: numerics.py:371
Contains setup(), which initializes the produtil package.
Definition: setup.py:1
def init_module
Initializes the HWRF object structure.
Definition: hwrf_expt.py:384
A shell-like syntax for running serial, MPI and OpenMP programs.
Definition: run.py:1
def setup(ignore_hup=False, dbnalert_logger=None, jobname=None, cluster=None, send_dbn=None, thread_logger=False, thread_stack=2 **24, kwargs)
Initializes the produtil package.
Definition: setup.py:15
def isnonempty(filename)
Returns True if the filename refers to an existent file that is non-empty, and False otherwise...
Definition: fileop.py:333
This subclass of TempDir takes a directory name, instead of generating one automatically.
Definition: cd.py:228
Time manipulation and other numerical routines.
Definition: numerics.py:1
Configures logging.
Definition: log.py:1