Index: /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90
===================================================================
--- /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 3495)
+++ /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zrem.F90	(revision 3496)
@@ -318,5 +318,5 @@
           zrfact2 = 1.e3 * rfact2r
           CALL iom_put( "REMIN" , zolimi(:,:,:) * tmask(:,:,:) * zrfact2 )  ! Remineralisation rate
-          CALL iom_put( "DENIT" , denitr(:,:,:) * tmask(:,:,:) * zrfact2  )  ! Denitrification
+          CALL iom_put( "DENIT" , denitr(:,:,:) * rdenit * rno3 * tmask(:,:,:) * zrfact2  )  ! Denitrification
       ENDIF
 
Index: /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90
===================================================================
--- /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 3495)
+++ /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsed.F90	(revision 3496)
@@ -38,4 +38,6 @@
    REAL(wp) :: r1_rday                  !: inverse of rday
 
+   INTEGER ::  numnit  
+
 
    !!* Substitution
@@ -70,4 +72,7 @@
       REAL(wp) ::  zsiloss, zcaloss, zwsbio3, zwsbio4, zwscal, zdep, zwstpoc
       REAL(wp) ::  ztrfer, ztrpo4, zwdust
+!!Ch  
+      REAL(wp) ::  zrdenittot, zsdenittot, znitrpottot, znitrfix
+!!Ch  
       CHARACTER (len=25) :: charout
       REAL(wp), POINTER, DIMENSION(:,:  ) :: zpdep, zsidep, zwork1, zwork2, zwork3, zwork4
@@ -83,4 +88,5 @@
          r1_rday  = 1. / rday
          r1_ryyss = 1. / ryyss
+         IF(lwp) CALL ctl_opn( numnit, 'nitrogen.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
       ENDIF
       !
@@ -127,6 +133,6 @@
             zirondep(:,:,1) = dustsolub  * dust(:,:) * rfact2 / fse3t(:,:,1) / ( 55.85 * rmtss ) + 3.e-10 * r1_ryyss 
          ENDIF
-         zsidep(:,:) = 8.8 * 0.075 * dust(:,:)        * rfact2 / fse3t(:,:,1) / ( 28.1  * rmtss )
-         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) / po4r * rfact2 / fse3t(:,:,1) / ( 31.   * rmtss )
+         zsidep(:,:) = 8.8 * 0.075 * dust(:,:) * rfact2 / fse3t(:,:,1) / ( 28.1  * rmtss )
+         zpdep (:,:) = 0.1 * 0.021 * dust(:,:) * rfact2 / fse3t(:,:,1) / ( 31.   * rmtss )
          !                                              ! Iron solubilization of particles in the water column
          zwdust = 0.005 / ( wdust * 55.85 * 30.42 ) / ( 45. * rday ) 
@@ -327,4 +333,14 @@
       END DO
  
+      ! The total gain from nitrogen fixation is scaled to balance the loss by denitrification
+      ! -------------------------------------------------------------
+      zrdenittot   = glob_sum ( denitr(:,:,:) * rdenit * xnegtr(:,:,:) * cvol(:,:,:) )
+      zsdenittot   = glob_sum ( zwork4(:,:)   * e1e2t(:,:) )
+      znitrpottot  = glob_sum ( znitrpot(:,:,:)                        * cvol(:,:,:) )
+      IF( kt == nitend .AND. jnt == nrdttrc ) THEN
+         zfact = 1.e+3 * rfact2r * rno3 * 365. * 86400. * 14. / 1e12
+         IF(lwp) WRITE(numnit,9100) ndastp, znitrpottot * nitrfix * zfact, zrdenittot * zfact , zsdenittot * zfact
+      ENDIF
+
       ! Nitrogen change due to nitrogen fixation
       ! ----------------------------------------
@@ -362,4 +378,6 @@
       IF( nn_timing == 1 )  CALL timing_stop('p4z_sed')
       !
+ 9100  FORMAT(i8,3f10.5)
+      !
    END SUBROUTINE p4z_sed
 
Index: /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90
===================================================================
--- /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 3495)
+++ /branches/2012/dev_r3438_LOCEAN15_PISLOB/NEMOGCM/NEMO/TOP_SRC/PISCES/P4Z/p4zsms.F90	(revision 3496)
@@ -37,10 +37,6 @@
 
    LOGICAL ::  ln_check_mass = .false.       !: Flag to check mass conservation 
-
-   INTEGER ::  numno3  !: logical unit for NO3 budget
-   INTEGER ::  numalk  !: logical unit for talk budget
-   INTEGER ::  numsil  !: logical unit for Si budget
-   INTEGER ::  numfer  !: logical unit for Fer budget
-   INTEGER ::  numco2  !: logical unit for co2 budget
+   REAL(wp) :: alkbudget, no3budget, silbudget, ferbudget
+   INTEGER ::  numco2, numnut  !: logical unit for co2 budget
 
    !!----------------------------------------------------------------------
@@ -84,5 +80,5 @@
       IF( ln_rsttr  .AND. ln_pisclo )                              CALL p4z_clo            ! damping on closed seas
       IF( ln_pisdmp .AND. MOD( kt - nn_dttrc, nn_pisdmp ) == 0 )   CALL p4z_dmp( kt )      ! Relaxation of some tracers
-                                                                   CALL p4z_chk_mass( kt ) ! Mass conservation checking
+      !
       IF( ndayflxtr /= nday_year ) THEN      ! New days
          !
@@ -148,19 +144,8 @@
       END IF
       !
-       !
-       IF( kt == nitend ) THEN
-         !
-         t_atm_co2_flx  = t_atm_co2_flx / glob_sum( e1e2t(:,:) )
-         t_oce_co2_flx  = t_oce_co2_flx         * 12. / 1.e15 * (-1 )
-         tpp            = tpp           * 1000. * 12. / 1.E15
-         t_oce_co2_exp  = t_oce_co2_exp * 1000. * 12. / 1.E15
-         !
-         IF(lwp) WRITE(numco2,9000) ndastp, t_atm_co2_flx, t_oce_co2_flx, tpp, t_oce_co2_exp
-         !
-      ENDIF
+      CALL p4z_chk_mass( kt ) ! Mass conservation checking
 
       IF( nn_timing == 1 )  CALL timing_stop('p4z_sms')
       !
- 9000  FORMAT(i8,f10.5,e18.10,f10.5,f10.5)
       !
    END SUBROUTINE p4z_sms
@@ -362,6 +347,4 @@
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
       !!
-      REAL(wp) :: zalkbudget, zno3budget, zsilbudget, zferbudget
-      !
       NAMELIST/nampismass/ ln_check_mass
       !!---------------------------------------------------------------------
@@ -378,14 +361,11 @@
 
          IF( ln_check_mass .AND. lwp) THEN      !   Open budget file of NO3, ALK, Si, Fer
-            CALL ctl_opn( numno3, 'no3.budget' , 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-            CALL ctl_opn( numsil, 'sil.budget' , 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-            CALL ctl_opn( numalk, 'talk.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-            CALL ctl_opn( numfer, 'iron.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+            CALL ctl_opn( numco2, 'carbon.budget'  , 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+            CALL ctl_opn( numnut, 'nutrient.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
          ENDIF
-         IF(lwp) CALL ctl_opn( numco2, 'carbon.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
-      ENDIF
-
-      IF( ln_check_mass ) THEN      !   Compute the budget of NO3, ALK, Si, Fer
-         zno3budget = glob_sum( (   trn(:,:,:,jpno3) + trn(:,:,:,jpnh4)  &
+      ENDIF
+
+      IF( ln_check_mass .AND. kt == nitend ) THEN      !   Compute the budget of NO3, ALK, Si, Fer
+         no3budget = glob_sum( (   trn(:,:,:,jpno3) + trn(:,:,:,jpnh4)  &
             &                     + trn(:,:,:,jpphy) + trn(:,:,:,jpdia)  &
             &                     + trn(:,:,:,jpzoo) + trn(:,:,:,jpmes)  &
@@ -397,12 +377,12 @@
             &                     + trn(:,:,:,jpdoc)                     ) * cvol(:,:,:)  ) 
          ! 
-         zsilbudget = glob_sum( (   trn(:,:,:,jpsil) + trn(:,:,:,jpgsi)  &
+         silbudget = glob_sum( (   trn(:,:,:,jpsil) + trn(:,:,:,jpgsi)  &
             &                     + trn(:,:,:,jpdsi)                     ) * cvol(:,:,:)  )
          ! 
-         zalkbudget = glob_sum( (   trn(:,:,:,jpno3) * rno3              &
+         alkbudget = glob_sum( (   trn(:,:,:,jpno3) * rno3              &
             &                     + trn(:,:,:,jptal)                     &
             &                     + trn(:,:,:,jpcal) * 2.                ) * cvol(:,:,:)  )
          ! 
-         zferbudget = glob_sum( (   trn(:,:,:,jpfer) + trn(:,:,:,jpnfe)  &
+         ferbudget = glob_sum( (   trn(:,:,:,jpfer) + trn(:,:,:,jpnfe)  &
             &                     + trn(:,:,:,jpdfe) + trn(:,:,:,jpbfe)  &
             &                     + trn(:,:,:,jpsfe) +                   &
@@ -410,13 +390,24 @@
             &                     + trn(:,:,:,jpmes) * ferat3            ) * cvol(:,:,:)  )
 
-         IF( lwp ) THEN
-            WRITE(numno3,9500) kt,  zno3budget / areatot
-            WRITE(numsil,9500) kt,  zsilbudget / areatot
-            WRITE(numalk,9500) kt,  zalkbudget / areatot
-            WRITE(numfer,9500) kt,  zferbudget / areatot
+         !
+         t_atm_co2_flx  = t_atm_co2_flx / glob_sum( e1e2t(:,:) )
+         t_oce_co2_flx  = t_oce_co2_flx         * 12. / 1.e15 * (-1 )
+         tpp            = tpp           * 1000. * 12. / 1.E15
+         t_oce_co2_exp  = t_oce_co2_exp * 1000. * 12. / 1.E15
+         !
+         no3budget = no3budget / areatot
+         silbudget = silbudget / areatot
+         alkbudget = alkbudget / areatot
+         ferbudget = ferbudget / areatot
+         !
+         IF(lwp) THEN
+            WRITE(numco2,9000) ndastp, t_atm_co2_flx, t_oce_co2_flx, tpp, t_oce_co2_exp
+            WRITE(numnut,9500) ndastp, alkbudget, no3budget, silbudget, ferbudget
          ENDIF
-       ENDIF
+         !
+      ENDIF
        !
- 9500  FORMAT(i10,e18.10)     
+ 9000  FORMAT(i8,f10.5,e18.10,f10.5,f10.5)
+ 9500  FORMAT(i8,4e18.10)     
        !
    END SUBROUTINE p4z_chk_mass
