#!/usr/bin/env python
"""This script is used by the batch_generate function in the arts_scat
module. It generates an arts scattering data file. The input parameters
are passed as pickled stdin and the pickled file name is sent to stdout.
A file is only generated if an existing file with the same automatically generated filename is not present
The script is necessary to enable utilization of multiple processors from
python code."""

import sys
import cPickle
from PyARTS import arts_types
import os
import traceback

params=cPickle.load(sys.stdin)

#Calculate single scattering data
a=arts_types.SingleScatteringData(params)

fname=a.filename_gen()
if (not os.path.exists(fname)):
    a.generate()
    
#print cPickle.dumps(a.filename)
cPickle.dump(fname,sys.stdout)

sys.stdout.flush()
os.close(sys.stdin.fileno())
os.close(sys.stdout.fileno())

	 
