Trouble with a simple sequence


RDD

Recommended Posts

This is a test sequence for moving a time/temperature array (Profile) into an array (PrfTrace) to be used in graphing the profile.  However, I get an error message (C1086) at line 7.

These first declarations are in the Startup sequence:

global Profile[12,3] = {{3,95,2},{4,120,3},{2,129,3},{5,90,1}}
global TmpStart = 82
global PrfTrace[12,2]

 

Sequence: SetProfileValues:


private ElapseTime = 0
private cnt = (2*Steps)+1
PrfTrace[0][0] = TmpStart
PrfTrace[0][1] = 20
for(private i=1, i<cnt, i=i+2)
   PrfTrace[i][0] = Profile[i-1][1]
   ElapseTime = ElapseTime + Profile[i-1][0]
   PrfTrace[i][1] = ElapseTime   
   PrfTrace[i+1][0] = Profile[i-1][1]
   ElapseTime = ElapseTime + Profile[i-1][2]
   PrfTrace[i+1][1] = ElapseTime
endfor

Link to comment
Share on other sites

The problem is that your declarations are wrong.  DAQFactory doesn't declare arrays like C.  They are fully dynamic and so you don't have to specify the size when declaring.  So:

global prfTrace[12,2]

is invalid, and just creates a variable prfTrace with no contents.  It does NOT create an 12x2 array full of 0's and so, until you actually assign values to the array, you can't access it.  Your issue is in profile, which you declare as profile[12,3] but then only initialize the first 4 rows.  You are assuming because you did [12,3] that the extra 8 rows are all 0's, but they aren't.  They don't exist, so when you get into your loop and get past the first 4 rows, it fails because there is no data available.

You have two choices and can implement both:

1) this applies across many languages: when iterating through an array, don't count to a constant, count to the size of the array.  So, in your case, instead of iterating to cnt, you should iterate to numrows(profile).  Then it won't matter what you initialized the array to, the loop won't go past the end of the array.

2) you can easily initialize an array with 0's by initializing the last element.  So:

global Profile = {{3,95,2},{4,120,3},{2,129,3},{5,90,1}}
profile[11,2] = 0

global PrfTrace
prfTrace[11,1] = 0

 

Link to comment
Share on other sites

I think I made the changes you suggested as shown below.  I'm still getting error C1086 at line 7

Startup sequence:

// set Global Variables
global TmpMax = 140
global TmpMin = 80
global TmpStart = 82
global PrfTrace
global Profile
Profile = {{3,95,2},{4,120,3},{2,129,3},{5,90,1}}

 

SetProfileValues sequence:

private ElapseTime = 0
private cnt = (2 * (NumRows(Profile))) + 1
PrfTrace[0][0] = TmpStart
PrfTrace[0][1] = 0
for(private i = 1, i < cnt, i = i+2)
   PrfTrace[i][0] = Profile[i-1][1]
   ElapseTime = ElapseTime + Profile[i-1][0]
   PrfTrace[i][1] = ElapseTime   
   PrfTrace[i+1][0] = Profile[i-1][1]
   ElapseTime = ElapseTime + Profile[i-1][2]
   PrfTrace[i+1][1] = ElapseTime
endfor

Link to comment
Share on other sites

No, you didn't.  You are still iterating to cnt, which is not the same as numrows(profile).  It is twice that plus 1, so, despite the -1 in the loop when you use profile, you are still iterating way past the number of rows in profile, which is causing the error.

Link to comment
Share on other sites

I see what your saying.  My rework, as shown below, still yields a C1070 error at line 3.  I'm guessing I still have an initialization issue.

Startup:

global TmpStart = 82
global PrfTrace
PrfTrace[11][1] = 0
global Profile
Profile = {{3,95,2},{4,120,3},{2,129,3},{5,90,1}}

Setup 2-column array from a 3-column array:

private ElapseTime = 0
for(private i = 0, i < NumRows(Profile), i++)
   if(i = 0)
      PrfTrace[0][0] = 0
      PrfTrace[0][1] = TmpStart
   endif
   ElapseTime = ElapseTime + Profile[i][0]
   PrfTrace[(2*i)+1][0] = ElapseTime
   PrfTrace[(2*i)+1][1] = Profile[i][1]
   ElapseTime = ElapseTime + Profile[i][2]
   PrfTrace[(2*i)+2][0] = ElapseTime   
   PrfTrace[(2*i)+2][1] = Profile[i][1]
endfor

Link to comment
Share on other sites

OK, now your problem is line 3 (as indicated).  DAQFactory, like C, JavaScript and really most languages uses one operator for assignment (=) and one for comparison (==).  C and JavaScript and others use these exact operators.  Others, like Pascal, use := for assignment and = for comparison.

Anyhow, unlike C, you can't do assignment inside an if() statement.

Three other things:

1) I would do the assignment for i=0 outside the loop to make the loop run faster, similar to how you did it the first time.  It is negligible in this case since the loop only iterates 4 times, but in larger loops, the if() evaluation would get expensive.

2) You can do the assignment of profile in the declaration like you had before.  The issue was the []'s in the declaration, not that you did the assignment.

 

Link to comment
Share on other sites

Bingo!  It finally works.  Thank you.  Below is the cleaned up sequence that works and the if() removed from the for() loop. 

Question:  As with PrfTrace here, does PrfTrace need to be initialized before it can be populated in other sequences, or can it just be declared and populated later?

 

Startup:

global TmpStart = 82
global PrfTrace
PrfTrace[11][1] = 0
global Profile
Profile = {{3,95,2},{4,120,3},{2,129,3},{5,90,1}}

SetValues sequence:

private ElapseTime = 0
PrfTrace[0][0] = 0
PrfTrace[0][1] = TmpStart
for(private i = 0, i < NumRows(Profile), i++)
   ElapseTime = ElapseTime + Profile[i][0]
   PrfTrace[(2*i)+1][0] = ElapseTime
   PrfTrace[(2*i)+1][1] = Profile[i][1]
   ElapseTime = ElapseTime + Profile[i][2]
   PrfTrace[(2*i)+2][0] = ElapseTime   
   PrfTrace[(2*i)+2][1] = Profile[i][1]
endfor

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.