PageRenderTime 60ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/external/io_grib1/io_grib1.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 3560 lines | 2077 code | 693 blank | 790 comment | 215 complexity | 711faad64316b7f9509963d31eec1ed4 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !*-----------------------------------------------------------------------------
  2. !*
  3. !* Todd Hutchinson
  4. !* WSI
  5. !* 400 Minuteman Road
  6. !* Andover, MA 01810
  7. !* thutchinson@wsi.com
  8. !*
  9. !*-----------------------------------------------------------------------------
  10. !*
  11. !* This io_grib1 API is designed to read WRF input and write WRF output data
  12. !* in grib version 1 format.
  13. !*
  14. module gr1_data_info
  15. !*
  16. !* This module will hold data internal to this I/O implementation.
  17. !* The variables will be accessible by all functions (provided they have a
  18. !* "USE gr1_data_info" line).
  19. !*
  20. integer , parameter :: FATAL = 1
  21. integer , parameter :: DEBUG = 100
  22. integer , parameter :: DateStrLen = 19
  23. integer , parameter :: firstFileHandle = 8
  24. integer , parameter :: maxFileHandles = 30
  25. integer , parameter :: maxLevels = 1000
  26. integer , parameter :: maxSoilLevels = 100
  27. integer , parameter :: maxDomains = 500
  28. logical , dimension(maxFileHandles) :: committed, opened, used
  29. character*128, dimension(maxFileHandles) :: DataFile
  30. integer, dimension(maxFileHandles) :: FileFd
  31. integer, dimension(maxFileHandles) :: FileStatus
  32. REAL, dimension(maxLevels) :: half_eta, full_eta
  33. REAL, dimension(maxSoilLevels) :: soil_depth, soil_thickness
  34. character*24 :: StartDate = ''
  35. character*24 :: InputProgramName = ''
  36. integer :: projection
  37. integer :: wg_grid_id
  38. real :: dx,dy
  39. real :: truelat1, truelat2
  40. real :: center_lat, center_lon
  41. real :: proj_central_lon
  42. real :: timestep
  43. character, dimension(:), pointer :: grib_tables
  44. logical :: table_filled = .FALSE.
  45. character, dimension(:), pointer :: grid_info
  46. integer :: full_xsize, full_ysize
  47. integer, dimension(maxDomains) :: domains = -1
  48. integer :: this_domain = 0
  49. integer :: max_domain = 0
  50. TYPE :: HandleVar
  51. character, dimension(:), pointer :: fileindex(:)
  52. integer :: CurrentTime
  53. integer :: NumberTimes
  54. character (DateStrLen), dimension(:),pointer :: Times(:)
  55. ENDTYPE
  56. TYPE (HandleVar), dimension(maxFileHandles) :: fileinfo
  57. TYPE :: prevdata
  58. integer :: fcst_secs_rainc
  59. integer :: fcst_secs_rainnc
  60. real, dimension(:,:), pointer :: rainc, rainnc
  61. END TYPE prevdata
  62. TYPE (prevdata), DIMENSION(500) :: lastdata
  63. TYPE :: initdata
  64. real, dimension(:,:), pointer :: snod
  65. END TYPE initdata
  66. TYPE (initdata), dimension(maxDomains) :: firstdata
  67. TYPE :: prestype
  68. real, dimension(:,:,:), pointer :: vals
  69. logical :: newtime
  70. character*120 :: lastDateStr
  71. END TYPE prestype
  72. character*120, dimension(maxDomains) :: lastDateStr
  73. TYPE (prestype), dimension(maxDomains) :: pressure
  74. TYPE (prestype), dimension(maxDomains) :: geopotential
  75. integer :: center, subcenter, parmtbl
  76. character(len=15000), dimension(firstFileHandle:maxFileHandles) :: td_output
  77. character(len=15000), dimension(firstFileHandle:maxFileHandles) :: ti_output
  78. logical :: WrfIOnotInitialized = .true.
  79. end module gr1_data_info
  80. subroutine ext_gr1_ioinit(SysDepInfo,Status)
  81. USE gr1_data_info
  82. implicit none
  83. #include "wrf_status_codes.h"
  84. #include "wrf_io_flags.h"
  85. CHARACTER*(*), INTENT(IN) :: SysDepInfo
  86. integer ,intent(out) :: Status
  87. integer :: i
  88. integer :: size, istat
  89. CHARACTER (LEN=300) :: wrf_err_message
  90. call wrf_debug ( DEBUG , 'Entering ext_gr1_ioinit')
  91. do i=firstFileHandle, maxFileHandles
  92. used(i) = .false.
  93. committed(i) = .false.
  94. opened(i) = .false.
  95. td_output(i) = ''
  96. ti_output(i) = ''
  97. enddo
  98. domains(:) = -1
  99. do i = 1, maxDomains
  100. pressure(i)%newtime = .false.
  101. pressure(i)%lastDateStr = ''
  102. geopotential(i)%newtime = .false.
  103. geopotential(i)%lastDateStr = ''
  104. lastDateStr(i) = ''
  105. enddo
  106. lastdata%fcst_secs_rainc = 0
  107. lastdata%fcst_secs_rainnc = 0
  108. FileStatus(1:maxFileHandles) = WRF_FILE_NOT_OPENED
  109. WrfIOnotInitialized = .false.
  110. Status = WRF_NO_ERR
  111. return
  112. end subroutine ext_gr1_ioinit
  113. !*****************************************************************************
  114. subroutine ext_gr1_ioexit(Status)
  115. USE gr1_data_info
  116. implicit none
  117. #include "wrf_status_codes.h"
  118. integer istat
  119. integer ,intent(out) :: Status
  120. call wrf_debug ( DEBUG , 'Entering ext_gr1_ioexit')
  121. if (table_filled) then
  122. CALL free_gribmap(grib_tables)
  123. DEALLOCATE(grib_tables, stat=istat)
  124. table_filled = .FALSE.
  125. endif
  126. IF ( ASSOCIATED ( grid_info ) ) THEN
  127. DEALLOCATE(grid_info, stat=istat)
  128. ENDIF
  129. NULLIFY(grid_info)
  130. Status = WRF_NO_ERR
  131. return
  132. end subroutine ext_gr1_ioexit
  133. !*****************************************************************************
  134. SUBROUTINE ext_gr1_open_for_read_begin ( FileName , Comm_compute, Comm_io, &
  135. SysDepInfo, DataHandle , Status )
  136. USE gr1_data_info
  137. IMPLICIT NONE
  138. #include "wrf_status_codes.h"
  139. #include "wrf_io_flags.h"
  140. CHARACTER*(*) :: FileName
  141. INTEGER , INTENT(IN) :: Comm_compute , Comm_io
  142. CHARACTER*(*) :: SysDepInfo
  143. INTEGER , INTENT(OUT) :: DataHandle
  144. INTEGER , INTENT(OUT) :: Status
  145. integer :: ierr
  146. integer :: size
  147. integer :: idx
  148. integer :: parmid
  149. integer :: dpth_parmid
  150. integer :: thk_parmid
  151. integer :: leveltype
  152. integer , DIMENSION(1000) :: indices
  153. integer :: numindices
  154. real , DIMENSION(1000) :: levels
  155. real :: tmp
  156. integer :: swapped
  157. integer :: etaidx
  158. integer :: grb_index
  159. integer :: level1, level2
  160. integer :: tablenum
  161. integer :: stat
  162. integer :: endchar
  163. integer :: last_grb_index
  164. CHARACTER (LEN=300) :: wrf_err_message
  165. call wrf_debug ( DEBUG , 'Entering ext_gr1_open_for_read_begin')
  166. CALL gr1_get_new_handle(DataHandle)
  167. if (DataHandle .GT. 0) then
  168. CALL open_file(TRIM(FileName), 'r', FileFd(DataHandle), ierr)
  169. if (ierr .ne. 0) then
  170. Status = WRF_ERR_FATAL_BAD_FILE_STATUS
  171. else
  172. opened(DataHandle) = .true.
  173. DataFile(DataHandle) = TRIM(FileName)
  174. FileStatus(DataHandle) = WRF_FILE_OPENED_NOT_COMMITTED
  175. endif
  176. else
  177. Status = WRF_WARN_TOO_MANY_FILES
  178. return
  179. endif
  180. ! Read the grib index file first
  181. if (.NOT. table_filled) then
  182. table_filled = .TRUE.
  183. CALL GET_GRIB1_TABLES_SIZE(size)
  184. ALLOCATE(grib_tables(1:size), STAT=ierr)
  185. CALL LOAD_GRIB1_TABLES ("gribmap.txt", grib_tables, ierr)
  186. if (ierr .ne. 0) then
  187. DEALLOCATE(grib_tables)
  188. WRITE( wrf_err_message , * ) &
  189. 'Could not open file gribmap.txt '
  190. CALL wrf_error_fatal ( TRIM ( wrf_err_message ) )
  191. Status = WRF_ERR_FATAL_BAD_FILE_STATUS
  192. return
  193. endif
  194. endif
  195. ! Begin by indexing file and reading metadata into structure.
  196. CALL GET_FILEINDEX_SIZE(size)
  197. ALLOCATE(fileinfo(DataHandle)%fileindex(1:size), STAT=ierr)
  198. CALL ALLOC_INDEX_FILE(fileinfo(DataHandle)%fileindex(:))
  199. CALL INDEX_FILE(FileFd(DataHandle),fileinfo(DataHandle)%fileindex(:))
  200. ! Get times into Times variable
  201. CALL GET_NUM_TIMES(fileinfo(DataHandle)%fileindex(:), &
  202. fileinfo(DataHandle)%NumberTimes);
  203. ALLOCATE(fileinfo(DataHandle)%Times(1:fileinfo(DataHandle)%NumberTimes), STAT=ierr)
  204. do idx = 1,fileinfo(DataHandle)%NumberTimes
  205. CALL GET_TIME(fileinfo(DataHandle)%fileindex(:),idx, &
  206. fileinfo(DataHandle)%Times(idx))
  207. enddo
  208. ! CurrentTime starts as 0. The first time in the file is 1. So,
  209. ! until set_time or get_next_time is called, the current time
  210. ! is not set.
  211. fileinfo(DataHandle)%CurrentTime = 0
  212. CALL gr1_fill_eta_levels(fileinfo(DataHandle)%fileindex(:), &
  213. FileFd(DataHandle), &
  214. grib_tables, "ZNW", full_eta)
  215. CALL gr1_fill_eta_levels(fileinfo(DataHandle)%fileindex(:), FileFd(DataHandle), &
  216. grib_tables, "ZNU", half_eta)
  217. !
  218. ! Now, get the soil levels
  219. !
  220. CALL GET_GRIB_PARAM(grib_tables, "ZS", center, subcenter, parmtbl, &
  221. tablenum, dpth_parmid)
  222. CALL GET_GRIB_PARAM(grib_tables,"DZS", center, subcenter, parmtbl, &
  223. tablenum, thk_parmid)
  224. if (dpth_parmid == -1) then
  225. call wrf_message ('Error getting grib parameter')
  226. endif
  227. leveltype = 112
  228. CALL GET_GRIB_INDICES(fileinfo(DataHandle)%fileindex(:),center, subcenter, parmtbl, &
  229. dpth_parmid,"*",leveltype, &
  230. -HUGE(1),-HUGE(1), -HUGE(1),-HUGE(1),indices,numindices)
  231. last_grb_index = -1;
  232. do idx = 1,numindices
  233. CALL READ_GRIB(fileinfo(DataHandle)%fileindex(:), FileFd(DataHandle), &
  234. indices(idx), soil_depth(idx))
  235. !
  236. ! Now read the soil thickenesses
  237. !
  238. CALL GET_LEVEL1(fileinfo(DataHandle)%fileindex(:),indices(idx),level1)
  239. CALL GET_LEVEL2(fileinfo(DataHandle)%fileindex(:),indices(idx),level2)
  240. CALL GET_GRIB_INDEX_GUESS(fileinfo(DataHandle)%fileindex(:), &
  241. center, subcenter, parmtbl, thk_parmid,"*",leveltype, &
  242. level1,level2,-HUGE(1),-HUGE(1), last_grb_index+1, grb_index)
  243. CALL READ_GRIB(fileinfo(DataHandle)%fileindex(:),FileFd(DataHandle),grb_index, &
  244. soil_thickness(idx))
  245. last_grb_index = grb_index
  246. enddo
  247. !
  248. ! Fill up any variables that need to be retrieved from Metadata
  249. !
  250. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), 'PROGRAM_NAME', "none", &
  251. "none", InputProgramName, stat)
  252. if (stat /= 0) then
  253. CALL wrf_debug (DEBUG , "PROGRAM_NAME not found in input METADATA")
  254. else
  255. endchar = SCAN(InputProgramName," ")
  256. InputProgramName = InputProgramName(1:endchar)
  257. endif
  258. call wrf_debug ( DEBUG , 'Exiting ext_gr1_open_for_read_begin')
  259. RETURN
  260. END SUBROUTINE ext_gr1_open_for_read_begin
  261. !*****************************************************************************
  262. SUBROUTINE ext_gr1_open_for_read_commit( DataHandle , Status )
  263. USE gr1_data_info
  264. IMPLICIT NONE
  265. #include "wrf_status_codes.h"
  266. #include "wrf_io_flags.h"
  267. character(len=1000) :: msg
  268. INTEGER , INTENT(IN ) :: DataHandle
  269. INTEGER , INTENT(OUT) :: Status
  270. call wrf_debug ( DEBUG , 'Entering ext_gr1_open_for_read_commit')
  271. Status = WRF_NO_ERR
  272. if(WrfIOnotInitialized) then
  273. Status = WRF_IO_NOT_INITIALIZED
  274. write(msg,*) 'ext_gr1_ioinit was not called ',__FILE__,', line', __LINE__
  275. call wrf_debug ( FATAL , msg)
  276. return
  277. endif
  278. committed(DataHandle) = .true.
  279. FileStatus(DataHandle) = WRF_FILE_OPENED_FOR_READ
  280. Status = WRF_NO_ERR
  281. RETURN
  282. END SUBROUTINE ext_gr1_open_for_read_commit
  283. !*****************************************************************************
  284. SUBROUTINE ext_gr1_open_for_read ( FileName , Comm_compute, Comm_io, &
  285. SysDepInfo, DataHandle , Status )
  286. USE gr1_data_info
  287. IMPLICIT NONE
  288. #include "wrf_status_codes.h"
  289. #include "wrf_io_flags.h"
  290. CHARACTER*(*) :: FileName
  291. INTEGER , INTENT(IN) :: Comm_compute , Comm_io
  292. CHARACTER*(*) :: SysDepInfo
  293. INTEGER , INTENT(OUT) :: DataHandle
  294. INTEGER , INTENT(OUT) :: Status
  295. call wrf_debug ( DEBUG , 'Entering ext_gr1_open_for_read')
  296. DataHandle = 0 ! dummy setting to quiet warning message
  297. CALL ext_gr1_open_for_read_begin( FileName, Comm_compute, Comm_io, &
  298. SysDepInfo, DataHandle, Status )
  299. IF ( Status .EQ. WRF_NO_ERR ) THEN
  300. FileStatus(DataHandle) = WRF_FILE_OPENED_NOT_COMMITTED
  301. CALL ext_gr1_open_for_read_commit( DataHandle, Status )
  302. ENDIF
  303. return
  304. RETURN
  305. END SUBROUTINE ext_gr1_open_for_read
  306. !*****************************************************************************
  307. SUBROUTINE ext_gr1_open_for_write_begin(FileName, Comm, IOComm, SysDepInfo, &
  308. DataHandle, Status)
  309. USE gr1_data_info
  310. implicit none
  311. #include "wrf_status_codes.h"
  312. #include "wrf_io_flags.h"
  313. character*(*) ,intent(in) :: FileName
  314. integer ,intent(in) :: Comm
  315. integer ,intent(in) :: IOComm
  316. character*(*) ,intent(in) :: SysDepInfo
  317. integer ,intent(out) :: DataHandle
  318. integer ,intent(out) :: Status
  319. integer :: ierr
  320. CHARACTER (LEN=300) :: wrf_err_message
  321. integer :: size
  322. call wrf_debug ( DEBUG , 'Entering ext_gr1_open_for_write_begin')
  323. if (.NOT. table_filled) then
  324. table_filled = .TRUE.
  325. CALL GET_GRIB1_TABLES_SIZE(size)
  326. ALLOCATE(grib_tables(1:size), STAT=ierr)
  327. CALL LOAD_GRIB1_TABLES ("gribmap.txt", grib_tables, ierr)
  328. if (ierr .ne. 0) then
  329. DEALLOCATE(grib_tables)
  330. WRITE( wrf_err_message , * ) &
  331. 'Could not open file gribmap.txt '
  332. CALL wrf_error_fatal ( TRIM ( wrf_err_message ) )
  333. Status = WRF_ERR_FATAL_BAD_FILE_STATUS
  334. return
  335. endif
  336. endif
  337. Status = WRF_NO_ERR
  338. CALL gr1_get_new_handle(DataHandle)
  339. if (DataHandle .GT. 0) then
  340. CALL open_file(TRIM(FileName), 'w', FileFd(DataHandle), ierr)
  341. if (ierr .ne. 0) then
  342. Status = WRF_WARN_WRITE_RONLY_FILE
  343. else
  344. opened(DataHandle) = .true.
  345. DataFile(DataHandle) = TRIM(FileName)
  346. FileStatus(DataHandle) = WRF_FILE_OPENED_NOT_COMMITTED
  347. endif
  348. committed(DataHandle) = .false.
  349. td_output(DataHandle) = ''
  350. else
  351. Status = WRF_WARN_TOO_MANY_FILES
  352. endif
  353. RETURN
  354. END SUBROUTINE ext_gr1_open_for_write_begin
  355. !*****************************************************************************
  356. SUBROUTINE ext_gr1_open_for_write_commit( DataHandle , Status )
  357. USE gr1_data_info
  358. IMPLICIT NONE
  359. #include "wrf_status_codes.h"
  360. #include "wrf_io_flags.h"
  361. INTEGER , INTENT(IN ) :: DataHandle
  362. INTEGER , INTENT(OUT) :: Status
  363. call wrf_debug ( DEBUG , 'Entering ext_gr1_open_for_write_commit')
  364. IF ( opened( DataHandle ) ) THEN
  365. IF ( used( DataHandle ) ) THEN
  366. committed(DataHandle) = .true.
  367. FileStatus(DataHandle) = WRF_FILE_OPENED_FOR_WRITE
  368. ENDIF
  369. ENDIF
  370. Status = WRF_NO_ERR
  371. RETURN
  372. END SUBROUTINE ext_gr1_open_for_write_commit
  373. !*****************************************************************************
  374. subroutine ext_gr1_inquiry (Inquiry, Result, Status)
  375. use gr1_data_info
  376. implicit none
  377. #include "wrf_status_codes.h"
  378. character *(*), INTENT(IN) :: Inquiry
  379. character *(*), INTENT(OUT) :: Result
  380. integer ,INTENT(INOUT) :: Status
  381. SELECT CASE (Inquiry)
  382. CASE ("RANDOM_WRITE","RANDOM_READ")
  383. Result='ALLOW'
  384. CASE ("SEQUENTIAL_WRITE","SEQUENTIAL_READ")
  385. Result='NO'
  386. CASE ("OPEN_READ", "OPEN_WRITE", "OPEN_COMMIT_WRITE")
  387. Result='REQUIRE'
  388. CASE ("OPEN_COMMIT_READ","PARALLEL_IO")
  389. Result='NO'
  390. CASE ("SELF_DESCRIBING","SUPPORT_METADATA","SUPPORT_3D_FIELDS")
  391. Result='YES'
  392. CASE ("MEDIUM")
  393. Result ='FILE'
  394. CASE DEFAULT
  395. Result = 'No Result for that inquiry!'
  396. END SELECT
  397. Status=WRF_NO_ERR
  398. return
  399. end subroutine ext_gr1_inquiry
  400. !*****************************************************************************
  401. SUBROUTINE ext_gr1_inquire_opened ( DataHandle, FileName , FileStat, Status )
  402. USE gr1_data_info
  403. IMPLICIT NONE
  404. #include "wrf_status_codes.h"
  405. #include "wrf_io_flags.h"
  406. INTEGER , INTENT(IN) :: DataHandle
  407. CHARACTER*(*) :: FileName
  408. INTEGER , INTENT(OUT) :: FileStat
  409. INTEGER , INTENT(OUT) :: Status
  410. call wrf_debug ( DEBUG , 'Entering ext_gr1_inquire_opened')
  411. FileStat = WRF_NO_ERR
  412. if ((DataHandle .ge. firstFileHandle) .and. &
  413. (DataHandle .le. maxFileHandles)) then
  414. FileStat = FileStatus(DataHandle)
  415. else
  416. FileStat = WRF_FILE_NOT_OPENED
  417. endif
  418. Status = FileStat
  419. RETURN
  420. END SUBROUTINE ext_gr1_inquire_opened
  421. !*****************************************************************************
  422. SUBROUTINE ext_gr1_ioclose ( DataHandle, Status )
  423. USE gr1_data_info
  424. IMPLICIT NONE
  425. #include "wrf_status_codes.h"
  426. INTEGER DataHandle, Status
  427. INTEGER istat
  428. INTEGER ierr
  429. character(len=1000) :: outstring
  430. character :: lf
  431. lf=char(10)
  432. call wrf_debug ( DEBUG , 'Entering ext_gr1_ioclose')
  433. Status = WRF_NO_ERR
  434. CALL write_file(FileFd(DataHandle), lf//'<METADATA>'//lf,ierr)
  435. outstring = &
  436. '<!-- The following are fields that were supplied to the WRF I/O API.'//lf//&
  437. 'Many variables (but not all) are redundant with the variables within '//lf//&
  438. 'the grib headers. They are stored here, as METADATA, so that the '//lf//&
  439. 'WRF I/O API has simple access to these variables.-->'
  440. CALL write_file(FileFd(DataHandle), trim(outstring), ierr)
  441. if (trim(ti_output(DataHandle)) /= '') then
  442. CALL write_file(FileFd(DataHandle), trim(ti_output(DataHandle)), ierr)
  443. CALL write_file(FileFd(DataHandle), lf, ierr)
  444. endif
  445. if (trim(td_output(DataHandle)) /= '') then
  446. CALL write_file(FileFd(DataHandle), trim(td_output(DataHandle)), ierr)
  447. CALL write_file(FileFd(DataHandle), lf, ierr)
  448. endif
  449. CALL write_file(FileFd(DataHandle), '</METADATA>'//lf,ierr)
  450. ti_output(DataHandle) = ''
  451. td_output(DataHandle) = ''
  452. if (ierr .ne. 0) then
  453. Status = WRF_WARN_WRITE_RONLY_FILE
  454. endif
  455. CALL close_file(FileFd(DataHandle))
  456. used(DataHandle) = .false.
  457. RETURN
  458. END SUBROUTINE ext_gr1_ioclose
  459. !*****************************************************************************
  460. SUBROUTINE ext_gr1_write_field( DataHandle , DateStrIn , VarName , &
  461. Field , FieldType , Comm , IOComm, &
  462. DomainDesc , MemoryOrder , Stagger , &
  463. DimNames , &
  464. DomainStart , DomainEnd , &
  465. MemoryStart , MemoryEnd , &
  466. PatchStart , PatchEnd , &
  467. Status )
  468. USE gr1_data_info
  469. IMPLICIT NONE
  470. #include "wrf_status_codes.h"
  471. #include "wrf_io_flags.h"
  472. #include "wrf_projection.h"
  473. INTEGER , INTENT(IN) :: DataHandle
  474. CHARACTER*(*) :: DateStrIn
  475. CHARACTER(DateStrLen) :: DateStr
  476. CHARACTER*(*) :: VarName
  477. CHARACTER*120 :: OutName
  478. CHARACTER(120) :: TmpVarName
  479. integer ,intent(in) :: FieldType
  480. integer ,intent(inout) :: Comm
  481. integer ,intent(inout) :: IOComm
  482. integer ,intent(in) :: DomainDesc
  483. character*(*) ,intent(in) :: MemoryOrder
  484. character*(*) ,intent(in) :: Stagger
  485. character*(*) , dimension (*) ,intent(in) :: DimNames
  486. integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
  487. integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
  488. integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
  489. integer ,intent(out) :: Status
  490. integer :: ierror
  491. character (120) :: msg
  492. integer :: xsize, ysize, zsize
  493. integer :: x, y, z
  494. integer :: x_start,x_end,y_start,y_end,z_start,z_end,ndim
  495. integer :: idx
  496. integer :: proj_center_flag
  497. logical :: vert_stag = .false.
  498. integer :: levelnum
  499. real, DIMENSION(:,:), POINTER :: data,tmpdata
  500. integer, DIMENSION(:), POINTER :: mold
  501. integer :: istat
  502. integer :: accum_period
  503. integer :: size
  504. integer, dimension(1000) :: level1, level2
  505. real, DIMENSION( 1:1,MemoryStart(1):MemoryEnd(1), &
  506. MemoryStart(2):MemoryEnd(2), &
  507. MemoryStart(3):MemoryEnd(3) ) :: Field
  508. real :: fcst_secs
  509. logical :: soil_layers, fraction
  510. integer :: vert_unit
  511. integer :: abc(2,2,2)
  512. integer :: def(8)
  513. logical :: output = .true.
  514. integer :: idx1, idx2, idx3
  515. logical :: new_domain
  516. real :: region_center_lat, region_center_lon
  517. integer :: dom_xsize, dom_ysize;
  518. integer :: ierr
  519. logical :: already_have_domain
  520. call wrf_debug ( DEBUG , 'Entering ext_gr1_write_field for parameter'//VarName)
  521. !
  522. ! If DateStr is all 0's, we reset it to StartDate (if StartDate exists).
  523. ! For some reason,
  524. ! in idealized simulations, StartDate is 0001-01-01_00:00:00 while
  525. ! the first DateStr is 0000-00-00_00:00:00.
  526. !
  527. if (DateStrIn .eq. '0000-00-00_00:00:00') then
  528. if (StartDate .ne. '') then
  529. DateStr = TRIM(StartDate)
  530. else
  531. DateStr = '0001-01-01_00:00:00'
  532. endif
  533. else
  534. DateStr = DateStrIn
  535. endif
  536. !
  537. ! Check if this is a domain that we haven't seen yet. If so, add it to
  538. ! the list of domains.
  539. !
  540. new_domain = .false.
  541. already_have_domain = .false.
  542. do idx = 1, max_domain
  543. if (this_domain .eq. domains(idx)) then
  544. already_have_domain = .true.
  545. endif
  546. enddo
  547. if (.NOT. already_have_domain) then
  548. max_domain = max_domain + 1
  549. domains(max_domain) = this_domain
  550. new_domain = .true.
  551. endif
  552. !
  553. ! If the time has changed, we open a new file. This is a kludge to get
  554. ! around slowness in WRF that occurs when opening a new data file the
  555. ! standard way.
  556. !
  557. #ifdef GRIB_ONE_TIME_PER_FILE
  558. if (lastDateStr(this_domain) .ne. DateStr) then
  559. write(DataFile(DataHandle),'(A8,i2.2,A1,A19)') 'wrfout_d',this_domain,'_',DateStr
  560. call ext_gr1_ioclose ( DataHandle, Status )
  561. CALL open_file(TRIM(DataFile(DataHandle)), 'w', FileFd(DataHandle), ierr)
  562. if (ierr .ne. 0) then
  563. print *,'Could not open new file: ',DataFile(DataHandle)
  564. print *,' Appending to old file.'
  565. else
  566. ! Just set used back to .true. here, since ioclose set it to false.
  567. used(DataHandle) = .true.
  568. endif
  569. td_output(DataHandle) = ''
  570. endif
  571. lastDateStr(this_domain) = DateStr
  572. #endif
  573. output = .true.
  574. zsize = 1
  575. xsize = 1
  576. ysize = 1
  577. OutName = VarName
  578. soil_layers = .false.
  579. fraction = .false.
  580. ! First, handle then special cases for the boundary data.
  581. CALL get_dims(MemoryOrder, PatchStart, PatchEnd, ndim, x_start, x_end, &
  582. y_start, y_end,z_start,z_end)
  583. xsize = x_end - x_start + 1
  584. ysize = y_end - y_start + 1
  585. zsize = z_end - z_start + 1
  586. do idx = 1, len(MemoryOrder)
  587. if ((MemoryOrder(idx:idx) .eq. 'Z') .and. &
  588. (DimNames(idx) .eq. 'soil_layers_stag')) then
  589. soil_layers = .true.
  590. else if ((OutName .eq. 'LANDUSEF') .or. (OutName .eq. 'SOILCBOT') .or. &
  591. (OutName .eq. 'SOILCTOP')) then
  592. fraction = .true.
  593. endif
  594. enddo
  595. if (.not. ASSOCIATED(grid_info)) then
  596. CALL get_grid_info_size(size)
  597. ALLOCATE(grid_info(1:size), STAT=istat)
  598. if (istat .eq. -1) then
  599. DEALLOCATE(grid_info)
  600. Status = WRF_ERR_FATAL_BAD_FILE_STATUS
  601. return
  602. endif
  603. endif
  604. if (new_domain) then
  605. ALLOCATE(firstdata(this_domain)%snod(xsize,ysize))
  606. firstdata(this_domain)%snod(:,:) = 0.0
  607. ALLOCATE(lastdata(this_domain)%rainc(xsize,ysize))
  608. lastdata(this_domain)%rainc(:,:) = 0.0
  609. ALLOCATE(lastdata(this_domain)%rainnc(xsize,ysize))
  610. lastdata(this_domain)%rainnc(:,:) = 0.0
  611. endif
  612. if (zsize .eq. 0) then
  613. zsize = 1
  614. endif
  615. ALLOCATE(data(1:xsize,1:ysize), STAT=istat)
  616. ALLOCATE(mold(1:ysize), STAT=istat)
  617. ALLOCATE(tmpdata(1:xsize,1:ysize), STAT=istat)
  618. if (OutName .eq. 'ZNU') then
  619. do idx = 1, zsize
  620. half_eta(idx) = Field(1,idx,1,1)
  621. enddo
  622. endif
  623. if (OutName .eq. 'ZNW') then
  624. do idx = 1, zsize
  625. full_eta(idx) = Field(1,idx,1,1)
  626. enddo
  627. endif
  628. if (OutName .eq. 'ZS') then
  629. do idx = 1, zsize
  630. soil_depth(idx) = Field(1,idx,1,1)
  631. enddo
  632. endif
  633. if (OutName .eq. 'DZS') then
  634. do idx = 1, zsize
  635. soil_thickness(idx) = Field(1,idx,1,1)
  636. enddo
  637. endif
  638. if ((xsize .lt. 1) .or. (ysize .lt. 1)) then
  639. write(msg,*) 'Cannot output field with memory order: ', &
  640. MemoryOrder,Varname
  641. call wrf_message(msg)
  642. return
  643. endif
  644. call get_vert_stag(OutName,Stagger,vert_stag)
  645. do idx = 1, zsize
  646. call gr1_get_levels(OutName, idx, zsize, soil_layers, vert_stag, fraction, &
  647. vert_unit, level1(idx), level2(idx))
  648. enddo
  649. !
  650. ! Get the center lat/lon for the area being output. For some cases (such
  651. ! as for boundary areas, the center of the area is different from the
  652. ! center of the model grid.
  653. !
  654. if (index(Stagger,'X') .le. 0) then
  655. dom_xsize = full_xsize - 1
  656. else
  657. dom_xsize = full_xsize
  658. endif
  659. if (index(Stagger,'Y') .le. 0) then
  660. dom_ysize = full_ysize - 1
  661. else
  662. dom_ysize = full_ysize
  663. endif
  664. !
  665. ! Handle case of polare stereographic centered on pole. In that case,
  666. ! always set center lon to be the projection central longitude.
  667. !
  668. if ((projection .eq. WRF_POLAR_STEREO) .AND. &
  669. (abs(center_lat - 90.0) < 0.01)) then
  670. center_lon = proj_central_lon
  671. endif
  672. CALL get_region_center(MemoryOrder, projection, center_lat, center_lon, &
  673. dom_xsize, dom_ysize, dx, dy, proj_central_lon, proj_center_flag, &
  674. truelat1, truelat2, xsize, ysize, region_center_lat, region_center_lon)
  675. if ( .not. opened(DataHandle)) then
  676. Status = WRF_WARN_FILE_NOT_OPENED
  677. return
  678. endif
  679. if (opened(DataHandle) .and. committed(DataHandle)) then
  680. #ifdef OUTPUT_FULL_PRESSURE
  681. !
  682. ! The following is a kludge to output full pressure instead of the two
  683. ! fields of base-state pressure and pressure perturbation.
  684. !
  685. ! This code can be turned on by adding -DOUTPUT_FULL_PRESSURE to the
  686. ! compile line
  687. !
  688. if ((OutName .eq. 'P') .or. (OutName.eq.'PB')) then
  689. do idx = 1, len(MemoryOrder)
  690. if (MemoryOrder(idx:idx) .eq. 'X') then
  691. idx1=idx
  692. endif
  693. if (MemoryOrder(idx:idx) .eq. 'Y') then
  694. idx2=idx
  695. endif
  696. if (MemoryOrder(idx:idx) .eq. 'Z') then
  697. idx3=idx
  698. endif
  699. enddo
  700. !
  701. ! Allocate space for pressure values (this variable holds
  702. ! base-state pressure or pressure perturbation to be used
  703. ! later to sum base-state and perturbation pressure to get full
  704. ! pressure).
  705. !
  706. if (.not. ASSOCIATED(pressure(this_domain)%vals)) then
  707. ALLOCATE(pressure(this_domain)%vals(MemoryStart(1):MemoryEnd(1), &
  708. MemoryStart(2):MemoryEnd(2),MemoryStart(3):MemoryEnd(3)))
  709. endif
  710. if (DateStr .NE. &
  711. pressure(this_domain)%lastDateStr) then
  712. pressure(this_domain)%newtime = .true.
  713. endif
  714. if (pressure(this_domain)%newtime) then
  715. pressure(this_domain)%vals = Field(1,:,:,:)
  716. pressure(this_domain)%newtime = .false.
  717. output = .false.
  718. else
  719. output = .true.
  720. endif
  721. pressure(this_domain)%lastDateStr=DateStr
  722. endif
  723. #endif
  724. #ifdef OUTPUT_FULL_GEOPOTENTIAL
  725. !
  726. ! The following is a kludge to output full geopotential height instead
  727. ! of the two fields of base-state geopotential and perturbation
  728. ! geopotential.
  729. !
  730. ! This code can be turned on by adding -DOUTPUT_FULL_GEOPOTENTIAL to the
  731. ! compile line
  732. !
  733. if ((OutName .eq. 'PHB') .or. (OutName.eq.'PH')) then
  734. do idx = 1, len(MemoryOrder)
  735. if (MemoryOrder(idx:idx) .eq. 'X') then
  736. idx1=idx
  737. endif
  738. if (MemoryOrder(idx:idx) .eq. 'Y') then
  739. idx2=idx
  740. endif
  741. if (MemoryOrder(idx:idx) .eq. 'Z') then
  742. idx3=idx
  743. endif
  744. enddo
  745. !
  746. ! Allocate space for geopotential values (this variable holds
  747. ! geopotential to be used
  748. ! later to sum base-state and perturbation to get full
  749. ! geopotential).
  750. !
  751. if (.not. ASSOCIATED(geopotential(this_domain)%vals)) then
  752. ALLOCATE(geopotential(this_domain)%vals(MemoryStart(1):MemoryEnd(1), &
  753. MemoryStart(2):MemoryEnd(2),MemoryStart(3):MemoryEnd(3)))
  754. endif
  755. if (DateStr .NE. &
  756. geopotential(this_domain)%lastDateStr) then
  757. geopotential(this_domain)%newtime = .true.
  758. endif
  759. if (geopotential(this_domain)%newtime) then
  760. geopotential(this_domain)%vals = Field(1,:,:,:)
  761. geopotential(this_domain)%newtime = .false.
  762. output = .false.
  763. else
  764. output = .true.
  765. endif
  766. geopotential(this_domain)%lastDateStr=DateStr
  767. endif
  768. #endif
  769. if (output) then
  770. if (StartDate == '') then
  771. StartDate = DateStr
  772. endif
  773. CALL geth_idts(DateStr,StartDate,fcst_secs)
  774. if (center_lat .lt. 0) then
  775. proj_center_flag = 2
  776. else
  777. proj_center_flag = 1
  778. endif
  779. do z = 1, zsize
  780. SELECT CASE (MemoryOrder)
  781. CASE ('XYZ')
  782. data = Field(1,1:xsize,1:ysize,z)
  783. CASE ('XZY')
  784. data = Field(1,1:xsize,z,1:ysize)
  785. CASE ('YXZ')
  786. do x = 1,xsize
  787. do y = 1,ysize
  788. data(x,y) = Field(1,y,x,z)
  789. enddo
  790. enddo
  791. CASE ('YZX')
  792. do x = 1,xsize
  793. do y = 1,ysize
  794. data(x,y) = Field(1,y,z,x)
  795. enddo
  796. enddo
  797. CASE ('ZXY')
  798. data = Field(1,z,1:xsize,1:ysize)
  799. CASE ('ZYX')
  800. do x = 1,xsize
  801. do y = 1,ysize
  802. data(x,y) = Field(1,z,y,x)
  803. enddo
  804. enddo
  805. CASE ('XY')
  806. data = Field(1,1:xsize,1:ysize,1)
  807. CASE ('YX')
  808. do x = 1,xsize
  809. do y = 1,ysize
  810. data(x,y) = Field(1,y,x,1)
  811. enddo
  812. enddo
  813. CASE ('XSZ')
  814. do x = 1,xsize
  815. do y = 1,ysize
  816. data(x,y) = Field(1,y,z,x)
  817. enddo
  818. enddo
  819. CASE ('XEZ')
  820. do x = 1,xsize
  821. do y = 1,ysize
  822. data(x,y) = Field(1,y,z,x)
  823. enddo
  824. enddo
  825. CASE ('YSZ')
  826. do x = 1,xsize
  827. do y = 1,ysize
  828. data(x,y) = Field(1,x,z,y)
  829. enddo
  830. enddo
  831. CASE ('YEZ')
  832. do x = 1,xsize
  833. do y = 1,ysize
  834. data(x,y) = Field(1,x,z,y)
  835. enddo
  836. enddo
  837. CASE ('XS')
  838. do x = 1,xsize
  839. do y = 1,ysize
  840. data(x,y) = Field(1,y,x,1)
  841. enddo
  842. enddo
  843. CASE ('XE')
  844. do x = 1,xsize
  845. do y = 1,ysize
  846. data(x,y) = Field(1,y,x,1)
  847. enddo
  848. enddo
  849. CASE ('YS')
  850. do x = 1,xsize
  851. do y = 1,ysize
  852. data(x,y) = Field(1,x,y,1)
  853. enddo
  854. enddo
  855. CASE ('YE')
  856. do x = 1,xsize
  857. do y = 1,ysize
  858. data(x,y) = Field(1,x,y,1)
  859. enddo
  860. enddo
  861. CASE ('Z')
  862. data(1,1) = Field(1,z,1,1)
  863. CASE ('z')
  864. data(1,1) = Field(1,z,1,1)
  865. CASE ('C')
  866. data = Field(1,1:xsize,1:ysize,z)
  867. CASE ('c')
  868. data = Field(1,1:xsize,1:ysize,z)
  869. CASE ('0')
  870. data(1,1) = Field(1,1,1,1)
  871. END SELECT
  872. !
  873. ! Here, we convert any integer fields to real
  874. !
  875. if (FieldType == WRF_INTEGER) then
  876. mold = 0
  877. do idx=1,xsize
  878. !
  879. ! The parentheses around data(idx,:) are needed in order
  880. ! to fix a bug with transfer with the xlf compiler on NCAR's
  881. ! IBM (bluesky).
  882. !
  883. data(idx,:)=transfer((data(idx,:)),mold)
  884. enddo
  885. endif
  886. !
  887. ! Here, we do any necessary conversions to the data.
  888. !
  889. ! Potential temperature is sometimes passed in as perturbation
  890. ! potential temperature (i.e., POT-300). Other times (i.e., from
  891. ! WRF SI), it is passed in as full potential temperature.
  892. ! Here, we convert to full potential temperature by adding 300
  893. ! only if POT < 200 K.
  894. !
  895. if (OutName == 'T') then
  896. if (data(1,1) < 200) then
  897. data = data + 300
  898. endif
  899. endif
  900. !
  901. ! For precip, we setup the accumulation period, and output a precip
  902. ! rate for time-step precip.
  903. !
  904. if (OutName .eq. 'RAINNCV') then
  905. ! Convert time-step precip to precip rate.
  906. data = data/timestep
  907. accum_period = 0
  908. else
  909. accum_period = 0
  910. endif
  911. #ifdef OUTPUT_FULL_PRESSURE
  912. !
  913. ! Computation of full-pressure off by default since there are
  914. ! uses for base-state and perturbation (i.e., restarts
  915. !
  916. if ((OutName .eq. 'P') .or. (OutName.eq.'PB')) then
  917. if (idx3 .eq. 1) then
  918. data = data + &
  919. pressure(this_domain)%vals(z, &
  920. patchstart(2):patchend(2),patchstart(3):patchend(3))
  921. elseif (idx3 .eq. 2) then
  922. data = data + &
  923. pressure(this_domain)%vals(patchstart(1):patchend(1), &
  924. z,patchstart(3):patchend(3))
  925. elseif (idx3 .eq. 3) then
  926. data = data + &
  927. pressure(this_domain)%vals(patchstart(1):patchend(1), &
  928. patchstart(2):patchend(2),z)
  929. else
  930. call wrf_message ('error in idx3, continuing')
  931. endif
  932. OutName = 'P'
  933. endif
  934. #endif
  935. #ifdef OUTPUT_FULL_GEOPOTENTIAL
  936. !
  937. ! Computation of full-geopotential off by default since there are
  938. ! uses for base-state and perturbation (i.e., restarts
  939. !
  940. if ((OutName .eq. 'PHB') .or. (OutName.eq.'PH')) then
  941. if (idx3 .eq. 1) then
  942. data = data + &
  943. geopotential(this_domain)%vals(z, &
  944. patchstart(2):patchend(2),patchstart(3):patchend(3))
  945. elseif (idx3 .eq. 2) then
  946. data = data + &
  947. geopotential(this_domain)%vals(patchstart(1):patchend(1), &
  948. z,patchstart(3):patchend(3))
  949. elseif (idx3 .eq. 3) then
  950. data = data + &
  951. geopotential(this_domain)%vals(patchstart(1):patchend(1), &
  952. patchstart(2):patchend(2),z)
  953. else
  954. call wrf_message ('error in idx3, continuing')
  955. endif
  956. OutName = 'PHP'
  957. endif
  958. #endif
  959. !
  960. ! Output current level
  961. !
  962. CALL load_grid_info(OutName, StartDate, vert_unit, level1(z), &
  963. level2(z), fcst_secs, accum_period, wg_grid_id, projection, &
  964. xsize, ysize, region_center_lat, region_center_lon, dx, dy, &
  965. proj_central_lon, proj_center_flag, truelat1, truelat2, &
  966. grib_tables, grid_info)
  967. !
  968. ! Here, we copy data to a temporary array. After write_grib,
  969. ! we copy back from the temporary array to the permanent
  970. ! array. write_grib modifies data. For certain fields that
  971. ! we use below, we want the original (unmodified) data
  972. ! values. This kludge assures that we have the original
  973. ! values.
  974. !
  975. if ((OutName .eq. 'RAINC') .or. (OutName .eq. 'RAINNC') .or. &
  976. (OutName .eq. 'SNOWH')) then
  977. tmpdata(:,:) = data(:,:)
  978. endif
  979. CALL write_grib(grid_info, FileFd(DataHandle), data)
  980. if ((OutName .eq. 'RAINC') .or. (OutName .eq. 'RAINNC') .or. &
  981. (OutName .eq. 'SNOWH')) then
  982. data(:,:) = tmpdata(:,:)
  983. endif
  984. CALL free_grid_info(grid_info)
  985. !
  986. ! If this is the total accumulated rain, call write_grib again
  987. ! to output the accumulation since the last output time as well.
  988. ! This is somewhat of a kludge to meet the requirements of PF.
  989. !
  990. if ((OutName .eq. 'RAINC') .or. (OutName .eq. 'RAINNC') .or. &
  991. (OutName .eq. 'SNOWH')) then
  992. if (OutName .eq. 'RAINC') then
  993. data(:,:) = data(:,:) - lastdata(this_domain)%rainc(:,:)
  994. lastdata(this_domain)%rainc(:,:) = tmpdata(:,:)
  995. accum_period = fcst_secs - &
  996. lastdata(this_domain)%fcst_secs_rainc
  997. lastdata(this_domain)%fcst_secs_rainc = fcst_secs
  998. TmpVarName = 'ACPCP'
  999. else if (OutName .eq. 'RAINNC') then
  1000. tmpdata(:,:) = data(:,:)
  1001. data(:,:) = data(:,:) - lastdata(this_domain)%rainnc(:,:)
  1002. lastdata(this_domain)%rainnc(:,:) = tmpdata(:,:)
  1003. accum_period = fcst_secs - &
  1004. lastdata(this_domain)%fcst_secs_rainnc
  1005. lastdata(this_domain)%fcst_secs_rainnc = fcst_secs
  1006. TmpVarName = 'NCPCP'
  1007. else if (OutName .eq. 'SNOWH') then
  1008. if (fcst_secs .eq. 0) then
  1009. firstdata(this_domain)%snod(:,:) = data(:,:)
  1010. endif
  1011. data(:,:) = data(:,:) - firstdata(this_domain)%snod(:,:)
  1012. TmpVarName = 'SNOWCU'
  1013. endif
  1014. CALL load_grid_info(TmpVarName, StartDate, vert_unit, level1(z),&
  1015. level2(z), fcst_secs, accum_period, wg_grid_id, &
  1016. projection, xsize, ysize, region_center_lat, &
  1017. region_center_lon, dx, dy, proj_central_lon, &
  1018. proj_center_flag, truelat1, truelat2, grib_tables, &
  1019. grid_info)
  1020. CALL write_grib(grid_info, FileFd(DataHandle), data)
  1021. CALL free_grid_info(grid_info)
  1022. endif
  1023. enddo
  1024. endif
  1025. endif
  1026. deallocate(data, STAT = istat)
  1027. deallocate(mold, STAT = istat)
  1028. deallocate(tmpdata, STAT = istat)
  1029. Status = WRF_NO_ERR
  1030. call wrf_debug ( DEBUG , 'Leaving ext_gr1_write_field')
  1031. RETURN
  1032. END SUBROUTINE ext_gr1_write_field
  1033. !*****************************************************************************
  1034. SUBROUTINE ext_gr1_read_field ( DataHandle , DateStr , VarName , Field , &
  1035. FieldType , Comm , IOComm, DomainDesc , MemoryOrder , Stagger , &
  1036. DimNames , DomainStart , DomainEnd , MemoryStart , MemoryEnd , &
  1037. PatchStart , PatchEnd , Status )
  1038. USE gr1_data_info
  1039. IMPLICIT NONE
  1040. #include "wrf_status_codes.h"
  1041. #include "wrf_io_flags.h"
  1042. INTEGER , INTENT(IN) :: DataHandle
  1043. CHARACTER*(*) :: DateStr
  1044. CHARACTER*(*) :: VarName
  1045. CHARACTER (len=400) :: msg
  1046. integer ,intent(inout) :: FieldType
  1047. integer ,intent(inout) :: Comm
  1048. integer ,intent(inout) :: IOComm
  1049. integer ,intent(inout) :: DomainDesc
  1050. character*(*) ,intent(inout) :: MemoryOrder
  1051. character*(*) ,intent(inout) :: Stagger
  1052. character*(*) , dimension (*) ,intent(inout) :: DimNames
  1053. integer ,dimension(*) ,intent(inout) :: DomainStart, DomainEnd
  1054. integer ,dimension(*) ,intent(inout) :: MemoryStart, MemoryEnd
  1055. integer ,dimension(*) ,intent(inout) :: PatchStart, PatchEnd
  1056. integer ,intent(out) :: Status
  1057. INTEGER ,intent(out) :: Field(*)
  1058. integer :: ndim,x_start,x_end,y_start,y_end,z_start,z_end
  1059. integer :: zidx
  1060. REAL, DIMENSION(:,:), POINTER :: data
  1061. logical :: vert_stag
  1062. logical :: soil_layers
  1063. integer :: level1,level2
  1064. integer :: parmid
  1065. integer :: vert_unit
  1066. integer :: grb_index
  1067. integer :: numcols, numrows
  1068. integer :: data_allocated
  1069. integer :: istat
  1070. integer :: tablenum
  1071. integer :: di
  1072. integer :: last_grb_index
  1073. call wrf_debug ( DEBUG , 'Entering ext_gr1_read_field')
  1074. !
  1075. ! Get dimensions of data.
  1076. ! Assume that the domain size in the input data is the same as the Domain
  1077. ! Size from the input arguments.
  1078. !
  1079. CALL get_dims(MemoryOrder,DomainStart,DomainEnd,ndim,x_start,x_end,y_start, &
  1080. y_end,z_start,z_end)
  1081. !
  1082. ! Get grib parameter id
  1083. !
  1084. CALL GET_GRIB_PARAM(grib_tables, VarName, center, subcenter, parmtbl, &
  1085. tablenum, parmid)
  1086. !
  1087. ! Setup the vertical unit and levels
  1088. !
  1089. CALL get_vert_stag(VarName,Stagger,vert_stag)
  1090. CALL get_soil_layers(VarName,soil_layers)
  1091. !
  1092. ! Loop over levels, grabbing data from each level, then assembling into a
  1093. ! 3D array.
  1094. !
  1095. data_allocated = 0
  1096. last_grb_index = -1
  1097. do zidx = z_start,z_end
  1098. CALL gr1_get_levels(VarName,zidx,z_end-z_start,soil_layers,vert_stag, &
  1099. .false., vert_unit,level1,level2)
  1100. CALL GET_GRIB_INDEX_VALIDTIME_GUESS(fileinfo(DataHandle)%fileindex(:), center, &
  1101. subcenter, parmtbl, parmid,DateStr,vert_unit,level1, &
  1102. level2, last_grb_index + 1, grb_index)
  1103. if (grb_index < 0) then
  1104. write(msg,*)'Field not found: parmid: ',VarName,parmid,DateStr, &
  1105. vert_unit,level1,level2
  1106. call wrf_debug (DEBUG , msg)
  1107. cycle
  1108. endif
  1109. if (data_allocated .eq. 0) then
  1110. CALL GET_SIZEOF_GRID(fileinfo(DataHandle)%fileindex(:),grb_index,numcols,numrows)
  1111. allocate(data(z_start:z_end,1:numcols*numrows),stat=istat)
  1112. data_allocated = 1
  1113. endif
  1114. CALL READ_GRIB(fileinfo(DataHandle)%fileindex(:), FileFd(DataHandle), grb_index, &
  1115. data(zidx,:))
  1116. !
  1117. ! Transpose data into the order specified by MemoryOrder, setting only
  1118. ! entries within the memory dimensions
  1119. !
  1120. CALL get_dims(MemoryOrder, MemoryStart, MemoryEnd, ndim, x_start, x_end, &
  1121. y_start, y_end,z_start,z_end)
  1122. if(FieldType == WRF_DOUBLE) then
  1123. di = 2
  1124. else
  1125. di = 1
  1126. endif
  1127. !
  1128. ! Here, we do any necessary conversions to the data.
  1129. !
  1130. ! The WRF executable (wrf.exe) expects perturbation potential
  1131. ! temperature. However, real.exe expects full potential T.
  1132. ! So, if the program is WRF, subtract 300 from Potential Temperature
  1133. ! to get perturbation potential temperature.
  1134. !
  1135. if (VarName == 'T') then
  1136. if ( &
  1137. (InputProgramName .eq. 'REAL_EM') .or. &
  1138. (InputProgramName .eq. 'IDEAL') .or. &
  1139. (InputProgramName .eq. 'NDOWN_EM')) then
  1140. data(zidx,:) = data(zidx,:) - 300
  1141. endif
  1142. endif
  1143. CALL Transpose_grib(MemoryOrder, di, FieldType, Field, &
  1144. MemoryStart(1), MemoryEnd(1), MemoryStart(2), MemoryEnd(2), &
  1145. MemoryStart(3), MemoryEnd(3), &
  1146. data(zidx,:), zidx, numrows, numcols)
  1147. if (zidx .eq. z_end) then
  1148. data_allocated = 0
  1149. deallocate(data)
  1150. endif
  1151. last_grb_index = grb_index
  1152. enddo
  1153. Status = WRF_NO_ERR
  1154. if (grb_index < 0) Status = WRF_WARN_VAR_NF
  1155. call wrf_debug ( DEBUG , 'Leaving ext_gr1_read_field')
  1156. RETURN
  1157. END SUBROUTINE ext_gr1_read_field
  1158. !*****************************************************************************
  1159. SUBROUTINE ext_gr1_get_next_var ( DataHandle, VarName, Status )
  1160. USE gr1_data_info
  1161. IMPLICIT NONE
  1162. #include "wrf_status_codes.h"
  1163. INTEGER , INTENT(IN) :: DataHandle
  1164. CHARACTER*(*) :: VarName
  1165. INTEGER , INTENT(OUT) :: Status
  1166. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_next_var')
  1167. call wrf_message ( 'WARNING: ext_gr1_get_next_var is not supported.')
  1168. Status = WRF_WARN_NOOP
  1169. RETURN
  1170. END SUBROUTINE ext_gr1_get_next_var
  1171. !*****************************************************************************
  1172. subroutine ext_gr1_end_of_frame(DataHandle, Status)
  1173. USE gr1_data_info
  1174. implicit none
  1175. #include "wrf_status_codes.h"
  1176. integer ,intent(in) :: DataHandle
  1177. integer ,intent(out) :: Status
  1178. call wrf_debug ( DEBUG , 'Entering ext_gr1_end_of_frame')
  1179. Status = WRF_WARN_NOOP
  1180. return
  1181. end subroutine ext_gr1_end_of_frame
  1182. !*****************************************************************************
  1183. SUBROUTINE ext_gr1_iosync ( DataHandle, Status )
  1184. USE gr1_data_info
  1185. IMPLICIT NONE
  1186. #include "wrf_status_codes.h"
  1187. INTEGER , INTENT(IN) :: DataHandle
  1188. INTEGER , INTENT(OUT) :: Status
  1189. call wrf_debug ( DEBUG , 'Entering ext_gr1_iosync')
  1190. Status = WRF_NO_ERR
  1191. if (DataHandle .GT. 0) then
  1192. CALL flush_file(FileFd(DataHandle))
  1193. else
  1194. Status = WRF_WARN_TOO_MANY_FILES
  1195. endif
  1196. RETURN
  1197. END SUBROUTINE ext_gr1_iosync
  1198. !*****************************************************************************
  1199. SUBROUTINE ext_gr1_inquire_filename ( DataHandle, FileName , FileStat, &
  1200. Status )
  1201. USE gr1_data_info
  1202. IMPLICIT NONE
  1203. #include "wrf_status_codes.h"
  1204. #include "wrf_io_flags.h"
  1205. INTEGER , INTENT(IN) :: DataHandle
  1206. CHARACTER*(*) :: FileName
  1207. INTEGER , INTENT(OUT) :: FileStat
  1208. INTEGER , INTENT(OUT) :: Status
  1209. CHARACTER *80 SysDepInfo
  1210. call wrf_debug ( DEBUG , 'Entering ext_gr1_inquire_filename')
  1211. FileName = DataFile(DataHandle)
  1212. if ((DataHandle .ge. firstFileHandle) .and. &
  1213. (DataHandle .le. maxFileHandles)) then
  1214. FileStat = FileStatus(DataHandle)
  1215. else
  1216. FileStat = WRF_FILE_NOT_OPENED
  1217. endif
  1218. Status = WRF_NO_ERR
  1219. RETURN
  1220. END SUBROUTINE ext_gr1_inquire_filename
  1221. !*****************************************************************************
  1222. SUBROUTINE ext_gr1_get_var_info ( DataHandle , VarName , NDim , &
  1223. MemoryOrder , Stagger , DomainStart , DomainEnd , WrfType, Status )
  1224. USE gr1_data_info
  1225. IMPLICIT NONE
  1226. #include "wrf_status_codes.h"
  1227. integer ,intent(in) :: DataHandle
  1228. character*(*) ,intent(in) :: VarName
  1229. integer ,intent(out) :: NDim
  1230. character*(*) ,intent(out) :: MemoryOrder
  1231. character*(*) ,intent(out) :: Stagger
  1232. integer ,dimension(*) ,intent(out) :: DomainStart, DomainEnd
  1233. integer ,intent(out) :: WrfType
  1234. integer ,intent(out) :: Status
  1235. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_info')
  1236. CALL wrf_message('ext_gr1_get_var_info not supported for grib version1 data')
  1237. Status = WRF_NO_ERR
  1238. RETURN
  1239. END SUBROUTINE ext_gr1_get_var_info
  1240. !*****************************************************************************
  1241. SUBROUTINE ext_gr1_set_time ( DataHandle, DateStr, Status )
  1242. USE gr1_data_info
  1243. IMPLICIT NONE
  1244. #include "wrf_status_codes.h"
  1245. INTEGER , INTENT(IN) :: DataHandle
  1246. CHARACTER*(*) :: DateStr
  1247. INTEGER , INTENT(OUT) :: Status
  1248. integer :: found_time
  1249. integer :: idx
  1250. call wrf_debug ( DEBUG , 'Entering ext_gr1_set_time')
  1251. found_time = 0
  1252. do idx = 1,fileinfo(DataHandle)%NumberTimes
  1253. if (fileinfo(DataHandle)%Times(idx) == DateStr) then
  1254. found_time = 1
  1255. fileinfo(DataHandle)%CurrentTime = idx
  1256. endif
  1257. enddo
  1258. if (found_time == 0) then
  1259. Status = WRF_WARN_TIME_NF
  1260. else
  1261. Status = WRF_NO_ERR
  1262. endif
  1263. RETURN
  1264. END SUBROUTINE ext_gr1_set_time
  1265. !*****************************************************************************
  1266. SUBROUTINE ext_gr1_get_next_time ( DataHandle, DateStr, Status )
  1267. USE gr1_data_info
  1268. IMPLICIT NONE
  1269. #include "wrf_status_codes.h"
  1270. INTEGER , INTENT(IN) :: DataHandle
  1271. CHARACTER*(*) , INTENT(OUT) :: DateStr
  1272. INTEGER , INTENT(OUT) :: Status
  1273. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_next_time')
  1274. if (fileinfo(DataHandle)%CurrentTime == fileinfo(DataHandle)%NumberTimes) then
  1275. Status = WRF_WARN_TIME_EOF
  1276. else
  1277. fileinfo(DataHandle)%CurrentTime = fileinfo(DataHandle)%CurrentTime + 1
  1278. DateStr = fileinfo(DataHandle)%Times(fileinfo(DataHandle)%CurrentTime)
  1279. Status = WRF_NO_ERR
  1280. endif
  1281. RETURN
  1282. END SUBROUTINE ext_gr1_get_next_time
  1283. !*****************************************************************************
  1284. SUBROUTINE ext_gr1_get_previous_time ( DataHandle, DateStr, Status )
  1285. USE gr1_data_info
  1286. IMPLICIT NONE
  1287. #include "wrf_status_codes.h"
  1288. INTEGER , INTENT(IN) :: DataHandle
  1289. CHARACTER*(*) :: DateStr
  1290. INTEGER , INTENT(OUT) :: Status
  1291. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_previous_time')
  1292. if (fileinfo(DataHandle)%CurrentTime <= 0) then
  1293. Status = WRF_WARN_TIME_EOF
  1294. else
  1295. fileinfo(DataHandle)%CurrentTime = fileinfo(DataHandle)%CurrentTime - 1
  1296. DateStr = fileinfo(DataHandle)%Times(fileinfo(DataHandle)%CurrentTime)
  1297. Status = WRF_NO_ERR
  1298. endif
  1299. RETURN
  1300. END SUBROUTINE ext_gr1_get_previous_time
  1301. !******************************************************************************
  1302. !* Start of get_var_ti_* routines
  1303. !******************************************************************************
  1304. SUBROUTINE ext_gr1_get_var_ti_real ( DataHandle,Element, Varname, Data, &
  1305. Count, Outcount, Status )
  1306. USE gr1_data_info
  1307. IMPLICIT NONE
  1308. #include "wrf_status_codes.h"
  1309. INTEGER , INTENT(IN) :: DataHandle
  1310. CHARACTER*(*) :: Element
  1311. CHARACTER*(*) :: VarName
  1312. real , INTENT(OUT) :: Data(*)
  1313. INTEGER , INTENT(IN) :: Count
  1314. INTEGER , INTENT(OUT) :: OutCount
  1315. INTEGER , INTENT(OUT) :: Status
  1316. INTEGER :: idx
  1317. INTEGER :: stat
  1318. CHARACTER*(1000) :: VALUE
  1319. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_real')
  1320. Status = WRF_NO_ERR
  1321. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  1322. Varname, Value, stat)
  1323. if (stat /= 0) then
  1324. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1325. Status = WRF_WARN_VAR_NF
  1326. RETURN
  1327. endif
  1328. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1329. if (stat .ne. 0) then
  1330. CALL wrf_message("Reading data from"//Value//"failed")
  1331. Status = WRF_WARN_COUNT_TOO_LONG
  1332. RETURN
  1333. endif
  1334. Outcount = idx
  1335. RETURN
  1336. END SUBROUTINE ext_gr1_get_var_ti_real
  1337. !*****************************************************************************
  1338. SUBROUTINE ext_gr1_get_var_ti_real8 ( DataHandle,Element, Varname, Data, &
  1339. Count, Outcount, Status )
  1340. USE gr1_data_info
  1341. IMPLICIT NONE
  1342. #include "wrf_status_codes.h"
  1343. INTEGER , INTENT(IN) :: DataHandle
  1344. CHARACTER*(*) :: Element
  1345. CHARACTER*(*) :: VarName
  1346. real*8 , INTENT(OUT) :: Data(*)
  1347. INTEGER , INTENT(IN) :: Count
  1348. INTEGER , INTENT(OUT) :: OutCount
  1349. INTEGER , INTENT(OUT) :: Status
  1350. INTEGER :: idx
  1351. INTEGER :: stat
  1352. CHARACTER*(1000) :: VALUE
  1353. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_real8')
  1354. Status = WRF_NO_ERR
  1355. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:),TRIM(Element),&
  1356. "none",Varname,Value,stat)
  1357. if (stat /= 0) then
  1358. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1359. Status = WRF_WARN_VAR_NF
  1360. RETURN
  1361. endif
  1362. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1363. if (stat .ne. 0) then
  1364. CALL wrf_message("Reading data from"//Value//"failed")
  1365. Status = WRF_WARN_COUNT_TOO_LONG
  1366. RETURN
  1367. endif
  1368. Outcount = idx
  1369. RETURN
  1370. END SUBROUTINE ext_gr1_get_var_ti_real8
  1371. !*****************************************************************************
  1372. SUBROUTINE ext_gr1_get_var_ti_double ( DataHandle,Element, Varname, Data, &
  1373. Count, Outcount, Status )
  1374. USE gr1_data_info
  1375. IMPLICIT NONE
  1376. #include "wrf_status_codes.h"
  1377. INTEGER , INTENT(IN) :: DataHandle
  1378. CHARACTER*(*) , INTENT(IN) :: Element
  1379. CHARACTER*(*) , INTENT(IN) :: VarName
  1380. real*8 , INTENT(OUT) :: Data(*)
  1381. INTEGER , INTENT(IN) :: Count
  1382. INTEGER , INTENT(OUT) :: OutCount
  1383. INTEGER , INTENT(OUT) :: Status
  1384. INTEGER :: idx
  1385. INTEGER :: stat
  1386. CHARACTER*(1000) :: VALUE
  1387. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_double')
  1388. Status = WRF_NO_ERR
  1389. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), &
  1390. "none", Varname, &
  1391. Value,stat)
  1392. if (stat /= 0) then
  1393. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1394. Status = WRF_WARN_VAR_NF
  1395. RETURN
  1396. endif
  1397. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1398. if (stat .ne. 0) then
  1399. CALL wrf_message("Reading data from"//Value//"failed")
  1400. Status = WRF_WARN_COUNT_TOO_LONG
  1401. RETURN
  1402. endif
  1403. Outcount = idx
  1404. RETURN
  1405. END SUBROUTINE ext_gr1_get_var_ti_double
  1406. !*****************************************************************************
  1407. SUBROUTINE ext_gr1_get_var_ti_integer ( DataHandle,Element, Varname, Data, &
  1408. Count, Outcount, Status )
  1409. USE gr1_data_info
  1410. IMPLICIT NONE
  1411. #include "wrf_status_codes.h"
  1412. INTEGER , INTENT(IN) :: DataHandle
  1413. CHARACTER*(*) :: Element
  1414. CHARACTER*(*) :: VarName
  1415. integer , INTENT(OUT) :: Data(*)
  1416. INTEGER , INTENT(IN) :: Count
  1417. INTEGER , INTENT(OUT) :: OutCount
  1418. INTEGER , INTENT(OUT) :: Status
  1419. INTEGER :: idx
  1420. INTEGER :: stat
  1421. CHARACTER*(1000) :: VALUE
  1422. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_integer')
  1423. Status = WRF_NO_ERR
  1424. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), &
  1425. "none", Varname, Value, stat)
  1426. if (stat /= 0) then
  1427. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1428. Status = WRF_WARN_VAR_NF
  1429. RETURN
  1430. endif
  1431. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1432. if (stat .ne. 0) then
  1433. CALL wrf_message("Reading data from"//Value//"failed")
  1434. Status = WRF_WARN_COUNT_TOO_LONG
  1435. RETURN
  1436. endif
  1437. Outcount = idx
  1438. RETURN
  1439. END SUBROUTINE ext_gr1_get_var_ti_integer
  1440. !*****************************************************************************
  1441. SUBROUTINE ext_gr1_get_var_ti_logical ( DataHandle,Element, Varname, Data, &
  1442. Count, Outcount, Status )
  1443. USE gr1_data_info
  1444. IMPLICIT NONE
  1445. #include "wrf_status_codes.h"
  1446. INTEGER , INTENT(IN) :: DataHandle
  1447. CHARACTER*(*) :: Element
  1448. CHARACTER*(*) :: VarName
  1449. logical , INTENT(OUT) :: Data(*)
  1450. INTEGER , INTENT(IN) :: Count
  1451. INTEGER , INTENT(OUT) :: OutCount
  1452. INTEGER , INTENT(OUT) :: Status
  1453. INTEGER :: idx
  1454. INTEGER :: stat
  1455. CHARACTER*(1000) :: VALUE
  1456. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_logical')
  1457. Status = WRF_NO_ERR
  1458. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), &
  1459. "none", Varname, Value,stat)
  1460. if (stat /= 0) then
  1461. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1462. Status = WRF_WARN_VAR_NF
  1463. RETURN
  1464. endif
  1465. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1466. if (stat .ne. 0) then
  1467. CALL wrf_message("Reading data from"//Value//"failed")
  1468. Status = WRF_WARN_COUNT_TOO_LONG
  1469. RETURN
  1470. endif
  1471. Outcount = idx
  1472. RETURN
  1473. END SUBROUTINE ext_gr1_get_var_ti_logical
  1474. !*****************************************************************************
  1475. SUBROUTINE ext_gr1_get_var_ti_char ( DataHandle,Element, Varname, Data, &
  1476. Status )
  1477. USE gr1_data_info
  1478. IMPLICIT NONE
  1479. #include "wrf_status_codes.h"
  1480. INTEGER , INTENT(IN) :: DataHandle
  1481. CHARACTER*(*) :: Element
  1482. CHARACTER*(*) :: VarName
  1483. CHARACTER*(*) :: Data
  1484. INTEGER , INTENT(OUT) :: Status
  1485. INTEGER :: stat
  1486. Status = WRF_NO_ERR
  1487. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_ti_char')
  1488. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), &
  1489. "none", Varname, Data,stat)
  1490. if (stat /= 0) then
  1491. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1492. Status = WRF_WARN_VAR_NF
  1493. RETURN
  1494. endif
  1495. RETURN
  1496. END SUBROUTINE ext_gr1_get_var_ti_char
  1497. !******************************************************************************
  1498. !* End of get_var_ti_* routines
  1499. !******************************************************************************
  1500. !******************************************************************************
  1501. !* Start of put_var_ti_* routines
  1502. !******************************************************************************
  1503. SUBROUTINE ext_gr1_put_var_ti_real ( DataHandle,Element, Varname, Data, &
  1504. Count, Status )
  1505. USE gr1_data_info
  1506. IMPLICIT NONE
  1507. #include "wrf_status_codes.h"
  1508. INTEGER , INTENT(IN) :: DataHandle
  1509. CHARACTER*(*) :: Element
  1510. CHARACTER*(*) :: VarName
  1511. real , INTENT(IN) :: Data(*)
  1512. INTEGER , INTENT(IN) :: Count
  1513. INTEGER , INTENT(OUT) :: Status
  1514. CHARACTER(len=1000) :: tmpstr(1000)
  1515. INTEGER :: idx
  1516. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_real')
  1517. if (committed(DataHandle)) then
  1518. do idx = 1,Count
  1519. write(tmpstr(idx),'(G17.10)')Data(idx)
  1520. enddo
  1521. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  1522. endif
  1523. RETURN
  1524. END SUBROUTINE ext_gr1_put_var_ti_real
  1525. !*****************************************************************************
  1526. SUBROUTINE ext_gr1_put_var_ti_double ( DataHandle,Element, Varname, Data, &
  1527. Count, Status )
  1528. USE gr1_data_info
  1529. IMPLICIT NONE
  1530. #include "wrf_status_codes.h"
  1531. INTEGER , INTENT(IN) :: DataHandle
  1532. CHARACTER*(*) , INTENT(IN) :: Element
  1533. CHARACTER*(*) , INTENT(IN) :: VarName
  1534. real*8 , INTENT(IN) :: Data(*)
  1535. INTEGER , INTENT(IN) :: Count
  1536. INTEGER , INTENT(OUT) :: Status
  1537. CHARACTER(len=1000) :: tmpstr(1000)
  1538. INTEGER :: idx
  1539. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_double')
  1540. if (committed(DataHandle)) then
  1541. do idx = 1,Count
  1542. write(tmpstr(idx),'(G17.10)')Data(idx)
  1543. enddo
  1544. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  1545. endif
  1546. RETURN
  1547. END SUBROUTINE ext_gr1_put_var_ti_double
  1548. !*****************************************************************************
  1549. SUBROUTINE ext_gr1_put_var_ti_real8 ( DataHandle,Element, Varname, Data, &
  1550. Count, Status )
  1551. USE gr1_data_info
  1552. IMPLICIT NONE
  1553. #include "wrf_status_codes.h"
  1554. INTEGER , INTENT(IN) :: DataHandle
  1555. CHARACTER*(*) :: Element
  1556. CHARACTER*(*) :: VarName
  1557. real*8 , INTENT(IN) :: Data(*)
  1558. INTEGER , INTENT(IN) :: Count
  1559. INTEGER , INTENT(OUT) :: Status
  1560. CHARACTER(len=1000) :: tmpstr(1000)
  1561. INTEGER :: idx
  1562. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_real8')
  1563. if (committed(DataHandle)) then
  1564. do idx = 1,Count
  1565. write(tmpstr(idx),'(G17.10)')Data(idx)
  1566. enddo
  1567. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  1568. endif
  1569. RETURN
  1570. END SUBROUTINE ext_gr1_put_var_ti_real8
  1571. !*****************************************************************************
  1572. SUBROUTINE ext_gr1_put_var_ti_integer ( DataHandle,Element, Varname, Data, &
  1573. Count, Status )
  1574. USE gr1_data_info
  1575. IMPLICIT NONE
  1576. #include "wrf_status_codes.h"
  1577. INTEGER , INTENT(IN) :: DataHandle
  1578. CHARACTER*(*) :: Element
  1579. CHARACTER*(*) :: VarName
  1580. integer , INTENT(IN) :: Data(*)
  1581. INTEGER , INTENT(IN) :: Count
  1582. INTEGER , INTENT(OUT) :: Status
  1583. CHARACTER(len=1000) :: tmpstr(1000)
  1584. INTEGER :: idx
  1585. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_integer')
  1586. if (committed(DataHandle)) then
  1587. do idx = 1,Count
  1588. write(tmpstr(idx),'(G17.10)')Data(idx)
  1589. enddo
  1590. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  1591. endif
  1592. RETURN
  1593. END SUBROUTINE ext_gr1_put_var_ti_integer
  1594. !*****************************************************************************
  1595. SUBROUTINE ext_gr1_put_var_ti_logical ( DataHandle,Element, Varname, Data, &
  1596. Count, Status )
  1597. USE gr1_data_info
  1598. IMPLICIT NONE
  1599. #include "wrf_status_codes.h"
  1600. INTEGER , INTENT(IN) :: DataHandle
  1601. CHARACTER*(*) :: Element
  1602. CHARACTER*(*) :: VarName
  1603. logical , INTENT(IN) :: Data(*)
  1604. INTEGER , INTENT(IN) :: Count
  1605. INTEGER , INTENT(OUT) :: Status
  1606. CHARACTER(len=1000) :: tmpstr(1000)
  1607. INTEGER :: idx
  1608. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_logical')
  1609. if (committed(DataHandle)) then
  1610. do idx = 1,Count
  1611. write(tmpstr(idx),'(G17.10)')Data(idx)
  1612. enddo
  1613. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  1614. endif
  1615. RETURN
  1616. END SUBROUTINE ext_gr1_put_var_ti_logical
  1617. !*****************************************************************************
  1618. SUBROUTINE ext_gr1_put_var_ti_char ( DataHandle,Element, Varname, Data, &
  1619. Status )
  1620. USE gr1_data_info
  1621. IMPLICIT NONE
  1622. #include "wrf_status_codes.h"
  1623. INTEGER , INTENT(IN) :: DataHandle
  1624. CHARACTER(len=*) :: Element
  1625. CHARACTER(len=*) :: VarName
  1626. CHARACTER(len=*) :: Data
  1627. INTEGER , INTENT(OUT) :: Status
  1628. REAL dummy
  1629. INTEGER :: Count
  1630. CHARACTER(len=1000) :: tmpstr(1)
  1631. INTEGER :: idx
  1632. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_ti_char')
  1633. if (committed(DataHandle)) then
  1634. write(tmpstr(1),*)trim(Data)
  1635. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, 1, Status)
  1636. endif
  1637. RETURN
  1638. END SUBROUTINE ext_gr1_put_var_ti_char
  1639. !******************************************************************************
  1640. !* End of put_var_ti_* routines
  1641. !******************************************************************************
  1642. !******************************************************************************
  1643. !* Start of get_var_td_* routines
  1644. !******************************************************************************
  1645. SUBROUTINE ext_gr1_get_var_td_double ( DataHandle,Element, DateStr, &
  1646. Varname, Data, Count, Outcount, Status )
  1647. USE gr1_data_info
  1648. IMPLICIT NONE
  1649. #include "wrf_status_codes.h"
  1650. INTEGER , INTENT(IN) :: DataHandle
  1651. CHARACTER*(*) , INTENT(IN) :: Element
  1652. CHARACTER*(*) , INTENT(IN) :: DateStr
  1653. CHARACTER*(*) , INTENT(IN) :: VarName
  1654. real*8 , INTENT(OUT) :: Data(*)
  1655. INTEGER , INTENT(IN) :: Count
  1656. INTEGER , INTENT(OUT) :: OutCount
  1657. INTEGER , INTENT(OUT) :: Status
  1658. INTEGER :: idx
  1659. INTEGER :: stat
  1660. CHARACTER*(1000) :: VALUE
  1661. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_double')
  1662. Status = WRF_NO_ERR
  1663. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:),TRIM(Element),DateStr,&
  1664. Varname,Value,stat)
  1665. if (stat /= 0) then
  1666. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1667. Status = WRF_WARN_VAR_NF
  1668. RETURN
  1669. endif
  1670. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1671. if (stat .ne. 0) then
  1672. CALL wrf_message("Reading data from"//Value//"failed")
  1673. Status = WRF_WARN_COUNT_TOO_LONG
  1674. RETURN
  1675. endif
  1676. Outcount = idx
  1677. RETURN
  1678. END SUBROUTINE ext_gr1_get_var_td_double
  1679. !*****************************************************************************
  1680. SUBROUTINE ext_gr1_get_var_td_real ( DataHandle,Element, DateStr,Varname, &
  1681. Data, Count, Outcount, Status )
  1682. USE gr1_data_info
  1683. IMPLICIT NONE
  1684. #include "wrf_status_codes.h"
  1685. INTEGER , INTENT(IN) :: DataHandle
  1686. CHARACTER*(*) :: Element
  1687. CHARACTER*(*) :: DateStr
  1688. CHARACTER*(*) :: VarName
  1689. real , INTENT(OUT) :: Data(*)
  1690. INTEGER , INTENT(IN) :: Count
  1691. INTEGER , INTENT(OUT) :: OutCount
  1692. INTEGER , INTENT(OUT) :: Status
  1693. INTEGER :: idx
  1694. INTEGER :: stat
  1695. CHARACTER*(1000) :: VALUE
  1696. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_real')
  1697. Status = WRF_NO_ERR
  1698. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  1699. Varname, Value, stat)
  1700. if (stat /= 0) then
  1701. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1702. Status = WRF_WARN_VAR_NF
  1703. RETURN
  1704. endif
  1705. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1706. if (stat .ne. 0) then
  1707. CALL wrf_message("Reading data from"//Value//"failed")
  1708. Status = WRF_WARN_COUNT_TOO_LONG
  1709. RETURN
  1710. endif
  1711. Outcount = idx
  1712. RETURN
  1713. END SUBROUTINE ext_gr1_get_var_td_real
  1714. !*****************************************************************************
  1715. SUBROUTINE ext_gr1_get_var_td_real8 ( DataHandle,Element, DateStr,Varname, &
  1716. Data, Count, Outcount, Status )
  1717. USE gr1_data_info
  1718. IMPLICIT NONE
  1719. #include "wrf_status_codes.h"
  1720. INTEGER , INTENT(IN) :: DataHandle
  1721. CHARACTER*(*) :: Element
  1722. CHARACTER*(*) :: DateStr
  1723. CHARACTER*(*) :: VarName
  1724. real*8 , INTENT(OUT) :: Data(*)
  1725. INTEGER , INTENT(IN) :: Count
  1726. INTEGER , INTENT(OUT) :: OutCount
  1727. INTEGER , INTENT(OUT) :: Status
  1728. INTEGER :: idx
  1729. INTEGER :: stat
  1730. CHARACTER*(1000) :: VALUE
  1731. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_real8')
  1732. Status = WRF_NO_ERR
  1733. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:),TRIM(Element),DateStr,&
  1734. Varname,Value,stat)
  1735. if (stat /= 0) then
  1736. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1737. Status = WRF_WARN_VAR_NF
  1738. RETURN
  1739. endif
  1740. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1741. if (stat .ne. 0) then
  1742. CALL wrf_message("Reading data from"//Value//"failed")
  1743. Status = WRF_WARN_COUNT_TOO_LONG
  1744. RETURN
  1745. endif
  1746. Outcount = idx
  1747. RETURN
  1748. END SUBROUTINE ext_gr1_get_var_td_real8
  1749. !*****************************************************************************
  1750. SUBROUTINE ext_gr1_get_var_td_integer ( DataHandle,Element, DateStr,Varname, &
  1751. Data, Count, Outcount, Status )
  1752. USE gr1_data_info
  1753. IMPLICIT NONE
  1754. #include "wrf_status_codes.h"
  1755. INTEGER , INTENT(IN) :: DataHandle
  1756. CHARACTER*(*) :: Element
  1757. CHARACTER*(*) :: DateStr
  1758. CHARACTER*(*) :: VarName
  1759. integer , INTENT(OUT) :: Data(*)
  1760. INTEGER , INTENT(IN) :: Count
  1761. INTEGER , INTENT(OUT) :: OutCount
  1762. INTEGER , INTENT(OUT) :: Status
  1763. INTEGER :: idx
  1764. INTEGER :: stat
  1765. CHARACTER*(1000) :: VALUE
  1766. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_integer')
  1767. Status = WRF_NO_ERR
  1768. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  1769. Varname, Value,stat)
  1770. if (stat /= 0) then
  1771. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1772. Status = WRF_WARN_VAR_NF
  1773. RETURN
  1774. endif
  1775. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1776. if (stat .ne. 0) then
  1777. CALL wrf_message("Reading data from"//Value//"failed")
  1778. Status = WRF_WARN_COUNT_TOO_LONG
  1779. RETURN
  1780. endif
  1781. Outcount = idx
  1782. RETURN
  1783. END SUBROUTINE ext_gr1_get_var_td_integer
  1784. !*****************************************************************************
  1785. SUBROUTINE ext_gr1_get_var_td_logical ( DataHandle,Element, DateStr,Varname, &
  1786. Data, Count, Outcount, Status )
  1787. USE gr1_data_info
  1788. IMPLICIT NONE
  1789. #include "wrf_status_codes.h"
  1790. INTEGER , INTENT(IN) :: DataHandle
  1791. CHARACTER*(*) :: Element
  1792. CHARACTER*(*) :: DateStr
  1793. CHARACTER*(*) :: VarName
  1794. logical , INTENT(OUT) :: Data(*)
  1795. INTEGER , INTENT(IN) :: Count
  1796. INTEGER , INTENT(OUT) :: OutCount
  1797. INTEGER , INTENT(OUT) :: Status
  1798. INTEGER :: idx
  1799. INTEGER :: stat
  1800. CHARACTER*(1000) :: VALUE
  1801. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_logical')
  1802. Status = WRF_NO_ERR
  1803. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  1804. Varname, Value,stat)
  1805. if (stat /= 0) then
  1806. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1807. Status = WRF_WARN_VAR_NF
  1808. RETURN
  1809. endif
  1810. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  1811. if (stat .ne. 0) then
  1812. CALL wrf_message("Reading data from"//Value//"failed")
  1813. Status = WRF_WARN_COUNT_TOO_LONG
  1814. RETURN
  1815. endif
  1816. Outcount = idx
  1817. RETURN
  1818. END SUBROUTINE ext_gr1_get_var_td_logical
  1819. !*****************************************************************************
  1820. SUBROUTINE ext_gr1_get_var_td_char ( DataHandle,Element, DateStr,Varname, &
  1821. Data, Status )
  1822. USE gr1_data_info
  1823. IMPLICIT NONE
  1824. #include "wrf_status_codes.h"
  1825. INTEGER , INTENT(IN) :: DataHandle
  1826. CHARACTER*(*) :: Element
  1827. CHARACTER*(*) :: DateStr
  1828. CHARACTER*(*) :: VarName
  1829. CHARACTER*(*) :: Data
  1830. INTEGER , INTENT(OUT) :: Status
  1831. INTEGER :: stat
  1832. Status = WRF_NO_ERR
  1833. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_var_td_char')
  1834. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  1835. Varname, Data,stat)
  1836. if (stat /= 0) then
  1837. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  1838. Status = WRF_WARN_VAR_NF
  1839. RETURN
  1840. endif
  1841. RETURN
  1842. END SUBROUTINE ext_gr1_get_var_td_char
  1843. !******************************************************************************
  1844. !* End of get_var_td_* routines
  1845. !******************************************************************************
  1846. !******************************************************************************
  1847. !* Start of put_var_td_* routines
  1848. !******************************************************************************
  1849. SUBROUTINE ext_gr1_put_var_td_double ( DataHandle, Element, DateStr, Varname, &
  1850. Data, Count, Status )
  1851. USE gr1_data_info
  1852. IMPLICIT NONE
  1853. #include "wrf_status_codes.h"
  1854. INTEGER , INTENT(IN) :: DataHandle
  1855. CHARACTER*(*) , INTENT(IN) :: Element
  1856. CHARACTER*(*) , INTENT(IN) :: DateStr
  1857. CHARACTER*(*) , INTENT(IN) :: VarName
  1858. real*8 , INTENT(IN) :: Data(*)
  1859. INTEGER , INTENT(IN) :: Count
  1860. INTEGER , INTENT(OUT) :: Status
  1861. CHARACTER(len=1000) :: tmpstr(1000)
  1862. INTEGER :: idx
  1863. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_double')
  1864. if (committed(DataHandle)) then
  1865. do idx = 1,Count
  1866. write(tmpstr(idx),'(G17.10)')Data(idx)
  1867. enddo
  1868. CALL gr1_build_string (td_output(DataHandle), &
  1869. Varname//';'//DateStr//';'//Element, tmpstr, Count, Status)
  1870. endif
  1871. RETURN
  1872. END SUBROUTINE ext_gr1_put_var_td_double
  1873. !*****************************************************************************
  1874. SUBROUTINE ext_gr1_put_var_td_integer ( DataHandle,Element, DateStr, &
  1875. Varname, Data, Count, Status )
  1876. USE gr1_data_info
  1877. IMPLICIT NONE
  1878. #include "wrf_status_codes.h"
  1879. INTEGER , INTENT(IN) :: DataHandle
  1880. CHARACTER*(*) :: Element
  1881. CHARACTER*(*) :: DateStr
  1882. CHARACTER*(*) :: VarName
  1883. integer , INTENT(IN) :: Data(*)
  1884. INTEGER , INTENT(IN) :: Count
  1885. INTEGER , INTENT(OUT) :: Status
  1886. CHARACTER(len=1000) :: tmpstr(1000)
  1887. INTEGER :: idx
  1888. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_integer')
  1889. if (committed(DataHandle)) then
  1890. do idx = 1,Count
  1891. write(tmpstr(idx),'(G17.10)')Data(idx)
  1892. enddo
  1893. CALL gr1_build_string (td_output(DataHandle), &
  1894. Varname//';'//DateStr//';'//Element, tmpstr, Count, Status)
  1895. endif
  1896. RETURN
  1897. END SUBROUTINE ext_gr1_put_var_td_integer
  1898. !*****************************************************************************
  1899. SUBROUTINE ext_gr1_put_var_td_real ( DataHandle,Element, DateStr,Varname, &
  1900. Data, Count, Status )
  1901. USE gr1_data_info
  1902. IMPLICIT NONE
  1903. #include "wrf_status_codes.h"
  1904. INTEGER , INTENT(IN) :: DataHandle
  1905. CHARACTER*(*) :: Element
  1906. CHARACTER*(*) :: DateStr
  1907. CHARACTER*(*) :: VarName
  1908. real , INTENT(IN) :: Data(*)
  1909. INTEGER , INTENT(IN) :: Count
  1910. INTEGER , INTENT(OUT) :: Status
  1911. CHARACTER(len=1000) :: tmpstr(1000)
  1912. INTEGER :: idx
  1913. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_real')
  1914. if (committed(DataHandle)) then
  1915. do idx = 1,Count
  1916. write(tmpstr(idx),'(G17.10)')Data(idx)
  1917. enddo
  1918. CALL gr1_build_string (td_output(DataHandle), &
  1919. Varname//';'//DateStr//';'//Element, tmpstr, Count, Status)
  1920. endif
  1921. RETURN
  1922. END SUBROUTINE ext_gr1_put_var_td_real
  1923. !*****************************************************************************
  1924. SUBROUTINE ext_gr1_put_var_td_real8 ( DataHandle,Element, DateStr,Varname, &
  1925. Data, Count, Status )
  1926. USE gr1_data_info
  1927. IMPLICIT NONE
  1928. #include "wrf_status_codes.h"
  1929. INTEGER , INTENT(IN) :: DataHandle
  1930. CHARACTER*(*) :: Element
  1931. CHARACTER*(*) :: DateStr
  1932. CHARACTER*(*) :: VarName
  1933. real*8 , INTENT(IN) :: Data(*)
  1934. INTEGER , INTENT(IN) :: Count
  1935. INTEGER , INTENT(OUT) :: Status
  1936. CHARACTER(len=1000) :: tmpstr(1000)
  1937. INTEGER :: idx
  1938. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_real8')
  1939. if (committed(DataHandle)) then
  1940. do idx = 1,Count
  1941. write(tmpstr(idx),'(G17.10)')Data(idx)
  1942. enddo
  1943. CALL gr1_build_string (td_output(DataHandle), &
  1944. Varname//';'//DateStr//';'//Element, tmpstr, Count, Status)
  1945. endif
  1946. RETURN
  1947. END SUBROUTINE ext_gr1_put_var_td_real8
  1948. !*****************************************************************************
  1949. SUBROUTINE ext_gr1_put_var_td_logical ( DataHandle,Element, DateStr, &
  1950. Varname, Data, Count, Status )
  1951. USE gr1_data_info
  1952. IMPLICIT NONE
  1953. #include "wrf_status_codes.h"
  1954. INTEGER , INTENT(IN) :: DataHandle
  1955. CHARACTER*(*) :: Element
  1956. CHARACTER*(*) :: DateStr
  1957. CHARACTER*(*) :: VarName
  1958. logical , INTENT(IN) :: Data(*)
  1959. INTEGER , INTENT(IN) :: Count
  1960. INTEGER , INTENT(OUT) :: Status
  1961. CHARACTER(len=1000) :: tmpstr(1000)
  1962. INTEGER :: idx
  1963. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_logical')
  1964. if (committed(DataHandle)) then
  1965. do idx = 1,Count
  1966. write(tmpstr(idx),'(G17.10)')Data(idx)
  1967. enddo
  1968. CALL gr1_build_string (td_output(DataHandle), &
  1969. Varname//';'//DateStr//';'//Element, tmpstr, Count, Status)
  1970. endif
  1971. RETURN
  1972. END SUBROUTINE ext_gr1_put_var_td_logical
  1973. !*****************************************************************************
  1974. SUBROUTINE ext_gr1_put_var_td_char ( DataHandle,Element, DateStr,Varname, &
  1975. Data, Status )
  1976. USE gr1_data_info
  1977. IMPLICIT NONE
  1978. #include "wrf_status_codes.h"
  1979. INTEGER , INTENT(IN) :: DataHandle
  1980. CHARACTER*(*) :: Element
  1981. CHARACTER*(*) :: DateStr
  1982. CHARACTER*(*) :: VarName
  1983. CHARACTER*(*) :: Data
  1984. INTEGER , INTENT(OUT) :: Status
  1985. CHARACTER(len=1000) :: tmpstr
  1986. INTEGER :: idx
  1987. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_var_td_char')
  1988. if (committed(DataHandle)) then
  1989. DO idx=1,LEN(Data)
  1990. tmpstr(idx:idx)=Data(idx:idx)
  1991. END DO
  1992. DO idx=LEN(Data)+1,1000
  1993. tmpstr(idx:idx)=' '
  1994. END DO
  1995. CALL gr1_build_string (td_output(DataHandle), &
  1996. Varname//';'//DateStr//';'//Element, tmpstr, 1, Status)
  1997. endif
  1998. RETURN
  1999. END SUBROUTINE ext_gr1_put_var_td_char
  2000. !******************************************************************************
  2001. !* End of put_var_td_* routines
  2002. !******************************************************************************
  2003. !******************************************************************************
  2004. !* Start of get_dom_ti_* routines
  2005. !******************************************************************************
  2006. SUBROUTINE ext_gr1_get_dom_ti_real ( DataHandle,Element, Data, Count, &
  2007. Outcount, Status )
  2008. USE gr1_data_info
  2009. IMPLICIT NONE
  2010. #include "wrf_status_codes.h"
  2011. INTEGER , INTENT(IN) :: DataHandle
  2012. CHARACTER*(*) :: Element
  2013. real , INTENT(OUT) :: Data(*)
  2014. INTEGER , INTENT(IN) :: Count
  2015. INTEGER , INTENT(OUT) :: Outcount
  2016. INTEGER , INTENT(OUT) :: Status
  2017. INTEGER :: idx
  2018. INTEGER :: stat
  2019. CHARACTER*(1000) :: VALUE
  2020. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_real')
  2021. Status = WRF_NO_ERR
  2022. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2023. "none", Value,stat)
  2024. if (stat /= 0) then
  2025. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2026. Status = WRF_WARN_VAR_NF
  2027. RETURN
  2028. endif
  2029. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2030. if (stat .ne. 0) then
  2031. CALL wrf_message("Reading data from"//Value//"failed")
  2032. Status = WRF_WARN_COUNT_TOO_LONG
  2033. RETURN
  2034. endif
  2035. Outcount = idx
  2036. RETURN
  2037. END SUBROUTINE ext_gr1_get_dom_ti_real
  2038. !*****************************************************************************
  2039. SUBROUTINE ext_gr1_get_dom_ti_real8 ( DataHandle,Element, Data, Count, &
  2040. Outcount, Status )
  2041. USE gr1_data_info
  2042. IMPLICIT NONE
  2043. #include "wrf_status_codes.h"
  2044. INTEGER , INTENT(IN) :: DataHandle
  2045. CHARACTER*(*) :: Element
  2046. real*8 , INTENT(OUT) :: Data(*)
  2047. INTEGER , INTENT(IN) :: Count
  2048. INTEGER , INTENT(OUT) :: OutCount
  2049. INTEGER , INTENT(OUT) :: Status
  2050. INTEGER :: idx
  2051. INTEGER :: stat
  2052. CHARACTER*(1000) :: VALUE
  2053. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_real8')
  2054. Status = WRF_NO_ERR
  2055. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2056. "none", Value,stat)
  2057. if (stat /= 0) then
  2058. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2059. Status = WRF_WARN_VAR_NF
  2060. RETURN
  2061. endif
  2062. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2063. if (stat .ne. 0) then
  2064. CALL wrf_message("Reading data from"//Value//"failed")
  2065. Status = WRF_WARN_COUNT_TOO_LONG
  2066. RETURN
  2067. endif
  2068. Outcount = idx
  2069. RETURN
  2070. END SUBROUTINE ext_gr1_get_dom_ti_real8
  2071. !*****************************************************************************
  2072. SUBROUTINE ext_gr1_get_dom_ti_integer ( DataHandle,Element, Data, Count, &
  2073. Outcount, Status )
  2074. USE gr1_data_info
  2075. IMPLICIT NONE
  2076. #include "wrf_status_codes.h"
  2077. INTEGER , INTENT(IN) :: DataHandle
  2078. CHARACTER*(*) :: Element
  2079. integer , INTENT(OUT) :: Data(*)
  2080. INTEGER , INTENT(IN) :: Count
  2081. INTEGER , INTENT(OUT) :: OutCount
  2082. INTEGER , INTENT(OUT) :: Status
  2083. INTEGER :: idx
  2084. INTEGER :: stat
  2085. CHARACTER*(1000) :: VALUE
  2086. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_integer Element: '//Element)
  2087. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2088. "none", Value,stat)
  2089. if (stat /= 0) then
  2090. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2091. Status = WRF_WARN_VAR_NF
  2092. RETURN
  2093. endif
  2094. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2095. if (stat .ne. 0) then
  2096. CALL wrf_message("Reading data from"//Value//"failed")
  2097. Status = WRF_WARN_COUNT_TOO_LONG
  2098. RETURN
  2099. endif
  2100. Outcount = Count
  2101. RETURN
  2102. END SUBROUTINE ext_gr1_get_dom_ti_integer
  2103. !*****************************************************************************
  2104. SUBROUTINE ext_gr1_get_dom_ti_logical ( DataHandle,Element, Data, Count, &
  2105. Outcount, Status )
  2106. USE gr1_data_info
  2107. IMPLICIT NONE
  2108. #include "wrf_status_codes.h"
  2109. INTEGER , INTENT(IN) :: DataHandle
  2110. CHARACTER*(*) :: Element
  2111. logical , INTENT(OUT) :: Data(*)
  2112. INTEGER , INTENT(IN) :: Count
  2113. INTEGER , INTENT(OUT) :: OutCount
  2114. INTEGER , INTENT(OUT) :: Status
  2115. INTEGER :: idx
  2116. INTEGER :: stat
  2117. CHARACTER*(1000) :: VALUE
  2118. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_logical')
  2119. Status = WRF_NO_ERR
  2120. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2121. "none", Value,stat)
  2122. if (stat /= 0) then
  2123. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2124. Status = WRF_WARN_VAR_NF
  2125. RETURN
  2126. endif
  2127. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2128. if (stat .ne. 0) then
  2129. CALL wrf_message("Reading data from"//Value//"failed")
  2130. Status = WRF_WARN_COUNT_TOO_LONG
  2131. RETURN
  2132. endif
  2133. Outcount = idx
  2134. RETURN
  2135. END SUBROUTINE ext_gr1_get_dom_ti_logical
  2136. !*****************************************************************************
  2137. SUBROUTINE ext_gr1_get_dom_ti_char ( DataHandle,Element, Data, Status )
  2138. USE gr1_data_info
  2139. IMPLICIT NONE
  2140. #include "wrf_status_codes.h"
  2141. INTEGER , INTENT(IN) :: DataHandle
  2142. CHARACTER*(*) :: Element
  2143. CHARACTER*(*) :: Data
  2144. INTEGER , INTENT(OUT) :: Status
  2145. INTEGER :: stat
  2146. INTEGER :: endchar
  2147. Status = WRF_NO_ERR
  2148. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_char')
  2149. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2150. "none", Data, stat)
  2151. if (stat /= 0) then
  2152. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2153. Status = WRF_WARN_VAR_NF
  2154. RETURN
  2155. endif
  2156. RETURN
  2157. END SUBROUTINE ext_gr1_get_dom_ti_char
  2158. !*****************************************************************************
  2159. SUBROUTINE ext_gr1_get_dom_ti_double ( DataHandle,Element, Data, Count, &
  2160. Outcount, Status )
  2161. USE gr1_data_info
  2162. IMPLICIT NONE
  2163. #include "wrf_status_codes.h"
  2164. INTEGER , INTENT(IN) :: DataHandle
  2165. CHARACTER*(*) , INTENT(IN) :: Element
  2166. real*8 , INTENT(OUT) :: Data(*)
  2167. INTEGER , INTENT(IN) :: Count
  2168. INTEGER , INTENT(OUT) :: OutCount
  2169. INTEGER , INTENT(OUT) :: Status
  2170. INTEGER :: idx
  2171. INTEGER :: stat
  2172. CHARACTER*(1000) :: VALUE
  2173. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_ti_double')
  2174. Status = WRF_NO_ERR
  2175. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), "none", &
  2176. "none", Value, stat)
  2177. if (stat /= 0) then
  2178. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2179. Status = WRF_WARN_VAR_NF
  2180. RETURN
  2181. endif
  2182. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2183. if (stat .ne. 0) then
  2184. CALL wrf_message("Reading data from"//Value//"failed")
  2185. Status = WRF_WARN_COUNT_TOO_LONG
  2186. RETURN
  2187. endif
  2188. Outcount = idx
  2189. RETURN
  2190. END SUBROUTINE ext_gr1_get_dom_ti_double
  2191. !******************************************************************************
  2192. !* End of get_dom_ti_* routines
  2193. !******************************************************************************
  2194. !******************************************************************************
  2195. !* Start of put_dom_ti_* routines
  2196. !******************************************************************************
  2197. SUBROUTINE ext_gr1_put_dom_ti_real ( DataHandle,Element, Data, Count, &
  2198. Status )
  2199. USE gr1_data_info
  2200. IMPLICIT NONE
  2201. #include "wrf_status_codes.h"
  2202. INTEGER , INTENT(IN) :: DataHandle
  2203. CHARACTER*(*) :: Element
  2204. real , INTENT(IN) :: Data(*)
  2205. INTEGER , INTENT(IN) :: Count
  2206. INTEGER , INTENT(OUT) :: Status
  2207. REAL dummy
  2208. CHARACTER(len=1000) :: tmpstr(1000)
  2209. character(len=2) :: lf
  2210. integer :: idx
  2211. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_real')
  2212. if (Element .eq. 'DX') then
  2213. dx = Data(1)/1000.
  2214. endif
  2215. if (Element .eq. 'DY') then
  2216. dy = Data(1)/1000.
  2217. endif
  2218. if (Element .eq. 'CEN_LAT') then
  2219. center_lat = Data(1)
  2220. endif
  2221. if (Element .eq. 'CEN_LON') then
  2222. center_lon = Data(1)
  2223. endif
  2224. if (Element .eq. 'TRUELAT1') then
  2225. truelat1 = Data(1)
  2226. endif
  2227. if (Element .eq. 'TRUELAT2') then
  2228. truelat2 = Data(1)
  2229. endif
  2230. if (Element == 'STAND_LON') then
  2231. proj_central_lon = Data(1)
  2232. endif
  2233. if (Element == 'DT') then
  2234. timestep = Data(1)
  2235. endif
  2236. if (committed(DataHandle)) then
  2237. do idx = 1,Count
  2238. write(tmpstr(idx),'(G17.10)')Data(idx)
  2239. enddo
  2240. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  2241. endif
  2242. RETURN
  2243. END SUBROUTINE ext_gr1_put_dom_ti_real
  2244. !*****************************************************************************
  2245. SUBROUTINE ext_gr1_put_dom_ti_real8 ( DataHandle,Element, Data, Count, &
  2246. Status )
  2247. USE gr1_data_info
  2248. IMPLICIT NONE
  2249. #include "wrf_status_codes.h"
  2250. INTEGER , INTENT(IN) :: DataHandle
  2251. CHARACTER*(*) :: Element
  2252. real*8 , INTENT(IN) :: Data(*)
  2253. INTEGER , INTENT(IN) :: Count
  2254. INTEGER , INTENT(OUT) :: Status
  2255. CHARACTER(len=1000) :: tmpstr(1000)
  2256. INTEGER :: idx
  2257. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_real8')
  2258. if (committed(DataHandle)) then
  2259. do idx = 1,Count
  2260. write(tmpstr(idx),'(G17.10)')Data(idx)
  2261. enddo
  2262. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  2263. endif
  2264. RETURN
  2265. END SUBROUTINE ext_gr1_put_dom_ti_real8
  2266. !*****************************************************************************
  2267. SUBROUTINE ext_gr1_put_dom_ti_integer ( DataHandle,Element, Data, Count, &
  2268. Status )
  2269. USE gr1_data_info
  2270. IMPLICIT NONE
  2271. #include "wrf_status_codes.h"
  2272. INTEGER , INTENT(IN) :: DataHandle
  2273. CHARACTER*(*) :: Element
  2274. INTEGER , INTENT(IN) :: Data(*)
  2275. INTEGER , INTENT(IN) :: Count
  2276. INTEGER , INTENT(OUT) :: Status
  2277. REAL dummy
  2278. CHARACTER(len=1000) :: tmpstr(1000)
  2279. INTEGER :: idx
  2280. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_integer')
  2281. if (Element == 'WEST-EAST_GRID_DIMENSION') then
  2282. full_xsize = Data(1)
  2283. else if (Element == 'SOUTH-NORTH_GRID_DIMENSION') then
  2284. full_ysize = Data(1)
  2285. else if (Element == 'MAP_PROJ') then
  2286. projection = Data(1)
  2287. else if (Element == 'WG_GRID_ID') then
  2288. wg_grid_id = Data(1)
  2289. else if (Element == 'GRID_ID') then
  2290. this_domain = Data(1)
  2291. endif
  2292. if (committed(DataHandle)) then
  2293. do idx = 1,Count
  2294. write(tmpstr(idx),'(G17.10)')Data(idx)
  2295. enddo
  2296. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  2297. endif
  2298. call wrf_debug ( DEBUG , 'Leaving ext_gr1_put_dom_ti_integer')
  2299. RETURN
  2300. END SUBROUTINE ext_gr1_put_dom_ti_integer
  2301. !*****************************************************************************
  2302. SUBROUTINE ext_gr1_put_dom_ti_logical ( DataHandle,Element, Data, Count, &
  2303. Status )
  2304. USE gr1_data_info
  2305. IMPLICIT NONE
  2306. #include "wrf_status_codes.h"
  2307. INTEGER , INTENT(IN) :: DataHandle
  2308. CHARACTER*(*) :: Element
  2309. logical , INTENT(IN) :: Data(*)
  2310. INTEGER , INTENT(IN) :: Count
  2311. INTEGER , INTENT(OUT) :: Status
  2312. CHARACTER(len=1000) :: tmpstr(1000)
  2313. INTEGER :: idx
  2314. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_logical')
  2315. if (committed(DataHandle)) then
  2316. do idx = 1,Count
  2317. write(tmpstr(idx),'(G17.10)')Data(idx)
  2318. enddo
  2319. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  2320. endif
  2321. RETURN
  2322. END SUBROUTINE ext_gr1_put_dom_ti_logical
  2323. !*****************************************************************************
  2324. SUBROUTINE ext_gr1_put_dom_ti_char ( DataHandle,Element, Data, &
  2325. Status )
  2326. USE gr1_data_info
  2327. IMPLICIT NONE
  2328. #include "wrf_status_codes.h"
  2329. INTEGER , INTENT(IN) :: DataHandle
  2330. CHARACTER*(*) :: Element
  2331. CHARACTER*(*), INTENT(IN) :: Data
  2332. INTEGER , INTENT(OUT) :: Status
  2333. REAL dummy
  2334. CHARACTER(len=1000) :: tmpstr(1000)
  2335. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_char')
  2336. if (Element .eq. 'START_DATE') then
  2337. StartDate = Data
  2338. endif
  2339. if (committed(DataHandle)) then
  2340. write(tmpstr(1),*)trim(Data)
  2341. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, 1, Status)
  2342. endif
  2343. RETURN
  2344. END SUBROUTINE ext_gr1_put_dom_ti_char
  2345. !*****************************************************************************
  2346. SUBROUTINE ext_gr1_put_dom_ti_double ( DataHandle,Element, Data, Count, &
  2347. Status )
  2348. USE gr1_data_info
  2349. IMPLICIT NONE
  2350. #include "wrf_status_codes.h"
  2351. INTEGER , INTENT(IN) :: DataHandle
  2352. CHARACTER*(*) , INTENT(IN) :: Element
  2353. real*8 , INTENT(IN) :: Data(*)
  2354. INTEGER , INTENT(IN) :: Count
  2355. INTEGER , INTENT(OUT) :: Status
  2356. CHARACTER(len=1000) :: tmpstr(1000)
  2357. INTEGER :: idx
  2358. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_ti_double')
  2359. if (committed(DataHandle)) then
  2360. do idx = 1,Count
  2361. write(tmpstr(idx),'(G17.10)')Data(idx)
  2362. enddo
  2363. CALL gr1_build_string (ti_output(DataHandle), Element, tmpstr, Count, Status)
  2364. endif
  2365. RETURN
  2366. END SUBROUTINE ext_gr1_put_dom_ti_double
  2367. !******************************************************************************
  2368. !* End of put_dom_ti_* routines
  2369. !******************************************************************************
  2370. !******************************************************************************
  2371. !* Start of get_dom_td_* routines
  2372. !******************************************************************************
  2373. SUBROUTINE ext_gr1_get_dom_td_real ( DataHandle,Element, DateStr, Data, &
  2374. Count, Outcount, Status )
  2375. USE gr1_data_info
  2376. IMPLICIT NONE
  2377. #include "wrf_status_codes.h"
  2378. INTEGER , INTENT(IN) :: DataHandle
  2379. CHARACTER*(*) :: Element
  2380. CHARACTER*(*) :: DateStr
  2381. real , INTENT(OUT) :: Data(*)
  2382. INTEGER , INTENT(IN) :: Count
  2383. INTEGER , INTENT(OUT) :: OutCount
  2384. INTEGER , INTENT(OUT) :: Status
  2385. INTEGER :: idx
  2386. INTEGER :: stat
  2387. CHARACTER*(1000) :: VALUE
  2388. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_real')
  2389. Status = WRF_NO_ERR
  2390. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2391. "none", Value, stat)
  2392. if (stat /= 0) then
  2393. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2394. Status = WRF_WARN_VAR_NF
  2395. RETURN
  2396. endif
  2397. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2398. if (stat .ne. 0) then
  2399. CALL wrf_message("Reading data from"//Value//"failed")
  2400. Status = WRF_WARN_COUNT_TOO_LONG
  2401. RETURN
  2402. endif
  2403. Outcount = idx
  2404. RETURN
  2405. END SUBROUTINE ext_gr1_get_dom_td_real
  2406. !*****************************************************************************
  2407. SUBROUTINE ext_gr1_get_dom_td_real8 ( DataHandle,Element, DateStr, Data, &
  2408. Count, Outcount, Status )
  2409. USE gr1_data_info
  2410. IMPLICIT NONE
  2411. #include "wrf_status_codes.h"
  2412. INTEGER , INTENT(IN) :: DataHandle
  2413. CHARACTER*(*) :: Element
  2414. CHARACTER*(*) :: DateStr
  2415. real*8 , INTENT(OUT) :: Data(*)
  2416. INTEGER , INTENT(IN) :: Count
  2417. INTEGER , INTENT(OUT) :: OutCount
  2418. INTEGER , INTENT(OUT) :: Status
  2419. INTEGER :: idx
  2420. INTEGER :: stat
  2421. CHARACTER*(1000) :: VALUE
  2422. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_real8')
  2423. Status = WRF_NO_ERR
  2424. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2425. "none", Value, stat)
  2426. if (stat /= 0) then
  2427. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2428. Status = WRF_WARN_VAR_NF
  2429. RETURN
  2430. endif
  2431. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2432. if (stat .ne. 0) then
  2433. CALL wrf_message("Reading data from"//Value//"failed")
  2434. Status = WRF_WARN_COUNT_TOO_LONG
  2435. RETURN
  2436. endif
  2437. Outcount = idx
  2438. RETURN
  2439. END SUBROUTINE ext_gr1_get_dom_td_real8
  2440. !*****************************************************************************
  2441. SUBROUTINE ext_gr1_get_dom_td_integer ( DataHandle,Element, DateStr, Data, &
  2442. Count, Outcount, Status )
  2443. USE gr1_data_info
  2444. IMPLICIT NONE
  2445. #include "wrf_status_codes.h"
  2446. INTEGER , INTENT(IN) :: DataHandle
  2447. CHARACTER*(*) :: Element
  2448. CHARACTER*(*) :: DateStr
  2449. integer , INTENT(OUT) :: Data(*)
  2450. INTEGER , INTENT(IN) :: Count
  2451. INTEGER , INTENT(OUT) :: OutCount
  2452. INTEGER , INTENT(OUT) :: Status
  2453. INTEGER :: idx
  2454. INTEGER :: stat
  2455. CHARACTER*(1000) :: VALUE
  2456. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_integer')
  2457. Status = WRF_NO_ERR
  2458. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2459. "none", Value,stat)
  2460. if (stat /= 0) then
  2461. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2462. Status = WRF_WARN_VAR_NF
  2463. RETURN
  2464. endif
  2465. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2466. if (stat .ne. 0) then
  2467. CALL wrf_message("Reading data from"//Value//"failed")
  2468. Status = WRF_WARN_COUNT_TOO_LONG
  2469. RETURN
  2470. endif
  2471. Outcount = idx
  2472. RETURN
  2473. END SUBROUTINE ext_gr1_get_dom_td_integer
  2474. !*****************************************************************************
  2475. SUBROUTINE ext_gr1_get_dom_td_logical ( DataHandle,Element, DateStr, Data, &
  2476. Count, Outcount, Status )
  2477. USE gr1_data_info
  2478. IMPLICIT NONE
  2479. #include "wrf_status_codes.h"
  2480. INTEGER , INTENT(IN) :: DataHandle
  2481. CHARACTER*(*) :: Element
  2482. CHARACTER*(*) :: DateStr
  2483. logical , INTENT(OUT) :: Data(*)
  2484. INTEGER , INTENT(IN) :: Count
  2485. INTEGER , INTENT(OUT) :: OutCount
  2486. INTEGER , INTENT(OUT) :: Status
  2487. INTEGER :: idx
  2488. INTEGER :: stat
  2489. CHARACTER*(1000) :: VALUE
  2490. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_logical')
  2491. Status = WRF_NO_ERR
  2492. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2493. "none", Value, stat)
  2494. if (stat /= 0) then
  2495. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2496. Status = WRF_WARN_VAR_NF
  2497. RETURN
  2498. endif
  2499. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2500. if (stat .ne. 0) then
  2501. CALL wrf_message("Reading data from"//Value//"failed")
  2502. Status = WRF_WARN_COUNT_TOO_LONG
  2503. RETURN
  2504. endif
  2505. Outcount = idx
  2506. RETURN
  2507. END SUBROUTINE ext_gr1_get_dom_td_logical
  2508. !*****************************************************************************
  2509. SUBROUTINE ext_gr1_get_dom_td_char ( DataHandle,Element, DateStr, Data, &
  2510. Status )
  2511. USE gr1_data_info
  2512. IMPLICIT NONE
  2513. #include "wrf_status_codes.h"
  2514. INTEGER , INTENT(IN) :: DataHandle
  2515. CHARACTER*(*) :: Element
  2516. CHARACTER*(*) :: DateStr
  2517. CHARACTER*(*) :: Data
  2518. INTEGER , INTENT(OUT) :: Status
  2519. INTEGER :: stat
  2520. Status = WRF_NO_ERR
  2521. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_char')
  2522. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2523. "none", Data, stat)
  2524. if (stat /= 0) then
  2525. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2526. Status = WRF_WARN_VAR_NF
  2527. RETURN
  2528. endif
  2529. RETURN
  2530. END SUBROUTINE ext_gr1_get_dom_td_char
  2531. !*****************************************************************************
  2532. SUBROUTINE ext_gr1_get_dom_td_double ( DataHandle,Element, DateStr, Data, &
  2533. Count, Outcount, Status )
  2534. USE gr1_data_info
  2535. IMPLICIT NONE
  2536. #include "wrf_status_codes.h"
  2537. INTEGER , INTENT(IN) :: DataHandle
  2538. CHARACTER*(*) , INTENT(IN) :: Element
  2539. CHARACTER*(*) , INTENT(IN) :: DateStr
  2540. real*8 , INTENT(OUT) :: Data(*)
  2541. INTEGER , INTENT(IN) :: Count
  2542. INTEGER , INTENT(OUT) :: OutCount
  2543. INTEGER , INTENT(OUT) :: Status
  2544. INTEGER :: idx
  2545. INTEGER :: stat
  2546. CHARACTER*(1000) :: VALUE
  2547. call wrf_debug ( DEBUG , 'Entering ext_gr1_get_dom_td_double')
  2548. Status = WRF_NO_ERR
  2549. CALL GET_METADATA_VALUE(fileinfo(DataHandle)%fileindex(:), TRIM(Element), DateStr, &
  2550. "none", Value, stat)
  2551. if (stat /= 0) then
  2552. CALL wrf_debug ( DEBUG , "GET_METADATA_VALUE failed for "//Element)
  2553. Status = WRF_WARN_VAR_NF
  2554. RETURN
  2555. endif
  2556. READ(Value,*,IOSTAT=stat)(Data(idx),idx=1,Count)
  2557. if (stat .ne. 0) then
  2558. CALL wrf_message("Reading data from"//Value//"failed")
  2559. Status = WRF_WARN_COUNT_TOO_LONG
  2560. RETURN
  2561. endif
  2562. Outcount = idx
  2563. RETURN
  2564. END SUBROUTINE ext_gr1_get_dom_td_double
  2565. !******************************************************************************
  2566. !* End of get_dom_td_* routines
  2567. !******************************************************************************
  2568. !******************************************************************************
  2569. !* Start of put_dom_td_* routines
  2570. !******************************************************************************
  2571. SUBROUTINE ext_gr1_put_dom_td_real8 ( DataHandle,Element, DateStr, Data, &
  2572. Count, Status )
  2573. USE gr1_data_info
  2574. IMPLICIT NONE
  2575. #include "wrf_status_codes.h"
  2576. INTEGER , INTENT(IN) :: DataHandle
  2577. CHARACTER*(*) :: Element
  2578. CHARACTER*(*) :: DateStr
  2579. real*8 , INTENT(IN) :: Data(*)
  2580. INTEGER , INTENT(IN) :: Count
  2581. INTEGER , INTENT(OUT) :: Status
  2582. CHARACTER(len=1000) :: tmpstr(1000)
  2583. INTEGER :: idx
  2584. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_real8')
  2585. if (committed(DataHandle)) then
  2586. do idx = 1,Count
  2587. write(tmpstr(idx),'(G17.10)')Data(idx)
  2588. enddo
  2589. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2590. Count, Status)
  2591. endif
  2592. RETURN
  2593. END SUBROUTINE ext_gr1_put_dom_td_real8
  2594. !*****************************************************************************
  2595. SUBROUTINE ext_gr1_put_dom_td_integer ( DataHandle,Element, DateStr, Data, &
  2596. Count, Status )
  2597. USE gr1_data_info
  2598. IMPLICIT NONE
  2599. #include "wrf_status_codes.h"
  2600. INTEGER , INTENT(IN) :: DataHandle
  2601. CHARACTER*(*) :: Element
  2602. CHARACTER*(*) :: DateStr
  2603. integer , INTENT(IN) :: Data(*)
  2604. INTEGER , INTENT(IN) :: Count
  2605. INTEGER , INTENT(OUT) :: Status
  2606. CHARACTER(len=1000) :: tmpstr(1000)
  2607. INTEGER :: idx
  2608. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_integer')
  2609. if (committed(DataHandle)) then
  2610. do idx = 1,Count
  2611. write(tmpstr(idx),'(G17.10)')Data(idx)
  2612. enddo
  2613. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2614. Count, Status)
  2615. endif
  2616. RETURN
  2617. END SUBROUTINE ext_gr1_put_dom_td_integer
  2618. !*****************************************************************************
  2619. SUBROUTINE ext_gr1_put_dom_td_logical ( DataHandle,Element, DateStr, Data, &
  2620. Count, Status )
  2621. USE gr1_data_info
  2622. IMPLICIT NONE
  2623. #include "wrf_status_codes.h"
  2624. INTEGER , INTENT(IN) :: DataHandle
  2625. CHARACTER*(*) :: Element
  2626. CHARACTER*(*) :: DateStr
  2627. logical , INTENT(IN) :: Data(*)
  2628. INTEGER , INTENT(IN) :: Count
  2629. INTEGER , INTENT(OUT) :: Status
  2630. CHARACTER(len=1000) :: tmpstr(1000)
  2631. INTEGER :: idx
  2632. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_logical')
  2633. if (committed(DataHandle)) then
  2634. do idx = 1,Count
  2635. write(tmpstr(idx),'(G17.10)')Data(idx)
  2636. enddo
  2637. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2638. Count, Status)
  2639. endif
  2640. RETURN
  2641. END SUBROUTINE ext_gr1_put_dom_td_logical
  2642. !*****************************************************************************
  2643. SUBROUTINE ext_gr1_put_dom_td_char ( DataHandle,Element, DateStr, Data, &
  2644. Status )
  2645. USE gr1_data_info
  2646. IMPLICIT NONE
  2647. #include "wrf_status_codes.h"
  2648. INTEGER , INTENT(IN) :: DataHandle
  2649. CHARACTER*(*) :: Element
  2650. CHARACTER*(*) :: DateStr
  2651. CHARACTER(len=*), INTENT(IN) :: Data
  2652. INTEGER , INTENT(OUT) :: Status
  2653. CHARACTER(len=1000) :: tmpstr(1)
  2654. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_char')
  2655. if (committed(DataHandle)) then
  2656. write(tmpstr(1),*)Data
  2657. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2658. 1, Status)
  2659. endif
  2660. RETURN
  2661. END SUBROUTINE ext_gr1_put_dom_td_char
  2662. !*****************************************************************************
  2663. SUBROUTINE ext_gr1_put_dom_td_double ( DataHandle,Element, DateStr, Data, &
  2664. Count, Status )
  2665. USE gr1_data_info
  2666. IMPLICIT NONE
  2667. #include "wrf_status_codes.h"
  2668. INTEGER , INTENT(IN) :: DataHandle
  2669. CHARACTER*(*) , INTENT(IN) :: Element
  2670. CHARACTER*(*) , INTENT(IN) :: DateStr
  2671. real*8 , INTENT(IN) :: Data(*)
  2672. INTEGER , INTENT(IN) :: Count
  2673. INTEGER , INTENT(OUT) :: Status
  2674. CHARACTER(len=1000) :: tmpstr(1000)
  2675. INTEGER :: idx
  2676. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_double')
  2677. if (committed(DataHandle)) then
  2678. do idx = 1,Count
  2679. write(tmpstr(idx),'(G17.10)')Data(idx)
  2680. enddo
  2681. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2682. Count, Status)
  2683. endif
  2684. RETURN
  2685. END SUBROUTINE ext_gr1_put_dom_td_double
  2686. !*****************************************************************************
  2687. SUBROUTINE ext_gr1_put_dom_td_real ( DataHandle,Element, DateStr, Data, &
  2688. Count, Status )
  2689. USE gr1_data_info
  2690. IMPLICIT NONE
  2691. #include "wrf_status_codes.h"
  2692. INTEGER , INTENT(IN) :: DataHandle
  2693. CHARACTER*(*) :: Element
  2694. CHARACTER*(*) :: DateStr
  2695. real , INTENT(IN) :: Data(*)
  2696. INTEGER , INTENT(IN) :: Count
  2697. INTEGER , INTENT(OUT) :: Status
  2698. CHARACTER(len=1000) :: tmpstr(1000)
  2699. INTEGER :: idx
  2700. call wrf_debug ( DEBUG , 'Entering ext_gr1_put_dom_td_real')
  2701. if (committed(DataHandle)) then
  2702. do idx = 1,Count
  2703. write(tmpstr(idx),'(G17.10)')Data(idx)
  2704. enddo
  2705. CALL gr1_build_string (td_output(DataHandle), DateStr//';'//Element, tmpstr, &
  2706. Count, Status)
  2707. endif
  2708. RETURN
  2709. END SUBROUTINE ext_gr1_put_dom_td_real
  2710. !******************************************************************************
  2711. !* End of put_dom_td_* routines
  2712. !******************************************************************************
  2713. !*****************************************************************************
  2714. SUBROUTINE gr1_build_string (string, Element, Value, Count, Status)
  2715. IMPLICIT NONE
  2716. #include "wrf_status_codes.h"
  2717. CHARACTER (LEN=*) , INTENT(INOUT) :: string
  2718. CHARACTER (LEN=*) , INTENT(IN) :: Element
  2719. CHARACTER (LEN=*) , INTENT(IN) :: Value(*)
  2720. INTEGER , INTENT(IN) :: Count
  2721. INTEGER , INTENT(OUT) :: Status
  2722. CHARACTER (LEN=2) :: lf
  2723. INTEGER :: IDX
  2724. lf=char(10)//' '
  2725. if (len_trim(string) == 0) then
  2726. string = lf//Element//' = '
  2727. else
  2728. string = trim(string)//lf//Element//' = '
  2729. endif
  2730. do idx = 1,Count
  2731. if (idx > 1) then
  2732. string = trim(string)//','
  2733. endif
  2734. string = trim(string)//' '//trim(adjustl(Value(idx)))
  2735. enddo
  2736. Status = WRF_NO_ERR
  2737. END SUBROUTINE gr1_build_string
  2738. !*****************************************************************************
  2739. SUBROUTINE gr1_get_new_handle(DataHandle)
  2740. USE gr1_data_info
  2741. IMPLICIT NONE
  2742. INTEGER , INTENT(OUT) :: DataHandle
  2743. INTEGER :: i
  2744. DataHandle = -1
  2745. do i=firstFileHandle, maxFileHandles
  2746. if (.NOT. used(i)) then
  2747. DataHandle = i
  2748. used(i) = .true.
  2749. exit
  2750. endif
  2751. enddo
  2752. RETURN
  2753. END SUBROUTINE gr1_get_new_handle
  2754. !******************************************************************************
  2755. SUBROUTINE gr1_get_levels(VarName, zidx, zsize, soil_layers, vert_stag, fraction, &
  2756. vert_unit, level1, level2)
  2757. use gr1_data_info
  2758. IMPLICIT NONE
  2759. integer :: zidx
  2760. integer :: zsize
  2761. logical :: soil_layers
  2762. logical :: vert_stag
  2763. logical :: fraction
  2764. integer :: vert_unit
  2765. integer :: level1
  2766. integer :: level2
  2767. character (LEN=*) :: VarName
  2768. ! Setup vert_unit, and vertical levels in grib units
  2769. if ((VarName .eq. 'LANDUSEF') .or. (VarName .eq. 'SOILCTOP') &
  2770. .or. (VarName .eq. 'SOILCBOT')) then
  2771. vert_unit = 109;
  2772. level1 = zidx
  2773. level2 = 0
  2774. else if ((zsize .gt. 1) .and. (.not. soil_layers) .and. (.not. fraction)) &
  2775. then
  2776. vert_unit = 119;
  2777. if (vert_stag) then
  2778. level1 = (10000*full_eta(zidx)+0.5)
  2779. else
  2780. level1 = (10000*half_eta(zidx)+0.5)
  2781. endif
  2782. level2 = 0
  2783. else
  2784. ! Set the vertical coordinate and level for soil and 2D fields
  2785. if (fraction) then
  2786. vert_unit = 109
  2787. level1 = zidx
  2788. level2 = 0
  2789. else if (soil_layers) then
  2790. vert_unit = 112
  2791. level1 = 100*(soil_depth(zidx) - 0.5*soil_thickness(zidx))+0.5
  2792. level2 = 100*(soil_depth(zidx) + 0.5*soil_thickness(zidx))+0.5
  2793. else if (VarName .eq. 'mu') then
  2794. vert_unit = 200
  2795. level1 = 0
  2796. level2 = 0
  2797. else if ((VarName .eq. 'Q2') .or. (VarName .eq. 'TH2') .or. &
  2798. (VarName .eq. 'T2')) then
  2799. vert_unit = 105
  2800. level1 = 2
  2801. level2 = 0
  2802. else if ((VarName .eq. 'Q10') .or. (VarName .eq. 'TH10') .or. &
  2803. (VarName .eq. 'U10') .or. (VarName .eq. 'V10')) then
  2804. vert_unit = 105
  2805. level1 = 10
  2806. level2 = 0
  2807. else
  2808. vert_unit = 1
  2809. level1 = 0
  2810. level2 = 0
  2811. endif
  2812. endif
  2813. end SUBROUTINE gr1_get_levels
  2814. !*****************************************************************************
  2815. SUBROUTINE gr1_fill_eta_levels(fileindex, FileFd, grib_tables, VarName, eta_levels)
  2816. IMPLICIT NONE
  2817. CHARACTER (len=*) :: fileindex
  2818. INTEGER :: FileFd
  2819. CHARACTER (len=*) :: grib_tables
  2820. character (len=*) :: VarName
  2821. REAL,DIMENSION(*) :: eta_levels
  2822. INTEGER :: center, subcenter, parmtbl
  2823. INTEGER :: swapped
  2824. INTEGER :: leveltype
  2825. INTEGER :: idx
  2826. INTEGER :: parmid
  2827. INTEGER :: tablenum
  2828. REAL :: tmp
  2829. INTEGER :: numindices
  2830. integer , DIMENSION(1000) :: indices
  2831. !
  2832. ! Read the levels from the grib file
  2833. !
  2834. CALL GET_GRIB_PARAM(grib_tables, VarName, center, subcenter, parmtbl, &
  2835. tablenum, parmid)
  2836. if (parmid == -1) then
  2837. call wrf_message ('Error getting grib parameter')
  2838. endif
  2839. leveltype = 119
  2840. CALL GET_GRIB_INDICES(fileindex(:), center, subcenter, parmtbl, &
  2841. parmid, "*", leveltype, &
  2842. -HUGE(1), -HUGE(1), -HUGE(1), -HUGE(1), indices, numindices)
  2843. do idx = 1,numindices
  2844. CALL READ_GRIB(fileindex(:),FileFd,indices(idx),eta_levels(idx))
  2845. enddo
  2846. !
  2847. ! Sort the levels--from highest (bottom) to lowest (top)
  2848. !
  2849. swapped = 1
  2850. sortloop : do
  2851. if (swapped /= 1) exit sortloop
  2852. swapped = 0
  2853. do idx=2, numindices
  2854. !
  2855. ! Remove duplicate levels, caused by multiple time periods in a
  2856. ! single file.
  2857. !
  2858. if (eta_levels(idx) == eta_levels(idx-1)) eta_levels(idx) = 0.0
  2859. if (eta_levels(idx) > eta_levels(idx-1)) then
  2860. tmp = eta_levels(idx)
  2861. eta_levels(idx) = eta_levels(idx - 1)
  2862. eta_levels(idx - 1) = tmp
  2863. swapped = 1
  2864. endif
  2865. enddo
  2866. enddo sortloop
  2867. end subroutine gr1_fill_eta_levels