Staff Answer
Jul 27, 2016 - 04:40 AM
Hello Tuan,
There are a few issues with the code. You can populate the arrays in the BEGIN section, but then you have some other issues (for example, you should use IUNIT, instead of manually assigning a number. This cannot be done in the BEGIN section). So I moved all the code to the main loop and used TIMEZERO instead. You also had some mistakes in properly allocating the storage and advancing the pointers (If you do use the RTCI and RTCF storage arrays in the BEGIN section, you need to advance these in both the BEGIN section as well as the main loop). Here is what the working code looks like:
#LOCAL INTEGER k
#LOCAL INTEGER m
#LOCAL INTEGER nHarm($Nh)
#LOCAL REAL mHarm($Nh)
#STORAGE REAL:$Nh INTEGER:$Nh
if (TIMEZERO) then
OPEN(IUNIT,FILE = "$fname",STATUS = 'OLD',ACTION = 'READ')
do k = 1, $Nh
read(IUNIT,*) STORI(NSTORI + k-1), STORF(NSTORF + k-1)
end do
CLOSE(IUNIT)
end if
do k = 1, $Nh
nHarm(k) = STORI(NSTORI + k-1)
mHarm(k) = STORF(NSTORF + k-1)
end do
$out = 0.0
do k = 1, $Nh
$out = $out + mHarm(k)*sin(nHarm(k)*(TWO_PI*$F_fund)*TIME +($ph*PI_BY180))
end do
NSTORI = NSTORI + $Nh
NSTORF = NSTORF + $Nh
Hope this helps.
Regards,
Mathias
Add New Comment