btb@ncoast.UUCP (Brad Banko) (12/04/86)
how do you access characters in arrays of character*n? I am using Vax Fortran, and would like to access individual characters in an array of character*n: character*n a(m) I want it to be "m lines of n character 'strings'", but fortran won't let me access character y in "line" x with: a(x,y), or a(x)(y)... what to do? (BTW, I have read the Vax Fortran manual, and it is little help in this particular area.) Thanks, -- Brad Banko ...!decvax!cwruecmp!ncoast!btb Cleveland, Ohio
russell@acf4.UUCP (Bill Russell) (12/04/86)
To reference a sub-string in an array of character strings: character*32 str(32) character*length string string = str(index)(first-char:last-char) Where index = array index, first-char & last-char are character index values.
cetron@utah-cs.UUCP (Edward J Cetron) (12/04/86)
In article <1772@ncoast.UUCP> btb@ncoast.UUCP (Brad Banko) writes: >how do you access characters in arrays of character*n? > >I am using Vax Fortran, and would like to access individual characters in >an array of character*n: > > character*n a(m) > >I want it to be "m lines of n character 'strings'", but fortran won't let >me access character y in "line" x with: > > a(x,y), or a(x)(y)... > try a(x)(y:y) where (x,x,x,...) are array delimiters, and (n:m) are substring specifiers... -ed cetron Center for Engineering Design Univ of Utah
steved@sun.uucp (Steve Dever) (12/04/86)
In article <1772@ncoast.UUCP> btb@ncoast.UUCP (Brad Banko) writes: >how do you access characters in arrays of character*n? > >I am using Vax Fortran, and would like to access individual characters in >an array of character*n: > > character*n a(m) > >I want it to be "m lines of n character 'strings'", but fortran won't let >me access character y in "line" x with: > > a(x,y), or a(x)(y)... > Character substrings in FORTRAN are accessed as: c(f:l) where f is the position of the first character referenced and l is the position of the last character. For array references, the substring follows the subscript. So in your example, the reference would be written: a(x)(y:y) -- --------------------------- Steve Dever steved@Sun.COM or Sun Microsystems sun!steved
falk@uiucuxc.cso.uiuc.edu (12/05/86)
>/* ---------- "accessing character arrays..." ---------- */ >how do you access characters in arrays of character*n? >I am using Vax Fortran, and would like to access individual characters in >an array of character*n: > character*n a(m) >I want it to be "m lines of n character 'strings'", but fortran won't let >me access character y in "line" x with: > a(x,y), or a(x)(y)... >-- >Brad Banko Look in the Fortran manual under "Substrings, character". You can accomplish what you want with that notation. The following program segment is an example: character*10 temp(5) data temp/'first ','second ','third ', ... / print*(temp(i)(2:4), i=1,5) stop end It will print the 2nd, 3rd and 4th characters in each of the 5 elements of temp. The 2 and 4 can be replaced by variable expressions and you can search the strings until you find an appropriate match.