source: nappy/trunk/notes_on_improving_write_api.txt @ 3427

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/notes_on_improving_write_api.txt@3427
Revision 3427, 1.5 KB checked in by astephen, 12 years ago (diff)

Added some notes on how we changed write api - but not up to date.

Line 
1Proposed change to NAppy so write is separated out from openNAFile() ====================================================================
2
3Currently when you do:
4
5>>> x = openNAFile("myfile.na", "w", na_dict)
6
7the NASA Ames file is opened and na_dict is written to it all in that one action.
8
9We propose that it would make more sense to split the process into stages as follows:
10
11>>> x = openNAFile("myfile.na", "w")
12>>> x.write(na_dict)
13>>> x.close()
14
15NOTE: need to include the following safety measures:
16
171. No writing is done:
18
19>>> x = openNAFile("myfile.na", "w")
20>>> x.close()
21
22Means that myfile.na is a zero-sized file - which is probably OK.
23
242. User tries to write to closed file:
25
26>>> x = openNAFile("myfile.na", "w")
27>>> x.write(na_dict)
28>>> x.close()
29
30>>> x.write(na_dict_2)
31WARNING! NASA Ames file instance is closed and cannot be written to.
32
333. User tries to write multiple na_dict objects to the file:
34
35>>> x = openNAFile("myfile.na", "w")
36>>> x.write(na_dict_1)
37>>> x.write(na_dict_2)
38WARNING! Cannot write multiple NASA Ames dictionaries to a single file. Please open a new NASA Ames file instance to write new data to.
39
40Also, I propose that we always do an x.file.flush() to make sure the data was written so even if user doesn't do x.close() before the process ends the data will always have been written.
41
424. If opened as read only then disable write:
43
44>>> x = openNAFile("myfile.na")
45>>> x.write(na_dict)
46WARNING: You cannot write to a read-only file! If you want to write to a file you must open with 'mode="w"'.
Note: See TracBrowser for help on using the repository browser.