Fortran Fortran-write file to directory other than current

  • Thread starter Thread starter ign
  • Start date Start date
  • Tags Tags
    Current File
Click For Summary
To direct output files from a Fortran F90 program to a specific folder, users can declare a path variable that specifies the desired output directory. In this case, the path was set as CHARACTER*29 :: path='/home/.../output/'. By concatenating this path with the desired file name using the union slashes (//), the output files can be organized neatly in the specified folder. For example, the open statement was modified to open(unit=3, file=path//val(i,1)//'_Brutes_lowD.txt', status='unknown'). This approach effectively keeps the program directory clean and manages outputs efficiently.
ign
Messages
5
Reaction score
0
Hello,

I am running a fortran f90 program and am writing outputs to several files,
the thing is I would like them to be written to a specific folder to better manage outputs
and so leaving the program directory clean.

here's a sample write sentence:

open(unit=3, file=val(i,1)//'_Brutes_lowV_thr_5_10_15.txt', status='replace')
do h=1, size(pmv)
write(3,*) YearList(h), pmv(h), lowV(h,:)
enddo
close(3)

where do I add instructions so that the file is written say in
an output folder located on the desktop (/home/ign/desktop/output)?

thank you in advance,
ign
 
Technology news on Phys.org
solved the problem!

and to make it cleaner I declared a path

CHARACTER*29 :: path='/home/.../output/'

I then added path (followed by union slashes //) at the beginning of the file name

open(unit=3, file=path//val(i,1)//'_Brutes_lowD.txt', status='unknown')
 
Thanks. this solved my problem too :)
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
81
Views
7K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 19 ·
Replies
19
Views
6K