how to run multiple program in one program?

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

how to run multiple program in one program?

Postby Liu » Thu Oct 20, 2011 2:30 pm

Hi,

I created quite a few modelling programs, say model1.prg, model2.prg... and I want to use a master program
to control what program to run everyday. For example, in masterprogram.prg I wrote commands as below:

run path:\model1.prg
run path:\model2.prg
run path:\model3.prg



The problem right now is that once the first sub program is finished, it doesn't procede to run the second program. The entire
master program stops now at model1.prg.

How can I let eviews continue with the rest of the program?

Thanks in advance.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: how to run multiple program in one program?

Postby EViews Glenn » Thu Oct 20, 2011 2:58 pm

Use include or better yet exec instead of run.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: how to run multiple program in one program?

Postby Liu » Fri Oct 21, 2011 5:48 am

Yes Glenn I used the exec now and it seem to run one program after another according to the list in my masterprogram.

I still have slightly a problem: if one program in the middle has some errors and paused, can I program the mastery program so that
it can proceed to the next program? what I mean is like this: suppose that the master program is :
exec model1.prg
exec model2.prg
exec model3.prg

what I'm trying to do is that in case something's wrong with model1, it dones't stop there, instead it proceed to run model2.
is there a better way other than setmaxerror?

Million thanks.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

how to run multiple program in one program?

Postby EViews Gareth » Fri Oct 21, 2011 7:04 am

Use @errorcount to check if a line caused an error, then "return" if it did.

Davidth
Posts: 10
Joined: Thu Feb 06, 2014 12:59 pm

Re: how to run multiple program in one program?

Postby Davidth » Thu Mar 06, 2014 1:05 pm

Is there a way to run the execute function across a bunch of programs in a specific folder? I have dozens of variations of models that I have to run on the same data. I would like to just group them into folders and run all of the programs in a folder as needed.

Thanks for the help.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: how to run multiple program in one program?

Postby EViews Gareth » Thu Mar 06, 2014 3:41 pm

Just make a program that executes all the programs in the folder.

Davidth
Posts: 10
Joined: Thu Feb 06, 2014 12:59 pm

Re: how to run multiple program in one program?

Postby Davidth » Thu Mar 06, 2014 8:38 pm

Thanks for the reply Gareth, but I only know how to get it to run specific programs that I specify directly. I was looking to find out how or where I can learn how to direct it to run a group of programs in a folder.

I looked through the Command Ref and Obj Ref guides and did not see an explanation for how to have the execute command run a series of programs from a single folder. Thanks again for your help.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: how to run multiple program in one program?

Postby EViews Gareth » Thu Mar 06, 2014 9:40 pm

Use the @wdir function to make a list of all files in the folder, then loop through them one at a time, execing each one.

Something like:

Code: Select all

%dir = "c:\temp" %list = @wdir(%dir) for %j {%list} if @upper(@right(%j, 3)) = "PRG" then %file = %dir + "\" + %j exec %file endif next

Davidth
Posts: 10
Joined: Thu Feb 06, 2014 12:59 pm

Re: how to run multiple program in one program?

Postby Davidth » Fri Mar 07, 2014 8:15 am

Thanks so much Gareth. This is my first job that requires me to get into this much detail with programming and I can honestly say, I do not think I would have ever figured that one out.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: how to run multiple program in one program?

Postby cc100 » Thu Dec 10, 2015 3:04 am

Hi Gareth, I'm using the code above to write a program that takes in a sample period and then runs a list of programs, and saves down the work files somewhere. I'm using the 'exec' function to run the programs and the 'wfsave' function to name the work files that each program run creates. I have a very simple question(!) - I have said 'wfsave "C:\my documents\testfile\JPY" how can I get it to time stamp the work file so that it calls it JPY_10/12/2015...ie so that it adds todays date at the end of the name. thanks!

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: how to run multiple program in one program?

Postby cc100 » Thu Dec 10, 2015 4:10 am

And one more question: I have a number of programs, which start with the following code:

%my_startdate = "31/10/2003"
%my_enddate = "08/12/2015"
'*********************************************************************************************************************

wfcreate file1_jpy d5 %my_startdate %my_enddate

All the program files start with the same code, i.e: they all take in a start and end date (except they have different names, file1, file2 etc..)

I want to write a master program file that takes in a start date and an end date and feeds that into each program, runs each program and then saves the workfiles. So I have the following:

%my_startdate = "31/10/2003"
%my_enddate = "10/12/2015"
'*********************************************************************************************************************

'exec "C:\documents\test1\file1_jpy.prg"
'wfsave "C:\documents\test1\jpy1.wf1"

'exec "C:\documents\test1\file2_jpy.prg"
'wfsave "C:\documents\test1\jpy2.wf1"

'exec "C:\documents\test1\file3_jpy.prg"
'wfsave "C:\documents\test1\jpy3.wf1"

The issue I am having is that the master program file cannot overwrite the dates in each individual file. So I would like to know the code that allows me to feed in dates into each individual file please. (and the other question of how to date stamp each work file so that it reads "jpy1_101215"

Thank you

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: how to run multiple program in one program?

Postby EViews Gareth » Thu Dec 10, 2015 7:28 am

Code: Select all

@datestr(@now, "yyyy-mm-dd")
returns the current date as a string.


To pass information onto child programs you'll want to use program arguments or program options.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: how to run multiple program in one program?

Postby cc100 » Thu Dec 10, 2015 8:39 am

HI Gareth, thank you - why doesn't the following syntax work: wfsave "C:\documents\test1\jpy3_" + %date +".wf1"

it just produces the file name jpy3_.wf1

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: how to run multiple program in one program?

Postby cc100 » Thu Dec 10, 2015 8:40 am

sorry forgot a bit of the program! where %date = @datestr(@now, "yyyy-mm-dd" )

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: how to run multiple program in one program?

Postby EViews Gareth » Thu Dec 10, 2015 9:49 am

Create the file name string before the wfsave command


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest