String variables in GAMS - gams-math

How can I define a string variable in GAMS. I want to use it as a reference to including files as shown below
set file = "myfile.inc"; (i have no idea how to do this part)
$include file;
istead of
$include "myfile.inc"

$set file file_name_here
$include %file%.inc
File is being replaced by your desired filename.
Note that if you want to use this string variable in other included files too you have to use $setglobal instead of $set

Related

CMake space delimited list of objects

$<TARGET_OBJECTS:objLib> this CMake genex gives semi-colon
separated list of objects in an object library.
I need to set space delimited list of objects in a variable and use the variable in add_custom_target
I have tried using string replace in a separate cmake file, call that cmake by passing $<TARGET_OBJECTS:objLib> as an argument. But I don't know how to return the new string.
I tried setting the new string as ENV variable and use it in add_custom_target but it didnt work.
can some one please help me resolve this ?

kscript : How to get directory of current file?

Is there a way to get directory of a current script location in kotlin script?
I could achieve this in bash with
dirname $0
or
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
The builtin kotlin-main-kts script definition adds a __FILE__ variable to the script context. Access works just as you'd expect:
println(__FILE__) // java.io.File object representing /home/user/bin/foo.main.kts (or wherever the script is)
println(__FILE__.parentFile) // java.io.File object representing /home/user/bin
println(__FILE__.absolutePath) // the string /home/user/bin/foo.main.kts
println(__FILE__.parent) // the string /home/user/bin
You can also change the name of the variable using the annotation ScriptFileLocation:
#file:ScriptFileLocation("scriptPath")
println(scriptPath.absolutePath) // /home/user/bin/foo.main.kts
Keep in mind IntelliJ autocomplete doesn't love changing the variable name like that, though. :-)
So how do you run your script with kotlin-main-kts? In Kotlin 1.3.70 and above, it's as easy as ensuring your script's name ends in .main.kts. The compiler will automatically apply this special context, giving you access to __FILE__. For more information, check out the Kotlin repository here.
You can use:
File(".")
and don't forget to import java.io.File

How can i override a default variable from CMakeLists.txt on CMake command line?

I have a .cmake file containing default values for variables. The .cmake file is called from CMakeLists.txt using 'include'.
One of the variables is a version number.
What is the best practice or setup to overrule that variable version number from CMake command line?
In gnu make you could use
var ?= value
where you can set var value on make command line. I do not see something similar in C-Make.
For boolean values, you can use option:
option(CUSTOMIZABLE_VAR "This variable do stuff" "default-value")
Also GUI apps exposing options such as CMake GUI or QtCreator you'll get a the description and a field to edit it.
For value of type string, you can set a cache value with a help string:
set(CUSTOMIZABLE_VAR "8" CACHE STRING "This option is a string")

I want to extract the value of a variable from different file in velocity template

I have a "header.vm", in which I have a variable named "tableHeight" and I want to use the value of this "tableHeight" variable in different .vm file.
I am able to extract the value in "header.vm" using below codes:
#set ($resultGroup = $resultFields.getChild("field-group"))
#set ($tableHeight = $resultGroup.getAttribute("tableHeight").getValue())
and in another file I am using:
#parse(header.vm)
and trying to use "tableHeight" but its not having the value
You should use #include instead of #parse directive in your case, because you want to parse the tableHeight inside your file. See include vs parse:
The #include directive allows the template designer to import a local file. Its contents replace the #include directive in the template. These contents are inserted as-is, they are not rendered through the template engine.
The #parse directive works similar to #include, but the contents of the file will be part of the template rendering process and all VTL elements in the file will be evaluted.

Filter files from directory vb.net

Straight to the question...I have files such as word documents with extension(.doc) and its respective sample files starting with (.sample)
Now I would like to load only the word documents..
I found the way as shown below to load the files but this loads all the files
Can anyone say me how do I filter these files while loading them ?
This is what I'm trying to do:
Dim files = Array.FindAll(Directory.GetFiles(mydir), Function(x) (Not x.StartsWith(".sample")))
This is my directory consists of files as said above:
The way you use it, all the files are retrieved (paying the whole computational cost) and then they are filtered.
As stated in this article, you can use a search pattern directly in file retrieval from your file system.
I suppose you could do something like that:
Dim files = Directory.GetFiles(mydir,".doc*")
If you gave an example of filenames, perhaps I would give you the right filter to apply too.
Hope I helped!
The GetFiles method returns filenames with the path that you specified included.
So if your files are in a folder C:\working\, your mydir variable will contain "C:\working\" and all of the results of GetFiles will be something like
"C:\working\.sample_filename.doc"
"C:\working\123797.doc"
So your x.StartsWith is always going to return false, because x always starts with C:\
Try this:
Dim files = Array.FindAll(Directory.GetFiles(mydir), Function(x) (Not x.StartsWith(mydir & ".sample")))
Note this assumes that your mydir variable ends with a \ character. If not, add it in in the concatenation within the function.
Try this,
Dim files = Array.FindAll(Directory.GetFiles(mydir), Function(x) (Not Path.GetFileName(x).StartsWith(".sample")))