write_output.f90 5.5 KB

!________________________________________________________________________________

                        !DESCRIPTION: This routine create the NETCDF output
                        !file. You must have the FORTRAN NETCDF libraries
                        !installed on your computer  to use this routine.


!________________________________________________________________________________

                        !INTERFACE:
                        subroutine write_output

                        !MODULE USES:
                        use netcdf
                        use parameters

                    

                        !LOCAL PARAMETERS:

                        implicit none

                         !INCLUDES:
                        include 'netcdf.inc'

                        integer :: ncid
                        integer :: omID
                        integer :: xID
                        integer :: tID
                        integer :: SpectreID
                        integer :: om_varID
                        integer :: x_varID
                        integer :: t_varID
                        integer :: stat
                        integer :: Dmax_varID
                        integer :: Dave_varID
                        integer :: c_varID
                        integer :: h_varID
                        integer :: floeID
                        integer :: fsdID
                        integer :: floe_varID
                        integer :: SrcID
                        integer :: HsID
                        integer :: thickcatID
                        integer :: thickcat_varID
                        integer :: idtID

!_________________________________________________________________________________
stat=nf90_create(namefile,cmode=or(nf90_clobber,nf90_64bit_offset),ncid=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)

        stat=nf90_def_dim(ncid,"thickness categories",nbcat_h, thickcatID)
        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,"thickness categories",nf90_double,thickcatID,thickcat_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,"att src term",nf90_double,(/ tID, xID, omID /),SrcID)
        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,thickcatID /),fsdID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"significant height",nf90_double,(/ tID,xID /),HsID)
        call handle_err(stat)
        stat=nf90_def_var(ncid,"Ice Thickness Distribution",nf90_double,(/ xID,thickcatID /),idtID)
        call handle_err(stat)

        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,SrcID,S_ice)
        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_put_var(ncid,thickcat_varID,middle_h_cat)
        call handle_err(stat)

         stat=nf90_put_var(ncid,HsID,h_sign)
        call handle_err(stat)
        stat=nf90_put_var(ncid,idtID,IDT)
        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