Recent

Author Topic: SOLVED by Handoko // Help, some OLD code  (Read 6009 times)

juanirias

  • Full Member
  • ***
  • Posts: 100
SOLVED by Handoko // Help, some OLD code
« on: September 17, 2018, 04:50:38 pm »
Hi!

Can some try to get working this codes?

https://celestrak.com/software/vallado/pascal.zip

Specially the testastf.pas & testpas.pas

They are the companion of the Book Fundamentals of Astrodynamics and Applications by David Vallado.

https://www.amazon.com/Fundamentals-Astrodynamics-Applications-Technology-Library/dp/1881883183/ref=sr_1_1?ie=UTF8&qid=1537198516&sr=8-1&keywords=vallado


Regards, JUAN
« Last Edit: September 19, 2018, 07:36:39 pm by juanirias »

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: Help, some OLD code
« Reply #1 on: September 17, 2018, 06:08:33 pm »
This is fairly old-fashioned Pascal code and should compile out of the box. It does not because of lots of syntax errors. Maybe it is some dialect which I don't know - but I fear this code was converted to Pascal from some other language by somebody who never tested what he wrote, it's a shame...

Do you know that astronomical calculations are available for Lazarus via the Online Package Manager in the packages DelphiMoon and SysTools?

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #2 on: September 17, 2018, 07:19:04 pm »
Hi wp !

Thanks for answer.

Attached the files below...

I can get working until example 3-7, but have some troubles with the function CONVTIME specific on the first parameter. ( ConvTime is part os AstTime.pas).

Code: Pascal  [Select][+][-]
  1. PROCEDURE CONVTIME           ( FileN1                                : Str64;
  2.                                Year,Mon,Day,Hr,MIN                   : INTEGER;
  3.                                SEC                                   : EXTENDED;
  4.                                TimeZone                              : INTEGER;
  5.                                TypeUTIn                              : CHAR;
  6.                                VAR DUT1,DAT,xp,yp,UT1,TUT1,JDUT1,UTC,JDUTC,
  7.                                TAI,TT,TTT,JDTT,TDB,TTDB,JDTDB,DDPsi,DDEps,XLOD : EXTENDED;
  8.                                VAR Error                             : Str12   );
  9.  
  10.  


I will review DelphiMoon and SysTools! ( can share a link of the source code, because I'm under Linux...)

Can try to compile the example_3_7.pas ?

I have this error:

Code: Pascal  [Select][+][-]
  1. An unhandled exception occurred at $0000000000425F14:
  2. EInOutError: File not found
  3.   $0000000000425F14
  4.   $000000000040177E
  5.  
  6.  
« Last Edit: September 17, 2018, 07:51:57 pm by juanirias »

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Help, some OLD code
« Reply #3 on: September 17, 2018, 08:09:52 pm »
Hi, I'm not a expert, but your error seems to be a runtime error. And said something about a missing file.
I other waey, you can get more info, and download online package manager from here:
http://wiki.freepascal.org/Online_Package_Manager

/BlueIcaro

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #4 on: September 17, 2018, 08:18:38 pm »
Hi!

I'm have a dude at:

Code: Pascal  [Select][+][-]
  1.         ReadLn( InFile, FileN1 );
  2.  
  3.  

regards, JUAN

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Help, some OLD code
« Reply #5 on: September 17, 2018, 08:34:27 pm »
Hi!

I'm have a dude at:

Code: Pascal  [Select][+][-]
  1.         ReadLn( InFile, FileN1 );
  2.  
  3.  

regards, JUAN

Veo que firmas con un nombre español, en este foro hay una sección en español, quizás allí te sea más fácil exponer tus dudas.

/BlueIcaro

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Help, some OLD code
« Reply #6 on: September 17, 2018, 08:34:41 pm »
Seems like the code needs to be compiled using Turbo Pascal syntax

Code: [Select]
        PROCEDURE TestDAYOFWEEK;
      VAR
         JD : Extended;
         DayW, DAYOFWEEK : INTEGER; // DAYOFWEEK should not be declared here,
                                    //  as it's a function in a another unit

      BEGIN
        ReadLn( InFile, JD );
        WriteLn( OutFile,  JD );

        DayW := DAYOFWEEK  ( JD );

        WriteLn( OutFile, '  Results:' );
        WriteLn( OutFile, DayW );

      END;
compiles fine as:
Code: [Select]
        PROCEDURE TestDAYOFWEEK;
      VAR
         JD : Extended;
         DayW: INTEGER;
      BEGIN
        ReadLn( InFile, JD );
        WriteLn( OutFile,  JD );

        DayW := DAYOFWEEK  ( JD );

        WriteLn( OutFile, '  Results:' );
        WriteLn( OutFile, DayW );

      END;

Was that code SCANNED out of the book?

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #7 on: September 18, 2018, 01:22:14 am »
Thanks for letting me know!

The idea of ask for help here in English is because I'm thinking is more people on English vocabulary than Spanish...

I'm trying to make work the examples of the book from the scratch...

Regards, Juan

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #8 on: September 18, 2018, 09:56:36 pm »
Hi!

I'm under linux, Can figure IF is a permission issue of the OS?
Can try someone to compile under Windows ?

regards, JUAN
« Last Edit: September 18, 2018, 10:43:00 pm by juanirias »

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #9 on: September 18, 2018, 11:47:04 pm »
Today I'm here: Runtime error 103

The error is next to         ReadLn( InFile, FileN1 );   


Code: Pascal  [Select][+][-]
  1. program example_3_7;       (* p.195 *)
  2.    
  3.      
  4. uses asttime,astmath;
  5.  
  6.  
  7. var    
  8.      
  9.      
  10.      
  11.       Year,Mon,Day,Hr,MIN                   : INTEGER;
  12.       SEC                                   : EXTENDED;
  13.       TimeZone                              : INTEGER;
  14.       TypeUTIn                              : CHAR;
  15.       DUT1,DAT,xp,yp,UT1,TUT1,JDUT1,UTC,JDUTC,TDT,TTDT,JDTDT,
  16.       TAI,TT,TTT,JDTT,TDB,TTDB,JDTDB,DDPsi,DDEps,XLOD : EXTENDED;
  17.       Error                                     : Str12   ;
  18.       FileN1,IFileName                                : Str64;
  19.      
  20.       InFile,OutFile : TEXTfile;
  21.  
  22.                            
  23.    
  24. begin  
  25.      
  26.        
  27.         IFileName := 'text.in';
  28.         ASSIGN( InFile,IFileName );
  29.         RESET( InFile );
  30.  
  31.         ASSIGN( OutFile,'text.out');
  32.         Rewrite( OutFile );
  33.      
  34.        
  35.         ReadLn( InFile, Year,Mon,Day,Hr,Min,Sec,TimeZone,TypeUtIn );
  36.         writeln('pudo leer el archivo!');
  37.         writeln('year ',year:4);
  38.         writeln('mon  ',mon:2);
  39.         writeln('day  ',day:2);
  40.         writeln(hr:2,' : ',min:2,' : ',sec:2:2);
  41.        
  42.         Write( OutFile, 'In',Year,Mon,Day,Hr,Min,Sec,TimeZone,TypeUtIn );
  43.  
  44.         ReadLn( InFile, FileN1 );                  
  45.        
  46.         CONVTIME( FileN1,Year,Mon,Day,Hr,MIN,SEC,TimeZone,TypeUTIn , DUT1,DAT,xp,yp,UT1,TUT1,JDUT1,UTC,JDUTC,TAI,TT,TTT,JDTT,TDB,TTDB,JDTDB,DDPsi,DDEps,XLOD,Error);                  
  47.  
  48.         WriteLn( OutFile, '  Results:' );
  49.         WriteLn( OutFile, DUT1,' ',DAT,' ',xp,' ',yp,' ' );
  50.         WriteLn( OutFile, UT1,' ',TUT1,' ',JDUT1,' ',UTC,' ',TAI,' ',tdt );
  51.         WriteLn( OutFile, TTDT,' ',JDTDT,' ',TDB,' ',TTDB,' ',JDTDB );
  52.        
  53.        
  54.        
  55.        
  56.        
  57.        
  58.        
  59.        
  60. end.
  61.  
  62.  
« Last Edit: September 18, 2018, 11:51:22 pm by juanirias »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Help, some OLD code
« Reply #10 on: September 18, 2018, 11:50:06 pm »
Yeah, nice meaningfull variable names  >:D

Bart

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #11 on: September 19, 2018, 06:16:46 pm »
Hi Bart!

The mistake is on
Code: Pascal  [Select][+][-]
  1.         Readln( InFile, FileN1 );
I cannot understand well...

regards, JUAN

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Help, some OLD code
« Reply #12 on: September 19, 2018, 06:29:33 pm »
I tested the code you provided but removing the CONVTIME and the uses clauses. No problem here on my Linux, everything seemed to work correctly. I think the problem should be in the text file not the code.

About the comment by Bart, he just telling you the good practice in coding. Using good names for variables, procedures and functions is very helpful, it will make the code more maintainable and easier to debug.

Maybe you haven't know, one of the notable difference about experienced programmers and novice programmers. Experienced programmers won't use meaningless name for variables. For examples:  DUT1, DAT, xp, yp, UT1, TUT1, JDUT1, UTC, JDUTC, TDT, TTDT, JDTDT, TAI, TT, TTT, JDTT, TDB, TTDB, JDTDB, DDPsi, DDEps, XLOD.

If you have chances, I recommend you to read this book. It explains the things a master/experienced programmer usually do, including why we should choose good/meaningful names:
https://en.wikipedia.org/wiki/Code_Complete
« Last Edit: September 19, 2018, 06:32:16 pm by Handoko »

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: Help, some OLD code
« Reply #13 on: September 19, 2018, 06:36:51 pm »
Thanks for the advice Handoko;
You are right; I'm not a pro... I will try to read the link; I appreciate the message.

The error is next to Readln( InFile, FileN1 )
Can figure or give some clue to fix-it ?

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. //
  4. //                       Individual PROCEDURES
  5. //
  6. //  These subroutines implement each function or procedure using a datafile
  7. //    with the number of each routine to identify which subroutine to use.
  8. //
  9. //  ------------------------------------------------------------------------
  10.  
  11.      PROCEDURE TestConvTime;
  12.       VAR
  13.         Year, Mon, Day, Hr, MIN, TimeZone: INTEGER;
  14.         TypeUTIn:char;
  15.         FileN1:str64;
  16.         Error:str12;
  17.         DUT1,DAT,xp,yp,UT1,TUT1,JDUT1,UTC,JDUTC,TAI,TT,TTT,JDTT,TDB,TTDB,JDTDB,DDPsi,DDEps,XLOD,sec : Extended;
  18.  
  19.       BEGIN
  20.         writeln('adentro del  procedimiento');
  21.        
  22.        
  23.      
  24.        
  25.         Read( InFile, Year,Mon,Day,Hr,Min,Sec,TimeZone,TypeUtIn );
  26.         Write( 'OutFile', ' year ',Year,' month ',Mon,' day ',Day,'  ',Hr,':',Min,':',Sec:2:2,' zone: ',TimeZone,'  ',TypeUtIn,  ' fin ' );
  27.         writeln('***');
  28.  
  29.       //CONVTIME(FileN1,Year,Mon,Day,Hr,MIN,SEC,TimeZone,TypeUTIn,DUT1,DAT, xp, yp, UT1,TUT1, JDUT1, UTC, TAI, TDT, TTDT, JDTDT,TDB,TTDB, JDTDB, Error );
  30.         Readln( InFile, FileN1 );
  31.         CONVTIME(FileN1, Year,Mon,Day,Hr,MIN,SEC,TimeZone,TypeUTIn,  DUT1,DAT,xp,yp,UT1,TUT1,JDUT1,UTC,JDUTC,TAI,TT,TTT,JDTT,TDB,TTDB,JDTDB,DDPsi,DDEps,XLOD,Error);
  32.  
  33.         WriteLn( OutFile, '  Results:' );
  34.         WriteLn( OutFile, DUT1,' ',DAT,' ',xp,' ',yp,' ' );
  35.         WriteLn( OutFile, UT1,' ',TUT1,' ',JDUT1,' ',UTC,' ',TAI,' ',tt );
  36.         WriteLn( OutFile, ttt,' ',JDTT,' ',TDB,' ',TTDB,' ',JDTDB,' ',JDTDB,' ',DDPsi,' ',DDEps,' ',XLOD,' ',Error );
  37.        
  38.        
  39.  
  40.       END;
  41.  
  42.  
  43. BEGIN // --------------------------- M A I N -----------------------------
  44.  
  45.         IFileName := 'in.dat';
  46.         ASSIGN( InFile,IFileName );
  47.         RESET( InFile );
  48.        
  49.         {$I-}
  50.                 { open it      }
  51.    {$I+}
  52.    if IOresult<>0 then
  53.    begin
  54.      writeln('Error encountered in reading file ');
  55.      halt;
  56.    end;
  57.  
  58.         ASSIGN( OutFile,'dat.out' );
  59.         Rewrite( OutFile );
  60. {$I-}
  61.                 { open it      }
  62.    {$I+}
  63.    if IOresult<>0 then
  64.    begin
  65.      writeln('Error encountered in write file ');
  66.      halt;
  67.    end;
  68.        
  69.         writeln('previo al llamado del procedimiento');
  70.         TestConvTime;      
  71.  
  72.            
  73.  
  74.         CLOSE( InFile );
  75.         CLOSE( OutFile );
  76.  
  77.     END. // Program Testastf
  78.  
  79.  

« Last Edit: September 19, 2018, 06:39:52 pm by juanirias »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Help, some OLD code
« Reply #14 on: September 19, 2018, 06:40:16 pm »
As I told you previously, I cannot reproduce the issue.

Can you provide all the necessary files, including the in.dat, out.dat, text.in, text.out?

I need to inspect them to understand the problem.

 

TinyPortal © 2005-2018