@@ -18,8 +18,14 @@ include("netcdf_writer_coordinates.jl")
1818A struct to remap `ClimaCore` `Fields` to rectangular grids and save the output to NetCDF
1919files.
2020"""
21- struct NetCDFWriter{T, TS, DI, SYNC, ZSM <: AbstractZSamplingMethod , DATE} < :
22- AbstractWriter
21+ struct NetCDFWriter{
22+ T,
23+ TS,
24+ DI,
25+ SYNC,
26+ ZSM <: Union{AbstractZSamplingMethod, Nothing} ,
27+ DATE,
28+ } <: AbstractWriter
2329 """ The base folder where to save the files."""
2430 output_dir:: String
2531
@@ -262,6 +268,42 @@ function NetCDFWriter(
262268 )
263269end
264270
271+ function NetCDFWriter (
272+ space:: Spaces.Spaces.PointSpace ,
273+ output_dir;
274+ compression_level = 9 ,
275+ sync_schedule = ClimaComms. device (space) isa ClimaComms. CUDADevice ?
276+ EveryStepSchedule () : nothing ,
277+ start_date = nothing ,
278+ kwargs... ,
279+ )
280+ comms_ctx = ClimaComms. context (space)
281+ preallocated_arrays =
282+ ClimaComms. iamroot (comms_ctx) ?
283+ Dict {ScheduledDiagnostic, ClimaComms.array_type(space)} () :
284+ Dict {ScheduledDiagnostic, Nothing} ()
285+ unsynced_datasets = Set {NCDatasets.NCDataset} ()
286+ return NetCDFWriter{
287+ Nothing,
288+ Nothing,
289+ typeof (preallocated_arrays),
290+ typeof (sync_schedule),
291+ Nothing,
292+ typeof (start_date),
293+ }(
294+ output_dir,
295+ Dict {String, Remapper} (),
296+ nothing ,
297+ compression_level,
298+ nothing ,
299+ Dict {String, NCDatasets.NCDataset} (),
300+ nothing ,
301+ preallocated_arrays,
302+ sync_schedule,
303+ unsynced_datasets,
304+ start_date,
305+ )
306+ end
265307"""
266308 interpolate_field!(writer::NetCDFWriter, field, diagnostic, u, p, t)
267309
@@ -278,7 +320,7 @@ function interpolate_field!(writer::NetCDFWriter, field, diagnostic, u, p, t)
278320 if has_horizontal_space
279321 horizontal_space = Spaces. horizontal_space (space)
280322
281- # We have to deal with to cases: when we have an horizontal slice (e.g., the
323+ # We have to deal with two cases: when we have an horizontal slice (e.g., the
282324 # surface), and when we have a full space. We distinguish these cases by checking if
283325 # the given space has the horizontal_space attribute. If not, it is going to be a
284326 # SpectralElementSpace2D and we don't have to deal with the z coordinates.
@@ -391,6 +433,11 @@ function write_field!(writer::NetCDFWriter, field, diagnostic, u, p, t)
391433 interpolated_field = permutedims (interpolated_field, perm)
392434 end
393435
436+ if space isa Spaces. PointSpace
437+ # If the space is a point space, we have to remove the singleton dimension
438+ interpolated_field = interpolated_field[]
439+ end
440+
394441 FT = Spaces. undertype (space)
395442
396443 output_path =
@@ -459,7 +506,8 @@ function write_field!(writer::NetCDFWriter, field, diagnostic, u, p, t)
459506 # We already have something in the file
460507 v = nc[" $(var. short_name) " ]
461508 temporal_size, spatial_size... = size (v)
462- spatial_size == size (interpolated_field) ||
509+ interpolated_size = size (interpolated_field)
510+ spatial_size == interpolated_size ||
463511 error (" incompatible dimensions for $(var. short_name) " )
464512 else
465513 v = NCDatasets. defVar (
0 commit comments