@@ -1102,6 +1102,12 @@ def __init__(
1102
1102
for i in range (self .grid_info ["npes" ])
1103
1103
]
1104
1104
1105
+ if self ._DataFileCaching or self ._parallel :
1106
+ # Keep reference to 0'th file, for reading attributes
1107
+ self ._file0 = DataFile (self ._file_list [0 ])
1108
+ else :
1109
+ self ._file0 = None
1110
+
1105
1111
if self ._info :
1106
1112
print (
1107
1113
"mxsub = {} mysub = {} mz = {}\n " .format (
@@ -1145,6 +1151,8 @@ def __del__(self):
1145
1151
connection .send (None )
1146
1152
worker .join ()
1147
1153
connection .close ()
1154
+ if self ._file0 is not None :
1155
+ self ._file0 .close ()
1148
1156
1149
1157
def _init_caching (self ):
1150
1158
"""
@@ -1224,6 +1232,64 @@ def evolvingVariables(self):
1224
1232
"""Return a list of names of time-evolving variables"""
1225
1233
return self .grid_info ["evolvingVariableNames" ]
1226
1234
1235
+ def get_attribute (self , variable , attrname ):
1236
+ """Get an attribute of a variable
1237
+
1238
+ Parameters
1239
+ ----------
1240
+ variable : str
1241
+ Name of variable to get attribute from
1242
+ attrname : str
1243
+ Name of attribute
1244
+
1245
+ Returns
1246
+ -------
1247
+ Value of attribute
1248
+ """
1249
+ if self ._file0 is None :
1250
+ with DataFile (self ._file_list [0 ]) as f :
1251
+ return f .attributes (variable )[attrname ]
1252
+ else :
1253
+ return self ._file0 .attributes (variable )[attrname ]
1254
+
1255
+ def get_file_attribute (self , attrname ):
1256
+ """Get an attribute of the output files.
1257
+
1258
+ Attribute is taken from the rank-0 file. No checking is done that the attribute
1259
+ is consistent between all the output files.
1260
+
1261
+ Parameters
1262
+ ----------
1263
+ attrname : str
1264
+ Name of attribute
1265
+
1266
+ Returns
1267
+ -------
1268
+ Value of attribute
1269
+ """
1270
+ if self ._file0 is None :
1271
+ with DataFile (self ._file_list [0 ]) as f :
1272
+ return f .read_file_attribute (attrname )
1273
+ else :
1274
+ return self ._file0 .read_file_attribute (attrname )
1275
+
1276
+ def list_file_attributes (self ):
1277
+ """List all file attributes of output files
1278
+
1279
+ List is taken from the rank-0 file. No checking is done that the file attributes
1280
+ are consistent between all the output files.
1281
+
1282
+ Returns
1283
+ -------
1284
+ List of str
1285
+ Names of the file attributes
1286
+ """
1287
+ if self ._file0 is None :
1288
+ with DataFile (self ._file_list [0 ]) as f :
1289
+ return f .list_file_attributes ()
1290
+ else :
1291
+ return self ._file0 .list_file_attributes ()
1292
+
1227
1293
def redistribute (self , npes , nxpe = None , mxg = 2 , myg = 2 , include_restarts = True ):
1228
1294
"""Create a new set of dump files for npes processors.
1229
1295
0 commit comments