[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Including files

J.D. Smith wrote:
> [...]

>  That is, you must use:
> common cblock, var1, var2, var3, var4, ...
> everywhere instead of:
> common cblock
> Normally this is a real pain, since changing the common block requires
> changing all of its definition statements.  However, if you put the
> definition in one file and simply do a:
> @cblock
> at the beginning of all relevant procedures, you can change your common
> block in one place and still not require an initializer.

This is not quite right. You will have to make sure that your common
block gets initialized correctly! For IDL, a common block at the
beginning is nothing else than a list of variable names. The first
procedure that uses these variables determines their type and
dimensions. Once these are set, you have to exit your IDL session and
restart if you want to make any changes. Unless you are certain that it
is always the same procedure that makes first use of the common block
variables, you are in great danger of trapping into conflicting variable
declarations (implicit definitions that is). 

   Of course ;-) I can also offer you a solution which is to include a
default definition in your include file as well, such as:

; myinclude.pro  === note, this is not a procedure
common bla,var1,var2,svar

if (n_elements(var1) eq 0) then begin
   var1 = fltarr(100)
   var2 = 100L
   svar = ''

Then, regardles which procedure uses your include (myinclude that is
;-), you will always have the same type and dimension for each variable.

> Of course,
> eliminating the common block is another good solution,
a much better one, I should say!

> but sometimes
> this can't be done.
also true.  ;-)

> This technique can be extended to other areas also, such as common error
> checking code, etc.
> Good Luck,
> JD
> --
>  J.D. Smith                             |*|      WORK: (607) 255-5842
>  Cornell University Dept. of Astronomy  |*|            (607) 255-6263
>  304 Space Sciences Bldg.               |*|       FAX: (607) 255-5875
>  Ithaca, NY 14853                       |*|

I really like participating in this newsgroup to get me started in the


Martin Schultz, DEAS, Harvard University, 29 Oxford St., Pierce 109,
Cambridge, MA 02138          phone (617) 496 8318   fax (617) 495 4551
e-mail mgs@io.harvard.edu    web http://www-as/people/staff/mgs/