home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / ada / 3922 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  4.7 KB

  1. Path: sparky!uunet!spool.mu.edu!agate!ucbvax!NOSVE.ELAN.AF.MIL!EDSKO
  2. From: EDSKO@NOSVE.ELAN.AF.MIL
  3. Newsgroups: comp.lang.ada
  4. Subject: Tricky FORTRAN -> Ada data file conversion
  5. Message-ID: <930107121644000-MTAAFFTC*EDSKO@nosve.elan.af.mil>
  6. Date: 7 Jan 93 20:20:02 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 99
  11.  
  12. A rather lengthy query follows.  Those with weak constitutions or short
  13. attention spans should move on to the next article.
  14.  
  15. We are attempting to use Ada to read files created by FORTRAN unformatted
  16. writes.  These records may be loosely classified as discriminated records,
  17. but each particular variant can be variable size.  The format of a typical
  18. variant of the record follows (in FORTRANese)
  19.  
  20.  word   variable  type       storage details
  21.  ----   --------  ----       ---------------
  22.  1      rtype     a8         left justified (lj), space filled (sf) in 64 bits
  23.  2      jon       a5         lj, sf in 64-bit word
  24.  3      itail     integer    signed binary, 64 bits
  25.  4..13  title     10(a6)     6 chars lj, sf in 64 bits; repeated 10 times
  26.  14     itest     integer    signed binary, 64 bits
  27.  15     flt       a4         lj, sf in 64 bits
  28.  16     dflt      a6         lj, sf in 64 bits
  29.  17     dreq      a6         lj, sf in 64 bits
  30.  18     dcom      a6         lj, sf in 64 bits
  31.  19     n         integer    signed binary, 64 bits
  32. 20..19+n rem      n(a6)      6 chars lj, sf in 64 bits; repeated n times
  33.  20+n   jflagp    integer    signed binary, 64 bits
  34.  
  35. An Ada-ish record definition for the above looks something like
  36.  
  37.     rtype  :  string(1..8);
  38.     jon    :  string(1..8);
  39.     itail  :  integer;
  40.     title  :  string(1..80);  -- the string is peppered with intervening blanks
  41.     itest  :  integer;
  42.     flt    :  string(1..8);
  43.     dflt   :  string(1..8);
  44.     dreq   :  string(1..8);
  45.     dcom   :  string(1..8);
  46.     n      :  integer;
  47.     rem    :  array(1..n) of string(1..8);  -- note n is VARIABLE, is it legal?
  48.     jflagp :  integer;
  49.  
  50. The record is read according to the FORTRAN statement:
  51.  
  52.   READ(unit) rtype,jon,itail,(title(i),i=1,10),itest,flt,dflt,dreq,dcom,n,
  53.  +           (rem(i),i=1,n),jflagp
  54.  
  55. The actual read is accomplished in two steps by virtue of the implied DO's.
  56. 19 words are read, n is digested, then n+1 words are read.
  57.  
  58. Question 1:  Can Ada deal with a record with a field whose size is dynamic?
  59.              For these records, n has a known maximum value (20), but it
  60.              does vary from record to record.
  61.  
  62. Question 2:  If Q1 has a yes answer, can Ada I/O read such a record from a file?
  63.  
  64. As if the above weren't bad enough, the file we are reading has several record
  65. types which are determined by the first 8 bytes (rtype).  To sequentially read
  66. this file, we need a file of discriminated records.  If we redefine the record
  67. as indicated below, I am certain that the compiler will abort because the
  68. descriminator must be a scalar or subrange.
  69.  
  70. (pardon my broken Ada)
  71.  
  72. TYPE the_record(rtype: string(1..8):=default_value) IS RECORD
  73.    CASE rtype IS
  74.      when 'P       '
  75.         a list of fields
  76.      when 'FMT     '
  77.         a different list of fields
  78.      when '????????'  -- various known record types exist.
  79.         an appropriate list of fields for each known record type
  80.      OTHERWISE  -- I don't even know if Ada has a catch-all
  81.         yet another list of fields
  82.    end CASE;
  83. end RECORD;
  84.  
  85. Question 3: Can the descriminator rtype be redefined as an integer, and the
  86.             WHEN values be the integer equivalent of the character array?
  87.  
  88. Question 4: Can the descriminator rtype be redefined as an enumeration, and
  89.             by using the FOR rtype USE clause specify the 64-bit value of the
  90.             ASCII (e.g. for 'P       ' specify x'5020202020202020')?
  91.  
  92. Our current workaround is to define either a large string or an array of
  93. 64-bit words as one of the variant records and thus overlay the appropriate
  94. type.  We are not yet to the point of scanning the string or array and setting
  95. the discriminator to the appropriate value.  Using the coincidental overlaying
  96. does not strike some of us here as adhering to the 'Ada paradigm,' but given
  97. that FORTRAN unformatted I/O is system dependent anyways, I have no guilt
  98. complex from kludging the silly thing.
  99.  
  100. I welcome any further clues or alternate strategies.  I do not subscribe to
  101. Info-Ada, but others at my site do.  If you have some comments which are
  102. not for distribution-wide consumption, please email me directly.
  103.  
  104. Ed Skochinski                 email: edsko@nosve.elan.af.mil
  105. Control Data Systems, Inc.    phone: 805.277.3152
  106. Edwards AFB
  107.  
  108.  Chism's Law of Completion:
  109.       The amount of time required to complete a government project is
  110.       precisely equal to the length of time already spent on it.
  111.