import sys
import epygram



filein=sys.argv[1]
field=sys.argv[2]
time=int(sys.argv[3])
lon=float(sys.argv[4])
lat=float(sys.argv[5])

epygram.init_env()



#loads the file to be read
r = epygram.formats.resource(filein,'r')
#reads the field EVAPC_ISBA in the upper file
f = r.readfield(field)

#gets the field for the 3rd output time step 
f2 = f.getvalidity(time)
#plots the field with graphicmode=colorshades (for regular grids)
fig, ax = f2.plotfield(graphicmode='colorshades')
#plots the field with graphicmode=points (for not regular grids)
#fig, ax = f2.plotfield(graphicmode='points',pointsize=30)
#saves the plot in the file EVAPC_ISBA.png
fig.savefig(field+".png")


#extracts the time series for the point of longitude 3. and latitude 46.
f3 = f.extract_point(lon,lat)
#plots the time series
serie, ax = f3.plotfield()
#saves the time series in the file serie.png
serie.savefig("serie.png")

#plots the animation with interval of 500ms (if regular grid)
anim = f.plotanimation(interval=500,title=field)
#save the animation in file EVAPC_ISBA.mp4
anim.save(field+".mp4")



