Questions and Answers

From Remeis-Wiki
Jump to navigation Jump to search

How can I find out which function/line in my code is causing a stack overflow?

You can use the package stkcheck and activate the function enable_stack_check():

printf("Guess how many characters were written...\n");

This will show in which line/functions values are left on the stack:

Guess how many characters were written...
<stdin>:4: 1 object(s) left on the stack

You have to know that in S-Lang, you have to explicitly catch all return values of the functions you're calling. In case you're not interested in the return value, discard it by assigning it to an empty pair of parentheses:

()=printf("I don't care about the number of bytes written!\n");
More information for experts

S-Lang functions may have more than one return value. A trivial example:

define sum_and_product(a, b)
  return (a+b, a*b);

(s, p) = sum_and_product(a0, b0);

One selectively discard some return values, or also all of them, by using according empty places in the comma-seaparated list of variables inside the parentheses:

(s,  ) = sum_and_product(a0, b0);
( , p) = sum_and_product(a0, b0);
( ,  ) = sum_and_product(a0, b0);

Note that in versions of S-Lang prior to pre2.2.4-7, qualifier values were confused with values left on the stack, such that enable_stack_check() would complain in any case.

How can I read CSV files?

CSV files are Comma-Seperated Variable ASCII files, which are easily read into ISIS using the ascii_read_table function. For each value in your file you have to give the format plus the separator to the next value, i.e., a comma (",").

variable dat = ascii_read_table("lc.csv", [{"%F,","time"},{"%F,","rate"},{"%F","err"}]) ;

This returns a structure dat

dat = struct{Double_Type time, Double_Type rate, Double_Type err}

or you can use the presumably better csv routines in ISIS, which you can get access to by require("csv"). You can then read your data using

reqiuire("csv") ;
variable dat = csv_readcol ("lc.csv" ; type=['d','d','d'], fields = ["time", "rate", "err"]) ;

which returns the same structure as above. Note that type needs to be an array of UChars, so single quotes only. Without the type qualifier the fields of dat will be String_Type.

See the documentation of csv_readcol and csv.readcol for further information.