Debian Codegraph @

src/read_data.F90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2023 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !-------------------------------------------------------------
24 !
25 ! Moldule used to consolidate all of the read_data options
26 !
27 !-------------------------------------------------------------
28
29 module readdata
30 ! This list is the reason why we really need a standard file format for SPH
31 use readdata_sphNG, only:read_data_sphNG, set_labels_sphNG, file_format_is_sphNG
32 use readdata_ascii, only:read_data_ascii, set_labels_ascii
33 use readdata_ndspmhd, only:read_data_ndspmhd, set_labels_ndspmhd, file_format_is_ndspmhd
34 use readdata_gadget, only:read_data_gadget, set_labels_gadget, file_format_is_gadget
35 use readdata_VINE, only:read_data_VINE, set_labels_VINE
36 use readdata_sro, only:read_data_sro, set_labels_sro
37 use readdata_dragon, only:read_data_dragon, set_labels_dragon
38 use readdata_seren, only:read_data_seren, set_labels_seren
39 use readdata_tipsy, only:read_data_tipsy, set_labels_tipsy, file_format_is_tipsy
40 use readdata_mhutch, only:read_data_mhutch, set_labels_mhutch
41 use readdata_UCLA, only:read_data_UCLA, set_labels_UCLA
42 use readdata_aly, only:read_data_aly, set_labels_aly
43 use readdata_bauswein, only:read_data_bauswein, set_labels_bauswein
44 use readdata_egaburov, only:read_data_egaburov, set_labels_egaburov
45 use readdata_foulkes, only:read_data_foulkes, set_labels_foulkes
46 use readdata_gadget_jsb, only:read_data_gadget_jsb, set_labels_gadget_jsb
47 use readdata_jjm, only:read_data_jjm, set_labels_jjm
48 use readdata_jjmmulti, only:read_data_jjmmulti, set_labels_jjmmulti
49 use readdata_mbate, only:read_data_mbate, set_labels_mbate
50 use readdata_oilonwater, only:read_data_oilonwater, set_labels_oilonwater
51 use readdata_rsph, only:read_data_rsph, set_labels_rsph
52 use readdata_vanaverbeke, only:read_data_vanaverbeke, set_labels_vanaverbeke
53 use readdata_spyros, only:read_data_spyros, set_labels_spyros
54 use readdata_urban, only:read_data_urban, set_labels_urban
55 use readdata_starsmasher, only:read_data_starsmasher, set_labels_starsmasher
56 use readdata_vtk, only:read_data_vtk, set_labels_vtk
57 use readdata_shamrock, only:read_data_shamrock, set_labels_shamrock
58
59 ! Make hdf5 fortran/c modules available if compiled with hdf5
60 #ifdef HDF5
61 use readdata_amuse_hdf5, only:read_data_amuse_hdf5, set_labels_amuse_hdf5
62 use readdata_cactus_hdf5, only:read_data_cactus_hdf5, set_labels_cactus_hdf5
63 ! use readdata_falcON_hdf5, only:read_data_falcON_hdf5, set_labels_falcON_hdf5
64 use readdata_flash_hdf5, only:read_data_flash_hdf5, set_labels_flash_hdf5
65 use readdata_gadget_hdf5, only:read_data_gadget_hdf5, set_labels_gadget_hdf5
66 #endif
67
68 ! Same for FITS files
69 #ifdef FITS
70 use readdata_fits, only:read_data_fits, set_labels_fits
71 #endif
72
73 ! If the PBOB_DIR is given, then also include this
74 #ifdef PBOB_DIR
75 use readdata_pbob, only:read_data_pbob, set_labels_pbob
76 #endif
77
78 #ifdef H5PART_DIR
79 use readdata_h5part, only:read_data_h5part, set_labels_h5part
80 #endif
81
82 ! use readdata_snsph, only:read_data_snsph, set_labels_snsph
83
84 implicit none
85 public :: select_data_format, guess_format
86 public :: print_available_formats
87
88 abstract interface
89 subroutine set_labels_subroutine
90 end subroutine
91 end interface
92
93 abstract interface
94 subroutine read_data_subroutine(rootname,indexstart,iposn,nstepsread)
95 integer, intent(in) :: indexstart,iposn
96 integer, intent(out) :: nstepsread
97 character(len=*), intent(in) :: rootname
98
99 end subroutine
100 end interface
101
102 procedure(read_data_subroutine), pointer, public :: read_data
103 procedure(set_labels_subroutine), pointer, public :: set_labels
104
105 private
106
107 contains
108
109 !----------------------------------------------------------------------
110 ! subroutine to select string specified data format
111 !----------------------------------------------------------------------
112
113 subroutine select_data_format(string_in,ierr)
114 use asciiutils, only:lcase
115
116 character(len=*), intent(in) :: string_in
117 integer, intent(out) :: ierr
118 character(len=len(string_in)) :: string
119
120 ! allow both -ascii and --ascii in flags
121 if (string_in(1:1)=='-') then
122 string = string_in(2:)
123 else
124 string = string_in
125 endif
126
127 !----------------------------
128 ! Checks for dependencies
129 !----------------------------
130
131 ! Check if SPLASH has been compiled with hdf5, if hdf5 format is requested
132 if ((index(string, 'hdf5') > 0) .or. (index(string, '.h5') > 0)) then
133 #ifndef HDF5
134 print "(/,a)", ' *** ERROR: hdf5 file format requested, but SPLASH not compiled with HDF5 ***'
135 print "(a)", ' Try make HDF5=yes '
136 stop
137 #else
138 continue
139 #endif
140 end if
141
142 ! Check if H5PART is being requested
143 if (string == 'h5part') then
144 #ifndef H5PART_DIR
145 print "(/,a)", ' *** ERROR: H5PART file given, but SPLASH not compiled with the H5PART library. ***'
146 print "(a)", ' Try make H5PART_DIR=/path/to/h5part/ Note: You must also compile with HDF5=yes'
147 stop
148 #else
149 continue
150 #endif
151 end if
152
153 ! Check if SPLASH has been compiled with the fits library, if fits format is requested
154 if (string == 'fits') then
155 #ifndef FITS
156 print "(/,a)", ' *** ERROR: .fits file given, but SPLASH not compiled with the fits library. ***'
157 print "(a)", ' Try make FITS=yes '
158 #endif
159 end if
160
161 ! Check if PBOB is being requested
162 if (string == 'pbob') then
163 #ifndef PBOB_DIR
164 print "(/,a)", ' *** ERROR: .pbob file given, but SPLASH has not been compiled with the PBOB library. ***'
165 print "(a)", ' Try make PBOB_DIR=/path/to/pbob/ '
166 #else
167 continue
168 #endif
169 end if
170
171 ierr=0
172
173 !----------------------------------------------------
174 ! Search input string for matching supported formats
175 !----------------------------------------------------
176
177 select case(trim(adjustl(lcase(string))))
178
179 case('sphng', 'phantom', 'phantomsph')
180 read_data=>read_data_sphNG
181 set_labels=>set_labels_sphNG
182
183 case('ascii')
184 read_data=>read_data_ascii
185 set_labels=>set_labels_ascii
186
187 case('ndspmhd')
188 read_data=>read_data_ndspmhd
189 set_labels=>set_labels_ndspmhd
190
191 case('gadget')
192 read_data=>read_data_gadget
193 set_labels=>set_labels_gadget
194
195 case('vine')
196 read_data=>read_data_VINE
197 set_labels=>set_labels_VINE
198
199 case('sro', 'srosph', 'magma')
200 read_data=>read_data_sro
201 set_labels=>set_labels_sro
202
203 case('dragon')
204 read_data=>read_data_dragon
205 set_labels=>set_labels_dragon
206
207 case('seren','gandalf')
208 read_data=>read_data_seren
209 set_labels=>set_labels_seren
210
211 case('tipsy', 'gasoline')
212 read_data=>read_data_tipsy
213 set_labels=>set_labels_tipsy
214
215 case('mhutch')
216 read_data=>read_data_mhutch
217 set_labels=>set_labels_mhutch
218
219 case('ucla', 'ascii_ucla', 'ucla_ascii', 'sky')
220 read_data=>read_data_ucla
221 set_labels=>set_labels_ucla
222
223 case('aly')
224 read_data=>read_data_aly
225 set_labels=>set_labels_aly
226
227 case('bauswein')
228 read_data=>read_data_bauswein
229 set_labels=>set_labels_bauswein
230
231 case('egaburov')
232 read_data=>read_data_egaburov
233 set_labels=>set_labels_egaburov
234
235 case('foulkes', 'steve')
236 read_data=>read_data_foulkes
237 set_labels=>set_labels_foulkes
238
239 case('gadget_jsb', 'gadget-jsb')
240 read_data=>read_data_gadget_jsb
241 set_labels=>set_labels_gadget_jsb
242
243 case('jjm')
244 read_data=>read_data_jjm
245 set_labels=>set_labels_jjm
246
247 case('jjmmulti', 'jjm_multi', 'jjm_multiphase')
248 read_data=>read_data_jjmmulti
249 set_labels=>set_labels_jjmmulti
250
251 case('mbate')
252 read_data=>read_data_mbate
253 set_labels=>set_labels_mbate
254
255 case('oilonwater')
256 read_data=>read_data_oilonwater
257 set_labels=>set_labels_oilonwater
258
259 case('rsph')
260 read_data=>read_data_rsph
261 set_labels=>set_labels_rsph
262
263 ! case('snsph', 'snsplash')
264 ! read_data=>read_data_snsph
265 ! set_labels=>set_labels_snsph
266
267 ! case('sphysics')
268 ! read_data=>read_data_sphysics
269 ! set_labels=>set_labels_sphysics
270
271 case('spyros')
272 read_data=>read_data_spyros
273 set_labels=>set_labels_spyros
274
275 case('urban')
276 read_data=>read_data_urban
277 set_labels=>set_labels_urban
278
279 case('gradsph', 'vanaverbeke', 'sigfried')
280 read_data=>read_data_vanaverbeke
281 set_labels=>set_labels_vanaverbeke
282
283 case('starsmasher', 'star_smasher', 'jamiesph')
284 read_data=> read_data_starsmasher
285 set_labels=>set_labels_starsmasher
286
287 case('vtk')
288 read_data=> read_data_vtk
289 set_labels=>set_labels_vtk
290
291 case('shamrock')
292 read_data=>read_data_shamrock
293 set_labels=>set_labels_shamrock
294
295 ! Make the hdf5 data formats available if SPLASH has been compiled with HDF5
296 #ifdef HDF5
297 case('phantom_hdf5', 'sphng_hdf5', 'phantomsph_hdf5')
298 print "(a)", 'Phantom HDF5 files are currently not supported :( '
299 stop
300
301 case('gadget_hdf5','swift')
302 read_data=>read_data_gadget_hdf5
303 set_labels=>set_labels_gadget_hdf5
304
305 case('amuse_hdf5')
306 read_data=>read_data_amuse_hdf5
307 set_labels=>set_labels_amuse_hdf5
308
309 ! case('falcon_hdf5', 'falconhdf5', 'falcon')
310 ! read_data=>read_data_falcON_hdf5
311 ! set_labels=>set_labels_falcON_hdf5
312
313 case('flash_hdf5', 'flashhdf5', 'flash')
314 read_data=>read_data_flash_hdf5
315 set_labels=>set_labels_flash_hdf5
316
317 case('cactus', 'cactus_hdf5')
318 read_data=>read_data_cactus_hdf5
319 set_labels=>set_labels_cactus_hdf5
320 #endif
321
322 ! Make fits routines available if SPLASH has been compiled with FITS
323 #ifdef FITS
324 case('fits')
325 read_data=>read_data_fits
326 set_labels=>set_labels_fits
327 #endif
328
329 ! Make PBOB available if PBOB_DIR defined
330 #ifdef PBOB_DIR
331 case('pbob')
332 read_data=>read_data_pbob
333 set_labels=>set_labels_pbob
334 #endif
335
336 ! Make H5PART available of H5PART_DIR defined
337 #ifdef H5PART_DIR
338 case('h5part')
339 read_data=>read_data_h5part
340 set_labels=>set_labels_h5part
341 #endif
342
343 case default
344 !call guess_format()
345 ierr=1
346 end select
347
348
349 end subroutine select_data_format
350
351 !----------------------------------------------------------------------
352 ! subroutine for printing help messages associated with reading data
353 !----------------------------------------------------------------------
354
355 subroutine print_available_formats(string)
356 character(len=*), intent(in), optional :: string
357
358 !print "(/,a)",' To select data formats, use the shortcuts below, or use the -f or --format command line options'
359 !print "(a)" ,' Multiple data formats are not support in a single instance.'
360 if (string == 'short') then
361 print "(/,a,/)",'Example data formats (type --formats for full list):'
362 else
363 print "(/,a,/)",'Supported data formats (auto = automatically identified from file contents):'
364 endif
365 print "(a)" ,' -ascii,-csv : ascii text/csv format (default)'
366 print "(a)" ,' -phantom -sphng : Phantom and sphNG codes (auto)'
367 print "(a)" ,' -vtk : vtk legacy binary format (auto)'
368 print "(a)" ,' -ndspmhd : ndspmhd code (auto)'
369 print "(a)" ,' -gandalf,-seren : Gandalf/Seren code'
370 print "(a)" ,' -shamrock : Shamrock code'
371 #ifdef HDF5
372 print "(a)" ,' -gadget -gadget_hdf5 : Gadget code (auto)'
373 print "(a)" ,' -falcon -falcon_hdf5 : FalcON code'
374 print "(a)" ,' -flash -flash_hdf5 : FLASH code'
375 print "(a)" ,' -cactus -cactus_hdf5 : Cactus code'
376 print "(a,/)",' -amuse -amuse_hdf5 : AMUSE Framework'
377 #else
378 print "(a)" ,' -gadget : Gadget code (auto)'
379 #endif
380 #ifdef FITS
381 print "(a)" ,' -fits : FITS format (auto)'
382 #endif
383 #ifdef PBOB_DIR
384 print "(a)" ,' -pbob : PBOB format'
385 #endif
386 #ifdef H5PART_DIR
387 print "(a)" ,' -h5part : H5PART format'
388 #endif
389
390 if (string /= 'short') then
391 print "(a)",' -tipsy -gasoline : Gasoline code (auto)'
392 print "(a)",' -vine : VINE SPH code'
393 print "(a)",' -rsph : Regularised SPH'
394 print "(a)",' -starsmasher : Star Smasher code'
395 print "(a)",' -dragon : DRAGON code'
396 print "(a)",' -sro -magma : Stephan Rosswog SPH code'
397 print "(a)",' -gradsph : GRADSPH code'
398 print "(a)"," -mhutch : Mark Hutchison's code"
399 print "(a)"," -mbate : Matthew Bate's code"
400 print "(a)",' -oilonwater : Oil-on-Water binary accretion SPH'
401 print "(a)",' -ucla : UCLA ascii format'
402 print "(a)",' -urban : Andrea Urban ascii format'
403 print "(a)",' -spyros : Spyros Kitsionas format'
404 print "(a)",' -jjm -jjmmulti : Joe Monaghan format'
405 print "(a)",' -bauswein : Andreas Bauswein format'
406 print "(a)",' -egaburov : Evghenii Gaburov format'
407 print "(a)",' -aly : Aly Reheam format'
408 print "(a)",' -foulkes : Foulkes ascii format'
409 print "(a)",' -vanaverbeke : Sigfried Vanaverbeke code'
410 print "(a)",' -gadget_jsb : GADGET Jamie Bolton variant'
411 #ifndef HDF5
412 print "(a)",' -gadget_hdf5 : Gadget HDF5 [not compiled]'
413 print "(a)",' -falcon -falcon_hdf5 : FalcON code [not compiled]'
414 print "(a)",' -flash -flash_hdf5 : FLASH code [not compiled]'
415 print "(a)",' -cactus -cactus_hdf5 : Cactus code [not compiled]'
416 print "(a)",' -amuse -amuse_hdf5 : AMUSE Framework [not compiled]'
417 #endif
418 #ifndef FITS
419 print "(a)",' -fits : FITS format [not compiled]'
420 #endif
421 end if
422
423 #ifdef HDF5
424 print "(/,a)" ,'This build supports HDF5 formats. HDF5 files will be automatically'
425 print "(a)",' recognised if they end with .h5, however you must specify a supported data format.'
426 print "(a)",' add a suffix "_hdf5" to above format if your data files do not end with .h5.'
427 #else
428 print "(/,a)",'This build does not support HDF5. Compile with HDF5=yes to change this.'
429 #endif
430 #ifndef FITS
431 print "(a)",'This build does not support FITS. Compile with FITS=yes to change this.'
432 #endif
433
434 end subroutine print_available_formats
435
436 !-----------------------------------------------------------------------------------
437 ! subroutine for guessing the file format if not specified, or full info not given
438 !-----------------------------------------------------------------------------------
439 subroutine guess_format(nfiles,filenames,ierr,informat)
440 use asciiutils, only:get_extensions
441 integer, intent(in) :: nfiles
442 character(len=*), intent(in) :: filenames(:)
443 character(len=*), intent(in), optional :: informat ! This is given if --format <string> is supplied
444 integer, intent(out) :: ierr
445 character(len=12), dimension(5) :: extensions(5)
446
447 call get_extensions(filenames(1), extensions)
448
449 ierr = 0
450 !
451 ! try to guess the file format from the extension
452 !
453 if (any(index(extensions, '.h5') > 0) .or. any(index(extensions, '.hdf5') > 0)) then
454 if (present(informat)) then
455 call select_data_format(informat//"_hdf5",ierr)
456 elseif (any((index(extensions, '.pb') > 0))) then
457 call select_data_format("phantom_hdf5", ierr)
458 else
459 call select_data_format('gadget_hdf5',ierr)
460 endif
461 elseif (any((index(extensions, '.fits') > 0))) then
462 call select_data_format('fits',ierr)
463 elseif (any((index(extensions, '.vtk') > 0))) then
464 call select_data_format('vtk',ierr)
465 elseif (any((index(extensions, '.pb') > 0))) then
466 call select_data_format('phantom', ierr)
467 elseif (any((index(extensions, '.sham') > 0))) then
468 call select_data_format('shamrock', ierr)
469 elseif (any((index(extensions, '.pbob') > 0))) then
470 call select_data_format('pbob', ierr)
471 elseif (any((index(extensions, '.csv') > 0))) then
472 call select_data_format('ascii', ierr)
473 else
474 !
475 ! if cannot guess from extension, then
476 ! try to guess from the filename/header
477 !
478 call guess_format_from_file_header(filenames(1),ierr)
479 !
480 ! it is ok to not get a format, just assume ascii
481 ! in this case we just return ierr /= 0
482 !
483 endif
484
485 end subroutine guess_format
486
487 !------------------------------------------------------------
488 ! subroutine for guessing the file format from the filename
489 ! and (if filename matches) the first few lines of the file
490 !------------------------------------------------------------
491 subroutine guess_format_from_file_header(filename,ierr)
492 character(len=*), intent(in) :: filename
493 integer, intent(out) :: ierr
494
495 ierr = 1
496 if (file_format_is_sphNG(filename)) then
497 call select_data_format('sphNG',ierr)
498 elseif (file_format_is_gadget(filename)) then
499 call select_data_format('gadget',ierr)
500 elseif (index(filename,'.hdf5') > 0) then
501 call select_data_format('gadget_hdf5',ierr)
502 elseif (file_format_is_ndspmhd(filename)) then
503 call select_data_format('ndspmhd',ierr)
504 elseif (file_format_is_tipsy(filename)) then
505 call select_data_format('tipsy',ierr)
506 endif
507
508 end subroutine guess_format_from_file_header
509
510 end module readdata