Skip to content

Commit

Permalink
made changes to speed things up when nyrs is large. reduced size of a…
Browse files Browse the repository at this point in the history
…ll_data array by adding another loop.
  • Loading branch information
dmcinern committed Jan 27, 2012
1 parent 0f2a96f commit 7a5bdd8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
55 changes: 38 additions & 17 deletions elliot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ program for_elliot
character :: str_grid_ID*7
real*4 :: solar, precip, tmax, tmin
integer :: time
integer :: n_chunks, nyr_chunk,chunk_start,chunk_end, chunk

!common /dirnames/ temp_source, precip_source, solar_source, bcsd_type, fileroot
!common /data_array/ data

Expand Down Expand Up @@ -100,6 +102,12 @@ program for_elliot

print*

write(str_start_yr,'(i4.4)') start_yr
write(str_end_yr,'(i4.4)') end_yr
write(str_proc_num,'(i1.1)') proc_num
open(unit=2,file=trim(outdir)//'/temp_diag.'//str_start_yr//'_'//str_end_yr//'.p'// &
str_proc_num//'.txt')

! list of variables we will read in
var_list = (/ 'precip', 'solar', 'tmax', 'tmin' /)

Expand All @@ -114,20 +122,35 @@ program for_elliot
data_time_0(v,:,:) = data(:,:,1)
end do

n_chunks = ceiling(float(nyr)/10.)
print*,n_chunks

! calculate number of land points, and which ones will be used by this processor
! this will be moved to start of program when i have land/ocean mask file
! this also copies soil data to new directory
call calc_land_points(data_time_0,proc_num,n_procs, lat, lon, outdir, &
print_point_lat, print_point_lon,n_land_points_all, &
min_land_point_proc,max_land_point_proc, n_land_points_proc)

allocate(all_data(4,n_land_points_proc,nyr*nday))
allocate(all_times(nyr*nday))
!allocate(all_data(4,n_land_points_proc,nyr*nday))
!allocate(all_times(nyr*nday))
!allocate(all_data(4,n_land_points_proc,nday))
!allocate(all_times(nday))

! index used for time in data array
day_start = 1

print*,"reading data"

do chunk = 1, n_chunks

chunk_start = int(1+dble(chunk-1)*dble(n_land_points_proc)/dble(n_chunks))
chunk_end = int(dble(chunk)*dble(n_land_points_proc)/dble(n_chunks))
print*,chunk_start,chunk_end

allocate(all_data(4,chunk_end-chunk_start+1,nyr*nday))
allocate(all_times(nyr*nday))

! loop over years
do iyr = 1, nyr

Expand All @@ -148,10 +171,12 @@ program for_elliot
call read_data(var_name,iyr+start_yr-1)

! copy data from netcdf file to big array of data
do counter = 1, n_land_points_proc
! do counter = 1, n_land_points_proc
do counter = chunk_start,chunk_end
ilat = print_point_lat(counter+min_land_point_proc-1)
jlon = print_point_lon(counter+min_land_point_proc-1)
all_data(v,counter,day_start:day_start+nday_yr-1) = data(jlon,ilat,1:nday_yr)
! all_data(v,counter,day_start:day_start+nday_yr-1) = data(jlon,ilat,1:nday_yr)
all_data(v,counter-chunk_start+1,day_start:day_start+nday_yr-1) = data(jlon,ilat,1:nday_yr)
end do
end do

Expand All @@ -166,17 +191,13 @@ program for_elliot

deallocate(data)

write(str_start_yr,'(i4.4)') start_yr
write(str_end_yr,'(i4.4)') end_yr
write(str_proc_num,'(i1.1)') proc_num
open(unit=2,file=trim(outdir)//'/temp_diag.'//str_start_yr//'_'//str_end_yr//'.p'// &
str_proc_num//'.txt')

print*,"writing data"
do counter = 1,n_land_points_proc
if (mod(counter,int(0.1*float(n_land_points_proc))).eq.0) print*,counter," (",n_land_points_proc,")"
!do counter = 1,n_land_points_proc
do counter = chunk_start,chunk_end
! if (mod(counter,int(0.1*float(n_land_points_proc))).eq.0) print*,counter," (",n_land_points_proc,")"
ilat = print_point_lat(counter+min_land_point_proc-1)
jlon = print_point_lon(counter+min_land_point_proc-1)

grid_ID = floor( 12*lon(jlon) - 51840*lat(ilat) + 4661280.5 )
write(str_grid_ID,'(i7.7)') grid_ID
dirname = trim(outdir)//"/"//str_grid_ID
Expand All @@ -192,10 +213,10 @@ program for_elliot
write(1,'(A)')"@DATE SRAD TMAX TMIN RAIN"
do n=1,day_start-1
time = all_times(n)
solar = all_data(2,counter,n)*0.0864
tmax = all_data(3,counter,n)-273.16
tmin = all_data(4,counter,n)-273.16
precip = all_data(1,counter,n)
solar = all_data(2,counter-chunk_start+1,n)*0.0864
tmax = all_data(3,counter-chunk_start+1,n)-273.16
tmin = all_data(4,counter-chunk_start+1,n)-273.16
precip = all_data(1,counter-chunk_start+1,n)

if (tmax < tmin+0.1) then
write(2,*) "lat=",lat(ilat),"lon=",lon(jlon),"time=",time,"tmax_orig=",tmax,"tmin_orig=",tmin
Expand All @@ -206,7 +227,6 @@ program for_elliot
! all_data(4,counter,n)-273.16, all_data(1,counter,n)

write(1,10) time, solar, tmax, tmin, precip


end do
close(1)
Expand All @@ -220,6 +240,7 @@ program for_elliot

end do

end do
10 format(I5.5,F6.1,F6.1,F6.1,F6.1)

end program
Expand Down
4 changes: 2 additions & 2 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This should work for all the historical datasets
set n_time_intervals = 1
set year_start_arr = ( 1980 )
set year_stop_arr = ( 2010 )
set year_stop_arr = ( 20100 )
set fname_arr = ( GENERIC1.WTH )

# The following should work for the CCSM scenarios except for the fact that
Expand All @@ -23,7 +23,7 @@ set solar_source = 'ncep'

set bcsd_type = 'downscaled'

set out_dir = /gpfs/pads/projects/see/data/dssat/grid_ncep/
set out_dir = /gpfs/pads/projects/see/CCSM_Library/nc_test_1/

set n_procs = 8

0 comments on commit 7a5bdd8

Please sign in to comment.