Sponsored Content
Top Forums Programming FORTRAN: Loop over variable file names Post 302942167 by saleheen on Friday 24th of April 2015 11:55:23 PM
Old 04-25-2015
Hi Don

Thanks a lot for you reply. 'T' is an array, I've defined the elements initially. 'r' is number of input files of that species (here 'reac') I have. It prompts me for how many species of reactant I have. It doesn't stop without printing 'reac-2', what it does is for a single temperature it prints for reac-1, then reac-2. And then when it goes for a new temperature, it prints
Code:
This is for temperature: 298

, then
Code:
This is for reac- 1

and than it stops. That's why I was thinking it's dying in the "file loop". I'm posting a part of the code in case you want to have a look at it.
Code:
program check
implicit none


! Setting up parameters and necessary conversion factors
real,parameter::h=4.135667516e-15;            		    ! planck's constant in eVs
real,parameter::c=3.0e10;                           	            ! velocity of light in cm/s
real,parameter::kb=8.6173324e-5;                            ! boltzmann's constant in eV/K

							
integer, parameter:: dp = selected_real_kind(15, 307)
real(dp),allocatable::zper(:)					! zero point energy array 
real(dp),allocatable::zpcr(:)				! zero point corrected energy
real(dp),allocatable::qvibr(:)
real(dp)::zpcrtot=0.0					! total zero point corrected energy 

integer::i,j
integer::r
character(len=20)::filename	
integer::ierror,alloc_err,nlines,nless,array_t
real(dp)::scf,vibmulti,freqtot
real(dp),allocatable::freq(:),vib(:)
real(dp)::T(29) =(/(array_t,array_t=273,973,25)/)



write(*,*)"How many reactants do you have?"
read(*,*)r


!allocate proper dimension to all zero point arrays
allocate(zper(r))
allocate(zpcr(r))
allocate(qvibr(r))

! Loop through reactant files

do j= 1,29 !temp loop

write(*,*)"This is for temperature: ",T(j)
    
  do i=1,r	! file loop
  write(filename,100)i
  100 format('reac-',I1)											! get filenames

	write(*,*)"This is for reac-",i
     
	freqtot=0														! initializing total frequency value
	vibmulti=1														!
    ! Count no of lines	
	nlines=0
	OPEN(unit=10,file=filename,status='old',action='read',&
	 iostat=ierror)
			do	! count loop
            read(10,*,iostat=ierror)
             if (ierror /= 0) exit
  			nlines=nlines+1
            end do !end count loop
	CLOSE(unit=10)
	
	! Count no of frequency elements
	nless=nlines-1
	
	!allocate a dimension to frquency array
	allocate(freq(nless))
	allocate(vib(nless))
	
	OPEN(unit=10,file=filename,status='old',action='read',&
	 iostat=ierror)

			read(10,*,iostat=ierror) scf
			
			do  	! freq loop
            read(10,*,iostat=ierror) freq(nless)
            if (ierror /= 0) exit
          	if (freq(nless) < 100) then
              	freq(nless) = 100
            end if            
            
			freqtot=freqtot+freq(nless)
            			           
			vib(nless)= 1/(1-exp(-h*c*freq(nless)/kb/T(j)))
            
            vibmulti=vib(nless)*vibmulti
			
	     	end do	!end freq loop
     
     deallocate (freq,stat=alloc_err) 
     deallocate (vib,stat=alloc_err)      		
     CLOSE(10)


zper(i)= 0.5*h*c*freqtot												! zero point energy
zpcr(i)= scf + zper(i)													! zero point correction
zpcrtot= zpcrtot+zpcr(i)												! total sum of zero point corrected energies of reactants												

write(*,*)"ZPER", zper(i)
write(*,*)"ZPCR", zpcr(i)
write(*,*)"ZPCRTOT", zpcrtot
write(*,*)"Vib.P.F for reac",i,vibmulti  
qvibr(i)=vibmulti
write(*,*)"This is test qvib: ", qvibr(i) 

	end do	! end file loop
    
write(*,*) "Try product: ",PRODUCT(qvibr)

deallocate (qvibr,stat=alloc_err)     
deallocate (zper,stat=alloc_err) 
deallocate (zpcr,stat=alloc_err)

end do  ! end temp loop

end program check

Again thanks a lot!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Variable assignment for file names.

I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension. for file in... (2 Replies)
Discussion started by: jagannatha
2 Replies

2. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

3. Shell Programming and Scripting

Problem with File Names under tcsh loop

Hello, I have a question regarding file naming under a loop in tcsh. I have the following code: #!/bin/tcsh foreach file (test/ProteinDirectory/*) # The * is a bunch of ProteinFile1, ProteinFile2, ProteinFile3, etc. sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh $file $file ... (4 Replies)
Discussion started by: InfoSeeker
4 Replies

4. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

5. Shell Programming and Scripting

How to make dynamic variable names for use in while loop?

i=0 while do sizesfor0=`cat 16 | grep 'pickSize' -A 1 | grep '_sz' | cut -d'_' -f1` sizesfor0=${sizesfor0//id=\"lll/:} IFS=: array0=( $sizesfor0 ) echo ${array0} i=$(( $i + 1 )) done So, right now I have two variables in the while statement above sizesfor0 and array0 The... (1 Reply)
Discussion started by: phpchick
1 Replies

6. Shell Programming and Scripting

Print file names in a loop

OS : RHEL 6.1 Shell : Bash I have lots of files in /tmp/stage directory as show below. Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ? # pwd /tmp/stage # # # ls -l * -rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies

7. UNIX for Dummies Questions & Answers

How to remove first few characters from multiple file names without do loop?

Hi Fellows, I was wondering how I can remove first few characters from multiple file names without do loop in unix? e.g. water123.xyz water456.xyz to 123.xyz 456.xyz Thanks Paul Thanks. (3 Replies)
Discussion started by: Paul Moghadam
3 Replies

8. Shell Programming and Scripting

Using nested for loop to iterate over file names

I'm trying to grab a list of file names from a directory, then process those files 5 at a time. In the link below. Instead of using files I'm using the files array which contains 15 strings starting with AAA. So I'm trying to assign $fileset 5 of the strings at a time to pass to a command. So... (4 Replies)
Discussion started by: zBernie
4 Replies

9. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

10. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies
All times are GMT -4. The time now is 02:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy