user2717742
user2717742

Reputation: 17

how to define variable name in fortran 90

I'm trying to define variable name via write command in my Fortran code to produce different files, I'm using these commands :

character plotname*100,zbin_str*5          
open(4,file='luminosity_func.asc')  
do j=1,b                      
   mag(j)=mag_min+(j-1)*bin  
   magup(j)=mag(j)+bin               
   kk=0           
loopread: do jj=1,total     
      if (z(i).le.redshift(jj).and.redshift(jj).le.zup(i).and.mag(j).le.mag_i(jj).and.mag_i(jj).le.magup(j)) then               
         vmax=S*dix  
         fi=fi+1/vmax   
         kk=kk+1  
      end if                                                                   
   end do  loopread
   write(4,'(i5,2x,f20.8,2x,3f9.4,2x,2f7.4,2x,2f14.10)')kk,fi,mag_average,mag(j),magup(j),z(i),zup(i)  
end do  loopmag
close(4)

zbin=zmin+(i-1)*step+step/2.           

open(4,file='luminosity_func.asc')                 
open(unit=5,file='plot.sm')                  
write(unit=zbin_str,fmt='(f5.2)') zbin

plotname="LF_z_"//zbin_str//".ps"                      

write(5,"dev postencap "//plotname)                      
write(5,'("data luminosity_func.asc")') 
write(5,'("read {fi 2 mag 3 }")')
write(5,'("define TeX_strings 1")')         
write(5,'("set lfi = lg(fi)")')
write(5,'("ctype blue")') 
write(5,'("vecminmax mag magmin magmax")')
write(5,'("XLABEL mag")')   
write(5,'("YLABEL log\Phi(m)")')
write(5,"toplabel LF for"//zbin_str)    
write(5,'("ptype 12 3 points mag lfi")')
write(5,'("hardcopy")')
close(5)    
call system ("sm < plot.sm")

but while I 'm running the code I'm receiving this error:

forrtl: info (58): format syntax error at or near dev postencap LF_z_ 0.05.ps                                               
forrtl: severe (62): syntax error in format, unit 5, file /home/TES/plot.sm
Image              PC                Routine            Line        Source 
test               00000000004854BE  Unknown               Unknown  Unknown
test               0000000000483F56  Unknown               Unknown  Unknown
test               000000000043DE42  Unknown               Unknown  Unknown
test               000000000040E82B  Unknown               Unknown  Unknown
test               000000000040DD92  Unknown               Unknown  Unknown
test               0000000000431CBB  Unknown               Unknown  Unknown
test               000000000040455B  Unknown               Unknown  Unknown
test               0000000000402E6C  Unknown               Unknown  Unknown
libc.so.6          00000032F401ECDD  Unknown               Unknown  Unknown
test               0000000000402D69  Unknown               Unknown  Unknown

How can I solve this problem ?

Upvotes: 0

Views: 340

Answers (1)

Kyle Kanos
Kyle Kanos

Reputation: 3264

Ignoring the fact that your code as presented does not compile, it appears there are two problems, both containing the same error:

write(5,"dev postencap "//plotname)
write(5,"toplabel LF for"//zbin_str)

While there is no compile-time error, it does present a run-time error that you are getting. You want these lines to be

write(5,'("dev postencap ",a)') plotname
write(5,'("toplabel LF for ",a)') zbin_str

And if you know how many characters are in plotname and zbin_str, you can replace a with aW where W is the number of characters in the string.

Upvotes: 1

Related Questions