r5152 | xinzhang | 2011-09-26 21:04:33 -0700 (Mon, 26 Sep 2011) | 3 lines
[wrffire.git] / wrfv2_fire / external / io_esmf / ext_esmf_open_for_read.F90
blobe76570b49edba50c6d3ff12d2d58205b16e39b6b
1 !--- open_for_read_begin
2 SUBROUTINE ext_esmf_open_for_read_begin( FileName , Comm_compute, Comm_io, SysDepInfo, &
3                                          DataHandle , Status )
4   USE module_ext_esmf
5   IMPLICIT NONE
6   CHARACTER*(*)               :: FileName
7   INTEGER ,       INTENT(IN)  :: Comm_compute , Comm_io
8   CHARACTER*(*)               :: SysDepInfo
9   INTEGER ,       INTENT(OUT) :: DataHandle
10   INTEGER ,       INTENT(OUT) :: Status
11   ! Local declarations
12   INTEGER :: i
13   TYPE(ESMF_State), POINTER :: importstate
14   TYPE(ESMF_StateIntent_Flag) :: stateIntent
15   INTEGER :: rc, itemCount
17   CALL int_get_fresh_handle(i)
18   okay_to_write(i) = .false.
19   okay_to_read(i) = .false.
20   opened_for_read(i) = .true.
21   opened_for_write(i) = .false.
22   DataHandle = i
24   ! Grab the current importState and ensure that it is empty
25   CALL ESMF_ImportStateGetCurrent(importstate, rc)
26   IF ( rc /= ESMF_SUCCESS ) THEN
27     CALL wrf_error_fatal("ext_esmf_open_for_read:  ESMF_ImportStateGetCurrent failed" )
28   ENDIF
29   ! For now, If the import state is not empty, whine and die.
30 !TODO:  Eventually, use nested states to allow more than one auxinput stream 
31 !TODO:  to be supported via ESMF.  
32 !TODO:  Eventually, get smart about interacting with "needed" and "optional" 
33 !TODO:  named state items
34   CALL ESMF_StateGet( importstate, itemCount=itemCount, &
35                       stateintent=stateintent, rc=rc )
36   IF ( rc /= ESMF_SUCCESS ) THEN
37     CALL wrf_error_fatal("ext_esmf_open_for_read:  ESMF_ImportStateGet failed" )
38   ENDIF
39   IF ( stateintent /= ESMF_STATEINTENT_IMPORT ) THEN
40     CALL wrf_error_fatal("ext_esmf_open_for_read:  not an import state" )
41   ENDIF
42   IF ( itemCount /= 0 ) THEN
43     CALL wrf_error_fatal("ext_esmf_open_for_read:  import state not empty, io_esmf is currently limited to only one auxinput stream" )
44   ENDIF
46   Status = 0
47   RETURN  
48 END SUBROUTINE ext_esmf_open_for_read_begin
51 !--- open_for_read_commit
52 SUBROUTINE ext_esmf_open_for_read_commit( DataHandle , Status )
53   USE module_ext_esmf
54   IMPLICIT NONE
55   INTEGER , INTENT(IN ) :: DataHandle
56   INTEGER , INTENT(OUT) :: Status
58   IF ( int_valid_handle( DataHandle ) ) THEN
59     IF ( int_handle_in_use( DataHandle ) ) THEN
60       okay_to_read( DataHandle ) = .true.
61     ENDIF
62   ENDIF
64   Status = 0
65   RETURN  
66 END SUBROUTINE ext_esmf_open_for_read_commit