[TRNSYS-users] Read Write function

thornton at tess-inc.com thornton at tess-inc.com
Wed Nov 23 09:43:48 PST 2022


On 2022-11-23 02:54, Gehad Azmy via TRNSYS-users wrote:

> Good morning I'm working on making a new component and I have a
> problem in understanding Read Function, Now I calculate some variables
> which will be used in the second iteration as inputs, so I make a Read
> Function
> j=100
> If  (current_time_step > 1) Then
>   open(109, file = 'm_new.dat', status='old')
>   Do i = j,0
>       start_element=(0.5*(i**2-i))+1
>       end_element=start_element+(i-1)
>       Read(109,*)  m_pb(start_element:end_element)
> 
> end do
> the function is working well, what I do not understand is, how does
> the do loop work from 100 to 0? And when I reverse it from 0 to 100,
> or from 1 to 100, it doesn't read anything.

I would add "End =" and "Err =" checks to your read statement as a first 
step and an "Err =" to your open statement.  I'm also guessing that the 
program is struggling to take i**2 when i = 0.  Typically the DO 
statement is of the form Do i,j,k  where i is the starting integer, j is 
the end integer and k is the integer step.  So to go from 100 to 0 it 
would be:

Do 100,0,-1
.
.
EndDo

Jeff

> _______________________________________________
> TRNSYS-users mailing list
> TRNSYS-users at lists.onebuilding.org
> http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org

-- 
----
Jeff Thornton
President
Thermal Energy System Specialists (TESS)
3 N. Pinckney Street - Suite 202
Madison WI 53703
(608) 274-2577
www.tess-inc.com


More information about the TRNSYS-users mailing list