LST_global_write_VOLMSK_surfrxnt.F90 19.2 KB
Newer Older
Femi Kadri's avatar
Femi Kadri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
SUBROUTINE LST_global_write_VOLMSK_surfrxnt(LST_local_fluid_surf_rxn_t_count,LST_time_increment_phys_units,&
& My_MPI_Process_ID,ROOT,local_x_min_ghost,local_x_max_ghost,local_y_min_ghost,&
& local_y_max_ghost,local_z_min_ghost,local_z_max_ghost,local_x_min_real,local_x_max_real,local_y_min_real,&
& local_y_max_real,local_z_min_real,local_z_max_real,local_product_xyz_nodes_real,all_processes_local_bounds,&
& global_x_nodes_real,global_y_nodes_real,global_z_nodes_real,LST_local_fluid_surf_rxn_count,&
& Number_Of_Processes,cartesian_communicator,lattice_dimension,LST_local_vol_of_int_user_mask)

!SURFACE COLLISION TIME IS SUM OF TIMES AT WHICH COLLUSIONS OCCURED AT EVERY SURFACE NODE
!DIVIDED BY TOTAL NUMBER OF COLLISIONS AT THAT SURFACE NODE


USE debug_module
USE precision_detector

	!THIS SUBROUTINE WILL GATHER A 3D ARRAY IN ALL THREE DIMENSIONS FROM ALL THE MPI PROCESSES TO ROOT, WHO IN TURN WILL WRITE THEM TO A FILE IN ORDER RECEIVED
	IMPLICIT NONE
	INCLUDE "mpif.h"

	!-----------INTENT(IN)------------------------------------------		
	INTEGER,INTENT(IN) :: My_MPI_Process_ID,ROOT,Number_Of_Processes,cartesian_communicator
	INTEGER,INTENT(IN) :: local_x_min_ghost,local_x_max_ghost,local_y_min_ghost,local_y_max_ghost,local_z_min_ghost,local_z_max_ghost
	INTEGER,INTENT(IN) :: local_x_min_real,local_x_max_real,local_y_min_real,local_y_max_real,local_z_min_real,local_z_max_real
	INTEGER,INTENT(IN) :: local_product_xyz_nodes_real,lattice_dimension
	INTEGER,INTENT(IN) :: global_x_nodes_real,global_y_nodes_real,global_z_nodes_real
	REAL,INTENT(IN) :: LST_time_increment_phys_units
	INTEGER,INTENT(IN),DIMENSION(6 * Number_Of_Processes) :: all_processes_local_bounds
	INTEGER,INTENT(IN),DIMENSION(local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,&
	& local_z_min_ghost:local_z_max_ghost) :: LST_local_fluid_surf_rxn_t_count,LST_local_fluid_surf_rxn_count

	LOGICAL*4,INTENT(IN),DIMENSION(local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,&
	& local_z_min_ghost:local_z_max_ghost) :: LST_local_vol_of_int_user_mask

	LOGICAL*4,PARAMETER :: debug = GLOBAL_DEBUG
	!-----------INTENT(OUT)------------------------------------------
	!-----------INTENT(INOUT)------------------------------------------	
	!-----------NO INTENT------------------------------------------
	!LOGICAL*4,PARAMETER :: debug = .true.
	INTEGER :: I,J,K,index,SOURCE,mpi_error_code,send_size_integer,MPI_Process_Number,counter,send_size_real
	INTEGER :: destination
	INTEGER :: mpi_abort_error
	INTEGER,PARAMETER :: IJK_communication_tag = 6789
	INTEGER,PARAMETER :: surf_rxn_time_count_comm_tag = 9876
	INTEGER,PARAMETER :: surf_rxn_count_communication_tag = 9678
	INTEGER,PARAMETER :: VOLMSK_logical_comm_tag = 2828

	INTEGER,DIMENSION(0:Number_Of_Processes-1) :: root_receive_counts_integer,root_receive_counts_array
	INTEGER,ALLOCATABLE,DIMENSION(:) :: local_integer_send_buffer,local_integer_recv_buffer
	INTEGER,ALLOCATABLE,DIMENSION(:) :: local_surf_rxn_t_count_send_bufr,local_surf_rxn_t_count_recv_bufr
	INTEGER,ALLOCATABLE,DIMENSION(:) :: local_surf_rxn_count_send_buffer,local_surf_rxn_count_recv_buffer		

	LOGICAL*4,ALLOCATABLE,DIMENSION(:) :: local_VOLMSK_logical_send_bufr,local_VOLMSK_logical_recv_bufr		


	
	INTEGER :: status (MPI_STATUS_SIZE)

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'entered SUBROUTINE LST_global_write_VOLMSK_surfrxnt'

	!my_mpi_real_data_type = get_my_mpi_real_data_type ()  !FUNNEL OUT THE RESULT OF PRECISION TESTING (this automatically sets the MPI REAL DATA PRECISION TYPE)
	

	!ROOT OPENS THE FILE
	IF (My_MPI_Process_ID.EQ.ROOT) THEN 
	IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to write array values from ROOT'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to write array values from ROOT'
		
		OPEN (84, FILE = 'results_LST/LST_global_VOL_MASK_fluid_surf_avg_collision_time.txt', STATUS = 'unknown', FORM='formatted')  
		WRITE(84,*) 'VARIABLES = "X [cm]", "Y [cm]", "Z [cm]", "avg collision time [s]"'
		WRITE(84,*) 'ZONE,i=',global_x_nodes_real,',j=',global_y_nodes_real,',k=',global_z_nodes_real,',F=POINT'

		!ROOT WRITES ITS OWN VALUES
		
		DO K = local_z_min_real,local_z_max_real	

			DO J = local_y_min_real,local_y_max_real

				DO I = local_x_min_real,local_x_max_real

					IF(LST_local_fluid_surf_rxn_count(I,J,K).GT.0) THEN


						IF(LST_local_vol_of_int_user_mask(I,J,K)) THEN
									
							WRITE(84,'(3I6.5,E19.10)') I,J,K,&
							& ( REAL(LST_local_fluid_surf_rxn_t_count(I,J,K)) &
							& / REAL(LST_local_fluid_surf_rxn_count(I,J,K)) ) &
							& * LST_time_increment_phys_units

						ELSE !.NOT.LST_local_vol_of_int_user_mask(I,J,K)

							WRITE(84,'(3I6.5,E19.10)') I,J,K,&
							& -1.0D0 !(MINUS ONE STANDS FOR INFINITE TIME)

						ENDIF !!LST_local_vol_of_int_user_mask(I,J,K)

					ELSEIF(LST_local_fluid_surf_rxn_count(I,J,K).EQ.0) THEN

						WRITE(84,'(3I6.5,E19.10)') I,J,K,&
						& -1.0D0 !(MINUS ONE STANDS FOR INFINITE TIME)

					ELSE !LST_local_fluid_surf_rxn_count(I,J,K).LT.0

						PRINT*,'ERROR:  LST_global_write_VOLMSK_surfrxnt: LST_local_fluid_surf_rxn_count(I,J,K).LT.0',LST_local_fluid_surf_rxn_count(I,J,K)
						IF(debug) WRITE (0,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: LST_local_fluid_surf_rxn_count(I,J,K).LT.0',LST_local_fluid_surf_rxn_count(I,J,K)
						IF(debug) WRITE (9,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: LST_local_fluid_surf_rxn_count(I,J,K).LT.0',LST_local_fluid_surf_rxn_count(I,J,K)
						IF(debug) WRITE (29,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: LST_local_fluid_surf_rxn_count(I,J,K).LT.0',LST_local_fluid_surf_rxn_count(I,J,K)
						CALL MPI_Abort(cartesian_communicator,mpi_abort_error,mpi_error_code)


					ENDIF !LST_local_fluid_surf_rxn_count(I,J,K).GT.0
		
				END DO !I

			END DO	!J

		END DO !K 

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished writing array values from ROOT'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished writing array values from ROOT'
	
	ENDIF !! My_MPI_Process_ID.EQ.ROOT

	
	!COMMUNICATE DATA TO ROOT FROM ALL NON-ROOT PROCESSES(PACK IT INTO BUFFERS FIRST) AND THEN HAVE ROOT WRITE IT TO A FILE
	IF (My_MPI_Process_ID.NE.ROOT) THEN  !MAKE ALL THE NON-ROOT PROCESSES SEND THEIR BUFFERS TO ROOT
	
		send_size_integer = local_product_xyz_nodes_real*lattice_dimension		
		send_size_real = local_product_xyz_nodes_real
		IF(debug) WRITE (0,*) My_MPI_Process_ID,'send_size_integer',send_size_integer,'send_size_real',send_size_real
		IF(debug) WRITE (9,*) My_MPI_Process_ID,'send_size_integer',send_size_integer,'send_size_real',send_size_real
		ALLOCATE( local_integer_send_buffer(send_size_integer) )	
		ALLOCATE ( local_surf_rxn_t_count_send_bufr(send_size_real) )
		ALLOCATE ( local_surf_rxn_count_send_buffer(send_size_real) )
		ALLOCATE ( local_VOLMSK_logical_send_bufr(send_size_real) )

		index = 1		
		counter = 1

		DO K = local_z_min_real,local_z_max_real	!PACK THE DATA IN THE SEND BUFFERS

			DO J = local_y_min_real,local_y_max_real

				DO I = local_x_min_real,local_x_max_real

					!STORE COORDINATES
					local_integer_send_buffer(index) = I 
					local_integer_send_buffer(index + 1) = J
					local_integer_send_buffer(index + 2) = K
			
					!STORE VELOCITIES
					local_surf_rxn_t_count_send_bufr(counter) = LST_local_fluid_surf_rxn_t_count(I,J,K)
					local_surf_rxn_count_send_buffer(counter) = LST_local_fluid_surf_rxn_count(I,J,K)
					local_VOLMSK_logical_send_bufr(counter) = LST_local_vol_of_int_user_mask(I,J,K)
					
					counter = counter + 1
					index = index + lattice_dimension

				END DO !I

			END DO	!J

		END DO !K

		destination = ROOT !SEND BUFFERS TO DESTINATION

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to send LST_global_write_VOLMSK_surfrxnt integer array'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to send LST_global_write_VOLMSK_surfrxnt integer array'
	CALL MPI_Send(local_integer_send_buffer,send_size_integer,MPI_INTEGER,destination,&
	& IJK_communication_tag,cartesian_communicator,mpi_error_code)
	IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished sending LST_global_write_VOLMSK_surfrxnt integer array'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished sending LST_global_write_VOLMSK_surfrxnt integer array'

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: about to send local_surf_rxn_t_count_send_bufr'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: about to send local_surf_rxn_t_count_send_bufr'
	CALL MPI_Send(local_surf_rxn_t_count_send_bufr,send_size_real,MPI_INTEGER,&
	& destination,surf_rxn_time_count_comm_tag,cartesian_communicator,mpi_error_code)
	IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: FINISHED to send local_surf_rxn_t_count_send_bufr'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: FINISHED to send local_surf_rxn_t_count_send_bufr'

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: about to send local_surf_rxn_count_send_buffer'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: about to send local_surf_rxn_count_send_buffer'
	CALL MPI_Send(local_surf_rxn_count_send_buffer,send_size_real,MPI_INTEGER,&
	& destination,surf_rxn_count_communication_tag,cartesian_communicator,mpi_error_code)
	IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: FINISHED to send local_surf_rxn_count_send_buffer'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt: FINISHED to send local_surf_rxn_count_send_buffer'

	IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to send LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_send_bufr array'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to send LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_send_bufr array'
	CALL MPI_Send(local_VOLMSK_logical_send_bufr,send_size_real,MPI_LOGICAL,&
	& destination,VOLMSK_logical_comm_tag,cartesian_communicator,mpi_error_code)
	IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished sending LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_send_bufr array'
	IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished sending LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_send_bufr array'

	DEALLOCATE( local_integer_send_buffer )	
	DEALLOCATE ( local_surf_rxn_t_count_send_bufr )
	DEALLOCATE ( local_surf_rxn_count_send_buffer )
	DEALLOCATE( local_VOLMSK_logical_send_bufr )			

	ELSE  !!My_MPI_Process_ID.EQ.ROOT (SO THIS HAPPENS ONLY ON THE ROOT PROCESS)
		
		IF(debug) WRITE (0,*) My_MPI_Process_ID,'Number_Of_Processes - 1',Number_Of_Processes - 1
		IF(debug) WRITE (9,*) My_MPI_Process_ID,'Number_Of_Processes - 1',Number_Of_Processes - 1
		DO MPI_Process_Number = 0, Number_Of_Processes - 1  !CYCLE OVER ALL PROCESSES ON THE ROOT PROCESS
		
			IF(debug) WRITE (0,*) My_MPI_Process_ID,'ROOT',ROOT,'Cycling over MPI_Process_Number',MPI_Process_Number,'of',Number_Of_Processes - 1,'processes'
			IF(debug) WRITE (9,*) My_MPI_Process_ID,'ROOT',ROOT,'Cycling over MPI_Process_Number',MPI_Process_Number,'of',Number_Of_Processes - 1,'processes'
			IF(MPI_Process_Number.NE.ROOT) THEN !THIS IS TO ACCOUNT FOR THE CASE IF ROOT IS NOT ZERO, WE COULD HAVE JUST STARTED THE LOOP AT 1 INSTEAD
				
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'THIS SHOULD BE ROOT CYCLING OVER NONROOT MPI_Process_Number',MPI_Process_Number
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'THIS SHOULD BE ROOT CYCLING OVER NONROOT MPI_Process_Number',MPI_Process_Number
				
				SOURCE = MPI_Process_Number !ASSIGN CURRENT PROCESS AS "SOURCE" FROM WHICH INFORMATION IS RECEIVED
				
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'ROOT is preparing to recv from SOURCE',SOURCE
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'ROOT is preparing to recv from SOURCE',SOURCE

				root_receive_counts_array(MPI_Process_Number) = ( all_processes_local_bounds(2 + MPI_Process_Number * 6) - all_processes_local_bounds(1 + MPI_Process_Number * 6) + 1 ) * &
				& ( all_processes_local_bounds(4 + MPI_Process_Number * 6) - all_processes_local_bounds(3 + MPI_Process_Number * 6) + 1 ) * &
				& ( all_processes_local_bounds(6 + MPI_Process_Number * 6) - all_processes_local_bounds(5 + MPI_Process_Number * 6) + 1 )
			
				root_receive_counts_integer(MPI_Process_Number) = lattice_dimension * root_receive_counts_array(MPI_Process_Number)
			
				IF(debug) WRITE (0,*),'SOURCE',SOURCE,'root_receive_counts_array',root_receive_counts_array(MPI_Process_Number),'root_receive_counts_integer',root_receive_counts_integer(MPI_Process_Number)
				IF(debug) WRITE (9,*),'SOURCE',SOURCE,'root_receive_counts_array',root_receive_counts_array(MPI_Process_Number),'root_receive_counts_integer',root_receive_counts_integer(MPI_Process_Number)
				ALLOCATE( local_integer_recv_buffer(root_receive_counts_integer(MPI_Process_Number)) )	
				ALLOCATE ( local_surf_rxn_t_count_recv_bufr(root_receive_counts_array(MPI_Process_Number)) )	
				ALLOCATE ( local_surf_rxn_count_recv_buffer(root_receive_counts_array(MPI_Process_Number)) )	
				ALLOCATE ( local_VOLMSK_logical_recv_bufr(root_receive_counts_array(MPI_Process_Number)) )	
				
				
!				local_integer_recv_buffer(:)=0
!				local_surf_rxn_t_count_recv_bufr(:)=0

				!ROOT RECEIVES FROM ALL THE NON-ROOT PROCESSES THEIR BUFFERS
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to recv LST_global_write_VOLMSK_surfrxnt integer array'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to recv LST_global_write_VOLMSK_surfrxnt integer array'
				CALL MPI_Recv( local_integer_recv_buffer,root_receive_counts_integer(MPI_Process_Number),MPI_INTEGER,SOURCE,IJK_communication_tag, cartesian_communicator,status,mpi_error_code)
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished recv LST_global_write_VOLMSK_surfrxnt integer array'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished recv LST_global_write_VOLMSK_surfrxnt integer array'
			
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt ABOUT TO CALL MPI_RECV local_surf_rxn_t_count_recv_bufr'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt ABOUT TO CALL MPI_RECV local_surf_rxn_t_count_recv_bufr'
				CALL MPI_Recv( local_surf_rxn_t_count_recv_bufr,root_receive_counts_array(MPI_Process_Number),&
				& MPI_INTEGER,SOURCE,surf_rxn_time_count_comm_tag,cartesian_communicator,status,mpi_error_code )
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt FINISHED TO CALL MPI_RECV local_surf_rxn_t_count_recv_bufr'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt FINISHED TO CALL MPI_RECV local_surf_rxn_t_count_recv_bufr'

				IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt ABOUT TO CALL MPI_RECV local_surf_rxn_count_recv_buffer'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt ABOUT TO CALL MPI_RECV local_surf_rxn_count_recv_buffer'
				CALL MPI_Recv( local_surf_rxn_count_recv_buffer,root_receive_counts_array(MPI_Process_Number),&
				& MPI_INTEGER,SOURCE,surf_rxn_count_communication_tag,cartesian_communicator,status,mpi_error_code )
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt FINISHED TO CALL MPI_RECV local_surf_rxn_count_recv_buffer'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'LST_global_write_VOLMSK_surfrxnt FINISHED TO CALL MPI_RECV local_surf_rxn_count_recv_buffer'


				IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to recv LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_recv_bufr array'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to recv LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_recv_bufr array'
				CALL MPI_Recv( local_VOLMSK_logical_recv_bufr,root_receive_counts_array(MPI_Process_Number),&
				& MPI_LOGICAL,SOURCE,VOLMSK_logical_comm_tag, cartesian_communicator,status,mpi_error_code )
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished recv LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_recv_bufr array'
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished recv LST_global_write_VOLMSK_surfrxnt local_VOLMSK_logical_recv_bufr array'

		
				!ROOT WRITES DATA RECIEVED FROM NON-ROOT PROCESSES TO A FILE
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to write 3D_array from process',MPI_Process_Number
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'about to write 3D_array from process',MPI_Process_Number
				
				COUNTER = 1

				DO index = 1,root_receive_counts_integer(MPI_Process_Number),lattice_dimension

					IF(local_surf_rxn_count_recv_buffer(COUNTER).GT.0) THEN

						IF(local_VOLMSK_logical_recv_bufr(COUNTER)) THEN
				
							WRITE(84,'(3I6.5,E19.10)') &
							& local_integer_recv_buffer(index),&
							& local_integer_recv_buffer(index + 1),&
							& local_integer_recv_buffer(index + 2),&
							& ( REAL(local_surf_rxn_t_count_recv_bufr(COUNTER)) &
							& / REAL(local_surf_rxn_count_recv_buffer(COUNTER)) ) &
							& * LST_time_increment_phys_units

						ELSE  !.NOT.local_VOLMSK_logical_recv_bufr(COUNTER)

							WRITE(84,'(3I6.5,E19.10)') &
							& local_integer_recv_buffer(index),&
							& local_integer_recv_buffer(index + 1),&
							& local_integer_recv_buffer(index + 2),&
							& -1.0D0 !(MINUS ONE STANDS FOR INFINITE TIME)							

						ENDIF  !!local_VOLMSK_logical_recv_bufr(COUNTER)

					ELSEIF(local_surf_rxn_count_recv_buffer(COUNTER).EQ.0) THEN

						WRITE(84,'(3I6.5,E19.10)') &
						& local_integer_recv_buffer(index),&
						& local_integer_recv_buffer(index + 1),&
						& local_integer_recv_buffer(index + 2),&
						& -1.0D0 !(MINUS ONE STANDS FOR INFINITE TIME)

					ELSE !LST_local_fluid_surf_rxn_count(I,J,K).LT.0

						PRINT*,'ERROR:  LST_global_write_VOLMSK_surfrxnt: local_surf_rxn_count_recv_buffer(COUNTER).LT.0',local_surf_rxn_count_recv_buffer(COUNTER)
						IF(debug) WRITE (0,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: local_surf_rxn_count_recv_buffer(COUNTER).LT.0',local_surf_rxn_count_recv_buffer(COUNTER)
						IF(debug) WRITE (9,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: local_surf_rxn_count_recv_buffer(COUNTER).LT.0',local_surf_rxn_count_recv_buffer(COUNTER)
						IF(debug) WRITE (29,*) My_MPI_Process_ID,'ERROR:  LST_global_write_VOLMSK_surfrxnt: local_surf_rxn_count_recv_buffer(COUNTER).LT.0',local_surf_rxn_count_recv_buffer(COUNTER)
						CALL MPI_Abort(cartesian_communicator,mpi_abort_error,mpi_error_code)


					ENDIF !LST_local_fluid_surf_rxn_count(I,J,K).GT.0
					
					COUNTER = COUNTER + 1
	
				END DO !index

				IF(debug) WRITE (0,*) My_MPI_Process_ID,'finished writing 3D_array from process',MPI_Process_Number
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'finished writing 3D_array from process',MPI_Process_Number
			
				DEALLOCATE( local_integer_recv_buffer )	
				DEALLOCATE ( local_surf_rxn_t_count_recv_bufr )
				DEALLOCATE ( local_surf_rxn_count_recv_buffer )
				DEALLOCATE ( local_VOLMSK_logical_recv_bufr )
				
				IF(debug) WRITE (0,*) My_MPI_Process_ID,'deallocated 3D_array buffers from process',MPI_Process_Number
				IF(debug) WRITE (9,*) My_MPI_Process_ID,'deallocated 3D_array buffers from process',MPI_Process_Number
	
			ENDIF !!MPI_Process_Number.NE.ROOT
		
		END DO !!MPI_Process_Number

	ENDIF !!My_MPI_Process_ID IS ROOT OR NON-ROOT

	!ROOT CLOSES THE FILE
	IF (My_MPI_Process_ID.EQ.ROOT) CLOSE (84)

IF(debug) WRITE (0,*) My_MPI_Process_ID,'about to call barrier in SUBROUTINE LST_global_write_VOLMSK_surfrxnt'
CALL MPI_Barrier(cartesian_communicator,mpi_error_code)

RETURN
END SUBROUTINE LST_global_write_VOLMSK_surfrxnt