[Lazarus] RE : reading FORTRAN-style input in Lazarus

David M. Lawrence dave at fuzzo.com
Sat Aug 6 07:51:05 CEST 2011


On 8/5/2011 7:43 AM, Ludo Brands wrote:
>> For example, here's a FORTRAN format I need to emulate: 
>> FORMAT(I3,I7,2X,A25,1X,F6.2,1X,F7.2,3(1X,I4),1X,F4.1,1X,I1) On a 
>> single line, I begin with two integer variables, skip two spaces, one 
>> string variable, one space followed by a real variable, skip a space, 
>> etc. I know of examples that involve treating each line as a 
>> character array, but I cannot find them now. I also know how to 
>> specify write formats, but have seen no examples of applying that to 
>> reading lines. 
> Another approach: Function eatchars(var s:string; i:integer):string; 
> Begin Result:=copy(s,1,i); Delete(s,1,i); End; ... Readln(line); 
> i1:=StrToInt(eatchars(line,3)); //I3 i2:=StrToInt(eatchars(line,7)); 
> //I7 eatchars(line,2); //X2 s1:=eatchars(line,25); //A25 
> eatchars(line,1); //X1 r1:=StrToFloat(eatchars(line,7); //F6.2 
> eatchars(line,1); //X1 r2:=StrToFloat(eatchars(line,8); //F7.2 
> eatchars(line,1); //X1 i3:=StrToInt(eatchars(line,4); //I4 etc... Ludo

For the record, this solution worked and is the one I've implemented in 
my code.

Later,

Dave

-- 
------------------------------------------------------
  David M. Lawrence        | Home:  (804) 559-9786
  7471 Brook Way Court     | Fax:   (804) 559-9787
  Mechanicsville, VA 23111 | Email: dave at fuzzo.com
  USA                      | http:  http://fuzzo.com
------------------------------------------------------

"All drains lead to the ocean."  -- Gill, Finding Nemo

"We have met the enemy and he is us."  -- Pogo

"No trespassing
  4/17 of a haiku"  --  Richard Brautigan





More information about the Lazarus mailing list