write_output.f90 2.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,c_varID,h_varID
        integer :: floeID,fsdID,floe_varID
stat=nf90_create(namefile,nf90_clobber,ncid)
call handle_err(stat)
!__________________dimensions_______________________________
        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_dim(ncid,"floe size",nbcat, floeID)
        call handle_err(stat)

!_____________variables__________________________________________
        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,"floe size",nf90_double,floeID,floe_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_def_var(ncid,"Ice concentration",nf90_double,xID,c_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Ice thickness",nf90_double,xID,h_varID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Floe size distribution",nf90_double,(/ tID, xID,floeID /),fsdID)
        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_put_var(ncid,c_varID,C_ice)
        call handle_err(stat)
        stat=nf90_put_var(ncid,h_varID,h)
        call handle_err(stat)
        stat=nf90_put_var(ncid,fsdID,FSD)
        call handle_err(stat)
        stat=nf90_put_var(ncid,floe_varID,middle_floe_cat)
        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