Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




 
   max_value = MAX( -123,  234.56, 345.678, -456E3, -455) ! built-in function MAX(...)
 
! or for an array:
   max_value = MAX( array_of_values )
 
! or to find a maximum value in a file named filename:
   CHARACTER List, filename='Greatest element of a list.hic' ! filename contains this script
   REAL values(1) ! unknown number of values, allocate more below
 
   OPEN(FIle=filename, BINary, LENgth=len)
   ALLOCATE(values, len/2) ! number of values <= half byte count of file
   ! read all values, returns item count in values_found:
   READ(FIle=filename, ItemS=values_found, CLoSe=1) values ! no Format needed for plain text numbers
 
   max_value = MAX(values)
 
   ! write values found in filename and result to spreadsheet type dialog window:
   DLG(Text=values, Text=max_value, TItle=values_found)
 
   WRITE(ClipBoard, Name) max_value, values_found, values ! pasted to line below
   ! max_value=345.678; values_found=30; values(1)=-123; values(2)=234.56; values(3)=345.678; values(4)=-456E3; values(5)=-455; values(6)=1; values(7)=2; values(8)=1; values(9)=0; values(10)=0; ...truncated
 END
 