da_stage0_initialize.inc
References to this file elsewhere.
1 subroutine da_stage0_initialize(input_file, var, dim1, dim2, dim3, ds)
2
3 !-----------------------------------------------------------------------
4 ! Purpose: TBD
5 !-----------------------------------------------------------------------
6
7 implicit none
8
9 #include "netcdf.inc"
10
11 character (len=200), intent(in):: input_file ! NETCDF file name.
12 character (len=10), intent(in) :: var ! Variable to search for.
13 integer, intent(out) :: dim1 ! Dimensions of field.
14 integer, intent(out) :: dim2 ! Dimensions of field.
15 integer, intent(out) :: dim3 ! Dimensions of field.
16 real, intent(out) :: ds ! Grid resolution.
17
18 character (len=80) :: att_name ! Attribute name.
19 integer :: i ! Loop counters.
20 integer :: attlen ! Length of attribute.
21 integer :: cdfid ! NETCDF file id.
22 integer :: rcode ! Return code (0=ok).
23 integer :: length ! Length of filename.
24 integer :: id_var ! NETCDF variable ID.
25 integer :: ivtype ! 4=integer, 5=real, 6=d.p.
26 integer :: ndims !
27 integer :: natts ! Number of attributes.
28
29 integer :: dimids(10) !
30 integer :: dims(1:4) ! Dimensions of field.
31 real (kind=4), allocatable :: value_real(:) ! real attribute value.
32
33 ! if (trace_use) call da_trace_entry("da_stage0_initialize")
34
35 ! Check file exists:
36 length = len_trim(input_file)
37 rcode = nf_open(input_file(1:length), NF_NOwrite, cdfid)
38 if (rcode /= 0) then
39 write(unit=message(1),fmt='(A,A)') &
40 ' Error opening netcdf file ', input_file(1:length)
41 call da_error(__FILE__,__LINE__,message(1:1))
42 end if
43
44 ! Check variable is in file:
45 rcode = nf_inq_varid (cdfid, var, id_var)
46 if (rcode /= 0) then
47 write(unit=message(1),fmt='(A,A)') &
48 var, ' variable is not in input file'
49 call da_error(__FILE__,__LINE__,message(1:1))
50 end if
51
52 ! Get metadata (time, dimensions, global attributes):
53 rcode = nf_inq_var(cdfid, id_var, var, ivtype, ndims, dimids, natts)
54 do i = 1, ndims
55 rcode = nf_inq_dimlen(cdfid, dimids(i), dims(i))
56 end do
57 dim1 = dims(1)
58 dim2 = dims(2)
59 dim3 = dims(3)
60
61 ! Get resolution:
62 att_name = 'DX' ! Assume dx= dy.
63 rcode = nf_inq_att(cdfid, nf_global, att_name, ivtype, attlen)
64 allocate(value_real(1:attlen))
65 rcode = NF_GET_ATT_real(cdfid, nf_global, att_name, value_real)
66 ds = value_real(1)
67 deallocate(value_real)
68
69 rcode = nf_close(cdfid)
70
71 ! if (trace_use) call da_trace_exit("da_stage0_initialize")
72
73 end subroutine da_stage0_initialize
74
75