source: branches/GRISLIv3/SOURCES/imposed_regions_rsl.f90 @ 483

Last change on this file since 483 was 449, checked in by aquiquet, 8 months ago

Cleaning branch: use only statement for netcdf modules

File size: 4.7 KB
Line 
1!> \file imposed_regions_rsl.f90
2!! Module permet d'imposer un scenario des variations locales, par regions - pas par pixel
3!<
4
5!> \namespace imposed_regions_rsl
6!! Module qui permet d'imposer un scenario des variations locales, par regions - pas par pixel
7!! \author A. Quiquet
8!! \date January 2018
9!! @note  used modules
10!! @note  - use module3D_phy
11!<
12
13module imposed_regions_rsl
14
15! 2 fichiers :
16!  i-  un fichier texte avec nb_reg colonnes et un certain nombre de lignes, comme fileforc dans forclim
17!  ii- un fichier netcdf qui contient les regions, numerotees en partant de 0. La region 0 n'est pas touchee, niveau eustatique
18
19  use geography, only:nx,ny
20  use io_netcdf_grisli, only:read_ncdf_var
21
22  implicit none
23
24
25  integer :: nft   !<   number of lines in the rsl history file
26  real,dimension(:),allocatable :: tdate         !< time for rsl forcing
27  real,dimension(:,:),allocatable :: reg_rsltime !< rsl forcing for a specific region (time,region)
28
29  integer nb_reg                                 !< number of regions
30  integer,dimension(nx,ny) :: zregions              !< mask of the different regions
31
32contains
33
34!> SUBROUTINE: input_rsl
35!! Routine permettant d'introduire des variations locales du niveau marin
36!! en anomalie par rapport au niveau eustatique
37!>
38  subroutine input_rsl
39
40    use module3D_phy, only:num_param,num_forc,num_rep_42
41    use geography, only: dirforcage,dirnameinp
42    implicit none
43
44    character(len=8)   :: control   ! label to check clim. forc. file (filin) is usable
45    character(len=150) :: filin     ! the file to be read
46    character(len=150) :: filinreg  ! the file to be read
47    character(len=100) :: filforc   ! the history of rsl, a row = a region
48    character(len=100) :: filreg    ! the file of the different regions
49
50
51    integer :: err                  ! recuperation erreur
52
53    real*8, dimension(:,:),   pointer    :: tab               !< tableau 2d real pointe
54
55    integer i
56
57    namelist/imposed_regions_rsl/nb_reg,filreg,filforc
58
59
60    rewind(num_param)
61    read(num_param,imposed_regions_rsl)
62
63    write(num_rep_42,'(A)')'!___________________________________________________________'
64    write(num_rep_42,'(A)') '&imposed_regions_rsl                         ! nom du bloc '
65    write(num_rep_42,*)
66    write(num_rep_42,*) 'nb_reg = ', nb_reg
67    write(num_rep_42,'(A,A,A)') 'filreg  = "',trim(filreg),'"'
68    write(num_rep_42,'(A,A,A)') 'filforc = "',trim(filforc),'"'
69    write(num_rep_42,*)'/'
70    write(num_rep_42,*)
71
72    filin=trim(dirforcage)//trim(filforc)
73
74    open(num_forc,file=filin,status='old')
75
76    read(num_forc,*) control,nft
77
78    ! Determination of file size (line nb), allocation of perturbation array
79
80    if (control.ne.'nb_lines') then
81       write(6,*) filin,'indiquer le nb de ligne en debut de fichier:'
82       write(6,*) 'le nb de lignes et le label de control nb_lines'
83       stop
84    endif
85
86    if (.not.allocated(tdate)) then
87       allocate(tdate(nft),stat=err)
88       if (err/=0) then
89          print *,"erreur a l'allocation du tableau Tdate dans imposed_regions_rsl",err
90          stop 4
91       end if
92    end if
93
94    if (.not.allocated(reg_rsltime)) then
95       allocate(reg_rsltime(nb_reg,nft),stat=err)
96       if (err/=0) then
97          print *,"erreur a l'allocation du tableau reg_rsltime dans imposed_regions_rsl",err
98          stop 4
99       end if
100    end if
101
102    do i=1,nft
103       read(num_forc,*) tdate(i),reg_rsltime(1:nb_reg,i)
104    end do
105    close(num_forc)
106
107    filinreg=trim(dirnameinp)//trim(filreg)
108    call read_ncdf_var('z',filinreg,tab)
109    zregions(:,:) = tab(:,:)
110    if (minval(zregions(:,:)).ne.0) then
111       write(*,*) "Error in imposed_regions_rsl: should be numbered from 0 to nb_reg (min)"
112    endif
113    if (maxval(zregions(:,:)).ne.nb_reg) then
114       write(*,*) "Error in imposed_regions_rsl: should be numbered from 0 to nb_reg (max)"
115    endif
116
117  end subroutine input_rsl
118
119
120!> SUBROUTINE: rsl
121!! Routine 
122!>
123  subroutine rsl
124   
125    use module3D_phy, only:sealevel,sealevel_2d,time
126
127    implicit none
128   
129    integer i,j
130
131    real,dimension(0:nb_reg) :: reg_rsl
132
133    reg_rsl(0) = sealevel
134
135    if(time.lt.tdate(1)) then
136       reg_rsl(1:nb_reg)=reg_rsltime(:,1)
137
138    else if (time.ge.tdate(nft)) then
139       reg_rsl(1:nb_reg)=reg_rsltime(:,nft)
140
141    else
142       do i=1,nft-1
143          if((time.ge.tdate(i)).and.(time.lt.tdate(i+1))) then ! entre i et i+1 : cas general
144             reg_rsl(1:nb_reg)=reg_rsltime(:,i)+(reg_rsltime(:,i+1)-reg_rsltime(:,i))*       &
145                  (time-tdate(i))/(tdate(i+1)-tdate(i))
146             goto 100
147          endif
148       end do
149    endif
150100     continue
151
152
153    reg_rsl(0) = sealevel
154
155    do j=1,ny
156       do i=1,nx
157
158          sealevel_2d(i,j)=reg_rsl(zregions(i,j))
159
160       enddo
161    enddo
162
163
164  end subroutine rsl
165
166end module imposed_regions_rsl
Note: See TracBrowser for help on using the repository browser.