
### A. Colaitis -- LMD -- 08/11/2011

def call_zrecast (  interp_mode   = '4', \
                    input_name      = None, \
                    fields  = 'all'):

    import numpy as np
    from myplot import separatenames
    from os import system

    system("rm -f zrecast.auto.def")
    system("touch zrecast.auto.def")
    indicefile=0
    outputfilename=""
    for zfile in input_name:
        system("echo "+zfile+" >> zrecast.auto.def")
        for zvar in [fields]:
            system("echo "+zvar+" >> zrecast.auto.def")
        system("echo >> zrecast.auto.def")
        if interp_mode == 4:
             append="_S"
             system("echo 3 >> zrecast.auto.def")
             system("echo yes >> zrecast.auto.def")
             system("echo 0 150000 >> zrecast.auto.def")
        elif interp_mode == 2:
             append="_P"
             system("echo 1 >> zrecast.auto.def")
             system("echo yes >> zrecast.auto.def")
             system("echo 370 0.1 >> zrecast.auto.def")  #I put that randomly! (a.c.)
             system("echo 20 >> zrecast.auto.def")
        else:
             print "zrecast interp option unsupported for now. Exiting."
             exit()
        system("zrecast.e < zrecast.auto.def")

        if indicefile is 0:
              outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
        else:
              outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
        indicefile = indicefile +1

        for i in range(len(outputfilename)):
            output_name = separatenames(outputfilename)

    return output_name

