View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Basic questions How to define string arrays and clear strings and arrays that I want to redefine

andrej wrote on Dec 15, 2014


Greetings. I am struggling so much to find some basic information but when I run a bunch of general internet searching, and search through the manual and the help in IRAF itself, I can't find answers to some basic things (tried on a few different days and have spent almost 6 hours with an exhaustive combination of search terms):

(1) How do I create a string array like "first," "second," "third," "fourth"?

(2) How do I print the whole string? Like if I do

string mycustomarray = "first," "second," "third," "fourth"

How can I use a print command to get

first, second, third, fourth

to appear in the Terminal?

(3) How do I clear the definition of mycustomarray so that I can define it to be something else later, like

mycustomarray = "one," "two," "three," "four"

?

(4) Likewise, how do I clear the definitions of other strings that I create, for example,

string myvariable = "December2014"

and redefine it to be

myvariable = "January2015"

?

(5) Where can I find a tutorial or workshop on how to work with how to set my own IRAF variables? The resources that I located were about parameters within tasks and advanced scripting.

Mike Fitzpatrick wrote on Dec 16, 2014


(1) How do I create a string array like "first," "second," "third," "fourth"?


Try

string foo[4] = "first", "second", "third", "fourth"

The size of the array must be part of the declaration.

(2) How do I print the whole string? Like if I do

string mycustomarray = "first," "second," "third," "fourth"

How can I use a print command to get

first, second, third, fourth

to appear in the Terminal?


You would have to do it in a loop, e.g.


   for (i=1; i <= 4; i=i+1) {
       printf ("%s", foo[i])
       if (i < 4)
           printf (",")
       else
           printf ("\n")
    }
 


(3) How do I clear the definition of mycustomarray so that I can define it to be something else later, like

mycustomarray = "one," "two," "three," "four"

?


You can't "undeclare" the array, you can simply reuse the elements. Note this means you can't change the size either.



(4) Likewise, how do I clear the definitions of other strings that I create, for example,

string myvariable = "December2014"

and redefine it to be

myvariable = "January2015"

?


Just exactly like that, i.e. you redefine to the value.



(5) Where can I find a tutorial or workshop on how to work with how to set my own IRAF variables? The resources that I located were about parameters within tasks and advanced scripting.


In case you haven't already found it, see the Script Guide at https://iraf.net/irafdocs/script/ as well as the CL Programmer's Manual at

ftp://iraf.noao.edu/iraf/docs/clman.ps.Z

Last post on Dec 16, 2014