1 SUBROUTINE wrf_tsin ( grid , ierr )
8 #include <wrf_io_flags.h>
9 #include <wrf_status_codes.h>
11 TYPE(domain), INTENT(INOUT) :: grid
12 INTEGER, INTENT(INOUT) :: ierr
14 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
15 INTEGER, EXTERNAL :: get_unused_unit
17 REAL, ALLOCATABLE, DIMENSION(:) :: lattslocs, lontslocs
18 INTEGER :: istatus, iunit
20 CHARACTER (LEN=256) :: errmess
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
29 grid%have_calculated_tslocs = .FALSE.
31 IF ( grid%max_ts_locs <= 0 ) RETURN
33 IF ( wrf_dm_on_monitor() ) THEN
35 INQUIRE(FILE='tslist', EXIST=exists)
39 iunit = get_unused_unit()
40 IF ( iunit <= 0 ) THEN
41 CALL wrf_error_fatal('Error in wrf_tsin: could not find a free Fortran unit.')
44 ! Input time series locations
45 OPEN(UNIT=iunit, FILE='tslist', FORM='formatted', STATUS='old', IOSTAT=istatus)
47 IF (istatus == 0) THEN
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)')
54 ! Read in time series locations
56 DO WHILE (istatus == 0)
57 READ(UNIT=iunit, FMT='(A25,1X,A5,1X,F7.3,1X,F8.3)', IOSTAT=istatus) &
58 grid%desctsloc(grid%ntsloc+1), grid%nametsloc(grid%ntsloc+1), &
59 grid%lattsloc(grid%ntsloc+1), grid%lontsloc(grid%ntsloc+1)
60 IF (istatus == 0) grid%ntsloc = grid%ntsloc + 1
62 WRITE(errmess, FMT='(I4)') grid%ntsloc + 3 ! Three extra for the header of the file
63 CALL wrf_message('Error in tslist, line '//trim(errmess))
64 EXIT ! (technically unecessary, as we will exit the loop anyway)
66 IF ( grid%ntsloc >= grid%max_ts_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%ntsloc,'. Increase max_ts_locs in namelist.input'
70 CALL wrf_message(trim(errmess))
80 END IF ! tslist file exists
85 CALL wrf_dm_bcast_integer(grid%ntsloc, 1)
86 CALL wrf_dm_bcast_real(grid%lattsloc, grid%max_ts_locs)
87 CALL wrf_dm_bcast_real(grid%lontsloc, grid%max_ts_locs)
89 #if ((EM_CORE == 1) && (DA_CORE != 1))
93 END SUBROUTINE wrf_tsin
96 INTEGER FUNCTION get_unused_unit()
100 INTEGER, PARAMETER :: min_unit_number = 30
101 INTEGER, PARAMETER :: max_unit_number = 99
105 DO get_unused_unit = min_unit_number, max_unit_number
106 INQUIRE(UNIT=get_unused_unit, OPENED=opened)
107 IF ( .NOT. opened ) RETURN
114 END FUNCTION get_unused_unit