-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpom2k.n
622 lines (622 loc) · 23.6 KB
/
pom2k.n
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
C***********************************************************************
C
C NetCDF subroutines for pom2k.f
C
C For version number and date, see start of subroutine write_netcdf
C
C***********************************************************************
C
subroutine def_var_netcdf(ncid,name,nvdims,vdims,varid,
$ n_long_name,long_name,n_units,units,
$ n_coords,coords,lcoords,
$ nf_float,nf_noerr)
C **********************************************************************
C * *
C * FUNCTION : Defines a netCDF variable and its attributes. *
C * *
C * ncid ........ the netCDF I.D. *
C * name ........ the variable name *
C * nvdims ...... the number of dimensions of name *
C * vdims ....... a vector of length at least nvdims, *
C * containing the dimension I.D.s *
C * varid ....... the variable I.D. returned *
C * n_long_name . the number of characters in long_name *
C * long_name ... the long name for the variable *
C * n_units ..... the number of characters in units *
C * units ....... the units of the variable *
C * n_coords .... the number of characters in coords *
C * (if applicable) *
C * coords ...... the names of variables for the *
C * "coordinates" attribute *
C * (if applicable) *
C * lcoords ..... .true. if a "coordinates" attribute *
C * required, otherwise .false. *
c * nf_float .... an integer defining the netCDF *
C * variable type *
C * nf_noerr .... an integer defining the netCDF "no *
C * error" status *
C * *
C * (nf_float and nf_noerr are declared and defined in *
C * the file netcdf.inc "included" in the subroutine *
C * write_netcdf.) *
C * *
C **********************************************************************
C
integer vdims(4)
C
integer ncid,nf_noerr,nvdims,varid,n_long_name,n_units,n_coords
C
logical lcoords
C
character*(*) name,long_name,units,coords
C
integer status
C
status=nf_def_var(ncid,name,nf_float,nvdims,vdims,varid)
C
call handle_netcdf_error('nf_def_var ',
$ status,nf_noerr)
C
C write(6,1) name,varid
C 1 format('Variable ID returned by nf_def_var for variable ',
C $ a7,' = ',i5)
C
status=nf_put_att_text(ncid,varid,'long_name',
$ n_long_name,long_name)
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
status=nf_put_att_text(ncid,varid,'units',
$ n_units,units)
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
C Add coordinates attribute, if necessary:
C
if(lcoords) then
C
status=nf_put_att_text(ncid,varid,'coordinates',
$ n_coords,coords)
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
endif
C
return
C
end
C
subroutine handle_netcdf_error(routine,status,nf_noerr)
C **********************************************************************
C * *
C * FUNCTION : Checks for netCDF error. *
C * *
C **********************************************************************
C
implicit none
C
integer status,nf_noerr
C
character*20 routine
C
character*80 nf_strerror
C
if (status.ne.nf_noerr) then
C
write(6,1) routine,nf_strerror(status)
1 format('NetCDF routine ',a20,' terminated with error:'/2x,a80)
stop
C
else
C
return
C
endif
C
end
C
subroutine write_netcdf(netcdf_file,option)
C **********************************************************************
C * *
C * FUNCTION : Initialises, writes to and closed netCDF file. *
C * *
C * netcdf_file ....... name of output file *
C * option ............ 1 to initialise file *
C * 2 to write a set of data *
C * 3 to close file *
C * *
C * In order to include another variable: *
C * *
C * 1. Within the loop "if(option.eq.1) then": *
C * *
C * Insert appropriate "call def_var_netcdf(.....)", *
C * followed by "status=nf_put_att_<type>(.....)" *
C * statements for any additional attributes. Each *
C * of these latter statements should be followed by *
C * a "call handle_netcdf_error(.....)" statement. *
C * *
C * 2. Within the loop "if(option.eq.2) then": *
C * *
C * Insert appropriate *
C * "status=nf_put_var_<type>(.....)" statement, *
C * followed by a "call handle_netcdf_error(.....)" *
C * statement. *
C * *
C **********************************************************************
C
implicit none
C
include 'pom2k.c'
C
C Filename of netCDF "include" file:
C
include '/scv2000/gaojie/install/Netcdf-3.6.3/include/netcdf.inc'
C
integer option
C
character*120 netcdf_file
C
integer count(4),start(4),vdims(4)
C
integer dum_varid,dvm_varid
integer dx_varid,dy_varid
integer east_c_varid,east_e_varid,east_u_varid,east_v_varid
integer elb_varid
integer fsm_varid
integer h_varid
integer iout
integer ncid
integer north_c_varid,north_e_varid,north_u_varid,north_v_varid
integer rho_varid,rmean_varid,rot_varid
integer status,s_varid
integer time_dimid,time_varid,t_varid
integer uab_varid,u_varid
integer vab_varid,v_varid
integer w_varid
integer x_dimid
integer y_dimid
integer z_dimid,z_varid,zz_varid
C
save dum_varid,dvm_varid
save dx_varid,dy_varid
save east_c_varid,east_e_varid,east_u_varid,east_v_varid
save elb_varid
save fsm_varid
save h_varid
save iout
save ncid
save north_c_varid,north_e_varid,north_u_varid,north_v_varid
save rho_varid,rmean_varid,rot_varid
save s_varid
save time_dimid,time_varid,t_varid
save uab_varid,u_varid
save vab_varid,v_varid
save w_varid
save x_dimid
save y_dimid
save z_dimid,z_varid,zz_varid
C
C***********************************************************************
C
C source_n should agree with source defined in pom2k.f.
C
character*40 source_n
parameter(source_n='pom2k 2006-05-03')
C
c if(source.ne.source_n) then
C
c write(6,4)
c 4 format(/'Incompatible versions of program and include files ',
c $ '..... program terminated'/)
c stop
C
c end if
C
C***********************************************************************
C
if(option.eq.1) then
C
C Initialise netCDF ouput:
C
C Initialise time index:
C
iout=0
C
C Create netcdf file:
C
status=nf_create(netcdf_file,nf_clobber,ncid)
call handle_netcdf_error('nf_create ',
$ status,nf_noerr)
C write(6,1) ncid
C 1 format('ncid returned by nf_create = ',i5)
C
C Define global attributes:
C
status=nf_put_att_text(ncid,nf_global,'source',
$ 40,source)
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
status=nf_put_att_text(ncid,nf_global,'title',
$ 40,title)
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
C Define dimensions:
C
status=nf_def_dim(ncid,'time',nf_unlimited,time_dimid)
call handle_netcdf_error('nf_def_dim ',
$ status,nf_noerr)
C write(6,2) 'time',time_dimid
C 2 format('Dimension ID returned by nf_def_dim for variable ',
C $ a4,' = ',i5)
C
status=nf_def_dim(ncid,'z',kb,z_dimid)
call handle_netcdf_error('nf_def_dim ',
$ status,nf_noerr)
C write(6,2) 'z',z_dimid
C
status=nf_def_dim(ncid,'y',jm,y_dimid)
call handle_netcdf_error('nf_def_dim ',
$ status,nf_noerr)
C write(6,2) 'y',y_dimid
C
status=nf_def_dim(ncid,'x',im,x_dimid)
call handle_netcdf_error('nf_def_dim ',
$ status,nf_noerr)
C write(6,2) 'x',x_dimid
C
C Define variables and their attributes:
C
vdims(1)=time_dimid
C
call def_var_netcdf(ncid,'time',1,vdims,time_varid,
$ 4,'time',37,'days since '//time_start,
$ 1,' ',.false.,
$ nf_float,nf_noerr)
C
vdims(1)=z_dimid
C
call def_var_netcdf(ncid,'z',1,vdims,z_varid,
$ 18,'sigma of cell face',11,'sigma_level',
$ 1,' ',.false.,
$ nf_float,nf_noerr)
status=nf_put_att_text(ncid,z_varid,'standard_name',
$ 22,'ocean_sigma_coordinate')
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
status=nf_put_att_text(ncid,z_varid,'formula_terms',
$ 26,'sigma: z eta: elb depth: h')
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
call def_var_netcdf(ncid,'zz',1,vdims,zz_varid,
$ 20,'sigma of cell centre',11,'sigma_level',
$ 1,' ',.false.,
$ nf_float,nf_noerr)
status=nf_put_att_text(ncid,zz_varid,'standard_name',
$ 22,'ocean_sigma_coordinate')
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
status=nf_put_att_text(ncid,zz_varid,'formula_terms',
$ 27,'sigma: zz eta: elb depth: h')
call handle_netcdf_error('nf_put_att_text ',
$ status,nf_noerr)
C
vdims(1)=x_dimid
vdims(2)=y_dimid
C
call def_var_netcdf(ncid,'dx',2,vdims,dx_varid,
$ 19,'grid increment in x',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'dy',2,vdims,dy_varid,
$ 19,'grid increment in y',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'east_u',2,vdims,east_u_varid,
$ 19,'easting of u-points',5,'metre',
$ 14,'east_u north_u',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'east_v',2,vdims,east_v_varid,
$ 19,'easting of v-points',5,'metre',
$ 14,'east_v north_v',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'east_e',2,vdims,east_e_varid,
$ 27,'easting of elevation points',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'east_c',2,vdims,east_c_varid,
$ 23,'easting of cell corners',5,'metre',
$ 14,'east_c north_c',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'north_u',2,vdims,north_u_varid,
$ 20,'northing of u-points',5,'metre',
$ 14,'east_u north_u',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'north_v',2,vdims,north_v_varid,
$ 20,'northing of v-points',5,'metre',
$ 14,'east_v north_v',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'north_e',2,vdims,north_e_varid,
$ 28,'northing of elevation points',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'north_c',2,vdims,north_c_varid,
$ 24,'northing of cell corners',5,'metre',
$ 14,'east_c north_c',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'rot',2,vdims,rot_varid,
$ 34,'Rotation angle of x-axis wrt. east',6,'degree',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'h',2,vdims,h_varid,
$ 23,'undisturbed water depth',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'fsm',2,vdims,fsm_varid,
$ 17,'free surface mask',13,'dimensionless',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'dum',2,vdims,dum_varid,
$ 15,'u-velocity mask',13,'dimensionless',
$ 14,'east_u north_u',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'dvm',2,vdims,dvm_varid,
$ 15,'v-velocity mask',13,'dimensionless',
$ 14,'east_v north_v',.true.,
$ nf_float,nf_noerr)
C
vdims(1)=x_dimid
vdims(2)=y_dimid
vdims(3)=z_dimid
C
call def_var_netcdf(ncid,'rmean',3,vdims,rmean_varid,
$ 25,'horizontally-averaged rho',13,'dimensionless',
$ 17,'east_e north_e zz',.true.,
$ nf_float,nf_noerr)
C
vdims(1)=x_dimid
vdims(2)=y_dimid
vdims(3)=time_dimid
C
call def_var_netcdf(ncid,'uab',3,vdims,uab_varid,
$ 16,'depth-averaged u',9,'metre/sec',
$ 14,'east_u north_u',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'vab',3,vdims,vab_varid,
$ 16,'depth-averaged v',9,'metre/sec',
$ 14,'east_v north_v',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'elb',3,vdims,elb_varid,
$ 17,'surface elevation',5,'metre',
$ 14,'east_e north_e',.true.,
$ nf_float,nf_noerr)
C
vdims(1)=x_dimid
vdims(2)=y_dimid
vdims(3)=z_dimid
vdims(4)=time_dimid
C
call def_var_netcdf(ncid,'u',4,vdims,u_varid,
$ 10,'x-velocity',9,'metre/sec',
$ 17,'east_u north_u zz',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'v',4,vdims,v_varid,
$ 10,'y-velocity',9,'metre/sec',
$ 17,'east_v north_v zz',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'w',4,vdims,w_varid,
$ 10,'z-velocity',9,'metre/sec',
$ 16,'east_e north_e z',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'t',4,vdims,t_varid,
$ 21,'potential temperature',1,'K',
$ 17,'east_e north_e zz',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'s',4,vdims,s_varid,
$ 23,'salinity x rho / rhoref',3,'PSS',
$ 17,'east_e north_e zz',.true.,
$ nf_float,nf_noerr)
C
call def_var_netcdf(ncid,'rho',4,vdims,rho_varid,
$ 21,'(density-1000)/rhoref',13,'dimensionless',
$ 17,'east_e north_e zz',.true.,
$ nf_float,nf_noerr)
C
C End definitions:
C
status=nf_enddef(ncid)
call handle_netcdf_error('nf_enddef ',
$ status,nf_noerr)
C
C Write initial data:
C
status=nf_put_var_real(ncid,z_varid,z)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,zz_varid,zz)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,dx_varid,dx)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,dy_varid,dy)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,east_u_varid,east_u)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,east_v_varid,east_v)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,east_e_varid,east_e)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,east_c_varid,east_c)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,north_u_varid,north_u)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,north_v_varid,north_v)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,north_e_varid,north_e)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,north_c_varid,north_c)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,rot_varid,rot)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,h_varid,h)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,fsm_varid,fsm)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,dum_varid,dum)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,dvm_varid,dvm)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
status=nf_put_var_real(ncid,rmean_varid,rmean)
call handle_netcdf_error('nf_put_var_real ',
$ status,nf_noerr)
C
C-----------------------------------------------------------------------
C
else if(option.eq.2) then
C
C Write a set of data:
C
iout=iout+1
start(1)=iout
count(1)=1
C
status=nf_put_vara_real(ncid,time_varid,start,count,time)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
start(1)=1
start(2)=1
start(3)=iout
count(1)=im
count(2)=jm
count(3)=1
C
status=nf_put_vara_real(ncid,uab_varid,start,count,uab)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,vab_varid,start,count,vab)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,elb_varid,start,count,elb)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
start(1)=1
start(2)=1
start(3)=1
start(4)=iout
count(1)=im
count(2)=jm
count(3)=kb
count(4)=1
C
status=nf_put_vara_real(ncid,u_varid,start,count,u)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,v_varid,start,count,v)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,w_varid,start,count,w)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,t_varid,start,count,t)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,s_varid,start,count,s)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
status=nf_put_vara_real(ncid,rho_varid,start,count,rho)
call handle_netcdf_error('nf_put_vara_real ',
$ status,nf_noerr)
C
C-----------------------------------------------------------------------
C
else if(option.eq.3) then
C
C Close file:
C
status=nf_close(ncid)
call handle_netcdf_error('nf_close ',
$ status,nf_noerr)
C
C-----------------------------------------------------------------------
C
else
C
write(6,3)
3 format(/'Invalid option for subroutine write_netcdf ..... ',
$ 'program terminated'/)
stop
C
endif
C
C-----------------------------------------------------------------------
C
return
C
end
C
C End of source code
C
C-----------------------------------------------------------------------
C