Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Mata fopen() and memory, manual error


From   Matissa Hollister <[email protected]>
To   [email protected]
Subject   st: Mata fopen() and memory, manual error
Date   Wed, 25 Jan 2006 12:39:41 -0800 (PST)

The Mata manual says that fputmatrix stores matrices
in a compact and efficient format.  Also, assuming my
reading is correct, more than one matrix can be saved
into a single file.  I'm planning to run analysis that
will do several iterations of a mata function I have
written with a moderately large matrix as the output
(perhaps as large as 1000x1000).  My inclination is to
append the resulting matrices all to one file, thereby
reducing clutter in my folders.  When I finally use
the results, though, I�ll only use one matrix at a
time (passing it into a clustering program).  I'm
wondering whether there are memory or other reasons
for keeping the matrices in separate files.  For
instance, when you use the command fopen()does it read
the entire contents of the file into memory?  If so,
then obviously creating separate files would use up
less memory.  My impression, though, is that fopen()
does not read the file into memory, it would only read
in the matrix when I specify fgetmatrix().  But I
can�t find documentation to support this and I don�t
have a good enough background in programming to be
sure.

On a related note, I think there might be an error on
p. 359 of the Mata manual.  The sample code at the top
of the page says:

fh_in = fopen(inputname, "r")
fh_out = fopen(outputname, "w")
while ((c=fread(fh_in,1))!=J(0,0,"") {
   fwrite(fh, (c=="a" ? "b" : c))
}
fclose(fh_out)
fclose(fh_in)

shouldn't the fourth line be:
fwrite(fh_out, (c=="a" ? "b" : c))

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index