A three dimensional gasdynamic model for solar wind flow past nonaxisymmetric magnetospheres: Application to Jupiter and Saturn