File Output Example

File Output Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 2047 times • Downloaded 137 times • Run 0 times
Download the 'File Output Example' modelDownload this modelEmbed this model

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


Comments and Questions

Click to Run Model

turtles-own [ value ]     ;; This is some phony turtle variable

;; This procedure creates 15 random turtles and opens a file dictated
;; by the user.  It will erase any pre-existing file.

to setup
  clear-all
  crt 15
  [
    setxy random-xcor random-ycor
    set value 5
  ]
  let file user-new-file
  ;; We check to make sure we actually got a string just in case
  ;; the user hits the cancel button.
  if is-string? file
  [
    ;; If the file already exists, we begin by deleting it, otherwise
    ;; new data would be appended to the old contents.
    if file-exists? file
      [ file-delete file ]
    file-open file
    ;; record the initial turtle data
    write-to-file
  ]
end 

;; This procedure makes the turtles move randomly.  It also changes their internal
;; variable by random +/- 1.  We report the patch coordinates and their internal variable
;; to the file.  To view the file, hit the file-close button and open it with a text
;; editor.

to go
  ask turtles
  [
    lt random 360
    fd 1 + random 4
    set value value + random 3
  ]
  tick
  write-to-file
end 

to write-to-file
  file-print (word "---------- Tick Number: " ticks "-----------")
  ;; use SORT so the turtles print their data in order by who number,
  ;; rather than in random order
  foreach sort turtles [
    ask ? [
      file-print (word self ": pxcor: " pxcor " pycor: " pycor " value: " value)
    ]
  ]
  file-print ""  ;; blank line
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago File Output Example Download this version
Uri Wilensky almost 14 years ago File Output Example Download this version

Attached files

File Type Description Last updated
File Output Example.png preview Preview for 'File Output Example' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.