      program nmmb2nc
!*****************************************************************************
!*
!*    This program reads the nmmb binary output history file(s) and creates 
!*    a NetCDF file.
!*
!*****************************************************************************
      use Master
      use InpOut
      implicit none
      logical :: go_on
      integer :: iarg,istep
!
!***  Gets filenames from the call arguments
!
      iarg = 1                          ! inp file
      call GETARG(iarg,file_inp)
!
!***  Reads the input config file 
!
      call readinp
!
!***  Reads the configuration table table 
!
      call readtbl
!
!***  Reads the dimensions and allocates memory
!
      call readdim
!
!***  Writes grid data in NetCDF
!
      file_nc = TRIM(file_nmm_path)//'/nmm_b.nc'
      call wri_nc_grid
!
!***  Loop over time steps
!
      istep = 1
      go_on = .true.
      do while(go_on)
         ihours_fcst = start_fcst + (istep-1)*nhours_history 
!
!***     Reads binary history file
!
         SELECT CASE (nmm_version)
         CASE('v200904rrtm_bsc1.0')
              call read_v200904rrtm_bsc10
         CASE DEFAULT
         
         END SELECT
!
!***     Convert to pressure levels
!
!
!***     Writes NetCDF
!
         call wri_nc
!
!***     Updates counter
!
         istep = istep + 1
         if( (ihours_fcst+nhours_history).gt.nhours_fcst) go_on=.false.
!
       end do
!
       call runend('OK')       
!        
       end program nmmb2nc

