Re: Save an array to memory for another program to read it



Hello,

Nektarios - Greece wrote:
I run a program and suppose it creates an array A.
I need the program to store into memory this array, end itself and when immediately runs again to load this array again from the memory.

H O W ?

One way is something like this

test to see if a file exists, named, say, array_a.dat

if it exists, read it

if not, compute A and write it to a file named array_a.dat

(You can choose any name you want for the file,
I chose array_a.dat for illustration.)

I am new in Fortran. So, please help me.

Thus,

program ...

real(...), dimension(...) :: a

inquire( file='array_a.dat', exists= file_exists)

if( file_exists )then

open( unit= a_unit, file= 'array_a.dat', form= 'unformatted', &
access= 'sequential', status= 'old')

call compute_array_a( a)

write( unit= a_unit) a

else

open( unit= a_unit, file= 'array_a.dat', form= 'unformatted', &
access= 'sequential', status= 'new')

read( unit= a_unit) a

endif

end program ...

I left out a bunch of stuff, but that's one general way
to solve my understanding of your problem.

HTH

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.
.



Relevant Pages

  • Re: fast stable sort
    ... For fastest load, at expense of slower sort, you ask the operating ... and you memory-map the file directly into that array. ... memory of your big array. ... possible to assure locality of reference and thus avoid thrashing ...
    (comp.programming)
  • Re: Storing large number of values in 2D array
    ... array.How can I store them and retrieve them later? ... around 32 000 bytes for the 2D array. ... But that was a memory efficient solution, ... I have seen proposals to add to C ...
    (comp.lang.c)
  • Re: A challenging file to parse
    ... algorithm problem and found a Orun-time and Omemory solution, ... Do the same thing, but when storing in an array, store it at ...
    (comp.lang.c)
  • Re: Database in memory
    ... > I have a large amount of information which I store in memory. ... > this information as array of structures using CPtrArray. ... > several tables completely in memory and query it with SQL? ...
    (microsoft.public.vc.mfc)
  • Re: dealing with a time series piece wise (with gaps)
    ... You do not mention the size of the text file, if its small enough to fit in memory, using LOAD and then working off the data in memory might be faster than: ... However, since you will not know how much data to expect in a segment you will not be able to pre-allocate, this might slow your code. ... store this piece of triplet array (time, ...
    (comp.soft-sys.matlab)

Loading