function plot_2D(fname,lon,lat)

% function plot_2D(fname,lon,lat)
% reads file fname in mitgcm format and contour plots it
% lon is either a vector of longitudes or a scalar length
% lat is either a vector of latitudes or a scalar length

if nargin ~= 3, error('function plot_2D requires 3 arguments'), end
if length(lon) == 1, lon=1:lon; end
if length(lat) == 1, lat=1:lat; end
nlon=length(lon); nlat=length(lat);

eval(['fid=fopen(''' fname ''',''r'',''b'');'])
tmp=fread(fid,1,'integer*8');        % fortran record length in bytes
if tmp ~= nlon*nlat*4, error('inconsistent length of fortran record'), end

fld=fread(fid,[nlon,nlat],'real*4')';
tmp=fread(fid,1,'integer*8');        % fortran record length in bytes
if tmp ~= nlon*nlat*4, error(['error reading file ' fname]), end

contourf(lon,lat,fld), colorbar('horiz')
tmp=fclose(fid);
