-
Notifications
You must be signed in to change notification settings - Fork 0
/
vs_trih2nc.m
1567 lines (1399 loc) · 87.4 KB
/
vs_trih2nc.m
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
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = vs_trih2nc(vsfile,varargin)
pkg load netcdf
addpath('');
addpath('./misc/');
addpath('./applications/delft3d/');
addpath('./applications/delft3d_matlab/');
addpath('./io/netcdf/');
addpath('./io/netcdf/nctools/');
addpath('./io/netcdf/snctools/');
addpath('./io/netcdf/snctools/private/');
addpath('./general/el_fun/');
addpath('./general/el_mat/');
addpath('./general/grid_fun/');
addpath('./general/io_fun/');
addpath('./general/nan_fun/');
addpath('./general/string_fun/');
%vs_trih2nc Convert part of a Delft3D trih file to netCDF-CF
%
% vs_trih2nc(NEFISfile,<'keyword',value>)
% vs_trih2nc(NEFISfile,<netCDFfile>,<'keyword',value>)
%
% converts Delft3D trih file (NEFIS file) to a netCDF file which has
% default name <RUNID>_his.nc to conform with default dflowfm history output.
% Do specify timezone and epsg code, to conform to CF standard and facilitate reuse.
%
% Example:
%
% vs_trih2nc('P:\aproject\trih-n15.dat','epsg',28992,'timezone',timezone_code2iso('GMT'))
%
% nc looks same as history nc of dflowfm, so be used in dflowfm.analyseHis, and
% loads well into Quickplot.
%
% Example how to use this netCDF file: read all
% H = nc2struct(ncfile)
%
% Example how to use this netCDF file: select one platform
% dflowfm.indexHis(ncfile,<platform_name>);
% ind = 48;
% D.platform_name = nc_varget (ncfile,'platform_name',[ ind-1 0],[ 1 -1 ]);
% D.eta = nc_varget (ncfile,'waterlevel' ,[0 ind-1 ],[-1 1 ]);
% D.u = nc_varget (ncfile,'u_x' ,[0 ind-1 0],[-1 1 -1]);
% D.v = nc_varget (ncfile,'u_y' ,[0 ind-1 0],[-1 1 -1]);
% D.dep = nc_varget (ncfile,'depth' ,[ ind-1 ],[1]);
% D.datenum = nc_cf_time(ncfile)
%
% Note: you can make an nc_dump cdl ascii file a char for keyword dump:
% vs_trih2nc('tst.dat','dump','tst.cdl');
% Note: you can save only a subset of stations, or reorder them, to netCDF file with keyword 'ind'
%
%See also: vs_trim2nc for trim-*.dat delft3d-flow map file,
% netcdf, snctools, vs_use, dflowfm, delft3d_io_obs, dflowfm.indexHis, dflowfm.analyseHis
% TO DO add morphological! depth
% TO DO check consistency with delft3d_to_netcdf.exe of Bert Jagers
% TO DO add sediment, turbulence etc
% TO DO add cell methods to xcor = mean(x)
% to do merge with OpenEarthTools\matlab\applications\cosmos\code\OMSRunner\fileio\trih2nc
%% --------------------------------------------------------------------
% Copyright (C) 2010 Deltares
%
% Gerben de Boer
%
%
% Deltares
% P.O. Box 177
% 2600 MH Delft
% The Netherlands
%
% This library is free software: you can redistribute it and/or
% modify it under the terms of the GNU Lesser General Public
% License as published by the Free Software Foundation, either
% version 2.1 of the License, or (at your option) any later version.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library. If not, see <http://www.gnu.org/licenses/>.
% --------------------------------------------------------------------
%% This tools is part of <a href="http://OpenEarth.Deltares.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute
% your own tools.
%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% $Id: vs_trih2nc.m 14419 2018-06-14 10:03:16Z schrijve $
% $Date: 2018-06-14 18:03:16 +0800 (Thu, 14 Jun 2018) $
% $Author: schrijve $
% $Revision: 14419 $
% $HeadURL: https://svn.oss.deltares.nl/repos/openearthtools/trunk/matlab/applications/delft3d/vs_trih2nc.m $
% $Keywords: $
%% keywords
OPT.Format = 'classic'; % '64bit','classic','netcdf4','netcdf4_classic'
OPT.refdatenum = datenum(0000,0,0); % matlab datenumber convention: A serial date number of 1 corresponds to Jan-1-0000. Gives wrong dates in ncbrowse due to different calendars. Must use doubles here.
OPT.refdatenum = datenum(1970,1,1); % linux datenumber convention
OPT.institution = '';
OPT.timezone = ''; %timezone_code2iso('GMT');
OPT.epsg = [];
OPT.type = 'single'; %'double'; % the nefis file is by default single precision, se better isn't useful
OPT.debug = 0;
OPT.time = 0; % subset of time indices in NEFIS file, 1-based
OPT.dump = 1;
OPT.quiet = 'quiet';
OPT.stride = 0; % write chunks per layer in case of large 3D matrices
OPT.ind = 0; % index of stations to include in netCDF file, 0=all
OPT.crs.ind = 0; % index of cross-sections to include in netCDF file, 0=all
OPT.trajectory = 0; % consider 'Stations' dimension as spatial trajectory dimension
OPT.name = ''; % addition to nc-filename
OPT.title = ['NetCDF created from NEFIS-file ',filenameext(vsfile)];
% TO DO: allow to transform sub-period too.
% TO DO: implement WI and PI from griddata_near2, and add rename dimension 'Station' to 'distance'
% TO DO: make QP fit for trajectory plotting
if nargin==0
varargout = {OPT};
return
end
% if verLessThan('matlab','7.12.0.635')
% error('At least Matlab release R2011a is required for writing netCDF files due tue NCWRITESCHEMA.')
% end
if ~odd(nargin)
ncfile = varargin{1};
varargin = {varargin{2:end}};
OPT = setproperty(OPT,varargin{:});
else
OPT = setproperty(OPT,varargin{:});
runid = filename(vsfile); runid = runid(6:end); % remove 'trih-'
ncfile = fullfile(fileparts(vsfile),['trih-', runid ,OPT.name,'.nc']); % '_his' is same as Delft3D-FM
end
tmp=dir(vsfile);
if isempty(tmp)
error(['file does not exist: ',vsfile])
end
if (tmp.bytes > 2^31) & strcmpi(OPT.Format,'classic')
fprintf(2,'> Delft3D NEFIS files larger than 2 Gb cannot be mapped entirely to netCDF classic format, set keyword vs_trim2nc(...,''Format'',''64bit'').\n')
end
%% 0 Read raw data
F = vs_use(vsfile,'quiet');
if ~strcmp(F.SubType,'Delft3D-trih')
error([mfilename ' works only for Delft3D-trih file, perhaps you needed vs_trim2nc for the Delft3D-trim file.'])
end
disp('Reading time...')
T.datenum = vs_time(F,OPT.time,'quiet');
if OPT.time==0
OPT.time = 1:length(T.datenum);
end
I = vs_get_constituent_index(F);
M.datestr = datestr(datenum(vs_get(F,'his-version','FLOW-SIMDAT' ,'quiet'),'yyyymmdd HHMMSS'),31);
M.version = [strtrim(vs_get(F,'his-version','FLOW-SYSTXT' ,'quiet')),', file version: ',...
strtrim(vs_get(F,'his-version','FILE-VERSION','quiet'))];
M.description = vs_get(F,'his-version','FLOW-RUNTXT',OPT.quiet);
%% 1a Create file (add all NEFIS 'map-version' group info)
% Add overall meta info
% http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.4/cf-conventions.html#description-of-file-contents
nc = struct('Name','/','Format',OPT.Format);
nc.Attributes( 1) = struct('Name','title' ,'Value', OPT.title);
nc.Attributes(end+1) = struct('Name','institution' ,'Value', OPT.institution);
nc.Attributes(end+1) = struct('Name','source' ,'Value', 'Delft3D trih file');
nc.Attributes(end+1) = struct('Name','history' ,'Value', ['Original filename: ',filenameext(vsfile),...
', ' ,M.version,...
', file date:',M.datestr,...
', transformation to netCDF: $HeadURL: https://svn.oss.deltares.nl/repos/openearthtools/trunk/matlab/applications/delft3d/vs_trih2nc.m $ $Id: vs_trih2nc.m 14419 2018-06-14 10:03:16Z schrijve $']);
nc.Attributes(end+1) = struct('Name','references' ,'Value', 'http://svn.oss.deltares.nl');
nc.Attributes(end+1) = struct('Name','email' ,'Value', '');
nc.Attributes(end+1) = struct('Name','comment' ,'Value', '');
nc.Attributes(end+1) = struct('Name','version' ,'Value', M.version);
nc.Attributes(end+1) = struct('Name','Conventions' ,'Value', 'CF-1.6');
nc.Attributes(end+1) = struct('Name','terms_for_use' ,'Value', ['These data can be used freely for research purposes provided that the following source is acknowledged: ',OPT.institution]);
nc.Attributes(end+1) = struct('Name','disclaimer' ,'Value', 'This data is made available in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.');
nc.Attributes(end+1) = struct('Name','delft3d_description','Value', str2line(M.description));
% ISO metadata "WHEN": http://www.unidata.ucar.edu/software/netcdf-java/formats/DataDiscoveryAttConvention.html
% https://geo-ide.noaa.gov/wiki/index.php?title=NetCDF_Attribute_Convention_for_Dataset_Discovery
nc.Attributes(end+1) = struct('Name','time_coverage_start','Value', datestr(T.datenum( 1),'yyyy-mm-ddTHH:MM'));
nc.Attributes(end+1) = struct('Name','time_coverage_end' ,'Value', datestr(T.datenum(end),'yyyy-mm-ddTHH:MM'));
%% Coordinate system
disp('Reading coordinates...')
G.kmax = vs_let(F,'his-const','KMAX' ,'quiet');
G.coordinates = strtrim(permute(vs_let(F,'his-const','COORDINATES' ,'quiet'),[1 3 2]));
G.m = squeeze(vs_let(F,'his-const','MNSTAT',{1,OPT.ind},'quiet'));
G.n = squeeze(vs_let(F,'his-const','MNSTAT',{2,OPT.ind},'quiet'));
G.angle = squeeze(vs_let(F,'his-const','ALFAS' ,{ OPT.ind},'quiet'));
G.kmax = squeeze(vs_let(F,'his-const','KMAX' , 'quiet'));
G.name = permute(vs_let(F,'his-const','NAMST' ,{ OPT.ind},'quiet'),[2 3 1]);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
G.crs.m = squeeze(vs_let(F,'his-const','MNTRA' ,{[1,3],OPT.crs.ind},'quiet'));
G.crs.n = squeeze(vs_let(F,'his-const','MNTRA' ,{[2,4],OPT.crs.ind},'quiet'));
G.crs.name = permute(vs_let(F,'his-const','NAMTRA',{ OPT.crs.ind},'quiet'),[2 3 1]);
end
% real and transform world coordinates
% define coordinate attribute
if any(strfind(G.coordinates,'CART')) % CARTESIAN, CARTHESIAN (old bug)
G.x = squeeze(vs_let(F,'his-const','XYSTAT',{1,OPT.ind} ,'quiet'));
G.y = squeeze(vs_let(F,'his-const','XYSTAT',{2,OPT.ind} ,'quiet'));
coordinates = 'x y platform_name'; % platform_name needed for stations to show up in QuickPlot
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
G.crs.x = squeeze(vs_let(F,'his-const','XYTRA',{[1,3],OPT.crs.ind},'quiet'));
G.crs.y = squeeze(vs_let(F,'his-const','XYTRA',{[2,4],OPT.crs.ind},'quiet'));
crs.coordinates = 'crs_x crs_y crs_name'; % crs_name needed for stations to show up in QuickPlot
end
if ~(isempty(OPT.epsg)||isnan(OPT.epsg))
[G.lon,G.lat] = convertCoordinates(G.x, G.y, 'CS1.code',OPT.epsg,'CS2.code',4326);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
[G.crs.lon,G.crs.lat] = convertCoordinates(G.crs.x,G.crs.y,'CS1.code',OPT.epsg,'CS2.code',4326);
end
else
fprintf(2,'> No EPSG code specified for CARTESIAN grid: grid not CF compliant: (lat,lon) can''t be calculated from (x,y)!\n')
end
else
G.lon = squeeze(vs_let(F,'his-const','XYSTAT',{1,OPT.ind},'quiet'));
G.lat = squeeze(vs_let(F,'his-const','XYSTAT',{2,OPT.ind},'quiet'));
coordinates = 'latitude longitude platform_name';
crs.coordinates = 'crs_latitude crs_longitude crs_name';
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
G.crs.lon = squeeze(vs_let(F,'his-const','XYTRA',{[1,3],OPT.crs.ind},'quiet'));
G.crs.lat = squeeze(vs_let(F,'his-const','XYTRA',{[2,4],OPT.crs.ind},'quiet'));
end
if ~(isempty(OPT.epsg)||isnan(OPT.epsg))
[G.x ,G.y ] = convertCoordinates(G.lon, G.lat, 'CS1.code',4326,'CS2.code',OPT.epsg);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
[G.crs.x ,G.crs.y ] = convertCoordinates(G.crs.lon,G.crs.lat,'CS1.code',4326,'CS2.code',OPT.epsg);
end
end
end
% vertical: z/sigma
G.layer_model = strtrim(permute(vs_let(F,'his-const','LAYER_MODEL','quiet'),[1 3 2]));
if strmatch('SIGMA-MODEL', G.layer_model)
G.sigma_dz = vs_let(F,'his-const','THICK','quiet');
[G.sigma_cent,...
G.sigma_intf] = d3d_sigma(G.sigma_dz);
coordinatesLayer = [coordinates]; % implicit via formula_terms att
coordinatesLayerInterf = [coordinates]; % implicit via formula_terms att
elseif strmatch('Z-MODEL', G.layer_model)
fprintf(2,'> Z-MODEL has not yet been tested.\n')
G.ZK = vs_let(F,'his-const' ,'ZK' ,'quiet');
coordinatesLayer = [coordinates]; % ' Layer'
coordinatesLayerInterf = [coordinates]; % ' LayerInterf'
end
%% sediment fractions
if ~isempty(strmatch('sediment',fieldnames(I)))
G.lsed = vs_let(F,'his-const','LSED','quiet');
G.namsed = cellstr(permute(vs_let(F,'his-const','NAMSED','quiet'),[2 3 1]));
% remove spaces
for jj=1:G.lsed
if any(G.namsed{jj}==' ')
fprintf(2,['> replaced spaces from sediment name "',G.namsed{jj},'" with "_"\n'])
G.namsed{jj} = mkvar(G.namsed{jj});
end
G.sedind(jj) = I.(lower(G.namsed{jj})).index;
end
else G.lsed = 0;
G.namsed = {};
end
%% 2 Create dimensions
ncdimlen.time = length(T.datenum);
ncdimlen.Layer = G.kmax ;
ncdimlen.LayerInterf = G.kmax+1;
ncdimlen.Fraction = G.lsed ;
ncdimlen.bounds2 = 2 ; % for corner (grid_*) indices
nc.Dimensions( 1) = struct('Name','time' ,'Length',ncdimlen.time );
nc.Dimensions(end+1) = struct('Name','Layer' ,'Length',ncdimlen.Layer );
nc.Dimensions(end+1) = struct('Name','LayerInterf' ,'Length',ncdimlen.LayerInterf);
nc.Dimensions(end+1) = struct('Name','Fraction' ,'Length',ncdimlen.Fraction );
nc.Dimensions(end+1) = struct('Name','bounds2' ,'Length',ncdimlen.bounds2 );
if OPT.trajectory
nc.Attributes(end+1) = struct('Name','featureType' ,'Value', 'trajectoryProfile');
dimname = 'Trajectory';
if isfield(G,'x')
G.trajectory = distance(G.x,G.y);
else
G.trajectory = nan.*G.lon;
fprintf(2,'> trajectory has no distance: spherical coordinates need epsg code to calculate Euclidian distance.\n')
end
else
nc.Attributes(end+1) = struct('Name','featureType' ,'Value', 'timeSeries');
dimname = 'Station';
ncdimlen.platform_name_len = size(G.name,2);
nc.Dimensions(end+1) = struct('Name','platform_name_len' ,'Length',ncdimlen.platform_name_len);
end
ncdimlen.(dimname) = size(G.name,1);
nc.Dimensions(end+1) = struct('Name',dimname ,'Length',ncdimlen.(dimname));
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
dimname2 = 'Crosssection';
ncdimlen.crs_name_len = size(G.crs.name,2);
nc.Dimensions(end+1) = struct('Name','crs_name_len' ,'Length',ncdimlen.crs_name_len);
ncdimlen.(dimname2) = size(G.crs.name,1);
nc.Dimensions(end+1) = struct('Name',dimname2 ,'Length',ncdimlen.(dimname2));
nc.Dimensions(end+1) = struct('Name','start_end' ,'Length',2);
end
%% 2 Create dimension combinations
% TO DO: why is field 'Length' needed, NCWRITESCHEMA should be able to find this out itself
% 2D
s_t.dims(1) = struct('Name', dimname ,'Length',ncdimlen.(dimname));
s_t.dims(2) = struct('Name', 'time' ,'Length',ncdimlen.time);
% 3D
s_t_k.dims(1) = struct('Name', 'Layer' ,'Length',ncdimlen.Layer);
s_t_k.dims(2) = struct('Name', dimname ,'Length',ncdimlen.(dimname));
s_t_k.dims(3) = struct('Name', 'time' ,'Length',ncdimlen.time);
% 3D
s_t_ki.dims(1) = struct('Name', 'LayerInterf' ,'Length',ncdimlen.LayerInterf);
s_t_ki.dims(2) = struct('Name', dimname ,'Length',ncdimlen.(dimname));
s_t_ki.dims(3) = struct('Name', 'time' ,'Length',ncdimlen.time);
% 3D
s_t_f.dims(1) = struct('Name', 'Fraction' ,'Length',ncdimlen.Fraction);
s_t_f.dims(2) = struct('Name', dimname ,'Length',ncdimlen.(dimname));
s_t_f.dims(3) = struct('Name', 'time' ,'Length',ncdimlen.time);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
% 2D
x_t.dims(1) = struct('Name', dimname2 ,'Length',ncdimlen.(dimname2));
x_t.dims(2) = struct('Name', 'time' ,'Length',ncdimlen.time);
% 3D
x_t_f.dims(1) = struct('Name', 'Fraction' ,'Length',ncdimlen.Fraction);
x_t_f.dims(2) = struct('Name', dimname2 ,'Length',ncdimlen.(dimname2));
x_t_f.dims(3) = struct('Name', 'time' ,'Length',ncdimlen.time);
end
%% 3 Fill variables
%% time
if isempty(OPT.timezone)
fprintf(2,'> No model timezone supplied, timezone could NOT be added to netCDF file. This will be interpreted as GMT! \n')
end
ifld = 1; clear attr dims;
attr( 1) = struct('Name', 'standard_name', 'Value', 'time');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'time');
attr(end+1) = struct('Name', 'units' , 'Value', ['days since ',datestr(OPT.refdatenum,'yyyy-mm-dd'),' 00:00:00 ',OPT.timezone]);
attr(end+1) = struct('Name', 'axis' , 'Value', 'T');
attr(end+1) = struct('Name', 'actual_range' , 'Value', [datestr(T.datenum(1),31),char(9),datestr(T.datenum(end),31)]);
nc.Variables(ifld) = struct('Name' , 'time', ...
'Datatype' , 'double', ...
'Dimensions', struct('Name', 'time','Length',ncdimlen.time), ...
'Attributes' , attr,...
'FillValue' , []);
%% platforms/stations/observation points or trajectory and cross-sections (optional)
if OPT.trajectory
ifld = ifld + 1; clear attr;
attr( 1) = struct('Name', 'standard_name', 'Value', 'projection_x_coordinate');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'trajectory');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'axis' , 'Value', 'X');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.trajectory(:)) max(G.trajectory(:))]);
nc.Variables(ifld) = struct('Name' , 'Trajectory', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
else
ifld = ifld + 1;clear attr;d3d_name = 'NAMST';
attr( 1) = struct('Name', 'standard_name', 'Value', 'platform_name');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', 'cf_role' , 'Value', 'timeseries_id');
% Where feasible a variable with the attribute cf_role should be included.
% The only acceptable values of cf_role for Discrete Geometry CF data sets
% are timeseries_id, profile_id, and trajectory_id.The variable carrying
% the cf_role attribute may have any data type. When a variable is assigned
% this attribute, it must provide a unique identifier for each feature instance.
% CF files that contain timeSeries, profile or trajectory featureTypes,
% should include only a single occurrence of a cf_role attribute;
% CF files that contain timeSeriesProfile or trajectoryProfile may
% contain two occurrences, corresponding to the two levels of structure
% in these feature types: cf_role timeseries_id
dims( 1) = struct('Name', 'platform_name_len','Length',ncdimlen.platform_name_len);
dims( 2) = struct('Name', dimname ,'Length',ncdimlen.(dimname));
nc.Variables(ifld) = struct('Name' , 'platform_name', ...
'Datatype' , 'char', ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'Delft3D-FLOW m index of station');
attr(end+1) = struct('Name', 'units' , 'Value', '1');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'MNSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.m(:)) max(G.m(:))]);
nc.Variables(ifld) = struct('Name' , 'platform_m_index', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'Delft3D-FLOW n index of station');
attr(end+1) = struct('Name', 'units' , 'Value', '1');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'MNSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.n(:)) max(G.n(:))]);
nc.Variables(ifld) = struct('Name' , 'platform_n_index', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;d3d_name = 'ALFAS';
attr( 1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
nc.Variables(ifld) = struct('Name' , 'platform_angle', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
ifld = ifld + 1;clear attr dims;d3d_name = 'NAMTRA';
attr( 1) = struct('Name', 'standard_name', 'Value', 'platform_name');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', 'cf_role' , 'Value', 'timeseries_id');
dims( 2) = struct('Name', dimname2 ,'Length',ncdimlen.(dimname2));
dims( 1) = struct('Name', 'crs_name_len','Length',ncdimlen.crs_name_len);
nc.Variables(ifld) = struct('Name' , 'crs_name', ...
'Datatype' , 'char', ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr dims;
attr( 1) = struct('Name', 'long_name' , 'Value', 'Delft3D-FLOW m indices of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', '1');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'MNTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.crs.m(:)) max(G.crs.m(:))]);
dims( 2) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_m', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr dims;
attr( 1) = struct('Name', 'long_name' , 'Value', 'Delft3D-FLOW n indices of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', '1');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'MNTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.crs.n(:)) max(G.crs.n(:))]);
dims( 2) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_n', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
end
%% horizontal coordinates: (x,y) and (lon,lat), on centres and corners
if any(strfind(G.coordinates,'CARTESIAN')) || ~isempty(OPT.epsg)
ifld = ifld + 1;clear attr
attr( 1) = struct('Name', 'standard_name', 'Value', 'projection_x_coordinate');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'x of station');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'axis' , 'Value', 'X');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.x(:)) max(G.x(:))]);
nc.Variables(ifld) = struct('Name' , 'x', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr
attr( 1) = struct('Name', 'standard_name', 'Value', 'projection_y_coordinate');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'y of station');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'axis' , 'Value', 'Y');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.y(:)) max(G.y(:))]);
nc.Variables(ifld) = struct('Name' , 'y', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
end
if ~any(strfind(G.coordinates,'CARTESIAN')) || ~isempty(OPT.epsg)
ifld = ifld + 1;clear attr
attr( 1) = struct('Name', 'standard_name', 'Value', 'longitude');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Longitude of station');
attr(end+1) = struct('Name', 'units' , 'Value', 'degrees_east');
attr(end+1) = struct('Name', 'axis' , 'Value', 'X');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.lon(:)) max(G.lon(:))]);
nc.Variables(ifld) = struct('Name' , 'longitude', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr
attr( 1) = struct('Name', 'standard_name', 'Value', 'latitude');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Latitude of station');
attr(end+1) = struct('Name', 'units' , 'Value', 'degrees_north');
attr(end+1) = struct('Name', 'axis' , 'Value', 'Y');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYSTAT');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.lat(:)) max(G.lat(:))]);
nc.Variables(ifld) = struct('Name' , 'latitude', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
end
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
attr(end+1) = struct('Name', 'bounds' , 'Value', 'crsx_bounds');
if any(strfind(G.coordinates,'CARTESIAN')) || ~isempty(OPT.epsg)
ifld = ifld + 1;clear attr dims
attr( 1) = struct('Name', 'standard_name', 'Value', 'projection_x_coordinate');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'x of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'axis' , 'Value', 'X');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.crs.x(:)) max(G.crs.x(:))]);
attr(end+1) = struct('Name', 'bounds' , 'Value', 'crsx_bounds');
dims( 1) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
%dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_x', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr dims
attr( 1) = struct('Name', 'standard_name', 'Value', 'projection_y_coordinate');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'y of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'axis' , 'Value', 'Y');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.y(:)) max(G.y(:))]);
attr(end+1) = struct('Name', 'bounds' , 'Value', 'crsy_bounds');
dims( 1) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
%dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_y', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
if ~any(strfind(G.coordinates,'CARTESIAN')) || ~isempty(OPT.epsg)
ifld = ifld + 1;clear attr dims
attr( 1) = struct('Name', 'standard_name', 'Value', 'longitude');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Longitude of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', 'degrees_east');
attr(end+1) = struct('Name', 'axis' , 'Value', 'X');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.crs.lon(:)) max(G.crs.lon(:))]);
attr(end+1) = struct('Name', 'bounds' , 'Value', 'crslongitude_bounds');
dims( 2) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_longitude', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr dims
attr( 1) = struct('Name', 'standard_name', 'Value', 'latitude');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Latitude of cross-section');
attr(end+1) = struct('Name', 'units' , 'Value', 'degrees_north');
attr(end+1) = struct('Name', 'axis' , 'Value', 'Y');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'XYTRA');
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [min(G.crs.lat(:)) max(G.crs.lat(:))]);
attr(end+1) = struct('Name', 'bounds' , 'Value', 'crslatitude_bounds');
dims( 2) = struct('Name', dimname2,'Length',ncdimlen.(dimname2));
dims( 1) = struct('Name', 'start_end','Length',2);
nc.Variables(ifld) = struct('Name' , 'crs_latitude', ...
'Datatype' , OPT.type, ...
'Dimensions', dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
end
%% vertical coordinates
if strmatch('SIGMA-MODEL', G.layer_model)
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'sigma at layer midpoints');
attr(end+1) = struct('Name', 'standard_name', 'Value', 'ocean_sigma_coordinate');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
attr(end+1) = struct('Name', 'formula_terms', 'Value', 'sigma: Layer eta: waterlevel depth: depth'); % requires depth to be positive !!
attr(end+1) = struct('Name', 'comment' , 'Value', 'The surface layer has index k=1 and is sigma=0, the bottom layer has index kmax and is sigma=-1.');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'his-const:KMAX his-const:LAYER_MODEL his-const:THICK');
nc.Variables(ifld) = struct('Name' , 'Layer', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', 'Layer','Length',ncdimlen.Layer), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'sigma at layer interfaces');
attr(end+1) = struct('Name', 'standard_name', 'Value', 'ocean_sigma_coordinate');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
attr(end+1) = struct('Name', 'formula_terms', 'Value', 'sigma: LayerInterf eta: waterlevel depth: depth'); % requires depth to be positive !!
attr(end+1) = struct('Name', 'comment' , 'Value', 'The surface layer has index k=1 and is sigma=0, the bottom layer has index kmax and is sigma=-1.');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'his-const:KMAX his-const:LAYER_MODEL his-const:THICK');
nc.Variables(ifld) = struct('Name' , 'LayerInterf', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', 'LayerInterf','Length',ncdimlen.LayerInterf), ...
'Attributes' , attr,...
'FillValue' , []);
elseif strmatch('Z-MODEL', G.layer_model)
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'z at layer midpoints');
attr(end+1) = struct('Name', 'standard_name', 'Value', 'altitude');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
attr(end+1) = struct('Name', 'formula_terms', 'Value', 'sigma: Layer eta: waterlevel depth: depth'); % requires depth to be positive !!
attr(end+1) = struct('Name', 'comment' , 'Value', 'The bottom layer has index k=1 and is the bottom depth, the surface layer has index kmax and is z=free water surface.');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'his-const:KMAX his-const:LAYER_MODEL his-const:ZK');
nc.Variables(ifld) = struct('Name' , 'Layer', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', 'Layer','Length',ncdimlen.Layer), ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'long_name' , 'Value', 'z at layer interfaces');
attr(end+1) = struct('Name', 'standard_name', 'Value', 'altitude');
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
attr(end+1) = struct('Name', 'formula_terms', 'Value', 'sigma: LayerInterf eta: waterlevel depth: depth'); % requires depth to be positive !!
attr(end+1) = struct('Name', 'comment' , 'Value', 'The bottom layer has index k=1 and is the bottom depth, the surface layer has index kmax and is z=free water surface.');
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', 'his-const:KMAX his-const:LAYER_MODEL his-const:ZK');
nc.Variables(ifld) = struct('Name' , 'LayerInterf', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', 'LayerInterf','Length',ncdimlen.LayerInterf), ...
'Attributes' , attr,...
'FillValue' , []);
end % z/sigma
%% bathymetry
ifld = ifld + 1;clear attr; d3d_name = 'DPS';
attr( 1) = struct('Name', 'standard_name', 'Value', 'altitude');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'positive' , 'Value', 'down');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', 'comment' , 'Value', '');
nc.Variables(ifld) = struct('Name' , 'depth', ...
'Datatype' , OPT.type, ...
'Dimensions', struct('Name', dimname,'Length',ncdimlen.(dimname)), ...
'Attributes' , attr,...
'FillValue' , []);
%% Create (primary) variables: momentum and mass conservation
ifld = ifld + 1;clear attr; d3d_name = 'ZWL';
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_surface_elevation');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
nc.Variables(ifld) = struct('Name' , 'waterlevel', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
if ~isempty(vs_get_elm_def(F,'ZKFS')) % old NEFIS fles
ifld = ifld + 1;clear attr; d3d_name = 'ZKFS';
attr( 1) = struct('Name', 'standard_name', 'Value', '');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'active');
attr(end+1) = struct('Name', 'units' , 'Value', '1');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
attr(end+1) = struct('Name', 'flag_values' , 'Value', [0 1]);
attr(end+1) = struct('Name', 'flag_meanings', 'Value', 'inactive active ');
nc.Variables(ifld) = struct('Name' , 'mask', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
ifld = ifld + 1;clear attr;d3d_name = 'ZCURU';
if (~any(strfind(G.coordinates,'CART'))) % CARTESIAN, CARTHESIAN (old bug)
attr( 1) = struct('Name', 'standard_name', 'Value', 'eastward_sea_water_velocity'); % surface_geostrophic_sea_water_x_velocity_assuming_sea_level_for_geoid
attr(end+1) = struct('Name', 'long_name' , 'Value', 'velocity, lon-component');
else
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_water_x_velocity'); % surface_geostrophic_sea_water_x_velocity_assuming_sea_level_for_geoid
attr(end+1) = struct('Name', 'long_name' , 'Value', 'velocity, x-component');
end
attr(end+1) = struct('Name', 'units' , 'Value', 'm/s');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.u_x = [Inf -Inf];
attr(end+1) = struct('Name', 'comment' , 'Value', 'TO DO: check whether is has been rotated from local (m,n) grid to global (x,y) or (lon,lat) grid');
nc.Variables(ifld) = struct('Name' , 'u_x', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;d3d_name = 'ZCURV';
if (~any(strfind(G.coordinates,'CART'))) % CARTESIAN, CARTHESIAN (old bug)
attr( 1) = struct('Name', 'standard_name', 'Value', 'northward_sea_water_velocity'); % surface_geostrophic_sea_water_y_velocity_assuming_sea_level_for_geoid
attr(end+1) = struct('Name', 'long_name' , 'Value', 'velocity, lat-component');
else
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_water_y_velocity'); % surface_geostrophic_sea_water_y_velocity_assuming_sea_level_for_geoid
attr(end+1) = struct('Name', 'long_name' , 'Value', 'velocity, y-component');
end
attr(end+1) = struct('Name', 'units' , 'Value', 'm/s');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.u_y = [Inf -Inf];
attr(end+1) = struct('Name', 'comment' , 'Value', 'TO DO: check whether is has been rotated from local (m,n) grid to global (x,y) or (lon,lat) grid');
nc.Variables(ifld) = struct('Name' , 'u_y', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;d3d_name = 'ZCURW';
attr( 1) = struct('Name', 'standard_name', 'Value', 'upward_sea_water_velocity');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'velocity, z-component');
attr(end+1) = struct('Name', 'units' , 'Value', 'm/s');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.u_z = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'u_z', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
%% Wind speed and direction
ifld = ifld + 1;clear attr;d3d_name = 'ZWNDSPD';
attr( 1) = struct('Name', 'standard_name', 'Value', 'wind_speed');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm/s');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
nc.Variables(ifld) = struct('Name' , 'windspeed', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;d3d_name = 'ZWNDDIR';
attr( 1) = struct('Name', 'standard_name', 'Value', 'wind_direction');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm/s');
attr(end+1) = struct('Name', 'positive' , 'Value', 'up');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);
nc.Variables(ifld) = struct('Name' , 'winddirection', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
if ~isempty(vs_get_elm_def(F,'NAMTRA')) && ~isempty(OPT.crs.ind)
ifld = ifld + 1;clear attr;d3d_name = 'CTR';
attr( 1) = struct('Name', 'standard_name', 'Value', 'water_flux_into_sea_water');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm3/s');
attr(end+1) = struct('Name', 'coordinates' , 'Value', crs.coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.Q = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'Q', ...
'Datatype' , OPT.type, ...
'Dimensions', x_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr;d3d_name = 'FLTR';
attr( 1) = struct('Name', 'standard_name', 'Value', 'water_flux_into_sea_water');
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'm3');
attr(end+1) = struct('Name', 'coordinates' , 'Value', crs.coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.CQ = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'CQ', ...
'Datatype' , OPT.type, ...
'Dimensions', x_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
% ifld = ifld + 1;clear attr;d3d_name = 'ATR';
% attr( 1) = struct('Name', 'standard_name', 'Value', '');
% attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
% attr(end+1) = struct('Name', 'units' , 'Value', 'm3/s');
% attr(end+1) = struct('Name', 'coordinates' , 'Value', crs.coordinates);
% attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
% attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
% attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.ATR_salinity = [Inf -Inf];
% nc.Variables(ifld) = struct('Name' , 'crs_salinity_advection', ...
% 'Datatype' , OPT.type, ...
% 'Dimensions', x_t.dims, ...
% 'Attributes' , attr,...
% 'FillValue' , []);
%
% ifld = ifld + 1;clear attr;d3d_name = 'DTR';
% attr( 1) = struct('Name', 'standard_name', 'Value', '');
% attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
% attr(end+1) = struct('Name', 'units' , 'Value', 'm3');
% attr(end+1) = struct('Name', 'coordinates' , 'Value', crs.coordinates);
% attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
% attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
% attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.DTR_salinity = [Inf -Inf];
% nc.Variables(ifld) = struct('Name' , 'crs_salinity_dispersion', ...
% 'Datatype' , OPT.type, ...
% 'Dimensions', x_t.dims, ...
% 'Attributes' , attr,...
% 'FillValue' , []);
end
% bottom shear stresses
ifld = ifld + 1;clear attr; d3d_name = 'ZTAUKS';
if (~any(strfind(G.coordinates,'CART'))) % CARTESIAN, CARTHESIAN (old bug)
attr( 1) = struct('Name', 'standard_name', 'Value', 'surface_downward_northward_stress');
else
attr( 1) = struct('Name', 'standard_name', 'Value', 'surface_downward_x_stress');
end
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'N m-2');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.tau_x = [Inf -Inf];
attr(end+1) = struct('Name', 'comment' , 'Value', 'The bed shear stresses are in real world directions x and y');
nc.Variables(ifld) = struct('Name' , 'tau_x', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
ifld = ifld + 1;clear attr; d3d_name = 'ZTAUET';
if (~any(strfind(G.coordinates,'CART'))) % CARTESIAN, CARTHESIAN (old bug)
attr( 1) = struct('Name', 'standard_name', 'Value', 'surface_downward_eastward_stress');
else
attr( 1) = struct('Name', 'standard_name', 'Value', 'surface_downward_y_stress');
end
attr(end+1) = struct('Name', 'long_name' , 'Value', vs_get_elm_def(F,d3d_name,'Description'));
attr(end+1) = struct('Name', 'units' , 'Value', 'N m-2');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.tau_y = [Inf -Inf];
attr(end+1) = struct('Name', 'comment' , 'Value', 'The bed shear stresses are in real world directions x and y');
nc.Variables(ifld) = struct('Name' , 'tau_y', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t.dims, ...
'Attributes' , attr,...
'FillValue' , []);
% density: temperature + salinity
d3d_name = 'ZRHO';
if ~isempty(vs_get_elm_def(F,d3d_name))
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_water_density');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Density in station');
attr(end+1) = struct('Name', 'units' , 'Value', 'kg/m3');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.density = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'density', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
d3d_name = 'GRO';
if ~isempty(strmatch('salinity',fieldnames(I)))
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_water_salinity');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Salinity in station');
attr(end+1) = struct('Name', 'units' , 'Value', 'psu');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.salinity = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'salinity', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
if ~isempty(strmatch('temperature',fieldnames(I)))
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'standard_name', 'Value', 'sea_water_temperature');
attr(end+1) = struct('Name', 'long_name' , 'Value', 'Temperature in station');
attr(end+1) = struct('Name', 'units' , 'Value', 'degree_Celsius');
attr(end+1) = struct('Name', 'coordinates' , 'Value', coordinates);
attr(end+1) = struct('Name', 'delft3d_name' , 'Value', d3d_name);
attr(end+1) = struct('Name', '_FillValue' , 'Value', single(NaN));
attr(end+1) = struct('Name', 'actual_range' , 'Value', [nan nan]);R.temperature = [Inf -Inf];
nc.Variables(ifld) = struct('Name' , 'temperature', ...
'Datatype' , OPT.type, ...
'Dimensions', s_t_k.dims, ...
'Attributes' , attr,...
'FillValue' , []);
end
% sediment concentration(s)
if ~isempty(strmatch('sediment',fieldnames(I)))
for jj=1:G.lsed
ifld = ifld + 1;clear attr;
attr( 1) = struct('Name', 'standard_name', 'Value', 'concentration_of_suspended_matter_in_sea_water'); % mass_concentration_of_suspended_matter_in_sea_water