INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Looping Through Dates

Looping Through Dates

(OP)
Hi, I am relatively new to Fortran and would like to run a script through multiple files that represent data on different dates. I would like to read in a .csv file with a different date per row, and then replace the input and output file names of my script with each of those dates and run the script. Any help would be greatly appreciated. I've attached the script that I would like to run, where you can see that the input and output files have dates in them that need to change with the dates from the dates from another .csv file (not included in this script).

PROGRAM convert_rfe_bin2asc

REAL*4 rfe(751,801),arr(3,601551)
real*4 lat,lon
INTEGER:: i,j,ind
character*30:: input_file

input_file="C:\all_products_20010213.bin"

do i = 1,751
do j = 1,801
rfe (i,j) = -999
end do
end do

open (unit=22,file=input_file,access="direct",
1 convert='big_endian',status="old",recl=751*801*4)
read (22, rec=1) rfe

open (88,file="C:\WorldCover\Data\Output\output_20010213.csv",
1 access='sequential',status='unknown',form='formatted')

ind=1
lat= -40.0
lon= -20.0
do j=1,801
do i=1,751
arr(1,ind)=lat
arr(2,ind)=lon
arr(3,ind)=rfe(i,j)

write (88,499) arr(1,ind), arr(2,ind), arr(3,ind)
499 format(1X,f6.2,1X,f6.2,1X,f8.2)

ind=ind+1
lon=lon+0.1
end do
lat=lat+0.1
lon=-20.0
end do

END PROGRAM

RE: Looping Through Dates

You need to put together the name of the input/output files using what is called "internal write"...basically, you write to a string variable instead of to a unit number.

Or, instead of reading dates from the input file, you could list the actual file names into a single file and read them directly from there...a bit of string manipulation and you can derive the output file name based on the name of the input file.

Putting together file names programmaticly, on-the-fly, has already been discussed here and there; do a search.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close