- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to save the data in my program to file and later read it back after restarting the program in a hopfully portable way.
My data is in a tree (+ linked list) like structure with allocted pointers and home made TYPEs.
Does anyone have a idea about where to start with this feature using Fortran 90/95 ?
Cheers/Magnus
I want to save the data in my program to file and later read it back after restarting the program in a hopfully portable way.
My data is in a tree (+ linked list) like structure with allocted pointers and home made TYPEs.
Does anyone have a idea about where to start with this feature using Fortran 90/95 ?
Cheers/Magnus
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't do that. Pointers cannot be reliably (or legally) written to and read from files. Two approaches come to mind. One is to create a big chunk of memory with the values laid out in it and use offsets within the chunk rather than absolute addresses, the other would be to have a nested text representation such as one based on XML. Both will require you to write code that converts the structures for input and output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I imagine your application will periodically checkpoint the current state and then continue to run. Should you experience some sort of failure, or required suspension such as nightly backup, you would restore to most recent (good) check point and resume. The Fortran application I use for Space Elevator simulation does just this. (simulation runs can go for days, weeks on quad core systems, and I do have occasional power outages).
In my case I am not so much tree structure but there are pointers to other structures or arrays of structures. In your case you might consider (you may have done most of this already) creating a module for managing the tree and nodes contained within the tree. (as opposed to dispersing this code throught the application). This module would contain the standard routines: allocate node, deallocate node, insert node, find node, then you would add backup nodes, and restore nodes.
If your insert node is relatively fast (or fast enough for your intermittant restores) then the backup nodes could traverse the tree writing every node, including a (or multiple)usless like pointers. The restore nodes would read the list of nodes and then perform an insert (recreating new linkages).
In the code I wrote for doing this, the backup data set would contain diagnostic information along with the backup data. I would emit 8 bytes of text pluse a numeric value followed by zero or more additional 8 bytes of text pluse a numeric value followed by the raw data. Example: "Tethers", 8, "Tether", 1, {tether data}, "Tether", 2, {tether data}, ..., "Tether", 8, {tether data}, "Objects", 12, "Object", 1, {object data}
and where {tether data} contains similar structure ("tag", number/count, {stuff}), where {stuff} is raw data or {"tag",number/count, {more stuff}).
Although inserting the "tag",number/count into the dump stream consumes space and adds overhead to the dump and restore time it has two redeeming values:
a) as a debugging aid/sanity check that the data you are reading belongs to the data set of which you believe it to be.
b) possibly more importantly, should your program crash due to a bug or some sort of configuration error, or some sort of goof-up by the operator/system admin, you may be able to fix the application and then resume using the snapshot data set made from the earlier revision of the application.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve and Jim!
I will go back to my drawing board and consider whether to store the objects in my tree in a large "integer" array which then goes to file or object by object in a XML like way with some "tags" for safety. Im sure I will implement some bugs too, so safeguards is a good idea.
Regards,
Magnus Jansson
I will go back to my drawing board and consider whether to store the objects in my tree in a large "integer" array which then goes to file or object by object in a XML like way with some "tags" for safety. Im sure I will implement some bugs too, so safeguards is a good idea.
Regards,
Magnus Jansson

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page