#!/usr/bin/env python

# Copyright (C) 2004-2007, ENPC - INRIA - EDF R&D
#     Author(s): Vivien Mallet
#
# This file is part of the air quality modeling system Polyphemus.
#
# Polyphemus is developed in the INRIA - ENPC joint project-team CLIME and in
# the ENPC - EDF R&D joint laboratory CEREA.
#
# Polyphemus is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Polyphemus is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# For more information, visit the Polyphemus web site:
#      http://cerea.enpc.fr/polyphemus

"""
This program applies the program 'bc' to all Mozart files (available at
http://dataportal.ucar.edu/data/mozart/mozart2.2/hist/), so as to generate
boundary conditions for Polair3D over a whole (typical) year.
"""

import os, sys

nb_args = len(sys.argv) - 1

script_name = os.path.split(sys.argv[0])[1]

if (nb_args != 2 and nb_args != 3):
    print __doc__
    print "Usage:"
    print "  \"" + script_name + "\" [main configuration file] " \
          + "[secondary configuration file] [Mozart directory]"
    print "Arguments:"
    print "  [main configuration file]: main configuration file."
    print "  [secondary configuration file (optional)]: " \
          + "secondary configuration file."
    print "  [Mozart directory]: the directory in which all Mozart files " \
          + "may be found"
    print "                      (hc00XX.nc where XX ranges from 40 to 77)."
    print
    sys.exit(1)

if (nb_args == 2):
    configuration = sys.argv[1]
else:
    configuration = sys.argv[1] + " " + sys.argv[2]
mozart_dir = os.path.normpath(sys.argv[-1])

for i in range(40, 78):
    print
    print
    print "### " + mozart_dir + "/h00" + str(i) + ".nc"
    print
    os.system("nice time ./bc " \
              + configuration + " " + mozart_dir + "/h00" + str(i) + ".nc")
