home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 215 / DDJ9206.ZIP / FORTEX.ASC < prev    next >
Text File  |  1992-05-18  |  12KB  |  358 lines

  1. _FORTEX: A Fortran Runtime Executive_
  2. by Harold R. Justice
  3.  
  4. [LISTING ONE]
  5.  
  6. c- climain.f -- top-level calling system utilized by FORTEX CLI.
  7. c- The main program calls user routine "dynxrun". For CLI-only, this routine
  8. c- the name is arbitrary. When linked to GUI library, "start" button calls 
  9. c- the subroutine "dynxrun", a reserved name that MUST be used with the GUI.
  10. c- Dynetics, Inc. 1000 Explorer Blvd. Huntsville, AL 35806 (205) 922-9230
  11.       program climain
  12.       integer icntl
  13. 100   continue
  14. c-------CLEXEC sends the program to the CLI> prompt
  15.         CALL CLEXEC(icntl)
  16. c-------check the return code to see whether the user typed 'stop'
  17.         if( icntl.lt. 0 ) then
  18.           write(*,*)'Normal exit from program'
  19.           stop
  20.         endif
  21. c-------call the user program to do computations, etc.
  22.         call dynxrun
  23. c-----return to the user CLI> prompt so that we may run again
  24.       goto 100
  25.       end
  26.  
  27.     
  28.  
  29.  
  30. [LISTING TWO]
  31.  
  32. c- monte.f -- bob graves -- (c) 1992, dynetics, inc., huntsville, al
  33. c- name    type   description 
  34. c- ----    ----   -----------
  35. c- dbldat  dp     array to read line of data from file
  36. c- idat    int    data counter
  37. c- irun    int    run counter
  38. c- nmnvec  int    number of points in shortest run
  39. c- nmxvec  int    number of points in longest run
  40. c- numrun  int    number of runs read from file
  41. c- there   log    boolean file exists (t) or not (f)
  42. c- clrecd  sub    FORTEX data recording routine
  43. c- dynxrun sub    main number cruncher for monte program
  44. c- mcavg   sub    compute average for all points, all runs
  45. c- mcsig   sub    compute sigma (std dev) for single point
  46.       subroutine dynxrun
  47. c- include file listed in clicom.def for FORTEX dictionary
  48.       include 'monte.h'
  49.       double precision dbldat(100)
  50.       logical there
  51. c- error checking
  52.        if( nsigma .lt. 0.0 ) then
  53.          write(*,*)'err: nsigma negative: defaults to 3.0'
  54.          nsigma = 3.0
  55.        endif
  56. c- user may access the file name through FORTEX set/display
  57.        inquire( file = fname, exist = there )
  58.        if( .not. there ) then
  59.           write(*, *) 'file not found : ', fname
  60.           return
  61.        endif
  62. c- file exists, so open.
  63.        open( lfdat, file=fname, form='unformatted', status='old')
  64. c- initialize counters.
  65.        idat = 1
  66.        irun = 1        
  67. c- data read loop reads from a FORTEX "clirrr" type file and
  68. c- presumes that time (independent variable) has been prepared
  69. c- first on the list. other parameters are data (nparm of them)
  70. 100    continue               
  71.        read(lfdat,err=110,end=110) t(idat,irun),(dbldat(i),i=1,nparm)
  72. c- pick out the column of data for analysis
  73.      work(idat,irun) = dbldat(ivar)
  74.      if( idat .gt. 1 ) then
  75. c- test whether we have entered into another run.
  76.       if( t(idat, irun ) .lt. t(idat-1,irun) ) then
  77. c- set the number of data points in the run.
  78.         num(irun) = idat - 1
  79.         irun = irun + 1
  80.         if( irun .gt. 1 ) then
  81. c- already into next run, so copy it to first element of next run
  82.           t(1, irun ) = t( idat, irun - 1)
  83.           work(1, irun ) = work( idat, irun - 1)
  84.         endif
  85.         idat = 2
  86.         goto 100
  87.       endif         
  88.      endif
  89.      idat = idat + 1
  90.      goto 100
  91. 110    continue              
  92. c- close the file in case we run again
  93.        close(lfdat)
  94. c- assign the number of data points in the last run.
  95.        num(irun) = idat - 1
  96.        numrun = irun
  97. c- find the length of the shortest and longest runs.
  98.        nmxvec = -1
  99.        nmnvec = mxdat
  100.        do 300 irun = 1, numrun
  101.           nmxvec = max ( num(irun), nmxvec )
  102.           nmnvec = min ( num(irun), nmnvec )
  103. 300    continue
  104. c- determine data extend or truncate mode: trunc=.t., truncate long runs; 
  105. c-  trunc=.f., extend all shorter runs to be identical to longest run
  106.        if ( trunc) then
  107.      numvec = nmnvec
  108.        else
  109.      numvec = nmxvec
  110.      imxrun = 1
  111. c- load shorter runs with longest run data. mechanism drives std dev to 0.0
  112.      do 350 irun = 1, numrun
  113.       if( nmxvec .eq. num(irun) ) then
  114.          imxrun = irun
  115.       endif
  116. 350  continue
  117. c- assign longest run data to shorter run data.
  118.      do 410 idat = nmnvec, nmxvec
  119.        do 400 irun = 1, numrun
  120.            work(idat, irun ) = work(idat, imxrun )
  121. 410    continue
  122. 400  continue
  123.        endif
  124. c- analysis section. looping for FORTEX output.
  125. c- do average and +/- n sigma computations.
  126.     call mcavg( avgvec, numvec, numrun, mxdat, work )
  127.     do 450 idat = 1, numvec
  128.       avg = avgvec(idat)
  129.       time = t(idat,1)
  130.       call mcsig( avg, idat, numrun, mxdat, work, 
  131.    .              nsigma, sigpos, signeg, sig )
  132. c-    FORTEX data recording in clrecd
  133.       CALL CLRECD(idat-1)
  134.   450   continue
  135.        return
  136.        end
  137.        subroutine mcsig( avg, idat, nrun, mxdat, work,
  138.      .           nsigma, ps3, ns3, sig )
  139. c-   compute +/- n sigma for data passed in. 
  140.        save
  141.        double precision avg, ps3, ns3, sig, work(mxdat,*), sum
  142. c- initialize.
  143.        sum = 0.0
  144. c- loop through points.
  145.        do 100 irun = 1, nrun    
  146.      sum = sum + ( work(idat, irun ) -  avg )**2
  147. 100    continue           
  148.        if(nrun .gt. 0) then
  149.      sig = sqrt(sum / dble( nrun - 1 ))
  150.        else
  151.      sig = 0.0
  152.        endif
  153. c- compute + and - N sigma vectors.  
  154.        ps3 = avg + nsigma * sig
  155.        ns3 = avg - nsigma * sig
  156.        return
  157.        end
  158.        subroutine mcavg( avg, ndat, nrun, mxdat, work )
  159. c- compute the average of nruns of data.
  160.        save
  161.        double precision avg(*), work(mxdat,*), sum
  162. c- initialize.
  163.        do 110 idat = 1, ndat
  164.        sum = 0.0
  165. c- loop the nrun loop.
  166.        do 100 irun = 1, nrun    
  167.      sum = sum + work( idat, irun )
  168. 100    continue           
  169. c- compute the average for this parameter.
  170.        avg( idat ) = sum / dble( nrun )
  171. 110    continue
  172. c- return.
  173.        return
  174.        end
  175.       block data mondat
  176.       include 'monte.h'
  177. c- initialize through data statements, may also use the monte.setup file
  178.       data nsigma /3/
  179.       data fname  /'monte.dat'/
  180.       data nparm  /2/
  181.       data ivar   /2/
  182.       end
  183.     
  184.  
  185.  
  186. [LISTING THREE]
  187.  
  188. c- monte.h / dynetics, inc., huntsville, al
  189. c- name   type  description
  190. c- ----   ----  -----------
  191. c- mxdat  parm  maximum number of data elements per run
  192. c- mxrun  parm  maximum number of runs
  193. c- work   dp    memory copy of raw data for use in statistics
  194. c- avg    dp    average for a given time point
  195. c- avgvec dp    average vector (keep the averages for std dev calc)
  196. c- signeg dp    minus n-sigma value for a given time point
  197. c- sigpos dp    plus n-sigma value for a given time point
  198. c- sig    dp    sigma (std dev) for a given time point
  199. c- nsigma int   1,2,or 3 for the +/- N sigma computation
  200. c- t      dp    time array
  201. c- time   dp    time for a given point (independent variable)
  202. c- nparm  int   number of data columns (not counting time) in file
  203. c- lfdat  int   logical file number of the data 
  204. c- fname  char  name of the input data file (binary)
  205. c- num    int   array of number of data points per run
  206. c- ivar   int   which data column to analyze
  207. c- trunc  log   whether to truncate to shortest run (T) or extrapolate
  208.       parameter( mxdat = 1000 )
  209.       parameter( mxrun = 100 )
  210.       double precision work( mxdat, mxrun )
  211.       double precision avg, avgvec(mxdat), signeg, sigpos, sig
  212.       double precision t(mxdat, mxrun ), time
  213.       common /monted/ work, avg, avgvec, signeg, sigpos, sig, time, t
  214.       integer numvar, nsigma, lfdat, nparm, ivar, num(mxrun)
  215.       logical trunc
  216.       common /monte/ numvar, lfdat, nsigma, nparm, ivar, num, trunc
  217.       character*64 fname
  218.       common /montec/ fname
  219.     
  220.  
  221.  
  222. [Example 1:  MONTE command file] 
  223.  
  224. echo Setup for MONTE program
  225. set fname='traj.rrr'
  226. set ivar = 2
  227. set lfdat = 30
  228. set nparm = 2
  229. prepar time,avg,sigpos,signeg,sig
  230. display 'prepare'
  231. macro facts
  232.   echo File name with trajectory data
  233.   display fname
  234.   echo Number of data columns
  235.   display nparm
  236.   echo Column of data to analyze
  237.   display ivar
  238. end
  239. macro sig3
  240.  echo 3 Sigma (nsigma=3)
  241.  set nsigma = 3
  242. end
  243. sig3
  244. macro latdat
  245.   echo Analyze the crossrange data
  246.   set ivar=2
  247.   set trunc=.t.
  248.   set fname='../inmonte/clirrr'
  249.   set nparm=3 $ "number of data columns in missile simulation clirrr file"
  250.   facts
  251.   output 'clear'
  252.   output time,avg,sigpos,signeg
  253.   start
  254.   plot
  255. end
  256. macro verdat
  257.   echo Analyze the altitude data
  258.   set ivar=3
  259.   set trunc=.t.
  260.   set fname='../inmonte/clirrr'
  261.   set nparm=3 $ "number of data columns in missile simulation clirrr file"
  262.   facts
  263.   output 'clear'
  264.   output time,avg,sigpos,signeg
  265.   start
  266.   plot
  267. end
  268. set nciout=10
  269. s cmd=5
  270.     
  271.  
  272.  
  273. [Example 2: Partial output from example run-time session]
  274.  
  275. riddler77%  DYNET-X (C) 1991 FORTRAN RUN-TIME EXECUTIVE V3.06 DYNETICS, INC.
  276.  CLI> read 'monte.setup'
  277.   Setup for MONTE program
  278.   Prepare List
  279.    TIME          AVG               SIGPOS
  280.    SIGNEG        SIG
  281.   End Prepare List
  282.   3 Sigma (nsigma=3)
  283.  CLI> "Run program to analyze vertical data"
  284.  CLI> display nciout
  285.     NCIOUT 10
  286.  CLI> "Every 10-th data point will be printed to the screen"
  287.  CLI> verdat
  288.   Analyze the altitude data
  289.   File name with trajectory data
  290.  FNAME '../inmonte/clirrr                                               '
  291.   Number of data columns
  292.      NPARM 3
  293.   Column of data to analyze
  294.       IVAR 3  
  295.       TIME 0.00000000        AVG 0.00000000      SIGPOS 0.00000000
  296.       SIGNEG 0.00000000                                
  297.       TIME 0.09999999        AVG 18.96214371         SIGPOS 20.76645258
  298.       SIGNEG 17.15783483                               
  299.       TIME 0.20000002        AVG 32.36762810         SIGPOS 36.44571089
  300.       SIGNEG 28.28954530                               
  301.          . 
  302.          .
  303.          .
  304.       TIME 4.80001497        AVG 719.5072083         SIGPOS 784.4273663
  305.       SIGNEG 654.5870502                               
  306.       TIME 4.90001726        AVG 738.4712952         SIGPOS 805.1422782
  307.       SIGNEG 671.8003122                               
  308.  CLI> "Only output every 100th point"
  309.  CLI> set nciout=100
  310.  CLI> "Run program to analyze the lateral data"
  311.  CLI> latdat
  312.   Analyze the crossrange data                            
  313.   File name with trajectory data
  314.  FNAME '../inmonte/clirrr                                               '
  315.   Number of data columns
  316.      NPARM 3
  317.   Column of data to analyze
  318.       IVAR 2
  319.       TIME 0.00000000        AVG 0.00000000      SIGPOS 0.00000000
  320.       SIGNEG 0.00000000                                
  321.       TIME 0.99999934        AVG 13.08728914         SIGPOS 15.78440254
  322.       SIGNEG 10.39017575                               
  323.       TIME 1.99999845        AVG 25.58025684         SIGPOS 28.22318408
  324.       SIGNEG 22.93732961                               
  325.       TIME 2.99999762        AVG 37.22265167         SIGPOS 40.50114335
  326.       SIGNEG 33.94416000                               
  327.       TIME 3.99999666        AVG 50.43453903         SIGPOS 54.86466342
  328.       SIGNEG 46.00441465                          
  329.  CLI> display nsigma
  330.     NSIGMA 3
  331.  CLI> "Change sigma level to 2"
  332.  CLI> set nsigma = 2
  333.  CLI> "Run lateral case again to obtain 2-sigma trajectories"
  334.  CLI> "Normally, you would type 'start' to run the program"
  335.  CLI> "but we would like to illustrate the repeat command"
  336.  CLI> !20
  337.        latdat
  338.   Analyze the crossrange data
  339.   File name with trajectory data
  340.  FNAME '../inmonte/clirrr                                               '
  341.   Number of data columns
  342.      NPARM 3
  343.   Column of data to analyze
  344.       IVAR 2
  345.       TIME 0.00000000        AVG 0.00000000      SIGPOS 0.00000000
  346.       SIGNEG 0.00000000                                
  347.       TIME 0.99999934        AVG 13.08728914         SIGPOS 14.88536474
  348.       SIGNEG 11.28921355                               
  349.       TIME 1.99999845        AVG 25.58025684         SIGPOS 27.34220833
  350.       SIGNEG 23.81830535                               
  351.       TIME 2.99999762        AVG 37.22265167         SIGPOS 39.40831279
  352.       SIGNEG 35.03699056                               
  353.       TIME 3.99999666        AVG 50.43453903         SIGPOS 53.38795529
  354.       SIGNEG 47.48112278                             
  355.  CLI> stop
  356.     
  357.  
  358.