source: lmdz_wrf/branches/LMDZ_WRFmeas/WRFV3/share/wrf_lidarin.F @ 103

Last change on this file since 103 was 22, checked in by lfita, 11 years ago

Adding WRFmeas modifications in the WRF code side

File size: 3.7 KB
Line 
1SUBROUTINE wrf_lidarin ( grid , ierr )
2
3    USE module_domain
4    USE module_utility
5
6    IMPLICIT NONE
7
8#include <wrf_io_flags.h>
9#include <wrf_status_codes.h>
10
11    TYPE(domain), INTENT(INOUT) :: grid
12    INTEGER, INTENT(INOUT) :: ierr
13
14    LOGICAL, EXTERNAL :: wrf_dm_on_monitor
15    INTEGER, EXTERNAL :: get_unused_unit
16
17    REAL, ALLOCATABLE, DIMENSION(:) :: latlidarlocs, lonlidarlocs
18    INTEGER :: istatus, iunit
19    LOGICAL :: exists
20    CHARACTER (LEN=256) :: errmess
21
22    ierr = 0
23
24#if ((EM_CORE == 1) && (DA_CORE != 1))
25    IF ( grid%dfi_opt == DFI_NODFI .OR. (grid%dfi_opt /= DFI_NODFI .AND. grid%dfi_stage == DFI_SETUP) ) THEN
26#endif
27
28       grid%nlidarloc = 0
29       grid%have_calculated_lidarlocs = .FALSE.
30   
31       IF ( grid%max_lidar_locs <= 0 ) RETURN
32   
33       IF ( wrf_dm_on_monitor() ) THEN
34   
35          INQUIRE(FILE='lidarlist', EXIST=exists)
36
37          IF (exists) THEN
38
39             iunit = get_unused_unit()
40             IF ( iunit <= 0 ) THEN
41                CALL wrf_error_fatal('Error in wrf_lidarin: could not find a free Fortran unit.')
42             END IF
43
44             ! Input time series locations
45             OPEN(UNIT=iunit, FILE='lidarlist', FORM='formatted', STATUS='old', IOSTAT=istatus)
46   
47             IF (istatus == 0) THEN
48   
49                ! Ignore first three lines, which constitute a header
50                READ(UNIT=iunit, FMT='(1X)')
51                READ(UNIT=iunit, FMT='(1X)')
52                READ(UNIT=iunit, FMT='(1X)')
53   
54                ! Read in time series locations
55                istatus = 0
56                DO WHILE (istatus == 0)
57                   READ(UNIT=iunit, FMT='(A25,1X,A5,1X,F7.3,1X,F8.3)', IOSTAT=istatus)            &
58                        grid%desclidarloc(grid%nlidarloc+1), grid%namelidarloc(grid%nlidarloc+1), &
59                        grid%latlidarloc(grid%nlidarloc+1), grid%lonlidarloc(grid%nlidarloc+1)
60                   IF (istatus == 0) grid%nlidarloc = grid%nlidarloc + 1
61                   IF (istatus > 0) THEN
62                      WRITE(errmess, FMT='(I4)') grid%nlidarloc + 3   ! Three extra for the header of the file
63                      CALL wrf_message('Error in lidarlist, line '//trim(errmess))
64                      EXIT    ! (technically unecessary, as we will exit the loop anyway)
65                   END IF
66                   IF ( grid%nlidarloc >= grid%max_lidar_locs ) THEN
67                      IF ( istatus == 0 ) THEN                 ! Assume there were more lines in the file
68                         WRITE(errmess, FMT='(A,I4,A)') 'Ignoring all time series locations beyond #', &
69                                                    grid%nlidarloc,'. Increase max_lidar_locs in namelist.input'
70                         CALL wrf_message(trim(errmess))
71                      END IF
72                      EXIT
73                   END IF
74                END DO
75     
76                CLOSE(iunit)
77   
78             END IF
79
80          END IF  ! lidarlist file exists
81   
82       END IF
83
84#ifdef DM_PARALLEL
85       CALL wrf_dm_bcast_integer(grid%nlidarloc, 1)
86       CALL wrf_dm_bcast_real(grid%latlidarloc, grid%max_lidar_locs)
87       CALL wrf_dm_bcast_real(grid%lonlidarloc, grid%max_lidar_locs)
88#endif
89#if ((EM_CORE == 1) && (DA_CORE != 1))
90    END IF
91#endif
92
93END SUBROUTINE wrf_lidarin
94
95
96! L. Fita, LMD. May 2014
97! Already defined as function by wrf_timeseries.F
98!
99!!INTEGER FUNCTION get_unused_unit()
100!!
101!!    IMPLICIT NONE
102!!
103!!    INTEGER, PARAMETER :: min_unit_number = 30
104!!    INTEGER, PARAMETER :: max_unit_number = 99
105!!
106!!    LOGICAL :: opened
107!!
108!!    DO get_unused_unit = min_unit_number, max_unit_number
109!!       INQUIRE(UNIT=get_unused_unit, OPENED=opened)
110!!       IF ( .NOT. opened ) RETURN
111!!    END DO
112!!
113!!    get_unused_unit = -1
114!!
115!!    RETURN
116!!   
117!!END FUNCTION get_unused_unit
Note: See TracBrowser for help on using the repository browser.