! Created by Andrey Debolskiy on 14.06.2024.

program test_netcdf
    use io, only: variable_metadata, write_2d_real_nc, write_1d_real_nc
    implicit none
    integer, parameter:: nx = 100, ny = 100
    real x(nx), y(ny), temperature(nx,ny)
    character(20) fname_nc
    type(variable_metadata) :: meta_x= variable_metadata( &
            name = 'X', &
            dim_names = [character(len=32) :: 'X','', '', ''], &
            char_name = [character(len=32) :: &
                    'long_name', &
                    'units', &
                    '', '', '', '', '', '', '', ''], &
            char_value = [character(len=32) :: &
                    'X', &
                    'm', &
                    '', '', '', '', '', '', '', ''], &
            real_name = [character(len=32) :: &
                    'missing_value', &
                    'scale_factor', &
                    '', '', '', '', '', '', '', ''], &
            real_value = [&
                    -9999.9, &
                            1.0, &
                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
    type(variable_metadata) :: meta_y= variable_metadata( &
            name = 'Y', &
            dim_names = [character(len=32) :: 'Y','', '', ''], &
            char_name = [character(len=32) :: &
                    'long_name', &
                    'units', &
                    '', '', '', '', '', '', '', ''], &
            char_value = [character(len=32) :: &
                    'Y', &
                    'm', &
                    '', '', '', '', '', '', '', ''], &
            real_name = [character(len=32) :: &
                    'missing_value', &
                    'scale_factor', &
                    '', '', '', '', '', '', '', ''], &
            real_value = [&
                    -9999.9, &
                            1.0, &
                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
    type(variable_metadata) :: meta_temperature = variable_metadata( &
            name = 'T2M', &
            dim_names = [character(len=32) :: 'X','Y','', ''], &
            char_name = [character(len=32) :: &
                    'long_name', &
                    'units', &
                    '', '', '', '', '', '', '', ''], &
            char_value = [character(len=32) :: &
                    'Air Temperature', &
                    'C', &
                    '', '', '', '', '', '', '', ''], &
            real_name = [character(len=32) :: &
                    'missing_value', &
                    'scale_factor', &
                    '', '', '', '', '', '', '', ''], &
            real_value = [&
                    -9999.9, &
                            1.0, &
                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])


    fname_nc =  'test_io.nc'
    call write_1d_real_nc(x,fname_nc,meta_x)
    call write_1d_real_nc(y,fname_nc,meta_y)
    call write_2d_real_nc(temperature,fname_nc,meta_temperature)
end program test_netcdf