Welcome to iraf.net Thursday, March 28 2024 @ 12:14 PM GMT


 Forum Index > Help Desk > Applications New Topic Post Reply
 an iraf script problem
   
haha
 08/29/2014 09:25AM (Read 2260 times)  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
How to write a wspectext script in bash?
It is like:
$wspectext spectra.fits spectext

So there are two parameters now.

images
imutil
noao
onedspec
unlearn wspectext
wspectext.wformat="%0.2f"
printf ("wspectext ('%s', input='%s', header-)\n", args) | cl

How to write the last line?



 
Profile Email
 Quote
fitz
 08/29/2014 03:41PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040

WSPECTEXT is actually a CL script, but more importantly it (and all the commands your list) are IRAF commands. You can't invoke it directly from a Bash script (well, not easily) since you need to load packages and set parameters, however you can write a host script for IRAF that does the same thing. For example,

PHP Formatted Code

    #!/iraf/iraf/bin.linux/cl.e -f

    set imdir = "HDR$pixels/"           # default environment  
    logver = "IRAF V2.11 May 1997"      # needed for IMAGES package

    images                              # load needed packages
   imutil
    noao
    onedspec
    {
        unlearn wspectext

        wspectext.wformat = "%0.2f"

        # Execute the command.
        printf ("wspectext %s\n", args) | cl()

        logout                          # shut down
   }
 


The first line invokes the CL interpreter, note the path to the binary and the "-f" flag are required. The 'logver' is an old version, you should replace it with whatever that line is from your login.cl file. The rest of the script loads the packages and executes the commands before logging out. Just save this script as something like "wspec" and make it executable and you can use the command 'wspec' from your shell.

More about host script is available at http://iraf.noao.edu/iraf/web/new_stuff/cl_host.html

 
Profile Email
 Quote
haha
 08/31/2014 04:36AM  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
Thanks. It can be run like
$
PHP Formatted Code
wspectext spec.fits spectext


However we have to extract the right band of an spectrum.fits first.
How to specify the band in the script?
Below does not work.
$
PHP Formatted Code
wspectext spectrum.fits[*,2] spectext

----------------
Another question is about the script splot.
Anyone can call xgterm successfully? The output of my script is messy code in the terminal.
How to revise below?

PHP Formatted Code
reset stdplot = "lw8"
noao
onedspec
splot.band=2
printf ("splot %s\n", args) | cl()
logout


 
Profile Email
 Quote
fitz
 08/31/2014 04:43AM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
wspectext spectrum.fits[*,2] spectext


In a command like this you need to put double quotes around the image name with the section to keep the unix shell from expanding it, e.g.

wspectext "spectrum.fits[*,2]" spectext


For SPLOT you can work interactively, but you need to put a "stty xgterm" in the script to tell IRAF what type of terminal you're using. If you see garbage on the screen it means there is a mismatch between the terminal you are actually using, and the one IRAF thinks you are using. Note you need to execute the script from an xgterm, it will not be started for you.

 
Profile Email
 Quote
haha
 08/31/2014 06:21AM  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
If I run\$this-\$this->_split2($m[0])_normalize_entities2($m[0])
PHP Formatted Code
wspectext  "spectrum.fits[*,2]"  spectext


Then below will appear in my terminal
PHP Formatted Code
ERROR: may not convert string to other types
ERROR: may not convert string to other types
    cl ()
    cl ()
    cl ()
    onedspec ()
    cl ()
 


I have to run in two steps:
PHP Formatted Code
scopy spectrum.fits spec.fits bands=2
wspectext  "spec.fits"  spectext


About splot:
I have specified stty already
However the output is below:
timeout - terminal type set wrong? (`stty termtype' to reset)
Then messy code in my terminal appears.

 
Profile Email
 Quote
fitz
 08/31/2014 06:29AM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
Is 'wspectext' in this case the name of your #!cl script or the iraf WSPECTEXT itself? I was assuming it was the #!cl script and so the quotes escape the characters in the unix shell.

The rest of the garbage output indicates you aren't running from an XGterm window.

 
Profile Email
 Quote
haha
 08/31/2014 07:07AM  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
All of them(wspectext,scopy,splot) are run in bash.

I have to use scopy to extract the right band, then use wspectext to get the text file.

splot(in shell) is not able to call xgterm. Xgterm just can not pop out.


You can run below in shell successfully?
PHP Formatted Code
$wspectext "spectrum.fits[*,2]" spectext
$splot spectrum.fits




 
Profile Email
 Quote
fitz
 08/31/2014 07:14AM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
You cannot call the tasks directly from bash, you have to use a #!cl script in order to have a CL run the task.

None of the tasks will start an xgterm for you, you have to start the window yourself and run IRAF or your #!cl script from that window first,

 
Profile Email
 Quote
haha
 08/31/2014 09:57AM  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
Yes. I have written the scripts(names are the same as in iraf) in cl format and put them into my /bin

You can run blow successfully?
$wspectext "spectrum.fits[*,2]" spectext


The main body of wspectext is as below.
PHP Formatted Code
{
  unlearn wspectext
  wspectext.header=no
  wspectext.wformat="%0.2f"
  printf("wspectext %s\n",args)|cl()
  logout
}



Yes. I can run my splot script in xgterm now.
However the two steps can be combined? Can I run it in one step in bash terminal?
How to open xgterm and run script in xgterm via a bash terminal?

 
Profile Email
 Quote
fitz
 09/01/2014 04:26AM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
Because WSPECTEXT is also a CL script there seems to be some weird interaction with the #!cl. Anyway, the following script seems to work as expected:

PHP Formatted Code

#!/iraf/iraf/bin.macintel/cl.e -f

noao
onedspec

{
  string  arglist, in, out

  printf ("args = '%s'\n", args)

  arglist = mktemp ("tmp$help")                 # get the arg words
 print (args) | words ("STDIN", > arglist)
  list = arglist
  i = fscan (list, in)                          # input file
 i = fscan (list, out)                         # output file

  unlearn wspectext
  wspectext.header=no
  wspectext.wformat="%0.2f"

  wspectext (in, out)                           # execute
 logout
}
 


The script can include SPLOT or any other commands you like. If you want to start an XGterm running the script then you can use something like

PHP Formatted Code
% xgterm -e wspectext "foo.fits[*,2]" spec.txt


 
Profile Email
 Quote
haha
 09/01/2014 12:18PM  
+++--
Chatty

Status: offline


Registered: 10/25/2013
Posts: 39
Yes! Thanks. The wspectext script is OK now.

However the reason I want to run xgterm first is only for splot. It is not necessary to run
PHP Formatted Code
 xgterm -e wspectxt "spectrum.fits[*,2]" spectxt


And it seems abc can not be transferred into in xgterm.
Because
PHP Formatted Code
xgterm -e abc
just merely opens xgterm.



 
Profile Email
 Quote
   
Content generated in: 0.51 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login