diff --git a/src/MNH/modd_lunitn.f90 b/src/MNH/modd_lunitn.f90 index f10bfbf1072220c2b66a27d4dbf71aae99a6cb3f..cee189b4bdcc42cbadf0710619083a68b6761765 100644 --- a/src/MNH/modd_lunitn.f90 +++ b/src/MNH/modd_lunitn.f90 @@ -83,22 +83,21 @@ USE MODD_IO, ONLY : TFILE_OUTPUTLISTING ! INTEGER, INTENT(IN) :: KFROM, KTO ! -!JUAN +! Save current state for allocated arrays +LUNIT_MODEL(KFROM)%CCPLFILE => CCPLFILE +LUNIT_MODEL(KFROM)%TCPLFILE => TCPLFILE +! IF (LUNIT_FIRST_CALL(KTO)) THEN -ALLOCATE (LUNIT_MODEL(KTO)%CCPLFILE(NPCPLFILEMAX)) -LUNIT_MODEL(KTO)%CCPLFILE(:) = '' -! TCPLFILE allocation is done in ini_cpl directly at the right size => commented here -! ALLOCATE (LUNIT_MODEL(KTO)%TCPLFILE(NPCPLFILEMAX)) -LUNIT_FIRST_CALL(KTO) = .FALSE. + !Do this AFTER saving current state to prevent loss of the correct allocated pointers if KFROM==KTO + ALLOCATE ( LUNIT_MODEL(KTO)%CCPLFILE(NPCPLFILEMAX) ) + LUNIT_MODEL(KTO)%CCPLFILE(:) = '' + ! TCPLFILE allocation is done in ini_cpl directly at the right size => commented here + ! ALLOCATE (LUNIT_MODEL(KTO)%TCPLFILE(NPCPLFILEMAX)) + LUNIT_FIRST_CALL(KTO) = .FALSE. ENDIF -!JUAN ! TFILE_OUTPUTLISTING => LUNIT_MODEL(KTO)%TLUOUT ! -! Save current state for allocated arrays -LUNIT_MODEL(KFROM)%CCPLFILE => CCPLFILE -LUNIT_MODEL(KFROM)%TCPLFILE => TCPLFILE -! ! Current model is set to model KTO CINIFILE=>LUNIT_MODEL(KTO)%CINIFILE TINIFILE=>LUNIT_MODEL(KTO)%TINIFILE