-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_harmonic_output.f90
123 lines (85 loc) · 4.5 KB
/
write_harmonic_output.f90
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
114
115
116
117
118
119
120
121
122
123
subroutine write_harmonic_output(nx,ny,nz,X,Y,Z,missing_val,amp,pha,mean_var)
use netcdf
implicit none
character(len=*), parameter :: file_out="harmonic_out.nc"
integer :: nx, ny, nz
real :: X(nx), Y(ny), Z(nz), NN(2), missing_val
real :: amp(nx,ny,nz,2), pha(nx,ny,nz,2), mean_var(nx,ny,nz)
integer, parameter :: NDIMS3 = 3
integer, parameter :: NDIMS4 = 4
character(len=*), parameter :: n_NAME="harmonic"
character(len=*), parameter :: z_NAME="depth"
character(len=*), parameter :: y_NAME="latitude"
character(len=*), parameter :: x_NAME="longitude"
integer :: n_dimid, z_dimid, y_dimid, x_dimid, n_varid, z_varid, y_varid, x_varid
character(len=*), parameter :: amp_NAME="amp_temp"
character(len=*), parameter :: pha_NAME="pha_temp"
character(len=*), parameter :: m_NAME="temp"
integer :: amp_varid, pha_varid, m_varid, dimids3(NDIMS3), dimids4(NDIMS4)
character(len=*), parameter :: UNITS="units"
character(len=*), parameter :: n_UNITS="1st and 2nd harmonic"
character(len=*), parameter :: z_UNITS="m"
character(len=*), parameter :: y_UNITS="degrees_north"
character(len=*), parameter :: x_UNITS="degrees_east"
character(len=*), parameter :: amp_UNITS="units variable"
character(len=*), parameter :: pha_UNITS="rad"
character(len=*), parameter :: m_UNITS="degrees_C"
character(len=*), parameter :: LNAME="long_name"
character(len=*), parameter :: n_LNAME="1st and 2nd harmonic"
character(len=*), parameter :: z_LNAME="depth"
character(len=*), parameter :: y_LNAME="Latitude"
character(len=*), parameter :: x_LNAME="Longitude"
character(len=*), parameter :: amp_LNAME="Temperature"
character(len=*), parameter :: pha_LNAME="Angle"
character(len=*), parameter :: m_LNAME="Temperature"
integer :: retval, ncid, rhvarid
NN = (/1,2/)
retval = nf90_create(file_out, ior(nf90_noclobber,nf90_64bit_offset), ncid)
retval = nf90_def_dim(ncid, n_NAME, 2, n_dimid)
retval = nf90_def_dim(ncid, z_NAME, NZ, z_dimid)
retval = nf90_def_dim(ncid, y_NAME, NY, y_dimid)
retval = nf90_def_dim(ncid, x_NAME, NX, x_dimid)
retval = nf90_def_var(ncid, n_NAME, NF90_REAL, n_dimid, n_varid)
retval = nf90_def_var(ncid, z_NAME, NF90_REAL, z_dimid, z_varid)
retval = nf90_def_var(ncid, y_NAME, NF90_REAL, y_dimid, y_varid)
retval = nf90_def_var(ncid, x_NAME, NF90_REAL, x_dimid, x_varid)
retval = nf90_put_att(ncid, n_varid, UNITS, n_UNITS)
retval = nf90_put_att(ncid, z_varid, UNITS, z_UNITS)
retval = nf90_put_att(ncid, y_varid, UNITS, y_UNITS)
retval = nf90_put_att(ncid, x_varid, UNITS, x_UNITS)
retval = nf90_put_att(ncid, n_varid, LNAME, n_LNAME)
retval = nf90_put_att(ncid, z_varid, LNAME, z_LNAME)
retval = nf90_put_att(ncid, y_varid, LNAME, y_LNAME)
retval = nf90_put_att(ncid, x_varid, LNAME, x_LNAME)
retval = nf90_put_att(ncid, rhvarid,"title",&
&"code written by fecg: fecampos1302@gmail.com")
dimids3(1) = x_dimid
dimids3(2) = y_dimid
dimids3(3) = z_dimid
dimids4(1) = x_dimid
dimids4(2) = y_dimid
dimids4(3) = z_dimid
dimids4(4) = n_dimid
retval = nf90_def_var(ncid, m_NAME, NF90_REAL, dimids3, m_varid)
retval = nf90_def_var(ncid, amp_NAME, NF90_REAL, dimids4, amp_varid)
retval = nf90_def_var(ncid, pha_NAME, NF90_REAL, dimids4, pha_varid)
retval = nf90_put_att(ncid, m_varid, UNITS, m_UNITS)
retval = nf90_put_att(ncid, pha_varid, UNITS, pha_UNITS)
retval = nf90_put_att(ncid, amp_varid, UNITS, amp_UNITS)
retval = nf90_put_att(ncid, m_varid, LNAME, m_LNAME)
retval = nf90_put_att(ncid, pha_varid, LNAME, pha_LNAME)
retval = nf90_put_att(ncid, amp_varid, LNAME, amp_LNAME)
retval = nf90_put_att(ncid,m_varid,'missing_value', missing_val)
retval = nf90_put_att(ncid,pha_varid,'missing_value', missing_val)
retval = nf90_put_att(ncid,amp_varid,'missing_value', missing_val)
retval = nf90_enddef(ncid)
retval = nf90_put_var(ncid, n_varid, NN)
retval = nf90_put_var(ncid, z_varid, Z)
retval = nf90_put_var(ncid, y_varid, Y)
retval = nf90_put_var(ncid, x_varid, X)
retval = nf90_put_var(ncid, m_varid, mean_var)
retval = nf90_put_var(ncid, pha_varid, pha)
retval = nf90_put_var(ncid, amp_varid, amp)
retval = nf90_close(ncid)
return
end subroutine