program root_example

! this program is written is pseudo code
! it creates a vector of 10 sine values over a given range 
! then makes a plot of the square root of each value.

! * * * first we do variable and parameter definitions * * * * * * * * 

integer size=10                          ! size of array 
real start, stop                         ! range of data   
real data_array[size], root_array[size]  ! allocate memory for arrays 

! * * * *  now we go to each step in the process * * * * * * * * **

! 1. 'input_range': a subroutine in which the user inputs data range  
! 2. 'make_data'  : a function to create sine data from which to extract root
! 3. 'trim_data'  : a function to trim out negative
! 4. extract the square root using the standard 'sqrt' function
! 5. use a packaged subroutine to plot the data

! normally after mapping out the program flow with comments, you would
! write the specific commands after each comment, but to show the terse
! clarity of a properly designed main program, we have separated the commands
! from the comments.  Note how the variables are passed between program blocks.

call input_range(start, stop)                 

data_array = make_data(start, stop, size)     

data_array = trim_data(data_array, size)      

root_array = sqrt(data_array)                

call plot(root_array)	                      

end

*********************** input subroutine ******************************

subroutine input_range( start,stop )
! manual input of starting and stopping range of data

real pi = 3.1416   
real start,stop

!The user enters the endpoints
prompt, 'start value? (degrees)', start
prompt, 'end value? (degrees)', stop

! convert to radians
start = start*pi/180
stop = stop*pi/180   

end

********************** data creation function ************************

function make_data( start,stop,size )

! this function creates an array based on the starting and stopping
! values that were input. 'x' values are incremented from the starting
! to the stopping point, then 'y' output values are created by operating
! on the 'x' values with the sin function.

integer count                    ! no need to define start,stop,size because
real increment, data_array[size] ! they are being passed to this function

increment = (stop-start)/size

! create array of sin values with x from start to stop
for count = 1 to size
    data_array[count] = sin(count*increment) 
endfor

return data_array

end
******************* trim function ************************************

function trim_data( size,data_array )

! this function sets values below zero equal to zero

integer count

for count = 1 to size
    if (data_array[count] < 0) then data_array[count] = 0
endfor

return data_array

end