source: dynamico_lmdz/simple_physics/phyparam/physics/restart.F90 @ 4236

Last change on this file since 4236 was 4236, checked in by dubos, 5 years ago

simple_physics : some Python bindings

File size: 1.9 KB
Line 
1MODULE restart
2  IMPLICIT NONE
3  PRIVATE
4  SAVE
5
6  ! right after allocating arrays for persistent data (internal state), the physics
7  ! code calls restart_register for each array
8  ! it is then left to the driver code to either call cold_start or to read data from disk into these arrays
9  ! it is also left to the driver code to write internal state to disk at the end of the time loop
10
11  INTEGER, PARAMETER :: max_restart_field=100, max_len=100
12  INTEGER :: nb_restart_field=0
13
14  TYPE restart_record_t
15     CHARACTER(max_len) :: name
16     REAL, POINTER :: data1(:), data2(:,:)
17  END TYPE restart_record_t
18
19  TYPE(restart_record_t) :: restart_record(max_restart_field)
20
21  INTERFACE restart_register
22     MODULE PROCEDURE restart_register_1D, restart_register_2D
23  END INTERFACE
24
25  PUBLIC :: restart_register
26
27CONTAINS
28
29  SUBROUTINE check_name(name)
30    CHARACTER(*), INTENT(IN) :: name ! unique name of the restart field
31    INTEGER :: id
32    DO id=1, nb_restart_field
33       IF(TRIM(restart_record(id)%name) == name) THEN
34          PRINT *, 'FATAL : Restart field ', name, ' already registered'
35          STOP
36       END IF
37    END DO
38    nb_restart_field = nb_restart_field+1
39  END SUBROUTINE check_name
40
41  SUBROUTINE restart_register_1D(name, field)
42    CHARACTER(*), INTENT(IN) :: name ! unique name of the restart field
43    REAL, INTENT(IN), TARGET :: field(:) ! 1D field to be read/written at checkpoint/restart
44    CALL check_name(name)
45    restart_record(nb_restart_field)%name = name
46    restart_record(nb_restart_field)%data1 => field
47  END SUBROUTINE restart_register_1D
48
49  SUBROUTINE restart_register_2D(name, field)
50    CHARACTER(*), INTENT(IN) :: name ! unique name of the restart field
51    REAL, INTENT(IN), TARGET :: field(:,:) ! 1D field to be read/written at checkpoint/restart
52    CALL check_name(name)
53    restart_record(nb_restart_field)%name = name
54    restart_record(nb_restart_field)%data2 => field
55  END SUBROUTINE restart_register_2D
56
57END MODULE restart
Note: See TracBrowser for help on using the repository browser.