ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a 50 file name NSSAVE0001.vtk to NSSAVE0050.vtk.
Do I have to manually type individually command to open each file or can I have a loop to open file?
I have a 50 file name NSSAVE0001.vtk to NSSAVE0050.vtk.
Do I have to manually type individually command to open each file or can I have a loop to open file?
Pretty sure the file name can be in an array, so no reason not to use the loop.
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
GNU bash 3.2.39
gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
-----
Fortran source:
program f1
character*20 :: my_unit
do n=1,5
write(my_unit,"(a,i4.4,a)") "nssave",n,".vtk"
write(*,*) " Preparing to open file: ",my_unit
open(unit=1,file=my_unit,err=100)
end do
stop "f1"
100 continue
write(*,*) " Error in opening file: ", my_unit
end
-----
Compile, link, execute:
Preparing to open file: nssave0001.vtk
Preparing to open file: nssave0002.vtk
Preparing to open file: nssave0003.vtk
Preparing to open file: nssave0004.vtk
Preparing to open file: nssave0005.vtk
STOP f1
-----
Resultant files opened (created):
-rw-r--r-- 1 0 Jun 29 15:35 nssave0001.vtk
-rw-r--r-- 1 0 Jun 29 15:35 nssave0002.vtk
-rw-r--r-- 1 0 Jun 29 15:35 nssave0003.vtk
-rw-r--r-- 1 0 Jun 29 15:35 nssave0004.vtk
-rw-r--r-- 1 0 Jun 29 15:35 nssave0005.vtk
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.