source: palm/trunk/UTIL/read_prt_data.f90 @ 1771

Last change on this file since 1771 was 1771, checked in by hoffmann, 8 years ago

program for analyzing binary particle data added

File size: 6.8 KB
Line 
1 PROGRAM read_prt_data
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2014  Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21! Initial revision.
22!
23! Former revisions:
24! -----------------
25! $Id: analyze_particle_data.f90 1310 2014-03-14 08:01:56Z raasch $
26!
27! Description:
28! ------------
29! This routine reads the particle data generated by PALM, and enables user
30! analysis. Compile and execute this program in the folder where your particle
31! data (_000000, _000001, ...) is stored.
32!-------------------------------------------------------------------------------!
33
34    IMPLICIT NONE
35
36    CHARACTER(LEN=7)    ::  i_proc_char
37    CHARACTER (LEN=80)  ::  rtext
38    CHARACTER (LEN=110) ::  run_description_header
39
40    REAL(KIND=8) ::  simulated_time
41    INTEGER      ::  ip, i_proc=0, i_proc_end, jp, kp,                         &
42                     max_number_of_particle_groups, number_of_particles,       &
43                     number_of_particle_groups, n, nxl,                        &
44                     nxr, nys, nyn, nzb, nzt, nbgp, status
45
46    INTEGER, DIMENSION(:,:,:), ALLOCATABLE ::  prt_count
47
48    TYPE particle_type
49       SEQUENCE
50       REAL(KIND=8) ::  radius, age, age_m, dt_sum, dvrp_psize, e_m,           &
51                        origin_x, origin_y, origin_z, rvar1, rvar2, rvar3,     &
52                        speed_x, speed_y, speed_z, weight_factor, x, y, z
53      INTEGER       ::  class, group, tailpoints, tail_id
54      LOGICAL       ::  particle_mask
55      INTEGER       ::  block_nr
56    END TYPE particle_type
57
58    TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  particles_temp
59    TYPE(particle_type), DIMENSION(:), POINTER     ::  particles
60
61    TYPE  grid_particle_def
62       TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  particles
63    END TYPE grid_particle_def
64
65    TYPE(grid_particle_def), DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  grid_particles
66
67    TYPE particle_groups_type
68        SEQUENCE
69        REAL(KIND=8) ::  density_ratio, radius, exp_arg, exp_term
70    END TYPE particle_groups_type
71
72    TYPE(particle_groups_type), DIMENSION(:), ALLOCATABLE ::  particle_groups
73
74    LOGICAL ::  found
75!
76!-- Check if file from PE0 exists and terminate program if it doesn't.
77    WRITE (i_proc_char,'(''_'',I6.6)')  i_proc
78    INQUIRE ( FILE=i_proc_char, EXIST=found )
79!
80!-- Estimate the number of files (equal to the number of PEs which
81!-- have been used in PALM)
82    DO  WHILE ( found )
83       OPEN ( 85, FILE=i_proc_char, FORM='UNFORMATTED' )
84       i_proc = i_proc + 1
85       WRITE (i_proc_char,'(''_'',I6.6)')  i_proc
86       INQUIRE ( FILE=i_proc_char, EXIST=found )
87       CLOSE( 85 )
88    ENDDO
89!
90!-- Info-output
91    PRINT*, ''
92    PRINT*, '*** read_prt ***'
93    IF ( i_proc /= 0 )  THEN
94       PRINT*, '***', i_proc, ' file(s) found'
95    ELSE
96       PRINT*, '+++ file _000000 not found'
97       PRINT*, '    program terminated'
98       STOP
99    ENDIF
100!
101!-- Set number of files and opens them sequentially
102    i_proc_end = i_proc-1
103
104    DO  i_proc = 0, i_proc_end
105!
106!--    Open particle data file for each process
107       WRITE (i_proc_char,'(''_'',I6.6)')  i_proc
108       OPEN ( 85, FILE=i_proc_char, FORM='UNFORMATTED' ) 
109!
110!--    Read general description of file and inform user
111       READ ( 85 )  run_description_header
112       READ ( 85 )  rtext
113       IF ( i_proc == 0 )  THEN
114          PRINT*, ' '
115          PRINT*, '*** data description header:'
116          PRINT*, '*** ', run_description_header
117          PRINT*, '*** ', rtext
118          PRINT*, ' '
119       ENDIF
120       PRINT*, '*** data of file', i_proc, 'is analysed'
121       READ ( 85 )  number_of_particle_groups, max_number_of_particle_groups
122
123       IF ( .NOT. ALLOCATED(particle_groups) )  THEN
124          ALLOCATE( particle_groups(max_number_of_particle_groups) )
125       ENDIF
126   
127       READ ( 85 )  particle_groups
128       READ ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
129
130       IF ( ALLOCATED(prt_count)  .OR.  ALLOCATED(grid_particles) )  THEN
131          DEALLOCATE( prt_count, grid_particles )
132       ENDIF
133
134       ALLOCATE( prt_count(nzb:nzt+1,nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp),     &
135                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
136
137!
138!--    Start individual time loop
139       DO
140          READ( 85, IOSTAT=status)  simulated_time
141          IF ( status < 0 )  THEN
142             PRINT*, '*** end of file reached'
143             EXIT
144          ENDIF
145          PRINT*, '*** time of analyzed data set:', simulated_time
146
147          READ ( 85 )  prt_count
148
149          DO  ip = nxl, nxr
150             DO  jp = nys, nyn
151                DO  kp = nzb+1, nzt
152                   number_of_particles = prt_count(kp,jp,ip)
153                   IF ( number_of_particles <= 0 )  CYCLE
154                   ALLOCATE( grid_particles(kp,jp,ip)%particles(1:number_of_particles) )
155                   ALLOCATE( particles_temp(1:number_of_particles) )
156                   READ ( 85 )  particles_temp
157                   grid_particles(kp,jp,ip)%particles = particles_temp
158                   DEALLOCATE( particles_temp )
159                ENDDO
160             ENDDO
161          ENDDO
162!
163!--       This part can be used for user analysis
164          DO  ip = nxl, nxr
165             DO  jp = nys, nyn
166                DO  kp = nzb+1, nzt
167                   number_of_particles = prt_count(kp,jp,ip)
168                   IF ( number_of_particles <= 0 )  CYCLE
169                   particles => grid_particles(kp,jp,ip)%particles
170!
171!--                Add your analysis here
172!                   DO  n = 1, number_of_particles
173!
174!                   ENDDO
175
176                ENDDO
177             ENDDO
178          ENDDO
179!
180!--       Deallocate grid_particles%particles in case of more than one timestep
181          DO  ip = nxl, nxr
182             DO  jp = nys, nyn
183                DO  kp = nzb+1, nzt
184                   number_of_particles = prt_count(kp,jp,ip)
185                   IF ( number_of_particles <= 0 )  CYCLE
186                   DEALLOCATE( grid_particles(kp,jp,ip)%particles )
187                ENDDO
188             ENDDO
189          ENDDO     
190
191       ENDDO ! end of time loop
192
193       CLOSE( 85 )
194
195    ENDDO ! end of file loop
196
197 END PROGRAM read_prt_data
Note: See TracBrowser for help on using the repository browser.