Changeset 1783


Ignore:
Timestamp:
Mar 6, 2016 6:36:17 PM (8 years ago)
Author:
raasch
Message:

NetCDF routines modularized; new parameter netcdf_deflate; further changes in the pmc

Location:
palm/trunk/SOURCE
Files:
33 edited
1 moved

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/Makefile

    r1780 r1783  
    2020# Current revisions:
    2121# ------------------
    22 #
     22# name change of netcdf routines and respective dependencies
    2323#
    2424# Former revisions:
     
    256256        lpm_write_exchange_statistics.f90 lpm_write_restart_file.f90 \
    257257        ls_forcing.f90 message.f90 microphysics.f90 modules.f90 mod_kinds.f90 \
    258         mod_particle_attributes.f90 netcdf.f90 nudging.f90 package_parin.f90 \
    259         palm.f90 parin.f90 plant_canopy_model.f90 pmc_interface.f90 \
     258        mod_particle_attributes.f90 netcdf_interface.f90 nudging.f90 \
     259        package_parin.f90 palm.f90 parin.f90 plant_canopy_model.f90 pmc_interface.f90 \
    260260        pmc_client.f90 pmc_general.f90 pmc_handle_communicator.f90 pmc_mpi_wrapper.f90 \
    261261        pmc_server.f90 \
     
    335335calc_spectra.o: modules.o cpulog.o fft_xy.o mod_kinds.o
    336336check_for_restart.o: modules.o mod_kinds.o
    337 check_open.o: modules.o mod_kinds.o mod_particle_attributes.o
    338 check_parameters.o: modules.o mod_kinds.o land_surface_model.o\
    339         plant_canopy_model.o pmc_interface.o radiation_model.o subsidence.o
    340 close_file.o: modules.o mod_kinds.o
     337check_open.o: modules.o mod_kinds.o mod_particle_attributes.o netcdf_interface.o
     338check_parameters.o: modules.o mod_kinds.o land_surface_model.o \
     339        netcdf_interface.o plant_canopy_model.o pmc_interface.o radiation_model.o \
     340        subsidence.o
     341close_file.o: modules.o mod_kinds.o netcdf_interface.o
    341342compute_vpt.o: modules.o mod_kinds.o
    342343coriolis.o: modules.o mod_kinds.o
     
    346347data_log.o: modules.o mod_kinds.o
    347348data_output_dvrp.o: modules.o cpulog.o mod_kinds.o
    348 data_output_mask.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o
    349 data_output_profiles.o: modules.o cpulog.o mod_kinds.o
    350 data_output_ptseries.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o
    351 data_output_spectra.o: modules.o cpulog.o mod_kinds.o
    352 data_output_tseries.o: modules.o cpulog.o mod_kinds.o
     349data_output_mask.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o \
     350   netcdf_interface.o
     351data_output_profiles.o: modules.o cpulog.o mod_kinds.o netcdf_interface.o
     352data_output_ptseries.o: modules.o cpulog.o mod_kinds.o \
     353   netcdf_interface.o mod_particle_attributes.o
     354data_output_spectra.o: modules.o cpulog.o mod_kinds.o netcdf_interface.o
     355data_output_tseries.o: modules.o cpulog.o mod_kinds.o netcdf_interface.o
    353356data_output_2d.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o\
    354                  land_surface_model.o radiation_model.o
     357   netcdf_interface.o land_surface_model.o radiation_model.o
    355358data_output_3d.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o\
    356                  land_surface_model.o
     359   netcdf_interface.o land_surface_model.o
    357360diffusion_e.o: modules.o mod_kinds.o
    358361diffusion_s.o: modules.o mod_kinds.o
     
    369372fft_xy.o: cuda_fft_interfaces.o modules.o mod_kinds.o singleton.o temperton_fft.o
    370373flow_statistics.o: modules.o cpulog.o mod_kinds.o land_surface_model.o\
    371                    radiation_model.o
     374   netcdf_interface.o radiation_model.o
    372375global_min_max.o: modules.o mod_kinds.o
    373 header.o: modules.o cpulog.o mod_kinds.o land_surface_model.o\
     376header.o: modules.o cpulog.o mod_kinds.o netcdf_interface.o land_surface_model.o\
    374377          plant_canopy_model.o pmc_interface.o radiation_model.o subsidence.o
    375378impact_of_latent_heat.o: modules.o mod_kinds.o
    376379inflow_turbulence.o: modules.o cpulog.o mod_kinds.o
    377380init_1d_model.o: modules.o mod_kinds.o
    378 init_3d_model.o: modules.o cpulog.o mod_kinds.o random_function.o advec_ws.o\
    379         land_surface_model.o ls_forcing.o lpm_init.o plant_canopy_model.o\
    380         radiation_model.o random_generator_parallel.o surface_layer_fluxes.o
     381init_3d_model.o: modules.o mod_kinds.o advec_ws.o cpulog.o land_surface_model.o \
     382   lpm_init.o ls_forcing.o netcdf_interface.o plant_canopy_model.o \
     383   radiation_model.o random_function.o random_generator_parallel.o \
     384        surface_layer_fluxes.o
    381385init_advec.o: modules.o mod_kinds.o
    382386init_cloud_physics.o: modules.o mod_kinds.o
     
    384388init_dvrp.o: modules.o mod_kinds.o
    385389init_grid.o: modules.o mod_kinds.o
    386 init_masks.o: modules.o mod_kinds.o
     390init_masks.o: modules.o mod_kinds.o netcdf_interface.o
    387391init_ocean.o: modules.o eqn_state_seawater.o mod_kinds.o
    388392init_pegrid.o: modules.o mod_kinds.o
     
    406410        mod_particle_attributes.o
    407411lpm_data_output_particles.o: modules.o cpulog.o mod_kinds.o \
    408         mod_particle_attributes.o
     412        mod_particle_attributes.o netcdf_interface.o
    409413lpm_droplet_collision.o: modules.o cpulog.o lpm_collision_kernels.o \
    410414        mod_kinds.o mod_particle_attributes.o
     
    412416        mod_kinds.o mod_particle_attributes.o
    413417lpm_exchange_horiz.o: modules.o cpulog.o lpm_pack_arrays.o mod_kinds.o \
    414         mod_particle_attributes.o
     418        mod_particle_attributes.o netcdf_interface.o
    415419lpm_extend_tails.o: modules.o mod_kinds.o mod_particle_attributes.o
    416420lpm_extend_tail_array.o: modules.o mod_kinds.o mod_particle_attributes.o
    417421lpm_init.o: modules.o lpm_collision_kernels.o mod_kinds.o \
    418         random_function.o mod_particle_attributes.o lpm_exchange_horiz.o \
    419         lpm_pack_arrays.o random_generator_parallel.o
     422        netcdf_interface.o random_function.o mod_particle_attributes.o \
     423        lpm_exchange_horiz.o lpm_pack_arrays.o random_generator_parallel.o
    420424lpm_init_sgs_tke.o: modules.o mod_kinds.o mod_particle_attributes.o
    421425lpm_pack_arrays.o: modules.o cpulog.o mod_kinds.o mod_particle_attributes.o
     
    433437mod_kinds.o: mod_kinds.f90
    434438mod_particle_attributes.o: mod_particle_attributes.f90 mod_kinds.o
    435 netcdf.o: modules.o mod_kinds.o land_surface_model.o
     439netcdf_interface.o: netcdf_interface.f90 modules.o mod_kinds.o land_surface_model.o
    436440nudging.o: modules.o cpulog.o mod_kinds.o
    437441package_parin.o: modules.o mod_kinds.o land_surface_model.o\
     
    439443palm.o: modules.o cpulog.o ls_forcing.o mod_kinds.o nudging.o\
    440444        pmc_interface.o surface_layer_fluxes.o
    441 parin.o: modules.o cpulog.o mod_kinds.o pmc_interface.o progress_bar.o
     445parin.o: modules.o cpulog.o mod_kinds.o netcdf_interface.o \
     446   pmc_interface.o progress_bar.o
    442447plant_canopy_model.o: modules.o mod_kinds.o
    443448pmc_interface.o: modules.o mod_kinds.o pmc_client.o pmc_general.o\
     
    470475                  radiation_model.o random_function.o\
    471476                  random_generator_parallel.o
    472 read_var_list.o: modules.o mod_kinds.o plant_canopy_model.o
     477read_var_list.o: modules.o mod_kinds.o netcdf_interface.o plant_canopy_model.o
    473478run_control.o: modules.o cpulog.o mod_kinds.o
    474479set_slicer_attributes_dvrp.o: modules.o mod_kinds.o
     
    497502user_additional_routines.o: modules.o mod_kinds.o user_module.o
    498503user_check_data_output.o: modules.o mod_kinds.o user_module.o
    499 user_check_data_output_pr.o: modules.o mod_kinds.o user_module.o
     504user_check_data_output_pr.o: modules.o mod_kinds.o user_module.o \
     505   netcdf_interface.o
    500506user_check_parameters.o: modules.o mod_kinds.o user_module.o
    501507user_data_output_2d.o: modules.o mod_kinds.o user_module.o
     
    506512user_dvrp_coltab.o: modules.o mod_kinds.o user_module.o
    507513user_header.o: modules.o mod_kinds.o user_module.o
    508 user_init.o: modules.o mod_kinds.o user_module.o
     514user_init.o: modules.o mod_kinds.o netcdf_interface.o user_module.o
    509515user_init_3d_model.o: modules.o mod_kinds.o user_module.o
    510516user_init_grid.o: modules.o mod_kinds.o user_module.o
     
    520526user_read_restart_data.o: modules.o mod_kinds.o user_module.o
    521527user_spectra.o: modules.o mod_kinds.o user_module.o
    522 user_statistics.o: modules.o mod_kinds.o user_module.o
     528user_statistics.o: modules.o mod_kinds.o netcdf_interface.o user_module.o
    523529wall_fluxes.o: modules.o mod_kinds.o
    524530write_3d_binary.o: modules.o cpulog.o mod_kinds.o land_surface_model.o\
    525531                   radiation_model.o random_function.o\
    526532                   random_generator_parallel.o
    527 write_var_list.o: modules.o mod_kinds.o plant_canopy_model.o
     533write_var_list.o: modules.o mod_kinds.o netcdf_interface.o plant_canopy_model.o
  • palm/trunk/SOURCE/check_open.f90

    r1780 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    106106    USE control_parameters,                                                    &
    107107        ONLY:  avs_data_file, coupling_char, data_output_2d_on_each_pe, host,  &
    108                message_string, mid, netcdf_data_format, nz_do3d, openfile,     &
     108               max_masks, message_string, mid, nz_do3d, openfile,              &
    109109               return_addres, return_username, run_description_header, runnr
    110110
     
    117117    USE kinds
    118118
    119     USE netcdf_control
     119#if defined( __netcdf )
     120    USE NETCDF
     121#endif
     122
     123    USE netcdf_interface,                                                      &
     124        ONLY:  id_set_mask, id_set_pr, id_set_prt, id_set_pts, id_set_sp,      &
     125               id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, nc_stat, &
     126               netcdf_create_file, netcdf_data_format, netcdf_define_header,   &
     127               netcdf_handle_error, netcdf_open_write_file
    120128
    121129    USE particle_attributes,                                                   &
     
    649657!
    650658!--          Open an existing netCDF file for output
    651              CALL open_write_netcdf_file( filename, id_set_xy(av), .TRUE., 20 )
     659             CALL netcdf_open_write_file( filename, id_set_xy(av), .TRUE., 20 )
    652660!
    653661!--          Read header information and set all ids. If there is a mismatch
    654662!--          between the previuos and the actual run, netcdf_extend is returned
    655663!--          as .FALSE.
    656              CALL define_netcdf_header( 'xy', netcdf_extend, av )
     664             CALL netcdf_define_header( 'xy', netcdf_extend, av )
    657665
    658666!
     
    660668             IF ( .NOT. netcdf_extend )  THEN
    661669                nc_stat = NF90_CLOSE( id_set_xy(av) )
    662                 CALL handle_netcdf_error( 'check_open', 21 )
     670                CALL netcdf_handle_error( 'check_open', 21 )
    663671                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
    664672#if defined( __parallel ) && ! defined ( __check )
     
    675683!
    676684!--          Create a new netCDF output file with requested netCDF format
    677              CALL create_netcdf_file( filename, id_set_xy(av), .TRUE., 22 )
     685             CALL netcdf_create_file( filename, id_set_xy(av), .TRUE., 22 )
    678686
    679687!
    680688!--          Define the header
    681              CALL define_netcdf_header( 'xy', netcdf_extend, av )
     689             CALL netcdf_define_header( 'xy', netcdf_extend, av )
    682690
    683691!
     
    711719!
    712720!--          Open an existing netCDF file for output
    713              CALL open_write_netcdf_file( filename, id_set_xz(av), .TRUE., 23 )
     721             CALL netcdf_open_write_file( filename, id_set_xz(av), .TRUE., 23 )
    714722!
    715723!--          Read header information and set all ids. If there is a mismatch
    716724!--          between the previuos and the actual run, netcdf_extend is returned
    717725!--          as .FALSE.
    718              CALL define_netcdf_header( 'xz', netcdf_extend, av )
     726             CALL netcdf_define_header( 'xz', netcdf_extend, av )
    719727
    720728!
     
    722730             IF ( .NOT. netcdf_extend )  THEN
    723731                nc_stat = NF90_CLOSE( id_set_xz(av) )
    724                 CALL handle_netcdf_error( 'check_open', 24 )
     732                CALL netcdf_handle_error( 'check_open', 24 )
    725733                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
    726734#if defined( __parallel ) && ! defined ( __check )
     
    737745!
    738746!--          Create a new netCDF output file with requested netCDF format
    739              CALL create_netcdf_file( filename, id_set_xz(av), .TRUE., 25 )
     747             CALL netcdf_create_file( filename, id_set_xz(av), .TRUE., 25 )
    740748
    741749!
    742750!--          Define the header
    743              CALL define_netcdf_header( 'xz', netcdf_extend, av )
     751             CALL netcdf_define_header( 'xz', netcdf_extend, av )
    744752
    745753!
     
    773781!
    774782!--          Open an existing netCDF file for output
    775              CALL open_write_netcdf_file( filename, id_set_yz(av), .TRUE., 26 )
     783             CALL netcdf_open_write_file( filename, id_set_yz(av), .TRUE., 26 )
    776784!
    777785!--          Read header information and set all ids. If there is a mismatch
    778786!--          between the previuos and the actual run, netcdf_extend is returned
    779787!--          as .FALSE.
    780              CALL define_netcdf_header( 'yz', netcdf_extend, av )
     788             CALL netcdf_define_header( 'yz', netcdf_extend, av )
    781789
    782790!
     
    784792             IF ( .NOT. netcdf_extend )  THEN
    785793                nc_stat = NF90_CLOSE( id_set_yz(av) )
    786                 CALL handle_netcdf_error( 'check_open', 27 )
     794                CALL netcdf_handle_error( 'check_open', 27 )
    787795                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
    788796#if defined( __parallel ) && ! defined ( __check )
     
    799807!
    800808!--          Create a new netCDF output file with requested netCDF format
    801              CALL create_netcdf_file( filename, id_set_yz(av), .TRUE., 28 )
     809             CALL netcdf_create_file( filename, id_set_yz(av), .TRUE., 28 )
    802810
    803811!
    804812!--          Define the header
    805              CALL define_netcdf_header( 'yz', netcdf_extend, av )
     813             CALL netcdf_define_header( 'yz', netcdf_extend, av )
    806814
    807815!
     
    829837!
    830838!--          Open an existing netCDF file for output
    831              CALL open_write_netcdf_file( filename, id_set_pr, .FALSE., 29 )
     839             CALL netcdf_open_write_file( filename, id_set_pr, .FALSE., 29 )
    832840!
    833841!--          Read header information and set all ids. If there is a mismatch
    834842!--          between the previuos and the actual run, netcdf_extend is returned
    835843!--          as .FALSE.
    836              CALL define_netcdf_header( 'pr', netcdf_extend, 0 )
     844             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
    837845
    838846!
     
    840848             IF ( .NOT. netcdf_extend )  THEN
    841849                nc_stat = NF90_CLOSE( id_set_pr )
    842                 CALL handle_netcdf_error( 'check_open', 30 )
     850                CALL netcdf_handle_error( 'check_open', 30 )
    843851                CALL local_system( 'rm ' // TRIM( filename ) )
    844852             ENDIF
     
    849857!
    850858!--          Create a new netCDF output file with requested netCDF format
    851              CALL create_netcdf_file( filename, id_set_pr, .FALSE., 31 )
     859             CALL netcdf_create_file( filename, id_set_pr, .FALSE., 31 )
    852860!
    853861!--          Define the header
    854              CALL define_netcdf_header( 'pr', netcdf_extend, 0 )
     862             CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
    855863
    856864          ENDIF
     
    869877!
    870878!--          Open an existing netCDF file for output
    871              CALL open_write_netcdf_file( filename, id_set_ts, .FALSE., 32 )
     879             CALL netcdf_open_write_file( filename, id_set_ts, .FALSE., 32 )
    872880!
    873881!--          Read header information and set all ids. If there is a mismatch
    874882!--          between the previuos and the actual run, netcdf_extend is returned
    875883!--          as .FALSE.
    876              CALL define_netcdf_header( 'ts', netcdf_extend, 0 )
     884             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
    877885
    878886!
     
    880888             IF ( .NOT. netcdf_extend )  THEN
    881889                nc_stat = NF90_CLOSE( id_set_ts )
    882                 CALL handle_netcdf_error( 'check_open', 33 )
     890                CALL netcdf_handle_error( 'check_open', 33 )
    883891                CALL local_system( 'rm ' // TRIM( filename ) )
    884892             ENDIF
     
    889897!
    890898!--          Create a new netCDF output file with requested netCDF format
    891              CALL create_netcdf_file( filename, id_set_ts, .FALSE., 34 )
     899             CALL netcdf_create_file( filename, id_set_ts, .FALSE., 34 )
    892900!
    893901!--          Define the header
    894              CALL define_netcdf_header( 'ts', netcdf_extend, 0 )
     902             CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
    895903
    896904          ENDIF
     
    916924!
    917925!--          Open an existing netCDF file for output
    918              CALL open_write_netcdf_file( filename, id_set_3d(av), .TRUE., 35 )
     926             CALL netcdf_open_write_file( filename, id_set_3d(av), .TRUE., 35 )
    919927!
    920928!--          Read header information and set all ids. If there is a mismatch
    921929!--          between the previuos and the actual run, netcdf_extend is returned
    922930!--          as .FALSE.
    923              CALL define_netcdf_header( '3d', netcdf_extend, av )
     931             CALL netcdf_define_header( '3d', netcdf_extend, av )
    924932
    925933!
     
    927935             IF ( .NOT. netcdf_extend )  THEN
    928936                nc_stat = NF90_CLOSE( id_set_3d(av) )
    929                 CALL handle_netcdf_error( 'check_open', 36 )
     937                CALL netcdf_handle_error( 'check_open', 36 )
    930938                IF ( myid == 0 )  CALL local_system( 'rm ' // TRIM( filename ) )
    931939#if defined( __parallel ) && ! defined ( __check )
     
    943951!
    944952!--          Create a new netCDF output file with requested netCDF format
    945              CALL create_netcdf_file( filename, id_set_3d(av), .TRUE., 37 )
     953             CALL netcdf_create_file( filename, id_set_3d(av), .TRUE., 37 )
    946954
    947955!
    948956!--          Define the header
    949              CALL define_netcdf_header( '3d', netcdf_extend, av )
     957             CALL netcdf_define_header( '3d', netcdf_extend, av )
    950958
    951959!
     
    974982!
    975983!--          Open an existing netCDF file for output
    976              CALL open_write_netcdf_file( filename, id_set_sp, .FALSE., 38 )
     984             CALL netcdf_open_write_file( filename, id_set_sp, .FALSE., 38 )
    977985
    978986!
     
    980988!--          between the previuos and the actual run, netcdf_extend is returned
    981989!--          as .FALSE.
    982              CALL define_netcdf_header( 'sp', netcdf_extend, 0 )
     990             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
    983991
    984992!
     
    986994             IF ( .NOT. netcdf_extend )  THEN
    987995                nc_stat = NF90_CLOSE( id_set_sp )
    988                 CALL handle_netcdf_error( 'check_open', 39 )
     996                CALL netcdf_handle_error( 'check_open', 39 )
    989997                CALL local_system( 'rm ' // TRIM( filename ) )
    990998             ENDIF
     
    9951003!
    9961004!--          Create a new netCDF output file with requested netCDF format
    997              CALL create_netcdf_file( filename, id_set_sp, .FALSE., 40 )
     1005             CALL netcdf_create_file( filename, id_set_sp, .FALSE., 40 )
    9981006!
    9991007!--          Define the header
    1000              CALL define_netcdf_header( 'sp', netcdf_extend, 0 )
     1008             CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
    10011009
    10021010          ENDIF
     
    10191027!
    10201028!--          Open an existing netCDF file for output
    1021              CALL open_write_netcdf_file( filename, id_set_prt, .FALSE., 41 )
     1029             CALL netcdf_open_write_file( filename, id_set_prt, .FALSE., 41 )
    10221030!
    10231031!--          Read header information and set all ids. If there is a mismatch
    10241032!--          between the previuos and the actual run, netcdf_extend is returned
    10251033!--          as .FALSE.
    1026              CALL define_netcdf_header( 'pt', netcdf_extend, 0 )
     1034             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
    10271035
    10281036!
     
    10301038             IF ( .NOT. netcdf_extend )  THEN
    10311039                nc_stat = NF90_CLOSE( id_set_prt )
    1032                 CALL handle_netcdf_error( 'check_open', 42 )
     1040                CALL netcdf_handle_error( 'check_open', 42 )
    10331041                CALL local_system( 'rm ' // TRIM( filename ) )
    10341042             ENDIF
     
    10561064!
    10571065!--          Create a new netCDF output file with requested netCDF format
    1058              CALL create_netcdf_file( filename, id_set_prt, .FALSE., 43 )
     1066             CALL netcdf_create_file( filename, id_set_prt, .FALSE., 43 )
    10591067
    10601068!
    10611069!--          Define the header
    1062              CALL define_netcdf_header( 'pt', netcdf_extend, 0 )
     1070             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
    10631071
    10641072          ENDIF
     
    10771085!
    10781086!--          Open an existing netCDF file for output
    1079              CALL open_write_netcdf_file( filename, id_set_pts, .FALSE., 393 )
     1087             CALL netcdf_open_write_file( filename, id_set_pts, .FALSE., 393 )
    10801088!
    10811089!--          Read header information and set all ids. If there is a mismatch
    10821090!--          between the previuos and the actual run, netcdf_extend is returned
    10831091!--          as .FALSE.
    1084              CALL define_netcdf_header( 'ps', netcdf_extend, 0 )
     1092             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
    10851093
    10861094!
     
    10881096             IF ( .NOT. netcdf_extend )  THEN
    10891097                nc_stat = NF90_CLOSE( id_set_pts )
    1090                 CALL handle_netcdf_error( 'check_open', 394 )
     1098                CALL netcdf_handle_error( 'check_open', 394 )
    10911099                CALL local_system( 'rm ' // TRIM( filename ) )
    10921100             ENDIF
     
    10971105!
    10981106!--          Create a new netCDF output file with requested netCDF format
    1099              CALL create_netcdf_file( filename, id_set_pts, .FALSE., 395 )
     1107             CALL netcdf_create_file( filename, id_set_pts, .FALSE., 395 )
    11001108!
    11011109!--          Define the header
    1102              CALL define_netcdf_header( 'ps', netcdf_extend, 0 )
     1110             CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
    11031111
    11041112          ENDIF
     
    11381146!
    11391147!--          Open an existing netCDF file for output
    1140              CALL open_write_netcdf_file( filename, id_set_mask(mid,av),       &
     1148             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
    11411149                                          .TRUE., 456 )
    11421150!
     
    11441152!--          between the previuos and the actual run, netcdf_extend is returned
    11451153!--          as .FALSE.
    1146              CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
     1154             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
    11471155
    11481156!
     
    11501158             IF ( .NOT. netcdf_extend )  THEN
    11511159                nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
    1152                 CALL handle_netcdf_error( 'check_open', 457 )
     1160                CALL netcdf_handle_error( 'check_open', 457 )
    11531161                CALL local_system('rm ' // TRIM( filename ) )
    11541162             ENDIF
     
    11591167!
    11601168!--          Create a new netCDF output file with requested netCDF format
    1161              CALL create_netcdf_file( filename, id_set_mask(mid,av), .TRUE., 458 )
     1169             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
    11621170!
    11631171!--          Define the header
    1164              CALL define_netcdf_header( 'ma', netcdf_extend, file_id )
     1172             CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
    11651173
    11661174          ENDIF
  • palm/trunk/SOURCE/check_parameters.f90

    r1765 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf variables and module name changed,
     22! check of netcdf precision removed (is done in the netcdf module)
    2223!
    2324! Former revisions:
     
    312313    USE kinds
    313314    USE model_1d
    314     USE netcdf_control
     315    USE netcdf_interface,                                                      &
     316        ONLY:  dopr_unit, do2d_unit, do3d_unit, netcdf_data_format,            &
     317               netcdf_data_format_string
    315318    USE particle_attributes
    316319    USE pegrid
     
    350353   
    351354    LOGICAL     ::  found                            !<
    352     LOGICAL     ::  ldum                             !<
    353355   
    354356    REAL(wp)    ::  gradient                         !<
     
    37333735    SELECT CASE ( netcdf_data_format )
    37343736       CASE ( 1 )
    3735           output_format_netcdf = 'netCDF classic'
     3737          netcdf_data_format_string = 'netCDF classic'
    37363738       CASE ( 2 )
    3737           output_format_netcdf = 'netCDF 64bit offset'
     3739          netcdf_data_format_string = 'netCDF 64bit offset'
    37383740       CASE ( 3 )
    3739           output_format_netcdf = 'netCDF4/HDF5'
     3741          netcdf_data_format_string = 'netCDF4/HDF5'
    37403742       CASE ( 4 )
    3741           output_format_netcdf = 'netCDF4/HDF5 classic'
     3743          netcdf_data_format_string = 'netCDF4/HDF5 classic'
    37423744       CASE ( 5 )
    3743           output_format_netcdf = 'parallel netCDF4/HDF5'
     3745          netcdf_data_format_string = 'parallel netCDF4/HDF5'
    37443746       CASE ( 6 )
    3745           output_format_netcdf = 'parallel netCDF4/HDF5 classic'
     3747          netcdf_data_format_string = 'parallel netCDF4/HDF5 classic'
    37463748
    37473749    END SELECT
     
    38643866    ENDIF
    38653867
    3866 #if ! defined( __check )
    3867 !
    3868 !-- Check netcdf precison
    3869     ldum = .FALSE.
    3870     CALL define_netcdf_header( 'ch', ldum, 0 )
    3871 #endif
    38723868!
    38733869!-- Check, whether a constant diffusion coefficient shall be used
  • palm/trunk/SOURCE/close_file.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    6565
    6666    USE control_parameters,                                                    &
    67         ONLY:  do2d_xz_n, do2d_xy_n, do2d_yz_n, do3d_avs_n,                    &
    68                host, max_masks, mid, netcdf_data_format,                       &
    69                nz_do3d, openfile, run_description_header,       &
    70                z_max_do2d
     67        ONLY:  do2d_xz_n, do2d_xy_n, do2d_yz_n, do3d_avs_n, host, max_masks,   &
     68               mid, nz_do3d, openfile, run_description_header, z_max_do2d
    7169               
    7270    USE grid_variables,                                                        &
     
    7876    USE kinds
    7977   
    80     USE netcdf_control
     78#if defined( __netcdf )
     79    USE NETCDF
     80#endif
     81
     82    USE netcdf_interface,                                                      &
     83        ONLY:  id_set_mask, id_set_pr, id_set_prt, id_set_pts, id_set_sp,      &
     84               id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, nc_stat, &
     85               netcdf_data_format, netcdf_handle_error
    8186               
    8287    USE pegrid                                           
     
    132137                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    133138                   nc_stat = NF90_CLOSE( id_set_xy(0) )
    134                    CALL handle_netcdf_error( 'close_file', 44 )
     139                   CALL netcdf_handle_error( 'close_file', 44 )
    135140                ENDIF
    136141
     
    139144                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    140145                   nc_stat = NF90_CLOSE( id_set_xz(0) )
    141                    CALL handle_netcdf_error( 'close_file', 45 )
     146                   CALL netcdf_handle_error( 'close_file', 45 )
    142147                ENDIF
    143148
     
    146151                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    147152                   nc_stat = NF90_CLOSE( id_set_yz(0) )
    148                    CALL handle_netcdf_error( 'close_file', 46 )
     153                   CALL netcdf_handle_error( 'close_file', 46 )
    149154                ENDIF
    150155
     
    153158                IF ( myid == 0 )  THEN
    154159                   nc_stat = NF90_CLOSE( id_set_pr )
    155                    CALL handle_netcdf_error( 'close_file', 47 )
     160                   CALL netcdf_handle_error( 'close_file', 47 )
    156161                ENDIF
    157162
     
    160165                IF ( myid == 0 )  THEN
    161166                   nc_stat = NF90_CLOSE( id_set_ts )
    162                    CALL handle_netcdf_error( 'close_file', 48 )
     167                   CALL netcdf_handle_error( 'close_file', 48 )
    163168                ENDIF
    164169
     
    167172                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    168173                   nc_stat = NF90_CLOSE( id_set_3d(0) )
    169                    CALL handle_netcdf_error( 'close_file', 49 )
     174                   CALL netcdf_handle_error( 'close_file', 49 )
    170175                ENDIF
    171176
     
    174179                IF ( myid == 0 )  THEN
    175180                   nc_stat = NF90_CLOSE( id_set_sp )
    176                    CALL handle_netcdf_error( 'close_file', 50 )
     181                   CALL netcdf_handle_error( 'close_file', 50 )
    177182                ENDIF
    178183
     
    180185
    181186                nc_stat = NF90_CLOSE( id_set_prt )
    182                 CALL handle_netcdf_error( 'close_file', 51 )
     187                CALL netcdf_handle_error( 'close_file', 51 )
    183188
    184189             CASE ( 109 )
    185190
    186191                nc_stat = NF90_CLOSE( id_set_pts )
    187                 CALL handle_netcdf_error( 'close_file', 412 )
     192                CALL netcdf_handle_error( 'close_file', 412 )
    188193
    189194             CASE ( 111 )
     
    191196                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    192197                   nc_stat = NF90_CLOSE( id_set_xy(1) )
    193                    CALL handle_netcdf_error( 'close_file', 52 )
     198                   CALL netcdf_handle_error( 'close_file', 52 )
    194199                ENDIF
    195200
     
    198203                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    199204                   nc_stat = NF90_CLOSE( id_set_xz(1) )
    200                    CALL handle_netcdf_error( 'close_file', 352 )
     205                   CALL netcdf_handle_error( 'close_file', 352 )
    201206                ENDIF
    202207
     
    205210                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    206211                   nc_stat = NF90_CLOSE( id_set_yz(1) )
    207                    CALL handle_netcdf_error( 'close_file', 353 )
     212                   CALL netcdf_handle_error( 'close_file', 353 )
    208213                ENDIF
    209214
     
    212217                IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
    213218                   nc_stat = NF90_CLOSE( id_set_3d(1) )
    214                    CALL handle_netcdf_error( 'close_file', 353 )
     219                   CALL netcdf_handle_error( 'close_file', 353 )
    215220                ENDIF
    216221
     
    228233                   ENDIF
    229234                   nc_stat = NF90_CLOSE( id_set_mask(mid,av) )
    230                    CALL handle_netcdf_error( 'close_file', 459 )
     235                   CALL netcdf_handle_error( 'close_file', 459 )
    231236               
    232237                ENDIF
  • palm/trunk/SOURCE/data_output_2d.f90

    r1746 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    141141               do2d_yz_last_time, do2d_yz_n, do2d_yz_time_count,               &
    142142               ibc_uv_b, icloud_scheme, io_blocks, io_group,                   &
    143                message_string, netcdf_data_format,                             &
     143               message_string,                             &
    144144               ntdim_2d_xy, ntdim_2d_xz, ntdim_2d_yz, psolver, section,        &
    145145               simulated_time,  simulated_time_chr, time_since_reference_point
     
    165165               shf_eb_av, t_soil, t_soil_av, zs
    166166   
    167     USE netcdf_control
     167#if defined( __netcdf )
     168    USE NETCDF
     169#endif
     170
     171    USE netcdf_interface,                                                      &
     172        ONLY:  id_set_xy, id_set_xz, id_set_yz, id_var_do2d, id_var_time_xy,   &
     173               id_var_time_xz, id_var_time_yz, nc_stat, netcdf_data_format,    &
     174               netcdf_handle_error
    168175
    169176    USE particle_attributes,                                                   &
     
    13221329                                         start = (/ do2d_xy_time_count(av) /), &
    13231330                                                    count = (/ 1 /) )
    1324                             CALL handle_netcdf_error( 'data_output_2d', 53 )
     1331                            CALL netcdf_handle_error( 'data_output_2d', 53 )
    13251332#endif
    13261333                         ENDIF
     
    14431450                                             count = (/ nx+2, ny+2, 1, 1 /) )
    14441451                            ENDIF
    1445                             CALL handle_netcdf_error( 'data_output_2d', 54 )
     1452                            CALL netcdf_handle_error( 'data_output_2d', 54 )
    14461453#endif
    14471454
     
    14811488                                           count = (/ nx+2, ny+2, 1, 1 /) )
    14821489                   ENDIF
    1483                    CALL handle_netcdf_error( 'data_output_2d', 447 )
     1490                   CALL netcdf_handle_error( 'data_output_2d', 447 )
    14841491#endif
    14851492#endif
     
    15111518                                         start = (/ do2d_xz_time_count(av) /), &
    15121519                                                    count = (/ 1 /) )
    1513                             CALL handle_netcdf_error( 'data_output_2d', 56 )
     1520                            CALL netcdf_handle_error( 'data_output_2d', 56 )
    15141521#endif
    15151522                         ENDIF
     
    16661673                            start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
    16671674                                             count = (/ nx+2, 1, nzt_do-nzb_do+1, 1 /) )
    1668                             CALL handle_netcdf_error( 'data_output_2d', 58 )
     1675                            CALL netcdf_handle_error( 'data_output_2d', 58 )
    16691676#endif
    16701677
     
    17071714                            start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
    17081715                                           count = (/ nx+2, 1, nzt_do-nzb_do+1, 1 /) )
    1709                    CALL handle_netcdf_error( 'data_output_2d', 451 )
     1716                   CALL netcdf_handle_error( 'data_output_2d', 451 )
    17101717#endif
    17111718#endif
     
    17301737                                         start = (/ do2d_yz_time_count(av) /), &
    17311738                                                    count = (/ 1 /) )
    1732                             CALL handle_netcdf_error( 'data_output_2d', 59 )
     1739                            CALL netcdf_handle_error( 'data_output_2d', 59 )
    17331740#endif
    17341741                         ENDIF
     
    18851892                            start = (/ is, 1, 1, do2d_yz_time_count(av) /), &
    18861893                                             count = (/ 1, ny+2, nzt_do-nzb_do+1, 1 /) )
    1887                             CALL handle_netcdf_error( 'data_output_2d', 61 )
     1894                            CALL netcdf_handle_error( 'data_output_2d', 61 )
    18881895#endif
    18891896
     
    19261933                            start = (/ is, 1, 1, do2d_xz_time_count(av) /), &
    19271934                                           count = (/ 1, ny+2, nzt_do-nzb_do+1, 1 /) )
    1928                    CALL handle_netcdf_error( 'data_output_2d', 452 )
     1935                   CALL netcdf_handle_error( 'data_output_2d', 452 )
    19291936#endif
    19301937#endif
     
    19972004                      ENDIF   
    19982005
    1999                       CALL handle_netcdf_error( 'data_output_2d', 55 )
     2006                      CALL netcdf_handle_error( 'data_output_2d', 55 )
    20002007
    20012008                   CASE ( 'xz' )
     
    20472054                      ENDIF
    20482055
    2049                       CALL handle_netcdf_error( 'data_output_2d', 57 )
     2056                      CALL netcdf_handle_error( 'data_output_2d', 57 )
    20502057
    20512058                   CASE ( 'yz' )
     
    20972104                      ENDIF
    20982105
    2099                       CALL handle_netcdf_error( 'data_output_2d', 60 )
     2106                      CALL netcdf_handle_error( 'data_output_2d', 60 )
    21002107
    21012108                   CASE DEFAULT
  • palm/trunk/SOURCE/data_output_3d.f90

    r1746 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    118118        ONLY:  avs_data_file, cloud_physics, do3d, do3d_avs_n,                 &
    119119               do3d_no, do3d_time_count, io_blocks, io_group,                  &
    120                message_string, netcdf_data_format, ntdim_3d,                   &
     120               message_string, ntdim_3d,                                       &
    121121               nz_do3d, plot_3d_precision, psolver, simulated_time,            &
    122122               simulated_time_chr, skip_do_avs, time_since_reference_point
     
    134134        ONLY: m_soil, m_soil_av, nzb_soil, nzt_soil, t_soil, t_soil_av
    135135
    136     USE netcdf_control
     136#if defined( __netcdf )
     137    USE NETCDF
     138#endif
     139
     140    USE netcdf_interface,                                                      &
     141        ONLY:  id_set_3d, id_var_do3d, id_var_time_3d, nc_stat,                &
     142               netcdf_data_format, netcdf_handle_error
    137143       
    138144    USE particle_attributes,                                                   &
     
    228234                               start = (/ do3d_time_count(av) /),           &
    229235                               count = (/ 1 /) )
    230        CALL handle_netcdf_error( 'data_output_3d', 376 )
     236       CALL netcdf_handle_error( 'data_output_3d', 376 )
    231237    ENDIF
    232238#endif
     
    688694                count = (/ nxr-nxl+1, nyn-nys+1, nzt_do-nzb_do+1, 1 /) )
    689695          ENDIF
    690           CALL handle_netcdf_error( 'data_output_3d', 386 )
     696          CALL netcdf_handle_error( 'data_output_3d', 386 )
    691697#endif
    692698       ENDIF
     
    697703                         start = (/ 1, 1, 1, do3d_time_count(av) /),     &
    698704                         count = (/ nx+2, ny+2, nzt_do-nzb_do+1, 1 /) )
    699        CALL handle_netcdf_error( 'data_output_3d', 446 )
     705       CALL netcdf_handle_error( 'data_output_3d', 446 )
    700706#endif
    701707#endif
  • palm/trunk/SOURCE/data_output_mask.f90

    r1692 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes,
     22! switch back of netcdf data format moved from time integration routine to here
    2223!
    2324! Former revisions:
     
    9697   
    9798    USE control_parameters,                                                    &
    98         ONLY:  cloud_physics, domask, domask_no, domask_time_count,            &
    99                mask_i, mask_j, mask_k, mask_size, mask_size_l,                 &
    100                mask_start_l, max_masks, message_string, mid,                   &
    101                netcdf_data_format, nz_do3d, simulated_time
     99        ONLY:  cloud_physics, domask, domask_no, domask_time_count, mask_i,    &
     100               mask_j, mask_k, mask_size, mask_size_l, mask_start_l,           &
     101               max_masks, message_string, mid, nz_do3d, simulated_time
    102102    USE cpulog,                                                                &
    103103        ONLY:  cpu_log, log_point
    104104
    105 
    106    
    107105    USE indices,                                                               &
    108106        ONLY:  nbgp, nxl, nxr, nyn, nys, nzb, nzt
     
    110108    USE kinds
    111109   
    112     USE netcdf
    113    
    114     USE netcdf_control
     110    USE NETCDF
     111   
     112    USE netcdf_interface,                                                      &
     113        ONLY:  id_set_mask, id_var_domask, id_var_time_mask, nc_stat,          &
     114               netcdf_data_format, netcdf_handle_error
    115115   
    116116    USE particle_attributes,                                                   &
     
    136136    INTEGER(iwp) ::  k        !<
    137137    INTEGER(iwp) ::  n        !<
     138    INTEGER(iwp) ::  netcdf_data_format_save !<
    138139    INTEGER(iwp) ::  psi      !<
    139140    INTEGER(iwp) ::  sender   !<
     
    158159
    159160    CALL cpu_log (log_point(49),'data_output_mask','start')
     161
     162!
     163!-- Parallel netcdf output is not tested so far for masked data, hence
     164!-- netcdf_data_format is switched back to non-paralell output.
     165    netcdf_data_format_save = netcdf_data_format
     166    IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
     167    IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
    160168
    161169!
     
    183191                               start = (/ domask_time_count(mid,av) /),       &
    184192                               count = (/ 1 /) )
    185        CALL handle_netcdf_error( 'data_output_mask', 460 )
     193       CALL netcdf_handle_error( 'data_output_mask', 460 )
    186194    ENDIF
    187195
     
    564572               count = (/ mask_size_l(mid,1), mask_size_l(mid,2),  &
    565573                          mask_size_l(mid,3), 1 /) )
    566           CALL handle_netcdf_error( 'data_output_mask', 461 )
     574          CALL netcdf_handle_error( 'data_output_mask', 461 )
    567575       ELSE
    568576#endif
     
    611619                  count = (/ mask_size(mid,1), mask_size(mid,2), &
    612620                             mask_size(mid,3), 1 /) )
    613              CALL handle_netcdf_error( 'data_output_mask', 462 )
     621             CALL netcdf_handle_error( 'data_output_mask', 462 )
    614622
    615623          ELSE
     
    656664            count = (/ mask_size_l(mid,1), mask_size_l(mid,2), &
    657665                       mask_size_l(mid,3), 1 /) )
    658        CALL handle_netcdf_error( 'data_output_mask', 463 )
     666       CALL netcdf_handle_error( 'data_output_mask', 463 )
    659667#endif
    660668
     
    672680#endif
    673681
     682!
     683!-- Switch back to original format given by user (see beginning of this routine)
     684    netcdf_data_format = netcdf_data_format_save
    674685
    675686    CALL cpu_log( log_point(49), 'data_output_mask', 'stop' )
  • palm/trunk/SOURCE/data_output_profiles.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    8686    USE kinds
    8787
    88     USE netcdf_control
     88#if defined( __netcdf )
     89    USE NETCDF
     90#endif
     91
     92    USE netcdf_interface,                                                      &
     93        ONLY:  id_set_pr, id_var_dopr, id_var_norm_dopr, id_var_time_pr,       &
     94               nc_stat, netcdf_handle_error, output_for_t0
    8995
    9096    USE pegrid
     
    155161                                        (/ -coupling_start_time /), &
    156162                                        start = (/ 1 /), count = (/ 1 /) )
    157                    CALL handle_netcdf_error( 'data_output_profiles', 329 )
     163                   CALL netcdf_handle_error( 'data_output_profiles', 329 )
    158164                   output_for_t0 = .TRUE.
    159165                   EXIT
     
    166172                                  (/ hom_sum(nzb,18,normalizing_region) /), &
    167173                                     start = (/ 1 /), count = (/ 1 /) )
    168              CALL handle_netcdf_error( 'data_output_profiles', 330 )
     174             CALL netcdf_handle_error( 'data_output_profiles', 330 )
    169175
    170176             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), & ! ws2
    171177                        (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /), &
    172178                                     start = (/ 1 /), count = (/ 1 /) )
    173              CALL handle_netcdf_error( 'data_output_profiles', 331 )
     179             CALL netcdf_handle_error( 'data_output_profiles', 331 )
    174180             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), & ! tsw2
    175181                        (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
    176182                                  start = (/ 1 /), count = (/ 1 /) )
    177              CALL handle_netcdf_error( 'data_output_profiles', 332 )
     183             CALL netcdf_handle_error( 'data_output_profiles', 332 )
    178184             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), & ! ws3
    179185                        (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /), &
    180186                                     start = (/ 1 /), count = (/ 1 /) )
    181              CALL handle_netcdf_error( 'data_output_profiles', 333 )
     187             CALL netcdf_handle_error( 'data_output_profiles', 333 )
    182188
    183189             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &!ws2tsw
     
    185191                           hom_sum(nzb+3,pr_palm,normalizing_region)    /), &
    186192                                     start = (/ 1 /), count = (/ 1 /) )
    187              CALL handle_netcdf_error( 'data_output_profiles', 334 )
     193             CALL netcdf_handle_error( 'data_output_profiles', 334 )
    188194
    189195             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &!wstsw2
     
    191197                           hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
    192198                                     start = (/ 1 /), count = (/ 1 /) )
    193              CALL handle_netcdf_error( 'data_output_profiles', 335 )
     199             CALL netcdf_handle_error( 'data_output_profiles', 335 )
    194200
    195201             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), & ! z_i
    196202                           (/ hom_sum(nzb+6,pr_palm,normalizing_region) /), &
    197203                                     start = (/ 1 /), count = (/ 1 /) )
    198              CALL handle_netcdf_error( 'data_output_profiles', 336 )
     204             CALL netcdf_handle_error( 'data_output_profiles', 336 )
    199205             
    200206#endif
     
    216222                                              start = (/ 1, 1 /),              &
    217223                                              count = (/ nzt-nzb+2, 1 /) )
    218                       CALL handle_netcdf_error( 'data_output_profiles', 337 )
     224                      CALL netcdf_handle_error( 'data_output_profiles', 337 )
    219225#endif
    220226
     
    240246                               start = (/ dopr_time_count /),    &
    241247                               count = (/ 1 /) )
    242        CALL handle_netcdf_error( 'data_output_profiles', 338 )
     248       CALL netcdf_handle_error( 'data_output_profiles', 338 )
    243249
    244250!
     
    248254                               start = (/ dopr_time_count /),               &
    249255                               count = (/ 1 /) )
    250        CALL handle_netcdf_error( 'data_output_profiles', 339 )
     256       CALL netcdf_handle_error( 'data_output_profiles', 339 )
    251257
    252258       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
     
    254260                               start = (/ dopr_time_count /),               &
    255261                               count = (/ 1 /) )
    256        CALL handle_netcdf_error( 'data_output_profiles', 340 )
     262       CALL netcdf_handle_error( 'data_output_profiles', 340 )
    257263
    258264       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
     
    260266                               start = (/ dopr_time_count /),               &
    261267                               count = (/ 1 /) )
    262        CALL handle_netcdf_error( 'data_output_profiles', 341 )
     268       CALL netcdf_handle_error( 'data_output_profiles', 341 )
    263269
    264270       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
     
    266272                               start = (/ dopr_time_count /),               &
    267273                               count = (/ 1 /) )
    268        CALL handle_netcdf_error( 'data_output_profiles', 342 )
     274       CALL netcdf_handle_error( 'data_output_profiles', 342 )
    269275
    270276       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
     
    273279                               start = (/ dopr_time_count /),               &
    274280                               count = (/ 1 /) )
    275        CALL handle_netcdf_error( 'data_output_profiles', 343 )
     281       CALL netcdf_handle_error( 'data_output_profiles', 343 )
    276282
    277283       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
     
    280286                               start = (/ dopr_time_count /),               &
    281287                               count = (/ 1 /) )
    282        CALL handle_netcdf_error( 'data_output_profiles', 344 )
     288       CALL netcdf_handle_error( 'data_output_profiles', 344 )
    283289
    284290       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
     
    286292                               start = (/ dopr_time_count /),               &
    287293                               count = (/ 1 /) )
    288        CALL handle_netcdf_error( 'data_output_profiles', 345 )
     294       CALL netcdf_handle_error( 'data_output_profiles', 345 )
    289295#endif
    290296
     
    304310                                     start = (/ 1, dopr_time_count /),      &
    305311                                     count = (/ nzt-nzb+2, 1 /) )
    306              CALL handle_netcdf_error( 'data_output_profiles', 346 )
     312             CALL netcdf_handle_error( 'data_output_profiles', 346 )
    307313#endif
    308314
  • palm/trunk/SOURCE/data_output_ptseries.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    8181    USE kinds
    8282
    83     USE netcdf_control
     83#if defined( __netcdf )
     84    USE NETCDF
     85#endif
     86
     87    USE netcdf_interface,                                                      &
     88        ONLY:  dopts_num, id_set_pts, id_var_dopts, id_var_time_pts, nc_stat,  &
     89               netcdf_handle_error
    8490
    8591    USE particle_attributes,                                                   &
     
    116122                               (/ time_since_reference_point /), &
    117123                               start = (/ dopts_time_count /), count = (/ 1 /) )
    118        CALL handle_netcdf_error( 'data_output_ptseries', 391 )
     124       CALL netcdf_handle_error( 'data_output_ptseries', 391 )
    119125#endif
    120126
     
    375381                                     start = (/ dopts_time_count /), &
    376382                                     count = (/ 1 /) )
    377              CALL handle_netcdf_error( 'data_output_ptseries', 392 )
     383             CALL netcdf_handle_error( 'data_output_ptseries', 392 )
    378384          ENDDO
    379385       ENDDO
  • palm/trunk/SOURCE/data_output_spectra.f90

    r1683 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    6969 SUBROUTINE data_output_spectra
    7070 
     71#if defined( __netcdf )
    7172#if defined( __spectra )
    7273
     
    8182    USE kinds
    8283
    83     USE netcdf_control
     84    USE NETCDF
     85
     86    USE netcdf_interface,                                                      &
     87        ONLY:  id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error
    8488
    8589    USE pegrid
     
    116120       dosp_time_count = dosp_time_count + 1
    117121
    118 #if defined( __netcdf )
    119122!
    120123!--    Update the spectra time axis
     
    122125                               (/ time_since_reference_point /), &
    123126                               start = (/ dosp_time_count /), count = (/ 1 /) )
    124        CALL handle_netcdf_error( 'data_output_spectra', 47 )
    125 #endif
     127       CALL netcdf_handle_error( 'data_output_spectra', 47 )
    126128
    127129!
     
    201203
    202204#endif
     205#endif
    203206 END SUBROUTINE data_output_spectra
    204207
     
    226229    USE kinds
    227230
    228     USE netcdf_control
     231    USE NETCDF
     232
     233    USE netcdf_interface,                                                      &
     234        ONLY:  id_set_sp, id_var_dospx, id_var_dospy, nc_stat,                 &
     235               netcdf_handle_error
    229236
    230237    USE spectrum,                                                              &
     
    261268                                  start = (/ 1, k, dosp_time_count /), &
    262269                                  count = (/ nx/2, 1, 1 /) )
    263           CALL handle_netcdf_error( 'data_output_spectra', 348 )
     270          CALL netcdf_handle_error( 'data_output_spectra', 348 )
    264271
    265272       ENDDO
     
    279286                                  start = (/ 1, k, dosp_time_count /), &
    280287                                  count = (/ ny/2, 1, 1 /) )
    281           CALL handle_netcdf_error( 'data_output_spectra', 349 )
     288          CALL netcdf_handle_error( 'data_output_spectra', 349 )
    282289
    283290       ENDDO
  • palm/trunk/SOURCE/data_output_tseries.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    7272    USE kinds
    7373
    74     USE netcdf_control
     74#if defined( __netcdf )
     75    USE NETCDF
     76#endif
     77    USE netcdf_interface,                                                      &
     78        ONLY:  dots_num, id_set_ts, id_var_dots, id_var_time_ts, nc_stat,      &
     79               netcdf_handle_error
    7580
    7681    USE pegrid
     
    115120                               start = (/ dots_time_count /),    &
    116121                               count = (/ 1 /) )
    117        CALL handle_netcdf_error( 'data_output_tseries', 350 )
     122       CALL netcdf_handle_error( 'data_output_tseries', 350 )
    118123#endif
    119124
     
    129134                                     start = (/ dots_time_count /), &
    130135                                     count = (/ 1 /) )
    131              CALL handle_netcdf_error( 'data_output_tseries', 351 )
     136             CALL netcdf_handle_error( 'data_output_tseries', 351 )
    132137          ENDDO
    133138#endif
  • palm/trunk/SOURCE/flow_statistics.f90

    r1748 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! +module netcdf_interface
    2222!
    2323! Former revisions:
     
    207207   
    208208    USE land_surface_model_mod,                                                &
    209         ONLY:   dots_soil, ghf_eb, land_surface, m_soil, nzb_soil, nzt_soil,   &
     209        ONLY:   ghf_eb, land_surface, m_soil, nzb_soil, nzt_soil,              &
    210210                qsws_eb, qsws_liq_eb, qsws_soil_eb, qsws_veg_eb, r_a, r_s,     &
    211211                shf_eb, t_soil
    212212
     213    USE netcdf_interface,                                                      &
     214        ONLY:  dots_rad, dots_soil
     215
    213216    USE pegrid
    214217
    215218    USE radiation_model_mod,                                                   &
    216         ONLY:  dots_rad, radiation, radiation_scheme, rad_net,                 &
     219        ONLY:  radiation, radiation_scheme, rad_net,                           &
    217220               rad_lw_in, rad_lw_out, rad_lw_cs_hr, rad_lw_hr,                 &
    218221               rad_sw_in, rad_sw_out, rad_sw_cs_hr, rad_sw_hr
  • palm/trunk/SOURCE/header.f90

    r1765 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module and variable names changed, output of netcdf_deflate
    2222!
    2323! Former revisions:
     
    249249        ONLY:  damp_level_ind_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
    250250       
     251    USE netcdf_interface,                                                      &
     252        ONLY:  netcdf_data_format, netcdf_data_format_string, netcdf_deflate
     253
    251254    USE particle_attributes,                                                   &
    252255        ONLY:  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, collision_kernel,     &
     
    13151318
    13161319       output_format = ''
    1317        output_format = output_format_netcdf
    1318        WRITE ( io, 344 )  output_format
     1320       output_format = netcdf_data_format_string
     1321       IF ( netcdf_deflate == 0 )  THEN
     1322          WRITE ( io, 344 )  output_format
     1323       ELSE
     1324          WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1325       ENDIF
    13191326
    13201327       DO  i = 1, dopr_n
     
    13791386
    13801387          output_format = ''
    1381           output_format = output_format_netcdf
    1382           WRITE ( io, 344 )  output_format
     1388          output_format = netcdf_data_format_string
     1389          IF ( netcdf_deflate == 0 )  THEN
     1390             WRITE ( io, 344 )  output_format
     1391          ELSE
     1392             WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1393          ENDIF
    13831394
    13841395          IF ( do2d_xy /= ''  .AND.  section(1,1) /= -9999 )  THEN
     
    15361547          ENDIF
    15371548
    1538           output_format = output_format_netcdf
    1539           WRITE ( io, 344 )  output_format
     1549          output_format = netcdf_data_format_string
     1550          IF ( netcdf_deflate == 0 )  THEN
     1551             WRITE ( io, 344 )  output_format
     1552          ELSE
     1553             WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1554          ENDIF
    15401555
    15411556          IF ( do3d_at_begin )  THEN
     
    15951610             ENDIF
    15961611
    1597              output_format = output_format_netcdf
     1612             output_format = netcdf_data_format_string
    15981613!--          Parallel output not implemented for mask data, hence
    15991614!--          output_format must be adjusted.
    16001615             IF ( netcdf_data_format == 5 ) output_format = 'netCDF4/HDF5'
    16011616             IF ( netcdf_data_format == 6 ) output_format = 'netCDF4/HDF5 classic'
    1602              WRITE ( io, 344 )  output_format
     1617             IF ( netcdf_deflate == 0 )  THEN
     1618                WRITE ( io, 344 )  output_format
     1619             ELSE
     1620                WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1621             ENDIF
    16031622
    16041623             IF ( av == 0 )  THEN
     
    16501669       WRITE ( io, 340 )
    16511670
    1652        output_format = output_format_netcdf
    1653        WRITE ( io, 344 )  output_format
     1671       output_format = netcdf_data_format_string
     1672       IF ( netcdf_deflate == 0 )  THEN
     1673          WRITE ( io, 344 )  output_format
     1674       ELSE
     1675          WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1676       ENDIF
    16541677       WRITE ( io, 341 )  dt_dots
    16551678    ENDIF
     
    17131736       WRITE ( io, 370 )
    17141737
    1715        output_format = output_format_netcdf
    1716        WRITE ( io, 344 )  output_format
     1738       output_format = netcdf_data_format_string
     1739       IF ( netcdf_deflate == 0 )  THEN
     1740          WRITE ( io, 344 )  output_format
     1741       ELSE
     1742          WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1743       ENDIF
    17171744       WRITE ( io, 371 )  dt_dosp
    17181745       IF ( skip_time_dosp /= 0.0_wp )  WRITE ( io, 339 )  skip_time_dosp
     
    18641891             output_format = 'netcdf and binary'
    18651892          ENDIF
    1866           WRITE ( io, 344 )  output_format
     1893          IF ( netcdf_deflate == 0 )  THEN
     1894             WRITE ( io, 344 )  output_format
     1895          ELSE
     1896             WRITE ( io, 354 )  TRIM( output_format ), netcdf_deflate
     1897          ENDIF
    18671898       ENDIF
    18681899       IF ( dt_dopts /= 9999999.9_wp )  WRITE ( io, 494 )  dt_dopts
     
    21762207352 FORMAT  (/'       Number of output time levels allowed: ',I3 /)
    21772208353 FORMAT  (/'       Number of output time levels allowed: unlimited' /)
     2209354 FORMAT ('       Output format: ',A, '   compressed with level: ',I1/)
    21782210#if defined( __dvrp_graphics )
    21792211360 FORMAT ('    Plot-Sequence with dvrp-software:'/ &
  • palm/trunk/SOURCE/init_3d_model.f90

    r1765 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    262262        ONLY:  e1d, kh1d, km1d, l1d, rif1d, u1d, us1d, usws1d, v1d, vsws1d
    263263   
    264     USE netcdf_control
     264    USE netcdf_interface,                                                      &
     265        ONLY:  dots_max, dots_num
    265266   
    266267    USE particle_attributes,                                                   &
  • palm/trunk/SOURCE/init_masks.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    9696               mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z,   &
    9797               mask_z_loop, max_masks,  message_string, mid,                   &
    98                netcdf_data_format, passive_scalar, precipitation, ocean
     98               passive_scalar, precipitation, ocean
    9999
    100100    USE grid_variables,                                                        &
     
    106106    USE kinds
    107107
    108     USE netcdf_control
     108    USE netcdf_interface,                                                      &
     109        ONLY:  domask_unit, netcdf_data_format
    109110
    110111    USE particle_attributes,                                                   &
  • palm/trunk/SOURCE/land_surface_model.f90

    r1758 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf variables moved to netcdf module
    2222!
    2323! Former revisions:
     
    132132    USE kinds
    133133
    134     USE netcdf_control,                                                        &
    135         ONLY:  dots_label, dots_num, dots_unit
    136 
    137134    USE pegrid
    138135
     
    157154                               nzt_soil = 3, & !< top of the soil model (to be switched)
    158155                               nzs = 4         !< number of soil layers (fixed for now)
    159 
    160     INTEGER(iwp) :: dots_soil = 0  !< starting index for timeseries output
    161 
    162     INTEGER(iwp), DIMENSION(0:1) :: id_dim_zs_xy, id_dim_zs_xz, id_dim_zs_yz,  &
    163                                     id_dim_zs_3d, id_var_zs_xy,                &
    164                                     id_var_zs_xz, id_var_zs_yz, id_var_zs_3d
    165                                    
    166     INTEGER(iwp), DIMENSION(1:max_masks,0:1) :: id_dim_zs_mask, id_var_zs_mask
    167156
    168157    REAL(wp), PARAMETER ::                     &
     
    519508
    520509!
    521 !-- Public grid and NetCDF variables
    522     PUBLIC dots_soil, id_dim_zs_xy, id_dim_zs_xz, id_dim_zs_yz,                &
    523            id_dim_zs_3d, id_dim_zs_mask, id_var_zs_xy, id_var_zs_xz,           &
    524            id_var_zs_yz, id_var_zs_3d, id_var_zs_mask, nzb_soil, nzs, nzt_soil,&
    525            zs
     510!-- Public grid variables
     511    PUBLIC nzb_soil, nzs, nzt_soil, zs
    526512
    527513!
     
    928914                                                statistic_regions+1 )
    929915
    930 !
    931 !--    Add timeseries for land surface model
    932        dots_soil = dots_num + 1
    933        dots_num  = dots_num + 8
    934 
    935        dots_label(dots_soil) = "ghf_eb"
    936        dots_label(dots_soil+1) = "shf_eb"
    937        dots_label(dots_soil+2) = "qsws_eb"
    938        dots_label(dots_soil+3) = "qsws_liq_eb"
    939        dots_label(dots_soil+4) = "qsws_soil_eb"
    940        dots_label(dots_soil+5) = "qsws_veg_eb"
    941        dots_label(dots_soil+6) = "r_a"
    942        dots_label(dots_soil+7) = "r_s"
    943 
    944        dots_unit(dots_soil:dots_soil+5) = "W/m2"
    945        dots_unit(dots_soil+6:dots_soil+7) = "s/m"
    946 
    947 
    948916    END SUBROUTINE init_lsm
    949917
  • palm/trunk/SOURCE/lpm_data_output_particles.f90

    r1683 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! name change of netcdf routines and module + related changes
    2222!
    2323! Former revisions:
     
    6565    USE kinds
    6666
    67     USE netcdf_control
     67    USE netcdf_interface,                                                      &
     68        ONLY:  nc_stat
    6869
    6970    USE particle_attributes,                                                   &
     
    122123!                             (/ simulated_time /),        &
    123124!                             start = (/ prt_time_count /), count = (/ 1 /) )
    124 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 1 )
     125!     CALL netcdf_handle_error( 'lpm_data_output_particles', 1 )
    125126!
    126127! !
     
    129130!                             (/ number_of_particles /),   &
    130131!                             start = (/ prt_time_count /), count = (/ 1 /) )
    131 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 2 )
     132!     CALL netcdf_handle_error( 'lpm_data_output_particles', 2 )
    132133!
    133134! !
     
    136137!                             start = (/ 1, prt_time_count /),               &
    137138!                             count = (/ maximum_number_of_particles /) )
    138 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 3 )
     139!     CALL netcdf_handle_error( 'lpm_data_output_particles', 3 )
    139140!
    140141!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(2), particles%dvrp_psize,&
    141142!                             start = (/ 1, prt_time_count /),                &
    142143!                             count = (/ maximum_number_of_particles /) )
    143 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 4 )
     144!     CALL netcdf_handle_error( 'lpm_data_output_particles', 4 )
    144145!
    145146!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(3), particles%origin_x, &
    146147!                             start = (/ 1, prt_time_count /),               &
    147148!                             count = (/ maximum_number_of_particles /) )
    148 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 5 )
     149!     CALL netcdf_handle_error( 'lpm_data_output_particles', 5 )
    149150!
    150151!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(4), particles%origin_y, &
    151152!                             start = (/ 1, prt_time_count /),               &
    152153!                             count = (/ maximum_number_of_particles /) )
    153 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 6 )
     154!     CALL netcdf_handle_error( 'lpm_data_output_particles', 6 )
    154155!
    155156!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(5), particles%origin_z, &
    156157!                             start = (/ 1, prt_time_count /),               &
    157158!                             count = (/ maximum_number_of_particles /) )
    158 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 7 )
     159!     CALL netcdf_handle_error( 'lpm_data_output_particles', 7 )
    159160!
    160161!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(6), particles%radius,   &
    161162!                             start = (/ 1, prt_time_count /),               &
    162163!                             count = (/ maximum_number_of_particles /) )
    163 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 8 )
     164!     CALL netcdf_handle_error( 'lpm_data_output_particles', 8 )
    164165!
    165166!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(7), particles%speed_x,  &
    166167!                             start = (/ 1, prt_time_count /),               &
    167168!                             count = (/ maximum_number_of_particles /) )
    168 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 9 )
     169!     CALL netcdf_handle_error( 'lpm_data_output_particles', 9 )
    169170!
    170171!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(8), particles%speed_y,  &
    171172!                             start = (/ 1, prt_time_count /),               &
    172173!                             count = (/ maximum_number_of_particles /) )
    173 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 10 )
     174!     CALL netcdf_handle_error( 'lpm_data_output_particles', 10 )
    174175!
    175176!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(9), particles%speed_z,  &
    176177!                             start = (/ 1, prt_time_count /),               &
    177178!                             count = (/ maximum_number_of_particles /) )
    178 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 11 )
     179!     CALL netcdf_handle_error( 'lpm_data_output_particles', 11 )
    179180!
    180181!     nc_stat = NF90_PUT_VAR( id_set_prt,id_var_prt(10),                     &
     
    182183!                             start = (/ 1, prt_time_count /),               &
    183184!                             count = (/ maximum_number_of_particles /) )
    184 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 12 )
     185!     CALL netcdf_handle_error( 'lpm_data_output_particles', 12 )
    185186!
    186187!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(11), particles%x,       &
    187188!                             start = (/ 1, prt_time_count /),               &
    188189!                             count = (/ maximum_number_of_particles /) )
    189 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 13 )
     190!     CALL netcdf_handle_error( 'lpm_data_output_particles', 13 )
    190191!
    191192!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(12), particles%y,       &
    192193!                             start = (/ 1, prt_time_count /),               &
    193194!                             count = (/ maximum_number_of_particles /) )
    194 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 14 )
     195!     CALL netcdf_handle_error( 'lpm_data_output_particles', 14 )
    195196!
    196197!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(13), particles%z,       &
    197198!                             start = (/ 1, prt_time_count /),               &
    198199!                             count = (/ maximum_number_of_particles /) )
    199 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 15 )
     200!     CALL netcdf_handle_error( 'lpm_data_output_particles', 15 )
    200201!
    201202!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(14), particles%class,   &
    202203!                             start = (/ 1, prt_time_count /),               &
    203204!                             count = (/ maximum_number_of_particles /) )
    204 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 16 )
     205!     CALL netcdf_handle_error( 'lpm_data_output_particles', 16 )
    205206!
    206207!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(15), particles%group,   &
    207208!                             start = (/ 1, prt_time_count /),               &
    208209!                             count = (/ maximum_number_of_particles /) )
    209 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 17 )
     210!     CALL netcdf_handle_error( 'lpm_data_output_particles', 17 )
    210211!
    211212!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(16),                    &
     
    213214!                             start = (/ 1, prt_time_count /),               &
    214215!                             count = (/ maximum_number_of_particles /) )
    215 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 18 )
     216!     CALL netcdf_handle_error( 'lpm_data_output_particles', 18 )
    216217!
    217218!     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(17), particles%tail_id, &
    218219!                             start = (/ 1, prt_time_count /),               &
    219220!                             count = (/ maximum_number_of_particles /) )
    220 !     CALL handle_netcdf_error( 'lpm_data_output_particles', 19 )
     221!     CALL netcdf_handle_error( 'lpm_data_output_particles', 19 )
    221222!
    222223#endif
  • palm/trunk/SOURCE/lpm_exchange_horiz.f90

    r1692 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! new netcdf-module included
    2222!
    2323! Former revisions:
     
    7070
    7171    USE control_parameters,                                                    &
    72         ONLY:  dz, message_string, netcdf_data_format, simulated_time
     72        ONLY:  dz, message_string, simulated_time
    7373
    7474    USE cpulog,                                                                &
     
    8585    USE lpm_pack_arrays_mod,                                                   &
    8686        ONLY:  lpm_pack_arrays
     87
     88    USE netcdf_interface,                                                      &
     89        ONLY:  netcdf_data_format
    8790
    8891    USE particle_attributes,                                                   &
  • palm/trunk/SOURCE/lpm_init.f90

    r1726 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module added
    2222!
    2323! Former revisions:
     
    108108    USE control_parameters,                                                    &
    109109        ONLY:  cloud_droplets, constant_flux_layer, current_timestep_number,   &
    110                dz, initializing_actions, message_string, netcdf_data_format,   &
    111                ocean, simulated_time
     110               dz, initializing_actions, message_string, ocean, simulated_time
    112111
    113112    USE dvrp_variables,                                                        &
     
    125124    USE lpm_collision_kernels_mod,                                             &
    126125        ONLY:  init_kernels
     126
     127    USE netcdf_interface,                                                      &
     128        ONLY:  netcdf_data_format
    127129
    128130    USE particle_attributes,                                                   &
  • palm/trunk/SOURCE/lpm_release_set.f90

    r1683 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! module control_parameters removed
    2222!
    2323! Former revisions:
     
    5858 SUBROUTINE lpm_release_set
    5959 
    60 
    61     USE control_parameters,                                                    &
    62         ONLY:  iran, message_string, netcdf_data_format
    6360
    6461    USE lpm_init_mod,                                                          &
  • palm/trunk/SOURCE/modules.f90

    r1780 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! netcdf variables moved to the netcdf-interface module
    2222!
    2323! Former revisions:
     
    614614                             return_addres, return_username, &
    615615                             timestep_scheme = 'runge-kutta-3'                             
    616     CHARACTER (LEN=40)   ::  avs_data_file, output_format_netcdf, &
    617                              topography = 'flat'
     616    CHARACTER (LEN=40)   ::  avs_data_file, topography = 'flat'
    618617    CHARACTER (LEN=64)   ::  host = ' '
    619618    CHARACTER (LEN=80)   ::  log_message, run_identifier
     
    629628    CHARACTER (LEN=20), DIMENSION(300) ::  data_output_pr = ' '
    630629    CHARACTER (LEN=20), DIMENSION(200) ::  data_output_pr_user = ' '
    631     CHARACTER (LEN=20), DIMENSION(11)  ::  netcdf_precision = ' '
    632 
    633630    CHARACTER (LEN=20), DIMENSION(max_masks,0:1,100) ::  domask = ' '
    634631    CHARACTER (LEN=20), DIMENSION(0:1,100) ::  do2d = ' ', do3d = ' '
     
    653650                     maximum_parallel_io_streams = -1, max_pr_user = 0, &
    654651                     mgcycles = 0, mg_cycles = -1, mg_switch_to_pe0_level = 0, mid, &
    655                      nlsf = 1000, ntnudge = 1000, netcdf_data_format = 2, ngsrb = 2, &
     652                     nlsf = 1000, ntnudge = 1000, ngsrb = 2, &
    656653                     nr_timesteps_this_run = 0, &
    657654                     nsor = 20, nsor_ini = 100, n_sor, normalizing_region = 0, &
     
    11531150
    11541151
    1155 !------------------------------------------------------------------------------!
    1156 ! Description:
    1157 ! ------------
    1158 !> Definition of parameters and variables for netcdf control.
    1159 !------------------------------------------------------------------------------!
    1160  MODULE netcdf_control
    1161 
    1162     USE control_parameters, ONLY: max_masks
    1163     USE kinds
    1164 #if defined( __netcdf )
    1165     USE netcdf
    1166 #endif
    1167 
    1168     INTEGER(iwp), PARAMETER ::  dopr_norm_num = 7, dopts_num = 29, dots_max = 100
    1169 
    1170     INTEGER(iwp) ::  dots_num = 23
    1171 
    1172     CHARACTER (LEN=6), DIMENSION(dopr_norm_num) ::  dopr_norm_names =          &
    1173          (/ 'wpt0  ', 'ws2   ', 'tsw2  ', 'ws3   ', 'ws2tsw', 'wstsw2',        &
    1174             'z_i   ' /)
    1175 
    1176     CHARACTER (LEN=6), DIMENSION(dopr_norm_num) ::  dopr_norm_longnames =      &
    1177          (/ 'wpt0  ', 'w*2   ', 't*w2  ', 'w*3   ', 'w*2t*w', 'w*t*w2',        &
    1178             'z_i   ' /)
    1179 
    1180     CHARACTER (LEN=7), DIMENSION(dopts_num) :: dopts_label =                   &
    1181           (/ 'tnpt   ', 'x_     ', 'y_     ', 'z_     ', 'z_abs  ', 'u      ', &
    1182              'v      ', 'w      ', 'u"     ', 'v"     ', 'w"     ', 'npt_up ', &
    1183              'w_up   ', 'w_down ', 'radius ', 'r_min  ', 'r_max  ', 'npt_max', &
    1184              'npt_min', 'x*2    ', 'y*2    ', 'z*2    ', 'u*2    ', 'v*2    ', &
    1185              'w*2    ', 'u"2    ', 'v"2    ', 'w"2    ', 'npt*2  ' /)
    1186 
    1187     CHARACTER (LEN=7), DIMENSION(dopts_num) :: dopts_unit =                    &
    1188           (/ 'number ', 'm      ', 'm      ', 'm      ', 'm      ', 'm/s    ', &
    1189              'm/s    ', 'm/s    ', 'm/s    ', 'm/s    ', 'm/s    ', 'number ', &
    1190              'm/s    ', 'm/s    ', 'm      ', 'm      ', 'm      ', 'number ', &
    1191              'number ', 'm2     ', 'm2     ', 'm2     ', 'm2/s2  ', 'm2/s2  ', &
    1192              'm2/s2  ', 'm2/s2  ', 'm2/s2  ', 'm2/s2  ', 'number2' /)
    1193 
    1194     CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_label =                    &
    1195           (/ 'E            ', 'E*           ', 'dt           ',                &
    1196              'u*           ', 'th*          ', 'umax         ',                &
    1197              'vmax         ', 'wmax         ', 'div_new      ',                &
    1198              'div_old      ', 'z_i_wpt      ', 'z_i_pt       ',                &
    1199              'w*           ', 'w"pt"0       ', 'w"pt"        ',                &
    1200              'wpt          ', 'pt(0)        ', 'pt(z_mo)     ',                &
    1201              'w"u"0        ', 'w"v"0        ', 'w"q"0        ',                &
    1202              'ol           ', 'q*           ',                                 &
    1203              ( 'unknown      ', i9 = 1, dots_max-23 ) /)
    1204 
    1205     CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_unit =                     &
    1206           (/ 'm2/s2        ', 'm2/s2        ', 's            ',                &
    1207              'm/s          ', 'K            ', 'm/s          ',                &
    1208              'm/s          ', 'm/s          ', 's-1          ',                &
    1209              's-1          ', 'm            ', 'm            ',                &
    1210              'm/s          ', 'K m/s        ', 'K m/s        ',                &
    1211              'K m/s        ', 'K            ', 'K            ',                &
    1212              'm2/s2        ', 'm2/s2        ', 'kg m/s       ',                &
    1213              'm            ', 'kg/kg        ',                                 &
    1214              ( 'unknown      ', i9 = 1, dots_max-23 ) /)
    1215 
    1216     CHARACTER (LEN=9), DIMENSION(300) ::  dopr_unit = 'unknown'
    1217 
    1218     CHARACTER (LEN=7), DIMENSION(0:1,100) ::  do2d_unit, do3d_unit
    1219 
    1220     CHARACTER (LEN=16), DIMENSION(25) ::  prt_var_names = &
    1221           (/ 'pt_age          ', 'pt_dvrp_size    ', 'pt_origin_x     ', &
    1222              'pt_origin_y     ', 'pt_origin_z     ', 'pt_radius       ', &
    1223              'pt_speed_x      ', 'pt_speed_y      ', 'pt_speed_z      ', &
    1224              'pt_weight_factor', 'pt_x            ', 'pt_y            ', &
    1225              'pt_z            ', 'pt_color        ', 'pt_group        ', &
    1226              'pt_tailpoints   ', 'pt_tail_id      ', 'pt_density_ratio', &
    1227              'pt_exp_arg      ', 'pt_exp_term     ', 'not_used        ', &
    1228              'not_used        ', 'not_used        ', 'not_used        ', &
    1229              'not_used        ' /)
    1230 
    1231     CHARACTER (LEN=16), DIMENSION(25) ::  prt_var_units = &
    1232           (/ 'seconds         ', 'meters          ', 'meters          ', &
    1233              'meters          ', 'meters          ', 'meters          ', &
    1234              'm/s             ', 'm/s             ', 'm/s             ', &
    1235              'factor          ', 'meters          ', 'meters          ', &
    1236              'meters          ', 'none            ', 'none            ', &
    1237              'none            ', 'none            ', 'ratio           ', &
    1238              'none            ', 'none            ', 'not_used        ', &
    1239              'not_used        ', 'not_used        ', 'not_used        ', &
    1240              'not_used        ' /)
    1241 
    1242     INTEGER(iwp) ::  id_dim_prtnum, id_dim_time_pr, id_dim_time_prt, &
    1243                      id_dim_time_pts, id_dim_time_sp, id_dim_time_ts, id_dim_x_sp, &
    1244                      id_dim_y_sp, id_dim_zu_sp, id_dim_zw_sp, id_set_pr, &
    1245                      id_set_prt, id_set_pts, id_set_sp, id_set_ts, id_var_prtnum, &
    1246                      id_var_rnop_prt, id_var_time_pr, id_var_time_prt, &
    1247                      id_var_time_pts, id_var_time_sp, id_var_time_ts, id_var_x_sp, &
    1248                      id_var_y_sp, id_var_zu_sp, id_var_zw_sp, nc_stat
    1249 
    1250     INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_xy, id_dim_time_xz, &
    1251                     id_dim_time_yz, id_dim_time_3d, id_dim_x_xy, id_dim_xu_xy, &
    1252                     id_dim_x_xz, id_dim_xu_xz, id_dim_x_yz, id_dim_xu_yz, &
    1253                     id_dim_x_3d, id_dim_xu_3d, id_dim_y_xy, id_dim_yv_xy, &
    1254                     id_dim_y_xz, id_dim_yv_xz, id_dim_y_yz, id_dim_yv_yz, &
    1255                     id_dim_y_3d, id_dim_yv_3d, id_dim_zu_xy, id_dim_zu1_xy, &
    1256                     id_dim_zu_xz, id_dim_zu_yz, id_dim_zu_3d, id_dim_zw_xy, &
    1257                     id_dim_zw_xz, id_dim_zw_yz, id_dim_zw_3d, id_set_xy, &
    1258                     id_set_xz, id_set_yz, id_set_3d, id_var_ind_x_yz, &
    1259                     id_var_ind_y_xz, id_var_ind_z_xy, id_var_time_xy, &
    1260                     id_var_time_xz, id_var_time_yz, id_var_time_3d, id_var_x_xy, &
    1261                     id_var_xu_xy, id_var_x_xz, id_var_xu_xz, id_var_x_yz, &
    1262                     id_var_xu_yz, id_var_x_3d, id_var_xu_3d, id_var_y_xy, &
    1263                     id_var_yv_xy, id_var_y_xz, id_var_yv_xz, id_var_y_yz, &
    1264                     id_var_yv_yz, id_var_y_3d, id_var_yv_3d, id_var_zusi_xy, &
    1265                     id_var_zusi_3d, id_var_zu_xy, id_var_zu1_xy, id_var_zu_xz, &
    1266                     id_var_zu_yz, id_var_zu_3d, id_var_zwwi_xy, id_var_zwwi_3d, &
    1267                     id_var_zw_xy, id_var_zw_xz, id_var_zw_yz, id_var_zw_3d
    1268 
    1269     INTEGER(iwp), DIMENSION(10)  ::  id_var_dospx, id_var_dospy
    1270     INTEGER(iwp), DIMENSION(20)  ::  id_var_prt
    1271     INTEGER(iwp), DIMENSION(11)  ::  nc_precision
    1272     INTEGER(iwp), DIMENSION(dopr_norm_num) ::  id_var_norm_dopr
    1273 
    1274     INTEGER(iwp), DIMENSION(dopts_num,0:10) ::  id_var_dopts
    1275     INTEGER(iwp), DIMENSION(0:1,100)        ::  id_var_do2d, id_var_do3d
    1276     INTEGER(iwp), DIMENSION(100,0:9)        ::  id_dim_z_pr, id_var_dopr, &
    1277                                                id_var_z_pr
    1278     INTEGER(iwp), DIMENSION(dots_max,0:9)   ::  id_var_dots
    1279 
    1280 !
    1281 !-- masked output
    1282     CHARACTER (LEN=7), DIMENSION(max_masks,0:1,100) ::  domask_unit
    1283 
    1284     LOGICAL ::  output_for_t0 = .FALSE.
    1285 
    1286     INTEGER(iwp), DIMENSION(1:max_masks,0:1) ::  id_dim_time_mask, id_dim_x_mask, &
    1287                    id_dim_xu_mask, id_dim_y_mask, id_dim_yv_mask, id_dim_zu_mask, &
    1288                    id_dim_zw_mask, &
    1289                    id_set_mask, &
    1290                    id_var_time_mask, id_var_x_mask, id_var_xu_mask, &
    1291                    id_var_y_mask, id_var_yv_mask, id_var_zu_mask, id_var_zw_mask, &
    1292                    id_var_zusi_mask, id_var_zwwi_mask
    1293 
    1294     INTEGER(iwp), DIMENSION(1:max_masks,0:1,100)         ::  id_var_domask
    1295 
    1296     SAVE
    1297 
    1298  END MODULE netcdf_control
    12991152
    13001153
  • palm/trunk/SOURCE/netcdf_interface.f90

    r1782 r1783  
    1 !> @file netcdf.f90
     1!> @file netcdf_interface.f90
    22!--------------------------------------------------------------------------------!
    33! This file is part of PALM.
     
    1919! Current revisions:
    2020! ------------------
    21 !
     21! netcdf interface has been modularized, former file netcdf renamed to
     22! netcdf_interface, creation of netcdf-dimensions and -variables moved to
     23! specific new subroutines create_netcdf_dim and create_netcdf_var,
     24! compression (deflation) of variables implemented,
     25! ibmy special cpp directive removed
    2226!
    2327! Former revisions:
     
    120124!>       cover every exception (change of dt_do, end_time in restart)
    121125!------------------------------------------------------------------------------!
    122 #if defined( __ibmy_special )
    123 @PROCESS NOOPTimize
     126 MODULE netcdf_interface
     127
     128    USE control_parameters, ONLY: max_masks
     129    USE kinds
     130#if defined( __netcdf )
     131    USE NETCDF
    124132#endif
    125  SUBROUTINE define_netcdf_header( callmode, extend, av )
     133
     134    PRIVATE
     135
     136    INTEGER(iwp), PARAMETER ::  dopr_norm_num = 7, dopts_num = 29, dots_max = 100
     137
     138    CHARACTER (LEN=6), DIMENSION(dopr_norm_num) ::  dopr_norm_names =          &
     139         (/ 'wpt0  ', 'ws2   ', 'tsw2  ', 'ws3   ', 'ws2tsw', 'wstsw2',        &
     140            'z_i   ' /)
     141
     142    CHARACTER (LEN=6), DIMENSION(dopr_norm_num) ::  dopr_norm_longnames =      &
     143         (/ 'wpt0  ', 'w*2   ', 't*w2  ', 'w*3   ', 'w*2t*w', 'w*t*w2',        &
     144            'z_i   ' /)
     145
     146    CHARACTER (LEN=7), DIMENSION(dopts_num) :: dopts_label =                   &
     147          (/ 'tnpt   ', 'x_     ', 'y_     ', 'z_     ', 'z_abs  ', 'u      ', &
     148             'v      ', 'w      ', 'u"     ', 'v"     ', 'w"     ', 'npt_up ', &
     149             'w_up   ', 'w_down ', 'radius ', 'r_min  ', 'r_max  ', 'npt_max', &
     150             'npt_min', 'x*2    ', 'y*2    ', 'z*2    ', 'u*2    ', 'v*2    ', &
     151             'w*2    ', 'u"2    ', 'v"2    ', 'w"2    ', 'npt*2  ' /)
     152
     153    CHARACTER (LEN=7), DIMENSION(dopts_num) :: dopts_unit =                    &
     154          (/ 'number ', 'm      ', 'm      ', 'm      ', 'm      ', 'm/s    ', &
     155             'm/s    ', 'm/s    ', 'm/s    ', 'm/s    ', 'm/s    ', 'number ', &
     156             'm/s    ', 'm/s    ', 'm      ', 'm      ', 'm      ', 'number ', &
     157             'number ', 'm2     ', 'm2     ', 'm2     ', 'm2/s2  ', 'm2/s2  ', &
     158             'm2/s2  ', 'm2/s2  ', 'm2/s2  ', 'm2/s2  ', 'number2' /)
     159
     160    INTEGER(iwp) ::  dots_num  = 31  !< number of timeseries defined by default
     161    INTEGER(iwp) ::  dots_soil = 24  !< starting index for soil-timeseries
     162    INTEGER(iwp) ::  dots_rad  = 32  !< starting index for radiation-timeseries
     163
     164    CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_label =                    &
     165          (/ 'E            ', 'E*           ', 'dt           ',                &
     166             'u*           ', 'th*          ', 'umax         ',                &
     167             'vmax         ', 'wmax         ', 'div_new      ',                &
     168             'div_old      ', 'z_i_wpt      ', 'z_i_pt       ',                &
     169             'w*           ', 'w"pt"0       ', 'w"pt"        ',                &
     170             'wpt          ', 'pt(0)        ', 'pt(z_mo)     ',                &
     171             'w"u"0        ', 'w"v"0        ', 'w"q"0        ',                &
     172             'ol           ', 'q*           ', 'ghf_eb       ',                &
     173             'shf_eb       ', 'qsws_eb      ', 'qsws_liq_eb  ',                &
     174             'qsws_soil_eb ', 'qsws_veg_eb  ', 'r_a          ',                &
     175             'r_s          ', 'rad_net      ', 'rad_lw_in    ',                &
     176             'rad_lw_out   ', 'rad_sw_in    ', 'rad_sw_out   ',                &
     177             'rrtm_aldif   ', 'rrtm_aldir   ', 'rrtm_asdif   ',                &
     178             'rrtm_asdir   ',                                                  &
     179             ( 'unknown      ', i9 = 1, dots_max-40 ) /)
     180
     181    CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_unit =                     &
     182          (/ 'm2/s2        ', 'm2/s2        ', 's            ',                &
     183             'm/s          ', 'K            ', 'm/s          ',                &
     184             'm/s          ', 'm/s          ', 's-1          ',                &
     185             's-1          ', 'm            ', 'm            ',                &
     186             'm/s          ', 'K m/s        ', 'K m/s        ',                &
     187             'K m/s        ', 'K            ', 'K            ',                &
     188             'm2/s2        ', 'm2/s2        ', 'kg m/s       ',                &
     189             'm            ', 'kg/kg        ', '             ',                &
     190             '             ', '             ', '             ',                &
     191             '             ', 'W/m2         ', 's/m          ',                &
     192             '             ', 'W/m2         ', 'W/m2         ',                &
     193             'W/m2         ', 'W/m2         ', 'W/m2         ',                &
     194             '             ', '             ', '             ',                &
     195             '             ',                                                  &
     196             ( 'unknown      ', i9 = 1, dots_max-40 ) /)
     197
     198    CHARACTER (LEN=9), DIMENSION(300) ::  dopr_unit = 'unknown'
     199
     200    CHARACTER (LEN=7), DIMENSION(0:1,100) ::  do2d_unit, do3d_unit
     201
     202    CHARACTER (LEN=16), DIMENSION(25) ::  prt_var_names = &
     203          (/ 'pt_age          ', 'pt_dvrp_size    ', 'pt_origin_x     ', &
     204             'pt_origin_y     ', 'pt_origin_z     ', 'pt_radius       ', &
     205             'pt_speed_x      ', 'pt_speed_y      ', 'pt_speed_z      ', &
     206             'pt_weight_factor', 'pt_x            ', 'pt_y            ', &
     207             'pt_z            ', 'pt_color        ', 'pt_group        ', &
     208             'pt_tailpoints   ', 'pt_tail_id      ', 'pt_density_ratio', &
     209             'pt_exp_arg      ', 'pt_exp_term     ', 'not_used        ', &
     210             'not_used        ', 'not_used        ', 'not_used        ', &
     211             'not_used        ' /)
     212
     213    CHARACTER (LEN=16), DIMENSION(25) ::  prt_var_units = &
     214          (/ 'seconds         ', 'meters          ', 'meters          ', &
     215             'meters          ', 'meters          ', 'meters          ', &
     216             'm/s             ', 'm/s             ', 'm/s             ', &
     217             'factor          ', 'meters          ', 'meters          ', &
     218             'meters          ', 'none            ', 'none            ', &
     219             'none            ', 'none            ', 'ratio           ', &
     220             'none            ', 'none            ', 'not_used        ', &
     221             'not_used        ', 'not_used        ', 'not_used        ', &
     222             'not_used        ' /)
     223
     224    CHARACTER(LEN=20), DIMENSION(11) ::  netcdf_precision = ' '
     225    CHARACTER(LEN=40) ::  netcdf_data_format_string
     226
     227    INTEGER(iwp) ::  id_dim_prtnum, id_dim_time_pr, id_dim_time_prt, &
     228                     id_dim_time_pts, id_dim_time_sp, id_dim_time_ts, id_dim_x_sp, &
     229                     id_dim_y_sp, id_dim_zu_sp, id_dim_zw_sp, id_set_pr, &
     230                     id_set_prt, id_set_pts, id_set_sp, id_set_ts, id_var_prtnum, &
     231                     id_var_rnop_prt, id_var_time_pr, id_var_time_prt, &
     232                     id_var_time_pts, id_var_time_sp, id_var_time_ts, id_var_x_sp, &
     233                     id_var_y_sp, id_var_zu_sp, id_var_zw_sp, nc_stat
     234
     235    INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_xy, id_dim_time_xz, &
     236                    id_dim_time_yz, id_dim_time_3d, id_dim_x_xy, id_dim_xu_xy, &
     237                    id_dim_x_xz, id_dim_xu_xz, id_dim_x_yz, id_dim_xu_yz, &
     238                    id_dim_x_3d, id_dim_xu_3d, id_dim_y_xy, id_dim_yv_xy, &
     239                    id_dim_y_xz, id_dim_yv_xz, id_dim_y_yz, id_dim_yv_yz, &
     240                    id_dim_y_3d, id_dim_yv_3d, id_dim_zs_xy, id_dim_zs_xz, &
     241                    id_dim_zs_yz, id_dim_zs_3d, id_dim_zu_xy, id_dim_zu1_xy, &
     242                    id_dim_zu_xz, id_dim_zu_yz, id_dim_zu_3d, id_dim_zw_xy, &
     243                    id_dim_zw_xz, id_dim_zw_yz, id_dim_zw_3d, id_set_xy, &
     244                    id_set_xz, id_set_yz, id_set_3d, id_var_ind_x_yz, &
     245                    id_var_ind_y_xz, id_var_ind_z_xy, id_var_time_xy, &
     246                    id_var_time_xz, id_var_time_yz, id_var_time_3d, id_var_x_xy, &
     247                    id_var_xu_xy, id_var_x_xz, id_var_xu_xz, id_var_x_yz, &
     248                    id_var_xu_yz, id_var_x_3d, id_var_xu_3d, id_var_y_xy, &
     249                    id_var_yv_xy, id_var_y_xz, id_var_yv_xz, id_var_y_yz, &
     250                    id_var_yv_yz, id_var_y_3d, id_var_yv_3d, id_var_zs_xy, &
     251                    id_var_zs_xz, id_var_zs_yz, id_var_zs_3d, id_var_zusi_xy, &
     252                    id_var_zusi_3d, id_var_zu_xy, id_var_zu1_xy, id_var_zu_xz, &
     253                    id_var_zu_yz, id_var_zu_3d, id_var_zwwi_xy, id_var_zwwi_3d, &
     254                    id_var_zw_xy, id_var_zw_xz, id_var_zw_yz, id_var_zw_3d
     255
     256    INTEGER ::  netcdf_data_format = 2  !< NetCDF3 64bit offset format
     257    INTEGER ::  netcdf_deflate = 0      !< NetCDF compression, default: no
     258                                        !< compression
     259
     260    INTEGER(iwp), DIMENSION(10)  ::  id_var_dospx, id_var_dospy
     261    INTEGER(iwp), DIMENSION(20)  ::  id_var_prt
     262    INTEGER(iwp), DIMENSION(11)  ::  nc_precision
     263    INTEGER(iwp), DIMENSION(dopr_norm_num) ::  id_var_norm_dopr
     264
     265    INTEGER(iwp), DIMENSION(dopts_num,0:10) ::  id_var_dopts
     266    INTEGER(iwp), DIMENSION(0:1,100)        ::  id_var_do2d, id_var_do3d
     267    INTEGER(iwp), DIMENSION(100,0:9)        ::  id_dim_z_pr, id_var_dopr, &
     268                                                id_var_z_pr
     269    INTEGER(iwp), DIMENSION(dots_max,0:9)   ::  id_var_dots
     270
     271!
     272!-- Masked output
     273    CHARACTER (LEN=7), DIMENSION(max_masks,0:1,100) ::  domask_unit
     274
     275    LOGICAL ::  output_for_t0 = .FALSE.
     276
     277    INTEGER(iwp), DIMENSION(1:max_masks,0:1) ::  id_dim_time_mask, id_dim_x_mask, &
     278                   id_dim_xu_mask, id_dim_y_mask, id_dim_yv_mask, id_dim_zs_mask, &
     279                   id_dim_zu_mask, id_dim_zw_mask, &
     280                   id_set_mask, &
     281                   id_var_time_mask, id_var_x_mask, id_var_xu_mask, &
     282                   id_var_y_mask, id_var_yv_mask, id_var_zs_mask, &
     283                   id_var_zu_mask, id_var_zw_mask, &
     284                   id_var_zusi_mask, id_var_zwwi_mask
     285
     286    INTEGER(iwp), DIMENSION(1:max_masks,0:1,100) ::  id_var_domask
     287
     288
     289    PUBLIC  domask_unit, dopr_unit, dopts_num, dots_label, dots_max, dots_num, &
     290            dots_rad, dots_soil, dots_unit, do2d_unit, do3d_unit, id_set_mask, &
     291            id_set_pr, id_set_prt, id_set_pts, id_set_sp, id_set_ts,           &
     292            id_set_xy, id_set_xz, id_set_yz, id_set_3d, id_var_domask,         &
     293            id_var_dopr, id_var_dopts, id_var_dospx, id_var_dospy,             &
     294            id_var_dots, id_var_do2d, id_var_do3d, id_var_norm_dopr,           &
     295            id_var_time_mask, id_var_time_pr, id_var_time_pts, id_var_time_ts, &
     296            id_var_time_xy, id_var_time_xz, id_var_time_yz,id_var_time_3d,     &
     297            nc_stat, netcdf_data_format, netcdf_data_format_string,            &
     298            netcdf_deflate, netcdf_precision, output_for_t0
     299
     300    SAVE
     301
     302    INTERFACE netcdf_create_dim
     303       MODULE PROCEDURE netcdf_create_dim
     304    END INTERFACE netcdf_create_dim
     305
     306    INTERFACE netcdf_create_file
     307       MODULE PROCEDURE netcdf_create_file
     308    END INTERFACE netcdf_create_file
     309
     310    INTERFACE netcdf_create_var
     311       MODULE PROCEDURE netcdf_create_var
     312    END INTERFACE netcdf_create_var
     313
     314    INTERFACE netcdf_define_header
     315       MODULE PROCEDURE netcdf_define_header
     316    END INTERFACE netcdf_define_header
     317
     318    INTERFACE netcdf_handle_error
     319       MODULE PROCEDURE netcdf_handle_error
     320    END INTERFACE netcdf_handle_error
     321
     322    INTERFACE netcdf_open_write_file
     323       MODULE PROCEDURE netcdf_open_write_file
     324    END INTERFACE netcdf_open_write_file
     325
     326    PUBLIC netcdf_create_file, netcdf_define_header, netcdf_handle_error,      &
     327           netcdf_open_write_file
     328
     329 CONTAINS
     330
     331 SUBROUTINE netcdf_define_header( callmode, extend, av )
    126332 
    127333#if defined( __netcdf )
     
    141347               dt_do2d_yz, dt_do3d, mask_size, do2d_xy_time_count,             &
    142348               do3d_time_count, domask_time_count, end_time, mask_i_global,    &
    143                mask_j_global, mask_k_global, message_string, mid,              &
    144                netcdf_data_format, netcdf_precision, ntdim_2d_xy,              &
     349               mask_j_global, mask_k_global, message_string, mid, ntdim_2d_xy, &
    145350               ntdim_2d_xz, ntdim_2d_yz, ntdim_3d, nz_do3d, prt_time_count,    &
    146351               run_description_header, section, simulated_time,                &
     
    155360        ONLY:  nx, ny, nz ,nzb, nzt
    156361
    157     USE netcdf_control
    158 
    159362    USE kinds
    160363
    161364    USE land_surface_model_mod,                                                &
    162         ONLY: land_surface, nzb_soil, nzt_soil, id_dim_zs_xy, id_dim_zs_xz,    &
    163               id_dim_zs_yz, id_dim_zs_3d, id_dim_zs_mask, id_var_zs_xy,        &
    164               id_var_zs_xz, id_var_zs_yz ,id_var_zs_3d, id_var_zs_mask,        &
    165               nzs, zs
     365        ONLY: land_surface, nzb_soil, nzt_soil, nzs, zs
    166366
    167367    USE pegrid
     
    172372    USE profil_parameter,                                                      &
    173373        ONLY:  crmax, cross_profiles, dopr_index, profile_columns, profile_rows
    174 
    175     USE radiation_model_mod,                                                   &
    176         ONLY:  rad_lw_in, rad_lw_out, rad_lw_cs_hr, rad_lw_hr,                 &
    177                rad_sw_in, rad_sw_out, rad_sw_cs_hr, rad_sw_hr
    178 
    179374
    180375    USE spectrum,                                                              &
     
    250445
    251446!
    252 !-- Initializing actions (return to calling routine check_parameters afterwards)
     447!-- Initializing actions
    253448    IF ( .NOT. init_netcdf )  THEN
    254449!
     
    263458                                         '"_"netcdf_precision(', i, ')="',   &
    264459                                         TRIM( netcdf_precision(i) ),'"'
    265              CALL message( 'define_netcdf_header', 'PA0241', 1, 2, 0, 6, 0 )
     460             CALL message( 'netcdf_define_header', 'PA0241', 2, 2, 0, 6, 0 )
    266461          ENDIF
    267462
     
    277472                                         'netcdf_precision(', i, ')="', &
    278473                                         TRIM( netcdf_precision(i) ),'"'
    279              CALL message( 'define_netcdf_header', 'PA0242', 1, 2, 0, 6, 0 )
     474             CALL message( 'netcdf_define_header', 'PA0242', 1, 2, 0, 6, 0 )
    280475          ENDIF
    281476
     
    308503                                  'assignment: netcdf_precision(', i, ')="',  &
    309504                                            TRIM( netcdf_precision(i) ),'"'
    310                 CALL message( 'define_netcdf_header', 'PA0243', 1, 2, 0, 6, 0 )
     505                CALL message( 'netcdf_define_header', 'PA0243', 1, 2, 0, 6, 0 )
    311506
    312507          END SELECT
     
    316511       ENDDO
    317512
     513!
     514!--    Check for allowed parameter range
     515       IF ( netcdf_deflate < 0  .OR.  netcdf_deflate > 9 )  THEN
     516          WRITE ( message_string, '(A,I3,A)' ) 'netcdf_deflate out of ' //     &
     517                                      'range & given value: ', netcdf_deflate, &
     518                                      ', allowed range: 0-9'
     519          CALL message( 'netcdf_define_header', 'PA0355', 2, 2, 0, 6, 0 )
     520       ENDIF
     521!
     522!--    Data compression does not work with parallel NetCDF/HDF5
     523       IF ( netcdf_deflate > 0  .AND.  netcdf_data_format /= 3 )  THEN
     524          message_string = 'netcdf_deflate reset to 0'
     525          CALL message( 'netcdf_define_header', 'PA0356', 0, 1, 0, 6, 0 )
     526
     527          netcdf_deflate = 0
     528       ENDIF
     529
    318530       init_netcdf = .TRUE.
    319 
    320        RETURN
    321531
    322532    ENDIF
     
    352562!--       Define some global attributes of the dataset
    353563          nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), NF90_GLOBAL, &
    354                'Conventions', 'COARDS' )
    355           CALL handle_netcdf_error( 'netcdf', 464 )
     564                                  'Conventions', 'COARDS' )
     565          CALL netcdf_handle_error( 'netcdf_define_header', 464 )
    356566
    357567          IF ( av == 0 )  THEN
     
    364574                                  TRIM( run_description_header ) //    &
    365575                                  TRIM( time_average_text ) )
    366           CALL handle_netcdf_error( 'netcdf', 465 )
     576          CALL netcdf_handle_error( 'netcdf_define_header', 465 )
    367577          IF ( av == 1 )  THEN
    368578             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
    369579             nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), NF90_GLOBAL, &
    370580                                     'time_avg', TRIM( time_average_text ) )
    371              CALL handle_netcdf_error( 'netcdf', 466 )
     581             CALL netcdf_handle_error( 'netcdf_define_header', 466 )
    372582          ENDIF
    373583
    374584!
    375585!--       Define time coordinate for volume data (unlimited dimension)
    376           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'time', NF90_UNLIMITED, &
    377                                   id_dim_time_mask(mid,av) )
    378           CALL handle_netcdf_error( 'netcdf', 467 )
    379 
    380           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'time', NF90_DOUBLE, &
    381                                   id_dim_time_mask(mid,av), &
    382                                   id_var_time_mask(mid,av) )
    383           CALL handle_netcdf_error( 'netcdf', 468 )
    384 
    385           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    386                                   id_var_time_mask(mid,av), 'units', &
    387                                   'seconds')
    388           CALL handle_netcdf_error( 'netcdf', 469 )
    389 
     586          CALL netcdf_create_dim( id_set_mask(mid,av), 'time', NF90_UNLIMITED, &
     587                                  id_dim_time_mask(mid,av), 467 )
     588          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     589                                  (/ id_dim_time_mask(mid,av) /), 'time',      &
     590                                  NF90_DOUBLE, id_var_time_mask(mid,av),       &
     591                                 'seconds', '', 468, 469, 000 )
    390592!
    391593!--       Define spatial dimensions and coordinates:
    392594!--       Define vertical coordinate grid (zu grid)
    393           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'zu_3d', &
    394                                   mask_size(mid,3), id_dim_zu_mask(mid,av) )
    395           CALL handle_netcdf_error( 'netcdf', 470 )
    396 
    397           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'zu_3d', NF90_DOUBLE, &
    398                                   id_dim_zu_mask(mid,av), &
    399                                   id_var_zu_mask(mid,av) )
    400           CALL handle_netcdf_error( 'netcdf', 471 )
    401 
    402           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_zu_mask(mid,av), &
    403                                   'units', 'meters' )
    404           CALL handle_netcdf_error( 'netcdf', 472 )
    405 
     595          CALL netcdf_create_dim( id_set_mask(mid,av), 'zu_3d',                &
     596                                  mask_size(mid,3), id_dim_zu_mask(mid,av),    &
     597                                  470 )
     598          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     599                                  (/ id_dim_zu_mask(mid,av) /), 'zu_3d',       &
     600                                  NF90_DOUBLE, id_var_zu_mask(mid,av),         &
     601                                  'meters', '', 471, 472, 000 )
    406602!
    407603!--       Define vertical coordinate grid (zw grid)
    408           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'zw_3d', &
    409                                   mask_size(mid,3), id_dim_zw_mask(mid,av) )
    410           CALL handle_netcdf_error( 'netcdf', 473 )
    411 
    412           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'zw_3d', NF90_DOUBLE, &
    413                                   id_dim_zw_mask(mid,av), &
    414                                   id_var_zw_mask(mid,av) )
    415           CALL handle_netcdf_error( 'netcdf', 474 )
    416 
    417           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_zw_mask(mid,av), &
    418                                   'units', 'meters' )
    419           CALL handle_netcdf_error( 'netcdf', 475 )
    420 
     604          CALL netcdf_create_dim( id_set_mask(mid,av), 'zw_3d',                &
     605                                  mask_size(mid,3), id_dim_zw_mask(mid,av),    &
     606                                  473 )
     607          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     608                                  (/ id_dim_zw_mask(mid,av) /), 'zw_3d',       &
     609                                  NF90_DOUBLE, id_var_zw_mask(mid,av),         &
     610                                 'meters', '', 474, 475, 000 )
    421611!
    422612!--       Define x-axis (for scalar position)
    423           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'x', &
    424                                   mask_size(mid,1), id_dim_x_mask(mid,av) )
    425           CALL handle_netcdf_error( 'netcdf', 476 )
    426 
    427           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'x', NF90_DOUBLE, &
    428                                   id_dim_x_mask(mid,av), id_var_x_mask(mid,av) )
    429           CALL handle_netcdf_error( 'netcdf', 477 )
    430 
    431           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_x_mask(mid,av), &
    432                                   'units', 'meters' )
    433           CALL handle_netcdf_error( 'netcdf', 478 )
    434 
     613          CALL netcdf_create_dim( id_set_mask(mid,av), 'x', mask_size(mid,1),  &
     614                                  id_dim_x_mask(mid,av), 476 )
     615          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     616                                  (/ id_dim_x_mask(mid,av) /), 'x',            &
     617                                  NF90_DOUBLE, id_var_x_mask(mid,av),          &
     618                                  'meters', '', 477, 478, 000 )
    435619!
    436620!--       Define x-axis (for u position)
    437           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'xu', &
    438                                   mask_size(mid,1), id_dim_xu_mask(mid,av) )
    439           CALL handle_netcdf_error( 'netcdf', 479 )
    440 
    441           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'xu', NF90_DOUBLE, &
    442                                   id_dim_xu_mask(mid,av), &
    443                                   id_var_xu_mask(mid,av) )
    444           CALL handle_netcdf_error( 'netcdf', 480 )
    445 
    446           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_xu_mask(mid,av), &
    447                                   'units', 'meters' )
    448           CALL handle_netcdf_error( 'netcdf', 481 )
    449 
     621          CALL netcdf_create_dim( id_set_mask(mid,av), 'xu', mask_size(mid,1), &
     622                                  id_dim_xu_mask(mid,av), 479 )
     623          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     624                                  (/ id_dim_xu_mask(mid,av) /), 'xu',          &
     625                                  NF90_DOUBLE, id_var_xu_mask(mid,av),         &
     626                                  'meters', '', 480, 481, 000 )
    450627!
    451628!--       Define y-axis (for scalar position)
    452           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'y', &
    453                                   mask_size(mid,2), id_dim_y_mask(mid,av) )
    454           CALL handle_netcdf_error( 'netcdf', 482 )
    455 
    456           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'y', NF90_DOUBLE, &
    457                                   id_dim_y_mask(mid,av), id_var_y_mask(mid,av) )
    458           CALL handle_netcdf_error( 'netcdf', 483 )
    459 
    460           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_y_mask(mid,av), &
    461                                   'units', 'meters' )
    462           CALL handle_netcdf_error( 'netcdf', 484 )
    463 
     629          CALL netcdf_create_dim( id_set_mask(mid,av), 'y', mask_size(mid,2),  &
     630                                  id_dim_y_mask(mid,av), 482 )
     631          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     632                                  (/ id_dim_y_mask(mid,av) /), 'y',            &
     633                                  NF90_DOUBLE, id_var_y_mask(mid,av),          &
     634                                  'meters', '', 483, 484, 000 )
    464635!
    465636!--       Define y-axis (for v position)
    466           nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'yv', &
    467                                   mask_size(mid,2), id_dim_yv_mask(mid,av) )
    468           CALL handle_netcdf_error( 'netcdf', 485 )
    469 
    470           nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'yv', NF90_DOUBLE, &
    471                                   id_dim_yv_mask(mid,av), &
    472                                   id_var_yv_mask(mid,av) )
    473           CALL handle_netcdf_error( 'netcdf', 486 )
    474 
    475           nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_yv_mask(mid,av), &
    476                                   'units', 'meters' )
    477           CALL handle_netcdf_error( 'netcdf', 487 )
    478 
     637          CALL netcdf_create_dim( id_set_mask(mid,av), 'yv', mask_size(mid,2), &
     638                                  id_dim_yv_mask(mid,av), 485 )
     639          CALL netcdf_create_var( id_set_mask(mid,av),                         &
     640                                  (/ id_dim_yv_mask(mid,av) /),                &
     641                                  'yv', NF90_DOUBLE, id_var_yv_mask(mid,av),   &
     642                                  'meters', '', 486, 487, 000 )
    479643!
    480644!--       In case of non-flat topography define 2d-arrays containing the height
     
    483647!
    484648!--          Define zusi = zu(nzb_s_inner)
    485              nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'zusi', NF90_DOUBLE, &
    486                                      (/ id_dim_x_mask(mid,av),    &
    487                                         id_dim_y_mask(mid,av) /), &
    488                                      id_var_zusi_mask(mid,av) )
    489              CALL handle_netcdf_error( 'netcdf', 488 )
    490              
    491              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    492                                      id_var_zusi_mask(mid,av), &
    493                                      'units', 'meters' )
    494              CALL handle_netcdf_error( 'netcdf', 489 )
    495              
    496              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    497                                      id_var_zusi_mask(mid,av), &
    498                                      'long_name', 'zu(nzb_s_inner)' )
    499              CALL handle_netcdf_error( 'netcdf', 490 )
    500 
     649             CALL netcdf_create_var( id_set_mask(mid,av),                      &
     650                                     (/ id_dim_x_mask(mid,av),                 &
     651                                        id_dim_y_mask(mid,av) /), 'zusi',      &
     652                                     NF90_DOUBLE, id_var_zusi_mask(mid,av),    &
     653                                     'meters', 'zu(nzb_s_inner)', 488, 489,    &
     654                                     490 )
    501655!             
    502656!--          Define zwwi = zw(nzb_w_inner)
    503              nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'zwwi', NF90_DOUBLE, &
    504                                      (/ id_dim_x_mask(mid,av),    &
    505                                         id_dim_y_mask(mid,av) /), &
    506                                      id_var_zwwi_mask(mid,av) )
    507              CALL handle_netcdf_error( 'netcdf', 491 )
    508              
    509              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    510                                      id_var_zwwi_mask(mid,av), &
    511                                      'units', 'meters' )
    512              CALL handle_netcdf_error( 'netcdf', 492 )
    513              
    514              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    515                                      id_var_zwwi_mask(mid,av), &
    516                                      'long_name', 'zw(nzb_w_inner)' )
    517              CALL handle_netcdf_error( 'netcdf', 493 )
    518 
     657             CALL netcdf_create_var( id_set_mask(mid,av),                      &
     658                                     (/ id_dim_x_mask(mid,av),                 &
     659                                        id_dim_y_mask(mid,av) /), 'zwwi',      &
     660                                     NF90_DOUBLE, id_var_zwwi_mask(mid,av),    &
     661                                     'meters', 'zw(nzb_w_inner)', 491, 492,    &
     662                                     493 )
    519663          ENDIF             
    520664 
     
    522666!
    523667!--          Define vertical coordinate grid (zw grid)
    524              nc_stat = NF90_DEF_DIM( id_set_mask(mid,av), 'zs_3d', &
    525                                      mask_size(mid,3), id_dim_zs_mask(mid,av) )
    526              CALL handle_netcdf_error( 'netcdf', 536 )
    527 
    528              nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), 'zs_3d', NF90_DOUBLE, &
    529                                      id_dim_zs_mask(mid,av), &
    530                                      id_var_zs_mask(mid,av) )
    531              CALL handle_netcdf_error( 'netcdf', 536 )
    532 
    533              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), id_var_zs_mask(mid,av), &
    534                                   'units', 'meters' )
    535              CALL handle_netcdf_error( 'netcdf', 537 )
    536 
     668             CALL netcdf_create_dim( id_set_mask(mid,av), 'zs_3d',             &
     669                                     mask_size(mid,3), id_dim_zs_mask(mid,av), &
     670                                     536 )
     671             CALL netcdf_create_var( id_set_mask(mid,av),                      &
     672                                     (/ id_dim_zs_mask(mid,av) /), 'zs_3d',    &
     673                                     NF90_DOUBLE, id_var_zs_mask(mid,av),      &
     674                                     'meters', '', 537, 555, 000 )
    537675          ENDIF
    538676
     
    591729!
    592730!--                Check for user-defined quantities
    593                    CALL user_define_netcdf_grid( domask(mid,av,i), found, &
     731                   CALL user_define_netcdf_grid( domask(mid,av,i), found,      &
    594732                                                 grid_x, grid_y, grid_z )
     733
     734                   IF ( .NOT. found )  THEN
     735                      WRITE ( message_string, * ) 'no grid defined for',       &
     736                           ' variable ', TRIM( domask(mid,av,i) )
     737                      CALL message( 'define_netcdf_header', 'PA0244', 0, 1, 0, &
     738                                    6, 0 )
     739                   ENDIF
    595740
    596741             END SELECT
     
    620765!
    621766!--          Define the grid
    622              nc_stat = NF90_DEF_VAR( id_set_mask(mid,av), domask(mid,av,i), &
    623                                      nc_precision(11),            &
    624                                      (/ id_x, id_y, id_z,                   &
    625                                         id_dim_time_mask(mid,av) /),        &
    626                                      id_var_domask(mid,av,i) )
    627 
    628              IF ( .NOT. found )  THEN
    629                 WRITE ( message_string, * ) 'no grid defined for', &
    630                      ' variable ', TRIM( domask(mid,av,i) )
    631                 CALL message( 'define_netcdf_header', 'PA0244', 0, 1, 0, 6, 0 )
    632              ENDIF
     767             CALL netcdf_create_var( id_set_mask(mid,av), (/ id_x, id_y, id_z, &
     768                                     id_dim_time_mask(mid,av) /),              &
     769                                     domask(mid,av,i), nc_precision(11),       &
     770                                     id_var_domask(mid,av,i),                  &
     771                                     TRIM( domask_unit(mid,av,i) ),            &
     772                                     domask(mid,av,i), 494, 495, 496 )
    633773
    634774             var_list = TRIM( var_list ) // TRIM( domask(mid,av,i) ) // ';'
    635 
    636              CALL handle_netcdf_error( 'netcdf', 494 )
    637 !
    638 !--          Store the 'real' name of the variable (with *, for example)
    639 !--          in the long_name attribute. This is evaluated by Ferret,
    640 !--          for example.
    641              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av),     &
    642                                      id_var_domask(mid,av,i), &
    643                                      'long_name', domask(mid,av,i) )
    644              CALL handle_netcdf_error( 'netcdf', 495 )
    645 !
    646 !--          Define the variable's unit
    647              nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), &
    648                                      id_var_domask(mid,av,i), &
    649                                      'units', TRIM( domask_unit(mid,av,i) ) )
    650              CALL handle_netcdf_error( 'netcdf', 496 )
    651775
    652776             i = i + 1
     
    663787          nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), NF90_GLOBAL, &
    664788                                  'VAR_LIST', var_list )
    665           CALL handle_netcdf_error( 'netcdf', 497 )
     789          CALL netcdf_handle_error( 'netcdf_define_header', 497 )
    666790
    667791!
    668792!--       Leave netCDF define mode
    669793          nc_stat = NF90_ENDDEF( id_set_mask(mid,av) )
    670           CALL handle_netcdf_error( 'netcdf', 498 )
     794          CALL netcdf_handle_error( 'netcdf_define_header', 498 )
    671795
    672796!
     
    679803                                  netcdf_data, start = (/ 1 /),               &
    680804                                  count = (/ mask_size(mid,1) /) )
    681           CALL handle_netcdf_error( 'netcdf', 499 )
     805          CALL netcdf_handle_error( 'netcdf_define_header', 499 )
    682806
    683807          netcdf_data = mask_i_global(mid,:mask_size(mid,1)) * dx
     
    686810                                  netcdf_data, start = (/ 1 /),               &
    687811                                  count = (/ mask_size(mid,1) /) )
    688           CALL handle_netcdf_error( 'netcdf', 500 )
     812          CALL netcdf_handle_error( 'netcdf_define_header', 500 )
    689813
    690814          DEALLOCATE( netcdf_data )
     
    699823                                  netcdf_data, start = (/ 1 /),               &
    700824                                  count = (/ mask_size(mid,2) /))
    701           CALL handle_netcdf_error( 'netcdf', 501 )
     825          CALL netcdf_handle_error( 'netcdf_define_header', 501 )
    702826
    703827          netcdf_data = mask_j_global(mid,:mask_size(mid,2)) * dy
     
    706830                                  netcdf_data, start = (/ 1 /),    &
    707831                                  count = (/ mask_size(mid,2) /))
    708           CALL handle_netcdf_error( 'netcdf', 502 )
     832          CALL netcdf_handle_error( 'netcdf_define_header', 502 )
    709833
    710834          DEALLOCATE( netcdf_data )
     
    719843                                  netcdf_data, start = (/ 1 /), &
    720844                                  count = (/ mask_size(mid,3) /) )
    721           CALL handle_netcdf_error( 'netcdf', 503 )
     845          CALL netcdf_handle_error( 'netcdf_define_header', 503 )
    722846
    723847          netcdf_data = zw( mask_k_global(mid,:mask_size(mid,3)) )
     
    726850                                  netcdf_data, start = (/ 1 /), &
    727851                                  count = (/ mask_size(mid,3) /) )
    728           CALL handle_netcdf_error( 'netcdf', 504 )
     852          CALL netcdf_handle_error( 'netcdf_define_header', 504 )
    729853
    730854          DEALLOCATE( netcdf_data )
     
    744868                                     count = (/ mask_size(mid,1), &
    745869                                                mask_size(mid,2) /) )
    746              CALL handle_netcdf_error( 'netcdf', 505 )
     870             CALL netcdf_handle_error( 'netcdf_define_header', 505 )
    747871
    748872             netcdf_data_2d = zw_w_inner( mask_i_global(mid,:mask_size(mid,1)),&
     
    755879                                     count = (/ mask_size(mid,1), &
    756880                                                mask_size(mid,2) /) )
    757              CALL handle_netcdf_error( 'netcdf', 506 )
     881             CALL netcdf_handle_error( 'netcdf_define_header', 506 )
    758882
    759883             DEALLOCATE( netcdf_data_2d )
     
    772896                                     netcdf_data, start = (/ 1 /), &
    773897                                     count = (/ mask_size(mid,3) /) )
    774              CALL handle_netcdf_error( 'netcdf', 538 )
     898             CALL netcdf_handle_error( 'netcdf_define_header', 538 )
    775899
    776900             DEALLOCATE( netcdf_data )
     
    804928          nc_stat = NF90_GET_ATT( id_set_mask(mid,av), NF90_GLOBAL, 'VAR_LIST',&
    805929                                  var_list_old )
    806           CALL handle_netcdf_error( 'netcdf', 507 )
     930          CALL netcdf_handle_error( 'netcdf_define_header', 507 )
    807931
    808932          var_list = ';'
     
    833957          nc_stat = NF90_INQ_VARID( id_set_mask(mid,av), 'zu_3d', &
    834958                                    id_var_zu_mask(mid,av) )
    835           CALL handle_netcdf_error( 'netcdf', 508 )
     959          CALL netcdf_handle_error( 'netcdf_define_header', 508 )
    836960
    837961          nc_stat = NF90_INQUIRE_VARIABLE( id_set_mask(mid,av),     &
    838962                                           id_var_zu_mask(mid,av),  &
    839963                                           dimids = id_dim_zu_mask_old )
    840           CALL handle_netcdf_error( 'netcdf', 509 )
     964          CALL netcdf_handle_error( 'netcdf_define_header', 509 )
    841965          id_dim_zu_mask(mid,av) = id_dim_zu_mask_old(1)
    842966
     
    844968                                            id_dim_zu_mask(mid,av), &
    845969                                            len = nz_old )
    846           CALL handle_netcdf_error( 'netcdf', 510 )
     970          CALL netcdf_handle_error( 'netcdf_define_header', 510 )
    847971
    848972          IF ( mask_size(mid,3) /= nz_old )  THEN
     
    864988          nc_stat = NF90_INQ_VARID( id_set_mask(mid,av), 'time', &
    865989                                    id_var_time_mask(mid,av) )
    866           CALL handle_netcdf_error( 'netcdf', 511 )
     990          CALL netcdf_handle_error( 'netcdf_define_header', 511 )
    867991
    868992          nc_stat = NF90_INQUIRE_VARIABLE( id_set_mask(mid,av), &
    869993                                           id_var_time_mask(mid,av), &
    870994                                           dimids = id_dim_time_old )
    871           CALL handle_netcdf_error( 'netcdf', 512 )
     995          CALL netcdf_handle_error( 'netcdf_define_header', 512 )
    872996          id_dim_time_mask(mid,av) = id_dim_time_old(1)
    873997
     
    875999                                            id_dim_time_mask(mid,av), &
    8761000                                            len = domask_time_count(mid,av) )
    877           CALL handle_netcdf_error( 'netcdf', 513 )
     1001          CALL netcdf_handle_error( 'netcdf_define_header', 513 )
    8781002
    8791003          nc_stat = NF90_GET_VAR( id_set_mask(mid,av), &
     
    8821006                                  start = (/ domask_time_count(mid,av) /), &
    8831007                                  count = (/ 1 /) )
    884           CALL handle_netcdf_error( 'netcdf', 514 )
     1008          CALL netcdf_handle_error( 'netcdf_define_header', 514 )
    8851009
    8861010          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    9041028                                       TRIM( domask(mid,av,i) ), &
    9051029                                       id_var_domask(mid,av,i) )
    906              CALL handle_netcdf_error( 'netcdf', 515 )
     1030             CALL netcdf_handle_error( 'netcdf_define_header', 515 )
    9071031             i = i + 1
    9081032          ENDDO
     
    9221046          ENDIF
    9231047          nc_stat = NF90_REDEF( id_set_mask(mid,av) )
    924           CALL handle_netcdf_error( 'netcdf', 516 )
     1048          CALL netcdf_handle_error( 'netcdf_define_header', 516 )
    9251049          nc_stat = NF90_PUT_ATT( id_set_mask(mid,av), NF90_GLOBAL, 'title', &
    9261050                                  TRIM( run_description_header ) //    &
    9271051                                  TRIM( time_average_text ) )
    928           CALL handle_netcdf_error( 'netcdf', 517 )
     1052          CALL netcdf_handle_error( 'netcdf_define_header', 517 )
    9291053          nc_stat = NF90_ENDDEF( id_set_mask(mid,av) )
    930           CALL handle_netcdf_error( 'netcdf', 518 )
     1054          CALL netcdf_handle_error( 'netcdf_define_header', 518 )
    9311055          WRITE ( message_string, * ) 'netCDF file for ', TRIM( var ), &
    9321056               ' data for mask', mid, ' from previous run found.', &
     
    9441068          nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'Conventions', &
    9451069                                  'COARDS' )
    946           CALL handle_netcdf_error( 'netcdf', 62 )
     1070          CALL netcdf_handle_error( 'netcdf_define_header', 62 )
    9471071
    9481072          IF ( av == 0 )  THEN
     
    9551079                                  TRIM( run_description_header ) //    &
    9561080                                  TRIM( time_average_text ) )
    957           CALL handle_netcdf_error( 'netcdf', 63 )
     1081          CALL netcdf_handle_error( 'netcdf_define_header', 63 )
    9581082          IF ( av == 1 )  THEN
    9591083             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
    9601084             nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'time_avg', &
    9611085                                     TRIM( time_average_text ) )
    962              CALL handle_netcdf_error( 'netcdf', 63 )
     1086             CALL netcdf_handle_error( 'netcdf_define_header', 63 )
    9631087          ENDIF
    9641088
     
    9681092!--       the performance drops significantly.
    9691093          IF ( netcdf_data_format < 5 )  THEN
    970              nc_stat = NF90_DEF_DIM( id_set_3d(av), 'time', NF90_UNLIMITED, &
    971                                      id_dim_time_3d(av) )
    972              CALL handle_netcdf_error( 'netcdf', 64 )
     1094             CALL netcdf_create_dim( id_set_3d(av), 'time', NF90_UNLIMITED,    &
     1095                                     id_dim_time_3d(av), 64 )
    9731096          ELSE
    974              nc_stat = NF90_DEF_DIM( id_set_3d(av), 'time', ntdim_3d(av), &
    975                                      id_dim_time_3d(av) )
    976              CALL handle_netcdf_error( 'netcdf', 523 )
    977           ENDIF
    978 
    979           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'time', NF90_DOUBLE, &
    980                                   id_dim_time_3d(av), id_var_time_3d(av) )
    981           CALL handle_netcdf_error( 'netcdf', 65 )
    982 
    983           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_time_3d(av), 'units', &
    984                                   'seconds')
    985           CALL handle_netcdf_error( 'netcdf', 66 )
    986 
     1097             CALL netcdf_create_dim( id_set_3d(av), 'time', ntdim_3d(av),      &
     1098                                     id_dim_time_3d(av), 523 )
     1099          ENDIF
     1100
     1101          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_time_3d(av) /),     &
     1102                                  'time', NF90_DOUBLE, id_var_time_3d(av),     &
     1103                                  'seconds', '', 65, 66, 00 )
    9871104!
    9881105!--       Define spatial dimensions and coordinates:
    9891106!--       Define vertical coordinate grid (zu grid)
    990           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'zu_3d', nz_do3d-nzb+1, &
    991                                   id_dim_zu_3d(av) )
    992           CALL handle_netcdf_error( 'netcdf', 67 )
    993 
    994           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zu_3d', NF90_DOUBLE, &
    995                                   id_dim_zu_3d(av), id_var_zu_3d(av) )
    996           CALL handle_netcdf_error( 'netcdf', 68 )
    997 
    998           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zu_3d(av), 'units', &
    999                                   'meters' )
    1000           CALL handle_netcdf_error( 'netcdf', 69 )
    1001 
     1107          CALL netcdf_create_dim( id_set_3d(av), 'zu_3d', nz_do3d-nzb+1,       &
     1108                                  id_dim_zu_3d(av), 67 )
     1109          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_zu_3d(av) /),       &
     1110                                  'zu_3d', NF90_DOUBLE, id_var_zu_3d(av),      &
     1111                                  'meters', '', 68, 69, 00 )
    10021112!
    10031113!--       Define vertical coordinate grid (zw grid)
    1004           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'zw_3d', nz_do3d-nzb+1, &
    1005                                   id_dim_zw_3d(av) )
    1006           CALL handle_netcdf_error( 'netcdf', 70 )
    1007 
    1008           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zw_3d', NF90_DOUBLE, &
    1009                                   id_dim_zw_3d(av), id_var_zw_3d(av) )
    1010           CALL handle_netcdf_error( 'netcdf', 71 )
    1011 
    1012           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zw_3d(av), 'units', &
    1013                                   'meters' )
    1014           CALL handle_netcdf_error( 'netcdf', 72 )
    1015 
     1114          CALL netcdf_create_dim( id_set_3d(av), 'zw_3d', nz_do3d-nzb+1,       &
     1115                                  id_dim_zw_3d(av), 70 )
     1116          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_zw_3d(av) /),       &
     1117                                  'zw_3d', NF90_DOUBLE, id_var_zw_3d(av),      &
     1118                                  'meters', '', 71, 72, 00 )
    10161119!
    10171120!--       Define x-axis (for scalar position)
    1018           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'x', nx+2, id_dim_x_3d(av) )
    1019           CALL handle_netcdf_error( 'netcdf', 73 )
    1020 
    1021           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'x', NF90_DOUBLE, &
    1022                                   id_dim_x_3d(av), id_var_x_3d(av) )
    1023           CALL handle_netcdf_error( 'netcdf', 74 )
    1024 
    1025           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_x_3d(av), 'units', &
    1026                                   'meters' )
    1027           CALL handle_netcdf_error( 'netcdf', 75 )
    1028 
     1121          CALL netcdf_create_dim( id_set_3d(av), 'x', nx+2, id_dim_x_3d(av),   &
     1122                                  73 )
     1123          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_x_3d(av) /), 'x',   &
     1124                                  NF90_DOUBLE, id_var_x_3d(av), 'meters', '',  &
     1125                                  74, 75, 00 )
    10291126!
    10301127!--       Define x-axis (for u position)
    1031           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'xu', nx+2, id_dim_xu_3d(av) )
    1032           CALL handle_netcdf_error( 'netcdf', 358 )
    1033 
    1034           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'xu', NF90_DOUBLE, &
    1035                                   id_dim_xu_3d(av), id_var_xu_3d(av) )
    1036           CALL handle_netcdf_error( 'netcdf', 359 )
    1037 
    1038           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_xu_3d(av), 'units', &
    1039                                   'meters' )
    1040           CALL handle_netcdf_error( 'netcdf', 360 )
    1041 
     1128          CALL netcdf_create_dim( id_set_3d(av), 'xu', nx+2, id_dim_xu_3d(av), &
     1129                                  358 )
     1130          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_xu_3d(av) /), 'xu', &
     1131                                  NF90_DOUBLE, id_var_xu_3d(av), 'meters', '', &
     1132                                  359, 360, 000 )
    10421133!
    10431134!--       Define y-axis (for scalar position)
    1044           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'y', ny+2, id_dim_y_3d(av) )
    1045           CALL handle_netcdf_error( 'netcdf', 76 )
    1046 
    1047           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'y', NF90_DOUBLE, &
    1048                                   id_dim_y_3d(av), id_var_y_3d(av) )
    1049           CALL handle_netcdf_error( 'netcdf', 77 )
    1050 
    1051           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_y_3d(av), 'units', &
    1052                                   'meters' )
    1053           CALL handle_netcdf_error( 'netcdf', 78 )
    1054 
     1135          CALL netcdf_create_dim( id_set_3d(av), 'y', ny+2, id_dim_y_3d(av),   &
     1136                                  76 )
     1137          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_y_3d(av) /), 'y',   &
     1138                                  NF90_DOUBLE, id_var_y_3d(av), 'meters', '',  &
     1139                                  77, 78, 00 )
    10551140!
    10561141!--       Define y-axis (for v position)
    1057           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'yv', ny+2, id_dim_yv_3d(av) )
    1058           CALL handle_netcdf_error( 'netcdf', 361 )
    1059 
    1060           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'yv', NF90_DOUBLE, &
    1061                                   id_dim_yv_3d(av), id_var_yv_3d(av) )
    1062           CALL handle_netcdf_error( 'netcdf', 362 )
    1063 
    1064           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_yv_3d(av), 'units', &
    1065                                   'meters' )
    1066           CALL handle_netcdf_error( 'netcdf', 363 )
    1067 
     1142          CALL netcdf_create_dim( id_set_3d(av), 'yv', ny+2, id_dim_yv_3d(av), &
     1143                                  361 )
     1144          CALL netcdf_create_var( id_set_3d(av), (/ id_dim_yv_3d(av) /), 'yv', &
     1145                                  NF90_DOUBLE, id_var_yv_3d(av), 'meters', '', &
     1146                                  362, 363, 000 )
    10681147!
    10691148!--       In case of non-flat topography define 2d-arrays containing the height
     
    10721151!
    10731152!--          Define zusi = zu(nzb_s_inner)
    1074              nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zusi', NF90_DOUBLE,     &
    1075                                      (/ id_dim_x_3d(av), id_dim_y_3d(av) /), &
    1076                                      id_var_zusi_3d(av) )
    1077              CALL handle_netcdf_error( 'netcdf', 413 )
    1078              
    1079              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zusi_3d(av), &
    1080                                      'units', 'meters' )
    1081              CALL handle_netcdf_error( 'netcdf', 414 )
    1082              
    1083              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zusi_3d(av), &
    1084                                      'long_name', 'zu(nzb_s_inner)' )
    1085              CALL handle_netcdf_error( 'netcdf', 415 )
    1086 
     1153             CALL netcdf_create_var( id_set_3d(av), (/ id_dim_x_3d(av),        &
     1154                                     id_dim_y_3d(av) /), 'zusi', NF90_DOUBLE,  &
     1155                                     id_var_zusi_3d(av), 'meters',             &
     1156                                     'zu(nzb_s_inner)', 413, 414, 415 )
    10871157!             
    10881158!--          Define zwwi = zw(nzb_w_inner)
    1089              nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zwwi', NF90_DOUBLE,     &
    1090                                      (/ id_dim_x_3d(av), id_dim_y_3d(av) /), &
    1091                                      id_var_zwwi_3d(av) )
    1092              CALL handle_netcdf_error( 'netcdf', 416 )
    1093              
    1094              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zwwi_3d(av), &
    1095                                      'units', 'meters' )
    1096              CALL handle_netcdf_error( 'netcdf', 417 )
    1097              
    1098              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zwwi_3d(av), &
    1099                                      'long_name', 'zw(nzb_w_inner)' )
    1100              CALL handle_netcdf_error( 'netcdf', 418 )
     1159             CALL netcdf_create_var( id_set_3d(av), (/ id_dim_x_3d(av),        &
     1160                                     id_dim_y_3d(av) /), 'zwwi', NF90_DOUBLE,  &
     1161                                     id_var_zwwi_3d(av), 'meters',             &
     1162                                     'zw(nzb_w_inner)', 416, 417, 418 )
    11011163
    11021164          ENDIF             
     
    11051167!
    11061168!--          Define vertical coordinate grid (zs grid)
    1107              nc_stat = NF90_DEF_DIM( id_set_3d(av), 'zs_3d', nzt_soil-nzb_soil+1, &
    1108                                      id_dim_zs_3d(av) )
    1109              CALL handle_netcdf_error( 'netcdf', 70 )
    1110 
    1111              nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zs_3d', NF90_DOUBLE, &
    1112                                      id_dim_zs_3d(av), id_var_zs_3d(av) )
    1113              CALL handle_netcdf_error( 'netcdf', 71 )
    1114 
    1115              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zs_3d(av), 'units', &
    1116                                      'meters' )
    1117              CALL handle_netcdf_error( 'netcdf', 72 )
     1169             CALL netcdf_create_dim( id_set_3d(av), 'zs_3d',                   &
     1170                                     nzt_soil-nzb_soil+1, id_dim_zs_3d(av), 70 )
     1171             CALL netcdf_create_var( id_set_3d(av), (/ id_dim_zs_3d(av) /),    &
     1172                                     'zs_3d', NF90_DOUBLE, id_var_zs_3d(av),   &
     1173                                     'meters', '', 71, 72, 00 )
    11181174
    11191175          ENDIF
     
    11751231                   CALL user_define_netcdf_grid( do3d(av,i), found, grid_x, &
    11761232                                                 grid_y, grid_z )
     1233
     1234                   IF ( .NOT. found )  THEN
     1235                      WRITE ( message_string, * ) 'no grid defined for varia', &
     1236                                                  'ble ', TRIM( do3d(av,i) )
     1237                      CALL message( 'define_netcdf_header', 'PA0244', 0, 1, 0, &
     1238                                    6, 0 )
     1239                   ENDIF
    11771240
    11781241             END SELECT
     
    12021265!
    12031266!--          Define the grid
    1204              nc_stat = NF90_DEF_VAR( id_set_3d(av), do3d(av,i),                &
    1205                                      nc_precision(4),                          &
    1206                                    (/ id_x, id_y, id_z, id_dim_time_3d(av) /), &
    1207                                      id_var_do3d(av,i) )
    1208 
    1209              IF ( .NOT. found )  THEN
    1210                 WRITE ( message_string, * ) 'no grid defined for', &
    1211                                             ' variable ', TRIM( do3d(av,i) )
    1212                 CALL message( 'define_netcdf_header', 'PA0244', 0, 1, 0, 6, 0 )
    1213              ENDIF
    1214 
    1215              var_list = TRIM( var_list ) // TRIM( do3d(av,i) ) // ';'
    1216 
    1217              CALL handle_netcdf_error( 'netcdf', 79 )
    1218 !
    1219 !--          Store the 'real' name of the variable (with *, for example)
    1220 !--          in the long_name attribute. This is evaluated by Ferret,
    1221 !--          for example.
    1222              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_do3d(av,i), &
    1223                                      'long_name', do3d(av,i) )
    1224              CALL handle_netcdf_error( 'netcdf', 80 )
    1225 !
    1226 !--          Define the variable's unit
    1227              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_do3d(av,i), &
    1228                                      'units', TRIM( do3d_unit(av,i) ) )
    1229              CALL handle_netcdf_error( 'netcdf', 357 )
     1267             CALL netcdf_create_var( id_set_3d(av),(/ id_x, id_y, id_z,        &
     1268                                     id_dim_time_3d(av) /), do3d(av,i),        &
     1269                                     nc_precision(4), id_var_do3d(av,i),       &
     1270                                     TRIM( do3d_unit(av,i) ), do3d(av,i), 79,  &
     1271                                     80, 357 )
    12301272#if defined( __netcdf4_parallel )
    12311273             IF ( netcdf_data_format > 4 )  THEN
     
    12351277                                             id_var_do3d(av,i), &
    12361278                                             1, 0 )
    1237                 CALL handle_netcdf_error( 'netcdf', 532 )
     1279                CALL netcdf_handle_error( 'netcdf_define_header', 532 )
    12381280!
    12391281!--             Set collective io operations for parallel io
     
    12411283                                               id_var_do3d(av,i), &
    12421284                                               NF90_COLLECTIVE )
    1243                 CALL handle_netcdf_error( 'netcdf', 445 )
     1285                CALL netcdf_handle_error( 'netcdf_define_header', 445 )
    12441286             ENDIF
    12451287#endif
     1288             var_list = TRIM( var_list ) // TRIM( do3d(av,i) ) // ';'
     1289
    12461290             i = i + 1
    12471291
     
    12571301          nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'VAR_LIST', &
    12581302                                  var_list )
    1259           CALL handle_netcdf_error( 'netcdf', 81 )
     1303          CALL netcdf_handle_error( 'netcdf_define_header', 81 )
    12601304
    12611305!
     
    12631307!--       parallel output.
    12641308          nc_stat = NF90_SET_FILL( id_set_3d(av), NF90_NOFILL, oldmode )
    1265           CALL handle_netcdf_error( 'netcdf', 528 )
     1309          CALL netcdf_handle_error( 'netcdf_define_header', 528 )
    12661310
    12671311!
    12681312!--       Leave netCDF define mode
    12691313          nc_stat = NF90_ENDDEF( id_set_3d(av) )
    1270           CALL handle_netcdf_error( 'netcdf', 82 )
     1314          CALL netcdf_handle_error( 'netcdf_define_header', 82 )
    12711315
    12721316!
     
    12851329                                     netcdf_data, start = (/ 1 /),    &
    12861330                                     count = (/ nx+2 /) )
    1287              CALL handle_netcdf_error( 'netcdf', 83 )
     1331             CALL netcdf_handle_error( 'netcdf_define_header', 83 )
    12881332
    12891333             DO  i = 0, nx+1
     
    12941338                                     netcdf_data, start = (/ 1 /),    &
    12951339                                     count = (/ nx+2 /) )
    1296              CALL handle_netcdf_error( 'netcdf', 385 )
     1340             CALL netcdf_handle_error( 'netcdf_define_header', 385 )
    12971341
    12981342             DEALLOCATE( netcdf_data )
     
    13091353                                     netcdf_data, start = (/ 1 /),    &
    13101354                                     count = (/ ny+2 /) )
    1311              CALL handle_netcdf_error( 'netcdf', 84 )
     1355             CALL netcdf_handle_error( 'netcdf_define_header', 84 )
    13121356
    13131357             DO  i = 0, ny+1
     
    13181362                                     netcdf_data, start = (/ 1 /),    &
    13191363                                     count = (/ ny+2 /))
    1320              CALL handle_netcdf_error( 'netcdf', 387 )
     1364             CALL netcdf_handle_error( 'netcdf_define_header', 387 )
    13211365
    13221366             DEALLOCATE( netcdf_data )
     
    13271371                                     zu(nzb:nz_do3d), start = (/ 1 /), &
    13281372                                     count = (/ nz_do3d-nzb+1 /) )
    1329              CALL handle_netcdf_error( 'netcdf', 85 )
     1373             CALL netcdf_handle_error( 'netcdf_define_header', 85 )
    13301374
    13311375
     
    13331377                                     zw(nzb:nz_do3d), start = (/ 1 /), &
    13341378                                     count = (/ nz_do3d-nzb+1 /) )
    1335              CALL handle_netcdf_error( 'netcdf', 86 )
     1379             CALL netcdf_handle_error( 'netcdf_define_header', 86 )
    13361380
    13371381!
     
    13431387                                        start = (/ 1, 1 /), &
    13441388                                        count = (/ nx+2, ny+2 /) )
    1345                 CALL handle_netcdf_error( 'netcdf', 419 )
     1389                CALL netcdf_handle_error( 'netcdf_define_header', 419 )
    13461390
    13471391                nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_zwwi_3d(av), &
     
    13491393                                        start = (/ 1, 1 /), &
    13501394                                        count = (/ nx+2, ny+2 /) )
    1351                 CALL handle_netcdf_error( 'netcdf', 420 )
     1395                CALL netcdf_handle_error( 'netcdf_define_header', 420 )
    13521396
    13531397             ENDIF
     
    13591403                                        - zs(nzb_soil:nzt_soil), start = (/ 1 /), &
    13601404                                        count = (/ nzt_soil-nzb_soil+1 /) )
    1361                 CALL handle_netcdf_error( 'netcdf', 86 )
     1405                CALL netcdf_handle_error( 'netcdf_define_header', 86 )
    13621406             ENDIF
    13631407
     
    13731417          nc_stat = NF90_GET_ATT( id_set_3d(av), NF90_GLOBAL, 'VAR_LIST', &
    13741418                                  var_list_old )
    1375           CALL handle_netcdf_error( 'netcdf', 87 )
     1419          CALL netcdf_handle_error( 'netcdf_define_header', 87 )
    13761420
    13771421          var_list = ';'
     
    14021446!--       Get and compare the number of vertical gridpoints
    14031447          nc_stat = NF90_INQ_VARID( id_set_3d(av), 'zu_3d', id_var_zu_3d(av) )
    1404           CALL handle_netcdf_error( 'netcdf', 88 )
     1448          CALL netcdf_handle_error( 'netcdf_define_header', 88 )
    14051449
    14061450          nc_stat = NF90_INQUIRE_VARIABLE( id_set_3d(av), id_var_zu_3d(av), &
    14071451                                           dimids = id_dim_zu_3d_old )
    1408           CALL handle_netcdf_error( 'netcdf', 89 )
     1452          CALL netcdf_handle_error( 'netcdf_define_header', 89 )
    14091453          id_dim_zu_3d(av) = id_dim_zu_3d_old(1)
    14101454
    14111455          nc_stat = NF90_INQUIRE_DIMENSION( id_set_3d(av), id_dim_zu_3d(av), &
    14121456                                            len = nz_old )
    1413           CALL handle_netcdf_error( 'netcdf', 90 )
     1457          CALL netcdf_handle_error( 'netcdf_define_header', 90 )
    14141458
    14151459          IF ( nz_do3d-nzb+1 /= nz_old )  THEN
     
    14311475!--       on the file.
    14321476          nc_stat = NF90_INQ_VARID( id_set_3d(av), 'time', id_var_time_3d(av) )
    1433           CALL handle_netcdf_error( 'netcdf', 91 )
     1477          CALL netcdf_handle_error( 'netcdf_define_header', 91 )
    14341478
    14351479          nc_stat = NF90_INQUIRE_VARIABLE( id_set_3d(av), id_var_time_3d(av), &
    14361480                                           dimids = id_dim_time_old )
    1437           CALL handle_netcdf_error( 'netcdf', 92 )
     1481          CALL netcdf_handle_error( 'netcdf_define_header', 92 )
    14381482
    14391483          id_dim_time_3d(av) = id_dim_time_old(1)
     
    14411485          nc_stat = NF90_INQUIRE_DIMENSION( id_set_3d(av), id_dim_time_3d(av), &
    14421486                                            len = ntime_count )
    1443           CALL handle_netcdf_error( 'netcdf', 93 )
     1487          CALL netcdf_handle_error( 'netcdf_define_header', 93 )
    14441488
    14451489!
     
    14541498                                  start = (/ do3d_time_count(av) /), &
    14551499                                  count = (/ 1 /) )
    1456           CALL handle_netcdf_error( 'netcdf', 94 )
     1500          CALL netcdf_handle_error( 'netcdf_define_header', 94 )
    14571501
    14581502          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    15241568             nc_stat = NF90_INQ_VARID( id_set_3d(av), TRIM( do3d(av,i) ), &
    15251569                                       id_var_do3d(av,i) )
    1526              CALL handle_netcdf_error( 'netcdf', 95 )
     1570             CALL netcdf_handle_error( 'netcdf_define_header', 95 )
    15271571#if defined( __netcdf4_parallel )
    15281572!
     
    15321576                                               id_var_do3d(av,i), &
    15331577                                               NF90_COLLECTIVE )
    1534                 CALL handle_netcdf_error( 'netcdf', 453 )
     1578                CALL netcdf_handle_error( 'netcdf_define_header', 453 )
    15351579             ENDIF
    15361580#endif
     
    15521596          ENDIF
    15531597          nc_stat = NF90_REDEF( id_set_3d(av) )
    1554           CALL handle_netcdf_error( 'netcdf', 429 )
     1598          CALL netcdf_handle_error( 'netcdf_define_header', 429 )
    15551599          nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'title', &
    15561600                                  TRIM( run_description_header ) //    &
    15571601                                  TRIM( time_average_text ) )
    1558           CALL handle_netcdf_error( 'netcdf', 96 )
     1602          CALL netcdf_handle_error( 'netcdf_define_header', 96 )
    15591603          nc_stat = NF90_ENDDEF( id_set_3d(av) )
    1560           CALL handle_netcdf_error( 'netcdf', 430 )
     1604          CALL netcdf_handle_error( 'netcdf_define_header', 430 )
    15611605          message_string = 'netCDF file for volume data ' //             &
    15621606                           TRIM( var ) // ' from previous run found.' // &
     
    15701614          nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'Conventions', &
    15711615                                  'COARDS' )
    1572           CALL handle_netcdf_error( 'netcdf', 97 )
     1616          CALL netcdf_handle_error( 'netcdf_define_header', 97 )
    15731617
    15741618          IF ( av == 0 )  THEN
     
    15811625                                  TRIM( run_description_header ) //    &
    15821626                                  TRIM( time_average_text ) )
    1583           CALL handle_netcdf_error( 'netcdf', 98 )
     1627          CALL netcdf_handle_error( 'netcdf_define_header', 98 )
    15841628          IF ( av == 1 )  THEN
    15851629             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
    15861630             nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'time_avg', &
    15871631                                     TRIM( time_average_text ) )
    1588              CALL handle_netcdf_error( 'netcdf', 98 )
     1632             CALL netcdf_handle_error( 'netcdf_define_header', 98 )
    15891633          ENDIF
    15901634
     
    15941638!--       the performance drops significantly.
    15951639          IF ( netcdf_data_format < 5 )  THEN
    1596              nc_stat = NF90_DEF_DIM( id_set_xy(av), 'time', NF90_UNLIMITED, &
    1597                                      id_dim_time_xy(av) )
    1598              CALL handle_netcdf_error( 'netcdf', 99 )
     1640             CALL netcdf_create_dim( id_set_xy(av), 'time', NF90_UNLIMITED,    &
     1641                                     id_dim_time_xy(av), 99 )
    15991642          ELSE
    1600              nc_stat = NF90_DEF_DIM( id_set_xy(av), 'time', ntdim_2d_xy(av), &
    1601                                      id_dim_time_xy(av) )
    1602              CALL handle_netcdf_error( 'netcdf', 524 )
    1603           ENDIF
    1604 
    1605           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'time', NF90_DOUBLE, &
    1606                                   id_dim_time_xy(av), id_var_time_xy(av) )
    1607           CALL handle_netcdf_error( 'netcdf', 100 )
    1608 
    1609           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_time_xy(av), 'units', &
    1610                                   'seconds')
    1611           CALL handle_netcdf_error( 'netcdf', 101 )
    1612 
     1643             CALL netcdf_create_dim( id_set_xy(av), 'time', ntdim_2d_xy(av),   &
     1644                                     id_dim_time_xy(av), 524 )
     1645          ENDIF
     1646
     1647          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_time_xy(av) /),     &
     1648                                  'time', NF90_DOUBLE, id_var_time_xy(av),     &
     1649                                  'seconds', '', 100, 101, 000 )
    16131650!
    16141651!--       Define the spatial dimensions and coordinates for xy-sections.
     
    16261663!
    16271664!--       Define vertical coordinate grid (zu grid)
    1628           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zu_xy', ns, id_dim_zu_xy(av) )
    1629           CALL handle_netcdf_error( 'netcdf', 102 )
    1630 
    1631           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zu_xy', NF90_DOUBLE, &
    1632                                   id_dim_zu_xy(av), id_var_zu_xy(av) )
    1633           CALL handle_netcdf_error( 'netcdf', 103 )
    1634 
    1635           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zu_xy(av), 'units', &
    1636                                   'meters' )
    1637           CALL handle_netcdf_error( 'netcdf', 104 )
    1638 
     1665          CALL netcdf_create_dim( id_set_xy(av), 'zu_xy', ns,                  &
     1666                                  id_dim_zu_xy(av), 102 )
     1667          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_zu_xy(av) /),       &
     1668                                  'zu_xy', NF90_DOUBLE, id_var_zu_xy(av),      &
     1669                                  'meters', '', 103, 104, 000 )
    16391670!
    16401671!--       Define vertical coordinate grid (zw grid)
    1641           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zw_xy', ns, id_dim_zw_xy(av) )
    1642           CALL handle_netcdf_error( 'netcdf', 105 )
    1643 
    1644           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zw_xy', NF90_DOUBLE, &
    1645                                   id_dim_zw_xy(av), id_var_zw_xy(av) )
    1646           CALL handle_netcdf_error( 'netcdf', 106 )
    1647 
    1648           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zw_xy(av), 'units', &
    1649                                   'meters' )
    1650           CALL handle_netcdf_error( 'netcdf', 107 )
    1651 
     1672          CALL netcdf_create_dim( id_set_xy(av), 'zw_xy', ns,                  &
     1673                                  id_dim_zw_xy(av), 105 )
     1674          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_zw_xy(av) /),       &
     1675                                  'zw_xy', NF90_DOUBLE, id_var_zw_xy(av),      &
     1676                                  'meters', '', 106, 107, 000 )
    16521677
    16531678          IF ( land_surface )  THEN
     
    16591684!
    16601685!--          Define vertical coordinate grid (zs grid)
    1661              nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zs_xy', ns_do, id_dim_zs_xy(av) )
    1662              CALL handle_netcdf_error( 'netcdf', 539 )
    1663 
    1664              nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zs_xy', NF90_DOUBLE, &
    1665                                      id_dim_zs_xy(av), id_var_zs_xy(av) )
    1666              CALL handle_netcdf_error( 'netcdf', 540 )
    1667 
    1668              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zs_xy(av), 'units', &
    1669                                   'meters' )
    1670              CALL handle_netcdf_error( 'netcdf', 541 )
     1686             CALL netcdf_create_dim( id_set_xy(av), 'zs_xy', ns_do,            &
     1687                                     id_dim_zs_xy(av), 539 )
     1688             CALL netcdf_create_var( id_set_xy(av), (/ id_dim_zs_xy(av) /),    &
     1689                                     'zs_xy', NF90_DOUBLE, id_var_zs_xy(av),   &
     1690                                     'meters', '', 540, 541, 000 )
    16711691
    16721692          ENDIF
     
    16751695!--       Define a pseudo vertical coordinate grid for the surface variables
    16761696!--       u* and t* to store their height level
    1677           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zu1_xy', 1, &
    1678                                   id_dim_zu1_xy(av) )
    1679           CALL handle_netcdf_error( 'netcdf', 108 )
    1680 
    1681           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zu1_xy', NF90_DOUBLE, &
    1682                                   id_dim_zu1_xy(av), id_var_zu1_xy(av) )
    1683           CALL handle_netcdf_error( 'netcdf', 109 )
    1684 
    1685           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zu1_xy(av), 'units', &
    1686                                   'meters' )
    1687           CALL handle_netcdf_error( 'netcdf', 110 )
    1688 
     1697          CALL netcdf_create_dim( id_set_xy(av), 'zu1_xy', 1,                  &
     1698                                  id_dim_zu1_xy(av), 108 )
     1699          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_zu1_xy(av) /),      &
     1700                                  'zu1_xy', NF90_DOUBLE, id_var_zu1_xy(av),    &
     1701                                  'meters', '', 109, 110, 000 )
    16891702!
    16901703!--       Define a variable to store the layer indices of the horizontal cross
    16911704!--       sections, too
    1692           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'ind_z_xy', NF90_DOUBLE, &
    1693                                   id_dim_zu_xy(av), id_var_ind_z_xy(av) )
    1694           CALL handle_netcdf_error( 'netcdf', 111 )
    1695 
    1696           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_ind_z_xy(av), 'units', &
    1697                                   'gridpoints')
    1698           CALL handle_netcdf_error( 'netcdf', 112 )
    1699 
     1705          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_zu_xy(av) /),       &
     1706                                  'ind_z_xy', NF90_DOUBLE,                     &
     1707                                  id_var_ind_z_xy(av), 'gridpoints', '', 111,  &
     1708                                  112, 000 )
    17001709!
    17011710!--       Define x-axis (for scalar position)
    1702           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'x', nx+2, id_dim_x_xy(av) )
    1703           CALL handle_netcdf_error( 'netcdf', 113 )
    1704 
    1705           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'x', NF90_DOUBLE, &
    1706                                   id_dim_x_xy(av), id_var_x_xy(av) )
    1707           CALL handle_netcdf_error( 'netcdf', 114 )
    1708 
    1709 
    1710           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_x_xy(av), 'units', &
    1711                                   'meters' )
    1712           CALL handle_netcdf_error( 'netcdf', 115 )
    1713 
     1711          CALL netcdf_create_dim( id_set_xy(av), 'x', nx+2, id_dim_x_xy(av),   &
     1712                                  113 )
     1713          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_x_xy(av) /), 'x',   &
     1714                                  NF90_DOUBLE, id_var_x_xy(av), 'meters', '',  &
     1715                                  114, 115, 000 )
    17141716!
    17151717!--       Define x-axis (for u position)
    1716           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'xu', nx+2, id_dim_xu_xy(av) )
    1717           CALL handle_netcdf_error( 'netcdf', 388 )
    1718 
    1719           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'xu', NF90_DOUBLE, &
    1720                                   id_dim_xu_xy(av), id_var_xu_xy(av) )
    1721           CALL handle_netcdf_error( 'netcdf', 389 )
    1722 
    1723           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_xu_xy(av), 'units', &
    1724                                   'meters' )
    1725           CALL handle_netcdf_error( 'netcdf', 390 )
    1726 
     1718          CALL netcdf_create_dim( id_set_xy(av), 'xu', nx+2,                   &
     1719                                  id_dim_xu_xy(av), 388 )
     1720          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_xu_xy(av) /), 'xu', &
     1721                                  NF90_DOUBLE, id_var_xu_xy(av), 'meters', '', &
     1722                                  389, 390, 000 )
    17271723!
    17281724!--       Define y-axis (for scalar position)
    1729           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'y', ny+2, id_dim_y_xy(av) )
    1730           CALL handle_netcdf_error( 'netcdf', 116 )
    1731 
    1732           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'y', NF90_DOUBLE, &
    1733                                   id_dim_y_xy(av), id_var_y_xy(av) )
    1734           CALL handle_netcdf_error( 'netcdf', 117 )
    1735 
    1736           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_y_xy(av), 'units', &
    1737                                   'meters' )
    1738           CALL handle_netcdf_error( 'netcdf', 118 )
    1739 
     1725          CALL netcdf_create_dim( id_set_xy(av), 'y', ny+2, id_dim_y_xy(av),   &
     1726                                  116 )
     1727          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_y_xy(av) /), 'y',   &
     1728                                  NF90_DOUBLE, id_var_y_xy(av), 'meters', '',  &
     1729                                  117, 118, 000 )
    17401730!
    17411731!--       Define y-axis (for scalar position)
    1742           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'yv', ny+2, id_dim_yv_xy(av) )
    1743           CALL handle_netcdf_error( 'netcdf', 364 )
    1744 
    1745           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'yv', NF90_DOUBLE, &
    1746                                   id_dim_yv_xy(av), id_var_yv_xy(av) )
    1747           CALL handle_netcdf_error( 'netcdf', 365 )
    1748 
    1749           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_yv_xy(av), 'units', &
    1750                                   'meters' )
    1751           CALL handle_netcdf_error( 'netcdf', 366 )
    1752 
     1732          CALL netcdf_create_dim( id_set_xy(av), 'yv', ny+2,                   &
     1733                                  id_dim_yv_xy(av), 364 )
     1734          CALL netcdf_create_var( id_set_xy(av), (/ id_dim_yv_xy(av) /), 'yv', &
     1735                                  NF90_DOUBLE, id_var_yv_xy(av), 'meters', '', &
     1736                                  365, 366, 000 )
    17531737!
    17541738!--       In case of non-flat topography define 2d-arrays containing the height
     
    17571741!
    17581742!--          Define zusi = zu(nzb_s_inner)
    1759              nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zusi', NF90_DOUBLE, &
    1760                                      (/ id_dim_x_xy(av), id_dim_y_xy(av) /), &
    1761                                      id_var_zusi_xy(av) )
    1762              CALL handle_netcdf_error( 'netcdf', 421 )
    1763              
    1764              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zusi_xy(av), &
    1765                                      'units', 'meters' )
    1766              CALL handle_netcdf_error( 'netcdf', 422 )
    1767              
    1768              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zusi_xy(av), &
    1769                                      'long_name', 'zu(nzb_s_inner)' )
    1770              CALL handle_netcdf_error( 'netcdf', 423 )
    1771 
     1743             CALL netcdf_create_var( id_set_xy(av), (/ id_dim_x_xy(av),        &
     1744                                     id_dim_y_xy(av) /), 'zusi', NF90_DOUBLE,  &
     1745                                     id_var_zusi_xy(av), 'meters',             &
     1746                                     'zu(nzb_s_inner)', 421, 422, 423 )
    17721747!             
    17731748!--          Define zwwi = zw(nzb_w_inner)
    1774              nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zwwi', NF90_DOUBLE, &
    1775                                      (/ id_dim_x_xy(av), id_dim_y_xy(av) /), &
    1776                                      id_var_zwwi_xy(av) )
    1777              CALL handle_netcdf_error( 'netcdf', 424 )
    1778              
    1779              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zwwi_xy(av), &
    1780                                      'units', 'meters' )
    1781              CALL handle_netcdf_error( 'netcdf', 425 )
    1782              
    1783              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zwwi_xy(av), &
    1784                                      'long_name', 'zw(nzb_w_inner)' )
    1785              CALL handle_netcdf_error( 'netcdf', 426 )
     1749             CALL netcdf_create_var( id_set_xy(av), (/ id_dim_x_xy(av),        &
     1750                                     id_dim_y_xy(av) /), 'zwwi', NF90_DOUBLE,  &
     1751                                     id_var_zwwi_xy(av), 'meters',             &
     1752                                     'zw(nzb_w_inner)', 424, 425, 426 )
    17861753
    17871754          ENDIF
     
    18001767                IF ( INDEX( do2d(av,i), '*' ) /= 0 )  THEN
    18011768
    1802                    nc_stat = NF90_DEF_VAR( id_set_xy(av),  do2d(av,i),         &
    1803                                            nc_precision(1),                    &
    1804                                            (/ id_dim_x_xy(av), id_dim_y_xy(av),&
    1805                                               id_dim_zu1_xy(av),               &
    1806                                               id_dim_time_xy(av) /),           &
    1807                                            id_var_do2d(av,i) )
    1808 
    1809                    var_list = TRIM(var_list) // TRIM( do2d(av,i) ) // ';'
     1769                   CALL netcdf_create_var( id_set_xy(av), (/ id_dim_x_xy(av),  &
     1770                                           id_dim_y_xy(av), id_dim_zu1_xy(av), &
     1771                                           id_dim_time_xy(av) /), do2d(av,i),  &
     1772                                           nc_precision(1), id_var_do2d(av,i), &
     1773                                           TRIM( do2d_unit(av,i) ),            &
     1774                                           do2d(av,i), 119, 120, 354 )
    18101775
    18111776                ELSE
     
    18621827                                                       grid_x, grid_y, grid_z )
    18631828
     1829                         IF ( .NOT. found )  THEN
     1830                            WRITE ( message_string, * ) 'no grid defined for', &
     1831                                                ' variable ', TRIM( do2d(av,i) )
     1832                            CALL message( 'define_netcdf_header', 'PA0244',    &
     1833                                          0, 1, 0, 6, 0 )
     1834                         ENDIF
     1835
    18641836                   END SELECT
    18651837
     
    18881860!
    18891861!--                Define the grid
    1890                    nc_stat = NF90_DEF_VAR( id_set_xy(av), do2d(av,i),          &
    1891                                            nc_precision(1),                    &
    1892                                    (/ id_x, id_y, id_z, id_dim_time_xy(av) /), &
    1893                                            id_var_do2d(av,i) )
    1894 
    1895                    IF ( .NOT. found )  THEN
    1896                       WRITE ( message_string, * ) 'no grid defined for', &
    1897                                             ' variable ', TRIM( do2d(av,i) )
    1898                       CALL message( 'define_netcdf_header', 'PA0244',&
    1899                                                                 0, 1, 0, 6, 0 )
    1900                    ENDIF
    1901 
    1902                    var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
     1862                   CALL netcdf_create_var( id_set_xy(av), (/ id_x, id_y, id_z, &
     1863                                           id_dim_time_xy(av) /), do2d(av,i),  &
     1864                                           nc_precision(1), id_var_do2d(av,i), &
     1865                                           TRIM( do2d_unit(av,i) ),            &
     1866                                           do2d(av,i), 119, 120, 354 )
    19031867
    19041868                ENDIF
    19051869
    1906                 CALL handle_netcdf_error( 'netcdf', 119 )
    1907 !
    1908 !--             Store the 'real' name of the variable (with *, for example)
    1909 !--             in the long_name attribute. This is evaluated by Ferret,
    1910 !--             for example.
    1911                 nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_do2d(av,i), &
    1912                                         'long_name', do2d(av,i) )
    1913                 CALL handle_netcdf_error( 'netcdf', 120 )
    1914 !
    1915 !--             Define the variable's unit
    1916                 nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_do2d(av,i), &
    1917                                         'units', TRIM( do2d_unit(av,i) ) )
    1918                 CALL handle_netcdf_error( 'netcdf', 354 )
    19191870#if defined( __netcdf4_parallel )
    19201871                IF ( netcdf_data_format > 4 )  THEN
     
    19241875                                                id_var_do2d(av,i), &
    19251876                                                1, 0 )
    1926                    CALL handle_netcdf_error( 'netcdf', 533 )
     1877                   CALL netcdf_handle_error( 'netcdf_define_header', 533 )
    19271878!
    19281879!--                Set collective io operations for parallel io
     
    19301881                                                  id_var_do2d(av,i), &
    19311882                                                  NF90_COLLECTIVE )
    1932                    CALL handle_netcdf_error( 'netcdf', 448 )
     1883                   CALL netcdf_handle_error( 'netcdf_define_header', 448 )
    19331884                ENDIF
    19341885#endif
     1886                var_list = TRIM( var_list) // TRIM( do2d(av,i) ) // ';'
     1887
    19351888             ENDIF
    19361889
     
    19481901          nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'VAR_LIST', &
    19491902                                  var_list )
    1950           CALL handle_netcdf_error( 'netcdf', 121 )
     1903          CALL netcdf_handle_error( 'netcdf_define_header', 121 )
    19511904
    19521905!
     
    19541907!--       parallel output.
    19551908          nc_stat = NF90_SET_FILL( id_set_xy(av), NF90_NOFILL, oldmode )
    1956           CALL handle_netcdf_error( 'netcdf', 529 )
     1909          CALL netcdf_handle_error( 'netcdf_define_header', 529 )
    19571910
    19581911!
    19591912!--       Leave netCDF define mode
    19601913          nc_stat = NF90_ENDDEF( id_set_xy(av) )
    1961           CALL handle_netcdf_error( 'netcdf', 122 )
     1914          CALL netcdf_handle_error( 'netcdf_define_header', 122 )
    19621915
    19631916!
     
    19821935                                     netcdf_data, start = (/ 1 /),    &
    19831936                                     count = (/ ns /) )
    1984              CALL handle_netcdf_error( 'netcdf', 123 )
     1937             CALL netcdf_handle_error( 'netcdf_define_header', 123 )
    19851938
    19861939!
     
    19961949                                     netcdf_data, start = (/ 1 /),    &
    19971950                                     count = (/ ns /) )
    1998              CALL handle_netcdf_error( 'netcdf', 124 )
     1951             CALL netcdf_handle_error( 'netcdf_define_header', 124 )
    19991952
    20001953!
     
    20151968                                        netcdf_data(1:ns_do), start = (/ 1 /),    &
    20161969                                        count = (/ ns_do /) )
    2017                 CALL handle_netcdf_error( 'netcdf', 124 )
     1970                CALL netcdf_handle_error( 'netcdf_define_header', 124 )
    20181971
    20191972             ENDIF
     
    20251978                                     netcdf_data, start = (/ 1 /),       &
    20261979                                     count = (/ ns /) )
    2027              CALL handle_netcdf_error( 'netcdf', 125 )
     1980             CALL netcdf_handle_error( 'netcdf_define_header', 125 )
    20281981
    20291982             DEALLOCATE( netcdf_data )
     
    20341987                                     (/ zu(nzb+1) /), start = (/ 1 /), &
    20351988                                     count = (/ 1 /) )
    2036              CALL handle_netcdf_error( 'netcdf', 126 )
     1989             CALL netcdf_handle_error( 'netcdf_define_header', 126 )
    20371990
    20381991!
     
    20472000                                     netcdf_data, start = (/ 1 /),   &
    20482001                                     count = (/ nx+2 /) )
    2049              CALL handle_netcdf_error( 'netcdf', 127 )
     2002             CALL netcdf_handle_error( 'netcdf_define_header', 127 )
    20502003
    20512004             DO  i = 0, nx+1
     
    20562009                                     netcdf_data, start = (/ 1 /),    &
    20572010                                     count = (/ nx+2 /) )
    2058              CALL handle_netcdf_error( 'netcdf', 367 )
     2011             CALL netcdf_handle_error( 'netcdf_define_header', 367 )
    20592012
    20602013             DEALLOCATE( netcdf_data )
     
    20712024                                     netcdf_data, start = (/ 1 /),   &
    20722025                                     count = (/ ny+2 /))
    2073              CALL handle_netcdf_error( 'netcdf', 128 )
     2026             CALL netcdf_handle_error( 'netcdf_define_header', 128 )
    20742027
    20752028             DO  i = 0, ny+1
     
    20802033                                     netcdf_data, start = (/ 1 /),    &
    20812034                                     count = (/ ny+2 /))
    2082              CALL handle_netcdf_error( 'netcdf', 368 )
     2035             CALL netcdf_handle_error( 'netcdf_define_header', 368 )
    20832036
    20842037             DEALLOCATE( netcdf_data )
     
    20922045                                        start = (/ 1, 1 /), &
    20932046                                        count = (/ nx+2, ny+2 /) )
    2094                 CALL handle_netcdf_error( 'netcdf', 427 )
     2047                CALL netcdf_handle_error( 'netcdf_define_header', 427 )
    20952048
    20962049                nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_zwwi_xy(av), &
     
    20982051                                        start = (/ 1, 1 /), &
    20992052                                        count = (/ nx+2, ny+2 /) )
    2100                 CALL handle_netcdf_error( 'netcdf', 428 )
     2053                CALL netcdf_handle_error( 'netcdf_define_header', 428 )
    21012054
    21022055             ENDIF
     
    21152068          nc_stat = NF90_GET_ATT( id_set_xy(av), NF90_GLOBAL, 'VAR_LIST', &
    21162069                                  var_list_old )
    2117           CALL handle_netcdf_error( 'netcdf', 129 )
     2070          CALL netcdf_handle_error( 'netcdf_define_header', 129 )
    21182071
    21192072          var_list = ';'
     
    21542107!--       Get and compare the number of horizontal cross sections
    21552108          nc_stat = NF90_INQ_VARID( id_set_xy(av), 'zu_xy', id_var_zu_xy(av) )
    2156           CALL handle_netcdf_error( 'netcdf', 130 )
     2109          CALL netcdf_handle_error( 'netcdf_define_header', 130 )
    21572110
    21582111          nc_stat = NF90_INQUIRE_VARIABLE( id_set_xy(av), id_var_zu_xy(av), &
    21592112                                           dimids = id_dim_zu_xy_old )
    2160           CALL handle_netcdf_error( 'netcdf', 131 )
     2113          CALL netcdf_handle_error( 'netcdf_define_header', 131 )
    21612114          id_dim_zu_xy(av) = id_dim_zu_xy_old(1)
    21622115
    21632116          nc_stat = NF90_INQUIRE_DIMENSION( id_set_xy(av), id_dim_zu_xy(av), &
    21642117                                            len = ns_old )
    2165           CALL handle_netcdf_error( 'netcdf', 132 )
     2118          CALL netcdf_handle_error( 'netcdf_define_header', 132 )
    21662119
    21672120          IF ( ns /= ns_old )  THEN
     
    21822135
    21832136          nc_stat = NF90_GET_VAR( id_set_xy(av), id_var_zu_xy(av), netcdf_data )
    2184           CALL handle_netcdf_error( 'netcdf', 133 )
     2137          CALL netcdf_handle_error( 'netcdf_define_header', 133 )
    21852138
    21862139          DO  i = 1, ns
     
    22222175!--       on the file.
    22232176          nc_stat = NF90_INQ_VARID( id_set_xy(av), 'time', id_var_time_xy(av) )
    2224           CALL handle_netcdf_error( 'netcdf', 134 )
     2177          CALL netcdf_handle_error( 'netcdf_define_header', 134 )
    22252178
    22262179          nc_stat = NF90_INQUIRE_VARIABLE( id_set_xy(av), id_var_time_xy(av), &
    22272180                                           dimids = id_dim_time_old )
    2228           CALL handle_netcdf_error( 'netcdf', 135 )
     2181          CALL netcdf_handle_error( 'netcdf_define_header', 135 )
    22292182          id_dim_time_xy(av) = id_dim_time_old(1)
    22302183
    22312184          nc_stat = NF90_INQUIRE_DIMENSION( id_set_xy(av), id_dim_time_xy(av), &
    22322185                                            len = ntime_count )
    2233           CALL handle_netcdf_error( 'netcdf', 136 )
     2186          CALL netcdf_handle_error( 'netcdf_define_header', 136 )
    22342187
    22352188!
     
    22442197                                  start = (/ do2d_xy_time_count(av) /), &
    22452198                                  count = (/ 1 /) )
    2246           CALL handle_netcdf_error( 'netcdf', 137 )
     2199          CALL netcdf_handle_error( 'netcdf_define_header', 137 )
    22472200
    22482201          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    23152268                nc_stat = NF90_INQ_VARID( id_set_xy(av), do2d(av,i), &
    23162269                                          id_var_do2d(av,i) )
    2317                 CALL handle_netcdf_error( 'netcdf', 138 )
     2270                CALL netcdf_handle_error( 'netcdf_define_header', 138 )
    23182271#if defined( __netcdf4_parallel )
    23192272!
     
    23232276                                                  id_var_do2d(av,i), &
    23242277                                                  NF90_COLLECTIVE )
    2325                    CALL handle_netcdf_error( 'netcdf', 454 )
     2278                   CALL netcdf_handle_error( 'netcdf_define_header', 454 )
    23262279                ENDIF
    23272280#endif
     
    23442297          ENDIF
    23452298          nc_stat = NF90_REDEF( id_set_xy(av) )
    2346           CALL handle_netcdf_error( 'netcdf', 431 )
     2299          CALL netcdf_handle_error( 'netcdf_define_header', 431 )
    23472300          nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'title', &
    23482301                                  TRIM( run_description_header ) //    &
    23492302                                  TRIM( time_average_text ) )
    2350           CALL handle_netcdf_error( 'netcdf', 139 )
     2303          CALL netcdf_handle_error( 'netcdf_define_header', 139 )
    23512304          nc_stat = NF90_ENDDEF( id_set_xy(av) )
    2352           CALL handle_netcdf_error( 'netcdf', 432 )
     2305          CALL netcdf_handle_error( 'netcdf_define_header', 432 )
    23532306          message_string = 'netCDF file for cross-sections ' //           &
    23542307                            TRIM( var ) // ' from previous run found.' // &
     
    23632316          nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'Conventions', &
    23642317                                  'COARDS' )
    2365           CALL handle_netcdf_error( 'netcdf', 140 )
     2318          CALL netcdf_handle_error( 'netcdf_define_header', 140 )
    23662319
    23672320          IF ( av == 0 )  THEN
     
    23742327                                  TRIM( run_description_header )  //   &
    23752328                                  TRIM( time_average_text ) )
    2376           CALL handle_netcdf_error( 'netcdf', 141 )
     2329          CALL netcdf_handle_error( 'netcdf_define_header', 141 )
    23772330          IF ( av == 1 )  THEN
    23782331             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
    23792332             nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'time_avg', &
    23802333                                     TRIM( time_average_text ) )
    2381              CALL handle_netcdf_error( 'netcdf', 141 )
     2334             CALL netcdf_handle_error( 'netcdf_define_header', 141 )
    23822335          ENDIF
    23832336
     
    23872340!--       the performance drops significantly.
    23882341          IF ( netcdf_data_format < 5 )  THEN
    2389              nc_stat = NF90_DEF_DIM( id_set_xz(av), 'time', NF90_UNLIMITED, &
    2390                                      id_dim_time_xz(av) )
    2391              CALL handle_netcdf_error( 'netcdf', 142 )
     2342             CALL netcdf_create_dim( id_set_xz(av), 'time', NF90_UNLIMITED,    &
     2343                                     id_dim_time_xz(av), 142 )
    23922344          ELSE
    2393              nc_stat = NF90_DEF_DIM( id_set_xz(av), 'time', ntdim_2d_xz(av), &
    2394                                      id_dim_time_xz(av) )
    2395              CALL handle_netcdf_error( 'netcdf', 525 )
    2396           ENDIF
    2397 
    2398           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'time', NF90_DOUBLE, &
    2399                                   id_dim_time_xz(av), id_var_time_xz(av) )
    2400           CALL handle_netcdf_error( 'netcdf', 143 )
    2401 
    2402           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_time_xz(av), 'units', &
    2403                                   'seconds')
    2404           CALL handle_netcdf_error( 'netcdf', 144 )
    2405 
     2345             CALL netcdf_create_dim( id_set_xz(av), 'time', ntdim_2d_xz(av),   &
     2346                                     id_dim_time_xz(av), 525 )
     2347          ENDIF
     2348
     2349          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_time_xz(av) /),     &
     2350                                  'time', NF90_DOUBLE, id_var_time_xz(av),     &
     2351                                  'seconds', '', 143, 144, 000 )
    24062352!
    24072353!--       Define the spatial dimensions and coordinates for xz-sections.
     
    24192365!
    24202366!--       Define y-axis (for scalar position)
    2421           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'y_xz', ns, id_dim_y_xz(av) )
    2422           CALL handle_netcdf_error( 'netcdf', 145 )
    2423 
    2424           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'y_xz', NF90_DOUBLE, &
    2425                                   id_dim_y_xz(av), id_var_y_xz(av) )
    2426           CALL handle_netcdf_error( 'netcdf', 146 )
    2427 
    2428           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_y_xz(av), 'units', &
    2429                                   'meters' )
    2430           CALL handle_netcdf_error( 'netcdf', 147 )
    2431 
     2367          CALL netcdf_create_dim( id_set_xz(av), 'y_xz', ns, id_dim_y_xz(av),  &
     2368                                  145 )
     2369          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_y_xz(av) /),        &
     2370                                  'y_xz', NF90_DOUBLE, id_var_y_xz(av),        &
     2371                                  'meters', '', 146, 147, 000 )
    24322372!
    24332373!--       Define y-axis (for v position)
    2434           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'yv_xz', ns, id_dim_yv_xz(av) )
    2435           CALL handle_netcdf_error( 'netcdf', 369 )
    2436 
    2437           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'yv_xz', NF90_DOUBLE, &
    2438                                   id_dim_yv_xz(av), id_var_yv_xz(av) )
    2439           CALL handle_netcdf_error( 'netcdf', 370 )
    2440 
    2441           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_yv_xz(av), 'units', &
    2442                                   'meters' )
    2443           CALL handle_netcdf_error( 'netcdf', 371 )
    2444 
     2374          CALL netcdf_create_dim( id_set_xz(av), 'yv_xz', ns,                  &
     2375                                  id_dim_yv_xz(av), 369 )
     2376          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_yv_xz(av) /),       &
     2377                                  'yv_xz', NF90_DOUBLE, id_var_yv_xz(av),      &
     2378                                  'meters', '', 370, 371, 000 )
    24452379!
    24462380!--       Define a variable to store the layer indices of the vertical cross
    24472381!--       sections
    2448           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'ind_y_xz', NF90_DOUBLE, &
    2449                                   id_dim_y_xz(av), id_var_ind_y_xz(av) )
    2450           CALL handle_netcdf_error( 'netcdf', 148 )
    2451 
    2452           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_ind_y_xz(av), 'units', &
    2453                                   'gridpoints')
    2454           CALL handle_netcdf_error( 'netcdf', 149 )
    2455 
     2382          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_y_xz(av) /),        &
     2383                                  'ind_y_xz', NF90_DOUBLE,                     &
     2384                                  id_var_ind_y_xz(av), 'gridpoints', '', 148,  &
     2385                                  149, 000 )
    24562386!
    24572387!--       Define x-axis (for scalar position)
    2458           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'x', nx+2, id_dim_x_xz(av) )
    2459           CALL handle_netcdf_error( 'netcdf', 150 )
    2460 
    2461           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'x', NF90_DOUBLE, &
    2462                                   id_dim_x_xz(av), id_var_x_xz(av) )
    2463           CALL handle_netcdf_error( 'netcdf', 151 )
    2464 
    2465           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_x_xz(av), 'units', &
    2466                                   'meters' )
    2467           CALL handle_netcdf_error( 'netcdf', 152 )
    2468 
     2388          CALL netcdf_create_dim( id_set_xz(av), 'x', nx+2, id_dim_x_xz(av),   &
     2389                                  150 )
     2390          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_x_xz(av) /), 'x',   &
     2391                                  NF90_DOUBLE, id_var_x_xz(av), 'meters', '',  &
     2392                                  151, 152, 000 )
    24692393!
    24702394!--       Define x-axis (for u position)
    2471           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'xu', nx+2, id_dim_xu_xz(av) )
    2472           CALL handle_netcdf_error( 'netcdf', 372 )
    2473 
    2474           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'xu', NF90_DOUBLE, &
    2475                                   id_dim_xu_xz(av), id_var_xu_xz(av) )
    2476           CALL handle_netcdf_error( 'netcdf', 373 )
    2477 
    2478           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_xu_xz(av), 'units', &
    2479                                   'meters' )
    2480           CALL handle_netcdf_error( 'netcdf', 374 )
    2481 
     2395          CALL netcdf_create_dim( id_set_xz(av), 'xu', nx+2, id_dim_xu_xz(av), &
     2396                                  372 )
     2397          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_xu_xz(av) /), 'xu', &
     2398                                  NF90_DOUBLE, id_var_xu_xz(av), 'meters', '', &
     2399                                  373, 374, 000 )
    24822400!
    24832401!--       Define the three z-axes (zu, zw, and zs)
    2484           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'zu', nz+2, id_dim_zu_xz(av) )
    2485           CALL handle_netcdf_error( 'netcdf', 153 )
    2486 
    2487           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'zu', NF90_DOUBLE, &
    2488                                   id_dim_zu_xz(av), id_var_zu_xz(av) )
    2489           CALL handle_netcdf_error( 'netcdf', 154 )
    2490 
    2491           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_zu_xz(av), 'units', &
    2492                                   'meters' )
    2493           CALL handle_netcdf_error( 'netcdf', 155 )
    2494 
    2495           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'zw', nz+2, id_dim_zw_xz(av) )
    2496           CALL handle_netcdf_error( 'netcdf', 156 )
    2497 
    2498           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'zw', NF90_DOUBLE, &
    2499                                   id_dim_zw_xz(av), id_var_zw_xz(av) )
    2500           CALL handle_netcdf_error( 'netcdf', 157 )
    2501 
    2502           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_zw_xz(av), 'units', &
    2503                                   'meters' )
    2504           CALL handle_netcdf_error( 'netcdf', 158 )
     2402          CALL netcdf_create_dim( id_set_xz(av), 'zu', nz+2, id_dim_zu_xz(av), &
     2403                                  153 )
     2404          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_zu_xz(av) /), 'zu', &
     2405                                  NF90_DOUBLE, id_var_zu_xz(av), 'meters', '', &
     2406                                  154, 155, 000 )
     2407          CALL netcdf_create_dim( id_set_xz(av), 'zw', nz+2, id_dim_zw_xz(av), &
     2408                                  156 )
     2409          CALL netcdf_create_var( id_set_xz(av), (/ id_dim_zw_xz(av) /), 'zw', &
     2410                                  NF90_DOUBLE, id_var_zw_xz(av), 'meters', '', &
     2411                                  157, 158, 000 )
    25052412
    25062413          IF ( land_surface )  THEN
    25072414
    2508              nc_stat = NF90_DEF_DIM( id_set_xz(av), 'zs', nzs, id_dim_zs_xz(av) )
    2509              CALL handle_netcdf_error( 'netcdf', 542 )
    2510 
    2511              nc_stat = NF90_DEF_VAR( id_set_xz(av), 'zs', NF90_DOUBLE, &
    2512                                      id_dim_zs_xz(av), id_var_zs_xz(av) )
    2513              CALL handle_netcdf_error( 'netcdf', 543 )
    2514 
    2515              nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_zs_xz(av), 'units', &
    2516                                      'meters' )
    2517              CALL handle_netcdf_error( 'netcdf', 544 )
     2415             CALL netcdf_create_dim( id_set_xz(av), 'zs', nzs,                 &
     2416                                     id_dim_zs_xz(av), 542 )
     2417             CALL netcdf_create_var( id_set_xz(av), (/ id_dim_zs_xz(av) /),    &
     2418                                     'zs', NF90_DOUBLE, id_var_zs_xz(av),      &
     2419                                     'meters', '', 543, 544, 000 )
    25182420
    25192421          ENDIF
     
    25802482                      CALL user_define_netcdf_grid( do2d(av,i), found, &
    25812483                                                    grid_x, grid_y, grid_z )
     2484                      IF ( .NOT. found )  THEN
     2485                         WRITE ( message_string, * ) 'no grid defined for', &
     2486                                                ' variable ', TRIM( do2d(av,i) )
     2487                         CALL message( 'define_netcdf_header', 'PA0244', &
     2488                                       0, 1, 0, 6, 0 )
     2489                      ENDIF
    25822490
    25832491                END SELECT
     
    26072515!
    26082516!--             Define the grid
    2609                 nc_stat = NF90_DEF_VAR( id_set_xz(av), do2d(av,i),             &
    2610                                         nc_precision(2),                       &
    2611                                    (/ id_x, id_y, id_z, id_dim_time_xz(av) /), &
    2612                                         id_var_do2d(av,i) )
    2613 
    2614                 IF ( .NOT. found )  THEN
    2615                    WRITE ( message_string, * ) 'no grid defined for', &
    2616                                             ' variable ', TRIM( do2d(av,i) )
    2617                    CALL message( 'define_netcdf_header', 'PA0244',&
    2618                                                                  0, 1, 0, 6, 0 )
    2619                 ENDIF
    2620 
    2621                 var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
    2622 
    2623                 CALL handle_netcdf_error( 'netcdf', 159 )
    2624 !
    2625 !--             Store the 'real' name of the variable (with *, for example)
    2626 !--             in the long_name attribute. This is evaluated by Ferret,
    2627 !--             for example.
    2628                 nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_do2d(av,i), &
    2629                                         'long_name', do2d(av,i) )
    2630                 CALL handle_netcdf_error( 'netcdf', 160 )
    2631 !
    2632 !--             Define the variable's unit
    2633                 nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_do2d(av,i), &
    2634                                         'units', TRIM( do2d_unit(av,i) ) )
    2635                 CALL handle_netcdf_error( 'netcdf', 355 )
     2517                CALL netcdf_create_var( id_set_xz(av), (/ id_x, id_y, id_z,    &
     2518                                        id_dim_time_xz(av) /), do2d(av,i),     &
     2519                                        nc_precision(2), id_var_do2d(av,i),    &
     2520                                        TRIM( do2d_unit(av,i) ), do2d(av,i),   &
     2521                                        159, 160, 355 )
     2522
    26362523#if defined( __netcdf4_parallel )
    26372524
     
    26422529                                                id_var_do2d(av,i), &
    26432530                                                1, 0 )
    2644                    CALL handle_netcdf_error( 'netcdf', 534 )
     2531                   CALL netcdf_handle_error( 'netcdf_define_header', 534 )
    26452532!
    26462533!--                Set independent io operations for parallel io. Collective io
     
    26642551!                                                     NF90_INDEPENDENT )
    26652552                   ENDIF
    2666                    CALL handle_netcdf_error( 'netcdf', 449 )
     2553                   CALL netcdf_handle_error( 'netcdf_define_header', 449 )
    26672554                ENDIF
    26682555#endif
     2556                var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
     2557
    26692558             ENDIF
    26702559
     
    26822571          nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'VAR_LIST', &
    26832572                                  var_list )
    2684           CALL handle_netcdf_error( 'netcdf', 161 )
     2573          CALL netcdf_handle_error( 'netcdf_define_header', 161 )
    26852574
    26862575!
     
    26882577!--       parallel output.
    26892578          nc_stat = NF90_SET_FILL( id_set_xz(av), NF90_NOFILL, oldmode )
    2690           CALL handle_netcdf_error( 'netcdf', 530 )
     2579          CALL netcdf_handle_error( 'netcdf_define_header', 530 )
    26912580
    26922581!
    26932582!--       Leave netCDF define mode
    26942583          nc_stat = NF90_ENDDEF( id_set_xz(av) )
    2695           CALL handle_netcdf_error( 'netcdf', 162 )
     2584          CALL netcdf_handle_error( 'netcdf_define_header', 162 )
    26962585
    26972586!
     
    27162605                                     netcdf_data, start = (/ 1 /),   &
    27172606                                     count = (/ ns /) )
    2718              CALL handle_netcdf_error( 'netcdf', 163 )
     2607             CALL netcdf_handle_error( 'netcdf_define_header', 163 )
    27192608
    27202609!
     
    27302619                                     netcdf_data, start = (/ 1 /),    &
    27312620                                     count = (/ ns /) )
    2732              CALL handle_netcdf_error( 'netcdf', 375 )
     2621             CALL netcdf_handle_error( 'netcdf_define_header', 375 )
    27332622
    27342623!
     
    27382627                                     netcdf_data, start = (/ 1 /),       &
    27392628                                     count = (/ ns /) )
    2740              CALL handle_netcdf_error( 'netcdf', 164 )
     2629             CALL netcdf_handle_error( 'netcdf_define_header', 164 )
    27412630
    27422631
     
    27542643                                     netcdf_data, start = (/ 1 /),   &
    27552644                                     count = (/ nx+2 /) )
    2756              CALL handle_netcdf_error( 'netcdf', 165 )
     2645             CALL netcdf_handle_error( 'netcdf_define_header', 165 )
    27572646
    27582647             DO  i = 0, nx+1
     
    27632652                                     netcdf_data, start = (/ 1 /),    &
    27642653                                     count = (/ nx+2 /) )
    2765              CALL handle_netcdf_error( 'netcdf', 377 )
     2654             CALL netcdf_handle_error( 'netcdf_define_header', 377 )
    27662655
    27672656             DEALLOCATE( netcdf_data )
     
    27752664                                     netcdf_data, start = (/ 1 /),    &
    27762665                                     count = (/ nz+2 /) )
    2777              CALL handle_netcdf_error( 'netcdf', 166 )
     2666             CALL netcdf_handle_error( 'netcdf_define_header', 166 )
    27782667
    27792668             netcdf_data(0:nz+1) = zw(nzb:nzt+1)
     
    27812670                                     netcdf_data, start = (/ 1 /),    &
    27822671                                     count = (/ nz+2 /) )
    2783              CALL handle_netcdf_error( 'netcdf', 167 )
     2672             CALL netcdf_handle_error( 'netcdf_define_header', 167 )
    27842673
    27852674!
     
    27902679                                        netcdf_data(0:nzs), start = (/ 1 /),    &
    27912680                                        count = (/ nzt_soil-nzb_soil+1 /) )
    2792                CALL handle_netcdf_error( 'netcdf', 548 )
     2681               CALL netcdf_handle_error( 'netcdf_define_header', 548 )
    27932682             ENDIF
    27942683
     
    28082697          nc_stat = NF90_GET_ATT( id_set_xz(av), NF90_GLOBAL, 'VAR_LIST', &
    28092698                                  var_list_old )
    2810           CALL handle_netcdf_error( 'netcdf', 168 )
     2699          CALL netcdf_handle_error( 'netcdf_define_header', 168 )
    28112700
    28122701          var_list = ';'
     
    28472736!--       Get and compare the number of vertical cross sections
    28482737          nc_stat = NF90_INQ_VARID( id_set_xz(av), 'y_xz', id_var_y_xz(av) )
    2849           CALL handle_netcdf_error( 'netcdf', 169 )
     2738          CALL netcdf_handle_error( 'netcdf_define_header', 169 )
    28502739
    28512740          nc_stat = NF90_INQUIRE_VARIABLE( id_set_xz(av), id_var_y_xz(av), &
    28522741                                           dimids = id_dim_y_xz_old )
    2853           CALL handle_netcdf_error( 'netcdf', 170 )
     2742          CALL netcdf_handle_error( 'netcdf_define_header', 170 )
    28542743          id_dim_y_xz(av) = id_dim_y_xz_old(1)
    28552744
    28562745          nc_stat = NF90_INQUIRE_DIMENSION( id_set_xz(av), id_dim_y_xz(av), &
    28572746                                            len = ns_old )
    2858           CALL handle_netcdf_error( 'netcdf', 171 )
     2747          CALL netcdf_handle_error( 'netcdf_define_header', 171 )
    28592748
    28602749          IF ( ns /= ns_old )  THEN
     
    28752764
    28762765          nc_stat = NF90_GET_VAR( id_set_xz(av), id_var_y_xz(av), netcdf_data )
    2877           CALL handle_netcdf_error( 'netcdf', 172 )
     2766          CALL netcdf_handle_error( 'netcdf_define_header', 172 )
    28782767
    28792768          DO  i = 1, ns
     
    29152804!--       on the file.
    29162805          nc_stat = NF90_INQ_VARID( id_set_xz(av), 'time', id_var_time_xz(av) )
    2917           CALL handle_netcdf_error( 'netcdf', 173 )
     2806          CALL netcdf_handle_error( 'netcdf_define_header', 173 )
    29182807
    29192808          nc_stat = NF90_INQUIRE_VARIABLE( id_set_xz(av), id_var_time_xz(av), &
    29202809                                           dimids = id_dim_time_old )
    2921           CALL handle_netcdf_error( 'netcdf', 174 )
     2810          CALL netcdf_handle_error( 'netcdf_define_header', 174 )
    29222811          id_dim_time_xz(av) = id_dim_time_old(1)
    29232812
    29242813          nc_stat = NF90_INQUIRE_DIMENSION( id_set_xz(av), id_dim_time_xz(av), &
    29252814                                            len = ntime_count )
    2926           CALL handle_netcdf_error( 'netcdf', 175 )
     2815          CALL netcdf_handle_error( 'netcdf_define_header', 175 )
    29272816
    29282817!
     
    29372826                                  start = (/ do2d_xz_time_count(av) /), &
    29382827                                  count = (/ 1 /) )
    2939           CALL handle_netcdf_error( 'netcdf', 176 )
     2828          CALL netcdf_handle_error( 'netcdf_define_header', 176 )
    29402829
    29412830          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    30082897                nc_stat = NF90_INQ_VARID( id_set_xz(av), do2d(av,i), &
    30092898                                          id_var_do2d(av,i) )
    3010                 CALL handle_netcdf_error( 'netcdf', 177 )
     2899                CALL netcdf_handle_error( 'netcdf_define_header', 177 )
    30112900#if defined( __netcdf4_parallel )
    30122901!
     
    30322921!                                                     NF90_INDEPENDENT )
    30332922                   ENDIF
    3034                    CALL handle_netcdf_error( 'netcdf', 455 )
     2923                   CALL netcdf_handle_error( 'netcdf_define_header', 455 )
    30352924                ENDIF
    30362925#endif
     
    30532942          ENDIF
    30542943          nc_stat = NF90_REDEF( id_set_xz(av) )
    3055           CALL handle_netcdf_error( 'netcdf', 433 )
     2944          CALL netcdf_handle_error( 'netcdf_define_header', 433 )
    30562945          nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'title', &
    30572946                                  TRIM( run_description_header ) //    &
    30582947                                  TRIM( time_average_text ) )
    3059           CALL handle_netcdf_error( 'netcdf', 178 )
     2948          CALL netcdf_handle_error( 'netcdf_define_header', 178 )
    30602949          nc_stat = NF90_ENDDEF( id_set_xz(av) )
    3061           CALL handle_netcdf_error( 'netcdf', 434 )
     2950          CALL netcdf_handle_error( 'netcdf_define_header', 434 )
    30622951          message_string = 'netCDF file for cross-sections ' //           &
    30632952                            TRIM( var ) // ' from previous run found.' // &
     
    30722961          nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'Conventions', &
    30732962                                  'COARDS' )
    3074           CALL handle_netcdf_error( 'netcdf', 179 )
     2963          CALL netcdf_handle_error( 'netcdf_define_header', 179 )
    30752964
    30762965          IF ( av == 0 )  THEN
     
    30832972                                  TRIM( run_description_header ) //    &
    30842973                                  TRIM( time_average_text ) )
    3085           CALL handle_netcdf_error( 'netcdf', 180 )
     2974          CALL netcdf_handle_error( 'netcdf_define_header', 180 )
    30862975          IF ( av == 1 )  THEN
    30872976             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
    30882977             nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'time_avg', &
    30892978                                     TRIM( time_average_text ) )
    3090              CALL handle_netcdf_error( 'netcdf', 180 )
     2979             CALL netcdf_handle_error( 'netcdf_define_header', 180 )
    30912980          ENDIF
    30922981
     
    30962985!--       the performance drops significantly.
    30972986          IF ( netcdf_data_format < 5 )  THEN
    3098              nc_stat = NF90_DEF_DIM( id_set_yz(av), 'time', NF90_UNLIMITED, &
    3099                                      id_dim_time_yz(av) )
    3100              CALL handle_netcdf_error( 'netcdf', 181 )
     2987             CALL netcdf_create_dim( id_set_yz(av), 'time', NF90_UNLIMITED,    &
     2988                                     id_dim_time_yz(av), 181 )
    31012989          ELSE
    3102              nc_stat = NF90_DEF_DIM( id_set_yz(av), 'time', ntdim_2d_yz(av), &
    3103                                      id_dim_time_yz(av) )
    3104              CALL handle_netcdf_error( 'netcdf', 526 )
    3105           ENDIF
    3106 
    3107           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'time', NF90_DOUBLE, &
    3108                                   id_dim_time_yz(av), id_var_time_yz(av) )
    3109           CALL handle_netcdf_error( 'netcdf', 182 )
    3110 
    3111           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_time_yz(av), 'units', &
    3112                                   'seconds')
    3113           CALL handle_netcdf_error( 'netcdf', 183 )
    3114 
     2990             CALL netcdf_create_dim( id_set_yz(av), 'time', ntdim_2d_yz(av),   &
     2991                                     id_dim_time_yz(av), 526 )
     2992          ENDIF
     2993
     2994          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_time_yz(av) /),     &
     2995                                  'time', NF90_DOUBLE, id_var_time_yz(av),     &
     2996                                  'seconds', '', 182, 183, 000 )
    31152997!
    31162998!--       Define the spatial dimensions and coordinates for yz-sections.
     
    31283010!
    31293011!--       Define x axis (for scalar position)
    3130           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'x_yz', ns, id_dim_x_yz(av) )
    3131           CALL handle_netcdf_error( 'netcdf', 184 )
    3132 
    3133           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'x_yz', NF90_DOUBLE, &
    3134                                   id_dim_x_yz(av), id_var_x_yz(av) )
    3135           CALL handle_netcdf_error( 'netcdf', 185 )
    3136 
    3137           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_x_yz(av), 'units', &
    3138                                   'meters' )
    3139           CALL handle_netcdf_error( 'netcdf', 186 )
    3140 
     3012          CALL netcdf_create_dim( id_set_yz(av), 'x_yz', ns, id_dim_x_yz(av),  &
     3013                                  184 )
     3014          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_x_yz(av) /),        &
     3015                                  'x_yz', NF90_DOUBLE, id_var_x_yz(av),        &
     3016                                  'meters', '', 185, 186, 000 )
    31413017!
    31423018!--       Define x axis (for u position)
    3143           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'xu_yz', ns, id_dim_xu_yz(av) )
    3144           CALL handle_netcdf_error( 'netcdf', 377 )
    3145 
    3146           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'xu_yz', NF90_DOUBLE, &
    3147                                   id_dim_xu_yz(av), id_var_xu_yz(av) )
    3148           CALL handle_netcdf_error( 'netcdf', 378 )
    3149 
    3150           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_xu_yz(av), 'units', &
    3151                                   'meters' )
    3152           CALL handle_netcdf_error( 'netcdf', 379 )
    3153 
     3019          CALL netcdf_create_dim( id_set_yz(av), 'xu_yz', ns,                  &
     3020                                  id_dim_xu_yz(av), 377 )
     3021          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_xu_yz(av) /),       &
     3022                                  'xu_yz', NF90_DOUBLE, id_var_xu_yz(av),      &
     3023                                  'meters', '', 378, 379, 000 )
    31543024!
    31553025!--       Define a variable to store the layer indices of the vertical cross
    31563026!--       sections
    3157           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'ind_x_yz', NF90_DOUBLE, &
    3158                                   id_dim_x_yz(av), id_var_ind_x_yz(av) )
    3159           CALL handle_netcdf_error( 'netcdf', 187 )
    3160 
    3161           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_ind_x_yz(av), 'units', &
    3162                                   'gridpoints')
    3163           CALL handle_netcdf_error( 'netcdf', 188 )
    3164 
     3027          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_x_yz(av) /),        &
     3028                                  'ind_x_yz', NF90_DOUBLE,                     &
     3029                                  id_var_ind_x_yz(av), 'gridpoints', '', 187,  &
     3030                                  188, 000 )
    31653031!
    31663032!--       Define y-axis (for scalar position)
    3167           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'y', ny+2, id_dim_y_yz(av) )
    3168           CALL handle_netcdf_error( 'netcdf', 189 )
    3169 
    3170           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'y', NF90_DOUBLE, &
    3171                                   id_dim_y_yz(av), id_var_y_yz(av) )
    3172           CALL handle_netcdf_error( 'netcdf', 190 )
    3173 
    3174           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_y_yz(av), 'units', &
    3175                                   'meters' )
    3176           CALL handle_netcdf_error( 'netcdf', 191 )
    3177 
     3033          CALL netcdf_create_dim( id_set_yz(av), 'y', ny+2, id_dim_y_yz(av),   &
     3034                                  189 )
     3035          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_y_yz(av) /), 'y',   &
     3036                                  NF90_DOUBLE, id_var_y_yz(av), 'meters', '',  &
     3037                                  190, 191, 000 )
    31783038!
    31793039!--       Define y-axis (for v position)
    3180           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'yv', ny+2, id_dim_yv_yz(av) )
    3181           CALL handle_netcdf_error( 'netcdf', 380 )
    3182 
    3183           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'yv', NF90_DOUBLE, &
    3184                                   id_dim_yv_yz(av), id_var_yv_yz(av) )
    3185           CALL handle_netcdf_error( 'netcdf', 381 )
    3186 
    3187           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_yv_yz(av), 'units', &
    3188                                   'meters' )
    3189           CALL handle_netcdf_error( 'netcdf', 382 )
    3190 
     3040          CALL netcdf_create_dim( id_set_yz(av), 'yv', ny+2, id_dim_yv_yz(av), &
     3041                                  380 )
     3042          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_yv_yz(av) /), 'yv', &
     3043                                  NF90_DOUBLE, id_var_yv_yz(av), 'meters', '', &
     3044                                  381, 382, 000 )
    31913045!
    31923046!--       Define the two z-axes (zu and zw)
    3193           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'zu', nz+2, id_dim_zu_yz(av) )
    3194           CALL handle_netcdf_error( 'netcdf', 192 )
    3195 
    3196           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'zu', NF90_DOUBLE, &
    3197                                   id_dim_zu_yz(av), id_var_zu_yz(av) )
    3198           CALL handle_netcdf_error( 'netcdf', 193 )
    3199 
    3200           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_zu_yz(av), 'units', &
    3201                                   'meters' )
    3202           CALL handle_netcdf_error( 'netcdf', 194 )
    3203 
    3204           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'zw', nz+2, id_dim_zw_yz(av) )
    3205           CALL handle_netcdf_error( 'netcdf', 195 )
    3206 
    3207           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'zw', NF90_DOUBLE, &
    3208                                   id_dim_zw_yz(av), id_var_zw_yz(av) )
    3209           CALL handle_netcdf_error( 'netcdf', 196 )
    3210 
    3211           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_zw_yz(av), 'units', &
    3212                                   'meters' )
    3213           CALL handle_netcdf_error( 'netcdf', 197 )
     3047          CALL netcdf_create_dim( id_set_yz(av), 'zu', nz+2, id_dim_zu_yz(av), &
     3048                                  192 )
     3049          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_zu_yz(av) /), 'zu', &
     3050                                  NF90_DOUBLE, id_var_zu_yz(av), 'meters', '', &
     3051                                  193, 194, 000 )
     3052
     3053          CALL netcdf_create_dim( id_set_yz(av), 'zw', nz+2, id_dim_zw_yz(av), &
     3054                                  195 )
     3055          CALL netcdf_create_var( id_set_yz(av), (/ id_dim_zw_yz(av) /), 'zw', &
     3056                                  NF90_DOUBLE, id_var_zw_yz(av), 'meters', '', &
     3057                                  196, 197, 000 )
    32143058
    32153059          IF ( land_surface )  THEN
    32163060
    3217              nc_stat = NF90_DEF_DIM( id_set_yz(av), 'zs', nzs, id_dim_zs_yz(av) )
    3218              CALL handle_netcdf_error( 'netcdf', 545 )
    3219 
    3220              nc_stat = NF90_DEF_VAR( id_set_yz(av), 'zs', NF90_DOUBLE, &
    3221                                      id_dim_zs_yz(av), id_var_zs_yz(av) )
    3222              CALL handle_netcdf_error( 'netcdf', 546 )
    3223 
    3224              nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_zs_yz(av), 'units', &
    3225                                      'meters' )
    3226              CALL handle_netcdf_error( 'netcdf', 547 )
    3227 
    3228           ENDIF
    3229 
     3061             CALL netcdf_create_dim( id_set_yz(av), 'zs', nzs,                 &
     3062                                     id_dim_zs_yz(av), 545 )
     3063             CALL netcdf_create_var( id_set_yz(av), (/ id_dim_zs_yz(av) /),    &
     3064                                     'zs', NF90_DOUBLE, id_var_zs_yz(av),      &
     3065                                     'meters', '', 546, 547, 000 )
     3066
     3067          ENDIF
    32303068
    32313069!
     
    32903128                                                    grid_x, grid_y, grid_z )
    32913129
     3130                      IF ( .NOT. found )  THEN
     3131                         WRITE ( message_string, * ) 'no grid defined for',    &
     3132                                                ' variable ', TRIM( do2d(av,i) )
     3133                         CALL message( 'define_netcdf_header', 'PA0244',       &
     3134                                       0, 1, 0, 6, 0 )
     3135                      ENDIF
     3136
    32923137                END SELECT
    32933138
     
    33163161!
    33173162!--             Define the grid
    3318                 nc_stat = NF90_DEF_VAR( id_set_yz(av), do2d(av,i),             &
    3319                                         nc_precision(3),                       &
    3320                                    (/ id_x, id_y, id_z, id_dim_time_yz(av) /), &
    3321                                         id_var_do2d(av,i) )
    3322 
    3323                 IF ( .NOT. found )  THEN
    3324                    WRITE ( message_string, * ) 'no grid defined for', &
    3325                                             ' variable ', TRIM( do2d(av,i) )
    3326                    CALL message( 'define_netcdf_header', 'PA0244',&
    3327                                                                  0, 1, 0, 6, 0 )
    3328                 ENDIF
    3329 
    3330                 var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
    3331 
    3332                 CALL handle_netcdf_error( 'netcdf', 198 )
    3333 !
    3334 !--             Store the 'real' name of the variable (with *, for example)
    3335 !--             in the long_name attribute. This is evaluated by Ferret,
    3336 !--             for example.
    3337                 nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_do2d(av,i), &
    3338                                         'long_name', do2d(av,i) )
    3339                 CALL handle_netcdf_error( 'netcdf', 199 )
    3340 !
    3341 !--             Define the variable's unit
    3342                 nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_do2d(av,i), &
    3343                                         'units', TRIM( do2d_unit(av,i) ) )
    3344                 CALL handle_netcdf_error( 'netcdf', 356 )
     3163                CALL netcdf_create_var( id_set_yz(av),  (/ id_x, id_y, id_z,   &
     3164                                        id_dim_time_yz(av) /), do2d(av,i),     &
     3165                                        nc_precision(3), id_var_do2d(av,i),    &
     3166                                        TRIM( do2d_unit(av,i) ), do2d(av,i),   &
     3167                                        198, 199, 356 )
     3168
    33453169#if defined( __netcdf4_parallel )
    33463170                IF ( netcdf_data_format > 4 )  THEN
     
    33503174                                                id_var_do2d(av,i), &
    33513175                                                1, 0 )
    3352                    CALL handle_netcdf_error( 'netcdf', 535 )
     3176                   CALL netcdf_handle_error( 'netcdf_define_header', 535 )
    33533177!
    33543178!--                Set independent io operations for parallel io. Collective io
     
    33723196!                                                     NF90_INDEPENDENT )
    33733197                   ENDIF
    3374                    CALL handle_netcdf_error( 'netcdf', 450 )
     3198                   CALL netcdf_handle_error( 'netcdf_define_header', 450 )
    33753199                ENDIF
    33763200#endif
     3201                var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
     3202
    33773203             ENDIF
    33783204
     
    33903216          nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'VAR_LIST', &
    33913217                                  var_list )
    3392           CALL handle_netcdf_error( 'netcdf', 200 )
     3218          CALL netcdf_handle_error( 'netcdf_define_header', 200 )
    33933219
    33943220!
     
    33963222!--       parallel output.
    33973223          nc_stat = NF90_SET_FILL( id_set_yz(av), NF90_NOFILL, oldmode )
    3398           CALL handle_netcdf_error( 'netcdf', 531 )
     3224          CALL netcdf_handle_error( 'netcdf_define_header', 531 )
    33993225
    34003226!
    34013227!--       Leave netCDF define mode
    34023228          nc_stat = NF90_ENDDEF( id_set_yz(av) )
    3403           CALL handle_netcdf_error( 'netcdf', 201 )
     3229          CALL netcdf_handle_error( 'netcdf_define_header', 201 )
    34043230
    34053231!
     
    34243250                                     netcdf_data, start = (/ 1 /),   &
    34253251                                     count = (/ ns /) )
    3426              CALL handle_netcdf_error( 'netcdf', 202 )
     3252             CALL netcdf_handle_error( 'netcdf_define_header', 202 )
    34273253
    34283254!
     
    34383264                                     netcdf_data, start = (/ 1 /),    &
    34393265                                     count = (/ ns /) )
    3440              CALL handle_netcdf_error( 'netcdf', 383 )
     3266             CALL netcdf_handle_error( 'netcdf_define_header', 383 )
    34413267
    34423268!
     
    34463272                                     netcdf_data, start = (/ 1 /),       &
    34473273                                     count = (/ ns /) )
    3448              CALL handle_netcdf_error( 'netcdf', 203 )
     3274             CALL netcdf_handle_error( 'netcdf_define_header', 203 )
    34493275
    34503276             DEALLOCATE( netcdf_data )
     
    34613287                                     netcdf_data, start = (/ 1 /),   &
    34623288                                     count = (/ ny+2 /) )
    3463              CALL handle_netcdf_error( 'netcdf', 204 )
     3289             CALL netcdf_handle_error( 'netcdf_define_header', 204 )
    34643290
    34653291             DO  j = 0, ny+1
     
    34703296                                     netcdf_data, start = (/ 1 /),    &
    34713297                                     count = (/ ny+2 /) )
    3472              CALL handle_netcdf_error( 'netcdf', 384 )
     3298             CALL netcdf_handle_error( 'netcdf_define_header', 384 )
    34733299
    34743300             DEALLOCATE( netcdf_data )
     
    34823308                                     netcdf_data, start = (/ 1 /),    &
    34833309                                     count = (/ nz+2 /) )
    3484              CALL handle_netcdf_error( 'netcdf', 205 )
     3310             CALL netcdf_handle_error( 'netcdf_define_header', 205 )
    34853311
    34863312             netcdf_data(0:nz+1) = zw(nzb:nzt+1)
     
    34883314                                     netcdf_data, start = (/ 1 /),    &
    34893315                                     count = (/ nz+2 /) )
    3490              CALL handle_netcdf_error( 'netcdf', 206 )
     3316             CALL netcdf_handle_error( 'netcdf_define_header', 206 )
    34913317
    34923318             DEALLOCATE( netcdf_data )
     
    35043330          nc_stat = NF90_GET_ATT( id_set_yz(av), NF90_GLOBAL, 'VAR_LIST', &
    35053331                                  var_list_old )
    3506           CALL handle_netcdf_error( 'netcdf', 207 )
     3332          CALL netcdf_handle_error( 'netcdf_define_header', 207 )
    35073333
    35083334          var_list = ';'
     
    35433369!--       Get and compare the number of vertical cross sections
    35443370          nc_stat = NF90_INQ_VARID( id_set_yz(av), 'x_yz', id_var_x_yz(av) )
    3545           CALL handle_netcdf_error( 'netcdf', 208 )
     3371          CALL netcdf_handle_error( 'netcdf_define_header', 208 )
    35463372
    35473373          nc_stat = NF90_INQUIRE_VARIABLE( id_set_yz(av), id_var_x_yz(av), &
    35483374                                           dimids = id_dim_x_yz_old )
    3549           CALL handle_netcdf_error( 'netcdf', 209 )
     3375          CALL netcdf_handle_error( 'netcdf_define_header', 209 )
    35503376          id_dim_x_yz(av) = id_dim_x_yz_old(1)
    35513377
    35523378          nc_stat = NF90_INQUIRE_DIMENSION( id_set_yz(av), id_dim_x_yz(av), &
    35533379                                            len = ns_old )
    3554           CALL handle_netcdf_error( 'netcdf', 210 )
     3380          CALL netcdf_handle_error( 'netcdf_define_header', 210 )
    35553381
    35563382          IF ( ns /= ns_old )  THEN
     
    35713397
    35723398          nc_stat = NF90_GET_VAR( id_set_yz(av), id_var_x_yz(av), netcdf_data )
    3573           CALL handle_netcdf_error( 'netcdf', 211 )
     3399          CALL netcdf_handle_error( 'netcdf_define_header', 211 )
    35743400
    35753401          DO  i = 1, ns
     
    36113437!--       on the file.
    36123438          nc_stat = NF90_INQ_VARID( id_set_yz(av), 'time', id_var_time_yz(av) )
    3613           CALL handle_netcdf_error( 'netcdf', 212 )
     3439          CALL netcdf_handle_error( 'netcdf_define_header', 212 )
    36143440
    36153441          nc_stat = NF90_INQUIRE_VARIABLE( id_set_yz(av), id_var_time_yz(av), &
    36163442                                           dimids = id_dim_time_old )
    3617           CALL handle_netcdf_error( 'netcdf', 213 )
     3443          CALL netcdf_handle_error( 'netcdf_define_header', 213 )
    36183444          id_dim_time_yz(av) = id_dim_time_old(1)
    36193445
    36203446          nc_stat = NF90_INQUIRE_DIMENSION( id_set_yz(av), id_dim_time_yz(av), &
    36213447                                            len = ntime_count )
    3622           CALL handle_netcdf_error( 'netcdf', 214 )
     3448          CALL netcdf_handle_error( 'netcdf_define_header', 214 )
    36233449
    36243450!
     
    36333459                                  start = (/ do2d_yz_time_count(av) /), &
    36343460                                  count = (/ 1 /) )
    3635           CALL handle_netcdf_error( 'netcdf', 215 )
     3461          CALL netcdf_handle_error( 'netcdf_define_header', 215 )
    36363462
    36373463          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    37043530                nc_stat = NF90_INQ_VARID( id_set_yz(av), do2d(av,i), &
    37053531                                          id_var_do2d(av,i) )
    3706                 CALL handle_netcdf_error( 'netcdf', 216 )
     3532                CALL netcdf_handle_error( 'netcdf_define_header', 216 )
    37073533#if defined( __netcdf4_parallel )
    37083534!
     
    37283554!                                                     NF90_INDEPENDENT )
    37293555                   ENDIF
    3730                    CALL handle_netcdf_error( 'netcdf', 450 )
     3556                   CALL netcdf_handle_error( 'netcdf_define_header', 450 )
    37313557                ENDIF
    37323558#endif
     
    37493575          ENDIF
    37503576          nc_stat = NF90_REDEF( id_set_yz(av) )
    3751           CALL handle_netcdf_error( 'netcdf', 435 )
     3577          CALL netcdf_handle_error( 'netcdf_define_header', 435 )
    37523578          nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'title', &
    37533579                                  TRIM( run_description_header ) //    &
    37543580                                  TRIM( time_average_text ) )
    3755           CALL handle_netcdf_error( 'netcdf', 217 )
     3581          CALL netcdf_handle_error( 'netcdf_define_header', 217 )
    37563582          nc_stat = NF90_ENDDEF( id_set_yz(av) )
    3757           CALL handle_netcdf_error( 'netcdf', 436 )
     3583          CALL netcdf_handle_error( 'netcdf_define_header', 436 )
    37583584          message_string = 'netCDF file for cross-sections ' //           &
    37593585                            TRIM( var ) // ' from previous run found.' // &
     
    37723598                                     TRIM( run_description_header ) //  &
    37733599                                     TRIM( time_average_text ) )
    3774              CALL handle_netcdf_error( 'netcdf', 218 )
     3600             CALL netcdf_handle_error( 'netcdf_define_header', 218 )
    37753601
    37763602             WRITE ( time_average_text,'(F7.1,'' s avg'')' ) averaging_interval_pr
     
    37813607                                     TRIM( run_description_header ) )
    37823608          ENDIF
    3783           CALL handle_netcdf_error( 'netcdf', 219 )
     3609          CALL netcdf_handle_error( 'netcdf_define_header', 219 )
    37843610
    37853611!
     
    37903616                                  'no_rows',                                  &
    37913617                                  profile_rows )
    3792           CALL handle_netcdf_error( 'netcdf', 519 )
     3618          CALL netcdf_handle_error( 'netcdf_define_header', 519 )
    37933619
    37943620          nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL,                     &
    37953621                                  'no_columns',                               &
    37963622                                  profile_columns )
    3797           CALL handle_netcdf_error( 'netcdf', 520 )
     3623          CALL netcdf_handle_error( 'netcdf_define_header', 520 )
    37983624
    37993625
     
    38313657!--       Check if all profiles defined in cross_profiles are defined in
    38323658!--       data_output_pr. If not, they will be skipped.
    3833 
    38343659          DO  i = 1, cross_profiles_count
    38353660             DO  j = 1, dopr_n
     
    38693694!--       Check if all profiles defined in data_output_pr are defined in
    38703695!--       cross_profiles. If not, they will be added to cross_profiles.
    3871 
    38723696          DO  i = 1, dopr_n
    38733697             DO  j = 1, cross_profiles_count
     
    39293753          nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'cross_profiles',   &
    39303754                                  TRIM( char_cross_profiles ) )
    3931           CALL handle_netcdf_error( 'netcdf', 521 )
     3755          CALL netcdf_handle_error( 'netcdf_define_header', 521 )
    39323756
    39333757!
    39343758!--       Define time coordinate for profiles (unlimited dimension)
    3935           nc_stat = NF90_DEF_DIM( id_set_pr, 'time', NF90_UNLIMITED, &
    3936                                   id_dim_time_pr )
    3937           CALL handle_netcdf_error( 'netcdf', 220 )
    3938 
    3939           nc_stat = NF90_DEF_VAR( id_set_pr, 'time', NF90_DOUBLE, &
    3940                                   id_dim_time_pr, id_var_time_pr )
    3941           CALL handle_netcdf_error( 'netcdf', 221 )
    3942 
    3943           nc_stat = NF90_PUT_ATT( id_set_pr, id_var_time_pr, 'units', 'seconds')
    3944           CALL handle_netcdf_error( 'netcdf', 222 )
    3945 
     3759          CALL netcdf_create_dim( id_set_pr, 'time', NF90_UNLIMITED,           &
     3760                                  id_dim_time_pr, 220 )
     3761          CALL netcdf_create_var( id_set_pr, (/ id_dim_time_pr /), 'time',     &
     3762                                  NF90_DOUBLE, id_var_time_pr, 'seconds', '',  &
     3763                                  221, 222, 000 )
    39463764!
    39473765!--       Define the variables
     
    39533771!
    39543772!--             Define the z-axes (each variable gets its own z-axis)
    3955                 nc_stat = NF90_DEF_DIM( id_set_pr,                        &
    3956                                         'z' // TRIM( data_output_pr(i) ), &
    3957                                         nzt+2-nzb, id_dim_z_pr(i,0) )
    3958                 CALL handle_netcdf_error( 'netcdf', 223 )
    3959 
    3960                 nc_stat = NF90_DEF_VAR( id_set_pr,                        &
    3961                                         'z' // TRIM( data_output_pr(i) ), &
    3962                                         NF90_DOUBLE, id_dim_z_pr(i,0),    &
    3963                                         id_var_z_pr(i,0) )
    3964                 CALL handle_netcdf_error( 'netcdf', 224 )
    3965 
    3966                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_z_pr(i,0), 'units', &
    3967                                         'meters' )
    3968                 CALL handle_netcdf_error( 'netcdf', 225 )
     3773                CALL netcdf_create_dim( id_set_pr,                             &
     3774                                        'z' // TRIM( data_output_pr(i) ),      &
     3775                                        nzt+2-nzb, id_dim_z_pr(i,0), 223 )
     3776                CALL netcdf_create_var( id_set_pr, (/ id_dim_z_pr(i,0) /),     &
     3777                                        'z' // TRIM( data_output_pr(i) ),      &
     3778                                       NF90_DOUBLE, id_var_z_pr(i,0),          &
     3779                                       'meters', '', 224, 225, 000 )
    39693780!
    39703781!--             Define the variable
    3971                 nc_stat = NF90_DEF_VAR( id_set_pr, data_output_pr(i),         &
    3972                                         nc_precision(5), (/ id_dim_z_pr(i,0), &
    3973                                         id_dim_time_pr /), id_var_dopr(i,0) )
    3974                 CALL handle_netcdf_error( 'netcdf', 226 )
    3975 
    3976                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,0), &
    3977                                         'long_name', TRIM( data_output_pr(i) ) )
    3978                 CALL handle_netcdf_error( 'netcdf', 227 )
    3979 
    3980                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,0), &
    3981                                         'units', TRIM( dopr_unit(i) ) )
    3982                 CALL handle_netcdf_error( 'netcdf', 228 )
     3782                CALL netcdf_create_var( id_set_pr, (/ id_dim_z_pr(i,0),        &
     3783                                        id_dim_time_pr /), data_output_pr(i),  &
     3784                                        nc_precision(5), id_var_dopr(i,0),     &
     3785                                        TRIM( dopr_unit(i) ),                  &
     3786                                        TRIM( data_output_pr(i) ), 226, 227,   &
     3787                                        228 )
    39833788
    39843789                var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) //  ';'
     
    39933798!
    39943799!--                Define the z-axes (each variable gets it own z-axis)
    3995                    nc_stat = NF90_DEF_DIM( id_set_pr,                          &
    3996                                          'z'//TRIM(data_output_pr(i))//suffix, &
    3997                                            nzt+2-nzb, id_dim_z_pr(i,j) )
    3998                    CALL handle_netcdf_error( 'netcdf', 229 )
    3999 
    4000                    nc_stat = NF90_DEF_VAR( id_set_pr,                          &
    4001                                          'z'//TRIM(data_output_pr(i))//suffix, &
    4002                                            nc_precision(5), id_dim_z_pr(i,j),  &
    4003                                            id_var_z_pr(i,j) )
    4004                    CALL handle_netcdf_error( 'netcdf', 230 )
    4005 
    4006                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_z_pr(i,j), &
    4007                                            'units', 'meters' )
    4008                    CALL handle_netcdf_error( 'netcdf', 231 )
    4009 
     3800                   CALL netcdf_create_dim( id_set_pr, 'z' //                   &
     3801                                           TRIM(data_output_pr(i)) // suffix,  &
     3802                                           nzt+2-nzb, id_dim_z_pr(i,j), 229 )
     3803                   CALL netcdf_create_var( id_set_pr, (/ id_dim_z_pr(i,j) /),  &
     3804                                           'z' // TRIM(data_output_pr(i)) //   &
     3805                                           suffix, NF90_DOUBLE,                &
     3806                                           id_var_z_pr(i,j), 'meters', '',     &
     3807                                           230, 231, 000 )
    40103808!
    40113809!--                Define the variable
    4012                    nc_stat = NF90_DEF_VAR( id_set_pr,                         &
    4013                                            TRIM(data_output_pr(i)) // suffix, &
    4014                                            nc_precision(5),                   &
    4015                                            (/ id_dim_z_pr(i,j),               &
    4016                                            id_dim_time_pr /), id_var_dopr(i,j) )
    4017                    CALL handle_netcdf_error( 'netcdf', 232 )
    4018 
    4019                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,j),        &
    4020                                            'long_name',                        &
    4021                                            TRIM( data_output_pr(i) ) // ' SR ' &
    4022                                            // suffix(2:2) )
    4023                    CALL handle_netcdf_error( 'netcdf', 233 )
    4024 
    4025                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,j), &
    4026                                            'units', TRIM( dopr_unit(i) ) )
    4027                    CALL handle_netcdf_error( 'netcdf', 234 )
     3810                   CALL netcdf_create_var( id_set_pr, (/ id_dim_z_pr(i,j),     &
     3811                                           id_dim_time_pr /),                  &
     3812                                           TRIM(data_output_pr(i)) // suffix,  &
     3813                                           nc_precision(5), id_var_dopr(i,j),  &
     3814                                           TRIM( dopr_unit(i) ),               &
     3815                                           TRIM( data_output_pr(i) ) //        &
     3816                                           ' SR ', 232, 233, 234 )
    40283817
    40293818                   var_list = TRIM( var_list ) // TRIM( data_output_pr(i) ) // &
     
    40403829!--       restart runs)
    40413830          nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'VAR_LIST', var_list )
    4042           CALL handle_netcdf_error( 'netcdf', 235 )
     3831          CALL netcdf_handle_error( 'netcdf_define_header', 235 )
    40433832
    40443833!
     
    40463835          DO  i = 1, dopr_norm_num
    40473836
    4048              nc_stat = NF90_DEF_VAR( id_set_pr, 'NORM_' // &
    4049                                      TRIM( dopr_norm_names(i) ), &
    4050                                      nc_precision(5), (/ id_dim_time_pr /), &
    4051                                      id_var_norm_dopr(i) )
    4052              CALL handle_netcdf_error( 'netcdf', 236 )
    4053 
    4054              nc_stat = NF90_PUT_ATT( id_set_pr, id_var_norm_dopr(i), &
    4055                                      'long_name',                    &
    4056                                      TRIM( dopr_norm_longnames(i) ) )
    4057              CALL handle_netcdf_error( 'netcdf', 237 )
     3837             CALL netcdf_create_var( id_set_pr, (/ id_dim_time_pr /),          &
     3838                                     'NORM_' // TRIM( dopr_norm_names(i) ),    &
     3839                                     nc_precision(5), id_var_norm_dopr(i),     &
     3840                                     '', TRIM( dopr_norm_longnames(i) ), 236,  &
     3841                                     000, 237 )
    40583842
    40593843          ENDDO
     
    40623846!--       Leave netCDF define mode
    40633847          nc_stat = NF90_ENDDEF( id_set_pr )
    4064           CALL handle_netcdf_error( 'netcdf', 238 )
     3848          CALL netcdf_handle_error( 'netcdf_define_header', 238 )
    40653849
    40663850!
     
    40733857                                        start = (/ 1 /),                  &
    40743858                                        count = (/ nzt-nzb+2 /) )
    4075                 CALL handle_netcdf_error( 'netcdf', 239 )
     3859                CALL netcdf_handle_error( 'netcdf_define_header', 239 )
    40763860
    40773861             ENDDO
     
    40883872          nc_stat = NF90_GET_ATT( id_set_pr, NF90_GLOBAL, 'VAR_LIST', &
    40893873                                  var_list_old )
    4090           CALL handle_netcdf_error( 'netcdf', 240 )
     3874          CALL netcdf_handle_error( 'netcdf_define_header', 240 )
    40913875
    40923876          var_list = ';'
     
    41223906!--       on the file.
    41233907          nc_stat = NF90_INQ_VARID( id_set_pr, 'time', id_var_time_pr )
    4124           CALL handle_netcdf_error( 'netcdf', 241 )
     3908          CALL netcdf_handle_error( 'netcdf_define_header', 241 )
    41253909
    41263910          nc_stat = NF90_INQUIRE_VARIABLE( id_set_pr, id_var_time_pr, &
    41273911                                           dimids = id_dim_time_old )
    4128           CALL handle_netcdf_error( 'netcdf', 242 )
     3912          CALL netcdf_handle_error( 'netcdf_define_header', 242 )
    41293913          id_dim_time_pr = id_dim_time_old(1)
    41303914
    41313915          nc_stat = NF90_INQUIRE_DIMENSION( id_set_pr, id_dim_time_pr, &
    41323916                                            len = dopr_time_count )
    4133           CALL handle_netcdf_error( 'netcdf', 243 )
     3917          CALL netcdf_handle_error( 'netcdf_define_header', 243 )
    41343918
    41353919          nc_stat = NF90_GET_VAR( id_set_pr, id_var_time_pr,        &
     
    41373921                                  start = (/ dopr_time_count /), &
    41383922                                  count = (/ 1 /) )
    4139           CALL handle_netcdf_error( 'netcdf', 244 )
     3923          CALL netcdf_handle_error( 'netcdf_define_header', 244 )
    41403924
    41413925          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    41623946                nc_stat = NF90_INQ_VARID( id_set_pr, data_output_pr(i), &
    41633947                                          id_var_dopr(i,0) )
    4164                 CALL handle_netcdf_error( 'netcdf', 245 )
     3948                CALL netcdf_handle_error( 'netcdf_define_header', 245 )
    41653949             ELSE
    41663950                DO  j = 0, statistic_regions
     
    41693953                   nc_stat = NF90_INQ_VARID( id_set_pr, netcdf_var_name, &
    41703954                                             id_var_dopr(i,j) )
    4171                    CALL handle_netcdf_error( 'netcdf', 246 )
     3955                   CALL netcdf_handle_error( 'netcdf_define_header', 246 )
    41723956                ENDDO
    41733957             ENDIF
     
    41813965                                       'NORM_' // TRIM( dopr_norm_names(i) ), &
    41823966                                       id_var_norm_dopr(i) )
    4183              CALL handle_netcdf_error( 'netcdf', 247 )
     3967             CALL netcdf_handle_error( 'netcdf_define_header', 247 )
    41843968          ENDDO
    41853969
     
    41983982          ENDIF
    41993983          nc_stat = NF90_REDEF( id_set_pr )
    4200           CALL handle_netcdf_error( 'netcdf', 437 )
     3984          CALL netcdf_handle_error( 'netcdf_define_header', 437 )
    42013985          nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'title', &
    42023986                                  TRIM( run_description_header ) //    &
    42033987                                  TRIM( time_average_text ) )
    4204           CALL handle_netcdf_error( 'netcdf', 248 )
     3988          CALL netcdf_handle_error( 'netcdf_define_header', 248 )
    42053989
    42063990          nc_stat = NF90_ENDDEF( id_set_pr )
    4207           CALL handle_netcdf_error( 'netcdf', 438 )
     3991          CALL netcdf_handle_error( 'netcdf_define_header', 438 )
    42083992          message_string = 'netCDF file for vertical profiles ' // &
    42093993                           'from previous run found.' //           &
     
    42184002          nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'title', &
    42194003                                  TRIM( run_description_header ) )
    4220           CALL handle_netcdf_error( 'netcdf', 249 )
     4004          CALL netcdf_handle_error( 'netcdf_define_header', 249 )
    42214005
    42224006!
    42234007!--       Define time coordinate for time series (unlimited dimension)
    4224           nc_stat = NF90_DEF_DIM( id_set_ts, 'time', NF90_UNLIMITED, &
    4225                                   id_dim_time_ts )
    4226           CALL handle_netcdf_error( 'netcdf', 250 )
    4227 
    4228           nc_stat = NF90_DEF_VAR( id_set_ts, 'time', NF90_DOUBLE, &
    4229                                   id_dim_time_ts, id_var_time_ts )
    4230           CALL handle_netcdf_error( 'netcdf', 251 )
    4231 
    4232           nc_stat = NF90_PUT_ATT( id_set_ts, id_var_time_ts, 'units', 'seconds')
    4233           CALL handle_netcdf_error( 'netcdf', 252 )
    4234 
     4008          CALL netcdf_create_dim( id_set_ts, 'time', NF90_UNLIMITED,           &
     4009                                  id_dim_time_ts, 250 )
     4010          CALL netcdf_create_var( id_set_ts, (/ id_dim_time_ts /), 'time',     &
     4011                                  NF90_DOUBLE, id_var_time_ts, 'seconds', '',  &
     4012                                  251, 252, 000 )
    42354013!
    42364014!--       Define the variables
     
    42404018             IF ( statistic_regions == 0 )  THEN
    42414019
    4242                 nc_stat = NF90_DEF_VAR( id_set_ts, dots_label(i),              &
    4243                                         nc_precision(6), (/ id_dim_time_ts /), &
    4244                                         id_var_dots(i,0) )
    4245                 CALL handle_netcdf_error( 'netcdf', 253 )
    4246 
    4247                 nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,0), &
    4248                                         'long_name', TRIM( dots_label(i) ) )
    4249                 CALL handle_netcdf_error( 'netcdf', 254 )
    4250 
    4251                 nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,0), &
    4252                                         'units', TRIM( dots_unit(i) ) )
    4253                 CALL handle_netcdf_error( 'netcdf', 255 )
    4254 
    4255                 var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // ';'
     4020                CALL netcdf_create_var( id_set_ts, (/ id_dim_time_ts /),       &
     4021                                        dots_label(i), nc_precision(6),        &
     4022                                        id_var_dots(i,0),                      &
     4023                                        TRIM( dots_unit(i) ),                  &
     4024                                        TRIM( dots_label(i) ), 253, 254, 255 )
    42564025
    42574026             ELSE
     
    42624031                   WRITE ( suffix, '(''_'',I1)' )  j
    42634032
    4264                    nc_stat = NF90_DEF_VAR( id_set_ts,                         &
    4265                                            TRIM( dots_label(i) ) // suffix,   &
    4266                                            nc_precision(6),                   &
    4267                                            (/ id_dim_time_ts /),              &
    4268                                            id_var_dots(i,j) )
    4269                    CALL handle_netcdf_error( 'netcdf', 256 )
    4270 
    4271                    nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,j),       &
    4272                                            'long_name',                       &
    4273                                            TRIM( dots_label(i) ) // ' SR ' // &
    4274                                            suffix(2:2) )
    4275                    CALL handle_netcdf_error( 'netcdf', 257 )
    4276 
    4277                    nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,j), &
    4278                                            'units', TRIM( dots_unit(i) ) )
    4279                    CALL handle_netcdf_error( 'netcdf', 347 )
    4280 
    4281                    var_list = TRIM( var_list ) // TRIM( dots_label(i) ) // &
    4282                               suffix // ';'
     4033                   CALL netcdf_create_var( id_set_ts, (/ id_dim_time_ts /),    &
     4034                                           TRIM( dots_label(i) ) // suffix,    &
     4035                                           nc_precision(6), id_var_dots(i,j),  &
     4036                                           TRIM( dots_unit(i) ),               &
     4037                                           TRIM( dots_label(i) ) // ' SR ' //  &
     4038                                           suffix(2:2), 256, 257, 347)
    42834039
    42844040                ENDDO
     
    42924048!--       restart runs)
    42934049          nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'VAR_LIST', var_list )
    4294           CALL handle_netcdf_error( 'netcdf', 258 )
     4050          CALL netcdf_handle_error( 'netcdf_define_header', 258 )
    42954051
    42964052!
    42974053!--       Leave netCDF define mode
    42984054          nc_stat = NF90_ENDDEF( id_set_ts )
    4299           CALL handle_netcdf_error( 'netcdf', 259 )
     4055          CALL netcdf_handle_error( 'netcdf_define_header', 259 )
    43004056
    43014057
     
    43094065          nc_stat = NF90_GET_ATT( id_set_ts, NF90_GLOBAL, 'VAR_LIST', &
    43104066                                  var_list_old )
    4311           CALL handle_netcdf_error( 'netcdf', 260 )
     4067          CALL netcdf_handle_error( 'netcdf_define_header', 260 )
    43124068
    43134069          var_list = ';'
     
    43444100!--       on the file.
    43454101          nc_stat = NF90_INQ_VARID( id_set_ts, 'time', id_var_time_ts )
    4346           CALL handle_netcdf_error( 'netcdf', 261 )
     4102          CALL netcdf_handle_error( 'netcdf_define_header', 261 )
    43474103
    43484104          nc_stat = NF90_INQUIRE_VARIABLE( id_set_ts, id_var_time_ts, &
    43494105                                           dimids = id_dim_time_old )
    4350           CALL handle_netcdf_error( 'netcdf', 262 )
     4106          CALL netcdf_handle_error( 'netcdf_define_header', 262 )
    43514107          id_dim_time_ts = id_dim_time_old(1)
    43524108
    43534109          nc_stat = NF90_INQUIRE_DIMENSION( id_set_ts, id_dim_time_ts, &
    43544110                                            len = dots_time_count )
    4355           CALL handle_netcdf_error( 'netcdf', 263 )
     4111          CALL netcdf_handle_error( 'netcdf_define_header', 263 )
    43564112
    43574113          nc_stat = NF90_GET_VAR( id_set_ts, id_var_time_ts,        &
     
    43594115                                  start = (/ dots_time_count /), &
    43604116                                  count = (/ 1 /) )
    4361           CALL handle_netcdf_error( 'netcdf', 264 )
     4117          CALL netcdf_handle_error( 'netcdf_define_header', 264 )
    43624118
    43634119          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    43844140                nc_stat = NF90_INQ_VARID( id_set_ts, dots_label(i), &
    43854141                                          id_var_dots(i,0) )
    4386                 CALL handle_netcdf_error( 'netcdf', 265 )
     4142                CALL netcdf_handle_error( 'netcdf_define_header', 265 )
    43874143             ELSE
    43884144                DO  j = 0, statistic_regions
     
    43914147                   nc_stat = NF90_INQ_VARID( id_set_ts, netcdf_var_name, &
    43924148                                             id_var_dots(i,j) )
    4393                    CALL handle_netcdf_error( 'netcdf', 266 )
     4149                   CALL netcdf_handle_error( 'netcdf_define_header', 266 )
    43944150                ENDDO
    43954151             ENDIF
     
    44054161!--       to ensure equal attribute size in a job chain. Maybe revise later.
    44064162          nc_stat = NF90_REDEF( id_set_ts )
    4407           CALL handle_netcdf_error( 'netcdf', 439 )
     4163          CALL netcdf_handle_error( 'netcdf_define_header', 439 )
    44084164          nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'title', &
    44094165                                  TRIM( run_description_header ) )
    4410           CALL handle_netcdf_error( 'netcdf', 267 )
     4166          CALL netcdf_handle_error( 'netcdf_define_header', 267 )
    44114167          nc_stat = NF90_ENDDEF( id_set_ts )
    4412           CALL handle_netcdf_error( 'netcdf', 440 )
     4168          CALL netcdf_handle_error( 'netcdf_define_header', 440 )
    44134169          message_string = 'netCDF file for time series ' // &
    44144170                           'from previous run found.' //     &
     
    44274183                                     TRIM( run_description_header ) // &
    44284184                                     TRIM( time_average_text ) )
    4429              CALL handle_netcdf_error( 'netcdf', 268 )
     4185             CALL netcdf_handle_error( 'netcdf_define_header', 268 )
    44304186
    44314187             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_sp
     
    44364192                                     TRIM( run_description_header ) )
    44374193          ENDIF
    4438           CALL handle_netcdf_error( 'netcdf', 269 )
     4194          CALL netcdf_handle_error( 'netcdf_define_header', 269 )
    44394195
    44404196!
    44414197!--       Define time coordinate for spectra (unlimited dimension)
    4442           nc_stat = NF90_DEF_DIM( id_set_sp, 'time', NF90_UNLIMITED, &
    4443                                   id_dim_time_sp )
    4444           CALL handle_netcdf_error( 'netcdf', 270 )
    4445 
    4446           nc_stat = NF90_DEF_VAR( id_set_sp, 'time', NF90_DOUBLE, &
    4447                                   id_dim_time_sp, id_var_time_sp )
    4448           CALL handle_netcdf_error( 'netcdf', 271 )
    4449 
    4450           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_time_sp, 'units', 'seconds')
    4451           CALL handle_netcdf_error( 'netcdf', 272 )
    4452 
     4198          CALL netcdf_create_dim( id_set_sp, 'time', NF90_UNLIMITED,           &
     4199                                  id_dim_time_sp, 270 )
     4200          CALL netcdf_create_var( id_set_sp, (/ id_dim_time_sp /), 'time',     &
     4201                                  NF90_DOUBLE, id_var_time_sp, 'seconds', '',  &
     4202                                  271, 272, 000 )
    44534203!
    44544204!--       Define the spatial dimensions and coordinates for spectra.
     
    44634213!
    44644214!--       Define vertical coordinate grid (zu grid)
    4465           nc_stat = NF90_DEF_DIM( id_set_sp, 'zu_sp', ns, id_dim_zu_sp )
    4466           CALL handle_netcdf_error( 'netcdf', 273 )
    4467 
    4468           nc_stat = NF90_DEF_VAR( id_set_sp, 'zu_sp', NF90_DOUBLE, &
    4469                                   id_dim_zu_sp, id_var_zu_sp )
    4470           CALL handle_netcdf_error( 'netcdf', 274 )
    4471 
    4472           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_zu_sp, 'units', 'meters' )
    4473           CALL handle_netcdf_error( 'netcdf', 275 )
    4474 
     4215          CALL netcdf_create_dim( id_set_sp, 'zu_sp', ns, id_dim_zu_sp, 273 )
     4216          CALL netcdf_create_var( id_set_sp, (/ id_dim_zu_sp /), 'zu_sp',      &
     4217                                  NF90_DOUBLE, id_var_zu_sp, 'meters', '',     &
     4218                                  274, 275, 000 )
    44754219!
    44764220!--       Define vertical coordinate grid (zw grid)
    4477           nc_stat = NF90_DEF_DIM( id_set_sp, 'zw_sp', ns, id_dim_zw_sp )
    4478           CALL handle_netcdf_error( 'netcdf', 276 )
    4479 
    4480           nc_stat = NF90_DEF_VAR( id_set_sp, 'zw_sp', NF90_DOUBLE, &
    4481                                   id_dim_zw_sp, id_var_zw_sp )
    4482           CALL handle_netcdf_error( 'netcdf', 277 )
    4483 
    4484           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_zw_sp, 'units', 'meters' )
    4485           CALL handle_netcdf_error( 'netcdf', 278 )
    4486 
     4221          CALL netcdf_create_dim( id_set_sp, 'zw_sp', ns, id_dim_zw_sp, 276 )
     4222          CALL netcdf_create_var( id_set_sp, (/ id_dim_zw_sp /), 'zw_sp',      &
     4223                                  NF90_DOUBLE, id_var_zw_sp, 'meters', '',     &
     4224                                  277, 278, 000 )
    44874225!
    44884226!--       Define x-axis
    4489           nc_stat = NF90_DEF_DIM( id_set_sp, 'k_x', nx/2, id_dim_x_sp )
    4490           CALL handle_netcdf_error( 'netcdf', 279 )
    4491 
    4492           nc_stat = NF90_DEF_VAR( id_set_sp, 'k_x', NF90_DOUBLE, id_dim_x_sp, &
    4493                                   id_var_x_sp )
    4494           CALL handle_netcdf_error( 'netcdf', 280 )
    4495 
    4496           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_x_sp, 'units', 'm-1' )
    4497           CALL handle_netcdf_error( 'netcdf', 281 )
    4498 
     4227          CALL netcdf_create_dim( id_set_sp, 'k_x', nx/2, id_dim_x_sp, 279 )
     4228          CALL netcdf_create_var( id_set_sp, (/ id_dim_x_sp /), 'k_x',         &
     4229                                  NF90_DOUBLE, id_var_x_sp, 'm-1', '', 280,    &
     4230                                  281, 000 )
    44994231!
    45004232!--       Define y-axis
    4501           nc_stat = NF90_DEF_DIM( id_set_sp, 'k_y', ny/2, id_dim_y_sp )
    4502           CALL handle_netcdf_error( 'netcdf', 282 )
    4503 
    4504           nc_stat = NF90_DEF_VAR( id_set_sp, 'k_y', NF90_DOUBLE, id_dim_y_sp, &
    4505                                   id_var_y_sp )
    4506           CALL handle_netcdf_error( 'netcdf', 283 )
    4507 
    4508           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_y_sp, 'units', 'm-1' )
    4509           CALL handle_netcdf_error( 'netcdf', 284 )
    4510 
     4233          CALL netcdf_create_dim(id_set_sp, 'k_y', ny/2, id_dim_y_sp, 282 )
     4234          CALL netcdf_create_var( id_set_sp, (/ id_dim_y_sp /), 'k_y',         &
     4235                                  NF90_DOUBLE, id_var_y_sp, 'm-1', '', 283,    &
     4236                                  284, 000 )
    45114237!
    45124238!--       Define the variables
     
    45464272                netcdf_var_name = TRIM( data_output_sp(i) ) // '_x'
    45474273                IF ( TRIM( grid_z ) == 'zw' )  THEN
    4548                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
    4549                                            nc_precision(7), (/ id_dim_x_sp, &
    4550                                            id_dim_zw_sp, id_dim_time_sp /), &
    4551                                            id_var_dospx(i) )
     4274                   CALL netcdf_create_var( id_set_sp, (/ id_dim_x_sp,          &
     4275                                           id_dim_zw_sp, id_dim_time_sp /),    &
     4276                                           netcdf_var_name, nc_precision(7),   &
     4277                                           id_var_dospx(i), 'unknown',         &
     4278                                           netcdf_var_name, 285, 286, 287 )
    45524279                ELSE
    4553                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
    4554                                            nc_precision(7), (/ id_dim_x_sp, &
    4555                                            id_dim_zu_sp, id_dim_time_sp /), &
    4556                                            id_var_dospx(i) )
     4280                   CALL netcdf_create_var( id_set_sp, (/ id_dim_x_sp,          &
     4281                                           id_dim_zu_sp, id_dim_time_sp /),    &
     4282                                           netcdf_var_name, nc_precision(7),   &
     4283                                           id_var_dospx(i), 'unknown',         &
     4284                                           netcdf_var_name, 285, 286, 287 )
    45574285                ENDIF
    4558                 CALL handle_netcdf_error( 'netcdf', 285 )
    4559 
    4560                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospx(i), &
    4561                                         'long_name', netcdf_var_name )
    4562                 CALL handle_netcdf_error( 'netcdf', 286 )
    4563 
    4564                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospx(i), &
    4565                                         'units', 'unknown' )
    4566                 CALL handle_netcdf_error( 'netcdf', 287 )
    45674286
    45684287                var_list = TRIM( var_list ) // TRIM( netcdf_var_name ) // ';'
     
    45764295                netcdf_var_name = TRIM( data_output_sp(i) ) // '_y'
    45774296                IF ( TRIM( grid_z ) == 'zw' )  THEN
    4578                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
    4579                                            nc_precision(7), (/ id_dim_y_sp, &
    4580                                            id_dim_zw_sp, id_dim_time_sp /), &
    4581                                            id_var_dospy(i) )
     4297                   CALL netcdf_create_var( id_set_sp, (/ id_dim_y_sp,          &
     4298                                           id_dim_zw_sp, id_dim_time_sp /),    &
     4299                                           netcdf_var_name, nc_precision(7),   &
     4300                                           id_var_dospy(i), 'unknown',         &
     4301                                           netcdf_var_name, 288, 289, 290 )
    45824302                ELSE
    4583                    nc_stat = NF90_DEF_VAR( id_set_sp, netcdf_var_name,      &
    4584                                            nc_precision(7), (/ id_dim_y_sp, &
    4585                                            id_dim_zu_sp, id_dim_time_sp /), &
    4586                                            id_var_dospy(i) )
     4303                   CALL netcdf_create_var( id_set_sp, (/ id_dim_y_sp,          &
     4304                                           id_dim_zu_sp, id_dim_time_sp /),    &
     4305                                           netcdf_var_name, nc_precision(7),   &
     4306                                           id_var_dospy(i), 'unknown',         &
     4307                                           netcdf_var_name, 288, 289, 290 )
    45874308                ENDIF
    4588                 CALL handle_netcdf_error( 'netcdf', 288 )
    4589 
    4590                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospy(i), &
    4591                                         'long_name', netcdf_var_name )
    4592                 CALL handle_netcdf_error( 'netcdf', 289 )
    4593 
    4594                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospy(i), &
    4595                                         'units', 'unknown' )
    4596                 CALL handle_netcdf_error( 'netcdf', 290 )
    45974309
    45984310                var_list = TRIM( var_list ) // TRIM( netcdf_var_name ) // ';'
     
    46084320!--       restart runs)
    46094321          nc_stat = NF90_PUT_ATT( id_set_sp, NF90_GLOBAL, 'VAR_LIST', var_list )
    4610           CALL handle_netcdf_error( 'netcdf', 291 )
     4322          CALL netcdf_handle_error( 'netcdf_define_header', 291 )
    46114323
    46124324!
    46134325!--       Leave netCDF define mode
    46144326          nc_stat = NF90_ENDDEF( id_set_sp )
    4615           CALL handle_netcdf_error( 'netcdf', 292 )
     4327          CALL netcdf_handle_error( 'netcdf_define_header', 292 )
    46164328
    46174329!
     
    46244336          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_zu_sp, netcdf_data, &
    46254337                                  start = (/ 1 /), count = (/ ns /) )
    4626           CALL handle_netcdf_error( 'netcdf', 293 )
     4338          CALL netcdf_handle_error( 'netcdf_define_header', 293 )
    46274339
    46284340!
     
    46314343          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_zw_sp, netcdf_data, &
    46324344                                  start = (/ 1 /), count = (/ ns /) )
    4633           CALL handle_netcdf_error( 'netcdf', 294 )
     4345          CALL netcdf_handle_error( 'netcdf_define_header', 294 )
    46344346
    46354347          DEALLOCATE( netcdf_data )
     
    46444356          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_x_sp, netcdf_data, &
    46454357                                  start = (/ 1 /), count = (/ nx/2 /) )
    4646           CALL handle_netcdf_error( 'netcdf', 295 )
     4358          CALL netcdf_handle_error( 'netcdf_define_header', 295 )
    46474359
    46484360          DEALLOCATE( netcdf_data )
     
    46554367          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_y_sp, netcdf_data, &
    46564368                                  start = (/ 1 /), count = (/ ny/2 /) )
    4657           CALL handle_netcdf_error( 'netcdf', 296 )
     4369          CALL netcdf_handle_error( 'netcdf_define_header', 296 )
    46584370
    46594371          DEALLOCATE( netcdf_data )
     
    46694381          nc_stat = NF90_GET_ATT( id_set_sp, NF90_GLOBAL, 'VAR_LIST', &
    46704382                                  var_list_old )
    4671           CALL handle_netcdf_error( 'netcdf', 297 )
     4383          CALL netcdf_handle_error( 'netcdf_define_header', 297 )
    46724384          var_list = ';'
    46734385          i = 1
     
    47114423!--       Get and compare the number of vertical levels
    47124424          nc_stat = NF90_INQ_VARID( id_set_sp, 'zu_sp', id_var_zu_sp )
    4713           CALL handle_netcdf_error( 'netcdf', 298 )
     4425          CALL netcdf_handle_error( 'netcdf_define_header', 298 )
    47144426
    47154427          nc_stat = NF90_INQUIRE_VARIABLE( id_set_sp, id_var_zu_sp, &
    47164428                                           dimids = id_dim_zu_sp_old )
    4717           CALL handle_netcdf_error( 'netcdf', 299 )
     4429          CALL netcdf_handle_error( 'netcdf_define_header', 299 )
    47184430          id_dim_zu_sp = id_dim_zu_sp_old(1)
    47194431
    47204432          nc_stat = NF90_INQUIRE_DIMENSION( id_set_sp, id_dim_zu_sp, &
    47214433                                            len = ns_old )
    4722           CALL handle_netcdf_error( 'netcdf', 300 )
     4434          CALL netcdf_handle_error( 'netcdf_define_header', 300 )
    47234435
    47244436          IF ( ns /= ns_old )  THEN
     
    47394451
    47404452          nc_stat = NF90_GET_VAR( id_set_sp, id_var_zu_sp, netcdf_data )
    4741           CALL handle_netcdf_error( 'netcdf', 301 )
     4453          CALL netcdf_handle_error( 'netcdf_define_header', 301 )
    47424454
    47434455          DO  i = 1, ns
     
    47634475!--       on the file.
    47644476          nc_stat = NF90_INQ_VARID( id_set_sp, 'time', id_var_time_sp )
    4765           CALL handle_netcdf_error( 'netcdf', 302 )
     4477          CALL netcdf_handle_error( 'netcdf_define_header', 302 )
    47664478
    47674479          nc_stat = NF90_INQUIRE_VARIABLE( id_set_sp, id_var_time_sp, &
    47684480                                           dimids = id_dim_time_old )
    4769           CALL handle_netcdf_error( 'netcdf', 303 )
     4481          CALL netcdf_handle_error( 'netcdf_define_header', 303 )
    47704482          id_dim_time_sp = id_dim_time_old(1)
    47714483
    47724484          nc_stat = NF90_INQUIRE_DIMENSION( id_set_sp, id_dim_time_sp, &
    47734485                                            len = dosp_time_count )
    4774           CALL handle_netcdf_error( 'netcdf', 304 )
     4486          CALL netcdf_handle_error( 'netcdf_define_header', 304 )
    47754487
    47764488          nc_stat = NF90_GET_VAR( id_set_sp, id_var_time_sp,        &
     
    47784490                                  start = (/ dosp_time_count /), &
    47794491                                  count = (/ 1 /) )
    4780           CALL handle_netcdf_error( 'netcdf', 305 )
     4492          CALL netcdf_handle_error( 'netcdf_define_header', 305 )
    47814493
    47824494          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    48044516                nc_stat = NF90_INQ_VARID( id_set_sp, netcdf_var_name, &
    48054517                                          id_var_dospx(i) )
    4806                 CALL handle_netcdf_error( 'netcdf', 306 )
     4518                CALL netcdf_handle_error( 'netcdf_define_header', 306 )
    48074519             ENDIF
    48084520
     
    48114523                nc_stat = NF90_INQ_VARID( id_set_sp, netcdf_var_name, &
    48124524                                          id_var_dospy(i) )
    4813                 CALL handle_netcdf_error( 'netcdf', 307 )
     4525                CALL netcdf_handle_error( 'netcdf_define_header', 307 )
    48144526             ENDIF
    48154527
     
    48264538!--       to ensure equal attribute size in a job chain. Maybe revise later.
    48274539          nc_stat = NF90_REDEF( id_set_sp )
    4828           CALL handle_netcdf_error( 'netcdf', 441 )
     4540          CALL netcdf_handle_error( 'netcdf_define_header', 441 )
    48294541          IF ( averaging_interval_sp /= 0.0_wp )  THEN
    48304542             WRITE (time_average_text,'('', '',F7.1,'' s average'')') &
     
    48334545                                     TRIM( run_description_header ) // &
    48344546                                     TRIM( time_average_text ) )
    4835              CALL handle_netcdf_error( 'netcdf', 308 )
     4547             CALL netcdf_handle_error( 'netcdf_define_header', 308 )
    48364548
    48374549             WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_sp
     
    48424554                                     TRIM( run_description_header ) )
    48434555          ENDIF
    4844           CALL handle_netcdf_error( 'netcdf', 309 )
     4556          CALL netcdf_handle_error( 'netcdf_define_header', 309 )
    48454557          nc_stat = NF90_ENDDEF( id_set_sp )
    4846           CALL handle_netcdf_error( 'netcdf', 442 )
     4558          CALL netcdf_handle_error( 'netcdf_define_header', 442 )
    48474559          message_string = 'netCDF file for spectra ' //     &
    48484560                           'from previous run found.' //     &
     
    48574569          nc_stat = NF90_PUT_ATT( id_set_prt, NF90_GLOBAL, 'title', &
    48584570                                  TRIM( run_description_header ) )
    4859           CALL handle_netcdf_error( 'netcdf', 310 )
     4571          CALL netcdf_handle_error( 'netcdf_define_header', 310 )
    48604572
    48614573!
    48624574!--       Define time coordinate for particles (unlimited dimension)
    4863           nc_stat = NF90_DEF_DIM( id_set_prt, 'time', NF90_UNLIMITED, &
    4864                                   id_dim_time_prt )
    4865           CALL handle_netcdf_error( 'netcdf', 311 )
    4866 
    4867           nc_stat = NF90_DEF_VAR( id_set_prt, 'time', NF90_DOUBLE, &
    4868                                   id_dim_time_prt, id_var_time_prt )
    4869           CALL handle_netcdf_error( 'netcdf', 312 )
    4870 
    4871           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_time_prt, 'units', &
    4872                                   'seconds' )
    4873           CALL handle_netcdf_error( 'netcdf', 313 )
    4874 
     4575          CALL netcdf_create_dim( id_set_prt, 'time', NF90_UNLIMITED,          &
     4576                                  id_dim_time_prt, 311 )
     4577          CALL netcdf_create_var( id_set_prt, (/ id_dim_time_prt /), 'time',   &
     4578                                  NF90_DOUBLE, id_var_time_prt, 'seconds', '', &
     4579                                  312, 313, 000 )
    48754580!
    48764581!--       Define particle coordinate (maximum particle number)
    48774582          IF ( netcdf_data_format < 3 )  THEN
    4878              nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
    4879                                      maximum_number_of_particles, id_dim_prtnum)
     4583             CALL netcdf_create_dim( id_set_prt, 'particle_number',            &
     4584                                     maximum_number_of_particles,              &
     4585                                     id_dim_prtnum, 314 )
    48804586          ELSE
    48814587!
    48824588!--          netCDF4 allows more than one unlimited dimension
    4883              nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
    4884                                      NF90_UNLIMITED, id_dim_prtnum)
    4885           ENDIF
    4886           CALL handle_netcdf_error( 'netcdf', 314 )
    4887 
    4888           nc_stat = NF90_DEF_VAR( id_set_prt, 'particle_number', NF90_DOUBLE, &
    4889                                   id_dim_prtnum, id_var_prtnum )
    4890           CALL handle_netcdf_error( 'netcdf', 315 )
    4891 
    4892           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prtnum, 'units', &
    4893                                   'particle number' )
    4894           CALL handle_netcdf_error( 'netcdf', 316 )
    4895 
     4589             CALL netcdf_create_dim( id_set_prt, 'particle_number',            &
     4590                                     NF90_UNLIMITED, id_dim_prtnum, 314 )
     4591          ENDIF
     4592
     4593          CALL netcdf_create_var( id_set_prt, (/ id_dim_prtnum /),             &
     4594                                  'particle_number', NF90_DOUBLE,              &
     4595                                  id_var_prtnum, 'particle number', '', 315,   &
     4596                                  316, 000 )
    48964597!
    48974598!--       Define variable which contains the real number of particles in use
    4898           nc_stat = NF90_DEF_VAR( id_set_prt, 'real_num_of_prt', NF90_INT, &
    4899                                   id_dim_time_prt, id_var_rnop_prt )
    4900           CALL handle_netcdf_error( 'netcdf', 317 )
    4901 
    4902           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_rnop_prt, 'units', &
    4903                                   'particle number' )
    4904           CALL handle_netcdf_error( 'netcdf', 318 )
    4905 
     4599          CALL netcdf_create_var( id_set_prt, (/ id_dim_time_prt /),           &
     4600                                  'real_num_of_prt', NF90_DOUBLE,              &
     4601                                  id_var_rnop_prt, 'particle number', '', 317, &
     4602                                  318, 000 )
    49064603!
    49074604!--       Define the variables
    49084605          DO  i = 1, 17
    49094606
    4910              nc_stat = NF90_DEF_VAR( id_set_prt, prt_var_names(i),         &
    4911                                      nc_precision(8),                      &
    4912                                      (/ id_dim_prtnum, id_dim_time_prt /), &
    4913                                      id_var_prt(i) )
    4914              CALL handle_netcdf_error( 'netcdf', 319 )
    4915 
    4916              nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prt(i), &
    4917                                      'long_name', TRIM( prt_var_names(i) ) )
    4918              CALL handle_netcdf_error( 'netcdf', 320 )
    4919 
    4920              nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prt(i), &
    4921                                      'units', TRIM( prt_var_units(i) ) )
    4922              CALL handle_netcdf_error( 'netcdf', 321 )
     4607             CALL netcdf_create_var( id_set_prt, (/ id_dim_prtnum,             &
     4608                                     id_dim_time_prt /), prt_var_names(i),     &
     4609                                     nc_precision(8), id_var_prt(i),           &
     4610                                     TRIM( prt_var_units(i) ),                 &
     4611                                     TRIM( prt_var_names(i) ), 319, 320, 321 )
    49234612
    49244613          ENDDO
     
    49274616!--       Leave netCDF define mode
    49284617          nc_stat = NF90_ENDDEF( id_set_prt )
    4929           CALL handle_netcdf_error( 'netcdf', 322 )
     4618          CALL netcdf_handle_error( 'netcdf_define_header', 322 )
    49304619
    49314620
     
    49384627!--       on the file.
    49394628          nc_stat = NF90_INQ_VARID( id_set_prt, 'time', id_var_time_prt )
    4940           CALL handle_netcdf_error( 'netcdf', 323 )
     4629          CALL netcdf_handle_error( 'netcdf_define_header', 323 )
    49414630
    49424631          nc_stat = NF90_INQUIRE_VARIABLE( id_set_prt, id_var_time_prt, &
    49434632                                           dimids = id_dim_time_old )
    4944           CALL handle_netcdf_error( 'netcdf', 324 )
     4633          CALL netcdf_handle_error( 'netcdf_define_header', 324 )
    49454634          id_dim_time_prt = id_dim_time_old(1)
    49464635
    49474636          nc_stat = NF90_INQUIRE_DIMENSION( id_set_prt, id_dim_time_prt, &
    49484637                                            len = prt_time_count )
    4949           CALL handle_netcdf_error( 'netcdf', 325 )
     4638          CALL netcdf_handle_error( 'netcdf_define_header', 325 )
    49504639
    49514640          nc_stat = NF90_GET_VAR( id_set_prt, id_var_time_prt,  &
     
    49534642                                  start = (/ prt_time_count /), &
    49544643                                  count = (/ 1 /) )
    4955           CALL handle_netcdf_error( 'netcdf', 326 )
     4644          CALL netcdf_handle_error( 'netcdf_define_header', 326 )
    49564645
    49574646          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    49744663          nc_stat = NF90_INQ_VARID( id_set_prt, 'real_num_of_prt', &
    49754664                                    id_var_rnop_prt )
    4976           CALL handle_netcdf_error( 'netcdf', 327 )
     4665          CALL netcdf_handle_error( 'netcdf_define_header', 327 )
    49774666
    49784667          DO  i = 1, 17
     
    49804669             nc_stat = NF90_INQ_VARID( id_set_prt, prt_var_names(i), &
    49814670                                       id_var_prt(i) )
    4982              CALL handle_netcdf_error( 'netcdf', 328 )
     4671             CALL netcdf_handle_error( 'netcdf_define_header', 328 )
    49834672
    49844673          ENDDO
     
    49974686          nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'title', &
    49984687                                  TRIM( run_description_header ) )
    4999           CALL handle_netcdf_error( 'netcdf', 396 )
     4688          CALL netcdf_handle_error( 'netcdf_define_header', 396 )
    50004689
    50014690!
    50024691!--       Define time coordinate for particle time series (unlimited dimension)
    5003           nc_stat = NF90_DEF_DIM( id_set_pts, 'time', NF90_UNLIMITED, &
    5004                                   id_dim_time_pts )
    5005           CALL handle_netcdf_error( 'netcdf', 397 )
    5006 
    5007           nc_stat = NF90_DEF_VAR( id_set_pts, 'time', NF90_DOUBLE, &
    5008                                   id_dim_time_pts, id_var_time_pts )
    5009           CALL handle_netcdf_error( 'netcdf', 398 )
    5010 
    5011           nc_stat = NF90_PUT_ATT( id_set_pts, id_var_time_pts, 'units', &
    5012                                   'seconds')
    5013           CALL handle_netcdf_error( 'netcdf', 399 )
    5014 
     4692          CALL netcdf_create_dim( id_set_pts, 'time', NF90_UNLIMITED,          &
     4693                                  id_dim_time_pts, 397 )
     4694          CALL netcdf_create_var( id_set_pts, (/ id_dim_time_pts /), 'time',   &
     4695                                  NF90_DOUBLE, id_var_time_pts, 'seconds', '', &
     4696                                  398, 399, 000 )
    50154697!
    50164698!--       Define the variables. If more than one particle group is defined,
     
    50274709                ENDIF
    50284710
    5029                 nc_stat = NF90_DEF_VAR( id_set_pts,                         &
    5030                                         TRIM( dopts_label(i) ) // suffix1,  &
    5031                                         nc_precision(6),                    &
    5032                                         (/ id_dim_time_pts /),              &
    5033                                         id_var_dopts(i,j) )
    5034                 CALL handle_netcdf_error( 'netcdf', 400 )
    5035 
    50364711                IF ( j == 0 )  THEN
    5037                    nc_stat = NF90_PUT_ATT( id_set_pts, id_var_dopts(i,j), &
    5038                                            'long_name', &
    5039                                            TRIM( dopts_label(i) ) )
     4712                   CALL netcdf_create_var( id_set_pts, (/ id_dim_time_pts /),  &
     4713                                           TRIM( dopts_label(i) ) // suffix1,  &
     4714                                           nc_precision(6), id_var_dopts(i,j), &
     4715                                           TRIM( dopts_unit(i) ),              &
     4716                                           TRIM( dopts_label(i) ), 400, 401,   &
     4717                                           402 )
    50404718                ELSE
    5041                    nc_stat = NF90_PUT_ATT( id_set_pts, id_var_dopts(i,j), &
    5042                                            'long_name', &
     4719                   CALL netcdf_create_var( id_set_pts, (/ id_dim_time_pts /),  &
     4720                                           TRIM( dopts_label(i) ) // suffix1,  &
     4721                                           nc_precision(6), id_var_dopts(i,j), &
     4722                                           TRIM( dopts_unit(i) ),              &
    50434723                                           TRIM( dopts_label(i) ) // ' PG ' // &
    5044                                            suffix1(2:3) )
     4724                                           suffix1(2:3), 400, 401, 402 )
    50454725                ENDIF
    5046                 CALL handle_netcdf_error( 'netcdf', 401 )
    5047 
    5048                 nc_stat = NF90_PUT_ATT( id_set_pts, id_var_dopts(i,j), &
    5049                                         'units', TRIM( dopts_unit(i) ) )
    5050                 CALL handle_netcdf_error( 'netcdf', 402 )
    50514726
    50524727                var_list = TRIM( var_list ) // TRIM( dopts_label(i) ) // &
     
    50644739          nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'VAR_LIST', &
    50654740                                  var_list )
    5066           CALL handle_netcdf_error( 'netcdf', 403 )
     4741          CALL netcdf_handle_error( 'netcdf_define_header', 403 )
    50674742
    50684743
     
    50704745!--       Leave netCDF define mode
    50714746          nc_stat = NF90_ENDDEF( id_set_pts )
    5072           CALL handle_netcdf_error( 'netcdf', 404 )
     4747          CALL netcdf_handle_error( 'netcdf_define_header', 404 )
    50734748
    50744749
     
    50824757          nc_stat = NF90_GET_ATT( id_set_pts, NF90_GLOBAL, 'VAR_LIST', &
    50834758                                  var_list_old )
    5084           CALL handle_netcdf_error( 'netcdf', 405 )
     4759          CALL netcdf_handle_error( 'netcdf_define_header', 405 )
    50854760
    50864761          var_list = ';'
     
    51224797!--       on the file.
    51234798          nc_stat = NF90_INQ_VARID( id_set_pts, 'time', id_var_time_pts )
    5124           CALL handle_netcdf_error( 'netcdf', 406 )
     4799          CALL netcdf_handle_error( 'netcdf_define_header', 406 )
    51254800
    51264801          nc_stat = NF90_INQUIRE_VARIABLE( id_set_pts, id_var_time_pts, &
    51274802                                           dimids = id_dim_time_old )
    5128           CALL handle_netcdf_error( 'netcdf', 407 )
     4803          CALL netcdf_handle_error( 'netcdf_define_header', 407 )
    51294804          id_dim_time_pts = id_dim_time_old(1)
    51304805
    51314806          nc_stat = NF90_INQUIRE_DIMENSION( id_set_pts, id_dim_time_pts, &
    51324807                                            len = dopts_time_count )
    5133           CALL handle_netcdf_error( 'netcdf', 408 )
     4808          CALL netcdf_handle_error( 'netcdf_define_header', 408 )
    51344809
    51354810          nc_stat = NF90_GET_VAR( id_set_pts, id_var_time_pts,    &
     
    51374812                                  start = (/ dopts_time_count /), &
    51384813                                  count = (/ 1 /) )
    5139           CALL handle_netcdf_error( 'netcdf', 409 )
     4814          CALL netcdf_handle_error( 'netcdf_define_header', 409 )
    51404815
    51414816          IF ( last_time_coordinate(1) >= simulated_time )  THEN
     
    51714846                nc_stat = NF90_INQ_VARID( id_set_pts, netcdf_var_name, &
    51724847                                          id_var_dopts(i,j) )
    5173                 CALL handle_netcdf_error( 'netcdf', 410 )
     4848                CALL netcdf_handle_error( 'netcdf_define_header', 410 )
    51744849
    51754850                IF ( number_of_particle_groups == 1 )  EXIT
     
    51874862!--       to ensure equal attribute size in a job chain. Maybe revise later.
    51884863          nc_stat = NF90_REDEF( id_set_pts )
    5189           CALL handle_netcdf_error( 'netcdf', 443 )
     4864          CALL netcdf_handle_error( 'netcdf_define_header', 443 )
    51904865          nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'title', &
    51914866                                  TRIM( run_description_header ) )
    5192           CALL handle_netcdf_error( 'netcdf', 411 )
     4867          CALL netcdf_handle_error( 'netcdf_define_header', 411 )
    51934868          nc_stat = NF90_ENDDEF( id_set_pts )
    5194           CALL handle_netcdf_error( 'netcdf', 444 )
     4869          CALL netcdf_handle_error( 'netcdf_define_header', 444 )
    51954870          message_string = 'netCDF file for particle time series ' // &
    51964871                           'from previous run found.' //              &
    51974872                           '&This file will be extended.'
    5198           CALL message( 'define_netcdf_header', 'PA0269', 0, 0, 0, 6, 0 )
     4873          CALL message( 'netcdf_define_header', 'PA0269', 0, 0, 0, 6, 0 )
    51994874
    52004875
     
    52024877
    52034878          message_string = 'mode "' // TRIM( mode) // '" not supported'
    5204           CALL message( 'define_netcdf_header', 'PA0270', 0, 0, 0, 6, 0 )
     4879          CALL message( 'netcdf_define_header', 'PA0270', 0, 0, 0, 6, 0 )
    52054880
    52064881    END SELECT
    52074882
    52084883#endif
    5209  END SUBROUTINE define_netcdf_header
     4884 END SUBROUTINE netcdf_define_header
    52104885
    52114886
     
    52174892!------------------------------------------------------------------------------!
    52184893 
    5219  SUBROUTINE create_netcdf_file( filename , id, parallel, errno )
     4894 SUBROUTINE netcdf_create_file( filename , id, parallel, errno )
    52204895#if defined( __netcdf )
    52214896
    5222 
    5223     USE control_parameters
    5224     USE netcdf
    5225     USE netcdf_control
    52264897    USE pegrid
    52274898
     
    52844955    ENDIF
    52854956
    5286     CALL handle_netcdf_error( 'create_netcdf_file', errno )
     4957    CALL netcdf_handle_error( 'netcdf_create_file', errno )
    52874958#endif
    5288  END SUBROUTINE create_netcdf_file
     4959 END SUBROUTINE netcdf_create_file
    52894960
    52904961
     
    52964967!------------------------------------------------------------------------------!
    52974968 
    5298  SUBROUTINE open_write_netcdf_file( filename, id, parallel, errno )
     4969 SUBROUTINE netcdf_open_write_file( filename, id, parallel, errno )
    52994970#if defined( __netcdf )
    5300 
    5301 
    5302     USE control_parameters,                                                    &
    5303         ONLY:  netcdf_data_format
    5304 
    5305     USE netcdf
    5306 
    5307     USE netcdf_control
    53084971
    53094972    USE pegrid
     
    53284991    ENDIF
    53294992
    5330     CALL handle_netcdf_error( 'open_write_netcdf_file', errno )
     4993    CALL netcdf_handle_error( 'netcdf_open_write_file', errno )
    53314994#endif
    5332  END SUBROUTINE open_write_netcdf_file
     4995 END SUBROUTINE netcdf_open_write_file
    53334996
    53344997
     
    53395002!------------------------------------------------------------------------------!
    53405003 
    5341  SUBROUTINE handle_netcdf_error( routine_name, errno )
     5004 SUBROUTINE netcdf_handle_error( routine_name, errno )
    53425005#if defined( __netcdf )
    53435006
     
    53465009        ONLY:  message_string
    53475010
    5348     USE netcdf
    5349 
    5350     USE netcdf_control
    5351 
    5352     USE pegrid
    5353 
    53545011    IMPLICIT NONE
    53555012
     
    53695026
    53705027#endif
    5371  END SUBROUTINE handle_netcdf_error
     5028 END SUBROUTINE netcdf_handle_error
     5029
     5030
     5031!------------------------------------------------------------------------------!
     5032! Description:
     5033! ------------
     5034!> Create a dimension in NetCDF file
     5035!------------------------------------------------------------------------------!
     5036
     5037 SUBROUTINE netcdf_create_dim(ncid, dim_name, ncdim_type, ncdim_id, error_no)
     5038
     5039#if defined( __netcdf )
     5040
     5041    USE kinds
     5042
     5043    IMPLICIT NONE
     5044
     5045    CHARACTER(LEN=*), INTENT(IN) ::  dim_name
     5046
     5047    INTEGER, INTENT(IN)  ::  error_no
     5048    INTEGER, INTENT(IN)  ::  ncid
     5049    INTEGER, INTENT(OUT) ::  ncdim_id
     5050    INTEGER, INTENT(IN)  ::  ncdim_type
     5051
     5052!
     5053!-- Define time coordinate for volume data (unlimited dimension)
     5054    nc_stat = NF90_DEF_DIM( ncid, dim_name, ncdim_type, ncdim_id )
     5055    CALL netcdf_handle_error( 'netcdf_create_dim', error_no )
     5056
     5057#endif
     5058
     5059 END SUBROUTINE netcdf_create_dim
     5060
     5061
     5062!------------------------------------------------------------------------------!
     5063! Description:
     5064! ------------
     5065!> Create a one dimensional variable in specific units in NetCDF file
     5066!------------------------------------------------------------------------------!
     5067
     5068 SUBROUTINE netcdf_create_var( ncid, dim_id, var_name, var_type, var_id,       &
     5069                               unit_name, long_name, error_no1, error_no2,     &
     5070                               error_no3 )
     5071
     5072#if defined( __netcdf )
     5073    IMPLICIT NONE
     5074
     5075    CHARACTER(LEN=*), INTENT(IN) ::  long_name
     5076    CHARACTER(LEN=*), INTENT(IN) ::  unit_name
     5077    CHARACTER(LEN=*), INTENT(IN) ::  var_name
     5078
     5079    INTEGER, INTENT(IN)  ::  error_no1
     5080    INTEGER, INTENT(IN)  ::  error_no2
     5081    INTEGER, INTENT(IN)  ::  error_no3
     5082    INTEGER, INTENT(IN)  ::  ncid
     5083    INTEGER, INTENT(OUT) ::  var_id
     5084    INTEGER, INTENT(IN)  ::  var_type
     5085
     5086    INTEGER, DIMENSION(:), INTENT(IN) ::  dim_id
     5087
     5088!
     5089!-- Define variable
     5090    nc_stat = NF90_DEF_VAR( ncid, var_name, var_type, dim_id, var_id )
     5091    CALL netcdf_handle_error( 'netcdf_create_var', error_no1 )
     5092
     5093#if defined( __netcdf4 )
     5094!
     5095!-- Check if variable should be deflate (including shuffling)
     5096!-- and if it is possible (only NetCDF4 with HDF5 supports compression)
     5097    IF ( netcdf_data_format > 2  .AND.  netcdf_deflate > 0 )  THEN
     5098       nc_stat = NF90_DEF_VAR_DEFLATE( ncid, var_id, 1, 1, netcdf_deflate )
     5099       CALL netcdf_handle_error( 'netcdf_create_var_deflate', error_no1 )
     5100    ENDIF
     5101#endif
     5102!
     5103!-- Set unit name if set
     5104    IF ( unit_name /= '' )  THEN
     5105       nc_stat = NF90_PUT_ATT( ncid, var_id, 'units', unit_name )
     5106       CALL netcdf_handle_error( 'netcdf_create_var', error_no2 )
     5107    ENDIF
     5108
     5109!
     5110!-- Set long name if set
     5111    IF ( long_name /= '' )  THEN
     5112       nc_stat = NF90_PUT_ATT( ncid, var_id, 'long_name', long_name )
     5113       CALL netcdf_handle_error( 'netcdf_create_var', error_no3 )
     5114    ENDIF
     5115
     5116#endif
     5117 END SUBROUTINE netcdf_create_var
     5118
     5119 END MODULE netcdf_interface
  • palm/trunk/SOURCE/palm.f90

    r1782 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! required user interface version changed
    2222!
    2323! Former revisions:
     
    186186
    187187    version = 'PALM 4.0'
    188     user_interface_required_revision = 'r1663'
     188    user_interface_required_revision = 'r1783'
    189189
    190190#if defined( __parallel )
  • palm/trunk/SOURCE/parin.f90

    r1765 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! +netcdf_deflate in d3par, netcdf module and variable names changed
    2222!
    2323! Former revisions:
     
    206206
    207207    USE pegrid
     208
     209    USE netcdf_interface,                                                      &
     210        ONLY:  netcdf_data_format, netcdf_deflate, netcdf_precision
    208211
    209212    USE pmc_interface,                                                         &
     
    297300             dt_run_control,end_time, force_print_header, mask_scale_x,        &
    298301             mask_scale_y, mask_scale_z, mask_x, mask_y, mask_z, mask_x_loop,  &
    299              mask_y_loop, mask_z_loop, netcdf_data_format, normalizing_region, &
    300              npex, npey, nz_do3d, precipitation_amount_interval,               &
    301              profile_columns, profile_rows, restart_time, section_xy,          &
    302              section_xz, section_yz, skip_time_data_output,                    &
    303              skip_time_data_output_av, skip_time_dopr, skip_time_do2d_xy,      &
    304              skip_time_do2d_xz, skip_time_do2d_yz, skip_time_do3d,             &
    305              skip_time_domask, synchronous_exchange, termination_time_needed,  &
    306              z_max_do2d
     302             mask_y_loop, mask_z_loop, netcdf_data_format, netcdf_deflate,    &
     303             normalizing_region, npex, npey, nz_do3d,                          &
     304             precipitation_amount_interval, profile_columns, profile_rows,     &
     305             restart_time, section_xy, section_xz, section_yz,                 &
     306             skip_time_data_output, skip_time_data_output_av, skip_time_dopr,  &
     307             skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz,          &
     308             skip_time_do3d, skip_time_domask, synchronous_exchange,           &
     309             termination_time_needed, z_max_do2d
    307310
    308311
  • palm/trunk/SOURCE/pmc_client.f90

    r1780 r1783  
    2020! Current revisions:
    2121! ------------------
    22 !
     22! Bugfix: wrong data-type in MPI_WIN_CREATE replaced
    2323!
    2424! Former revisions:
     
    263263
    264264       ALLOCATE(myInd(2*WinSize))
    265        WinSize = WinSize*c_sizeof(i)
     265       WinSize = 1
    266266
    267267!      local Buffer used in MPI_Get can but must not be inside the MPI Window
    268268!      Here, we use a dummy for MPI Window because the server PEs do not access the RMA window via MPI_get or MPI_Put
    269269
    270        CALL MPI_Win_create (dummy, 1, iwp, MPI_INFO_NULL, me%intra_comm, indWin2, ierr);
     270       CALL MPI_Win_create (dummy, WinSize, iwp, MPI_INFO_NULL, me%intra_comm, indWin2, ierr);
    271271
    272272       CALL MPI_Win_fence (0, indWin2, ierr)    ! MPI_get is Non-blocking -> data in NrEle is not available until MPI_fence CALL
  • palm/trunk/SOURCE/pmc_interface.f90

    r1782 r1783  
    2020! Current revisions:
    2121! ------------------
    22 !
     22! calculation of nest top area simplified,
     23! interpolation and anterpolation moved to seperate wrapper subroutines
    2324!
    2425! Former revisions:
     
    678679    INTEGER(iwp), DIMENSION(5) ::  val        !:
    679680   
    680     REAL(wp)                   ::  area_t_l   !:
    681681    REAL(wp), DIMENSION(1)     ::  fval       !:
    682682    REAL(wp)                   ::  xcs        !:
     
    684684    REAL(wp)                   ::  ycs        !:
    685685    REAL(wp)                   ::  yce        !:
    686     REAL(wp)                   ::  zct        !:
    687     REAL(wp), DIMENSION(4)     ::  ztt        !:
    688686                                             
    689687
     
    830828!--    Finally, compute the total area of the top-boundary face of the domain.
    831829!--    This is needed in the pmc_ensure_nest_mass_conservation     
    832        area_t_l = ( nxr + 1 - nxl ) * ( nyn + 1 - nys ) * dx * dy
    833        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
    834        CALL MPI_ALLREDUCE( area_t_l, area_t, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
    835 
    836 !
    837 !--    TO_DO: Why not just simply? test this!
    838        !area_t_l = ( nx + 1 ) * (ny + 1 ) * dx * dy           
     830       area_t = ( nx + 1 ) * (ny + 1 ) * dx * dy
    839831
    840832    ENDIF
     
    10791071
    10801072      REAL(wp), ALLOCATABLE, DIMENSION(:) ::  lcr   !:
    1081       LOGICAL  ::  more             !:
    10821073
    10831074!
     
    23992390          CALL cpu_log( log_point_s(73), 'PMC Client Recv', 'stop' )
    24002391
    2401 !
    2402 !--       The interpolation. Add IF-condition here: IF not vertical nesting
    2403           IF ( nest_bound_l )  THEN   !  Left border pe
    2404              CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
    2405                                        nzb_u_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 'u' )
    2406              CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
    2407                                        nzb_v_inner, logc_v_l, logc_ratio_v_l, nzt_topo_nestbc_l, 'l', 'v' )
    2408              CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
    2409                                        nzb_w_inner, logc_w_l, logc_ratio_w_l, nzt_topo_nestbc_l, 'l', 'w' )
    2410              CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2411                                        nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 'e' )
    2412              CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2413                                        nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 's' )
    2414              IF ( humidity  .OR.  passive_scalar )  THEN
    2415                 CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
    2416                                           nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 's' )
    2417              ENDIF
    2418              IF ( nesting_mode == 'one-way' )  THEN
    2419                 CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'l', 'u' )
    2420                 CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'l', 'v' )
    2421                 CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'l', 'w' )
    2422                 CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'l', 'e' )
    2423                 CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'l', 's' )
    2424                 IF ( humidity  .OR.  passive_scalar )  THEN
    2425                    CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'l', 's' )
    2426                 ENDIF
    2427              ENDIF
    2428           ENDIF
    2429           IF ( nest_bound_r )  THEN   !  Right border pe
    2430              CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
    2431                                        nzb_u_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 'u' )
    2432              CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
    2433                                        nzb_v_inner, logc_v_r, logc_ratio_v_r, nzt_topo_nestbc_r, 'r', 'v' )
    2434              CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
    2435                                        nzb_w_inner, logc_w_r, logc_ratio_w_r, nzt_topo_nestbc_r, 'r', 'w' )
    2436              CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2437                                        nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 'e' )
    2438              CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2439                                        nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 's' )
    2440              IF ( humidity  .OR.  passive_scalar )  THEN
    2441                 CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
    2442                                           nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 's' )
    2443              ENDIF
    2444              IF ( nesting_mode == 'one-way' )  THEN
    2445                 CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'r', 'u' )
    2446                 CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'r', 'v' )
    2447                 CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'r', 'w' )
    2448                 CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'r', 'e' )
    2449                 CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'r', 's' )
    2450                 IF ( humidity  .OR.  passive_scalar )  THEN
    2451                    CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'r', 's' )
    2452                 ENDIF
    2453              ENDIF
    2454           ENDIF
    2455           IF ( nest_bound_s )  THEN   !  South border pe
    2456              CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
    2457                                        nzb_u_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 'u' )
    2458              CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
    2459                                        nzb_v_inner, logc_v_s, logc_ratio_v_s, nzt_topo_nestbc_s, 's', 'v' )
    2460              CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
    2461                                        nzb_w_inner, logc_w_s, logc_ratio_w_s, nzt_topo_nestbc_s, 's', 'w' )
    2462              CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2463                                        nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 'e' )
    2464              CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2465                                        nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 's' )
    2466              IF ( humidity  .OR.  passive_scalar )  THEN
    2467                 CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
    2468                                           nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 's' )
    2469              ENDIF
    2470              IF ( nesting_mode == 'one-way' )  THEN
    2471                 CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 's', 'u' )
    2472                 CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 's', 'v' )
    2473                 CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 's', 'w' )
    2474                 CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 's', 'e' )
    2475                 CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 's', 's' )
    2476                 IF ( humidity  .OR.  passive_scalar )  THEN
    2477                    CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 's', 's' )
    2478                 ENDIF
    2479              ENDIF
    2480           ENDIF
    2481           IF ( nest_bound_n )  THEN   !  North border pe
    2482              CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
    2483                                        nzb_u_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 'u' )
    2484              CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
    2485                                        nzb_v_inner, logc_v_n, logc_ratio_v_n, nzt_topo_nestbc_n, 'n', 'v' )
    2486              CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
    2487                                        nzb_w_inner, logc_w_n, logc_ratio_w_n, nzt_topo_nestbc_n, 'n', 'w' )
    2488              CALL pmci_interp_tril_sn( e,  ec,  ico,jco,kco,r1xo,r2xo,r1yo,r2yo,r1zo,r2zo,                  &
    2489                                        nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 'e' )
    2490              CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
    2491                                        nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 's' )
    2492              IF ( humidity  .OR.  passive_scalar )  THEN
    2493                 CALL pmci_interp_tril_sn( q, qc, ico,jco,kco,r1xo,r2xo,r1yo,r2yo,r1zo,r2zo,                 &
    2494                                           nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 's' )
    2495              ENDIF
    2496              IF ( nesting_mode == 'one-way' )  THEN             
    2497                 CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 'n', 'u' )
    2498                 CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 'n', 'v' )
    2499                 CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 'n', 'w' )
    2500                 CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 'n', 'e' )
    2501                 CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 'n', 's' )
    2502                 IF ( humidity  .OR.  passive_scalar )  THEN
    2503                    CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 'n', 's' )
    2504                 ENDIF
    2505              ENDIF
    2506           ENDIF
    2507 
    2508 !
    2509 !--       All PEs are top-border PEs
    2510           CALL pmci_interp_tril_t( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo, 'u' )
    2511           CALL pmci_interp_tril_t( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo, 'v' )
    2512           CALL pmci_interp_tril_t( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw, 'w' )
    2513           CALL pmci_interp_tril_t( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 'e' )
    2514           CALL pmci_interp_tril_t( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 's' )
    2515           IF ( humidity  .OR.  passive_scalar )  THEN
    2516              CALL pmci_interp_tril_t( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 's' )
    2517           ENDIF
    2518           IF ( nesting_mode == 'one-way' )  THEN
    2519              CALL pmci_extrap_ifoutflow_t( u,  'u' )
    2520              CALL pmci_extrap_ifoutflow_t( v,  'v' )
    2521              CALL pmci_extrap_ifoutflow_t( w,  'w' )
    2522              CALL pmci_extrap_ifoutflow_t( e,  'e' )
    2523              CALL pmci_extrap_ifoutflow_t( pt, 's' )
    2524              IF ( humidity  .OR.  passive_scalar )  THEN
    2525                 CALL pmci_extrap_ifoutflow_t( q, 's' )
    2526              ENDIF
    2527           ENDIF
    2528        ELSE    !  IF ( direction == server_to_client )
    2529           CALL pmci_anterp_tophat( u,  uc,  kceu, iflu, ifuu, jflo, jfuo, kflo, kfuo, nzb_u_inner, 'u' )
    2530           CALL pmci_anterp_tophat( v,  vc,  kceu, iflo, ifuo, jflv, jfuv, kflo, kfuo, nzb_v_inner, 'v' )
    2531           CALL pmci_anterp_tophat( w,  wc,  kcew, iflo, ifuo, jflo, jfuo, kflw, kfuw, nzb_w_inner, 'w' )
    2532           CALL pmci_anterp_tophat( pt, ptc, kceu, iflo, ifuo, jflo, jfuo, kflo, kfuo, nzb_s_inner, 's' )
    2533           IF ( humidity  .OR.  passive_scalar )  THEN
    2534              CALL pmci_anterp_tophat( q, qc, kceu, iflo, ifuo, jflo, jfuo, kflo, kfuo, nzb_s_inner, 's' )
    2535           ENDIF
     2392          CALL pmci_interpolation
     2393
     2394       ELSE    !  IF ( direction == server_to_client )
     2395
     2396          CALL pmci_anterpolation
     2397
    25362398          CALL cpu_log( log_point_s(74), 'PMC Client Send', 'start' )
    25372399          CALL pmc_c_putbuffer( WaitTime = WaitTime )
     
    25392401       ENDIF
    25402402    ENDIF
    2541    
     2403
    25422404 CONTAINS
     2405
     2406
     2407   SUBROUTINE pmci_interpolation
     2408
     2409!
     2410!--   A wrapper routine for all interpolation and extrapolation actions.
     2411      IMPLICIT NONE
     2412
     2413!
     2414!--   Add IF-condition here: IF not vertical nesting
     2415      IF ( nest_bound_l )  THEN   !  Left border pe
     2416         CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
     2417                                   nzb_u_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 'u' )
     2418         CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
     2419                                   nzb_v_inner, logc_v_l, logc_ratio_v_l, nzt_topo_nestbc_l, 'l', 'v' )
     2420         CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
     2421                                   nzb_w_inner, logc_w_l, logc_ratio_w_l, nzt_topo_nestbc_l, 'l', 'w' )
     2422         CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2423                                   nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 'e' )
     2424         CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2425                                   nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 's' )
     2426         IF ( humidity  .OR.  passive_scalar )  THEN
     2427            CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
     2428                                      nzb_s_inner, logc_u_l, logc_ratio_u_l, nzt_topo_nestbc_l, 'l', 's' )
     2429         ENDIF
     2430         IF ( nesting_mode == 'one-way' )  THEN
     2431            CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'l', 'u' )
     2432            CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'l', 'v' )
     2433            CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'l', 'w' )
     2434            CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'l', 'e' )
     2435            CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'l', 's' )
     2436            IF ( humidity  .OR.  passive_scalar )  THEN
     2437               CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'l', 's' )
     2438            ENDIF
     2439         ENDIF
     2440      ENDIF
     2441      IF ( nest_bound_r )  THEN   !  Right border pe
     2442         CALL pmci_interp_tril_lr( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
     2443                                   nzb_u_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 'u' )
     2444         CALL pmci_interp_tril_lr( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
     2445                                   nzb_v_inner, logc_v_r, logc_ratio_v_r, nzt_topo_nestbc_r, 'r', 'v' )
     2446         CALL pmci_interp_tril_lr( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
     2447                                   nzb_w_inner, logc_w_r, logc_ratio_w_r, nzt_topo_nestbc_r, 'r', 'w' )
     2448         CALL pmci_interp_tril_lr( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2449                                   nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 'e' )
     2450         CALL pmci_interp_tril_lr( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2451                                   nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 's' )
     2452         IF ( humidity  .OR.  passive_scalar )  THEN
     2453            CALL pmci_interp_tril_lr( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
     2454                                      nzb_s_inner, logc_u_r, logc_ratio_u_r, nzt_topo_nestbc_r, 'r', 's' )
     2455         ENDIF
     2456         IF ( nesting_mode == 'one-way' )  THEN
     2457            CALL pmci_extrap_ifoutflow_lr( u, nzb_u_inner, 'r', 'u' )
     2458             CALL pmci_extrap_ifoutflow_lr( v, nzb_v_inner, 'r', 'v' )
     2459             CALL pmci_extrap_ifoutflow_lr( w, nzb_w_inner, 'r', 'w' )
     2460             CALL pmci_extrap_ifoutflow_lr( e, nzb_s_inner, 'r', 'e' )
     2461             CALL pmci_extrap_ifoutflow_lr( pt,nzb_s_inner, 'r', 's' )
     2462             IF ( humidity  .OR.  passive_scalar )  THEN
     2463                CALL pmci_extrap_ifoutflow_lr( q, nzb_s_inner, 'r', 's' )
     2464             ENDIF
     2465          ENDIF
     2466       ENDIF
     2467       IF ( nest_bound_s )  THEN   !  South border pe
     2468          CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
     2469                                    nzb_u_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 'u' )
     2470          CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
     2471                                    nzb_v_inner, logc_v_s, logc_ratio_v_s, nzt_topo_nestbc_s, 's', 'v' )
     2472          CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
     2473                                    nzb_w_inner, logc_w_s, logc_ratio_w_s, nzt_topo_nestbc_s, 's', 'w' )
     2474          CALL pmci_interp_tril_sn( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2475                                    nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 'e' )
     2476          CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2477                                    nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 's' )
     2478          IF ( humidity  .OR.  passive_scalar )  THEN
     2479             CALL pmci_interp_tril_sn( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,         &
     2480                                       nzb_s_inner, logc_u_s, logc_ratio_u_s, nzt_topo_nestbc_s, 's', 's' )
     2481          ENDIF
     2482          IF ( nesting_mode == 'one-way' )  THEN
     2483             CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 's', 'u' )
     2484             CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 's', 'v' )
     2485             CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 's', 'w' )
     2486             CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 's', 'e' )
     2487             CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 's', 's' )
     2488             IF ( humidity  .OR.  passive_scalar )  THEN
     2489                CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 's', 's' )
     2490             ENDIF
     2491          ENDIF
     2492       ENDIF
     2493       IF ( nest_bound_n )  THEN   !  North border pe
     2494          CALL pmci_interp_tril_sn( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo,          &
     2495                                    nzb_u_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 'u' )
     2496          CALL pmci_interp_tril_sn( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo,          &
     2497                                    nzb_v_inner, logc_v_n, logc_ratio_v_n, nzt_topo_nestbc_n, 'n', 'v' )
     2498          CALL pmci_interp_tril_sn( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw,          &
     2499                                    nzb_w_inner, logc_w_n, logc_ratio_w_n, nzt_topo_nestbc_n, 'n', 'w' )
     2500          CALL pmci_interp_tril_sn( e,  ec,  ico,jco,kco,r1xo,r2xo,r1yo,r2yo,r1zo,r2zo,                  &
     2501                                    nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 'e' )
     2502          CALL pmci_interp_tril_sn( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo,          &
     2503                                    nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 's' )
     2504          IF ( humidity  .OR.  passive_scalar )  THEN
     2505             CALL pmci_interp_tril_sn( q, qc, ico,jco,kco,r1xo,r2xo,r1yo,r2yo,r1zo,r2zo,                 &
     2506                                       nzb_s_inner, logc_u_n, logc_ratio_u_n, nzt_topo_nestbc_n, 'n', 's' )
     2507          ENDIF
     2508          IF ( nesting_mode == 'one-way' )  THEN
     2509             CALL pmci_extrap_ifoutflow_sn( u, nzb_u_inner, 'n', 'u' )
     2510             CALL pmci_extrap_ifoutflow_sn( v, nzb_v_inner, 'n', 'v' )
     2511             CALL pmci_extrap_ifoutflow_sn( w, nzb_w_inner, 'n', 'w' )
     2512             CALL pmci_extrap_ifoutflow_sn( e, nzb_s_inner, 'n', 'e' )
     2513             CALL pmci_extrap_ifoutflow_sn( pt,nzb_s_inner, 'n', 's' )
     2514             IF ( humidity  .OR.  passive_scalar )  THEN
     2515                CALL pmci_extrap_ifoutflow_sn( q, nzb_s_inner, 'n', 's' )
     2516             ENDIF
     2517          ENDIF
     2518      ENDIF
     2519
     2520!
     2521!--   All PEs are top-border PEs
     2522       CALL pmci_interp_tril_t( u,  uc,  icu, jco, kco, r1xu, r2xu, r1yo, r2yo, r1zo, r2zo, 'u' )
     2523       CALL pmci_interp_tril_t( v,  vc,  ico, jcv, kco, r1xo, r2xo, r1yv, r2yv, r1zo, r2zo, 'v' )
     2524       CALL pmci_interp_tril_t( w,  wc,  ico, jco, kcw, r1xo, r2xo, r1yo, r2yo, r1zw, r2zw, 'w' )
     2525       CALL pmci_interp_tril_t( e,  ec,  ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 'e' )
     2526       CALL pmci_interp_tril_t( pt, ptc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 's' )
     2527       IF ( humidity  .OR.  passive_scalar )  THEN
     2528          CALL pmci_interp_tril_t( q, qc, ico, jco, kco, r1xo, r2xo, r1yo, r2yo, r1zo, r2zo, 's' )
     2529       ENDIF
     2530       IF ( nesting_mode == 'one-way' )  THEN
     2531          CALL pmci_extrap_ifoutflow_t( u,  'u' )
     2532          CALL pmci_extrap_ifoutflow_t( v,  'v' )
     2533          CALL pmci_extrap_ifoutflow_t( w,  'w' )
     2534          CALL pmci_extrap_ifoutflow_t( e,  'e' )
     2535          CALL pmci_extrap_ifoutflow_t( pt, 's' )
     2536          IF ( humidity  .OR.  passive_scalar )  THEN
     2537             CALL pmci_extrap_ifoutflow_t( q, 's' )
     2538          ENDIF
     2539      ENDIF
     2540   END SUBROUTINE pmci_interpolation
     2541
     2542
     2543
     2544   SUBROUTINE pmci_anterpolation
     2545
     2546!
     2547!--   A wrapper routine for all anterpolation actions.
     2548      IMPLICIT NONE
     2549
     2550      CALL pmci_anterp_tophat( u,  uc,  kceu, iflu, ifuu, jflo, jfuo, kflo, kfuo, nzb_u_inner, 'u' )
     2551      CALL pmci_anterp_tophat( v,  vc,  kceu, iflo, ifuo, jflv, jfuv, kflo, kfuo, nzb_v_inner, 'v' )
     2552      CALL pmci_anterp_tophat( w,  wc,  kcew, iflo, ifuo, jflo, jfuo, kflw, kfuw, nzb_w_inner, 'w' )
     2553      CALL pmci_anterp_tophat( pt, ptc, kceu, iflo, ifuo, jflo, jfuo, kflo, kfuo, nzb_s_inner, 's' )
     2554      IF ( humidity  .OR.  passive_scalar )  THEN
     2555         CALL pmci_anterp_tophat( q, qc, kceu, iflo, ifuo, jflo, jfuo, kflo, kfuo, nzb_s_inner, 's' )
     2556      ENDIF
     2557
     2558   END SUBROUTINE pmci_anterpolation
    25432559
    25442560
  • palm/trunk/SOURCE/radiation_model.f90

    r1758 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! palm-netcdf-module removed in order to avoid a circular module dependency,
     22! netcdf-variables moved to netcdf-module, new routine netcdf_handle_error_mod
     23! added
    2224!
    2325! Former revisions:
     
    8385 MODULE radiation_model_mod
    8486 
    85 
    8687    USE arrays_3d,                                                             &
    8788        ONLY:  dzw, hyp, pt, q, ql, zw
     
    104105
    105106#if defined ( __netcdf )
    106     USE netcdf
     107    USE NETCDF
    107108#endif
    108 
    109     USE netcdf_control,                                                        &
    110         ONLY:  dots_label, dots_num, dots_unit
    111109
    112110#if defined ( __rrtmg )
     
    642640       CALL user_init_radiation
    643641
    644 
    645 !
    646 !--    Add timeseries for radiation model
    647        dots_rad = dots_num + 1
    648        dots_num = dots_num + 5
    649 
    650        dots_label(dots_rad) = "rad_net"
    651        dots_label(dots_rad+1) = "rad_lw_in"
    652        dots_label(dots_rad+2) = "rad_lw_out"
    653        dots_label(dots_rad+3) = "rad_sw_in"
    654        dots_label(dots_rad+4) = "rad_sw_out"
    655        dots_unit(dots_rad:dots_rad+4) = "W/m2"
    656 
    657 !
    658 !--    Output of albedos is only required for RRTMG
    659        IF ( radiation_scheme == 'rrtmg' )  THEN
    660           dots_num  = dots_num + 4
    661           dots_label(dots_rad+5) = "rrtm_aldif"
    662           dots_label(dots_rad+6) = "rrtm_aldir"
    663           dots_label(dots_rad+7) = "rrtm_asdif"
    664           dots_label(dots_rad+8) = "rrtm_asdir"
    665           dots_unit(dots_num+5:dots_num+8) = ""
    666 
    667        ENDIF
    668 
    669642!
    670643!--    Calculate radiative fluxes at model start
     
    10981071!------------------------------------------------------------------------------!
    10991072    SUBROUTINE read_sounding_data
    1100 
    1101        USE netcdf_control
    11021073
    11031074       IMPLICIT NONE
     
    11681139!--    Open file for reading
    11691140       nc_stat = NF90_OPEN( rrtm_input_file, NF90_NOWRITE, id )
    1170        CALL handle_netcdf_error( 'netcdf', 549 )
     1141       CALL netcdf_handle_error_rad( 'read_sounding_data', 549 )
    11711142
    11721143!
     
    11741145       nc_stat = NF90_INQ_DIMID( id, "Pressure", id_dim_zrad )
    11751146       nc_stat = NF90_INQUIRE_DIMENSION( id, id_dim_zrad, len = nz_snd )
    1176        CALL handle_netcdf_error( 'netcdf', 551 )
     1147       CALL netcdf_handle_error_rad( 'read_sounding_data', 551 )
    11771148
    11781149!
     
    11861157       nc_stat = NF90_GET_VAR( id, id_var, hyp_snd_tmp(:), start = (/1/),      &
    11871158                               count = (/nz_snd/) )
    1188        CALL handle_netcdf_error( 'netcdf', 552 )
     1159       CALL netcdf_handle_error_rad( 'read_sounding_data', 552 )
    11891160
    11901161!
     
    11981169       nc_stat = NF90_GET_VAR( id, id_var, t_snd_tmp(:), start = (/1/),        &
    11991170                               count = (/nz_snd/) )
    1200        CALL handle_netcdf_error( 'netcdf', 553 )
     1171       CALL netcdf_handle_error_rad( 'read_sounding_data', 553 )
    12011172
    12021173!
     
    13711342    SUBROUTINE read_trace_gas_data
    13721343
    1373        USE netcdf_control
    13741344       USE rrsw_ncpar
    13751345
     
    14351405!--    Open file for reading
    14361406       nc_stat = NF90_OPEN( rrtm_input_file, NF90_NOWRITE, id )
    1437        CALL handle_netcdf_error( 'netcdf', 549 )
     1407       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 549 )
    14381408!
    14391409!--    Inquire dimension ids and dimensions
    14401410       nc_stat = NF90_INQ_DIMID( id, "Pressure", id_dim )
    1441        CALL handle_netcdf_error( 'netcdf', 550 )
     1411       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14421412       nc_stat = NF90_INQUIRE_DIMENSION( id, id_dim, len = np)
    1443        CALL handle_netcdf_error( 'netcdf', 550 )
     1413       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14441414
    14451415       nc_stat = NF90_INQ_DIMID( id, "Absorber", id_dim )
    1446        CALL handle_netcdf_error( 'netcdf', 550 )
     1416       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14471417       nc_stat = NF90_INQUIRE_DIMENSION( id, id_dim, len = nabs )
    1448        CALL handle_netcdf_error( 'netcdf', 550 )
     1418       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14491419   
    14501420
     
    14571427
    14581428       nc_stat = NF90_INQ_VARID( id, "Pressure", id_var )
    1459        CALL handle_netcdf_error( 'netcdf', 550 )
     1429       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14601430       nc_stat = NF90_GET_VAR( id, id_var, p_mls )
    1461        CALL handle_netcdf_error( 'netcdf', 550 )
     1431       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14621432
    14631433       nc_stat = NF90_INQ_VARID( id, "AbsorberAmountMLS", id_var )
    1464        CALL handle_netcdf_error( 'netcdf', 550 )
     1434       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14651435       nc_stat = NF90_GET_VAR( id, id_var, trace_mls_tmp )
    1466        CALL handle_netcdf_error( 'netcdf', 550 )
     1436       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 550 )
    14671437
    14681438
     
    14841454
    14851455       nc_stat = NF90_CLOSE( id )
    1486        CALL handle_netcdf_error( 'netcdf', 551 )
     1456       CALL netcdf_handle_error_rad( 'read_trace_gas_data', 551 )
    14871457
    14881458!
     
    16231593    END SUBROUTINE read_trace_gas_data
    16241594
     1595    SUBROUTINE netcdf_handle_error_rad( routine_name, errno )
     1596
     1597       USE control_parameters,                                                 &
     1598           ONLY:  message_string
     1599
     1600       USE NETCDF
     1601
     1602       USE pegrid
     1603
     1604       IMPLICIT NONE
     1605
     1606       CHARACTER(LEN=6) ::  message_identifier
     1607       CHARACTER(LEN=*) ::  routine_name
     1608
     1609       INTEGER(iwp) ::  errno
     1610
     1611       IF ( nc_stat /= NF90_NOERR )  THEN
     1612
     1613          WRITE( message_identifier, '(''NC'',I4.4)' )  errno
     1614          message_string = TRIM( NF90_STRERROR( nc_stat ) )
     1615
     1616          CALL message( routine_name, message_identifier, 2, 2, 0, 6, 1 )
     1617
     1618       ENDIF
     1619
     1620    END SUBROUTINE netcdf_handle_error_rad
    16251621#endif
    16261622
  • palm/trunk/SOURCE/read_var_list.f90

    r1700 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    173173        ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
    174174
    175     USE netcdf_control
     175    USE netcdf_interface,                                                      &
     176        ONLY:  netcdf_precision, output_for_t0
    176177
    177178    USE particle_attributes,                                                   &
  • palm/trunk/SOURCE/time_integration.f90

    r1782 r1783  
    1919! Current revisions:
    2020! ------------------
    21 !
     21! switch back of netcdf data format for mask output moved to the mask output
     22! routine
    2223!
    2324! Former revisions:
     
    200201               intermediate_timestep_count_max, large_scale_forcing,           &
    201202               loop_optimization, lsf_surf, lsf_vert, masks, mid, nest_domain, &
    202                netcdf_data_format, neutral, nr_timesteps_this_run, nudging,    &
     203               neutral, nr_timesteps_this_run, nudging,                        &
    203204               ocean, on_device, passive_scalar, precipitation,                &
    204205               prho_reference, pt_reference, pt_slope_offset, random_heatflux, &
     
    280281    CHARACTER (LEN=9) ::  time_to_string          !<
    281282
    282     INTEGER(iwp)      ::  netcdf_data_format_save !<
    283 
    284283!
    285284!-- At the beginning of a simulation determine the time step as well as
     
    10481047
    10491048!
    1050 !--    masked data output
    1051 !--    Parallel netcdf output is not tested so far for masked data, hence
    1052 !--    netcdf_data_format is switched back to non-paralell output.
    1053        netcdf_data_format_save = netcdf_data_format
    1054        IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
    1055        IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
     1049!--    Masked data output
    10561050       DO  mid = 1, masks
    10571051          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
     
    10611055          ENDIF
    10621056       ENDDO
    1063        netcdf_data_format = netcdf_data_format_save
    10641057
    10651058!
     
    10711064          CALL data_output_2d( 'yz', 1 )
    10721065          CALL data_output_3d( 1 )
    1073 !--       Parallel netcdf output is not tested so far for masked data, hence
    1074 !--       netcdf_data_format is switched back to non-paralell output.
    1075           netcdf_data_format_save = netcdf_data_format
    1076           IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
    1077           IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
    10781066          DO  mid = 1, masks
    10791067             CALL data_output_mask( 1 )
    10801068          ENDDO
    1081           netcdf_data_format = netcdf_data_format_save
    10821069          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
    10831070       ENDIF
  • palm/trunk/SOURCE/user_check_data_output_pr.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + relatec changes
    2222!
    2323! Former revisions:
     
    5757    USE kinds
    5858
    59     USE netcdf_control
     59    USE netcdf_interface,                                                      &
     60        ONLY:  dopr_unit
    6061
    6162    USE profil_parameter
  • palm/trunk/SOURCE/user_init.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    5555    USE kinds
    5656   
    57     USE netcdf_control
     57    USE netcdf_interface,                                                      &
     58        ONLY: dots_label, dots_unit
    5859   
    5960    USE pegrid
  • palm/trunk/SOURCE/user_parin.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! required interface revision changed
    2222!
    2323! Former revisions:
     
    8989!-- current revision does not match with previous revisions (e.g. if routines
    9090!-- have been added/deleted or if parameter lists in subroutines have been changed).
    91     user_interface_current_revision = 'r1663'
     91    user_interface_current_revision = 'r1783'
    9292
    9393!
  • palm/trunk/SOURCE/user_statistics.f90

    r1683 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    6666    USE kinds
    6767   
    68     USE netcdf_control
    69    
     68    USE netcdf_interface,                                                      &
     69        ONLY:  dots_max
     70
    7071    USE pegrid
    7172   
  • palm/trunk/SOURCE/write_var_list.f90

    r1706 r1783  
    1919! Current revisions:
    2020! -----------------
    21 !
     21! netcdf module name changed + related changes
    2222!
    2323! Former revisions:
     
    155155        ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
    156156   
    157     USE netcdf_control
     157    USE netcdf_interface,                                                      &
     158        ONLY:  netcdf_precision, output_for_t0
    158159   
    159160    USE particle_attributes,                                                   &
Note: See TracChangeset for help on using the changeset viewer.