Board index FlightGear Development Nasal

Nasal IO - no such file or directory.

Nasal is the scripting language of FlightGear.

Nasal IO - no such file or directory.

Postby legoboyvdlp » Thu Jan 17, 2019 4:10 pm

Hi,
I'm trying to use Nasal IO for a side project:

Code: Select all
var cyclePath = getprop("/sim/fg-home") ~ "/Export/AloftWx/cycle-2018121906.grib2";
   var cycleFile = io.open(cyclePath, "wb+"); # open in write mode
http.load("http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.2018121906/WAFS_blended_2018121906f06.grib2").done(func(r) io.write(cycleFile, r.response));
   io.close(cycleFile);


In this case, I get "No such file or directory". Isn't io.open(file, "wb+"); meant to open it in write mode? How can I create a new file?
User avatar
legoboyvdlp
 
Posts: 6731
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: Nasal IO - no such file or directory.

Postby wkitty42 » Thu Jan 17, 2019 5:55 pm

does that "AloftWx" directory exist? if no, you need to create it before attempting to create the file... unless there's an existing call i don't know about (very likely) that will create the full path for you as well as the file...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5430
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Nasal IO - no such file or directory.

Postby V12 » Thu Feb 21, 2019 8:33 pm

And what about acces rights on that directory ?
Fly high, fly fast - fly Concorde !
User avatar
V12
 
Posts: 1299
Joined: Thu Jan 12, 2017 4:27 pm
Location: LZIB
Callsign: BAWV12

Re: Nasal IO - no such file or directory.

Postby Hooray » Thu Feb 21, 2019 8:42 pm

The SGPath API (meanwhile exposed to Nasal thanks to work done by TheTom a few years ago), is the correct API to ensure that the path/directory is created first.

Also, keep in mind that paths may be case-sensitive, depending on your OS/file system type
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11317
Joined: Tue Mar 25, 2008 8:40 am

Re: Nasal IO - no such file or directory.

Postby legoboyvdlp » Fri Feb 22, 2019 12:07 pm

I've since managed to solve it using

Code: Select all
http.save


However, I'm unable to read a binary (grib2) file; any ideas about that? I suppose FlightGear needs a grib2 parser library added for that...?
User avatar
legoboyvdlp
 
Posts: 6731
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: Nasal IO - no such file or directory.

Postby wkitty42 » Fri Feb 22, 2019 3:46 pm

that depends on what you are trying to do with them... there're some really huge files in there, too...

what are you trying to do?

i took a look at the site and at least for today, 20190222, the one file you referenced above doesn't exist...

i also noticed for some others, they were two days behind... like the files for the 15th were stamped the 17th...

if you can execute external programs from within FG, you might consider the wgrib2 programs to process externally and produce other formats you might easier use... for example, you could convert to csv and then do what you are trying to do... the problem there is having to distribute the binary for each OS and execute the right one when running...
https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/

but again, it depends on what you are trying to do... perhaps processing the file before flight and generating the needed data files for the flight which you can then use would be the thing to do? that way, folks who want it can run it and then go flying with the data...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5430
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Nasal IO - no such file or directory.

Postby legoboyvdlp » Fri Feb 22, 2019 5:10 pm

Yeah, that file referenced above was from September.

What I'm trying to do is extract the aloft wind information and pass it to advanced weather, but I've been unable to get beyond downloading the file from within FlightGear. Wgrib2 looks good, but I'm not entirely sure how one would run it within FlightGear.
User avatar
legoboyvdlp
 
Posts: 6731
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: Nasal IO - no such file or directory.

Postby wkitty42 » Sat Feb 23, 2019 6:51 am

You wouldn't unless it could be done in the background... Then there's processing time which we don't know yet... But based on the file sizes, it could be a while... Not sure folks on slow connections would want to be pulling many files of those sizes... What I'm also seeing is those files are historic instead of live... I may not be seeing everything, though...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 5430
Joined: Fri Feb 20, 2015 3:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 14.04.5

Re: Nasal IO - no such file or directory.

Postby Hooray » Sun Feb 24, 2019 4:36 pm

that's indeed the correct answer - while Nasal does have threading support, most of the FG-related APIs are not thread-safe at all.
What is commonly done in such cases is to create a separate middleware and hook that up to fgfs using some kind of IPC/networking

Apart from that historical data might be used to extrapolate data points
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11317
Joined: Tue Mar 25, 2008 8:40 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest