Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
storing data in csv
#1
THIS IS THE ORIGANL:

10 CLS:KEY OFF
60 BA = 1016:REM BA = COM ADDRESS
70 TM = TIMER: IF TM > 86370! THEN 70:REM MIDNIGHT TRAP
80 F1 = 0: F2 = 0
90 OUT (BA + 4), 1 + M
100 TM = TIMER: WHILE TIMER < TM + 2: WEND
110 LOCATE 5,6: PRINT "READ TEMPERATURES "
120 OUT BA + 3, 0: TM1 = TIMER: TM2 = TIMER
130 OUT BA + 3, 64
140 IF F1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN F1 = 1: P1 = TIMER - TM1
150 IF F2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN F2 = 1: P2 = TIMER - TM2
160 IF F1 <> 1 OR F2<> 1 THEN 140
170 P1 = P1 * 100: P2 = P2 * 100
180 LOCATE 8,5: PRINT USING "PERIOD (1) = ###.## SECONDS; P1 / 100
190 T1 = 522 - 88.6299 * LOG(P1) + 3.0209 * LOG(P1) ^ 2
200 LOCATE 10, 7TongueRINT USING "TEMP (1) = ###.#"; T1
210 LOCATE 13,5: PRINT USING "PERIOD (2) = ###.## SECONDS; P2 / 100
220 T2 = 522 - 88.6299 * LOG(P2) + 3.0209 * LOG(P2) ^ 2
230 LOCATE 15, 7TongueRINT USING "TEMP (2) = ###.#"; T2
240 LOCATE 5, 6: PRINT "END READ TEMP"


What I am looking for is a mod for the code that would track the temp by time and date in time intravls that could be change say five minutes for now. i would like to save the values to a csv file with the values being date time temp1 and temp2. I am good with hardware but my coding is weak any suggestions would be great thanks.

Smaug
Reply
#2
a simple text file with commas in between items on each line? I assume you want to write the same stuff to the file that you're now writing to the screen. First, get rid of your LOCATE statements. Then, before you go to output anything to the file, open the file:

OPEN "MYFILE.CSV" FOR OUTPUT AS #1

Then, get rid of the LOCATE statements and change your "PRINT ... " statements (or PRINT USING statements) to

WRITE#1, ...

where "..." simply refers to the list of stuff you want written to a single line in your file. When you're all done, do

CLOSE #1
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
That sounds perfect. I am leaving the print lines in for now for debugging.


10 CLS:KEY OFF
60 BA = 1016:REM BA = COM ADDRESS
70 TM = TIMER: IF TM > 86370! THEN 70:REM MIDNIGHT TRAP
80 F1 = 0: F2 = 0
90 OUT (BA + 4), 1 + M
100 TM = TIMER: WHILE TIMER < TM + 2: WEND
110 PRINT "READ TEMPERATURES "
120 OUT BA + 3, 0: TM1 = TIMER: TM2 = TIMER
130 OUT BA + 3, 64
140 IF F1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN F1 = 1: P1 = TIMER - TM1
150 IF F2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN F2 = 1: P2 = TIMER - TM2
160 IF F1 <> 1 OR F2<> 1 THEN 140
170 P1 = P1 * 100: P2 = P2 * 100
180 PRINT USING "PERIOD (1) = ###.## SECONDS; P1 / 100
190 T1 = 522 - 88.6299 * LOG(P1) + 3.0209 * LOG(P1) ^ 2
200 PRINT USING "TEMP (1) = ###.#"; T1
210 PRINT USING "PERIOD (2) = ###.## SECONDS; P2 / 100
220 T2 = 522 - 88.6299 * LOG(P2) + 3.0209 * LOG(P2) ^ 2
230 PRINT USING "TEMP (2) = ###.#"; T2
240 OPEN "TEST.CSV" FOR OUTPUT #1
250 WRITE #1, DATE$, TIME$, T1, T2
260 CLOSE #1

How does that look?

How should i go about a time comparision so that i am only getting the data in time frames that i want? I would like a varible that could be changed.

I want to say thanks I am sure this stuff seems like simple questions to you but I am stumped.

Smaug
Reply
#4
1) If you must have lines, make them 1, 2, 3.. etc. not 10 20 30.
2) Use ' instead of REM.
3) Use lowercase variables. That way they stand out from the functions.
EDIT

Code:
CLS: KEY OFF
ba = 1016 'ba = com address.
redo1: tm = TIMER: IF tm > 86370! THEN goto redo1 'Midnight trap.
f1 = 0: f2 = 0
OUT (BA + 4), 1 + M
tm = TIMER + 2: WHILE TIMER < tm: WEND
PRINT "Read Temperatures: "
OUT ba + 3, 0: tm1 = TIMER: tm2 = TIMER: OUT ba + 3, 64

redo2:
IF f1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN f1 = 1: p1 = TIMER - tm1
IF f2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN f2 = 1: p2 = TIMER - tm2
IF f1 <> 1 OR f2 <> 1 then goto redo2

p1 = p1 * 100: p2 = p2 * 100
t1 = 522 - 88.6299 * LOG(p1) + 3.0209 * LOG(p1) ^ 2
t2 = 522 - 88.6299 * LOG(p2) + 3.0209 * LOG(p2) ^ 2

PRINT USING "Period (1) = ###.## seconds."; p1 / 100
PRINT USING "Temp (1) = ###.## celcius."; t1
PRINT USING "Period (2) = ###.## seconds."; p2 / 100
PRINT USING "Temp (2) = ###.## celcius."; t2

OPEN "test.csv" FOR OUTPUT as #1: WRITE #1, DATE$, TIME$, t1, t2: CLOSE #1
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
If you did, you'd know the really obvious reason why contiguous line numbers are a REAL bad idea. (Think about the concept of *insertion*.) Smile As for the rest, that's *his* business too.


Quote:1) If you must have lines, make them 1, 2, 3.. etc. not 10 20 30.
2) Use ' instead of REM.
3) Use lowercase variables. That way they stand out from the functions.
EDIT

[
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#6
you could use TIMER, e.g.,

TESTTIME = TIMER
IF LOWTIME <= TESTTIME AND TESTTIME <= HIGHTIME THEN do whatever

Or you can use the MID$ and VAL functions to pull the hours, minutes, and seconds out of TIME$ (and the month, day, and year out of DATE$) and test against those.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#7
i am not sure how to go about adding the timer.
Quote:Here's one way to get the timer to look more "clock-like":

Code:
CLS
DO
  t = INT(TIMER)
  th = INT(t / 3600)
  tm = INT((t - (th * 3600)) / 60)
  ts = INT(t - ((th * 3600) + (tm * 60)))
  hours$ = RIGHT$(STR$(th), 2)
  minutes$ = RIGHT$(STR$(tm), 2)
  seconds$ = RIGHT$(STR$(ts), 2)
  LOCATE 6, 4: PRINT USING "&:&:&";hours$ ;minutes$ ;seconds$
  LOCATE 8, 4: PRINT "Hit any key to continue . . ."
LOOP UNTIL INKEY$ <> ""
END

Modify it however fits your needs.

Dex

could i use something like this and subtract 5 from the minutes and then do a if x = 0 or x = 5 then write the data to the file. I would cut the code that i dont need of course. An the reason the code has line numbers is that is the way it was written. I just copied it the way it was. I do think that if you use them then you should leave space for modifaction and adding code for an easier reading.

Thanks agian
Smaug
Reply
#8
Quote:If you did, you'd know the really obvious reason why contiguous line numbers are a REAL bad idea. (Think about the concept of *insertion*.) Smile As for the rest, that's *his* business too.


Agamemnus Wrote:1) If you must have lines, make them 1, 2, 3.. etc. not 10 20 30.
2) Use ' instead of REM.
3) Use lowercase variables. That way they stand out from the functions.
EDIT

[

Yeah. When you code in GWBASIC or BASICA, where there is no a real editor, you can't simply edit your text and insert a new line. If you use 1, 2, 3, 4... How do you add a line between 1 and 2?

And... Why did you suggest use 1,2,3 and not 10,20,30??? I'm still wondering... What's the mysterious reason? Big Grin
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#9
Code:
1.1 PRINT "Hi."

Quote:I just copied it the way it was.

Yes, that's the way that you do it so that you don't get bugs.

Hm... now the time problem. Do you mean you want to measure it more than once, based on some variable time period?

EDIT:

I think I figured it out. Instead of doing "tm = TIMER + 2" make it "tm = TIMER + dt".

Code:
CLS: KEY OFF
dt = 4
ba = 1016 'ba = com address.
redo1: tm = TIMER: IF tm > 86370! THEN goto redo1 'Midnight trap.
f1 = 0: f2 = 0
OUT (BA + 4), 1 + M
tm = TIMER + dt: WHILE TIMER < tm: WEND
PRINT "Read Temperatures: "
OUT ba + 3, 0: tm1 = TIMER: tm2 = TIMER: OUT ba + 3, 64

redo2:
IF f1 = 0 AND (INP(BA + 6) AND 128) = 0 THEN f1 = 1: p1 = TIMER - tm1
IF f2 = 0 AND (INP(BA + 6) AND 32) = 0 THEN f2 = 1: p2 = TIMER - tm2
IF f1 <> 1 OR f2 <> 1 then goto redo2

p1 = p1 * 100: p2 = p2 * 100
t1 = 522 - 88.6299 * LOG(p1) + 3.0209 * LOG(p1) ^ 2
t2 = 522 - 88.6299 * LOG(p2) + 3.0209 * LOG(p2) ^ 2

PRINT USING "Period (1) = ###.## seconds."; p1 / 100
PRINT USING "Temp (1) = ###.## celcius."; t1
PRINT USING "Period (2) = ###.## seconds."; p2 / 100
PRINT USING "Temp (2) = ###.## celcius."; t2

OPEN "test.csv" FOR OUTPUT as #1: WRITE #1, DATE$, TIME$, t1, t2: CLOSE #1
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
(Learn to count by 10s. You'll be amazed at what the mental exercise does for your programming abilities.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)