- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A subroutne populates a matrix A(10,10) as follows (actually it doesn't populate last two rows):
SUBROUTINE GLNAM(I,J,FNAME1,FNAME2)
CHARACTER FNAME1*10, FNAME2*10,A(10,10)*3,B(10,10)*3
DATA A(1,1),A(1,2),A(1,3),A(1,4)/'1M1','1M2','1M3','1M4'/
DATA A(2,1),A(2,2),A(2,3),A(2,4)/'2M1','2M2','2M3','2M4'/
DATA A(3,1),A(3,2),A(3,3),A(3,4)/'3M1','3M2','3M3','3M4'/
DATA A(4,1),A(4,2),A(4,3),A(4,4)/'4M1','4M2','4M3','4M4'/
DATA A(5,1),A(5,2),A(5,3),A(5,4)/'5M1','5M2','5M3','5M4'/
DATA A(6,1),A(6,2),A(6,3),A(6,4)/'6M1','6M2','6M3','6M4'/
DATA A(7,1),A(7,2),A(7,3),A(7,4)/'7M1','7M2','7M3','7M4'/
DATA A(8,1),A(8,2),A(8,3),A(8,4)/'8M1','8M2','8M3','8M4'/
DATA A(1,5),A(1,6),A(1,7),A(1,8)/'1M5','1M6','1M7','1M8'/
DATA A(2,5),A(2,6),A(2,7),A(2,8)/'2M5','2M6','2M7','2M8'/
DATA A(3,5),A(3,6),A(3,7),A(3,8)/'3M5','3M6','3M7','3M8'/
DATA A(4,5),A(4,6),A(4,7),A(4,8)/'4M5','4M6','4M7','4M8'/
DATA A(5,5),A(5,6),A(5,7),A(5,8)/'5M5','5M6','5M7','5M8'/
DATA A(6,5),A(6,6),A(6,7),A(6,8)/'6M5','6M6','6M7','6M8'/
DATA A(7,5),A(7,6),A(7,7),A(7,8)/'7M5','7M6','7M7','7M8'/
DATA A(8,5),A(8,6),A(8,7),A(8,8)/'8M5','8M6','8M7','8M8'/
DATA A(1,9),A(1,10) /'1M9','1M0'/
DATA A(2,9),A(2,10) /'2M9','2M0'/
DATA A(3,9),A(3,10) /'3M9','3M0'/
DATA A(4,9),A(4,10) /'4M9','4M0'/
DATA A(5,9),A(5,10) /'5M9','5M0'/
DATA A(6,9),A(6,10) /'6M9','6M0'/
DATA A(7,9),A(7,10) /'7M9','7M0'/
DATA A(8,9),A(8,10) /'8M9','8M0'/
FNAME1 = 'GNOUT'//A(I,J)
What is the meaning of '*3' in character A(10,10) *3
Also what is the meaning of: FNAME1 = 'GNOUT'//A(I,J)
what sort of function is: // before A(i,j)
I deleted B inputs with data command as it is same as A
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
D.W. van Meeuwen wrote:Dear Drik Thanks for your input. I will check those sites.The *3 denotes the length of the character (see also http://software.intel.com/sites/default/files/m/3/1/3/1/a/14323-406092.pdf chapter 5 on the character data type)
A character expression consists of a character operator (//) that concatenates two operands
of type character. (see also http://software.intel.com/sites/default/files/m/3/1/3/1/a/14323-406092.pdf chapter 6 on the character expressions)Hope this helps
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
D.W. van Meeuwen wrote:I haven't downloaded the 2nd file yet, but their file size is different.Please note that the two files are the same, it is the Intel(R) Fortran Language Reference.
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anthony Richards wrote:Obviously your solution is smarter than mine, but I couldn't understand it. Could you please explain how these commands produces ((iMj, j=1,10),i=1,8) If the write command doesn't have * or unit number, where the WRITE command is writing?Alternatively, you can create the data using internal writes to character variables:
DO I=1,8
DO J=1,9
WRITE(A(i,j),'(I1,A1,I1)') i,'M',j
ENDDO
WRITE(A(i,10),'(I1,A1,I1)') i,'M',MOD(J,10)
ENDDOor alternatively,
DO I=1,8
DO J=1,10
WRITE(A(i,j),'(I1,A1,I1)') i,'M',MOD(J,10)
ENDDO
ENDDONote that Rows 9 and 10 of array A are uninitialised.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to use the above formula for generating A(i,j) in the following manner. However it doesn't work. Could you please let me know the correct form? In other words I want to use concatnation in Do loop to produce the desired carachters.
DO I=1,8
DO J=1,10
A(i,j)= i//'M'//MOD(J,10)//'.txt'
ENDDO
ENDDO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to replace
A(i,j) = i//'M'//MOD(j,10)//'.txt'
with
WRITE(A(i,j),'(i0,a1,i0,a)') i,'M',mod(j,10),'.txt'
note the use of i0 (i zero) in the format, which allows for "as many digits as are needed" This means that future changes to your program will allow for do loops greater than the ones you currently have.
Assuming of course that A() is a character array of sufficient character length to hold the result.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Les Neilson wrote:
You need to replace
A(i,j) = i//'M'//MOD(j,10)//'.txt'
with
WRITE(A(i,j),'(i0,a1,i0,a)') i,'M',mod(j,10),'.txt'note the use of i0 (i zero) in the format, which allows for "as many digits as are needed" This means that future changes to your program will allow for do loops greater than the ones you currently have.
Assuming of course that A() is a character array of sufficient character length to hold the result.Les
Dear Les
Thanks for your reply.Where does this "write" takes place? Into monitor or where. I want to produce
A(1,1)= 1M1 and then in next line want to concatnate it with 'GNOUT' to produce GNOUT1M1 as follows:
FNAME1='GNOUT'//A(i,j)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your earlier post you had the following :
DO I=1,8
DO J=1,10
A(i,j)= i//'M'//MOD(J,10)//'.txt' ! **** this is the line to replace with the code I showed
ENDDO
ENDDO
As Anthony and I mentioned in earlier posts it uses "internal I/O" There is no disk file the code "writes" the data from i,'M' and j into the variable A(i,j). You should read about it in a Fortran manual if you want to understand more.
You may then have FNAME1 = 'GNOUT'//A(i,j) just as you have written it .
We assume that you have A() declared as CHARACTER(len=12) :: A(8,10)
or something similar.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rasoul,
OK I jumped in a bit quickly there. I should have re-read the original post.
In your first post, there is the line :
CHARACTER FNAME1*10, FNAME2*10,A(10,10)*3,B(10,10)*3
This means that A is a character array (10,10) the length of each string is 3 characters
and FNAME1 is a single character string of length 10
so your do-loop should have :
write(A(i,j), '(i1,a1,i1)') i, 'M', mod(j,10)
Then you can have immediately after that line, (or perhaps in another do-loop further down the code) :
FNAME1 = 'GNOUT'//A(i,j)//'.txt'
to make what appears to be a file name - however note as I said above FNAME is 10 characters long but
'GNOUT' is 5 characters long
A(i,j) is 3 characters long
and '.txt' is 4 characters long
making 12 characters in total.
This will be truncated and you will lose the 'xt' off the end of the string!
(In other words : you need to make FNAME 12 characters long.)
Hope this helps
Les
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page