2 registered members (AndrewAMD, howardR),
472
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
strf length-limitation
#467640
08/18/17 14:15
08/18/17 14:15
|
Joined: Aug 2017
Posts: 294 Netherlands
Grant
OP
Member
|
OP
Member
Joined: Aug 2017
Posts: 294
Netherlands
|
Greetings all, I'm working on a script to create a data set for R which requires a lot of input variables. As a result, the total character length per record exceeds the 1000 characters limit from the strf function. Is there a workaround for this? for better readability I'm limiting the length of my code, but it looks like this
for(i=0; i < 10; i++)
{
file_append(name,strf(
"n%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,etc...",
DS, (DS + IH), (DS + IH - 10), (DS + IH - 20), (DS + IH - 30), (DS + IH - 40), (DS + IH - 50), (DS + IH - 60), (DS + IH - 70), (DS + IH - 80), (DS + IH - 90),etc...));
DS = DS - 1;
}
Thanks for any feedback! Grant
|
|
|
Re: strf length-limitation
[Re: jcl]
#467670
08/20/17 16:49
08/20/17 16:49
|
Joined: Aug 2017
Posts: 294 Netherlands
Grant
OP
Member
|
OP
Member
Joined: Aug 2017
Posts: 294
Netherlands
|
Thank you for your suggestion, JCL. I'm not familiar yet with this sprintf function, so I had to look it up. I've tried the following simplified code, but now it seems that there's a hard limit for the number of individual arguments from the sprintf function: 123 max. Is this correct? Once I try to compile my script with more arguments, it results in syntax error with a reference to the sprintf function.
function run()
{
char buffer[2000];
int DS = 1500;
string name = "DataExport.csv";
if(is(FIRSTRUN))
for(i=0; i < 10; i++)
{
sprintf(buffer,"n%i,etc..", DS, etc..);
file_append(name, buffer);
DS = DS - 1;
}
}
Last edited by Grant; 08/20/17 18:18.
|
|
|
Re: strf length-limitation
[Re: jcl]
#467682
08/21/17 14:13
08/21/17 14:13
|
Joined: Aug 2017
Posts: 294 Netherlands
Grant
OP
Member
|
OP
Member
Joined: Aug 2017
Posts: 294
Netherlands
|
I was able to throw it in a for-loop. It's definitely not the fastest way, but I only need this routine during the initialization of the model. Once again thanks for your input! Grant
function run()
{
char buffer[2500];
int DS = 1500, i, i2, i3, IH = 60;
if(is(FIRSTRUN))
for(i=0; i < 10; i++)
{
i3 = sprintf(buffer, "n%i", DS);
for (i2=0; i2 < 144; i2++)
{
i3 += sprintf(buffer + i3, "%s", ",");
i3 += sprintf(buffer + i3, "%i", DS + IH - (10 * i2));
}
file_append(name, buffer);
DS = DS - 1;
}
}
Last edited by Grant; 08/21/17 14:21.
|
|
|
|