nivi (netlogo interface variables info)

nivi (netlogo interface variables info) preview image

1 collaborator

Default-person Doug Edmunds (Author)

Tags

utility 

Tagged by Doug Edmunds almost 8 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0 • Viewed 382 times • Downloaded 35 times • Run 0 times
Download the 'nivi (netlogo interface variables info)' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

It is a handy tool.

1) Use it to document your own code 2) Use it to help figure out what's going on with a nlogo file.

It shows you what's behind the widgets on the interface.

HOW IT WORKS

It reads the nlogo file line by line, and either displays something or ignores it.

HOW TO USE IT

1) Press Select File and select a file. 2) Press Go

Beyond that, if you want to save the output, highlight everything in the output window and copy/paste it somewhere.

THINGS TO NOTICE

How the code has a bazillion if clauses, but they are in a particular order.

THINGS TO TRY

Try it on all kinds of nlogo files. If you find a problem let the author know (dougedmunds at gmail dot com).

EXTENDING THE MODEL

With some hunting around, you could figure out other details about the widgets.

CREDITS AND REFERENCES

Doug Edmunds developed version 1.0, September 2015. The file is located at http://netlogo.dougedmunds.com

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)

Comments and Questions

Use it to document your code.

When you have many global variables on the interface, the code tab may be difficult to follow. 1. Run this program on your completed code, 2. Copy/paste the output to the top of your code tab, 3. Highlight it, and use Edit/comment, to comment it out. Now all the global variables from the interface can be 'pulled into one document'. You will find this very helpful if you are printing out the code from the code tab.

Posted about 4 years ago

Click to Run Model

; nivi.nlogo "NETLOGO INTERFACE VARIABLES INFORMATION"
; version 1.3
; Requires Netlogo 6.0
; 8 Feb 2017
; Author Doug Edmunds.
; Extracts variables and code hidden behind interface widgets.

extensions [csv]

globals [infile mydata mydata-list
  first_block button_count monitor_count input_count
  slider_count switch_count plot_count pen_count chooser_count
  report-title use-csv?]

to setup
  ca
  ask patches [set pcolor white]
  set first_block 0
  set button_count  0
  set monitor_count  0
  set input_count  0
  set slider_count  0
  set plot_count  0
  set pen_count  0
  set chooser_count 0
  set mydata-list []
  set use-csv? true

  file-close-all
  clear-output
  set infile user-file
  let file_ext ".nlogo"
  ifelse is-string? infile and
         substring infile (length infile - 6 ) (length infile) = file_ext
    [
    file-open infile
    set report-title "nivi - NETLOGO INTERFACE VARIABLES INFORMATION"
    output-print report-title
    output-print infile
    output-print word "Generated: " date-and-time
    reset-ticks
     ]
    [output-print "No file selected. *.nlogo files only"]
  ;reset-ticks
end 

to go
  if is-string? infile
    [
    file-open infile
    ifelse file-at-end?
      [ output-print "end of infile"]
      [ parse-file ]
      file-close-all
    ]
end 

to-report netlogo-delimiter
  report (word "@#$#" "@#$#@")
end 

to parse-file
  while [first_block < 2]

  [ file-open infile
    ifelse file-at-end? ; should not happen
     [ set first_block 9999
       output-print "Reached end of file."
       output-print "Is this a Netlogo .logo file?"]
     [set mydata file-read-line]

    ;allow to exit the while loop
    if first_block = 1 and mydata = netlogo-delimiter [
      set first_block 2
      ;print "ending first_block = 2"
      ]


    if first_block = 1 [

     ;BUTTONS
     if button_count = 6 [output-print word "var: " mydata]
     if button_count = 6 [set button_count  0]  ; reset
     if button_count = 5 [output-print word"label: " mydata]
     if button_count = 5 [set button_count  6]
     if button_count = 4 [set button_count  5]
     if button_count = 3 [set button_count  4]
     if button_count = 2 [set button_count  3]
     if button_count = 1 [set button_count  2]
     if mydata = "BUTTON" [set button_count  1]
     if button_count = 1 [output-print  mydata]

     ;MONITORS
     if monitor_count = 6 [output-print word "var: " mydata ]
     if monitor_count = 6 [set monitor_count  0]
     if monitor_count = 5 [output-print word "label: " mydata]
     if monitor_count = 5 [set monitor_count  6]
     if monitor_count = 4 [set monitor_count  5]
     if monitor_count = 3 [set monitor_count  4]
     if monitor_count = 2 [set monitor_count  3]
     if monitor_count = 1 [set monitor_count  2]
     if mydata = "MONITOR" [set monitor_count 1]
     if monitor_count = 1 [output-print mydata]

     ;INPUT BOXES
     if input_count = 5 [output-print mydata]
     if input_count = 5 [set input_count  0]
     if input_count = 4 [set input_count  5]
     if input_count = 3 [set input_count  4]
     if input_count = 2 [set  input_count 3]
     if input_count = 1 [set input_count  2]
     if mydata = "INPUTBOX" [set input_count  1]
     if input_count = 1 [output-print mydata]

     ;SLIDERS
     if slider_count = 5 [output-print mydata ]
     if slider_count = 5 [set slider_count  0]
     if slider_count = 4 [set slider_count  5]
     if slider_count = 3 [set slider_count  4]
     if slider_count = 2 [set slider_count  3]
     if slider_count = 1 [set slider_count  2]
     if mydata = "SLIDER" [set slider_count  1]
     if slider_count = 1 [output-print mydata]

     ;SWITCHES
     if switch_count = 5 [output-print mydata]
     if switch_count = 5 [set switch_count  0]
     if switch_count = 4 [set switch_count  5]
     if switch_count = 3 [set switch_count  4]
     if switch_count = 2 [set switch_count  3]
     if switch_count = 1 [set switch_count  2]
     if mydata = "SWITCH" [set switch_count 1]
     if switch_count = 1 [output-print mydata]

     ;CHOOSERS
     if chooser_count = 7 [output-print mydata]
     if chooser_count = 7 [set chooser_count  0]
     if chooser_count = 6 [output-print mydata]
     if chooser_count = 6 [set chooser_count  7]
     if chooser_count = 5 [set chooser_count  6]
     if chooser_count = 4 [set chooser_count  5]
     if chooser_count = 3 [set chooser_count  4]
     if chooser_count = 2 [set chooser_count  3]
     if chooser_count = 1 [set chooser_count  2]
     if mydata = "CHOOSER" [set chooser_count 1]
     if chooser_count = 1 [output-print mydata]

     ;PLOTS AND PENS
     if plot_count = 14 [
        test-use-csv
        ifelse use-csv?
         [find-dq
          set mydata-list  ( csv:from-row mydata " " )
          revert-dq 0
          revert-dq 1
          output-print word "Plot setup: "  item 0 mydata-list
          output-print word "Plot update: " item 1 mydata-list ]
        [ output-print word "setup/update: " mydata ]
        ]
     if plot_count = 14 [set plot_count  0]
     if plot_count = 13 [set plot_count  14]
     if plot_count = 12 [set plot_count  13]
     if plot_count = 11 [set plot_count  12]
     if plot_count = 10 [set plot_count  11]
     if plot_count = 9  [set plot_count  10]
     if plot_count = 8  [set plot_count  9]
     if plot_count = 7  [set plot_count  8]
     if plot_count = 6  [set plot_count  7]
     if plot_count = 5  [output-print word "title: " mydata]
     if plot_count = 5  [set plot_count  6]
     if plot_count = 4  [set plot_count  5]
     if plot_count = 3  [set plot_count  4]
     if plot_count = 2  [set plot_count  3]
     if plot_count = 1  [set plot_count  2]
     if mydata = "PLOT" [set plot_count  1]
     if plot_count = 1  [output-print mydata]

     if pen_count = 2
      [if mydata != "" [
         test-use-csv
         ifelse use-csv?
          [ find-dq
            set mydata-list  (csv:from-row mydata " ")
            revert-dq 0
            revert-dq 5
            revert-dq 6
            output-print word "Name: " item 0 mydata-list
            output-print word " setup:  " item 5 mydata-list
            output-print word " update: " item 6 mydata-list
            ]
          [ output-print word "Name-setup-update: " mydata]
          ]
        if mydata = ""  [set pen_count  0]
       ]
     if mydata = "PENS"[set pen_count  1]
     if pen_count = 1  [output-print mydata]
     if pen_count = 1  [set pen_count  2]

  ] ; end of if first_block = 1


 ;file-read-line skips everything until this next line is true
 if first_block = 0 and mydata = netlogo-delimiter
      [ set first_block  1 ]
  tick
  ] ; end while [first_block < 2]
end 

to test-use-csv
  set use-csv? true
  ; false only if "@@" in the original
  let at-at? position "@@" mydata
  if is-number? at-at? [set use-csv? false]
end 

to find-dq
  ; one string
  ; use @@ as the substitute, hopefully available
  ; if it already contains @@, then don't use csv:from-row
  let more-loops? true
  while [more-loops?]
  [
    let pos1 position "\\\"" mydata ; that finds \", all or nothing
    ifelse is-number? pos1  ; found pattern
      [  set mydata replace-item pos1 mydata "@"
         set mydata replace-item (pos1 + 1) mydata "@" ]
      [  set more-loops? false]
   ]
end 

to revert-dq [myitem-number]
  ; this had to be done for each item Pens 0, 5, 6, Plots 0, 1
  let more-loops? true
  while [more-loops?]
  [
    let myitem-val item myitem-number mydata-list
    let pos1 position "@@" myitem-val
    ifelse is-number? pos1  ; found pattern
      [
        let pos2 pos1 + 1
        set myitem-val replace-item pos1 myitem-val "\\"
        set myitem-val replace-item pos2 myitem-val "\""
        set mydata-list replace-item myitem-number mydata-list myitem-val
        ]
      [ set more-loops? false ]
   ]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Doug Edmunds almost 8 years ago Improve file opening Download this version
Doug Edmunds almost 8 years ago For NetLogo 6.0 and higher Download this version
Doug Edmunds almost 8 years ago Initial upload Download this version

Attached files

File Type Description Last updated
nivi (netlogo interface variables info).png preview Preview for 'nivi (netlogo interface variables info)' almost 8 years ago, by Doug Edmunds Download

This model does not have any ancestors.

This model does not have any descendants.