From: Fortran_follower on 25 Jan 2010 05:46 Dear friends, I have some problem in selecting specified columns from a character array. The story is as follows... Below are the file names, the data in which I want to merge into a single file. 07-Jul-2001-23-59-59.txt 08-Jul-2001-23-59-59.txt 09-Jul-2001-23-59-59.txt 19-Aug-2001-23-59-59.txt 20-Aug-2001-23-59-59.txt In order to name the output file... I thought to select the dates of first & last files. I wrote like this...!! outfname=fname(1,1:7) // fname(num,1:6) fname(1,1:7) - first row & 1 to 7 columns fname(num,1:6) - last row & 1 to 6 columns What I get is: outfname=fname(1,1:7)//fname(num,1:6) 1 2 Error: Shapes for operands at (1) and (2) are not conformable Can any one help to resolve this problem. Thanks a lot in advance. Best regards Praveen.
From: Jugoslav Dujic on 25 Jan 2010 06:24 Fortran_follower wrote: > Dear friends, > > I have some problem in selecting specified columns from a character > array. > The story is as follows... > > outfname=fname(1,1:7)//fname(num,1:6) > 1 2 > Error: Shapes for operands at (1) and (2) are not conformable > > Can any one help to resolve this problem. I didn't read too carefully (for the start, you didn't give us the declaration of fname), but you probably want: outfname=fname(1)(1:7)//fname(num)(1:6) This is -- as far as I can tell offhan -- the only situation where Fortran syntax requires two consecutive brackets. -- Jugoslav www.xeffort.com Please reply to the newsgroup. You can find my real e-mail on my home page above.
From: Richard Maine on 25 Jan 2010 11:41 Fortran_follower <ezeepraveen4u(a)gmail.com> wrote: > I have some problem in selecting specified columns from a character > array. .... > outfname=fname(1,1:7) // fname(num,1:6) As Jugoslav mentions, you didn't show the declarations. They matter. A lot. That means all I can do is fairly wild speculation. For future urposes, be aware that declarations usually matter a lot. A large fraction of the problems people report here turn out to be related to the declarations... and a large fraction of the questions unfortunately fail to include the needed declarations. For my speculation, I willl guess that perhaps you actually mean exactly what you say when you use the term "character array" - that is, your fname is a 2-D array of single characters. More common for something like this in Fortran would be to have a 1-D array of character strings. If indeed you have a 2-D array of characters, then fname(1,1:7) and fname(num,1:6) are both array slices. They are *NOT* character strings. Concatenation is not an array operation; it is for strings. What the aboev syntax indicates would be an elemental operation on the two array slices, but the slices are different sizes, which isn't allowed for elemental operations. That's what the error message sounds like and it is consistent with your description. But an elemental operation isn't at all what you want. If you really want to keep your data as a character array, then you need an array operation. You could do it with an array constructor as outfname = [fname(1,1:7), fname(num,1:6)] (where I'm using the f2003 [] for array constructors as I think it much nicer than the older form). But I fairly strongly advise against doing Fortran character stuff as arrays instead of strings. It is possible, and there are cases where it is a good idea, but for ordinary uses I would avoid it. It certainly will confuse you if you aren't pretty fluent in such things because most of the Fortran character manipulation features don't work with character arrays (which is exactly what you ran into). Alternatively, if you do have 1-D arrays of character strings, then you would need the syntax Jugoslav showed. I would have expected a different error message from the compiler in that case, but my expectations could be wrong. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
From: Fortran_follower on 25 Jan 2010 11:55 Dear Richard Maine, Thank you for your detailed reply to my query. Please have a look at my declaration below: character,allocatable,dimension(:,:) :: fname character*100 :: outfile,infile,outfname character*150 :: infpath,outfpath,line integer :: num,i,j,col c col=50 i=1 j=1 c write(*,*)'Enter no.of files to merge' read(*,*)num allocate(fname(num,col)) c > outfname = [fname(1,1:7), fname(num,1:6)] For the solution you have mentioned, I am getting the following error. outfname = [fname(1,1:7), fname(num,1:6)] 1 Error: Incompatible ranks 0 and 1 in assignment at (1) Can you please let me know...whether the problem is with the declaration or with something else...!! Thanking you. Praveen.
From: Fortran_follower on 25 Jan 2010 11:55 Dear Richard Maine, Thank you for your detailed reply to my query. Please have a look at my declaration below: character,allocatable,dimension(:,:) :: fname character*100 :: outfile,infile,outfname character*150 :: infpath,outfpath,line integer :: num,i,j,col c col=50 i=1 j=1 c write(*,*)'Enter no.of files to merge' read(*,*)num allocate(fname(num,col)) c > outfname = [fname(1,1:7), fname(num,1:6)] For the solution you have mentioned, I am getting the following error. outfname = [fname(1,1:7), fname(num,1:6)] 1 Error: Incompatible ranks 0 and 1 in assignment at (1) Can you please let me know...whether the problem is with the declaration or with something else...!! Thanking you. Praveen.
|
Next
|
Last
Pages: 1 2 3 Prev: should not g95 be downward compatible Next: Another class of "DO10I=" bug |