1 SUBROUTINE wrf_tsin ( grid , ierr )
5 USE module_configure, ONLY : model_config_rec, grid_config_rec_type, model_to_grid_config_rec
6 USE module_string_tools, ONLY : capitalize
10 #include "wrf_io_flags.h"
11 #include "wrf_status_codes.h"
13 TYPE(domain), INTENT(INOUT) :: grid
14 TYPE (grid_config_rec_type) :: config_flags
15 INTEGER, INTENT(INOUT) :: ierr
17 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
18 INTEGER, EXTERNAL :: get_unused_unit
20 INTEGER :: istatus, iunit
22 CHARACTER (LEN=256) :: errmess
23 CHARACTER (LEN=256) :: IorLat,JorLon
28 ! If time series locations have already been computed by calc_ts_locations,
29 ! assume that we have already read the 'tslist' file for this domain and return
31 IF ( grid%have_calculated_tslocs ) RETURN
33 #if ((EM_CORE == 1) && (DA_CORE != 1))
34 IF ( grid%dfi_opt == DFI_NODFI .OR. (grid%dfi_opt /= DFI_NODFI .AND. grid%dfi_stage == DFI_SETUP) ) THEN
36 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
39 IF ( grid%max_ts_locs <= 0 ) RETURN
41 IF ( wrf_dm_on_monitor() ) THEN
43 CALL wrf_tsin_exist ( exists )
47 iunit = get_unused_unit()
48 IF ( iunit <= 0 ) THEN
49 CALL wrf_error_fatal('Error in wrf_tsin: could not find a free Fortran unit.')
52 ! Input time series locations
53 OPEN(UNIT=iunit, FILE='tslist', FORM='formatted', STATUS='old', IOSTAT=istatus)
54 IF (istatus == 0) THEN
56 ! The header will be parsed to see if lat/lon or i/j is given...
57 READ(UNIT=iunit, FMT='(1X)')
58 READ(UNIT=iunit, FMT='(32X,A7,2X,A7)') IorLat, JorLon
59 READ(UNIT=iunit, FMT='(1X)')
60 grid%tslist_ij = .false.
61 ! If the header contains "LAT" and "LON",
62 ! then it will expect lat/lon coords in the file
63 ! If the header has "I" and "J",
64 ! then it will expect grid index coords in the file
65 IorLat = capitalize(IorLat)
66 JorLon = capitalize(JorLon)
67 if(index(IorLat,'LAT').ne.0 .and. index(JorLon,'LON').ne.0) then
68 grid%tslist_ij = .false.
69 elseif(index(IorLat,'I').ne.0 .and. index(JorLon,'J').ne.0) then
70 grid%tslist_ij = .true.
72 CALL wrf_error_fatal('Error in wrf_tsin: Header line requires either LAT LON or I J')
78 ! Read in time series locations
80 DO WHILE (istatus == 0)
81 IF (config_flags%map_proj == 0 .OR. grid%tslist_ij) THEN !ideal run will only use i,j
82 READ(UNIT=iunit, FMT='(A25,1X,A5,1X,I7,1X,I8)', IOSTAT=istatus) &
83 grid%desctsloc(grid%ntsloc+1), grid%nametsloc(grid%ntsloc+1), &
84 grid%itsloc(grid%ntsloc+1), grid%jtsloc(grid%ntsloc+1)
86 READ(UNIT=iunit, FMT='(A25,1X,A5,1X,F7.3,1X,F8.3)', IOSTAT=istatus) &
87 grid%desctsloc(grid%ntsloc+1), grid%nametsloc(grid%ntsloc+1), &
88 grid%lattsloc(grid%ntsloc+1), grid%lontsloc(grid%ntsloc+1)
90 IF (istatus == 0) grid%ntsloc = grid%ntsloc + 1
92 WRITE(errmess, FMT='(I4)') grid%ntsloc + 4 ! Three extra for the header of the file
93 ! One extra for the line we incorrectly read
94 CALL wrf_message('Error in tslist, line '//trim(errmess))
95 CALL wrf_error_fatal('Error --- Maybe check that the header (I,J) vs (LAT,LON) matches the provided information')
96 EXIT ! (technically unecessary, as we will exit the loop anyway)
98 IF ( ( grid%ntsloc == 1 ) .and. ( .NOT. grid%tslist_ij ) ) THEN
99 IF ( ( ABS(grid%lattsloc(grid%ntsloc)) <= 0.1 ) .and. &
100 ( ABS(grid%lontsloc(grid%ntsloc)) <= 0.1 ) ) THEN
101 CALL wrf_message('WARNING ')
102 CALL wrf_message('WARNING --- Maybe you have (I,J) locations for the (LAT,LON) values in tslist?')
103 CALL wrf_message('WARNING --- Are you purposefully studying Null Island?')
104 CALL wrf_message('WARNING ')
107 IF ( grid%ntsloc >= grid%max_ts_locs ) THEN
108 IF ( istatus == 0 ) THEN ! Assume there were more lines in the file
109 WRITE(errmess, FMT='(A,I4,A)') 'Ignoring all time series locations beyond #', &
110 grid%ntsloc,'. Increase max_ts_locs in namelist.input'
111 CALL wrf_message(trim(errmess))
121 END IF ! tslist file exists
126 CALL wrf_dm_bcast_integer(grid%ntsloc, 1)
127 CALL wrf_dm_bcast_integer(grid%tslist_ij, 1)
128 CALL wrf_dm_bcast_real(grid%lattsloc, grid%max_ts_locs)
129 CALL wrf_dm_bcast_real(grid%lontsloc, grid%max_ts_locs)
130 CALL wrf_dm_bcast_integer(grid%itsloc, grid%max_ts_locs)
131 CALL wrf_dm_bcast_integer(grid%jtsloc, grid%max_ts_locs)
133 #if ((EM_CORE == 1) && (DA_CORE != 1))
137 END SUBROUTINE wrf_tsin
139 SUBROUTINE wrf_tsin_exist ( exists )
141 LOGICAL , INTENT(OUT) :: exists
142 INQUIRE(FILE='tslist', EXIST=exists)
143 END SUBROUTINE wrf_tsin_exist
146 INTEGER FUNCTION get_unused_unit()
150 INTEGER, PARAMETER :: min_unit_number = 30
151 INTEGER, PARAMETER :: max_unit_number = 99
155 DO get_unused_unit = min_unit_number, max_unit_number
156 INQUIRE(UNIT=get_unused_unit, OPENED=opened)
157 IF ( .NOT. opened ) RETURN
164 END FUNCTION get_unused_unit