1

Solved, now working example!

I have a set of time series that is populated in a folder structure as follows:

TimeSeriesData\Config_000000\seed_001\Aggregate_Quantity.txt
…
TimeSeriesData\Config_000058\seed_010\Aggregate_Quantity.txt

And in each file there is a first line containing a character, followed by lines containing the data. E.g.

share
-21.75
-20.75
…

Now, I would like to import all those files (at best, without specifying ex post the number of configs and seeds, at worst with supplying it) into single time series of the like: “AggQuant_config_seed” where config relates to the config ID and seed to the seed id.

I tried the following (using the non-preferred way), but “parsing” the “path” does not work / I do not know how to do it.

string base = "TimeSeriesData/Config_"
string middle = "/seed_"
string endd = "/Aggregate_Quantity.txt"
string path = ""
loop for (i=0;i<=58;i+=1)
    loop for (j=1;j<=10;j+=1)
        path = ""
        sprintf path "%s%06d%s%03d%s",base,i,middle,j,endd
        append @path #will be named share
        rename share Agg_Q_$i_$j #rename
    endloop
endloop 

To sum up the problem, the following does not work:

string path="somwhere/a_file.txt" #string holding path
#wrong: append $path #use append on string
append @path #works!

And if possible, a way to search recursively through a set of folders, using the folder information together with file-information for the variable name, would be nice. Is that possible within gretl?

I realize that in many cases I would like to refer to a specific “help” section like those for functions and commands, but for operators instead (like “$”, which is obviously wrong here).

Frederik
  • 355
  • 2
  • 8
  • This is not a complete answer, just some partial remarks. – Sven S. Dec 02 '16 at 15:39
  • 1
    Argh, why doesn't return enter a line break in this field? Anyway, first, it looks as if you can delete the `path=""` line. Second, indeed `$path` is wrong, you need the at-character @ instead of the dollar here.Third, in the sprintf line you want the numerical values of i and j and thus get rid of the $ signs there. But the general approach looks feasible. Good luck! – Sven S. Dec 02 '16 at 15:49
  • That's it. Thanks Sven! – Frederik Dec 02 '16 at 18:59

0 Answers0