write_output.f90 1.97 KB
subroutine write_output

use netcdf
use parameters
implicit none
include 'netcdf.inc'
	integer :: ncid,omID,xID,tID,SpectreID
	integer :: om_varID,x_varID,t_varID,stat
	integer :: Dmax_varID,Dave_varID

stat=nf90_create(namefile,nf90_clobber,ncid)
call handle_err(stat)

        stat=nf90_def_dim(ncid,"omega", nfreq, omID)
        call handle_err(stat)

        stat=nf90_def_dim(ncid,"x_axis", nbin, xID)
        call handle_err(stat)
        stat=nf90_def_dim(ncid,"time", nsteps, tID)
        call handle_err(stat)

        stat=nf90_def_var(ncid,"omega",nf90_double,omID,om_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"x_axis",nf90_double,xID,x_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"time",nf90_double,tID,t_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Spectrum",nf90_double,(/ tID, xID, omID /),SpectreID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Dave",nf90_double,xID,Dave_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Dmax",nf90_double,xID,Dmax_varID)
        call handle_err(stat)


        !stat=nf90_put_att(ncid,ID,"units", values)
        stat=nf90_enddef(ncid)
        call handle_err(stat)
        stat=nf90_put_var(ncid,om_varID,omega)
        call handle_err(stat)
        stat=nf90_put_var(ncid,spectreID,E)
        call handle_err(stat)
        stat=nf90_put_var(ncid,Dmax_varID,Dmax)
        call handle_err(stat)
        stat=nf90_put_var(ncid,Dave_varID,Dave)
        call handle_err(stat)
        stat=nf90_put_var(ncid,t_varID,time)
        call handle_err(stat)
        stat=nf90_put_var(ncid,x_varID,x_axis)
        call handle_err(stat)




stat=nf90_close(ncid)
call handle_err(stat)
        
contains

subroutine handle_err(stat)
        integer, intent(in) :: stat

        if(stat /=nf90_noerr) then
        write(*,*)trim(nf90_strerror(stat))
        STOP 'unable de write the netcdf output' 
        end if
end subroutine handle_err



end subroutine write_output