@@ -86,6 +86,30 @@ impl RawFile {
86
86
Ok ( File ( Self { ncid } ) )
87
87
}
88
88
89
+ /// Open a `netCDF` file in read only mode in parallel mode.
90
+ #[ cfg( feature = "mpi" ) ]
91
+ pub ( crate ) fn open_par_with (
92
+ path : & path:: Path ,
93
+ communicator : mpi_sys:: MPI_Comm ,
94
+ info : mpi_sys:: MPI_Info ,
95
+ options : Options ,
96
+ ) -> error:: Result < File > {
97
+ let f = get_ffi_from_path ( path) ;
98
+ let mut ncid: nc_type = 0 ;
99
+ unsafe {
100
+ error:: checked ( with_lock ( || {
101
+ netcdf_sys:: par:: nc_open_par (
102
+ f. as_ptr ( ) . cast ( ) ,
103
+ options. bits ( ) ,
104
+ communicator,
105
+ info,
106
+ & mut ncid,
107
+ )
108
+ } ) ) ?;
109
+ }
110
+ Ok ( File ( Self { ncid } ) )
111
+ }
112
+
89
113
/// Open a `netCDF` file in append mode (read/write).
90
114
pub ( crate ) fn append_with ( path : & path:: Path , options : Options ) -> error:: Result < FileMut > {
91
115
let file = Self :: open_with ( path, options | Options :: WRITE ) ?;
@@ -105,6 +129,31 @@ impl RawFile {
105
129
Ok ( FileMut ( File ( Self { ncid } ) ) )
106
130
}
107
131
132
+ /// Create a new `netCDF` file in parallel mode
133
+ #[ cfg( feature = "mpi" ) ]
134
+ pub ( crate ) fn create_par_with (
135
+ path : & path:: Path ,
136
+ communicator : mpi_sys:: MPI_Comm ,
137
+ info : mpi_sys:: MPI_Info ,
138
+ options : Options ,
139
+ ) -> error:: Result < FileMut > {
140
+ let f = get_ffi_from_path ( path) ;
141
+ let mut ncid: nc_type = -1 ;
142
+ unsafe {
143
+ error:: checked ( with_lock ( || {
144
+ netcdf_sys:: par:: nc_create_par (
145
+ f. as_ptr ( ) . cast ( ) ,
146
+ options. bits ( ) ,
147
+ communicator,
148
+ info,
149
+ & mut ncid,
150
+ )
151
+ } ) ) ?;
152
+ }
153
+
154
+ Ok ( FileMut ( File ( Self { ncid } ) ) )
155
+ }
156
+
108
157
#[ cfg( feature = "has-mmap" ) ]
109
158
pub ( crate ) fn open_from_memory < ' buffer > (
110
159
name : Option < & str > ,
@@ -225,6 +274,14 @@ impl File {
225
274
. unwrap ( )
226
275
. map ( Result :: unwrap)
227
276
}
277
+ /// Get the length of a dimension
278
+ pub fn dimension_len ( & self , name : & str ) -> Option < usize > {
279
+ let ( ncid, name) =
280
+ super :: group:: try_get_parent_ncid_and_stem ( self . ncid ( ) , name) . unwrap ( ) ?;
281
+ super :: dimension:: dimension_from_name ( ncid, name)
282
+ . unwrap ( )
283
+ . map ( |x| x. len ( ) )
284
+ }
228
285
229
286
/// Get a group
230
287
///
@@ -440,6 +497,16 @@ impl FileMut {
440
497
let Self ( File ( file) ) = self ;
441
498
file. close ( )
442
499
}
500
+
501
+ /// Open the file for new definitions
502
+ pub fn redef ( & mut self ) -> error:: Result < ( ) > {
503
+ error:: checked ( with_lock ( || unsafe { netcdf_sys:: nc_redef ( self . ncid ( ) ) } ) )
504
+ }
505
+
506
+ /// Close the file for new definitions
507
+ pub fn enddef ( & mut self ) -> error:: Result < ( ) > {
508
+ error:: checked ( with_lock ( || unsafe { netcdf_sys:: nc_enddef ( self . ncid ( ) ) } ) )
509
+ }
443
510
}
444
511
445
512
#[ cfg( feature = "has-mmap" ) ]
0 commit comments