Fortran-write file to directory other than current

  • Context: Fortran 
  • Thread starter Thread starter ign
  • Start date Start date
  • Tags Tags
    Current File
Click For Summary
SUMMARY

The discussion focuses on writing output files from a Fortran 90 program to a specific directory instead of the current working directory. The user initially faced challenges in managing output files but resolved the issue by declaring a character variable for the path to the desired output folder. By concatenating this path with the file name in the open statement, the user successfully redirected the output files to the specified directory on the desktop.

PREREQUISITES
  • Understanding of Fortran 90 syntax and file handling
  • Familiarity with character string manipulation in Fortran
  • Basic knowledge of file system paths in Unix-like operating systems
  • Experience with output management in programming
NEXT STEPS
  • Learn about Fortran file I/O operations in detail
  • Explore advanced string manipulation techniques in Fortran
  • Research best practices for organizing output files in programming
  • Investigate error handling in Fortran file operations
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers managing file outputs, and anyone looking to improve their file handling practices in Fortran applications.

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 :)
 

Similar threads

Replies
81
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K
  • · 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
7K