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

from datetime import datetime
from multiprocessing import Pool

import os
import sys

import smartcarb as sc
import config


def run(a):
    #sc.level2.main(instrument, 0, None, None, config.path_2d_fields, config.path_level2_data, lon_eq=0.0)
    print(a[0], a[1], a[-1])
    sc.level2.main(*a)

if __name__ == '__main__':

    #starttime = datetime(2015,1,1)
    #stoptime = datetime(2015,1,5)
    #starttime = datetime(2015,7,1)
    #stoptime = datetime(2015,7,19)

    lon_eq = 0.0 # [0.0, 90., 18.0, 270.0, etc.]

    #instrument = 'Sentinel_5'
    #instrument = 'Sentinel_7_CO2'
    #instrument = 'Sentinel_7_NO2_1km' # FIXME: not working because pixel might be too small?
    #instrument = 'Sentinel_7_NO2_2km'
    #instrument = 'Sentinel_7_NO2_4km'
    instrument = sys.argv[1]
    lon_eq = int(sys.argv[2])
    print(instrument)

    # create args
    args = []
    for orbit_number in range(1000,2000):
        args += [(
            instrument, orbit_number, None, # all CO2 tracers or NO2/CO tracers plus clouds
            config.path_orbits,
            config.path_2d_fields,
            os.path.join(config.path_level2_data, instrument),
            lon_eq
        )]

    # start (S7_CO2 works with 12-18 processes)
    pool = Pool(processes=12)# (reduced to have enough memory)  config.nproc) 
    pool.map(run, sorted(args))



