File: cdi_read_f2003.f90

package info (click to toggle)
cdo 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 49,836 kB
  • sloc: cpp: 185,271; ansic: 95,766; sh: 7,192; f90: 6,147; makefile: 1,977; ruby: 1,078; csh: 1,028; python: 995; fortran: 319; pascal: 219; perl: 9
file content (91 lines) | stat: -rw-r--r-- 2,607 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
PROGRAM CDIREADF2003
  use iso_c_binding
  use mo_cdi

  IMPLICIT NONE

  INTEGER :: gsize, nmiss
  INTEGER :: nlevel, nvars, code
  INTEGER :: vdate, vtime, status, ilev
  INTEGER :: streamID, varID, gridID, zaxisID
  INTEGER :: tsID, vlistID, taxisID
  DOUBLE PRECISION, ALLOCATABLE :: field(:,:)
  CHARACTER(kind=c_char), POINTER, DIMENSION(:) :: &
       msg, cdi_version
  CHARACTER(kind=c_char, LEN = cdi_max_name + 1) :: &
       name, longname, units
  INTEGER :: name_c_len, longname_c_len, units_c_len

  cdi_version => cdiLibraryVersion()

  WRITE (0, '(a,132a)') 'cdi version: ', cdi_version

  ! Open the dataset
  streamID = streamOpenRead(C_CHAR_"example_f2003.nc"//C_NULL_CHAR)
  IF ( streamID < 0 ) THEN
    PRINT *,  'Could not Read the file.'
    msg => cdiStringError(streamID)
    WRITE(0,'(132a)') msg
    STOP 1
  END IF

  ! Get the variable list of the dataset
  vlistID = streamInqVlist(streamID)

  nvars = vlistNvars(vlistID)

  DO varID = 0, nvars-1
    code = vlistInqVarCode(vlistID, varID)
    CALL vlistInqVarName(vlistID, varID, name)
    CALL vlistInqVarLongname(vlistID, varID, longname)
    CALL vlistInqVarUnits(vlistID, varID, units)

    ! CALL ctrim(name)
    ! CALL ctrim(longname)
    ! CALL ctrim(units)

    longname_c_len = c_len(longname)
    name_c_len = c_len(name)
    units_c_len = c_len(units)
    PRINT '(a,2(i0,a),132a)', 'Parameter: ', varID+1, ' ', code, ' ', &
         name(1:name_c_len), ' ', longname(1:longname_c_len), ' ', &
         units(1:units_c_len), ' |'

  END DO

  ! Get the Time axis form the variable list
  taxisID = vlistInqTaxis(vlistID)

  ! Loop over the time steps
  DO tsID = 0, 999999
    ! Read the time step
    status = streamInqTimestep(streamID, tsID)
    IF ( status == 0 ) exit

    ! Get the verification date and time
    vdate = taxisInqVdate(taxisID)
    vtime = taxisInqVtime(taxisID)

    PRINT '(a,i3,i10,i10)', 'Timestep: ', tsID+1, vdate, vtime

    ! Read the variables at the current timestep
    DO varID = 0, nvars-1
      gridID = vlistInqVarGrid(vlistID, varID)
      gsize = gridInqSize(gridID)
      zaxisID = vlistInqVarZaxis(vlistID, varID)
      nlevel = zaxisInqSize(zaxisID)
      ALLOCATE(field(gsize, nlevel))
      CALL streamReadVar(streamID, varID, field, nmiss)
      DO ilev = 1, nlevel
        PRINT '(a,i3,a,i3,a,f10.5,1x,f10.5)', '   var=', varID+1, &
             ' level=', ilev, ':', &
             MINVAL(field(:,ilev)), MAXVAL(field(:,ilev))
      END DO
      DEALLOCATE(field)
    END DO
  END DO

  ! Close the input stream
  CALL streamClose(streamID)

END PROGRAM CDIREADF2003