Opened 4 years ago

Closed 4 years ago

#371 closed defect (fixed)

exception is raised when NBUFF is not divisible by the number of forcing timesteps

Reported by: ajornet Owned by: jgipsl
Priority: major Milestone: ORCHIDEE 2.0
Component: Driver files Version: trunc
Keywords: nbuff Cc:

Description

The call NF90_GET_VAR (located in IOIPSL flinget_mat) call fails when NBUFF is not divisible by the total number of forcing file timesteps. This happens in the last iteration. When the requested timesteps (NBUFF) are bigger than the remaing part to be read.
NF90_GET_VAR is requested to read more values than actually found in the netcdf forcing file.

IOIPSL does not check the returning error code. Those uncontrolled values go back to Orchidee. Eventualy fails due to the inconsistency.

This can be reproduced:

In run.def:

  • Forcing_file.nc: input forcing file of 1460 timesteps
  • NBUFF: 15

Modify IOIPSL/src/flincom.f90 so it stops when the call returns an error:

[p529jorn@curie70 src]$ svn diff
Index: flincom.f90
===================================================================
--- flincom.f90	(revision 4284)
+++ flincom.f90	(working copy)
@@ -1612,6 +1612,11 @@
     iret = NF90_GET_VAR (fid, vid, var_tmp, &
              start=w_sta(:), count=w_len(:))
 !---
+    IF (iret /= NF90_NOERR) THEN
+        WRITE(ipslout,*) 'flinget_mat 2.9 : ',NF90_STRERROR (iret)
+        CALL ipslerr(3, 'flinget_mat','Error on netcdf NF90_GET_VAR','', '')
+    ENDIF
+!---
     itau_len=itau_fin-itau_dep+1
     IF (l_dbg) WRITE(ipslout,*) 'flinget_mat 3.0 : clen, itau_len ',clen,itau_len
     var(:) = mis_v
@@ -1630,9 +1635,14 @@
   ELSE
     iret = NF90_GET_VAR (fid, vid, var, &
              start=w_sta(:), count=w_len(:))
+
+    IF (iret /= NF90_NOERR) THEN
+        WRITE(ipslout,*) 'flinget_mat 3.1 : ',NF90_STRERROR (iret)
+        CALL  ipslerr(3, 'flinget_mat','Error on netcdf NF90_GET_VAR','Read in netcdf failed', '')
+    ENDIF
   ENDIF
 !-
-  IF (l_dbg) WRITE(ipslout,*) 'flinget_mat 3.1 : ',NF90_STRERROR (iret)
+  IF (l_dbg) WRITE(ipslout,*) 'flinget_mat 3.2 : ',NF90_STRERROR (iret)
 !--------------------------
 END  SUBROUTINE flinget_mat
 !-

Change History (3)

comment:1 Changed 4 years ago by ajornet

Suggested modification in flinget_buffer to allow any NBUFF value:

  • It checks for the latest part so it is properly read
  • It resizes the buffer when required to avoid using extra memory
[p529jorn@curie70 MICT_HEAD]$ svn diff src_driver/readdim2.f90
Index: src_driver/readdim2.f90
===================================================================
--- src_driver/readdim2.f90	(revision 4375)
+++ src_driver/readdim2.f90	(working copy)
@@ -2502,6 +2502,8 @@
     LOGICAL, SAVE   :: first=.TRUE.                          !! First call to this subroutine
     INTEGER         :: index                                 !! Index in data_buffer for current variable
     INTEGER         :: i, ierr                               !! Loop and error variables
+    INTEGER         :: tsend                                 !! Ending timestep
+    INTEGER         :: new_buf_sz                            !! New buffer size
     
     
     !! 1. Initialization
@@ -2582,7 +2584,20 @@
        ! Reading of forcing file will now be done
        ! First recalculate index to be read
        data_buffer(index)%istart = itb
-       data_buffer(index)%iend   = itb + nbuff - 1
+
+       tsend = itb + nbuff - 1
+       ! when NBUFF is not divisible by total forcing timesteps it requires some extra management 
+       ! This avoid requesting more data at the end of the simulation 
+       IF (tsend > ttm) tsend = ttm 
+       new_buf_sz = tsend-itb+1
+
+       ! Resize data buffer
+       IF (SIZE(data_buffer(index)%data, DIM=3) .NE. new_buf_sz ) THEN
+         DEALLOCATE(data_buffer(index)%data)
+         ALLOCATE (data_buffer(index)%data(iim_full,jjm_full, new_buf_sz), stat=ierr )
+         IF (ierr /= 0) CALL ipslerr_p(3,'flinget_buffer','pb alloc data_buffer%data','for variable=',varname)
+       ENDIF
+       data_buffer(index)%iend   = tsend 
        
 !       WRITE(numout,*) 'Now do flinget for ',varname,', itb=',itb,', istart=',&
 !            data_buffer(index)%istart,', iend=',data_buffer(index)%iend

comment:2 Changed 4 years ago by jgipsl

  • Milestone changed from orchidee_1_9_6 to ORCHIDEE 2.0
  • Owner changed from somebody to jgipsl
  • Status changed from new to assigned

comment:3 Changed 4 years ago by jgipsl

  • Resolution set to fixed
  • Status changed from assigned to closed

done in the trunk rev [4621]

Note: See TracTickets for help on using tickets.