LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-07-2010, 11:46 PM   #1
vjramana
Member
 
Registered: Sep 2009
Posts: 89

Rep: Reputation: 0
generating files with different names at each loop in fortran


Hi,

I am trying to write a loop to open four main-data-files. At each open of the main-data-file, I want the loop to open another four sub-files and split the data from the mail-data-file according to the creteria and dump into the four files.
When the loop goes to the second main-data-file, it shall generate another 4 sub-files with different file name. And the process goes on. That means I will have total of 16 sub files for the four main-data-files. Each four files from the 16 files shall have specific name on it.

Based on the code which I given below, I would say when the file at UNIT=100 is opened, 4 new files needed to be opened as well. They are:
maximum_dist_001_064.dat
maximum_dist_065_128.dat
maximum_dist_129_192.dat
maximum_dist_193_256.dat

But at the same time I want this files to be named as

maximum_dist_001_064_100.dat
maximum_dist_065_128_100.dat
maximum_dist_129_192_100.dat
maximum_dist_193_256_100.dat

In the calling of second file, UNIT=101, I want another four files to open and named as below:

maximum_dist_001_064_101.dat
maximum_dist_065_128_101.dat
maximum_dist_129_192_101.dat
maximum_dist_193_256_101.dat

And the process goes on. I have tried to write the code as below but it doesnt seems to work.

Code:
program final
implicit none
!
integer :: i,j, k, m, jj, kk
integer, parameter :: dist_lines=256
real, DIMENSION(dist_lines) :: dist

! main-data-files
open(unit=100,status="old",file="selected_MAXdista nce_only_malto_THERMO_1st.dat")
open(unit=101,status="old",file="selected_MAXdista nce_only_malto_THERMO_2nd.dat")
open(unit=102,status="old",file="selected_MAXdista nce_only_malto_THERMO_3rd.dat")
open(unit=103,status="old",file="selected_MAXdista nce_only_malto_THERMO_4th.dat")

do kk = 100,103

! sub-files
     open(unit=(10+kk), file="maximum_dist_001_064.dat")
     open(unit=(11+kk), file="maximum_dist_065_128.dat")
     open(unit=(12+kk), file="maximum_dist_129_192.dat")
     open(unit=(13+kk), file="maximum_dist_193_256.dat")

     read(kk,'(F8.3)') (dist(i), i = 1,dist_lines)

       do k = 1, 256

        if (k < 65 ) then
          write ((kk+10),'(F8.3)'), dist(k)
        elseif ( k >=65 .and. k < 129 ) then
          write( (kk+11),'(F8.3)'), dist(k)
        elseif ( k >=129 .and. k < 193 ) then
          write ((kk+12),'(F8.3)'), dist(k)
        elseif ( k >=193 .and. k < 257 ) then
          write ((kk+13),'(F8.3)'), dist(k)
        end if


     end do

end do

stop
end
Could anyone help me in this matter?
Many thanks in advance.

Regards
Vijay
 
Old 11-09-2010, 12:14 PM   #2
sylvain.mazet
LQ Newbie
 
Registered: Aug 2006
Posts: 6

Rep: Reputation: 0
I had a quick look,

but first: you are not closing the files.

then: your unit numbers overstep each other
between loops:

UNIT=110, 111, 112, 113 in the first pass of the loop
UNIT=111, 112, 113, 114 in the second pass of the loop
This is not good, you should either
- close the files at end of each loop
- or renumber the units.

Hope this helps,
S.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save the results of a fortran loop in a text file simpleman0982 Programming 2 11-02-2010 11:40 PM
For loop in bash using ls to get array of file names bioinformatics_guy Linux - Newbie 5 02-19-2009 10:49 AM
Need help with a little bash script - generating unique folder names Shay Linux - Software 4 10-31-2008 10:07 PM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM
loop for generating var names ? Dominik Programming 1 12-11-2003 04:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration