Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
fvcom-toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
FVCOM
fvcom-toolbox
Commits
1488cb63
Commit
1488cb63
authored
Feb 27, 2015
by
Pierre Cazenave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add human readable times to the netCDF.
parent
37fdb4ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
8 deletions
+41
-8
fvcom_prepro/write_FVCOM_nested_forcing.m
fvcom_prepro/write_FVCOM_nested_forcing.m
+41
-8
No files found.
fvcom_prepro/write_FVCOM_nested_forcing.m
View file @
1488cb63
...
...
@@ -53,6 +53,9 @@ function write_FVCOM_nested_forcing(nest, ncfile, nesttype)
% 2013-06-04 First version.
% 2015-02-19 Updated to use either weighted or non-weighted nesting. Also
% general tidy up.
% 2015-02-24 Add extra time variables, which although not strictly
% necessary for the model to run, makes sanity checking the time series a
% lot more straightforward.
%
%==========================================================================
...
...
@@ -70,6 +73,10 @@ function write_FVCOM_nested_forcing(nest, ncfile, nesttype)
% weight_node: Weighting for nodes [node]
% Itime: Days since 1858-11-17 00:00:00 [time]
% Itime2: msec since 00:00:00 [time]
%
% We include these optional ones for humans:
% time: Modified Julian Day [time]
% Times: Gregorian dates [time, datestrlen]
subname
=
'write_FVCOM_nested_forcing'
;
...
...
@@ -98,7 +105,7 @@ for f = required
end
end
[
elems
,
nsiglay
,
~
]
=
size
(
nest
.
u
);
[
elems
,
nsiglay
,
ntimes
]
=
size
(
nest
.
u
);
nsiglev
=
nsiglay
+
1
;
[
nodes
,
~
]
=
size
(
nest
.
zeta
);
...
...
@@ -123,13 +130,14 @@ three_dimid = netcdf.defDim(nc, 'three', 3);
time_dimid
=
netcdf
.
defDim
(
nc
,
'time'
,
netcdf
.
getConstant
(
'NC_UNLIMITED'
));
siglay_dimid
=
netcdf
.
defDim
(
nc
,
'siglay'
,
nsiglay
);
siglev_dimid
=
netcdf
.
defDim
(
nc
,
'siglev'
,
nsiglev
);
datestrlen_dimid
=
netcdf
.
defDim
(
nc
,
'DateStrLen'
,
26
);
% define variables
%
time_varid = netcdf.defVar(nc, 'time', 'NC_FLOAT', time_dimid);
%
netcdf.putAtt(nc, time_varid, 'long_name', 'time');
%
netcdf.putAtt(nc, time_varid, 'units', 'days since 1858-11-17 00:00:00');
%
netcdf.putAtt(nc, time_varid, 'format', 'modified julian day (MJD)');
%
netcdf.putAtt(nc, time_varid, 'time_zone', 'UTC');
time_varid
=
netcdf
.
defVar
(
nc
,
'time'
,
'NC_FLOAT'
,
time_dimid
);
netcdf
.
putAtt
(
nc
,
time_varid
,
'long_name'
,
'time'
);
netcdf
.
putAtt
(
nc
,
time_varid
,
'units'
,
'days since 1858-11-17 00:00:00'
);
netcdf
.
putAtt
(
nc
,
time_varid
,
'format'
,
'modified julian day (MJD)'
);
netcdf
.
putAtt
(
nc
,
time_varid
,
'time_zone'
,
'UTC'
);
itime_varid
=
netcdf
.
defVar
(
nc
,
'Itime'
,
'NC_INT'
,
...
time_dimid
);
...
...
@@ -142,6 +150,10 @@ itime2_varid = netcdf.defVar(nc, 'Itime2', 'NC_INT', ...
netcdf
.
putAtt
(
nc
,
itime2_varid
,
'units'
,
'msec since 00:00:00'
);
netcdf
.
putAtt
(
nc
,
itime2_varid
,
'time_zone'
,
'UTC'
);
Times_varid
=
netcdf
.
defVar
(
nc
,
'Times'
,
'NC_CHAR'
,
...
[
datestrlen_dimid
,
time_dimid
]);
netcdf
.
putAtt
(
nc
,
Times_varid
,
'time_zone'
,
'UTC'
);
x_varid
=
netcdf
.
defVar
(
nc
,
'x'
,
'NC_FLOAT'
,
...
node_dimid
);
netcdf
.
putAtt
(
nc
,
x_varid
,
'units'
,
'meters'
);
...
...
@@ -287,10 +299,31 @@ end
% end definitions
netcdf
.
endDef
(
nc
);
% write data
% write time data
nStringOut
=
char
();
for
i
=
1
:
ntimes
[
nYr
,
nMon
,
nDay
,
nHour
,
nMin
,
nSec
]
=
mjulian2greg
(
nest
.
time
(
i
));
if
strcmp
(
sprintf
(
'%02i'
,
nSec
),
'60'
)
% Fix some weirdness with mjulian2greg. I think this is caused by
% rounding errors. My testing suggests this is not a problem around
% midnight, so the number of days (and thus possibly months and
% years) is unaffected.
if
mod
(
nMin
+
1
,
60
)
==
0
% Up the hour by one too
nHour
=
mod
(
nHour
+
1
,
24
);
end
nMin
=
mod
(
nMin
+
1
,
60
);
nSec
=
0
;
end
nDate
=
[
nYr
,
nMon
,
nDay
,
nHour
,
nMin
,
nSec
];
nStringOut
=
[
nStringOut
,
sprintf
(
'%04i/%02i/%02i %02i:%02i:%02i '
,
nDate
)];
end
netcdf
.
putVar
(
nc
,
itime_varid
,
0
,
numel
(
nest
.
time
),
floor
(
nest
.
time
));
netcdf
.
putVar
(
nc
,
itime2_varid
,
0
,
numel
(
nest
.
time
),
...
mod
(
nest
.
time
,
1
)
*
24
*
3600
*
1000
);
netcdf
.
putVar
(
nc
,
Times_varid
,
nStringOut
);
% write grid information
netcdf
.
putVar
(
nc
,
nv_varid
,
nest
.
nv
);
netcdf
.
putVar
(
nc
,
x_varid
,
nest
.
x
);
...
...
@@ -301,6 +334,7 @@ netcdf.putVar(nc, lon_varid, nest.lon);
netcdf
.
putVar
(
nc
,
lat_varid
,
nest
.
lat
);
netcdf
.
putVar
(
nc
,
lonc_varid
,
nest
.
lonc
);
netcdf
.
putVar
(
nc
,
latc_varid
,
nest
.
latc
);
% dump data
netcdf
.
putVar
(
nc
,
zeta_varid
,
nest
.
zeta
);
netcdf
.
putVar
(
nc
,
ua_varid
,
nest
.
ua
);
...
...
@@ -321,4 +355,3 @@ netcdf.close(nc)
if
ftbverbose
fprintf
(
'end : %s\n'
,
subname
)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment