Changeset c77630a in flex_extract.git for Source/Python/Classes/GribUtil.py
- Timestamp:
- Aug 13, 2019, 12:32:22 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 0690a6c
- Parents:
- 33a4ccc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/Classes/GribUtil.py
r44174de rc77630a 91 91 codes_release) 92 92 93 fileid = open(self.filenames, 'r')94 95 93 return_list = [] 96 94 97 while 1: 95 with open(self.filenames, 'rb') as fileid: 96 98 97 gid = codes_new_from_file(fileid) 99 100 if gid is None:101 break102 98 103 99 if len(wherekeynames) != len(wherekeyvalues): … … 123 119 codes_release(gid) 124 120 125 fileid.close()126 127 121 return return_list 128 122 129 123 130 124 def set_keys(self, fromfile, keynames, keyvalues, wherekeynames=[], 131 wherekeyvalues=[], strict=False, filemode='w '):125 wherekeyvalues=[], strict=False, filemode='wb'): 132 126 '''Opens the file to read the grib messages and then write 133 127 the selected messages (with wherekeys) to a new output file. … … 161 155 162 156 filemode : :obj:`string`, optional 163 Sets the mode for the output file. Default is "w ".157 Sets the mode for the output file. Default is "wb". 164 158 165 159 Return … … 175 169 176 170 fout = open(self.filenames, filemode) 177 fin = open(fromfile) 178 179 while 1: 171 172 with open(fromfile, 'rb') as fin: 180 173 gid = codes_grib_new_from_file(fin) 181 182 if gid is None:183 break184 174 185 175 select = True … … 206 196 codes_release(gid) 207 197 208 fin.close()209 198 fout.close() 210 199 … … 212 201 213 202 def copy_dummy_msg(self, filename_in, selectWhere=True, 214 keynames=[], keyvalues=[], filemode='w '):203 keynames=[], keyvalues=[], filemode='wb'): 215 204 '''Add the content of another input grib file to the objects file but 216 205 only messages corresponding to keys/values passed to the function. … … 235 224 236 225 filemode : :obj:`string`, optional 237 Sets the mode for the output file. Default is "w ".226 Sets the mode for the output file. Default is "wb". 238 227 239 228 Return … … 247 236 raise Exception("Give a value for each keyname!") 248 237 249 fin = open(filename_in, 'rb') 238 250 239 fout = open(self.filenames, filemode) 251 240 252 241 fields = 0 253 242 254 while fields < 1: 243 with open(filename_in, 'rb') as fin: 244 if fields >= 1: 245 fout.close() 246 return 247 255 248 gid = codes_grib_new_from_file(fin) 256 257 if gid is None:258 break259 249 260 250 select = True … … 278 268 codes_release(gid) 279 269 280 fin.close()281 270 fout.close() 282 271
Note: See TracChangeset
for help on using the changeset viewer.