Blame view

src/write_output.f90 5.58 KB
4e5b4414   Jérémy Baudry   ajout commentaire...
1

c2c1e911   Dany Dumont   Renommage de vari...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
!____________________________________________________________________
!
!DESCRIPTION: This routine create the NETCDF output
!             file. You must have the FORTRAN NETCDF libraries
!             installed on your computer  to use this routine.
!
!____________________________________________________________________

!INTERFACE:
subroutine write_output

!MODULE USES:
   use netcdf
   use parameters                 

!LOCAL PARAMETERS:

   implicit none

!INCLUDES:
   include 'netcdf.inc'

   integer :: ncid
c2c1e911   Dany Dumont   Renommage de vari...
25
   integer :: xID
37b993a2   Dany Dumont   Nettoyage et reso...
26
27
28
   integer :: fID
   integer :: rID
   integer :: hID
c2c1e911   Dany Dumont   Renommage de vari...
29
30
   integer :: tID
   integer :: EID
37b993a2   Dany Dumont   Nettoyage et reso...
31
   integer :: f_varID
c2c1e911   Dany Dumont   Renommage de vari...
32
33
34
35
36
37
38
   integer :: x_varID
   integer :: t_varID
   integer :: stat
   integer :: Dmax_varID
   integer :: Dave_varID
   integer :: c_varID
   integer :: h_varID
c2c1e911   Dany Dumont   Renommage de vari...
39
   integer :: fsdID
37b993a2   Dany Dumont   Nettoyage et reso...
40
   integer :: r_varID
c2c1e911   Dany Dumont   Renommage de vari...
41
42
   integer :: SrcID
   integer :: HsID
c2c1e911   Dany Dumont   Renommage de vari...
43
   integer :: hcat_varID
31a3ff4d   Dany Dumont   Changement de la ...
44
   integer :: itdID
c2c1e911   Dany Dumont   Renommage de vari...
45
46
47

   stat=nf90_create(namefile,cmode=or(nf90_clobber,nf90_64bit_offset),ncid=ncid)
   call handle_err(stat)
4e5b4414   Jérémy Baudry   ajout commentaire...
48

c2c1e911   Dany Dumont   Renommage de vari...
49
   ! dimensions
37b993a2   Dany Dumont   Nettoyage et reso...
50
   stat=nf90_def_dim(ncid,"omega",nf,fID)
c2c1e911   Dany Dumont   Renommage de vari...
51
   call handle_err(stat)
4e5b4414   Jérémy Baudry   ajout commentaire...
52

c2c1e911   Dany Dumont   Renommage de vari...
53
54
55
56
57
58
   stat=nf90_def_dim(ncid,"x"   ,nx,xID)
   call handle_err(stat)

   stat=nf90_def_dim(ncid,"time",nt,tID)
   call handle_err(stat)

37b993a2   Dany Dumont   Nettoyage et reso...
59
   stat=nf90_def_dim(ncid,"dcat",nr,rID)
c2c1e911   Dany Dumont   Renommage de vari...
60
61
62
63
64
65
   call handle_err(stat)

   stat=nf90_def_dim(ncid,"hcat",nh,hID)
   call handle_err(stat)

   ! coordinates
37b993a2   Dany Dumont   Nettoyage et reso...
66
   stat=nf90_def_var(ncid,"omega",nf90_double,fID,f_varID)
c2c1e911   Dany Dumont   Renommage de vari...
67
68
69
70
71
72
73
74
75
76
77
   call handle_err(stat)

   stat=nf90_def_var(ncid,"x",nf90_double,xID,x_varID)
   call handle_err(stat)

   stat=nf90_def_var(ncid,"time",nf90_double,tID,t_varID)
   call handle_err(stat)

   stat=nf90_def_var(ncid,"hcat",nf90_double,hID,hcat_varID)
   call handle_err(stat)

37b993a2   Dany Dumont   Nettoyage et reso...
78
   stat=nf90_def_var(ncid,"dcat",nf90_double,rID,r_varID)
c2c1e911   Dany Dumont   Renommage de vari...
79
80
81
82
   call handle_err(stat)

   ! variables
   ! (x, f, t)
37b993a2   Dany Dumont   Nettoyage et reso...
83
   stat=nf90_def_var(ncid,"E",nf90_double,(/xID,fID,tID/),EID)
c2c1e911   Dany Dumont   Renommage de vari...
84
85
   call handle_err(stat)

37b993a2   Dany Dumont   Nettoyage et reso...
86
   stat=nf90_def_var(ncid,"Sice",nf90_double,(/xID,fID,tID/),SrcID)
c2c1e911   Dany Dumont   Renommage de vari...
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
   call handle_err(stat)

   ! (x)
   stat=nf90_def_var(ncid,"dave",nf90_double,xID,Dave_varID)
   call handle_err(stat)

   stat=nf90_def_var(ncid,"dmax",nf90_double,xID,Dmax_varID)
   call handle_err(stat)

   stat=nf90_def_var(ncid,"icec",nf90_double,xID,c_varID)
   call handle_err(stat)

   stat=nf90_def_var(ncid,"ithk",nf90_double,xID,h_varID)
   call handle_err(stat)

31a3ff4d   Dany Dumont   Changement de la ...
102
   ! (x, r, h, t)
37b993a2   Dany Dumont   Nettoyage et reso...
103
   stat=nf90_def_var(ncid,"fsd",nf90_double,(/xID,rID,hID,tID/),fsdID)
c2c1e911   Dany Dumont   Renommage de vari...
104
105
   call handle_err(stat)

31a3ff4d   Dany Dumont   Changement de la ...
106
107
   ! (x, t)
   stat=nf90_def_var(ncid,"hs",nf90_double,(/xID,tID/),HsID)
c2c1e911   Dany Dumont   Renommage de vari...
108
109
110
   call handle_err(stat)

   ! (x, h)
31a3ff4d   Dany Dumont   Changement de la ...
111
   stat=nf90_def_var(ncid,"itd",nf90_double,(/xID,hID/),itdID)
c2c1e911   Dany Dumont   Renommage de vari...
112
113
114
115
   call handle_err(stat)

   ! set attributes
   stat=nf_put_att_text(ncid,xID,'units',10,'km')
37b993a2   Dany Dumont   Nettoyage et reso...
116
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
117
   stat=nf_put_att_text(ncid,xID,'axis',1,'X')
37b993a2   Dany Dumont   Nettoyage et reso...
118
119
120
   call handle_err(stat)
   stat=nf_put_att_text(ncid,xID,'long_name',10,'Distance')
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
121

37b993a2   Dany Dumont   Nettoyage et reso...
122
123
124
125
126
127
128
129
130
   stat=nf_put_att_text(ncid,rID,'units',5,'m')
   call handle_err(stat)
   stat=nf_put_att_text(ncid,rID,'long_name',10,'Floe size')
   call handle_err(stat)

   stat=nf_put_att_text(ncid,fID,'units',5,'Hz')
   call handle_err(stat)
   stat=nf_put_att_text(ncid,fID,'long_name',10,'Frequency')
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
131
132

   stat=nf_put_att_text(ncid,hID,'units',5,'m')
37b993a2   Dany Dumont   Nettoyage et reso...
133
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
134
   stat=nf_put_att_text(ncid,hID,'axis',1,'Z')
37b993a2   Dany Dumont   Nettoyage et reso...
135
136
137
   call handle_err(stat)
   stat=nf_put_att_text(ncid,hID,'long_name',20,'Ice thickness')
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
138
139

   stat=nf_put_att_text(ncid,tID,'units',7,'hours')
37b993a2   Dany Dumont   Nettoyage et reso...
140
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
141
   stat=nf_put_att_text(ncid,tID,'axis',1,'T')
37b993a2   Dany Dumont   Nettoyage et reso...
142
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
143
   stat=nf_put_att_text(ncid,tID,'long_name',4,'Time')
37b993a2   Dany Dumont   Nettoyage et reso...
144
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
145
146

   stat=nf_put_att_text(ncid,HsID,'units',1,'m')
37b993a2   Dany Dumont   Nettoyage et reso...
147
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
148
   stat=nf_put_att_text(ncid,HsID,'long_name',23,               &
37b993a2   Dany Dumont   Nettoyage et reso...
149
150
        'Significant Wave Height')
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
151
152

   stat=nf_put_att_text(ncid,EID,'units',10,'m2 s rad-1')
37b993a2   Dany Dumont   Nettoyage et reso...
153
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
154
155
   stat=nf_put_att_text(ncid,EID,'long_name',50,                &
        'Sea surface wave variance spectral density')
37b993a2   Dany Dumont   Nettoyage et reso...
156
   call handle_err(stat)
c2c1e911   Dany Dumont   Renommage de vari...
157

31a3ff4d   Dany Dumont   Changement de la ...
158
159
160
   stat=nf_put_att_text(ncid,fsdID,'units',10,'m m-1')
   stat=nf_put_att_text(ncid,fsdID,'long_name',50,                &
        'Floe size and thickness distribution')
37b993a2   Dany Dumont   Nettoyage et reso...
161

c2c1e911   Dany Dumont   Renommage de vari...
162
163
164
165
166
   ! end file definition
   stat=nf90_enddef(ncid)
   call handle_err(stat)

   ! populate variables
37b993a2   Dany Dumont   Nettoyage et reso...
167
   stat=nf90_put_var(ncid,f_varID,omega)
c2c1e911   Dany Dumont   Renommage de vari...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
   call handle_err(stat)

   stat=nf90_put_var(ncid,EID,E)
   call handle_err(stat)

   stat=nf90_put_var(ncid,SrcID,S_ice)
   call handle_err(stat)

   stat=nf90_put_var(ncid,Dmax_varID,Dmax)
   call handle_err(stat)

   stat=nf90_put_var(ncid,Dave_varID,Dave)
   call handle_err(stat)

   stat=nf90_put_var(ncid,t_varID,time)
   call handle_err(stat)

   stat=nf90_put_var(ncid,x_varID,x_axis)
   call handle_err(stat)

   stat=nf90_put_var(ncid,c_varID,C_ice)
   call handle_err(stat)

   stat=nf90_put_var(ncid,h_varID,h)
   call handle_err(stat)

31a3ff4d   Dany Dumont   Changement de la ...
194
   stat=nf90_put_var(ncid,fsdID,fsd)
c2c1e911   Dany Dumont   Renommage de vari...
195
196
   call handle_err(stat)

37b993a2   Dany Dumont   Nettoyage et reso...
197
   stat=nf90_put_var(ncid,r_varID,middle_floe_cat)
c2c1e911   Dany Dumont   Renommage de vari...
198
199
200
201
202
203
204
205
   call handle_err(stat)

   stat=nf90_put_var(ncid,hcat_varID,middle_h_cat)
   call handle_err(stat)

   stat=nf90_put_var(ncid,HsID,h_sign)
   call handle_err(stat)

31a3ff4d   Dany Dumont   Changement de la ...
206
   stat=nf90_put_var(ncid,itdID,itd)
c2c1e911   Dany Dumont   Renommage de vari...
207
208
209
210
   call handle_err(stat)

   stat=nf90_close(ncid)
   call handle_err(stat)
d380ec6c   Jérémy Baudry   second commit
211
212
213
        
contains

d380ec6c   Jérémy Baudry   second commit
214
subroutine handle_err(stat)
d380ec6c   Jérémy Baudry   second commit
215

c2c1e911   Dany Dumont   Renommage de vari...
216
217
218
219
220
221
222
   integer, intent(in) :: stat

   if ( stat /= nf90_noerr ) then
      write(*,*)trim(nf90_strerror(stat))
      stop 'unable to write the netcdf output' 
   end if

d380ec6c   Jérémy Baudry   second commit
223
end subroutine handle_err
81dede1c   Jérémy Baudry   first commit
224

81dede1c   Jérémy Baudry   first commit
225
226

end subroutine write_output