IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Turbo Pascal Discussion :

Générer des fichiers de coordonnées


Sujet :

Turbo Pascal

  1. #1
    Candidat au Club
    Inscrit en
    Mars 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 3
    Par défaut Générer des fichiers de coordonnées
    Salut !

    Je suis en train de simuler les trajectoires d'électrons dans un microscope electronique à balayage par méthode Monte Carlo. Alors j'ai élaboré un programme en Turbo Pascal. Parmi les fonctions de ce programme, il doit enregistrer les coordonnées de chaque électron dans un fichier à part.
    Je n'arrive pas à le faire !!

    Alors comment faire pour générer des fichiers automatiquement ?

  2. #2
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 042
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 042
    Billets dans le blog
    2
    Par défaut
    Bonjour et bienvenue !

    Est-ce la création de fichier elle-même qui te pose problème ?

    Si oui, les fonctions qui permettent de créer un fichier binaire sont :
    • Assign pour affecter un fichier physique à la variable de type fichier
    • Rewrite pour créer le fichier
    • Write pour écrire dans le fichier
    • Close pour refermer le fichier
    • IOResult pour détecter les erreurs lors des opérations précédentes

    L'aide du compilateur devrait te donner tous les détails et des exemples d'utilisation de ces différentes routines.

    Si non, quelle est la vitesse d'acquisition des coordonnées, quel volume total cela peut-il constituer ?

    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  3. #3
    Candidat au Club
    Inscrit en
    Mars 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 3
    Par défaut
    Bonjour

    En réponse à votre question, ce n'est pas la création d'un seul fichier qui pose problème. En effet, je peux enregistrer toutes les coordonnées de tous les électrons dans un seul fichier. Mais ce que je souhaite, c'est enregistrer les coordonnées de chaque électron dans un fichier à part.
    Par exemple, si j'ai un grand nombre (N) d'électrons, je veux que soient créés N fichiers; ou le programme envoie les coordonnées de chaque électron dans 1 fichier (exemple : les coordonnées de l'électron numero N=1 enregistrées dans un fichier Numero 1).
    Je peux afficher le programme que j'ai élaboré afin que quelqu'un puisse détecter les erreurs (attention il est long !!).
    Avant j'ai fait ça (mais ça n'a pas marché) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    type
    tab= array[0..1000] of real   ; { pour les cordonnees x,y,z}
    tab1= array[0..200] of string[200] ;
     
    const
    .....
    ......
    var
     
    x,y,z:tab;
    nom:string[200];
    fich1,fichdo:text
     
    ................................
    ...............................
    begin
    {******************* entree des donnees specifiques***}
     writeln(' donnez le nombre d''electron à simuler N0');
    readln(N);
    ................................ect
    {*************initialisation**************}
    N:=1;
    N
    assign(fichdo,'d:\res.dat');
    reset(fichdo);
    while N< = N0 do 
    begin
    readln(fichdo,nom);
    assign(fich1,nom)
    rewrite(fich1);
    ...........................................................etc

  4. #4
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 042
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 042
    Billets dans le blog
    2
    Par défaut
    Il serait intéressant de voir le contenu de la boucle
    Surtout pour voir à quel endroit tu refermes les fichiers. En effet, le nombre maximal de fichiers ouverts simultanément est limité.
    Au fait, quelle erreur rencontres-tu exactement ?
    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

  5. #5
    Membre averti

    Inscrit en
    Janvier 2009
    Messages
    37
    Détails du profil
    Informations personnelles :
    Âge : 57

    Informations forums :
    Inscription : Janvier 2009
    Messages : 37
    Par défaut
    Une autre solution, limitant le nombre de fichiers, pourrait être de créer un seul fichier dans lequel tu te contentes d'ajouter l'électron suivant.

    je n'ai pas testé le code, je tape de tête sur le site, mais cela pourrait donner cela :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    PROGRAM ELECTRON;
    
    USES CRT;
    
    type
    tab= array[0..1000] of real   ; { pour les cordonnees x,y,z}
    tab1= array[0..200] of string[200] ;
     
    var
    x,y,z:tab;
    nom:string[200];
    fich1,fichdo:text
    temp : string;
    
    begin
    clrscr;
    {******************* entree des donnees specifiques***}
     writeln(' donnez le nombre d''electron à simuler N0');
    readln(N0); {je pense ici que tu as fais une erreur précédemment en indiquant realdn(N)}
    ................................ect
    {*************initialisation**************}
    N:=1;
    assign(fichdo,'d:\res.dat');
    rewrite(fichdo);
    writeln(fichdo,N0);
    close(fichdo); {ne jamais oublier de refermer son fichier, sinon on explose la limite admise par TP}
    {*************boucle******************}
    while N< = N0 do begin
       {là, ce que tu veux faire pour récupérer tes coordonnées...
        puis la gestion du fichier}
       append(fichdo)  {ouvre en mode ajout, donc sans effacer ce qui est déjà enregistré}
       temp:=concat('* ELECTRON ',N);
       writeln(fichdo,temp);
       writeln(fichedo,{information 1});
       writeln(fichedo,{information 2});
       {etc}
       close(fichdo);{j'ai fait un append, donc une ouverture, donc je ferme. Cela peut sembler répétitif, mais je te promets que quand tu utilises des masses de fichiers, tu te plantes à coup sûr si tu ne te forces pas à fermer ce que tu ouvres à la fin de ton besoin}
    end;
    
    END.

    Pour la lecture du fichier, cela pourrait donner cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    assign(fichdo,'d:\res.dat');
       reset(fichdo);
       writeln(fichdo,N0); {lit le nombre d'électrons sauvegardés dans le fichier}
       for a:=1 to N0 do begin
       {ce qui aurait aussi pu marcher avec while not eof(fichdo) do begin}
          readln(fichdo,temp);
          temp:=copy(temp,1,1);
          if temp='*' then begin {cela signifie que je suis au début d'un nouvel    électron}
             readln(fichdo,{information 1});
             readln(fichdo,{information 2});
             {etc}
          end;
       end;

  6. #6
    Candidat au Club
    Inscrit en
    Mars 2009
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 3
    Par défaut
    Salut c'est toujours moi !!
    Merci tout d'abord de votre aide.
    Hier, j'ai essayé d'afficher tout le programme; hélas la connexion s'est interrompue; j'ai lu ce que vous avez écrit dernièrement - je suis dans un cyber maitenant. Tout à l'heure j'essayerai !!
    Pour le moment, aucune solution ne m'est apparue
    Voici le programme presque entier (juste une remarque : chaque électron pourrait avoir plusieurs coordonnées qui devraient être enregistrées dans un seul fichier).
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    Program Argon;
    
    
    
    uses crt;
    
    label      exit;
    
      type
      tab = array [0..1000] of real;
     tab1=array[0..200] of string[200] ;
    
    
    
      
        const      two_pi=6.28318;
                   pi=3.14;
                   e_min=0.01;         {cutoff energy in keV }
                   repos=511000;
                   T=293;
                   ah=5.29*1E-11;
                   Tol1=1E-5;
                   Tol=1E-5;
                   F=4.71E-10;
    
                   demi=0.0;
                   at_num=18;
    
                   at_wht=39.95;
    
        var
           inc_energy,density,mn_ion_pot:extended;
           sp,cp,ga,bk_sct,al_a,al_a1,sg_a,lam_a,er,fe_val:extended;
           x0,y0,z0,x1,y1,z1,x2,y2,z2,ca,cb,cc,cx,cy,cz,sab,broadening,broadening1:extended;
           step,stepi,stepj,del_step,del_E,del_E1,s_en,pel,pel1,pel2,p1,p2,p11,mm:extended;
           x,y,z:tab;
           thick,pla1,D,del_z,del_x,del_y,ll,rayon,rayon1,rayon2,rayon0:extended;
           gliset,glgset,probe_size,test_type,r,r1,gen:extended;
           pp,po,pc,del_pp,delta_pp,ti,mat,bat:real;
           num,traj_num,cont,s,k,bem:longint;
          i1,i2,i3, l,n,u,m,mf,perdu,hh,nlot,i,j,ff,it:longint;
           S01,S02,S03,L01,L02,L03,L9,sl:extended;
           onde,ray,A,psi,dob,ano,gco,eco,mola:extended;
           fich3,fich2,fich4,fich1,fichdo1,fich5:text;
           fich: text;
    
           nom: string[200];
           b,g:boolean;
    
           prof:tab;
    
    
    {***********************************************************************************}
    function inn(p:extended;q1:extended;q2:extended;q3:extended):extended;
    
      begin
    
                     inn:=((p*p+q1)*sin(p))/((sqr(p)+sqr(q2))*sqr(sqr(p)+q3));
                     end;
    {***********************************************************************************}
    FUNCTION Fx(X: extended;aa:extended): extended;
    
    BEGIN
      Fx :=sin(x)/sqr(x*x+aa);
    END;  { function Fx }
    
    
    {***************************************   section elastique diatomique   *********************************}
    function  som(infer:extended;super:extended;w11:extended):extended;
    VAR
      I, Pieces: longint;
      x, Delta_X, Pair_Som,vv,  Impair_Som, End_Som, Som1: extended;
    BEGIN
      Pieces := 2;
      Delta_X := (Super - Infer)/Pieces;
      Impair_Som := Fx(Infer + Delta_X,w11);
      Pair_Som := 0.0;
      End_Som := Fx(Infer,w11) + Fx(Super,w11);
      vv := (End_Som + 4.0*Impair_Som)*Delta_X/3.0;
    
       repeat
        Pieces := Pieces*2;
        Som1 := vv;
        Delta_X := (Super - Infer)/Pieces;
        Pair_Som := Pair_Som + Impair_Som;
        Impair_Som := 0.0;
        FOR I:= 1 TO Pieces DIV 2 DO
          BEGIN
            X := Infer + Delta_X*(2.0*I - 1.0);
            Impair_Som := Impair_Som +Fx(X,w11);
          END;
        vv := (End_Som + 4.0*Impair_Som + 2.0*Pair_Som)*Delta_X/3.0;
    
    
      UNTIL Abs(vv - Som1) <= Abs(Tol*vv);
      som:=vv;
    END;
    
    
    {*********************************section innelastique diatomique******************************}
    
    function  sec(infer1:extended;super1:extended;u1:extended;u2:extended;u3:extended):extended;
    VAR
      I, Piece: longint;
      xx, Delta_X, Pair_Som,
    vv1,  Impair_Som, End_Som, Som2: extended;
    
    BEGIN
    
    
      Piece := 2;
      Delta_X := (Super1 - Infer1)/Piece;
    
      Impair_Som := inn(Infer1 + Delta_X,u1,u2,u3);
    
      Pair_Som := 0.0;
      End_Som := inn(Infer1,u1,u2,u3) + inn(Super1,u1,u2,u3);
    
      vv1 := (End_Som + 4.0*Impair_Som)*Delta_X/3.0;
      { WriteLn(Pieces:5, Som:9:5);}
      REPEAT
        Piece := Piece * 2;
        Som2 := vv1;
    
        Delta_X := (Super1 - Infer1)/Piece;
        Pair_Som := Pair_Som + Impair_Som;
        Impair_Som := 0.0;
        FOR I:= 1 TO Piece DIV 2 DO
          BEGIN
            xx := Infer1 + Delta_X*(2.0*I - 1.0);
            Impair_Som := Impair_Som + inn(xx,u1,u2,u3)
          END;
        vv1 := (End_Som + 4.0*Impair_Som
             + 2.0*Pair_Som) * Delta_X / 3.0;
         { WriteLn(Pieces:5, Som:9:5)}
      UNTIL Abs(vv1 - Som2) <=abs(Tol1*vv1);
      sec:=pi*vv1;
    
     END;
    
    
    
    {**************************************************************************************}
    Function power(mantissa,exponent:real):real;
       {this is necessary because PASCAL does not have an exponentiation function}
             begin
               if mantissa<=0 then power:=0
             else
               power:=exp(ln(mantissa)*exponent);
             end;
    {**************************************************************************************}
    Function stop_pwr(energy:real):real;
       {this computes the stopping power in keV/gm/cm2  using the
         modified Bethe expression }
       var temp:extended;
    
          begin
            if energy<0.05 then energy:=0.05;
             temp:=ln(1.166*(energy+0.85*mn_ion_pot)/mn_ion_pot);
               stop_pwr:=temp*78500*at_num/(at_wht*energy);
    
          end;
          {********************************************************************************}
       
               Function gasdev:real;
          {this generates a gaussian deviate of zero mean and unit variance
          to simulate the finite incidence probe diameter. The code is adapted
          from that in Numerical Recipes, by Press et al., Cambridge University
          Press, 1986, page 203}
    
           var
             fac,r,v1,v2:real;
    
             begin
               if gliset=0 then
                 begin
                   repeat
                     v1:=2.0*random-1.0;     {pick a random number}
                     v2:=2.0*random-1.0;     {and another}
                      r:=(v1*v1)+(v2*v2);    {are they in unit circle?}
                    until r<1.0;             {if not try again}
                     fac:=sqrt(-2.0*ln(r)/r);{Box-Muller transform}
                     glgset:=v1*fac;         {get two normal deviates -save one}
                     gasdev:=v2*fac;         {and return the other}
                      gliset:=1;
                 end
                else                         {we already have a spare value}
                 begin
                    gasdev:=glgset;          {so return it}
                     gliset:=0;              {and reset the flag to zero}
                 end;
             end;
    {**************************************************************************************}
    Procedure get_constants;
        {computes some constants needed by the program}
         begin
    
        {computes elastique and inelastique cross section needed by the program}
    
    
    
    
    onde:=1000*s_en*(1+0.9778*s_en*1E-3);
    onde:=sqrt(onde);
    onde:=(1.226E-9)/onde;
    
    ray:=F*ah/(2.0*at_num);
    ray:=sqrt(ray);
    
    A:=sqr(onde)*sqr(onde)*at_num;
    A:=A*sqr(1.0+(s_en*1000/repos));
    r:=(4.0*sqr(Pi)*sqr(Pi)*sqr(ah));
    A:=A/r;
    
    psi:=onde/(2.0*Pi*ray);
    
    dob:=sqr(sin(psi/2.0));
    
    ano:=(mn_ion_pot)/(4.0*s_en);
    
    eco:=(mn_ion_pot)/(4.0*s_en);
    eco:=sqr(eco);
    eco:=eco+2.0*sqr(psi);
    gco:=(mn_ion_pot)/(4.0*s_en);
    gco:=sqr(gco);
    gco:=gco+sqr(psi);
    
    mola:=(2*Pi*A*at_num);
      S01:=mola*som(sin(psi/2),pi,dob);
    
    
      S02:=2.0*A*sec(ano,pi,eco,ano,gco);
    
    
      S03:=S01+S02;
    
     { pel:=S01/S03;}
    end;
    {**********************************************************************************}
    procedure get_constants2;
    
    
      begin
    
       density := at_wht*1.203*1E-7;
               density := density*(pp/293);
    
    
            L01:= (1.38*1E-23*293)/(S01*pp);
            L02:=(1.38*1E-23*293)/(S02*pp);
            L03:=(1.38*1E-23*293)/(s03*pp);
             L9:=1.0/l01 + 1.0/l02;
            L9:=1.0/l9;
          PEL:=L9/l01;
    
    
        end;
    
    {***************************************************************************************}
    
     Procedure set_up_screen;
      {gets the input data to run this program}
    
        begin
                   ClrScr;         {erases all previous data from screen}
    
    
                      Writeln('Mansour Omar Monte Carlo Simulation' );
    
        {Having set up the screen now get input data}
    
    
               Write('Input beam energy in keV: ');
                 Readln(Inc_Energy);
    
    
                     al_a:=power(at_num,0.67)*3.43E-3;
    
    
    
     {  Calculate J the  mean ionization potential mn_ion_pot  }
        mn_ion_pot:=(9.76*at_num+(58.5/power(at_num,0.19)))*0.001;
    
        Writeln('pla diameter (meter) D  =  ');
        Readln(D);
           Writeln('pression à l''issue du pla  pascale is po =  ');
                    Readln(po);
          Writeln('pressure at specimen chamber in pascale is pc =  ');
                    Readln(pc);
                { pla1:=0.001/pc; }
    
    
                Writeln('deviding number nlot=  ');
              Readln(nlot);
               del_z:=2*D/nlot;
                Writeln('del_z  =  ',del_z);
    
                   del_x:=D/nlot;
                 Writeln('del_x  =  ',del_x);
                     del_y:=D/nlot;
                   Writeln('del_y  =  ',del_y);
                   del_pp:=(pc-po)/nlot ;
    
    
    
                    pp:=po;
    
                    density := at_wht*1.203*1E-7;
               density := density*(po/293);
                 { write('Probe diameter (angstroms): ');
                   readln(probe_size);  }
                   {if probe_size<1 then probe_size:=1;}
                 {convert this to unit variance for GasDev routine}
                 { probe_size:=(probe_size*1E-10)/2.24; }
    
    
                  write('working distance (m):  ');
                     readln(thick);
    
                    {write('tilt in degree: ');
                        readln(ti); }
    
    
      { get the number of trajectories to be run in this simulation }
                     GoToXY(22,11);
                      write('Number of trajectories required: ');
                        readln(traj_num);
    
          end;
    
    {***************************************************************************}
    Procedure reset_coordinates;
         {resets coordinates at start of each trajectory}
                   begin
                       s_en:=inc_energy;
                        x0:=0;   x[0]:=x0;
                         y0:=0;  y[0]:=y0;
                          z0:=-D;  z[0]:=z0;
                         cx:=0;
                        cy:=0;
                      cz:=1;
                   end;
    {****************************************************************************}
    Procedure zero_counters;
       {since PASCAL does not zero variables on start-up we must do this}
               begin
               bk_sct:=0;
               num:=1;
               gliset:=0;
               u:=0;
               l:=0;
               n:=0;
               k:=0;
               m:=0;
               perdu:=0;
               s:=0;
               hh:=0;
               ff:=0;
               end;
      {***************************************************************************}
    
    Procedure s_scatter(energy:real);
             {calculates elatic scattering angle using screened Rutherford cross-section}
             var R1,al:real;
             begin
                  al:=al_a/energy;
                  R1:=random;
                  cp:=1.0-((2.0*al*R1)/(1.0+al-R1));
                  sp:=sqrt(1.0-cp*cp);
             {and get the azimuthal scattering angle}
                  ga:=two_pi*random;
             end;
    {******************************************************************************}
    Procedure inelastic_scatter(energy:real);
             {calculates inelastic scattering angles }
             var R1:real;
             begin
                  R1:=random;
                  sp:=del_E/energy;
             {and get the azimuthal scattering angle}
                  ga:=two_pi*R1;
             end;
             {*******************************************************************}
               Procedure new_coord1(step:real);
            {gets xn,yn,zn from x,y,z and scattering angles}
            var an_n,an_m,v1,v2,v3,v4:real;
            begin
             { find the transformation angles }
                              if cz=0 then cz:=0.000001;
                                 an_m:=(-cx/cz);
                                 an_n:=1.0/sqrt(1+(an_m*an_m));
           { save computation time by getting all the transcendentals first }
                                 v1:=an_n*sp;
                                 v2:=an_m*an_n*sp;
                                 v3:=cos(ga);
                                 v4:=sin(ga);
           { find the new direction cosines}
                           ca:=(cx*cp) + (v1*v3) + (cy*v2*v4);
                           cb:=(cy*cp) + (v4*(cz*v1 - cx*v2));
                           cc:=(cz*cp) + (v2*v3) - (cy*v1*v4);
           { and get the new coordinates }
                           x2:=x0 + step*ca;   x[2]:=x2;
                           y2:=y0 + step*cb;   y[2]:=y2;
                           z2:=z0 + step*cc;    z[2]:=z2;
    
            end;
    
    {******************************************************************************}
    
    
    Procedure new_coord(step:real);
            {gets xn,yn,zn from x,y,z and scattering angles}
            var an_n,an_m,v1,v2,v3,v4:real;
            begin
             { find the transformation angles }
                              if cz=0 then cz:=0.000001;
                                 an_m:=(-cx/cz);
                                 an_n:=1.0/sqrt(1+(an_m*an_m));
           { save computation time by getting all the transcendentals first }
                                 v1:=an_n*sp;
                                 v2:=an_m*an_n*sp;
                                 v3:=cos(ga);
                                 v4:=sin(ga);
           { find the new direction cosines}
                           ca:=(cx*cp) + (v1*v3) + (cy*v2*v4);
                           cb:=(cy*cp) + (v4*(cz*v1 - cx*v2));
                           cc:=(cz*cp) + (v2*v3) - (cy*v1*v4);
           { and get the new coordinates }
                           x1:=x0 + step*ca;       x[1]:=x1;
                           y1:=y0 + step*cb;      y[1]:=y1;
                           z1:=z0 + step*cc;      z[1]:=z1;
    
            end;
    {******************************************************************************}
    Procedure back_scatter;
        {handles case of backscattered electrons}
                      begin
                         bk_sct:=bk_sct+1;
    
                         end;
    
    {******************************************************************************}
    Procedure transmit_electron;
        {handles case of unscattered electron}
              begin
    
                           z1:=thick;                            z[1]:=z1;
                            x1:=x0 + (thick-z0)/abs(cc)*ca;       x[1]:=x1;
                            y1:=y0 + (thick-z0)/abs(cc)*cb;        y[1]:=y1;
    
    
    
               end;
    {*******************************************************************************}
    Procedure transmit_electron1;
        {handles case of unscattered electron}
              begin
    
                            z1:=thick ;       z[1]:=z1;
                            x1:=x0 ;    x[1]:=x1;
                            y1:=y0 ;   y[1]:=y1;
    
    
               end;
               {***************************************************************}
             procedure localise;      {localise les cordonnees de l''e-}
             begin
             rayon2:=sqrt(sqr(x2)+sqr(y2));
             if (z2>=-D) then
             begin
             if (rayon2<D/2)and (z2<D) then
             begin
             j:=trunc(z2/del_z)+1;
             end
    
             else
             begin
             j:=nlot;
             end;
             end
             else
             begin
             j:= 0;
             end;
    
             end;
               {***********************************************************}
           
           {*****************************************************************}
            procedure localise1;
             begin
    
             if (z1>=-D)and(z1<D) then
    
    
             begin
             i:=trunc(z1/del_z)+1;
             end;
              if (z1>=-D)and(z1>=D) then
             begin
             i:=nlot;
             end;
    
             if  (z1<-D)  then
             begin
             i:=0;
             end;
    
             end;
             {*****************************************************************}
           { procedure localisex;
            begin
            if( x1<D/2)then
            begin
           i1:=trunc(abs(x1/del_x))+1;
    
            end
           else
            begin
            i1:=nlot;
    
            end;
            end;}
         {*******************************************************************}
    {procedure localisey;
            begin
            if( y1<D/2)then
            begin
           i2:=trunc(abs(y1/del_y))+1;
    
            end
           else
            begin
            i2:=nlot;
    
            end;
            end;}
      {*******************************************************************}
      procedure retou_elast;
      begin
                           mat:= Random ;
                           localise1;
                           stepi:=-(Ln(mat)*L01);
                         {  l:=l+1;}
                           new_coord1(stepi);
                            localise;
    
                             del_step:=1.38E-23;
                            del_step:= del_step*293/S01;
                            del_step:=(del_step*ln(mat))*(j-i)*del_pp;
                             del_step:= del_step/(sqr(po)+(i+j)*po*del_pp+ i*j*sqr(del_pp));
                            stepj:= stepi+ del_step;
                               l:=l+1;
                               new_coord(stepj);
    
                              pp:=po+j*del_pp;
    
                              end;
     
    {*******************************************************************************}
    procedure retou_inela;
    begin
                                 bat:= random;
                                 localise1;
                                     stepi:=-(Ln(bat)*L02);
                          { n:=n+1; }
                                    new_coord1(stepi);
                                    localise;
    
                             del_step:=1.38E-23;
                            del_step:= del_step*293/S02;
                            del_step:=(del_step*ln(mat))*(j-i)*del_pp;
                             del_step:= del_step/(sqr(po)+(i+j)*po*del_pp+ i*j*sqr(del_pp));
                            stepj:= stepi+ del_step;
                              n:=n+1;
                               new_coord(stepj);
                                 pp:=po+j*del_pp;
                               end;
    
      {*******************************************************************************}
    
    Procedure reset_next_step;
    
    {resets variables for next trajectory step}
                    begin
    
                           cx:=ca;
                           cy:=cb;
                           cz:=cc;
                       x0:=x1;   x[0]:=x0;
                                 x[1]:=x1;
    
                       y0:=y1;   y[0]:=y0;
                                 y[1]:=y1;
    
                       z0:=z1;  z[0]:=z0;
                                 z[1]:=z1;
    
    end;
    
    {*******************************************************************************}
    procedure energy_loss;
    begin
                      {find the energy lost on this step}
                         del_E:=step*stop_pwr(s_en)*density*100;
    
                      {so the current energy is}
                         s_en:=s_en - del_E;
                   end;
    
    {******************************************************************************}
    
    procedure skirting;
    var
    gen,gen1:extended;
    begin
    gen:=sqrt(sqr(demi-x1)+sqr(demi-y1));
    if gen> 0 then begin
    
    k:=k+1;
    writeln(Fich2,' ',z1,'      ',gen);
    gen1:=gen/(psi*(thick));
    { writeln(Fich1,' ',k,'      ',gen1);}
    
    end
    else begin
    hh:=hh+1;
    end;
    end;
    
    {********************************************************************************}
    
    
    
    
           { ********************************************************
             *        this is the start of the main program         *
             ********************************************************}
    
        begin
                              set_up_screen;   {get input data and find J value}
    
    
    
                      {  reset the random number generator}
                                randomize;
                                    zero_counters;
                           {***********************************************}
                                     assign(fich5,'C:\mausta5.DAT');
                                    rewrite(fich5);
                                    assign(fich3,'c:\mausta3.DAT');
                                    rewrite(fich3);
    
                                  {  assign(fich1,'c:\mausta1.DAT');
                                    rewrite(fich1);  }
    
    
                                    assign(fich2,'c:\mausta2.DAT');
                                    rewrite(fich2);
    
                                  assign(fichdo1,'c:\RES.dat');
                                    reset(fichdo1);
    
                            {***********************************************}
    
    
    {  *******************************************************************
       *                     the Monte Carlo Loop                        *
       *******************************************************************}
    
    
    
    
    
    
    
    
    while num <=(traj_num)   do
    
      begin
    
        readln(fichdo1,nom);
        assign(fich1,nom);
        rewrite(fich1);
    
    
                               reset_coordinates;
                                     get_constants;
    
    
                               cp:=1;sp:=0;ga:=0;
    {allow initial entrance of electron/distance before first scattering}
          g:=true;
     while g=true do
     begin
    
    
                             {  step:=-693.68*ln(random);}
                               step:=1E-6;
                              { pla1:=-693.68*1e-5/pc; }
    
    
    
    
    
    
                         {allow initial entrance of electron/distance before first scattering  }
    
                           new_coord(step);
                                            { locate z1}
    
    
    
    
                               rayon:=sqrt(sqr(x1)+sqr(y1));
    
    
    if z1>(thick)  then  {this one is unscattered}
    begin
    
    
    
                              transmit_electron1;
    
                              skirting;
                              u:=u+1;
                              goto exit;
    end
    else
    begin
    
    
                                  if (D>z1)and(D/2>rayon) then
                                    begin
                                   if z1 >=-D then
                                  begin
                                  sab:=trunc(abs(z1/del_z))+1;
    
                                  pp:=sab*del_pp+po;
                                  end
                                  else
    
                                  begin
                                  pp:=po;
                                  end;
                     end
                      else
                             begin
                                   pp:=pc;
                               end;
    
    
    
    
    
                             get_constants2;
                         reset_next_step;
    
    
        end;
    
    
     b:=true;
     while b=true do
     begin
    
    p1:=random;
    p2:= 1-exp(-2.472*1E20*S03*step*pp);
    {if  P1 is larger than p2 then no collision has occurred}
    
    if p1>p2 then begin
    b:=false;
    end
    else
    begin
    
                             {now start the scattering loop}
                             it:=0;
    
    
    
    
    
    
    repeat
    
    
    
    
    
    
    
                              {now test the type of scattering}
                      test_type:=random;
                     If test_type <= pel   Then    {its elastically scattered}
                     begin
    
                           s_scatter(s_en);
                            retou_elast;
                           it:=it+1;
                           rayon1:=sqrt(sqr(x1)+sqr(y1));
                       end
    
    
                     else
                     begin
    
                           inelastic_scatter(s_en);
                           retou_inela;
                           it:=it+1;
                           rayon1:=sqrt(sqr(x1)+sqr(y1));
                      end;
    
    
    
                          writeln(fich1,'  ',x[1],'   ',z[1],'  ');
    
    
    
                         
    
                           get_constants2;
                           
    
    
                          {decide what happens next}
    
                          if z1<0 then    {this one is backscattered}
                           begin
                             back_scatter;
                            goto exit;
                           end;
    
                          if (z1)>(thick) then {this one is transmitted}
                           begin
                             transmit_electron;
                             skirting;
                            goto exit;
                           end;
                           
                          {otherwise we go round again}
                           s:=s+1;
                          energy_loss;
                          reset_next_step;
    
    
                          if del_E > s_en then
                          begin
                          perdu:=perdu+1;
                          goto exit;
                          end;
                          get_constants;
                         get_constants2;
    
    
    
    
    until s_en<=e_min ;
    perdu:=perdu+1;
    goto exit;           {end of  loop - the energy drops below e_min}
    end;{ end of probabilty of collision}
    
    
       end;
                   { end of goto jumps/end of b=true}
    end; {end of g true}
     {
        ***********************************************************
        *               end of the Monte Carlo Loop               *
        ***********************************************************
     }
       exit:
    
    {writeln(fich,num,'   ',prof[num]); }
    
                        num:=num+1;
    
                       if num mod 100=0 then  randomize;
    
                  writeln('N=   ', Num);
                     close(fich1);
    
    
    end;
    
    
    
    thick:=thick;
    s_en:=Inc_Energy;
    get_constants;
    
    {broadening:=(135.2515E-14)*at_num*thick*sqrt(mf/S03)/(Inc_Energy);}
    
    {broadening:=broadening*sqrt(mf/S03); }
    {broadening:=broadening*thick*sqrt(thick); }
      mm:=(7.2463768*1E22*S03)*(pc*(thick-D)+D*po+(1+nlot)*D*del_pp/2)/293;
    broadening1:=thick*(0.0039 + 0.00155*power((mm*T/(S03*7.243E22)),1.83));
    
    
    
           
    
        end.

  7. #7
    Responsable Pascal, Lazarus et Assembleur


    Avatar de Alcatîz
    Homme Profil pro
    Ressources humaines
    Inscrit en
    Mars 2003
    Messages
    8 042
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ressources humaines
    Secteur : Service public

    Informations forums :
    Inscription : Mars 2003
    Messages : 8 042
    Billets dans le blog
    2
    Par défaut
    Pfiouuu, sans vouloir te froisser, le programme est très difficile à lire à cause de l'indentation un peu anarchique.

    Quoi qu'il en soit, pour éviter de devoir avoir trop de fichiers ouverts simultanément, je te proposerais plutôt la solution de créer un arbre en mémoire, dont chaque branche correspondrait à un électron distinct. Ton arbre serait construit au cours de l'exécution du programme et, in fine, tu pourrais créer tous tes fichiers à ton aise, un par un, en parcourant l'arbre branche par branche.
    Règles du forum
    Cours et tutoriels Pascal, Delphi, Lazarus et Assembleur
    Avant de poser une question, consultez les FAQ Pascal, Delphi, Lazarus et Assembleur
    Mes tutoriels et sources Pascal

    Le problème en ce bas monde est que les imbéciles sont sûrs d'eux et fiers comme des coqs de basse cour, alors que les gens intelligents sont emplis de doute. [Bertrand Russell]
    La tolérance atteindra un tel niveau que les personnes intelligentes seront interdites de toute réflexion afin de ne pas offenser les imbéciles. [Fiodor Mikhaïlovitch Dostoïevski]

Discussions similaires

  1. [XSLT] Générer des fichier SQL avec un XSD
    Par NoiBe dans le forum XSL/XSLT/XPATH
    Réponses: 3
    Dernier message: 18/01/2007, 10h39
  2. lire et générer des fichiers pdf et doc
    Par aziz jim dans le forum wxWidgets
    Réponses: 3
    Dernier message: 12/11/2006, 17h03
  3. Générer des fichiers à partir d'un état
    Par laurent35 dans le forum Access
    Réponses: 3
    Dernier message: 02/05/2006, 02h54
  4. [Excel] Générer des fichiers Excel avec PHP et des données SQL
    Par MaTHieU_ dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 29/03/2006, 15h46
  5. Générer des fichiers PDF
    Par bobbafet dans le forum C++Builder
    Réponses: 5
    Dernier message: 29/11/2004, 23h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo