Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help me in fortran90 3

Status
Not open for further replies.

hamedpar

Programmer
Jun 13, 2009
8
IR
I had a problem on my program
this is my program:

program iso
implicit none

real , dimension(1000) :: St01,St02
integer :: k

X1=0.05 (variable & Changeable)
X2=0.1 (variable & Changeable)

open(1,file='D:\X1\ST01_drift.txt')
open(2,file='D:\X2\ST02_drift.txt')

Do k = 1,1000
read(1,*) st01(k)
end do

Do k = 1,1000
read(2,*) st02(k)
end do

end program iso


the problem is that my program can not read ST01_drift.txt and ST02_drift.txt form folders with name 0.05 and 0.1
in other words, folders 0.05 and 0.1 contains ST01_drift.txt and ST02_drift.txt
and in "open" comment, folders 0.05 and 0.1 should be opened with variables X1 and X2.
I don't know what kind of Variable X1 and X2 must be defined.for example REAL or CHARACTER or other things like these.
 
Not sure if I'm missing something.
Code:
program iso
implicit none

real , dimension(1000) :: St01,St02
integer :: k

open(1,file='D:\0.05\ST01_drift.txt')
open(2,file='D:\0.1\ST02_drift.txt')

Do k = 1,1000
read(1,*) st01(k)
end do

Do k = 1,1000
read(2,*) st02(k)
end do

end program iso
Alternatively, if you want the values of X1 and X2 in a string, you have to be consistent about it. If you always stick to 2 decimal places, it would help, so instead of 0.1, have it as 0.10. Then you could do something like
Code:
character*64 filename1, filename2
100 format ('D:\',F4.2,'\ST0',I1,'_drift.txt')
write(filename1, 100) X1, 1 
write(filename2, 100) X2, 2
...
open(1,file=trim(filename1))
open(2,file=trim(filename2))
...
 
thanks for your help .here are some questions:
1.where can I assign X1=0.05 and X2=0.10?
2.when I ran this code,it show what variables X1 and X2 are?(we did not defined X1 and X2 in the begining of the program)
 
You can assign them anywhere before you use them. Alternatively, you could have them as parameters (constants)
Code:
program iso
implicit none
real , dimension(1000) :: St01,St02
integer :: k
real, parameter:: X1 = 0.05, X2 = 0.1
character*64 filename1, filename2

100 format ('D:\',F4.2,'\ST0',I1,'_drift.txt')

write(filename1, 100) X1, 1
write(filename2, 100) X2, 2

open(1,file=trim(filename1))
open(2,file=trim(filename2))

Do k = 1,1000
   read(1,*) st01(k)
end do
Do k = 1,1000
   read(2,*) st02(k)
end do
end program iso
 
I have some folders with name like this:(2V or 4G or 9D)
the first part is number ,the second part is letter.what kind of variable I should define for "folder" variable??
how can I assign for example 2V to "folder"??(folder=2V)
I defined it as (F2.0) but it seems to be wrong





11 format ('D:\',F2.0,'\result.txt')
write(filename1, 11) folder
 
You can specify X1 and X2 as character string

character*12 X1,X2
integer*2 lenX1,lenX2
X1 = '2V'
X2 = '4G'
lenX1 = len_trim(X1)
lenX2 = len_trim(X2)
write(filename1,100) X1(1:lenX1),1
write(filename2,100) X1(1:lenX2),2
100 format('D:\',A,'\ST0',I1,'_drift.txt')
c ... etc ...
 
thanks for your help.This is an other problem.it does not refer to X1 and X2.I didi not use X1 and X2.
[I have some folders with name like this:(2V or 4G or 9D)
the first part is number ,the second part is letter.what kind of variable I should define for "folder" variable??
how can I assign for example 2V to "folder"??(folder=2V)
I defined it as (F2.0) but it seems to be wrong ]


folder=2V
...
11 format ('D:\',F2.0,'\result.txt')
write(filename1, 11) folder
 
Try this:

character*2 folder
folder = '2V'
write(filename1,11) folder
11 format('D:\',A,'\result.txt')

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top