	integer function putmap(unit, maxlats, maxlons, nlats, lats,
     &	nlons, lons, header, field)
c this function writes out the data for a mapprs-style map
c it  does not demand the map to be dense in the array
c the dimensions are specified
c author: peter rayner
c date: october 1990

c return value:
c 0 - success
c 1 - error condition

c parameters:
c unit (integer) - logical unit number (supplied)
c maxlats (maximum number of latitudes (supplied)
c maxlons - maximum number of longitudes including wrap around (supplied)
c nlats - number of latitudes in map (supplied)
c lats - real array of latitudes in header (supplied)
c nlons - number of longitudes in header (including wrap around) (supplied)
c lons - real array of longitudes in header (supplied)
c header - character header (supplied)
c field - contents of field (supplied

	integer unit, maxlats, maxlons, nlats, nlons
	real lats(maxlats), lons(maxlons), field(maxlons,maxlats)
	character*80 header


c size checks
	if( nlats .gt. maxlats) then
	  print*, 'putmap: nlats > maxlats, increase maxlats in caller'
	  stop
	endif

	if( nlons .gt. maxlons) then
	  print*, 'putmap: nlons > maxlons, increase maxlons in
     &	  caller '
	endif
c start writing elements, error escapes are to the bottom
c of the routine
	write(unit,err=1001) nlats
	write(unit,err=1002) (lats(i),i=1,nlats)
	write(unit,err=1003) nlons
	write(unit,err=1004) (lons(i),i=1,nlons)
	write(unit,err=1005) header
	write(unit,err=1006) ((field(i,j),i=1,nlons),j=1,nlats)

c success!
	putmap = 0
	return


1001	print*,'putmap: error writing nlats'
	putmap = 1
	return
1002	print*,'putmap: error writing lats'
	putmap = 1
	return
1003	print*,'putmap: error writing nlons'
	putmap = 1
	return
1004	print*,'putmap: error writing lons'
	putmap = 1
	return
1005	print*,'putmap: error writing header'
	putmap = 1
	return
1006	print*,'putmap: error writing field'
	putmap = 1
	return


c no more errors
	end

