! Revised on 11/9/2007 to manage a single field

	module m_output

contains

	subroutine output(field,str_name,dimx,dimy,index,ntype)

	use param_run
	
        implicit none

        real(kind(0d0)), dimension(:,:), intent(in) :: field

	integer,intent(in) :: index,ntype,dimx,dimy
	character suff*3,fichier*150,le_type*1
        character*(*) str_name

        write(suff,"(i3)") index

	if (ntype == 0) write(le_type,"(a)") 'b'   ! raw data
	if (ntype == 1) write(le_type,"(a)") 'h'   ! high resolution
	if (ntype == 2) write(le_type,"(a)") 'm'   ! medium resolution
	if (ntype == 3) write(le_type,"(a)") 'l'   ! low resolution
	if (ntype == 4) write(le_type,"(a)") 'k'   ! very low resolution

        suff=trim(adjustl(suff))//le_type

 fichier=trim(adjustl(postprocessingpath))//'/'//trim(adjustl(str_name))//suff
        print*,'check in output ',fichier
        open(unit=4,file=fichier)
        write(4,'(3i5,2(3x,f7.3))') dimx,dimy,bin_sp,pixel,arcsec
        write(4,'(6(1x,1pd12.5))') field
        close(4)
!       fichier=trim(adjustl(postprocessingpath))//'/uy'//suff
!       open(unit=4,file=fichier)
!       write(4,'(3i5,2(3x,f7.3))') dimx,dimy,bin_sp,pixel,arcsec
!       write(4,'(6(1x,1pd12.5))') uy
!       close(4)
!       fichier=trim(adjustl(postprocessingpath))//'/div'//suff
!       open(unit=4,file=fichier)
!       write(4,'(3i5,2(3x,f7.3))') dimx,dimy,bin_sp,pixel,arcsec
!       write(4,'(6(1x,1pd12.5))') div/(bin_sp*pixel*arcsec)
!       close(4)
!       fichier=trim(adjustl(postprocessingpath))//'/rot'//suff
!       open(unit=4,file=fichier)
!       write(4,'(3i5,2(3x,f7.3))') dimx,dimy,bin_sp,pixel,arcsec
!       write(4,'(6(1x,1pd12.5))') rot/(bin_sp*pixel*arcsec)
!       close(4)
!       fichier=trim(adjustl(postprocessingpath))//'/err'//suff
!       open(unit=4,file=fichier)
!       write(4,'(3i5,2(3x,f7.3))') dimx,dimy,bin_sp,pixel,arcsec
!       write(4,'(6(1x,1pd12.5))') du
!       write(4,'(6(1x,1pd12.5))') ddiv/(bin_sp*pixel*arcsec)
!       close(4)

	end subroutine

	end module
