File: rewrite_harvardf_data.f90

package info (click to toggle)
cmor 3.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,976 kB
  • sloc: ansic: 28,053; f90: 13,893; python: 12,699; sh: 3,739; makefile: 111
file content (113 lines) | stat: -rw-r--r-- 5,120 bytes parent folder | download | duplicates (5)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
      program rewrite_harvardf_data

!  Use CMOR routines to rewrite Harvard Forest obs data into CF-standard netCDF.
!  Start with data in easy-to-read ASCII text (Mathematica input) format, which
!  was produced by the script read_harvard_forest_obs_dat.py.

!  Note: first line of each input data file is ASCII text to be skipped over.

!		Curt Covey		January 2006

USE cmor_users_functions

      character(len = 25) :: input_file   = 'Test/tas_harvardf.txt'
      character(len = 20) :: output_file  = 'tas_harvardf.nc'
      character(len = 20) :: units_string = 'K'
!     character(len = 20) :: input_table  = 'IPCC_test_table_A'
!!$      character(len = 20) :: input_table  = 'IPCC_table_A2'
      character(len = 25) :: input_table  = 'Tables/CMIP6_day.json'

      character :: first_line    ! throwaway

      integer   :: iaxis(3)      ! identifier for axes (time, latitude, longitude)

!!$      integer, parameter :: ndatalines = 4383 ! # lines in file that contain data
      integer, parameter :: ndatalines = 10 ! # lines in file that contain data
                                              ! ( = total # lines in file - 1)
      integer, parameter :: np1 = ndatalines + 1

      double precision      :: lat(1)        ! single-member array to hold latitude
      double precision      :: lon(1)        ! single-member array to hold longitude
      double precision      :: blat(2)        ! single-member array to hold latitude
      double precision      :: blon(2)        ! single-member array to hold longitude
      double precision      :: t(ndatalines) ! array to hold time coordinate
      double precision      :: tbounds(np1)  ! array to hold time coordinate cell bounds
      real      :: x(ndatalines,1,1) ! array to hold data from each input data file
      double precision bt
      bt=0.
!    -Harvard Forest is located at 42.5 deg N, 72.2 deg W ...
      lat(1) = 42.5d0
      lon(1) = 360-72.2d0
      blat(1) = 42.5d0
      blon(1) = 360-72.2d0
      blat(2) = 42.5d0
      blon(2) = 360-72.2d0
!     ... and is 3000 acres ~ a circle with radius of 0.02 deg lat/lon:
      latlonrad = 0.02
      do i = 1, ndatalines
         t(i)       = i - 1.0  ! time coord  = "days since" =  0,       1, ...
         tbounds(i) = i - 1.5  ! time bounds =           -0.5,    +0.5,    ...
      enddo
      tbounds(np1) = ndatalines - 0.5

      print *, 'Opening ', input_file, '...'
      open(10, file = input_file)
      read(10, '(A)') first_line
      print    '(A)', 'First line begins with: ', first_line
      do i = 1, ndatalines
         read(10, '(F6.2)') x(i,1,1)
!        print *, x(i,1,1)
      enddo

      print *, 'Initializing CMOR ...'
      ierrorflag = cmor_setup(netcdf_file_action = 'replace')

      print *, 'Identifying output data sets for CMOR ...'
      ierrorflag = cmor_dataset_json("Test/CMOR_input_example.json")

!     print *, ' ** Time coordinate vector:', t
!     print *, ' ** Time bounds vector:',     tbounds

      print *, 'Defining coordinates for CMOR output data ...',t
      iaxis(1)   = cmor_axis(                                  &
                      table       = input_table,               &
                      table_entry = 'time',                    &
                      units       = 'days since 1992-1-1',     &
                      length      = ndatalines,                &
                      coord_vals  = t,                         &
                      cell_bounds = tbounds)

      iaxis(2)   = cmor_axis(                                  &
                      table       = input_table,               &
                      table_entry = 'latitude',                &
                      units       = 'degrees_north',           &
                      length      = 1,                         &
                      coord_vals  = lat,                       &
                      cell_bounds = blat)                       

      iaxis(3)   = cmor_axis(                                  &
                      table       = input_table,               &
                      table_entry = 'longitude',               &
                      units       = 'degrees_east',            &
                      length      = 1,                         &
                      coord_vals  = lon,                       &
                      cell_bounds = blon)

      print *, 'Defining CMOR output data variables ...'
      ivarb     =  cmor_variable(                              &
                      table       = input_table,               &
                      table_entry = 'tas',                     &
                      units       = units_string,              &
                      axis_ids    = iaxis)

!!$      print *, ' ** Data vector:', x

      print *, 'Writing CMOR output ...',shape(x)
      ierrorflag = cmor_write(                                 &
                      var_id    = ivarb,                       &
                      data      = x(:,1,1)+2.5)

      print *, 'Closing file(s) created by CMOR ...'
      ierrorflag = cmor_close()

      end program rewrite_harvardf_data