Ada: escribir en archivos dentro de una declaración de bloque
Estoy tratando con una matriz cuya longitud se determina durante la ejecución del programa. Así que estoy haciendo uso de unblock
Declaración en la que puedo establecer los límites de la matriz.
Tengo problemas para escribir los elementos de la matriz en un archivoComo estaba usando un talón para el procedimiento de escritura. Quité el talón para tener todo en el mismo código. Aunque ahora mi códigocompila y corre, no se está escribiendo en el archivo. Aquí está el código:
<code>with Ada.Float_Text_IO; with Ada.Integer_Text_IO; with Ada.Text_IO; procedure Compute_Parameters is Spin_Speed, Whirling_Speed : Float; Time_Step, Rotor_Revolutions : Float; Number_Of_Steps : Float; begin Ada.Text_IO.Put("Enter the spin speed "); Ada.Float_Text_IO.Get (Item => Spin_Speed); Ada.Text_IO.New_Line (1); Ada.Text_IO.Put("Enter the whirling speed "); Ada.Float_Text_IO.Get (Item => Whirling_Speed); Ada.Text_IO.New_Line (1); Ada.Text_IO.Put("Enter the time step "); Ada.Float_Text_IO.Get (Item => Time_Step); Ada.Text_IO.New_Line (1); Ada.Text_IO.Put("Enter the number of revolutions of the rotor "); Ada.Float_Text_IO.Get (Item => Rotor_Revolutions); Number_Of_Steps := (360.0 / (Time_Step * Whirling_Speed)) * Rotor_Revolutions * (Whirling_Speed / Spin_Speed); declare type Vector is array (Integer range <>) of Float; Time_Vector : Vector (1 .. Integer (Float'Truncation (Number_Of_Steps)) + 1); Rotor_Position_Degrees : Vector (1 .. Integer (Float'Truncation (Number_Of_Steps)) + 1); Count : Integer := 0; Start : Float := 0.0; Step : Float := Time_Step; Output_Data_File : File_Type; procedure Write_Files (Output_File : File_Type; Out_1 : Integer; Out_2 : Float; Prec : Natural := 5 ) is begin Ada.Integer_Text_IO.Put (File => Output_File, Item => Out_1); Ada.Text_IO.Put (Output_File, " "); Ada.Float_Text_IO.Put (File => Output_File, Item => Out_2, Fore => 6, Aft => Prec, Exp => 0); Ada.Text_IO.New_Line (Output_File); end Write_Files; begin -- begin of Declare Ada.Text_IO.Put ("Put file name to write: "); Create (Output_Data_File, Out_File, Get_Line); for I in 1 .. Time_Vector'Length loop Count := Count + 1; Time_Vector(I) := Start + Step * Float(I-1); Put (Integer'Image(Count)); Ada.Text_IO.Put(" "); Rotor_Position_Degrees(I) := Spin_Speed * Time_Step * Float(I-1); Ada.Float_Text_IO.Put (Item => Rotor_Position_Degrees(I), Fore => 5, Aft => 1, Exp => 0); Ada.Text_IO.New_Line(1); --write to file Write_Files (Output_Data_File, Out_1 => Count, Out_2 => Rotor_Position_Degrees(I) ); end loop; close(Output_Data_File); end; -- end of Declare end Compute_Parameters; </code>
Me doy cuenta de que las 2 líneas justo después.begin
enDeclare
no se están ejecutando en absoluto:
<code>Ada.Text_IO.Put ("Put file name to write: "); Create (Output_Data_File, Out_File, Get_Line); </code>
¿Qué estoy haciendo mal?
Gracias...