SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
read_surf_atm.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6 SUBROUTINE read_surf_atm (HPROGRAM, PFIELD, KFORC_STEP, KNB, KINIT)
7 !**************************************************************************
8 !
9 !! PURPOSE
10 !! -------
11 ! Read in the ascii file the atmospheric forcing for the actual time
12 ! step KFORC_STEP, and for the next one.
13 ! The two time step are needed for the time interpolation of the
14 ! forcing.
15 ! If the end of the file is reached, set the two step to the last
16 ! values.
17 ! Return undef value if the variable is not present
18 !!
19 !!** METHOD
20 !! ------
21 !!
22 !! EXTERNAL
23 !! --------
24 !!
25 !! IMPLICIT ARGUMENTS
26 !! ------------------
27 !!
28 !! REFERENCE
29 !! ---------
30 !!
31 !!
32 !! AUTHOR
33 !! ------
34 !! A. Lemonsu *Meteo France*
35 !!
36 !! MODIFICATIONS
37 !! -------------
38 !! Original 03/2008
39 !
40 USE modd_surfex_mpi, ONLY : nrank, npio, nindex, xtime_comm_read, xtime_npio_read
41 !
42 USE modd_surf_par, ONLY : xundef
43 USE modd_io_surf_ol, ONLY : xstart,xcount,xstride,lpartr
44 USE modd_io_surf_asc,ONLY : nni_forc
45 !
46 USE modd_arch, ONLY : little_endian_arch
47 !
49 !
50 USE modi_abor1_sfx
53 !
54 USE yomhook ,ONLY : lhook, dr_hook
55 USE parkind1 ,ONLY : jprb
56 !
57 IMPLICIT NONE
58 !
59 #ifdef SFX_MPI
60 include 'mpif.h'
61 #endif
62 !
63 ! global variables
64 REAL, DIMENSION(:,:),INTENT(INOUT) :: pfield
65 INTEGER,INTENT(IN) :: kforc_step
66 INTEGER,INTENT(IN) :: knb
67 INTEGER,INTENT(IN) :: kinit
68  CHARACTER(LEN=6) ,INTENT(IN) :: hprogram
69 
70 ! local variables
71 INTEGER :: i, ini, j, i1
72  CHARACTER(LEN=4), DIMENSION(:), ALLOCATABLE :: yf
73  CHARACTER(LEN=4) :: ywork
74 DOUBLE PRECISION :: xtime0
75 REAL*4 :: zwork4
76 REAL, DIMENSION(:,:), ALLOCATABLE :: zfield
77 REAL :: zwork
78 LOGICAL :: gswap ! T: swap has been done
79 REAL(KIND=JPRB) :: zhook_handle
80 !
81 IF (lhook) CALL dr_hook('READ_SURF_ATM',0,zhook_handle)
82 !
83 IF (nrank==npio) THEN
84  ini = SIZE(nindex)
85  ALLOCATE(zfield(ini,SIZE(pfield,2)))
86  IF (hprogram == 'BINARY') THEN
87  ALLOCATE(yf(ini))
88  ENDIF
89 ELSE
90  ALLOCATE(zfield(0,0))
91  ALLOCATE(yf(0))
92 ENDIF
93 !
94  CALL gather_and_write_mpi(pfield,zfield)
95 !
96 IF (nrank==npio) THEN
97  !
98 #ifdef SFX_MPI
99  xtime0 = mpi_wtime()
100 #endif
101  !
102  IF (hprogram == 'ASCII ') THEN
103  !
104  IF (kforc_step .EQ. 1) THEN
105  i1 = 1
106  rewind(kinit)
107  ELSE
108  i1 = 2
109  zfield(:,1) = zfield(:,knb)
110  ENDIF
111  DO i=i1,knb
112  IF (nni_forc==1) THEN
113  READ(unit=kinit,fmt=*) zwork
114  zfield(:,i) = zwork
115  ELSE
116  READ(unit=kinit,fmt=*) zfield(:,i)
117  END IF
118  ENDDO
119  !
120  ELSE IF (hprogram == 'BINARY') THEN
121  !
122  IF (kforc_step .EQ. 1) THEN
123  i1 = 1
124  gswap = .false.
125  ELSE
126  i1 = 2
127  zfield(:,1) = zfield(:,knb)
128  ENDIF
129  DO i=i1,knb
130  IF (nni_forc==1) THEN
131  READ(unit=kinit,rec=kforc_step+i-1) ywork
132  yf(:) = ywork
133  ELSE
134  READ(unit=kinit,rec=kforc_step+i-1) yf(:)
135  END IF
136  zfield(:,i) = yf(:)
137  IF ( any(abs(zfield(:,i))>0. .AND. abs(zfield(:,i))<1.e-30) &
138  .OR. any(abs(zfield(:,i))>1.e6) ) THEN
139  CALL abor1_sfx('READ_SURF_ATM: SWAP SET IN YOUR PARAMS_CONFIG FILE SEEMS '//&
140  'INAPPROPRIATE - VERIFY ')
141  END IF
142  ENDDO
143  !
144  ENDIF
145  !
146 #ifdef SFX_MPI
147  xtime_npio_read = xtime_npio_read + (mpi_wtime() - xtime0)
148 #endif
149  !
150 ENDIF
151 !
152  CALL read_and_send_mpi(zfield,pfield)
153 !
154 DEALLOCATE(zfield)
155 IF (hprogram=='BINARY') THEN
156  DEALLOCATE(yf)
157 ENDIF
158 !
159 lpartr=.false.
160 !
161 IF (lhook) CALL dr_hook('READ_SURF_ATM',1,zhook_handle)
162 
163 END SUBROUTINE read_surf_atm
subroutine read_surf_atm(HPROGRAM, PFIELD, KFORC_STEP, KNB, KINIT)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6