#!/usr/bin/env python
# coding: utf-8

from datetime import datetime, timedelta

import glob
import os
import subprocess

import smartcarb as sc

script = 'main.py'
os.environ['script'] = script


#instrument = 'Sentinel_5'
#instrument = 'Sentinel_7_CO2'
instrument = 'Sentinel_7_NO2_1km'
#instrument = 'Sentinel_7_NO2_2km'
#instrument = 'Sentinel_7_NO2_4km'


if instrument == 'Sentinel_5':
    lon_eqs = [0]
else:
    lon_eqs = [0, 90, 180, 270]

if instrument == 'Sentinel_7_NO2_1km':
    delta = 400
    nproc = 18
else:
    delta = 1000
    nproc = 36

for orbit in range(0,5001,delta):
    for lon_eq in lon_eqs:
        logfile = 'logs/%s_o%04d_l%03d.log' % (instrument, orbit, lon_eq)

        args = [
            '--instrument', instrument, '--compute_orbit', '--orbit_number', str(orbit), str(orbit+delta),
            '--longitude_equator', str(lon_eq),
            '--output_path', '/scratch/snx3000/gkuhl/smartcarb/level2/%s' % instrument,
            '--cosmo_path',  '/scratch/snx3000/gkuhl/smartcarb/cosmo2D_2015-{month}/cosmo_2d_%Y%m%d%H.nc',
            '--albedo_path', '/scratch/snx3000/gkuhl/smartcarb/aux/COSMO_2D_MCD43A3.006_WSA.nc',
            '--log_level', 'WARNING', '--nproc', str(nproc)
         ]

        subprocess.call(['sbatch', '--output=%s' % logfile, 'run.job'] + args)

