'program with a collection of useful subroutines

'	'testing
'	ktsim(notabd) 2018 2023
'	%spec=""
'	%m="_kvarts"
'	%var= "pbol"
'	call spec(%m, %var)  	'returns a string %SPEC with the specification of a variable within a model object (including coefficients), see addins\subroutines.prg
'	string _a=%spec
'	show _a


'SPEC - subroutine that finds the specification of a variable within a model object
	'returns a string %SPEC with the specification of a variable within a model object (including coefficients) 
	subroutine spec(string %m, string %var)
			%spec={%m}.@spec(%var)
				'if it is an equation object or some other object, must get the underlying specification
				if @left(%spec,1)=":" then
						%equation=@mid(%spec,2) 'save equation name for later
						'find specification from other objects, such as systems
						%auxmodspec=@getnextname("zauxmod")
						%auxsvecspec=@getnextname("zauxsvec")
						'create auxiliary model
						model {%auxmodspec}

						'update coefficient vector (needs this because of a bug, see forum: http://forums.eviews.com/viewtopic.php?f=4&t=20625, fixed 23. nov 2020
							!builddate=@dateval(@builddate, "YYYY-MM-DD")
							!updatedate= @dateval("2020-11-23", "YYYY-MM-DD")
							!neweviews=@datediff({!updatedate}, {!builddate}, "dd")-1
							'%pre_existing_content = @wlookup("*") ''Find existing objects in workfile 						
							'minimize workfile window
								if !neweviews >=0 then 'hvis det en gammel versjon av EViews, dvs før 23. nov 2020
									{%equation}.updatecoefs
								endif

						'create svec object with substituted coefficients
						svector {%auxsvecspec}={%equation}.@subst
						close {%equation}
						!elem=@rows({%auxsvecspec})
							for !i=1 to !elem
								%specsub= {%auxsvecspec}(!i)
								{%auxmodspec}.append {%specsub}
							next			
							%spec={%auxmodspec}.@spec(%var)		
							delete {%auxsvecspec}  {%auxmodspec}						
				endif
	endsub


