Search code examples
netlogo

Netlogo 5.3.1 - export-world not working and not producing any files


I am trying to use export-world with NetLogo to get my data out and into an excel file (I want to run stats on how many times my agents walk over sites in a model). It initially worked once with the "export-world" command, but it stopped working.

I saw that this command over-writes the initial file, so following the Netlogo dictionary, I changed the code to read as below:

to go

   move

   check-if-site

   tick

   if ticks = 100 [stop
    
    export-world (word "results " date-and-time ".csv") ]



end

However, now, no CSV document is being created at all.

Thanks for any help!

Update - I tried shifting the stop position, but it created the following error:

export-world: java.io.IOException: The filename, directory name, or volume label syntax is incorrect

error while observer running EXPORT-WORLD called by procedure GO called by Button 'go'

UPDATE 2 -

Thank you so much for that extra line of code!

While the model worked with the new line of code, I couldn't find the export file anywhere (admittedly, this could simply be due to user error on my end).

However - I found that if I ran it with the line of code, saved it after the model finished, and then used export world from the File menu, it appeared as a CSV file.

Thank you so much again for all your help!


Solution

  • The problem is your scheduling of events. stop happens before export-world and immediately exists the go procedure, therefore export-world will never happen. If you include a stop within any procedure, make sure to always write it down after the last thing you want to happen.

    EDIT AFTER UPDATE A second problem you have is that date-and-time gives you a string of the following format: "01:19:36.685 PM 19-Sep-2002". This string includes a :, which is an invalid character for file-names. You can either choose a different way to name your outputs, or you can use date-and-time but remove the offending characters.

    to go
    
       move
    
       check-if-site
    
       tick
    
       if ticks = 100 [
    
          let new-date-and-time replace-item 2 date-and-time ";"
          set new-date-and-time replace-item 5 new-date-and-time ";"
          export-world (word "results " new-date-and-time ".csv") 
    
          stop
       ]
    
    end
    

    This gives you a file with the following name: results 01;19;36.685 PM 19-Sep-2002.csv. You can of course do the replacement to whatever character you want, as long as it is a valid one.