Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problem

Status
Not open for further replies.

hd7

Programmer
Sep 10, 2015
2
AT
Hello everyone,

I have a fortran code which reads an ascii file with data of rainfall for the years from 1993 to 2014. I need to count number of dry and wet days in every month. I have posted my code here. I am not getting any error but the code does not count the number of dry and wet days correctly. I don't know what is wrong with my code. Can anyone help me in figuring out this? Thanks in advance.
 
 http://files.engineering.com/getfile.aspx?folder=5c7bc359-6909-463b-ad6b-b5e2966e4696&file=wetdry.f03
If the data gives the rainfall for the date, then why are you doing range checks on j? You don't even need to read the data into an array. Just do something like this
Code:
program wetanddry
integer, parameter:: np=8035
integer rainfall(12), year, month, day, rain
do mm = 1,12
   rainfall(mm) = 0
end do

open(233,file="11804_separate.text",status="unknown")
do i=1,np
   read(233,*)year,month,day,rain
   if (rain==-1) then
      rain = 0
   else
      ! are you changing mm to cm?
      rain = 0.1*rain
   end if
   rainfall(month) = rainfall(month) + rain;
end do
close(233)
do mm = 1, 12
   print  *, 'Month ', mm, ' rain ', rainfall(mm)
end do

end
 
Hi,
Thanks for your reply and suggestion. I used array because I need number of rainy days in every month. And the data is available for leap years. So I need to put conditions for leap years and NO leap years.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top