Index: palm/trunk/DOC/tec/message_identifiers
===================================================================
--- palm/trunk/DOC/tec/message_identifiers	(revision 262)
+++ palm/trunk/DOC/tec/message_identifiers	(revision 263)
@@ -3,4 +3,5 @@
     PA****  Identifier for messages in the PALM standard code
     UI****  Identifier for messages in "user_" routines
+    NC****  Identifier for messages from the NetCDF library
 
 message_identifier   message string
Index: palm/trunk/SOURCE/CURRENT_MODIFICATIONS
===================================================================
--- palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 262)
+++ palm/trunk/SOURCE/CURRENT_MODIFICATIONS	(revision 263)
@@ -22,4 +22,8 @@
 Changed:
 -------
+Output of NetCDF messages with aid of message handling routine.
+(check_open, close_file, data_output_2d, data_output_3d, 
+data_output_profiles, data_output_ptseries, data_output_spectra, 
+data_output_tseries, netcdf, output_particles_netcdf)
 
 Output of messages replaced by message handling routine.
@@ -39,5 +43,5 @@
 user_init_grid, user_parin, write_var_list)
 
-advec_particles, advec_s_bc, buoyancy, calc_spectra, check_for_restart, check_open, check_parameters, coriolis, cpu_log, data_output_2d, data_output_3d, data_output_dvrp, data_output_profiles, data_output_spectra,  eqn_state_seawater, fft_xy, flow_statistics, header, init_1d_model, init_3d_model, init_dvrp, init_grid, init_particles, init_pegrid, netcdf, parin, plant_canopy_model, poisfft_hybrid, poismg, read_3d_binary, read_var_list, sort_particles, user_check_parameters, user_header, user_init_grid, user_parin, surface_coupler, temperton_fft, timestep, user_actions, user_data_output_dvrp, user_dvrp_coltab, user_init_grid, user_init_plant_canopy, user_parin, user_read_restart_data, user_spectra, write_var_list
+advec_particles, advec_s_bc, buoyancy, calc_spectra, check_for_restart, check_open, check_parameters, close_file, coriolis, cpu_log, data_output_2d, data_output_3d, data_output_dvrp, data_output_profiles, data_output_ptseries, data_output_spectra, data_output_tseries, eqn_state_seawater, fft_xy, flow_statistics, header, init_1d_model, init_3d_model, init_dvrp, init_grid, init_particles, init_pegrid, netcdf, output_particles_netcdf, parin, plant_canopy_model, poisfft_hybrid, poismg, read_3d_binary, read_var_list, sort_particles, user_check_parameters, user_header, user_init_grid, user_parin, surface_coupler, temperton_fft, timestep, user_actions, user_data_output_dvrp, user_dvrp_coltab, user_init_grid, user_init_plant_canopy, user_parin, user_read_restart_data, user_spectra, write_var_list
 
 
Index: palm/trunk/SOURCE/advec_particles.f90
===================================================================
--- palm/trunk/SOURCE/advec_particles.f90	(revision 262)
+++ palm/trunk/SOURCE/advec_particles.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine
 ! Bugfix: error in check, if particles moved further than one subdomain length.
@@ -3594,5 +3595,5 @@
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_time_prt, (/ simulated_time /), &
                             start = (/ prt_time_count /), count = (/ 1 /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 1 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 1 )
 
 !
@@ -3601,5 +3602,5 @@
                             (/ number_of_particles /),   &
                             start = (/ prt_time_count /), count = (/ 1 /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 2 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 2 )
 
 !
@@ -3608,85 +3609,85 @@
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 3 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 3 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(2), particles%dvrp_psize,  &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 4 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 4 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(3), particles%origin_x,    &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 5 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 5 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(4), particles%origin_y,    &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 6 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 6 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(5), particles%origin_z,    &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 7 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 7 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(6), particles%radius,      &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 8 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 8 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(7), particles%speed_x,     &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 9 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 9 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(8), particles%speed_y,     &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 10 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 10 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(9), particles%speed_z,     &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 11 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 11 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt,id_var_prt(10),particles%weight_factor,&
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 12 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 12 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(11), particles%x,           &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 13 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 13 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(12), particles%y,          & 
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 14 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 14 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(13), particles%z,          &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 15 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 15 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(14), particles%color,      &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 16 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 16 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(15), particles%group,      &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 17 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 17 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(16), particles%tailpoints, &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 18 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 18 )
 
     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(17), particles%tail_id,    &
                             start = (/ 1, prt_time_count /),                  &
                             count = (/ maximum_number_of_particles /) )
-    IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 19 )
+    CALL handle_netcdf_error( 'output_particles_netcdf', 19 )
 
 #endif
Index: palm/trunk/SOURCE/check_open.f90
===================================================================
--- palm/trunk/SOURCE/check_open.f90	(revision 262)
+++ palm/trunk/SOURCE/check_open.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine
 !
@@ -697,5 +698,6 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xy(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 20 )
+
+             CALL handle_netcdf_error( 'check_open', 20 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -708,5 +710,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_xy(av) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 21 )
+                CALL handle_netcdf_error( 'check_open', 21 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -731,5 +733,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xy(av) )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 22 )
+             CALL handle_netcdf_error( 'check_open', 22 )
 !
 !--          Define the header
@@ -758,5 +760,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_xz(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 23 )
+             CALL handle_netcdf_error( 'check_open', 23 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -769,5 +771,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_xz(av) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 24 )
+                CALL handle_netcdf_error( 'check_open', 24 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -792,5 +794,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_xz(av) )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 25 )
+             CALL handle_netcdf_error( 'check_open', 25 )
 !
 !--          Define the header
@@ -819,5 +821,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_yz(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 26 )
+             CALL handle_netcdf_error( 'check_open', 26 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -830,5 +832,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_yz(av) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 27 )
+                CALL handle_netcdf_error( 'check_open', 27 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -853,5 +855,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_yz(av) )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 28 )
+             CALL handle_netcdf_error( 'check_open', 28 )
 !
 !--          Define the header
@@ -874,5 +876,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_pr )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 29 )
+             CALL handle_netcdf_error( 'check_open', 29 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -885,5 +887,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_pr )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 30 )
+                CALL handle_netcdf_error( 'check_open', 30 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -908,5 +910,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pr )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 31 )
+             CALL handle_netcdf_error( 'check_open', 31 )
 !
 !--          Define the header
@@ -929,5 +931,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_ts )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 32 )
+             CALL handle_netcdf_error( 'check_open', 32 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -940,5 +942,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_ts )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 33 )
+                CALL handle_netcdf_error( 'check_open', 33 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -963,5 +965,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_ts )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 34 )
+             CALL handle_netcdf_error( 'check_open', 34 )
 !
 !--          Define the header
@@ -991,5 +993,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_3d(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 35 )
+             CALL handle_netcdf_error( 'check_open', 35 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -1002,5 +1004,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_3d(av) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 36 )
+                CALL handle_netcdf_error( 'check_open', 36 )
                 CALL local_system('rm ' // TRIM( filename ) )
              ENDIF
@@ -1025,5 +1027,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_3d(av) )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 37 )
+             CALL handle_netcdf_error( 'check_open', 37 )
 !
 !--          Define the header
@@ -1047,5 +1049,6 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_sp )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 38 )
+             CALL handle_netcdf_error( 'check_open', 38 )
+
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -1058,5 +1061,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_sp )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 39 )
+                CALL handle_netcdf_error( 'check_open', 39 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -1081,5 +1084,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_sp )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 40 )
+             CALL handle_netcdf_error( 'check_open', 40 )
 !
 !--          Define the header
@@ -1106,5 +1109,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_prt )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 41 )
+             CALL handle_netcdf_error( 'check_open', 41 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -1117,5 +1120,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_prt )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 42 )
+                CALL handle_netcdf_error( 'check_open', 42 )
                 CALL local_system( 'rm ' // filename )
              ENDIF
@@ -1157,5 +1160,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_prt )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 43 )
+             CALL handle_netcdf_error( 'check_open', 43 )  
 
 !
@@ -1179,5 +1182,5 @@
 !--          Open an existing NetCDF file for output 
              nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set_pts )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 393 )
+             CALL handle_netcdf_error( 'check_open', 393 )
 !
 !--          Read header information and set all ids. If there is a mismatch
@@ -1190,5 +1193,5 @@
              IF ( .NOT. netcdf_extend )  THEN
                 nc_stat = NF90_CLOSE( id_set_pts )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 394 )
+                CALL handle_netcdf_error( 'check_open', 394 )
                 CALL local_system( 'rm ' // TRIM( filename ) )
              ENDIF
@@ -1213,5 +1216,5 @@
                 nc_stat = NF90_CREATE( filename, NF90_NOCLOBBER, id_set_pts )
              ENDIF
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 395 )
+             CALL handle_netcdf_error( 'check_open', 395 )
 !
 !--          Define the header
Index: palm/trunk/SOURCE/close_file.f90
===================================================================
--- palm/trunk/SOURCE/close_file.f90	(revision 262)
+++ palm/trunk/SOURCE/close_file.f90	(revision 263)
@@ -2,7 +2,7 @@
 
 !------------------------------------------------------------------------------!
-! Actual revisions:
+! Current revisions:
 ! -----------------
-! 
+! Output of NetCDF messages with aid of message handling routine.
 !
 ! Former revisions:
@@ -403,5 +403,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_xy(0) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 44 )
+                   CALL handle_netcdf_error( 'close_file', 44 )
                 ENDIF
 
@@ -410,5 +410,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_xz(0) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 45 )
+                   CALL handle_netcdf_error( 'close_file', 45 )
                 ENDIF
 
@@ -417,5 +417,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_yz(0) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 46 )
+                   CALL handle_netcdf_error( 'close_file', 46 )
                 ENDIF
 
@@ -424,5 +424,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_pr )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 47 )
+                   CALL handle_netcdf_error( 'close_file', 47 )
                 ENDIF
 
@@ -431,5 +431,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_ts )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 48 )
+                   CALL handle_netcdf_error( 'close_file', 48 )
                 ENDIF
 
@@ -438,5 +438,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_3d(0) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 49 )
+                   CALL handle_netcdf_error( 'close_file', 49 )
                 ENDIF
 
@@ -445,5 +445,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_sp )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 50 )
+                   CALL handle_netcdf_error( 'close_file', 50 )
                 ENDIF
 
@@ -452,5 +452,5 @@
                 IF (  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_prt )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 51 )
+                   CALL handle_netcdf_error( 'close_file', 51 )
                 ENDIF
 
@@ -459,5 +459,5 @@
                 IF (  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_pts )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 412 )
+                   CALL handle_netcdf_error( 'close_file', 412 )
                 ENDIF
 
@@ -466,5 +466,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_xy(1) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 52 )
+                   CALL handle_netcdf_error( 'close_file', 52 )
                 ENDIF
 
@@ -473,5 +473,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_xz(1) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 352 )
+                   CALL handle_netcdf_error( 'close_file', 352 )
                 ENDIF
 
@@ -480,5 +480,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_yz(1) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 353 )
+                   CALL handle_netcdf_error( 'close_file', 353 )
                 ENDIF
 
@@ -487,5 +487,5 @@
                 IF ( myid == 0  .AND.  netcdf_output )  THEN
                    nc_stat = NF90_CLOSE( id_set_3d(1) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 353 )
+                   CALL handle_netcdf_error( 'close_file', 353 )
                 ENDIF
 
Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine.
 !
@@ -568,7 +569,5 @@
                                          start = (/ do2d_xy_time_count(av) /), &
                                                     count = (/ 1 /) )
-                            IF ( nc_stat /= NF90_NOERR )  THEN
-                               CALL handle_netcdf_error( 53 )
-                            ENDIF
+                         CALL handle_netcdf_error( 'data_output_2d', 53 )
 #endif
                          ENDIF
@@ -666,6 +665,5 @@
                                                 count = (/ nx+2, ny+2, 1, 1 /) )
                             ENDIF
-                            IF ( nc_stat /= NF90_NOERR )  &
-                                                  CALL handle_netcdf_error( 54 )
+                            CALL handle_netcdf_error( 'data_output_2d', 54 )
                          ENDIF
 #endif
@@ -708,6 +706,5 @@
                                               count = (/ nx+2, ny+2, 1, 1 /) )
                       ENDIF
-                      IF ( nc_stat /= NF90_NOERR )  &
-                                                  CALL handle_netcdf_error( 55 )
+                      CALL handle_netcdf_error( 'data_output_2d', 55 )
                    ENDIF
 #endif
@@ -758,7 +755,5 @@
                                          start = (/ do2d_xz_time_count(av) /), &
                                                     count = (/ 1 /) )
-                            IF ( nc_stat /= NF90_NOERR )  THEN
-                               CALL handle_netcdf_error( 56 )
-                            ENDIF
+                             CALL handle_netcdf_error( 'data_output_2d', 56 )
 #endif
                          ENDIF
@@ -882,6 +877,5 @@
                                start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
                                                 count = (/ nx+2, 1, nz+2, 1 /) )
-                            IF ( nc_stat /= NF90_NOERR ) &
-                                                  CALL handle_netcdf_error( 57 )
+                            CALL handle_netcdf_error( 'data_output_2d', 57 )
                          ENDIF
 #endif
@@ -926,6 +920,5 @@
                                start = (/ 1, is, 1, do2d_xz_time_count(av) /), &
                                               count = (/ nx+2, 1, nz+2, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  &
-                                                  CALL handle_netcdf_error( 58 )
+                      CALL handle_netcdf_error( 'data_output_2d', 58 )
                    ENDIF
 #endif
@@ -969,7 +962,5 @@
                                          start = (/ do2d_yz_time_count(av) /), &
                                                     count = (/ 1 /) )
-                            IF ( nc_stat /= NF90_NOERR )  THEN
-                               CALL handle_netcdf_error( 59 )
-                            ENDIF
+                            CALL handle_netcdf_error( 'data_output_2d', 59 )
 #endif
                          ENDIF
@@ -1093,6 +1084,5 @@
                                start = (/ is, 1, 1, do2d_yz_time_count(av) /), &
                                                 count = (/ 1, ny+2, nz+2, 1 /) )
-                            IF ( nc_stat /= NF90_NOERR ) &
-                                                  CALL handle_netcdf_error( 60 )
+                            CALL handle_netcdf_error( 'data_output_2d', 60 )
                          ENDIF
 #endif
@@ -1137,6 +1127,5 @@
                                start = (/ is, 1, 1, do2d_xz_time_count(av) /), &
                                               count = (/ 1, ny+2, nz+2, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  &
-                                                  CALL handle_netcdf_error( 61 )
+                      CALL handle_netcdf_error( 'data_output_2d', 61 )
                    ENDIF
 #endif
Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_3d.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine.
 !
@@ -95,5 +96,5 @@
                                start = (/ do3d_time_count(av) /), &
                                count = (/ 1 /) )
-       IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 1009 )
+       CALL handle_netcdf_error( 'data_output_3d', 1009 )
     ENDIF
 #endif
@@ -385,5 +386,5 @@
                                   start = (/ 1, 1, 1, do3d_time_count(av) /), &
                                   count = (/ nx+2, ny+2, nz_do3d-nzb+1, 1 /) )
-             IF ( nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 1010 )
+             CALL handle_netcdf_error( 'data_output_3d', 1010 )
           ENDIF
 #endif
Index: palm/trunk/SOURCE/data_output_profiles.f90
===================================================================
--- palm/trunk/SOURCE/data_output_profiles.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_profiles.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine.
 !
@@ -117,5 +118,5 @@
                                            (/ 0.0 /), start = (/ 1 /), &
                                            count = (/ 1 /) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 329 )
+                   CALL handle_netcdf_error( 'data_output_profiles', 329 )
                    output_for_t0 = .TRUE.
                    EXIT
@@ -128,20 +129,18 @@
                                   (/ hom_sum(nzb,18,normalizing_region) /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 330 )
+             CALL handle_netcdf_error( 'data_output_profiles', 330 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
                         (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 331 )
-
+             CALL handle_netcdf_error( 'data_output_profiles', 331 )
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
                         (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 332 )
-
+             CALL handle_netcdf_error( 'data_output_profiles', 332 )
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
                         (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 333 )
+             CALL handle_netcdf_error( 'data_output_profiles', 333 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
@@ -149,5 +148,5 @@
                            hom_sum(nzb+3,pr_palm,normalizing_region)    /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 334 )
+             CALL handle_netcdf_error( 'data_output_profiles', 334 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
@@ -155,10 +154,10 @@
                            hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 335 )
+             CALL handle_netcdf_error( 'data_output_profiles', 335 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
                            (/ hom_sum(nzb+6,pr_palm,normalizing_region) /), &
                                      start = (/ 1 /), count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 336 )
+             CALL handle_netcdf_error( 'data_output_profiles', 336 )
 #endif
           ENDIF
@@ -197,6 +196,5 @@
                                               start = (/ 1, 1 /),              &
                                               count = (/ nzt-nzb+2, 1 /) )
-                      IF ( nc_stat /= NF90_NOERR )  &
-                                                CALL handle_netcdf_error( 337 )
+                      CALL handle_netcdf_error( 'data_output_profiles', 337 )
 #endif
                    ENDIF
@@ -361,5 +359,5 @@
                                   start = (/ dopr_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 338 )
+          CALL handle_netcdf_error( 'data_output_profiles', 338 )
 
 !
@@ -369,5 +367,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 339 )
+          CALL handle_netcdf_error( 'data_output_profiles', 339 )
 
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
@@ -375,5 +373,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 340 )
+          CALL handle_netcdf_error( 'data_output_profiles', 340 )
 
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
@@ -381,5 +379,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 341 )
+          CALL handle_netcdf_error( 'data_output_profiles', 341 )
 
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
@@ -387,5 +385,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 342 )
+          CALL handle_netcdf_error( 'data_output_profiles', 342 )
 
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
@@ -394,6 +392,6 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 343 )
-
+          CALL handle_netcdf_error( 'data_output_profiles', 343 )
+         
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
                         (/ hom_sum(nzb+8,pr_palm,normalizing_region) *      &
@@ -401,5 +399,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 344 )
+          CALL handle_netcdf_error( 'data_output_profiles', 344 )
 
           nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
@@ -407,5 +405,5 @@
                                   start = (/ dopr_time_count /),               &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 345 )
+          CALL handle_netcdf_error( 'data_output_profiles', 345 )
 #endif
        ENDIF
@@ -443,5 +441,5 @@
                                         start = (/ 1, dopr_time_count /),      &
                                         count = (/ nzt-nzb+2, 1 /) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 346 )
+                CALL handle_netcdf_error( 'data_output_profiles', 346 )
 #endif
              ENDIF
Index: palm/trunk/SOURCE/data_output_ptseries.f90
===================================================================
--- palm/trunk/SOURCE/data_output_ptseries.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_ptseries.f90	(revision 263)
@@ -2,7 +2,8 @@
 
 !------------------------------------------------------------------------------!
-! Actual revisions:
+! Current revisions:
 ! -----------------
-! 
+! Output of NetCDF messages with aid of message handling routine.
+!
 !
 ! Former revisions:
@@ -57,5 +58,5 @@
                                (/ simulated_time /),           &
                                start = (/ dopts_time_count /), count = (/ 1 /) )
-       IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 391 )
+       CALL handle_netcdf_error( 'data_output_ptseries', 391 )
 #endif
 
@@ -269,5 +270,5 @@
                                      start = (/ dopts_time_count /), &
                                      count = (/ 1 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 392 )
+             CALL handle_netcdf_error( 'data_output_ptseries', 392 )
           ENDDO
        ENDDO
Index: palm/trunk/SOURCE/data_output_spectra.f90
===================================================================
--- palm/trunk/SOURCE/data_output_spectra.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_spectra.f90	(revision 263)
@@ -4,4 +4,5 @@
 ! Current revisions:
 ! -----------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine.
 !
@@ -66,5 +67,5 @@
        nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp, (/ simulated_time /),&
                                start = (/ dosp_time_count /), count = (/ 1 /) )
-       IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 47 )
+       CALL handle_netcdf_error( 'data_output_spectra', 47 )
 #endif
 
@@ -225,5 +226,5 @@
                                   start = (/ 1, k, dosp_time_count /), &
                                   count = (/ nx/2, 1, 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 348 )
+          CALL handle_netcdf_error( 'data_output_spectra', 348 )
 
        ENDDO
@@ -243,5 +244,5 @@
                                   start = (/ 1, k, dosp_time_count /), &
                                   count = (/ ny/2, 1, 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 349 )
+          CALL handle_netcdf_error( 'data_output_spectra', 349 )
 
        ENDDO
Index: palm/trunk/SOURCE/data_output_tseries.f90
===================================================================
--- palm/trunk/SOURCE/data_output_tseries.f90	(revision 262)
+++ palm/trunk/SOURCE/data_output_tseries.f90	(revision 263)
@@ -2,7 +2,8 @@
 
 !------------------------------------------------------------------------------!
-! Actual revisions:
+! Current revisions:
 ! -----------------
-! 
+! Output of NetCDF messages with aid of message handling routine.
+!
 !
 ! Former revisions:
@@ -66,5 +67,5 @@
                                   start = (/ dots_time_count /), &
                                   count = (/ 1 /) )
-          IF (nc_stat /= NF90_NOERR)  CALL handle_netcdf_error( 350 )
+          CALL handle_netcdf_error( 'data_output_tseries', 350 )
 #endif
        ENDIF
@@ -82,5 +83,5 @@
                                         start = (/ dots_time_count /), &
                                         count = (/ 1 /) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 351 )
+                CALL handle_netcdf_error( 'data_output_tseries', 351 )
              ENDDO
           ENDIF
Index: palm/trunk/SOURCE/netcdf.f90
===================================================================
--- palm/trunk/SOURCE/netcdf.f90	(revision 262)
+++ palm/trunk/SOURCE/netcdf.f90	(revision 263)
@@ -7,4 +7,5 @@
 ! Current revisions:
 ! ------------------
+! Output of NetCDF messages with aid of message handling routine.
 ! Output of messages replaced by message handling routine.
 !
@@ -187,5 +188,5 @@
           nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'Conventions', &
                                   'COARDS' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 62 )
+          CALL handle_netcdf_error( 'netcdf', 62 )
 
           IF ( av == 0 )  THEN
@@ -198,10 +199,10 @@
                                   TRIM( run_description_header ) //    &
                                   TRIM( time_average_text ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 63 )
+          CALL handle_netcdf_error( 'netcdf', 63 )
           IF ( av == 1 )  THEN
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
              nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'time_avg', &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 63 )
+             CALL handle_netcdf_error( 'netcdf', 63 )
           ENDIF
 
@@ -210,13 +211,13 @@
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'time', NF90_UNLIMITED, &
                                   id_dim_time_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 64 )
+          CALL handle_netcdf_error( 'netcdf', 64 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'time', NF90_DOUBLE, &
                                   id_dim_time_3d(av), id_var_time_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 65 )
+          CALL handle_netcdf_error( 'netcdf', 65 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_time_3d(av), 'units', &
                                   'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 66 )
+          CALL handle_netcdf_error( 'netcdf', 66 )
 
 !
@@ -225,13 +226,13 @@
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'zu_3d', nz_do3d-nzb+1, &
                                   id_dim_zu_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 67 )
+          CALL handle_netcdf_error( 'netcdf', 67 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zu_3d', NF90_DOUBLE, &
                                   id_dim_zu_3d(av), id_var_zu_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 68 )
+          CALL handle_netcdf_error( 'netcdf', 68 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zu_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 69 )
+          CALL handle_netcdf_error( 'netcdf', 69 )
 
 !
@@ -239,65 +240,65 @@
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'zw_3d', nz_do3d-nzb+1, &
                                   id_dim_zw_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 70 )
+          CALL handle_netcdf_error( 'netcdf', 70 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'zw_3d', NF90_DOUBLE, &
                                   id_dim_zw_3d(av), id_var_zw_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 71 )
+          CALL handle_netcdf_error( 'netcdf', 71 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zw_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 72 )
+          CALL handle_netcdf_error( 'netcdf', 72 )
 
 !
 !--       Define x-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'x', nx+2, id_dim_x_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 73 )
+          CALL handle_netcdf_error( 'netcdf', 73 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'x', NF90_DOUBLE, &
                                   id_dim_x_3d(av), id_var_x_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 74 )
+          CALL handle_netcdf_error( 'netcdf', 74 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_x_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 75 )
+          CALL handle_netcdf_error( 'netcdf', 75 )
 
 !
 !--       Define x-axis (for u position)
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'xu', nx+2, id_dim_xu_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 358 )
+          CALL handle_netcdf_error( 'netcdf', 358 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'xu', NF90_DOUBLE, &
                                   id_dim_xu_3d(av), id_var_xu_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 359 )
+          CALL handle_netcdf_error( 'netcdf', 359 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_xu_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 360 )
+          CALL handle_netcdf_error( 'netcdf', 360 )
 
 !
 !--       Define y-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'y', ny+2, id_dim_y_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 76 )
+          CALL handle_netcdf_error( 'netcdf', 76 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'y', NF90_DOUBLE, &
                                   id_dim_y_3d(av), id_var_y_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 77 )
+          CALL handle_netcdf_error( 'netcdf', 77 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_y_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 78 )
+          CALL handle_netcdf_error( 'netcdf', 78 )
 
 !
 !--       Define y-axis (for v position)
           nc_stat = NF90_DEF_DIM( id_set_3d(av), 'yv', ny+2, id_dim_yv_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 361 )
+          CALL handle_netcdf_error( 'netcdf', 361 )
 
           nc_stat = NF90_DEF_VAR( id_set_3d(av), 'yv', NF90_DOUBLE, &
                                   id_dim_yv_3d(av), id_var_yv_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 362 )
+          CALL handle_netcdf_error( 'netcdf', 362 )
 
           nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_yv_3d(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 363 )
+          CALL handle_netcdf_error( 'netcdf', 363 )
 
 !
@@ -310,13 +311,13 @@
                                      (/ id_dim_x_3d(av), id_dim_y_3d(av) /), &
                                      id_var_zusi_3d(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 413 )
+             CALL handle_netcdf_error( 'netcdf', 413 )
              
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zusi_3d(av), &
                                      'units', 'meters' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 414 )
+             CALL handle_netcdf_error( 'netcdf', 414 )
              
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zusi_3d(av), &
                                      'long_name', 'zu(nzb_s_inner)' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 415 )
+             CALL handle_netcdf_error( 'netcdf', 415 )
 
 !             
@@ -325,13 +326,13 @@
                                      (/ id_dim_x_3d(av), id_dim_y_3d(av) /), &
                                      id_var_zwwi_3d(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 416 )
+             CALL handle_netcdf_error( 'netcdf', 416 )
              
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zwwi_3d(av), &
                                      'units', 'meters' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 417 )
+             CALL handle_netcdf_error( 'netcdf', 417 )
              
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_zwwi_3d(av), &
                                      'long_name', 'zw(nzb_w_inner)' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 418 )
+             CALL handle_netcdf_error( 'netcdf', 418 )
 
           ENDIF             
@@ -422,5 +423,5 @@
              var_list = TRIM( var_list ) // TRIM( do3d(av,i) ) // ';'
 
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 79 )
+             CALL handle_netcdf_error( 'netcdf', 79 )
 !
 !--          Store the 'real' name of the variable (with *, for example)
@@ -429,10 +430,10 @@
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_do3d(av,i), &
                                      'long_name', do3d(av,i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 80 )
+             CALL handle_netcdf_error( 'netcdf', 80 )
 !
 !--          Define the variable's unit
              nc_stat = NF90_PUT_ATT( id_set_3d(av), id_var_do3d(av,i), &
                                      'units', TRIM( do3d_unit(av,i) ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 357 )
+             CALL handle_netcdf_error( 'netcdf', 357 )
 
              i = i + 1
@@ -449,10 +450,10 @@
           nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 81 )
+          CALL handle_netcdf_error( 'netcdf', 81 )
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 82 )
+          CALL handle_netcdf_error( 'netcdf', 82 )
 
 !
@@ -466,5 +467,5 @@
           nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_x_3d(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 83 )
+          CALL handle_netcdf_error( 'netcdf', 83 )
 
           DO  i = 0, nx+1
@@ -475,5 +476,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 385 )
+          CALL handle_netcdf_error( 'netcdf', 385 )
 
           DEALLOCATE( netcdf_data )
@@ -489,5 +490,5 @@
           nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_y_3d(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ny+2 /))
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 84 )
+          CALL handle_netcdf_error( 'netcdf', 84 )
 
           DO  i = 0, ny+1
@@ -498,5 +499,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ny+2 /))
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 387 )
+          CALL handle_netcdf_error( 'netcdf', 387 )
 
           DEALLOCATE( netcdf_data )
@@ -507,10 +508,11 @@
                                   zu(nzb:nz_do3d), start = (/ 1 /), &
                                   count = (/ nz_do3d-nzb+1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 85 )
+          CALL handle_netcdf_error( 'netcdf', 85 )
+
 
           nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_zw_3d(av),    &
                                   zw(nzb:nz_do3d), start = (/ 1 /), &
                                   count = (/ nz_do3d-nzb+1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 86 )
+          CALL handle_netcdf_error( 'netcdf', 86 )
 
 
@@ -523,5 +525,5 @@
                                      start = (/ 1, 1 /), &
                                      count = (/ nx+2, ny+2 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 419 )
+             CALL handle_netcdf_error( 'netcdf', 419 )
 
              nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_zwwi_3d(av), &
@@ -529,5 +531,5 @@
                                      start = (/ 1, 1 /), &
                                      count = (/ nx+2, ny+2 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 420 )
+             CALL handle_netcdf_error( 'netcdf', 420 )
 
           ENDIF
@@ -542,5 +544,5 @@
           nc_stat = NF90_GET_ATT( id_set_3d(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 87 )
+          CALL handle_netcdf_error( 'netcdf', 87 )
 
           var_list = ';'
@@ -571,14 +573,14 @@
 !--       Get and compare the number of vertical gridpoints
           nc_stat = NF90_INQ_VARID( id_set_3d(av), 'zu_3d', id_var_zu_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 88 )
+          CALL handle_netcdf_error( 'netcdf', 88 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_3d(av), id_var_zu_3d(av), &
                                            dimids = id_dim_zu_3d_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 89 )
+          CALL handle_netcdf_error( 'netcdf', 89 )
           id_dim_zu_3d(av) = id_dim_zu_3d_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_3d(av), id_dim_zu_3d(av), &
                                             len = nz_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 90 )
+          CALL handle_netcdf_error( 'netcdf', 90 )
 
           IF ( nz_do3d-nzb+1 /= nz_old )  THEN
@@ -600,14 +602,15 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_3d(av), 'time', id_var_time_3d(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 91 )
+          CALL handle_netcdf_error( 'netcdf', 91 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_3d(av), id_var_time_3d(av), &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 92 )
+          CALL handle_netcdf_error( 'netcdf', 92 )
+
           id_dim_time_3d(av) = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_3d(av), id_dim_time_3d(av), &
                                             len = do3d_time_count(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 93 )
+          CALL handle_netcdf_error( 'netcdf', 93 )
 
           nc_stat = NF90_GET_VAR( id_set_3d(av), id_var_time_3d(av), &
@@ -615,5 +618,5 @@
                                   start = (/ do3d_time_count(av) /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 94 )
+          CALL handle_netcdf_error( 'netcdf', 94 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -638,5 +641,5 @@
              nc_stat = NF90_INQ_VARID( id_set_3d(av), TRIM( do3d(av,i) ), &
                                        id_var_do3d(av,i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 95 )
+             CALL handle_netcdf_error( 'netcdf', 95 )
              i = i + 1
           ENDDO
@@ -646,5 +649,5 @@
           nc_stat = NF90_PUT_ATT( id_set_3d(av), NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 96 )
+          CALL handle_netcdf_error( 'netcdf', 96 )
           message_string = 'NetCDF file for volume data ' //             &
                            TRIM( var ) // ' from previous run found.' // &
@@ -658,5 +661,5 @@
           nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'Conventions', &
                                   'COARDS' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 97 )
+          CALL handle_netcdf_error( 'netcdf', 97 )
 
           IF ( av == 0 )  THEN
@@ -669,10 +672,10 @@
                                   TRIM( run_description_header ) //    &
                                   TRIM( time_average_text ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 98 )
+          CALL handle_netcdf_error( 'netcdf', 98 )
           IF ( av == 1 )  THEN
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
              nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'time_avg', &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 98 )
+             CALL handle_netcdf_error( 'netcdf', 98 )
           ENDIF
 
@@ -681,13 +684,13 @@
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'time', NF90_UNLIMITED, &
                                   id_dim_time_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 99 )
+          CALL handle_netcdf_error( 'netcdf', 99 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'time', NF90_DOUBLE, &
                                   id_dim_time_xy(av), id_var_time_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 100 )
+          CALL handle_netcdf_error( 'netcdf', 100 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_time_xy(av), 'units', &
                                   'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 101 )
+          CALL handle_netcdf_error( 'netcdf', 101 )
 
 !
@@ -707,26 +710,26 @@
 !--       Define vertical coordinate grid (zu grid)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zu_xy', ns, id_dim_zu_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 102 )
+          CALL handle_netcdf_error( 'netcdf', 102 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zu_xy', NF90_DOUBLE, &
                                   id_dim_zu_xy(av), id_var_zu_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 103 )
+          CALL handle_netcdf_error( 'netcdf', 103 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zu_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 104 )
+          CALL handle_netcdf_error( 'netcdf', 104 )
 
 !
 !--       Define vertical coordinate grid (zw grid)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zw_xy', ns, id_dim_zw_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 105 )
+          CALL handle_netcdf_error( 'netcdf', 105 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zw_xy', NF90_DOUBLE, &
                                   id_dim_zw_xy(av), id_var_zw_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 106 )
+          CALL handle_netcdf_error( 'netcdf', 106 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zw_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 107 )
+          CALL handle_netcdf_error( 'netcdf', 107 )
 
 !
@@ -735,13 +738,13 @@
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'zu1_xy', 1, &
                                   id_dim_zu1_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 108 )
+          CALL handle_netcdf_error( 'netcdf', 108 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'zu1_xy', NF90_DOUBLE, &
                                   id_dim_zu1_xy(av), id_var_zu1_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 109 )
+          CALL handle_netcdf_error( 'netcdf', 109 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zu1_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 110 )
+          CALL handle_netcdf_error( 'netcdf', 110 )
 
 !
@@ -750,61 +753,62 @@
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'ind_z_xy', NF90_DOUBLE, &
                                   id_dim_zu_xy(av), id_var_ind_z_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 111 )
+          CALL handle_netcdf_error( 'netcdf', 111 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_ind_z_xy(av), 'units', &
                                   'gridpoints')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 112 )
+          CALL handle_netcdf_error( 'netcdf', 112 )
 
 !
 !--       Define x-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'x', nx+2, id_dim_x_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 113 )
+          CALL handle_netcdf_error( 'netcdf', 113 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'x', NF90_DOUBLE, &
                                   id_dim_x_xy(av), id_var_x_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 114 )
+          CALL handle_netcdf_error( 'netcdf', 114 )
+
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_x_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 115 )
+          CALL handle_netcdf_error( 'netcdf', 115 )
 
 !
 !--       Define x-axis (for u position)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'xu', nx+2, id_dim_xu_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 388 )
+          CALL handle_netcdf_error( 'netcdf', 388 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'xu', NF90_DOUBLE, &
                                   id_dim_xu_xy(av), id_var_xu_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 389 )
+          CALL handle_netcdf_error( 'netcdf', 389 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_xu_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 390 )
+          CALL handle_netcdf_error( 'netcdf', 390 )
 
 !
 !--       Define y-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'y', ny+2, id_dim_y_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 116 )
+          CALL handle_netcdf_error( 'netcdf', 116 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'y', NF90_DOUBLE, &
                                   id_dim_y_xy(av), id_var_y_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 117 )
+          CALL handle_netcdf_error( 'netcdf', 117 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_y_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 118 )
+          CALL handle_netcdf_error( 'netcdf', 118 )
 
 !
 !--       Define y-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_xy(av), 'yv', ny+2, id_dim_yv_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 364 )
+          CALL handle_netcdf_error( 'netcdf', 364 )
 
           nc_stat = NF90_DEF_VAR( id_set_xy(av), 'yv', NF90_DOUBLE, &
                                   id_dim_yv_xy(av), id_var_yv_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 365 )
+          CALL handle_netcdf_error( 'netcdf', 365 )
 
           nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_yv_xy(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 366 )
+          CALL handle_netcdf_error( 'netcdf', 366 )
 
 !
@@ -817,13 +821,13 @@
                                      (/ id_dim_x_xy(av), id_dim_y_xy(av) /), &
                                      id_var_zusi_xy(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 421 )
+             CALL handle_netcdf_error( 'netcdf', 421 )
              
              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zusi_xy(av), &
                                      'units', 'meters' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 422 )
+             CALL handle_netcdf_error( 'netcdf', 422 )
              
              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zusi_xy(av), &
                                      'long_name', 'zu(nzb_s_inner)' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 423 )
+             CALL handle_netcdf_error( 'netcdf', 423 )
 
 !             
@@ -832,13 +836,13 @@
                                      (/ id_dim_x_xy(av), id_dim_y_xy(av) /), &
                                      id_var_zwwi_xy(av) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 424 )
+             CALL handle_netcdf_error( 'netcdf', 424 )
              
              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zwwi_xy(av), &
                                      'units', 'meters' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 425 )
+             CALL handle_netcdf_error( 'netcdf', 425 )
              
              nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_zwwi_xy(av), &
                                      'long_name', 'zw(nzb_w_inner)' )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 426 )
+             CALL handle_netcdf_error( 'netcdf', 426 )
 
           ENDIF
@@ -953,5 +957,5 @@
                 ENDIF
 
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 119 )
+                CALL handle_netcdf_error( 'netcdf', 119 )
 !
 !--             Store the 'real' name of the variable (with *, for example)
@@ -960,10 +964,10 @@
                 nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_do2d(av,i), &
                                         'long_name', do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 120 )
+                CALL handle_netcdf_error( 'netcdf', 120 )
 !
 !--             Define the variable's unit
                 nc_stat = NF90_PUT_ATT( id_set_xy(av), id_var_do2d(av,i), &
                                         'units', TRIM( do2d_unit(av,i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 354 )
+                CALL handle_netcdf_error( 'netcdf', 354 ) 
              ENDIF
 
@@ -981,10 +985,10 @@
           nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 121 )
+          CALL handle_netcdf_error( 'netcdf', 121 ) 
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 122 )
+          CALL handle_netcdf_error( 'netcdf', 122 ) 
 
 !
@@ -1004,5 +1008,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 123 )
+          CALL handle_netcdf_error( 'netcdf', 123 )
 
 !
@@ -1018,5 +1022,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 124 )
+          CALL handle_netcdf_error( 'netcdf', 124 )
 
 !
@@ -1026,5 +1030,5 @@
                                   netcdf_data, start = (/ 1 /),       &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 125 )
+          CALL handle_netcdf_error( 'netcdf', 125 )
 
           DEALLOCATE( netcdf_data )
@@ -1035,5 +1039,5 @@
                                   (/ zu(nzb+1) /), start = (/ 1 /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 126 )
+          CALL handle_netcdf_error( 'netcdf', 126 )
 
 !
@@ -1047,5 +1051,5 @@
           nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_x_xy(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 127 )
+          CALL handle_netcdf_error( 'netcdf', 127 )
 
           DO  i = 0, nx+1
@@ -1056,5 +1060,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 367 )
+          CALL handle_netcdf_error( 'netcdf', 367 )
 
           DEALLOCATE( netcdf_data )
@@ -1070,5 +1074,5 @@
           nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_y_xy(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ny+2 /))
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 128 )
+          CALL handle_netcdf_error( 'netcdf', 128 )
 
           DO  i = 0, ny+1
@@ -1079,5 +1083,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ny+2 /))
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 368 )
+          CALL handle_netcdf_error( 'netcdf', 368 )
 
           DEALLOCATE( netcdf_data )
@@ -1091,5 +1095,5 @@
                                      start = (/ 1, 1 /), &
                                      count = (/ nx+2, ny+2 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 427 )
+             CALL handle_netcdf_error( 'netcdf', 427 )
 
              nc_stat = NF90_PUT_VAR( id_set_xy(av), id_var_zwwi_xy(av), &
@@ -1097,5 +1101,5 @@
                                      start = (/ 1, 1 /), &
                                      count = (/ nx+2, ny+2 /) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 428 )
+             CALL handle_netcdf_error( 'netcdf', 428 )
 
           ENDIF
@@ -1111,5 +1115,5 @@
           nc_stat = NF90_GET_ATT( id_set_xy(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 129 )
+          CALL handle_netcdf_error( 'netcdf', 129 )
 
           var_list = ';'
@@ -1152,14 +1156,14 @@
 !--       Get and compare the number of horizontal cross sections
           nc_stat = NF90_INQ_VARID( id_set_xy(av), 'zu_xy', id_var_zu_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 130 )
+          CALL handle_netcdf_error( 'netcdf', 130 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_xy(av), id_var_zu_xy(av), &
                                            dimids = id_dim_zu_xy_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 131 )
+          CALL handle_netcdf_error( 'netcdf', 131 )
           id_dim_zu_xy(av) = id_dim_zu_xy_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_xy(av), id_dim_zu_xy(av), &
                                             len = ns_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 132 )
+          CALL handle_netcdf_error( 'netcdf', 132 )
 
           IF ( ns /= ns_old )  THEN
@@ -1180,5 +1184,5 @@
 
           nc_stat = NF90_GET_VAR( id_set_xy(av), id_var_zu_xy(av), netcdf_data )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 133 )
+          CALL handle_netcdf_error( 'netcdf', 133 )
 
           DO  i = 1, ns
@@ -1218,14 +1222,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_xy(av), 'time', id_var_time_xy(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 134 )
+          CALL handle_netcdf_error( 'netcdf', 134 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_xy(av), id_var_time_xy(av), &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 135 )
+          CALL handle_netcdf_error( 'netcdf', 135 )
           id_dim_time_xy(av) = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_xy(av), id_dim_time_xy(av), &
                                             len = do2d_xy_time_count(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 136 )
+          CALL handle_netcdf_error( 'netcdf', 136 )
 
           nc_stat = NF90_GET_VAR( id_set_xy(av), id_var_time_xy(av),    &
@@ -1233,5 +1237,5 @@
                                   start = (/ do2d_xy_time_count(av) /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 137 )
+          CALL handle_netcdf_error( 'netcdf', 137 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -1259,5 +1263,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_xy(av), netcdf_var_name, &
                                           id_var_do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 138 )
+                CALL handle_netcdf_error( 'netcdf', 138 )
              ENDIF
              i = i + 1
@@ -1268,5 +1272,5 @@
           nc_stat = NF90_PUT_ATT( id_set_xy(av), NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 139 )
+          CALL handle_netcdf_error( 'netcdf', 139 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -1281,5 +1285,5 @@
           nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'Conventions', &
                                   'COARDS' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 140 )
+          CALL handle_netcdf_error( 'netcdf', 140 )
 
           IF ( av == 0 )  THEN
@@ -1292,10 +1296,10 @@
                                   TRIM( run_description_header )  //   &
                                   TRIM( time_average_text ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 141 )
+          CALL handle_netcdf_error( 'netcdf', 141 )
           IF ( av == 1 )  THEN
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
              nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'time_avg', &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 141 )
+             CALL handle_netcdf_error( 'netcdf', 141 )
           ENDIF
 
@@ -1304,13 +1308,13 @@
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'time', NF90_UNLIMITED, &
                                   id_dim_time_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 142 )
+          CALL handle_netcdf_error( 'netcdf', 142 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'time', NF90_DOUBLE, &
                                   id_dim_time_xz(av), id_var_time_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 143 )
+          CALL handle_netcdf_error( 'netcdf', 143 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_time_xz(av), 'units', &
                                   'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 144 )
+          CALL handle_netcdf_error( 'netcdf', 144 )
 
 !
@@ -1330,26 +1334,26 @@
 !--       Define y-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'y_xz', ns, id_dim_y_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 145 )
+          CALL handle_netcdf_error( 'netcdf', 145 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'y_xz', NF90_DOUBLE, &
                                   id_dim_y_xz(av), id_var_y_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 146 )
+          CALL handle_netcdf_error( 'netcdf', 146 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_y_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 147 )
+          CALL handle_netcdf_error( 'netcdf', 147 )
 
 !
 !--       Define y-axis (for v position)
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'yv_xz', ns, id_dim_yv_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 369 )
+          CALL handle_netcdf_error( 'netcdf', 369 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'yv_xz', NF90_DOUBLE, &
                                   id_dim_yv_xz(av), id_var_yv_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 370 )
+          CALL handle_netcdf_error( 'netcdf', 370 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_yv_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 371 )
+          CALL handle_netcdf_error( 'netcdf', 371 )
 
 !
@@ -1358,59 +1362,59 @@
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'ind_y_xz', NF90_DOUBLE, &
                                   id_dim_y_xz(av), id_var_ind_y_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 148 )
+          CALL handle_netcdf_error( 'netcdf', 148 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_ind_y_xz(av), 'units', &
                                   'gridpoints')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 149 )
+          CALL handle_netcdf_error( 'netcdf', 149 )
 
 !
 !--       Define x-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'x', nx+2, id_dim_x_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 150 )
+          CALL handle_netcdf_error( 'netcdf', 150 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'x', NF90_DOUBLE, &
                                   id_dim_x_xz(av), id_var_x_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 151 )
+          CALL handle_netcdf_error( 'netcdf', 151 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_x_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 152 )
+          CALL handle_netcdf_error( 'netcdf', 152 )
 
 !
 !--       Define x-axis (for u position)
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'xu', nx+2, id_dim_xu_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 372 )
+          CALL handle_netcdf_error( 'netcdf', 372 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'xu', NF90_DOUBLE, &
                                   id_dim_xu_xz(av), id_var_xu_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 373 )
+          CALL handle_netcdf_error( 'netcdf', 373 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_xu_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 374 )
+          CALL handle_netcdf_error( 'netcdf', 374 )
 
 !
 !--       Define the two z-axes (zu and zw)
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'zu', nz+2, id_dim_zu_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 153 )
+          CALL handle_netcdf_error( 'netcdf', 153 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'zu', NF90_DOUBLE, &
                                   id_dim_zu_xz(av), id_var_zu_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 154 )
+          CALL handle_netcdf_error( 'netcdf', 154 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_zu_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 155 )
+          CALL handle_netcdf_error( 'netcdf', 155 )
 
           nc_stat = NF90_DEF_DIM( id_set_xz(av), 'zw', nz+2, id_dim_zw_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 156 )
+          CALL handle_netcdf_error( 'netcdf', 156 )
 
           nc_stat = NF90_DEF_VAR( id_set_xz(av), 'zw', NF90_DOUBLE, &
                                   id_dim_zw_xz(av), id_var_zw_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 157 )
+          CALL handle_netcdf_error( 'netcdf', 157 )
 
           nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_zw_xz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 158 )
+          CALL handle_netcdf_error( 'netcdf', 158 )
 
 
@@ -1502,5 +1506,5 @@
                 var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
 
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 159 )
+                CALL handle_netcdf_error( 'netcdf', 159 )
 !
 !--             Store the 'real' name of the variable (with *, for example)
@@ -1509,10 +1513,10 @@
                 nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_do2d(av,i), &
                                         'long_name', do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 160 )
+                CALL handle_netcdf_error( 'netcdf', 160 )
 !
 !--             Define the variable's unit
                 nc_stat = NF90_PUT_ATT( id_set_xz(av), id_var_do2d(av,i), &
                                         'units', TRIM( do2d_unit(av,i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 355 )
+                CALL handle_netcdf_error( 'netcdf', 355 )
              ENDIF
 
@@ -1530,10 +1534,10 @@
           nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 161 )
+          CALL handle_netcdf_error( 'netcdf', 161 )
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 162 )
+          CALL handle_netcdf_error( 'netcdf', 162 )
 
 !
@@ -1552,5 +1556,5 @@
           nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_y_xz(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 163 )
+          CALL handle_netcdf_error( 'netcdf', 163 )
 
 !
@@ -1566,5 +1570,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 375 )
+          CALL handle_netcdf_error( 'netcdf', 375 )
 
 !
@@ -1574,5 +1578,6 @@
                                   netcdf_data, start = (/ 1 /),       &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 164 )
+          CALL handle_netcdf_error( 'netcdf', 164 )
+
 
           DEALLOCATE( netcdf_data )
@@ -1588,5 +1593,5 @@
           nc_stat = NF90_PUT_VAR( id_set_xz(av), id_var_x_xz(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 165 )
+          CALL handle_netcdf_error( 'netcdf', 165 )
 
           DO  i = 0, nx+1
@@ -1597,5 +1602,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nx+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 376 )
+          CALL handle_netcdf_error( 'netcdf', 377 )
 
           DEALLOCATE( netcdf_data )
@@ -1609,5 +1614,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nz+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 166 )
+          CALL handle_netcdf_error( 'netcdf', 166 )
 
           netcdf_data(0:nz+1) = zw(nzb:nzt+1)
@@ -1615,5 +1620,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nz+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 167 )
+          CALL handle_netcdf_error( 'netcdf', 167 )
 
           DEALLOCATE( netcdf_data )
@@ -1629,5 +1634,5 @@
           nc_stat = NF90_GET_ATT( id_set_xz(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 168 )
+          CALL handle_netcdf_error( 'netcdf', 168 )
 
           var_list = ';'
@@ -1670,14 +1675,14 @@
 !--       Get and compare the number of vertical cross sections
           nc_stat = NF90_INQ_VARID( id_set_xz(av), 'y_xz', id_var_y_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 169 )
+          CALL handle_netcdf_error( 'netcdf', 169 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_xz(av), id_var_y_xz(av), &
                                            dimids = id_dim_y_xz_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 170 )
+          CALL handle_netcdf_error( 'netcdf', 170 )
           id_dim_y_xz(av) = id_dim_y_xz_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_xz(av), id_dim_y_xz(av), &
                                             len = ns_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 171 )
+          CALL handle_netcdf_error( 'netcdf', 171 )
 
           IF ( ns /= ns_old )  THEN
@@ -1698,5 +1703,5 @@
 
           nc_stat = NF90_GET_VAR( id_set_xz(av), id_var_y_xz(av), netcdf_data )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 172 )
+          CALL handle_netcdf_error( 'netcdf', 172 )
 
           DO  i = 1, ns
@@ -1736,14 +1741,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_xz(av), 'time', id_var_time_xz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 173 )
+          CALL handle_netcdf_error( 'netcdf', 173 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_xz(av), id_var_time_xz(av), &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 174 )
+          CALL handle_netcdf_error( 'netcdf', 174 )
           id_dim_time_xz(av) = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_xz(av), id_dim_time_xz(av), &
                                             len = do2d_xz_time_count(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 175 )
+          CALL handle_netcdf_error( 'netcdf', 175 )
 
           nc_stat = NF90_GET_VAR( id_set_xz(av), id_var_time_xz(av),    &
@@ -1751,5 +1756,5 @@
                                   start = (/ do2d_xz_time_count(av) /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 176 )
+          CALL handle_netcdf_error( 'netcdf', 176 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -1777,5 +1782,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_xz(av), netcdf_var_name, &
                                           id_var_do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 177 )
+                CALL handle_netcdf_error( 'netcdf', 177 )
              ENDIF
              i = i + 1
@@ -1786,5 +1791,5 @@
           nc_stat = NF90_PUT_ATT( id_set_xz(av), NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 178 )
+          CALL handle_netcdf_error( 'netcdf', 178 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -1799,5 +1804,5 @@
           nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'Conventions', &
                                   'COARDS' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 179 )
+          CALL handle_netcdf_error( 'netcdf', 179 )
 
           IF ( av == 0 )  THEN
@@ -1810,10 +1815,10 @@
                                   TRIM( run_description_header ) //    &
                                   TRIM( time_average_text ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 180 )
+          CALL handle_netcdf_error( 'netcdf', 180 )
           IF ( av == 1 )  THEN
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval
              nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'time_avg', &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 180 )
+             CALL handle_netcdf_error( 'netcdf', 180 )
           ENDIF
 
@@ -1822,13 +1827,13 @@
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'time', NF90_UNLIMITED, &
                                   id_dim_time_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 181 )
+          CALL handle_netcdf_error( 'netcdf', 181 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'time', NF90_DOUBLE, &
                                   id_dim_time_yz(av), id_var_time_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 182 )
+          CALL handle_netcdf_error( 'netcdf', 182 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_time_yz(av), 'units', &
                                   'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 183 )
+          CALL handle_netcdf_error( 'netcdf', 183 )
 
 !
@@ -1848,26 +1853,26 @@
 !--       Define x axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'x_yz', ns, id_dim_x_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 184 )
+          CALL handle_netcdf_error( 'netcdf', 184 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'x_yz', NF90_DOUBLE, &
                                   id_dim_x_yz(av), id_var_x_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 185 )
+          CALL handle_netcdf_error( 'netcdf', 185 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_x_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 186 )
+          CALL handle_netcdf_error( 'netcdf', 186 )
 
 !
 !--       Define x axis (for u position)
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'xu_yz', ns, id_dim_xu_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 377 )
+          CALL handle_netcdf_error( 'netcdf', 377 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'xu_yz', NF90_DOUBLE, &
                                   id_dim_xu_yz(av), id_var_xu_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 378 )
+          CALL handle_netcdf_error( 'netcdf', 378 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_xu_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 379 )
+          CALL handle_netcdf_error( 'netcdf', 379 )
 
 !
@@ -1876,59 +1881,59 @@
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'ind_x_yz', NF90_DOUBLE, &
                                   id_dim_x_yz(av), id_var_ind_x_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 187 )
+          CALL handle_netcdf_error( 'netcdf', 187 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_ind_x_yz(av), 'units', &
                                   'gridpoints')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 188 )
+          CALL handle_netcdf_error( 'netcdf', 188 )
 
 !
 !--       Define y-axis (for scalar position)
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'y', ny+2, id_dim_y_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 189 )
+          CALL handle_netcdf_error( 'netcdf', 189 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'y', NF90_DOUBLE, &
                                   id_dim_y_yz(av), id_var_y_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 190 )
+          CALL handle_netcdf_error( 'netcdf', 190 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_y_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 191 )
+          CALL handle_netcdf_error( 'netcdf', 191 )
 
 !
 !--       Define y-axis (for v position)
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'yv', ny+2, id_dim_yv_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 380 )
+          CALL handle_netcdf_error( 'netcdf', 380 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'yv', NF90_DOUBLE, &
                                   id_dim_yv_yz(av), id_var_yv_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 381 )
+          CALL handle_netcdf_error( 'netcdf', 381 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_yv_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 382 )
+          CALL handle_netcdf_error( 'netcdf', 382 )
 
 !
 !--       Define the two z-axes (zu and zw)
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'zu', nz+2, id_dim_zu_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 192 )
+          CALL handle_netcdf_error( 'netcdf', 192 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'zu', NF90_DOUBLE, &
                                   id_dim_zu_yz(av), id_var_zu_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 193 )
+          CALL handle_netcdf_error( 'netcdf', 193 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_zu_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 194 )
+          CALL handle_netcdf_error( 'netcdf', 194 )
 
           nc_stat = NF90_DEF_DIM( id_set_yz(av), 'zw', nz+2, id_dim_zw_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 195 )
+          CALL handle_netcdf_error( 'netcdf', 195 )
 
           nc_stat = NF90_DEF_VAR( id_set_yz(av), 'zw', NF90_DOUBLE, &
                                   id_dim_zw_yz(av), id_var_zw_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 196 )
+          CALL handle_netcdf_error( 'netcdf', 196 )
 
           nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_zw_yz(av), 'units', &
                                   'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 197 )
+          CALL handle_netcdf_error( 'netcdf', 197 )
 
 
@@ -2020,5 +2025,5 @@
                 var_list = TRIM( var_list ) // TRIM( do2d(av,i) ) // ';'
 
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 198 )
+                CALL handle_netcdf_error( 'netcdf', 198 )
 !
 !--             Store the 'real' name of the variable (with *, for example)
@@ -2027,10 +2032,10 @@
                 nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_do2d(av,i), &
                                         'long_name', do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 199 )
+                CALL handle_netcdf_error( 'netcdf', 199 )
 !
 !--             Define the variable's unit
                 nc_stat = NF90_PUT_ATT( id_set_yz(av), id_var_do2d(av,i), &
                                         'units', TRIM( do2d_unit(av,i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 356 )
+                CALL handle_netcdf_error( 'netcdf', 356 )
              ENDIF
 
@@ -2048,10 +2053,10 @@
           nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 200 )
+          CALL handle_netcdf_error( 'netcdf', 200 )
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 201 )
+          CALL handle_netcdf_error( 'netcdf', 201 )
 
 !
@@ -2070,5 +2075,5 @@
           nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_x_yz(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 202 )
+          CALL handle_netcdf_error( 'netcdf', 202 ) 
 
 !
@@ -2083,5 +2088,5 @@
           nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_xu_yz(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 383 )
+          CALL handle_netcdf_error( 'netcdf', 383 ) 
 
 !
@@ -2091,5 +2096,5 @@
                                   netcdf_data, start = (/ 1 /),       &
                                   count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 203 )
+          CALL handle_netcdf_error( 'netcdf', 203 ) 
 
           DEALLOCATE( netcdf_data )
@@ -2105,5 +2110,5 @@
           nc_stat = NF90_PUT_VAR( id_set_yz(av), id_var_y_yz(av), netcdf_data, &
                                   start = (/ 1 /), count = (/ ny+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 204 )
+           CALL handle_netcdf_error( 'netcdf', 204 ) 
 
           DO  j = 0, ny+1
@@ -2114,5 +2119,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ ny+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 384 )
+          CALL handle_netcdf_error( 'netcdf', 384 ) 
 
           DEALLOCATE( netcdf_data )
@@ -2126,5 +2131,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nz+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 205 )
+          CALL handle_netcdf_error( 'netcdf', 205 ) 
 
           netcdf_data(0:nz+1) = zw(nzb:nzt+1)
@@ -2132,5 +2137,5 @@
                                   netcdf_data, start = (/ 1 /),    &
                                   count = (/ nz+2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 206 )
+          CALL handle_netcdf_error( 'netcdf', 206 ) 
 
           DEALLOCATE( netcdf_data )
@@ -2146,5 +2151,5 @@
           nc_stat = NF90_GET_ATT( id_set_yz(av), NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 207 )
+          CALL handle_netcdf_error( 'netcdf', 207 )
 
           var_list = ';'
@@ -2187,14 +2192,14 @@
 !--       Get and compare the number of vertical cross sections
           nc_stat = NF90_INQ_VARID( id_set_yz(av), 'x_yz', id_var_x_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 208 )
+          CALL handle_netcdf_error( 'netcdf', 208 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_yz(av), id_var_x_yz(av), &
                                            dimids = id_dim_x_yz_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 209 )
+          CALL handle_netcdf_error( 'netcdf', 209 )
           id_dim_x_yz(av) = id_dim_x_yz_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_yz(av), id_dim_x_yz(av), &
                                             len = ns_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 210 )
+          CALL handle_netcdf_error( 'netcdf', 210 )
 
           IF ( ns /= ns_old )  THEN
@@ -2215,5 +2220,5 @@
 
           nc_stat = NF90_GET_VAR( id_set_yz(av), id_var_x_yz(av), netcdf_data )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 211 )
+          CALL handle_netcdf_error( 'netcdf', 211 )
 
           DO  i = 1, ns
@@ -2253,14 +2258,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_yz(av), 'time', id_var_time_yz(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 212 )
+          CALL handle_netcdf_error( 'netcdf', 212 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_yz(av), id_var_time_yz(av), &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 213 )
+          CALL handle_netcdf_error( 'netcdf', 213 )
           id_dim_time_yz(av) = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_yz(av), id_dim_time_yz(av), &
                                             len = do2d_yz_time_count(av) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 214 )
+          CALL handle_netcdf_error( 'netcdf', 214 )
 
           nc_stat = NF90_GET_VAR( id_set_yz(av), id_var_time_yz(av),    &
@@ -2268,5 +2273,5 @@
                                   start = (/ do2d_yz_time_count(av) /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 215 )
+          CALL handle_netcdf_error( 'netcdf', 215 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -2294,5 +2299,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_yz(av), netcdf_var_name, &
                                           id_var_do2d(av,i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 216 )
+                CALL handle_netcdf_error( 'netcdf', 216 )
              ENDIF
              i = i + 1
@@ -2303,5 +2308,5 @@
           nc_stat = NF90_PUT_ATT( id_set_yz(av), NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 217 )
+          CALL handle_netcdf_error( 'netcdf', 217 )
           message_string = 'NetCDF file for cross-sections ' //           & 
                             TRIM( var ) // ' from previous run found.' // &
@@ -2320,5 +2325,5 @@
                                      TRIM( run_description_header ) //  &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 218 )
+             CALL handle_netcdf_error( 'netcdf', 218 )
 
              WRITE ( time_average_text,'(F7.1,'' s avg'')' ) averaging_interval_pr
@@ -2329,5 +2334,5 @@
                                      TRIM( run_description_header ) )
           ENDIF
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 219 )
+          CALL handle_netcdf_error( 'netcdf', 219 )
 
 !
@@ -2335,12 +2340,12 @@
           nc_stat = NF90_DEF_DIM( id_set_pr, 'time', NF90_UNLIMITED, &
                                   id_dim_time_pr )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 220 )
+          CALL handle_netcdf_error( 'netcdf', 220 )
 
           nc_stat = NF90_DEF_VAR( id_set_pr, 'time', NF90_DOUBLE, &
                                   id_dim_time_pr, id_var_time_pr )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 221 )
+          CALL handle_netcdf_error( 'netcdf', 221 )
 
           nc_stat = NF90_PUT_ATT( id_set_pr, id_var_time_pr, 'units', 'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 222 )
+          CALL handle_netcdf_error( 'netcdf', 222 )
 
 !
@@ -2359,15 +2364,14 @@
                 nc_stat = NF90_DEF_DIM( id_set_pr, 'z'//TRIM(netcdf_var_name), &
                                         nzt+2-nzb, id_dim_z_pr(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 223 )
+                CALL handle_netcdf_error( 'netcdf', 223 )
 
                 nc_stat = NF90_DEF_VAR( id_set_pr, 'z'//TRIM(netcdf_var_name), &
                                         NF90_DOUBLE, id_dim_z_pr(i,0),         &
                                         id_var_z_pr(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 224 )
+                CALL handle_netcdf_error( 'netcdf', 224 )
 
                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_z_pr(i,0), 'units', &
                                         'meters' )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 225 )
-
+                CALL handle_netcdf_error( 'netcdf', 225 )
 !
 !--             Define the variable
@@ -2375,13 +2379,13 @@
                                         nc_precision(5), (/ id_dim_z_pr(i,0), &
                                         id_dim_time_pr /), id_var_dopr(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 226 )
+                CALL handle_netcdf_error( 'netcdf', 226 )
 
                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,0), &
                                         'long_name', TRIM( data_output_pr(i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 227 )
+                CALL handle_netcdf_error( 'netcdf', 227 )
 
                 nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,0), &
                                         'units', TRIM( dopr_unit(i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 228 )
+                CALL handle_netcdf_error( 'netcdf', 228 )
 
                 var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
@@ -2399,5 +2403,5 @@
                                            'z'//TRIM(netcdf_var_name)//suffix, &
                                            nzt+2-nzb, id_dim_z_pr(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 229 )
+                   CALL handle_netcdf_error( 'netcdf', 229 )
 
                    nc_stat = NF90_DEF_VAR( id_set_pr,                          &
@@ -2405,9 +2409,9 @@
                                            nc_precision(5), id_dim_z_pr(i,j),  &
                                            id_var_z_pr(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 230 )
+                   CALL handle_netcdf_error( 'netcdf', 230 )
 
                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_z_pr(i,j), &
                                            'units', 'meters' )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 231 )
+                   CALL handle_netcdf_error( 'netcdf', 231 )
 
 !
@@ -2418,5 +2422,5 @@
                                            (/ id_dim_z_pr(i,j),               &
                                            id_dim_time_pr /), id_var_dopr(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 232 )
+                   CALL handle_netcdf_error( 'netcdf', 232 )
 
                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,j),        &
@@ -2424,9 +2428,9 @@
                                            TRIM( data_output_pr(i) ) // ' SR ' &
                                            // suffix(2:2) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 233 )
+                   CALL handle_netcdf_error( 'netcdf', 233 )
 
                    nc_stat = NF90_PUT_ATT( id_set_pr, id_var_dopr(i,j), &
                                            'units', TRIM( dopr_unit(i) ) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 234 )
+                   CALL handle_netcdf_error( 'netcdf', 234 )
 
                    var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
@@ -2443,5 +2447,5 @@
 !--       restart runs)
           nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'VAR_LIST', var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 235 )
+          CALL handle_netcdf_error( 'netcdf', 235 )
 
 !
@@ -2453,10 +2457,10 @@
                                      nc_precision(5), (/ id_dim_time_pr /), &
                                      id_var_norm_dopr(i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 236 )
+             CALL handle_netcdf_error( 'netcdf', 236 )
 
              nc_stat = NF90_PUT_ATT( id_set_pr, id_var_norm_dopr(i), &
                                      'long_name',                    &
                                      TRIM( dopr_norm_longnames(i) ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 237 )
+             CALL handle_netcdf_error( 'netcdf', 237 )
 
           ENDDO
@@ -2465,5 +2469,5 @@
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_pr )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 238 )
+          CALL handle_netcdf_error( 'netcdf', 238 )
 
 !
@@ -2476,5 +2480,5 @@
                                         start = (/ 1 /),                  &
                                         count = (/ nzt-nzb+2 /) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 239 )
+                CALL handle_netcdf_error( 'netcdf', 239 )
 
              ENDDO
@@ -2491,5 +2495,5 @@
           nc_stat = NF90_GET_ATT( id_set_pr, NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 240 )
+          CALL handle_netcdf_error( 'netcdf', 240 )
 
           var_list = ';'
@@ -2528,14 +2532,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_pr, 'time', id_var_time_pr )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 241 )
+          CALL handle_netcdf_error( 'netcdf', 241 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_pr, id_var_time_pr, &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 242 )
+          CALL handle_netcdf_error( 'netcdf', 242 )
           id_dim_time_pr = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_pr, id_dim_time_pr, &
                                             len = dopr_time_count )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 243 )
+          CALL handle_netcdf_error( 'netcdf', 243 )
 
           nc_stat = NF90_GET_VAR( id_set_pr, id_var_time_pr,        &
@@ -2543,5 +2547,5 @@
                                   start = (/ dopr_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 244 )
+          CALL handle_netcdf_error( 'netcdf', 244 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -2571,5 +2575,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_pr, netcdf_var_name_base, &
                                           id_var_dopr(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 245 )
+                CALL handle_netcdf_error( 'netcdf', 245 )
              ELSE
                 DO  j = 0, statistic_regions
@@ -2578,5 +2582,5 @@
                    nc_stat = NF90_INQ_VARID( id_set_pr, netcdf_var_name, &
                                              id_var_dopr(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 246 )
+                   CALL handle_netcdf_error( 'netcdf', 246 )
                 ENDDO
              ENDIF
@@ -2590,5 +2594,5 @@
                                        'NORM_' // TRIM( dopr_norm_names(i) ), &
                                        id_var_norm_dopr(i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 247 )
+             CALL handle_netcdf_error( 'netcdf', 247 )
           ENDDO
 
@@ -2597,5 +2601,5 @@
           nc_stat = NF90_PUT_ATT( id_set_pr, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 248 )
+          CALL handle_netcdf_error( 'netcdf', 248 )
           message_string = 'NetCDF file for vertical profiles ' // & 
                            'from previous run found.' //           &
@@ -2610,5 +2614,5 @@
           nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 249 )
+          CALL handle_netcdf_error( 'netcdf', 249 )
 
 !
@@ -2616,12 +2620,12 @@
           nc_stat = NF90_DEF_DIM( id_set_ts, 'time', NF90_UNLIMITED, &
                                   id_dim_time_ts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 250 )
+          CALL handle_netcdf_error( 'netcdf', 250 )
 
           nc_stat = NF90_DEF_VAR( id_set_ts, 'time', NF90_DOUBLE, &
                                   id_dim_time_ts, id_var_time_ts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 251 )
+          CALL handle_netcdf_error( 'netcdf', 251 )
 
           nc_stat = NF90_PUT_ATT( id_set_ts, id_var_time_ts, 'units', 'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 252 )
+          CALL handle_netcdf_error( 'netcdf', 252 )
 
 !
@@ -2639,13 +2643,13 @@
                                         nc_precision(6), (/ id_dim_time_ts /), &
                                         id_var_dots(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 253 )
+                CALL handle_netcdf_error( 'netcdf', 253 )
 
                 nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,0), &
                                         'long_name', TRIM( dots_label(i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 254 )
+                CALL handle_netcdf_error( 'netcdf', 254 )
 
                 nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,0), &
                                         'units', TRIM( dots_unit(i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 255 )
+                CALL handle_netcdf_error( 'netcdf', 255 )
 
                 var_list = TRIM(var_list) // TRIM(netcdf_var_name) // ';'
@@ -2663,5 +2667,5 @@
                                            (/ id_dim_time_ts /),              &
                                            id_var_dots(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 256 )
+                   CALL handle_netcdf_error( 'netcdf', 256 )
 
                    nc_stat = NF90_PUT_ATT( id_set_ts, id_var_dots(i,j),       &
@@ -2669,5 +2673,5 @@
                                            TRIM( dots_label(i) ) // ' SR ' // &
                                            suffix(2:2) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 257 )
+                   CALL handle_netcdf_error( 'netcdf', 257 )
 
                    var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
@@ -2684,10 +2688,10 @@
 !--       restart runs)
           nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'VAR_LIST', var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 258 )
+          CALL handle_netcdf_error( 'netcdf', 258 )
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_ts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 259 )
+          CALL handle_netcdf_error( 'netcdf', 259 )
 
 
@@ -2701,5 +2705,5 @@
           nc_stat = NF90_GET_ATT( id_set_ts, NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 260 )
+          CALL handle_netcdf_error( 'netcdf', 260 )
 
           var_list = ';'
@@ -2739,14 +2743,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_ts, 'time', id_var_time_ts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 261 )
+          CALL handle_netcdf_error( 'netcdf', 261 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_ts, id_var_time_ts, &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 262 )
+          CALL handle_netcdf_error( 'netcdf', 262 )
           id_dim_time_ts = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_ts, id_dim_time_ts, &
                                             len = dots_time_count )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 263 )
+          CALL handle_netcdf_error( 'netcdf', 263 )
 
           nc_stat = NF90_GET_VAR( id_set_ts, id_var_time_ts,        &
@@ -2754,5 +2758,5 @@
                                   start = (/ dots_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 264 )
+          CALL handle_netcdf_error( 'netcdf', 264 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -2782,5 +2786,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_ts, netcdf_var_name_base, &
                                           id_var_dots(i,0) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 265 )
+                CALL handle_netcdf_error( 'netcdf', 265 )
              ELSE
                 DO  j = 0, statistic_regions
@@ -2789,5 +2793,5 @@
                    nc_stat = NF90_INQ_VARID( id_set_ts, netcdf_var_name, &
                                              id_var_dots(i,j) )
-                   IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 266 )
+                   CALL handle_netcdf_error( 'netcdf', 266 )
                 ENDDO
              ENDIF
@@ -2799,5 +2803,5 @@
           nc_stat = NF90_PUT_ATT( id_set_ts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 267 )
+          CALL handle_netcdf_error( 'netcdf', 267 )
           message_string = 'NetCDF file for time series ' // & 
                            'from previous run found.' //     &
@@ -2816,5 +2820,5 @@
                                      TRIM( run_description_header ) // &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 268 )
+             CALL handle_netcdf_error( 'netcdf', 268 )
 
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_sp
@@ -2825,5 +2829,5 @@
                                      TRIM( run_description_header ) )
           ENDIF
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 269 )
+          CALL handle_netcdf_error( 'netcdf', 269 )
 
 !
@@ -2831,12 +2835,12 @@
           nc_stat = NF90_DEF_DIM( id_set_sp, 'time', NF90_UNLIMITED, &
                                   id_dim_time_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 270 )
+          CALL handle_netcdf_error( 'netcdf', 270 )
 
           nc_stat = NF90_DEF_VAR( id_set_sp, 'time', NF90_DOUBLE, &
                                   id_dim_time_sp, id_var_time_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 271 )
+          CALL handle_netcdf_error( 'netcdf', 271 )
 
           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_time_sp, 'units', 'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 272 )
+          CALL handle_netcdf_error( 'netcdf', 272 )
 
 !
@@ -2853,48 +2857,48 @@
 !--       Define vertical coordinate grid (zu grid)
           nc_stat = NF90_DEF_DIM( id_set_sp, 'zu_sp', ns, id_dim_zu_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 273 )
+          CALL handle_netcdf_error( 'netcdf', 273 )
 
           nc_stat = NF90_DEF_VAR( id_set_sp, 'zu_sp', NF90_DOUBLE, &
                                   id_dim_zu_sp, id_var_zu_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 274 )
+          CALL handle_netcdf_error( 'netcdf', 274 )
 
           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_zu_sp, 'units', 'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 275 )
+          CALL handle_netcdf_error( 'netcdf', 275 )
 
 !
 !--       Define vertical coordinate grid (zw grid)
           nc_stat = NF90_DEF_DIM( id_set_sp, 'zw_sp', ns, id_dim_zw_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 276 )
+          CALL handle_netcdf_error( 'netcdf', 276 )
 
           nc_stat = NF90_DEF_VAR( id_set_sp, 'zw_sp', NF90_DOUBLE, &
                                   id_dim_zw_sp, id_var_zw_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 277 )
+          CALL handle_netcdf_error( 'netcdf', 277 )
 
           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_zw_sp, 'units', 'meters' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 278 )
+          CALL handle_netcdf_error( 'netcdf', 278 )
 
 !
 !--       Define x-axis
           nc_stat = NF90_DEF_DIM( id_set_sp, 'k_x', nx/2, id_dim_x_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 279 )
+          CALL handle_netcdf_error( 'netcdf', 279 )
 
           nc_stat = NF90_DEF_VAR( id_set_sp, 'k_x', NF90_DOUBLE, id_dim_x_sp, &
                                   id_var_x_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 280 )
+          CALL handle_netcdf_error( 'netcdf', 280 )
 
           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_x_sp, 'units', 'm-1' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 281 )
+          CALL handle_netcdf_error( 'netcdf', 281 )
 
 !
 !--       Define y-axis
           nc_stat = NF90_DEF_DIM( id_set_sp, 'k_y', ny/2, id_dim_y_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 282 )
+          CALL handle_netcdf_error( 'netcdf', 282 )
 
           nc_stat = NF90_DEF_VAR( id_set_sp, 'k_y', NF90_DOUBLE, id_dim_y_sp, &
                                   id_var_y_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 283 )
+          CALL handle_netcdf_error( 'netcdf', 283 )
 
           nc_stat = NF90_PUT_ATT( id_set_sp, id_var_y_sp, 'units', 'm-1' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 284 )
+          CALL handle_netcdf_error( 'netcdf', 284 )
 
 !
@@ -2945,13 +2949,13 @@
                                            id_var_dospx(i) )
                 ENDIF
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 285 )
+                CALL handle_netcdf_error( 'netcdf', 285 )
 
                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospx(i), &
                                         'long_name', netcdf_var_name )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 286 )
+                CALL handle_netcdf_error( 'netcdf', 286 )
 
                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospx(i), &
                                         'units', 'unknown' )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 287 )
+                CALL handle_netcdf_error( 'netcdf', 287 )
 
                 var_list = TRIM( var_list ) // TRIM( netcdf_var_name ) // ';'
@@ -2976,13 +2980,13 @@
                                            id_var_dospy(i) )
                 ENDIF
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 288 )
+                CALL handle_netcdf_error( 'netcdf', 288 )
 
                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospy(i), &
                                         'long_name', netcdf_var_name )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 289 )
+                CALL handle_netcdf_error( 'netcdf', 289 )
 
                 nc_stat = NF90_PUT_ATT( id_set_sp, id_var_dospy(i), &
                                         'units', 'unknown' )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 290 )
+                CALL handle_netcdf_error( 'netcdf', 290 )
 
                 var_list = TRIM( var_list ) // TRIM( netcdf_var_name ) // ';'
@@ -2998,10 +3002,10 @@
 !--       restart runs)
           nc_stat = NF90_PUT_ATT( id_set_sp, NF90_GLOBAL, 'VAR_LIST', var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 291 )
+          CALL handle_netcdf_error( 'netcdf', 291 )
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 292 )
+          CALL handle_netcdf_error( 'netcdf', 292 )
 
 !
@@ -3014,5 +3018,5 @@
           nc_stat = NF90_PUT_VAR( id_set_sp, id_var_zu_sp, netcdf_data, &
                                   start = (/ 1 /), count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 293 )
+          CALL handle_netcdf_error( 'netcdf', 293 )
 
 !
@@ -3021,5 +3025,5 @@
           nc_stat = NF90_PUT_VAR( id_set_sp, id_var_zw_sp, netcdf_data, &
                                   start = (/ 1 /), count = (/ ns /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 294 )
+          CALL handle_netcdf_error( 'netcdf', 294 )
 
           DEALLOCATE( netcdf_data )
@@ -3034,5 +3038,5 @@
           nc_stat = NF90_PUT_VAR( id_set_sp, id_var_x_sp, netcdf_data, &
                                   start = (/ 1 /), count = (/ nx/2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 295 )
+          CALL handle_netcdf_error( 'netcdf', 295 )
 
           DEALLOCATE( netcdf_data )
@@ -3045,5 +3049,5 @@
           nc_stat = NF90_PUT_VAR( id_set_sp, id_var_y_sp, netcdf_data, &
                                   start = (/ 1 /), count = (/ ny/2 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 296 )
+          CALL handle_netcdf_error( 'netcdf', 296 )
 
           DEALLOCATE( netcdf_data )
@@ -3059,6 +3063,5 @@
           nc_stat = NF90_GET_ATT( id_set_sp, NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 297 )
-
+          CALL handle_netcdf_error( 'netcdf', 297 )
           var_list = ';'
           i = 1
@@ -3102,14 +3105,14 @@
 !--       Get and compare the number of vertical levels
           nc_stat = NF90_INQ_VARID( id_set_sp, 'zu_sp', id_var_zu_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 298 )
+          CALL handle_netcdf_error( 'netcdf', 298 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_sp, id_var_zu_sp, &
                                            dimids = id_dim_zu_sp_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 299 )
+          CALL handle_netcdf_error( 'netcdf', 299 )
           id_dim_zu_sp = id_dim_zu_sp_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_sp, id_dim_zu_sp, &
                                             len = ns_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 300 )
+          CALL handle_netcdf_error( 'netcdf', 300 )
 
           IF ( ns /= ns_old )  THEN
@@ -3130,5 +3133,5 @@
 
           nc_stat = NF90_GET_VAR( id_set_sp, id_var_zu_sp, netcdf_data )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 301 )
+          CALL handle_netcdf_error( 'netcdf', 301 )
 
           DO  i = 1, ns
@@ -3154,14 +3157,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_sp, 'time', id_var_time_sp )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 302 )
+          CALL handle_netcdf_error( 'netcdf', 302 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_sp, id_var_time_sp, &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 303 )
+          CALL handle_netcdf_error( 'netcdf', 303 )
           id_dim_time_sp = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_sp, id_dim_time_sp, &
                                             len = dosp_time_count )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 304 )
+          CALL handle_netcdf_error( 'netcdf', 304 )
 
           nc_stat = NF90_GET_VAR( id_set_sp, id_var_time_sp,        &
@@ -3169,5 +3172,5 @@
                                   start = (/ dosp_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 305 )
+          CALL handle_netcdf_error( 'netcdf', 305 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -3195,5 +3198,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_sp, netcdf_var_name, &
                                           id_var_dospx(i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 306 )
+                CALL handle_netcdf_error( 'netcdf', 306 )
              ENDIF
 
@@ -3202,5 +3205,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_sp, netcdf_var_name, &
                                           id_var_dospy(i) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 307 )
+                CALL handle_netcdf_error( 'netcdf', 307 )
              ENDIF
 
@@ -3217,5 +3220,5 @@
                                      TRIM( run_description_header ) // &
                                      TRIM( time_average_text ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 308 )
+             CALL handle_netcdf_error( 'netcdf', 308 )
 
              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_sp
@@ -3226,5 +3229,5 @@
                                      TRIM( run_description_header ) )
           ENDIF
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 309 )
+          CALL handle_netcdf_error( 'netcdf', 309 )
           message_string = 'NetCDF file for spectra ' //     & 
                            'from previous run found.' //     &
@@ -3239,5 +3242,5 @@
           nc_stat = NF90_PUT_ATT( id_set_prt, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 310 )
+          CALL handle_netcdf_error( 'netcdf', 310 )
 
 !
@@ -3245,13 +3248,13 @@
           nc_stat = NF90_DEF_DIM( id_set_prt, 'time', NF90_UNLIMITED, &
                                   id_dim_time_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 311 )
+          CALL handle_netcdf_error( 'netcdf', 311 )
 
           nc_stat = NF90_DEF_VAR( id_set_prt, 'time', NF90_DOUBLE, &
                                   id_dim_time_prt, id_var_time_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 312 )
+          CALL handle_netcdf_error( 'netcdf', 312 )
 
           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_time_prt, 'units', &
                                   'seconds' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 313 )
+          CALL handle_netcdf_error( 'netcdf', 313 )
 
 !
@@ -3259,13 +3262,13 @@
           nc_stat = NF90_DEF_DIM( id_set_prt, 'particle_number', &
                                   maximum_number_of_particles, id_dim_prtnum )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 314 )
+          CALL handle_netcdf_error( 'netcdf', 314 )
 
           nc_stat = NF90_DEF_VAR( id_set_prt, 'particle_number', NF90_DOUBLE, &
                                   id_dim_prtnum, id_var_prtnum )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 315 )
+          CALL handle_netcdf_error( 'netcdf', 315 )
 
           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prtnum, 'units', &
                                   'particle number' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 316 )
+          CALL handle_netcdf_error( 'netcdf', 316 )
 
 !
@@ -3273,9 +3276,9 @@
           nc_stat = NF90_DEF_VAR( id_set_prt, 'real_num_of_prt', NF90_INT, &
                                   id_dim_time_prt, id_var_rnop_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 317 )
+          CALL handle_netcdf_error( 'netcdf', 317 )
 
           nc_stat = NF90_PUT_ATT( id_set_prt, id_var_rnop_prt, 'units', &
                                   'particle number' )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 318 )
+          CALL handle_netcdf_error( 'netcdf', 318 )
 
 !
@@ -3287,13 +3290,13 @@
                                      (/ id_dim_prtnum, id_dim_time_prt /), &
                                      id_var_prt(i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 319 )
+             CALL handle_netcdf_error( 'netcdf', 319 )
 
              nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prt(i), &
                                      'long_name', TRIM( prt_var_names(i) ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 320 )
+             CALL handle_netcdf_error( 'netcdf', 320 )
 
              nc_stat = NF90_PUT_ATT( id_set_prt, id_var_prt(i), &
                                      'units', TRIM( prt_var_units(i) ) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 321 )
+             CALL handle_netcdf_error( 'netcdf', 321 )
 
           ENDDO
@@ -3302,5 +3305,5 @@
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 322 )
+          CALL handle_netcdf_error( 'netcdf', 322 )
 
 
@@ -3313,14 +3316,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_prt, 'time', id_var_time_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 323 )
+          CALL handle_netcdf_error( 'netcdf', 323 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_prt, id_var_time_prt, &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 324 )
+          CALL handle_netcdf_error( 'netcdf', 324 )
           id_dim_time_prt = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_prt, id_dim_time_prt, &
                                             len = prt_time_count )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 325 )
+          CALL handle_netcdf_error( 'netcdf', 325 )
 
           nc_stat = NF90_GET_VAR( id_set_prt, id_var_time_prt,  &
@@ -3328,5 +3331,5 @@
                                   start = (/ prt_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 326 )
+          CALL handle_netcdf_error( 'netcdf', 326 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -3349,5 +3352,5 @@
           nc_stat = NF90_INQ_VARID( id_set_prt, 'real_num_of_prt', &
                                     id_var_rnop_prt )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 327 )
+          CALL handle_netcdf_error( 'netcdf', 327 )
 
           DO  i = 1, 17
@@ -3355,5 +3358,5 @@
              nc_stat = NF90_INQ_VARID( id_set_prt, prt_var_names(i), &
                                        id_var_prt(i) )
-             IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 328 )
+             CALL handle_netcdf_error( 'netcdf', 328 )
 
           ENDDO
@@ -3372,5 +3375,5 @@
           nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 396 )
+          CALL handle_netcdf_error( 'netcdf', 396 )
 
 !
@@ -3378,13 +3381,13 @@
           nc_stat = NF90_DEF_DIM( id_set_pts, 'time', NF90_UNLIMITED, &
                                   id_dim_time_pts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 397 )
+          CALL handle_netcdf_error( 'netcdf', 397 )
 
           nc_stat = NF90_DEF_VAR( id_set_pts, 'time', NF90_DOUBLE, &
                                   id_dim_time_pts, id_var_time_pts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 398 )
+          CALL handle_netcdf_error( 'netcdf', 398 )
 
           nc_stat = NF90_PUT_ATT( id_set_pts, id_var_time_pts, 'units', &
                                   'seconds')
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 399 )
+          CALL handle_netcdf_error( 'netcdf', 399 )
 
 !
@@ -3412,5 +3415,5 @@
                                         (/ id_dim_time_pts /),              &
                                         id_var_dopts(i,j) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 400 )
+                CALL handle_netcdf_error( 'netcdf', 400 )
 
                 IF ( j == 0 )  THEN
@@ -3424,9 +3427,9 @@
                                            suffix1(2:3) )
                 ENDIF
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 401 )
+                CALL handle_netcdf_error( 'netcdf', 401 )
 
                 nc_stat = NF90_PUT_ATT( id_set_pts, id_var_dopts(i,j), &
                                         'units', TRIM( dopts_unit(i) ) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 402 )
+                CALL handle_netcdf_error( 'netcdf', 402 )
 
                 var_list = TRIM(var_list) // TRIM(netcdf_var_name) // &
@@ -3444,10 +3447,11 @@
           nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'VAR_LIST', &
                                   var_list )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 403 )
+          CALL handle_netcdf_error( 'netcdf', 403 )
+
 
 !
 !--       Leave NetCDF define mode
           nc_stat = NF90_ENDDEF( id_set_pts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 404 )
+          CALL handle_netcdf_error( 'netcdf', 404 )
 
 
@@ -3461,5 +3465,5 @@
           nc_stat = NF90_GET_ATT( id_set_pts, NF90_GLOBAL, 'VAR_LIST', &
                                   var_list_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 405 )
+          CALL handle_netcdf_error( 'netcdf', 405 )
 
           var_list = ';'
@@ -3504,14 +3508,14 @@
 !--       on the file.
           nc_stat = NF90_INQ_VARID( id_set_pts, 'time', id_var_time_pts )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 406 )
+          CALL handle_netcdf_error( 'netcdf', 406 )
 
           nc_stat = NF90_INQUIRE_VARIABLE( id_set_pts, id_var_time_pts, &
                                            dimids = id_dim_time_old )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 407 )
+          CALL handle_netcdf_error( 'netcdf', 407 )
           id_dim_time_pts = id_dim_time_old(1)
 
           nc_stat = NF90_INQUIRE_DIMENSION( id_set_pts, id_dim_time_pts, &
                                             len = dopts_time_count )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 408 )
+          CALL handle_netcdf_error( 'netcdf', 408 )
 
           nc_stat = NF90_GET_VAR( id_set_pts, id_var_time_pts,    &
@@ -3519,5 +3523,5 @@
                                   start = (/ dopts_time_count /), &
                                   count = (/ 1 /) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 409 )
+          CALL handle_netcdf_error( 'netcdf', 409 )
 
           IF ( last_time_coordinate(1) >= simulated_time )  THEN
@@ -3556,5 +3560,5 @@
                 nc_stat = NF90_INQ_VARID( id_set_pts, netcdf_var_name, &
                                           id_var_dopts(i,j) )
-                IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 410 )
+                CALL handle_netcdf_error( 'netcdf', 410 )
 
                 IF ( number_of_particle_groups == 1 )  EXIT
@@ -3568,5 +3572,5 @@
           nc_stat = NF90_PUT_ATT( id_set_pts, NF90_GLOBAL, 'title', &
                                   TRIM( run_description_header ) )
-          IF ( nc_stat /= NF90_NOERR )  CALL handle_netcdf_error( 411 )
+          CALL handle_netcdf_error( 'netcdf', 411 )
           message_string = 'NetCDF file for particle time series ' // & 
                            'from previous run found.' //              &
@@ -3586,6 +3590,5 @@
 
 
-
- SUBROUTINE handle_netcdf_error( errno )
+SUBROUTINE handle_netcdf_error( routine_name, errno )
 #if defined( __netcdf )
 
@@ -3597,4 +3600,5 @@
 !------------------------------------------------------------------------------!
 
+    USE control_parameters
     USE netcdf
     USE netcdf_control
@@ -3603,13 +3607,16 @@
     IMPLICIT NONE
 
+    CHARACTER(LEN=6) ::  message_identifier
+    CHARACTER(LEN=*) ::  routine_name
+
     INTEGER ::  errno
 
     IF ( nc_stat /= NF90_NOERR )  THEN
-       PRINT*, '+++ netcdf error ', errno,': ', TRIM( NF90_STRERROR( nc_stat ) )
-#if defined( __parallel )
-       CALL MPI_ABORT( comm2d, 9999, ierr )
-#else
-       CALL local_stop
-#endif
+
+       WRITE( message_identifier, '(''NC'',I4.4)' )  errno
+       message_string = TRIM( NF90_STRERROR( nc_stat ) )
+
+       CALL message( routine_name, message_identifier, 2, 2, 0, 6, 0 )
+
     ENDIF
 
