Loading ...
Sorry, an error occurred while loading the content.

RV: James help me with a process please

Expand Messages
  • MAGALY DE LOS ANGELES ABAD ESCUDERO
    Nota: mensaje reenviado como archivo adjunto. ... Correo Yahoo! Comprueba qué es nuevo, aquí http://correo.yahoo.es Nota: mensaje reenviado como archivo
    Message 1 of 3 , Nov 30, 2005
    • 0 Attachment


      Nota: mensaje reenviado como archivo adjunto.



      Correo Yahoo!
      Comprueba qué es nuevo, aquí
      http://correo.yahoo.es
    • James Steiner
      You must write the values to the file in the format called CSV Comma Seperated Values . Excel can read CSV file correctly. Example CSV Format: Item1 ,
      Message 2 of 3 , Dec 1, 2005
      • 0 Attachment
        You must write the values to the file in the format called "CSV"
        "Comma Seperated Values". Excel can read CSV file correctly.

        Example CSV Format:

        "Item1", "Item2", "Item3", "Item4"
        45, 23, 45, 0
        12, 2, 2, 3

        I guess that variable No is a list, so, the list must be combined into
        a string, with the numbers having commas between:

        Example:

        to-report split [ a-list ]
        let result ""
        ifelse is-list? a-list
        [ ifelse length a-list = 0
        [ ;; list is empty
        set result "" ;; empty result
        ][
        ifelse length a-list = 1
        [ set result format first a-list
        ][


        let result reduce [ ?1 + ", " + format ?2 ] a-list
        go
        ....
        ....


        On 11/30/05, MAGALY DE LOS ANGELES ABAD ESCUDERO <abadescudero@...> wrote:
        >
        >
        >
        > Nota: mensaje reenviado como archivo adjunto.
        >
        > ________________________________
        >
        > Correo Yahoo!
        > Comprueba qué es nuevo, aquí
        > http://correo.yahoo.es
        >
        > ________________________________
        > YAHOO! GROUPS LINKS
        >
        >
        > Visit your group "netlogo-users" on the web.
        >
        > To unsubscribe from this group, send an email to:
        > netlogo-users-unsubscribe@yahoogroups.com
        >
        > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
        >
        > ________________________________
        >
        >
        >
        >
        > ---------- Forwarded message ----------
        > From: MAGALY DE LOS ANGELES ABAD ESCUDERO <abadescudero@...>
        > To: James.Steiner@yahoogroups.com
        > Date: Tue, 29 Nov 2005 17:04:58 +0100 (CET)
        > Subject: Files in Netlogo
        >
        >
        > Hello, James please you could help me with something. I need to obtain some
        > data in excel from netlogo, I am working with files and I am not able to use
        > the file-read but or fewer are this what I want to make:
        > I have to send the following values:
        > Value 100 80 70 60
        >
        > until there shipment without any problem now wants that the values that they
        > are generated in a monitor they are placed under each value this way:
        > Value 100 80 70 60
        > nº 2 5 40 4
        > 8 10 5 16
        > ..... .... .... ....
        >
        > now what generates me the slider is the variable nº the problem is as
        > making so that they are gone placing the numbers (2,5,40,4, etc)debajo of
        > each value like I use files in netlogo that interactuen with one excel leaf.
        >
        > If it was so kind of helping I need to end a I model and this process stops
        > me.
        > He will be to their help very grateful.
        > Greetings
        > MAGALY
        >
        > NOTA: I attach him an excel leaf so that she/he observes as
        > the data are sent from the program.
        >
        > ________________________________
        >
        > Correo Yahoo!
        > Comprueba qué es nuevo, aquí
        > http://correo.yahoo.es
        >
        >
        >
        >


        --
        ~~James
        _____________________________________
        turtlezero.com -- its turtles, all the way down!
      • James Steiner
        MY prior response was, obviously, incomplete. Sorry. Here s a more complete sample. Note that this is slower than it could be (but pretty much fast enough)
        Message 3 of 3 , Dec 1, 2005
        • 0 Attachment
          MY prior response was, obviously, incomplete. Sorry.

          Here's a more complete sample. Note that this is slower than it could
          be (but pretty much fast enough) because it opens and closes the file
          to write each line. It would be faster to store the lines (perhaps in
          another list) then write them out in chunks.

          globals
          [ filename ]

          to-report csv-format [ a-list ]
          let result ""
          ifelse is-list? a-list
          [ ifelse length a-list = 0
          [ ;; list is empty
          set result "" ;; empty result
          ][
          ifelse length a-list = 1
          [ ;; only one item, report it
          ;; (add quotes if not a number)
          set result quote first a-list
          ][
          ;; more than one, quote each item, comma separate.
          set result reduce [ (word ?1 ", " ?2) ] (map [ quote ? ] a-list )
          ]]]
          [ ;; input is not a list,
          ;; so just quote the input
          set result quote a-list
          ]
          report result
          end

          to-report quote [ a-string ]
          ;; reports a-string with quotes, unless a-string is a number
          ifelse is-number? a-string
          [ report (word a-string) ]
          [ report (word "\"" a-string "\"" ) ]
          end

          to-report append-to-file [ line file]
          ;; opens filename, prints line to end of file, closes file
          ;; if file does not exist, creates a new file
          ;; reports TRUE if no errors, FALSE if any errors
          let success true
          carefully
          [ file-open file
          file-print line
          file-close
          ]
          [ set success false ]
          report success
          end

          to file-reset [ file ]
          carefully
          [ if file-exists? file
          [ file-delete file ]
          ]
          []
          end

          to quick-append [ string ]
          ;; wrapper for append-to-file uses global filename, interprets error message
          ;; writes formatted string to global file, prints message in output window
          ;; if any error occurs
          if append-to-file (csv-format string) filename = false
          [ output-print "Error writing to file.." ]
          end

          to setup
          ;; always uses same file name
          ;; to use different filenames automatically,
          ;; need a procedure to generate new / unique names
          ;; filename is a global variable
          set filename "datafile.csv"

          let column-names [ "item1" "item2" "item3" "item4" ]
          ;; delete filename
          file-reset filename
          quick-append column-names
          end

          to go
          let no []
          ;;; ... blah blah blah...
          ;; results in No containing a list
          ;; DEMONSTRATION:
          ;; write 40 rows of 4 columns of random integers
          repeat 40
          [ set no n-values 4 [ random 100 ]
          output-print no
          quick-append no
          ]
          end
        Your message has been successfully submitted and would be delivered to recipients shortly.