|
Hello again and thank you for the reply, Yes, when I was checking the OPEN and FILE statements on google, all I got was I/O fortran and Java instances. My operating system is windows 7. I am using default libraries of Lua plus a code generated in our lab for optimization purposes. In this specific case we are actually using Dakota for optimization. So what happens is that Lua will generate a Dakota run file which will be called through serpent library. This Dakota run file has to call
lua files in loops (a multi-objective genetic algorithm). The thing is that I didn’t write this handler but as far as I can check the code several libraries are used including: socket, and serpent. I am attaching part of the code dealing with this call. Function “optimize” which call “requireSocket” and later “PrivateListen” which will call “call”. Serpent is used for serialization. Sorry for the amount of code. This part is not well written and I do not really understand the way it works. Thank you again for your help, Maziar function lib:optimize(args) --------------------------------------- self.options.graph = false self.options.d3js = false self.objectives_size = args.objectives_size local socket = lib.requireSocket() local software = args['software'] local cmd = '' local tmpDir = '' -- Preparing socket local server = assert(socket.bind("*", 0)) local ip,port = server:getsockname() local encoding = nil --------------------------------------- if software == nil then print('You must specify a software name for optimization.[dakota/moo,MOO]') return nil elseif software == 'dakota' then self.dakota = true local dakota_helper = require 'osmose.helpers.dakotaHelper' -- create the directory that will run dakota tmpDir = ('./results/'..self.name..'/run_' .. string.format('%03i', self.run) .. '/dakota') lub.makePath(tmpDir) -- prepare objective file for Dakota cmd = dakota_helper.prepareFiles(tmpDir,self.sourceDir,args,port) cmd = cmd .." > "..tmpDir.."/JEGA.log" cmd = cmd .." && "..(OSMOSE_ENV["LUA_EXE"] or 'lua').."
"..tmpDir.."/stop.lua" elseif software == 'moo' or software == 'MOO' then local moo = require 'osmose.helpers.mooHelper' -- preparing tmp directory tmpDir = ('./results/'..self.name..'/run_' .. string.format('%03i', self.run) .. '/moo') lub.makePath(tmpDir) cmd = moo.prepareFiles(tmpDir,self.sourceDir,args,port) encoding = 'json' end local project = Eiampl(self) -- prepare project with Eiampl print('Software command is', cmd) local file = assert(io.popen(cmd,"w")) lib.privateListen(project,server,encoding) print("Optimization finished") print("Result directory is", tmpDir) end function lib.requireSocket()
local ok, socket = pcall(require,"socket") if ok == false then error('lua socket is not installed. Please install it with:\nluarocks install socket') end return socket end function lib.privateListen(project,server,encoding) while true do local ip,port = server:getsockname() print('Listen to port ',port) local client = server:accept() local line, err, partial = client:receive("*l") print('receive', line, err, partial) local solve = string.find(line,"solve") if line == "stop" or partial == "stop" then print("Closing port ", port) client:close() server:close() return "stop" end if err then client:close() print(err) end local rslt = lib.call(project,line,encoding) print('result', line, rslt) if rslt then client:send(rslt.."\n") client:close() else client:send("nil\n") client:close() end end end function lib:call(str,encoding) local _encode if encoding == 'serpent' or encoding == nil then -- Serpent is used for serializing results local ok, serpent = pcall(require ,'serpent') if ok == false then error('serpent is not installed. Please install it:\nluarocks install serpent') end _encode = function(value) return serpent.dump(value) end elseif encoding == 'json' then local json = (loadfile "./lib/vendors/json.lua")() _encode = function(value) if type(value) == 'number' or type(value) == 'string' then value = {value} end return json:encode(value) end end if str == nil or str == '' then return _encode(nil) end if self.dakota then self.best_run = self.best_run or 1e10 if self.best_run > help.sum(result) then self.best_run = help.sum(result) -- Write eiampl_best.in local tmpDir = (self.dirRun .. '/scenario_' .. string.format('%02i',1) .. '/hc/') local in_file = assert(io.open(tmpDir..'/'..'eiampl.in',"r")) local best = assert(io.open(tmpDir..'/'..'eiampl_best.in',"w")) local text_in = in_file:read("*a") in_file:close() best:write(text_in) best:close() -- Write eiampl_0000_best.txt local out_file = assert(io.open(tmpDir..'/'..'eiampl_0000.txt',"r")) best = assert(io.open(tmpDir..'/'..'eiampl_0000_best.txt',"w")) local text_out = out_file:read("*a") out_file:close() best:write(text_out) best:close() end end else result = nil end return _encode(result) end Message: 4 Date: Wed, 31 May 2017 13:11:13 +0000 From: ? ?? <nerditation@outlook.com> Subject: Re: ERROR of I/O To: "lua-l@lists.lua.org" <lua-l@lists.lua.org> Message-ID: <CY4PR14MB1432027ECCEDF3EDCC856631A1F10@CY4PR14MB1432.namprd14.prod.outlook.com> Content-Type: text/plain; charset="utf-8" ??? 2017/5/31 20:58, Kermani Maziar ??????: > Hello everyone, > > > *The value of the FILE specifier in an OPEN statement is invalid
> (unit=12).* > > this doesn't seem to be an error generated by Lua runtime. you should provide more context on the environment, such as on what operating system your program is running, what libraries are used, etc. most importantly, is your host program
the standalone Lua interpreter or any program that embeds Lua, such as a game mod or plugin, etc. -- the nerdy Peng / ????????? / From: Kermani Maziar Hello everyone, I am using lua version 5.1 and in some instances I get the following error: The value of the FILE specifier in an OPEN statement is invalid (unit=12). I really appreciate it if anyone knows what this error is all about. Thank,
|