Index: LMDZ4/trunk/libf/phylmd/physiq.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/physiq.F	(revision 1340)
+++ LMDZ4/trunk/libf/phylmd/physiq.F	(revision 1352)
@@ -34,4 +34,6 @@
       use regr_pr_av_m, only: regr_pr_av
       use netcdf95, only: nf95_close
+cIM for NMC files
+      use netcdf, only: nf90_fill_real
       use mod_phys_lmdz_mpi_data, only: is_mpi_root
       USE aero_mod
@@ -53,5 +55,5 @@
 c   CLEFS CPP POUR LES IO
 c   =====================
-c#define histmthNMC
+#define histNMC
 c#define histISCCP
 c======================================================================
@@ -256,10 +258,5 @@
       CHARACTER*4 bb2
       CHARACTER*2 bb3
-c
-      real tlevSTD(klon,nlevSTD), qlevSTD(klon,nlevSTD)
-      real rhlevSTD(klon,nlevSTD), philevSTD(klon,nlevSTD)
-      real ulevSTD(klon,nlevSTD), vlevSTD(klon,nlevSTD)
-      real wlevSTD(klon,nlevSTD) 
-
+c 
       real twriteSTD(klon,nlevSTD,nfiles)
       real qwriteSTD(klon,nlevSTD,nfiles)
@@ -269,4 +266,33 @@
       real vwriteSTD(klon,nlevSTD,nfiles)
       real wwriteSTD(klon,nlevSTD,nfiles)
+cIM for NMC files
+      REAL geo500(klon)
+      real :: rlevSTD3(nlevSTD3)
+      DATA rlevSTD3/85000., 50000., 25000./
+      SAVE rlevSTD3
+c$OMP THREADPRIVATE(rlevSTD3)
+      real :: rlevSTD8(nlevSTD8)
+      DATA rlevSTD8/100000., 85000., 70000., 50000., 25000., 10000.,
+     $     5000., 1000./
+      SAVE rlevSTD8
+c$OMP THREADPRIVATE(rlevSTD8) 
+      real twriteSTD3(klon,nlevSTD3)
+      real qwriteSTD3(klon,nlevSTD3)
+      real rhwriteSTD3(klon,nlevSTD3)
+      real phiwriteSTD3(klon,nlevSTD3)
+      real uwriteSTD3(klon,nlevSTD3)
+      real vwriteSTD3(klon,nlevSTD3)
+      real wwriteSTD3(klon,nlevSTD3)
+c
+      real tnondefSTD8(klon,nlevSTD8)
+      real twriteSTD8(klon,nlevSTD8)
+      real qwriteSTD8(klon,nlevSTD8)
+      real rhwriteSTD8(klon,nlevSTD8)
+      real phiwriteSTD8(klon,nlevSTD8)
+      real uwriteSTD8(klon,nlevSTD8)
+      real vwriteSTD8(klon,nlevSTD8)
+      real wwriteSTD8(klon,nlevSTD8)
+c
+c plevSTD3 END
 c
 c nout : niveau de output des variables a une pression donnee
@@ -276,15 +302,4 @@
 c a partir des valeurs instantannees toutes les 6 h
 c qui sont moyennees sur le mois
-c
-      real uvSTD(klon,nlevSTD)
-      real vqSTD(klon,nlevSTD)
-      real vTSTD(klon,nlevSTD)
-      real wqSTD(klon,nlevSTD)
-c
-      real vphiSTD(klon,nlevSTD)
-      real wTSTD(klon,nlevSTD)
-      real u2STD(klon,nlevSTD)
-      real v2STD(klon,nlevSTD)
-      real T2STD(klon,nlevSTD)
 c
 #include "radopt.h"
@@ -971,5 +986,5 @@
       REAL zx_tmp_fi2d(klon)      ! variable temporaire grille physique
       REAL zx_tmp_fi3d(klon,klev) ! variable temporaire pour champs 3D 
-c#ifdef histmthNMC
+c#ifdef histNMC
 cym   A voir plus tard !!!!
 cym      REAL zx_tmp_NC(iim,jjmp1,nlevSTD)
@@ -979,10 +994,15 @@
       REAL zx_tmp_2d(iim,jjmp1), zx_tmp_3d(iim,jjmp1,klev)
       REAL zx_lon(iim,jjmp1), zx_lat(iim,jjmp1)
-c
-      INTEGER nid_day, nid_mth, nid_ins, nid_nmc, nid_day_seri
-      INTEGER nid_ctesGCM
-      SAVE nid_day, nid_mth, nid_ins, nid_nmc, nid_day_seri
-      SAVE nid_ctesGCM
-c$OMP THREADPRIVATE(nid_day, nid_mth, nid_ins, nid_nmc)
+cIM for NMC files
+      REAL missing_val
+      REAL, SAVE :: freq_moyNMC(nout)
+c$OMP THREADPRIVATE(freq_moyNMC)
+c
+      INTEGER nid_day, nid_mth, nid_ins, nid_mthnmc, nid_daynmc
+      INTEGER nid_hfnmc, nid_day_seri, nid_ctesGCM
+      SAVE nid_day, nid_mth, nid_ins, nid_mthnmc, nid_daynmc
+      SAVE nid_hfnmc, nid_day_seri, nid_ctesGCM
+c$OMP THREADPRIVATE(nid_day, nid_mth, nid_ins)
+c$OMP THREADPRIVATE(nid_mthnmc, nid_daynmc, nid_hfnmc)
 c$OMP THREADPRIVATE(nid_day_seri,nid_ctesGCM)
 c
@@ -1107,4 +1127,6 @@
 !     edges of pressure intervals for ozone climatologies, in Pa, in strictly
 !     ascending order
+cIM for NMC files en parallele
+c$OMP THREADPRIVATE(read_climoz, ncid_climoz, press_climoz)
 
       integer, save:: co3i = 0
@@ -1130,4 +1152,6 @@
 c============================================================
       real :: mr_ozone(klon,klev)
+cIM for NMC files
+      missing_val=nf90_fill_real
 c======================================================================
 ! Ecriture eventuelle d'un profil verticale en entree de la physique.
@@ -1175,4 +1199,6 @@
       print*, 'Allocation des variables locales et sauvegardees'
       call phys_local_var_init
+c
+      pasphys=pdtphys
 c     appel a la lecture du run.def physique
       call conf_phys(ok_journe, ok_mensuel,
@@ -1192,5 +1218,11 @@
       call phys_output_var_init
       print*, '================================================='
-
+cIM for NMC files
+cIM freq_moyNMC = frequences auxquelles on moyenne les champs accumules 
+cIM               sur les niveaux de pression standard du NMC
+      DO n=1, nout
+       freq_moyNMC(n)=freq_outNMC(n)/freq_calNMC(n)
+      ENDDO
+c
 cIM beg
           dnwd0=0.0
@@ -1469,5 +1501,7 @@
 #endif
 
-#ifdef histmthNMC
+#ifdef histNMC
+#include "ini_histhfNMC.h"
+#include "ini_histdayNMC.h"
 #include "ini_histmthNMC.h"
 #endif
@@ -1483,9 +1517,9 @@
 
          ecrit_hf = ecrit_hf * un_jour
-!IM
+cIM
          IF(ecrit_day.LE.1.) THEN
           ecrit_day = ecrit_day * un_jour !en secondes
          ENDIF
-!IM
+cIM
          ecrit_mth = ecrit_mth * un_jour
          ecrit_ins = ecrit_ins * un_jour
@@ -3331,19 +3365,19 @@
 c
 #include "calcul_STDlev.h"
-      twriteSTD(:,:,1)=tsumSTD(:,:,2)
-      qwriteSTD(:,:,1)=qsumSTD(:,:,2)
-      rhwriteSTD(:,:,1)=rhsumSTD(:,:,2)
-      phiwriteSTD(:,:,1)=phisumSTD(:,:,2)
-      uwriteSTD(:,:,1)=usumSTD(:,:,2)
-      vwriteSTD(:,:,1)=vsumSTD(:,:,2)
-      wwriteSTD(:,:,1)=wsumSTD(:,:,2)
-
-      twriteSTD(:,:,2)=tsumSTD(:,:,1)
-      qwriteSTD(:,:,2)=qsumSTD(:,:,1)
-      rhwriteSTD(:,:,2)=rhsumSTD(:,:,1)
-      phiwriteSTD(:,:,2)=phisumSTD(:,:,1)
-      uwriteSTD(:,:,2)=usumSTD(:,:,1)
-      vwriteSTD(:,:,2)=vsumSTD(:,:,1)
-      wwriteSTD(:,:,2)=wsumSTD(:,:,1)
+      twriteSTD(:,:,1)=tsumSTD(:,:,1)
+      qwriteSTD(:,:,1)=qsumSTD(:,:,1)
+      rhwriteSTD(:,:,1)=rhsumSTD(:,:,1)
+      phiwriteSTD(:,:,1)=phisumSTD(:,:,1)
+      uwriteSTD(:,:,1)=usumSTD(:,:,1)
+      vwriteSTD(:,:,1)=vsumSTD(:,:,1)
+      wwriteSTD(:,:,1)=wsumSTD(:,:,1)
+
+      twriteSTD(:,:,2)=tsumSTD(:,:,2)
+      qwriteSTD(:,:,2)=qsumSTD(:,:,2)
+      rhwriteSTD(:,:,2)=rhsumSTD(:,:,2)
+      phiwriteSTD(:,:,2)=phisumSTD(:,:,2)
+      uwriteSTD(:,:,2)=usumSTD(:,:,2)
+      vwriteSTD(:,:,2)=vsumSTD(:,:,2)
+      wwriteSTD(:,:,2)=wsumSTD(:,:,2)
 
       twriteSTD(:,:,3)=tlevSTD(:,:)
@@ -3362,4 +3396,42 @@
       vwriteSTD(:,:,4)=vlevSTD(:,:)
       wwriteSTD(:,:,4)=wlevSTD(:,:)
+c
+cIM initialisation 5eme fichier de sortie 
+      twriteSTD(:,:,5)=tlevSTD(:,:)
+      qwriteSTD(:,:,5)=qlevSTD(:,:)
+      rhwriteSTD(:,:,5)=rhlevSTD(:,:)
+      phiwriteSTD(:,:,5)=philevSTD(:,:)
+      uwriteSTD(:,:,5)=ulevSTD(:,:)
+      vwriteSTD(:,:,5)=vlevSTD(:,:)
+      wwriteSTD(:,:,5)=wlevSTD(:,:)
+cIM for NMC files
+      DO n=1, nlevSTD3
+       DO k=1, nlevSTD
+        if(rlevSTD3(n).EQ.rlevSTD(k)) THEN
+         twriteSTD3(:,n)=tlevSTD(:,k)
+         qwriteSTD3(:,n)=qlevSTD(:,k)
+         rhwriteSTD3(:,n)=rhlevSTD(:,k)
+         phiwriteSTD3(:,n)=philevSTD(:,k)
+         uwriteSTD3(:,n)=ulevSTD(:,k)
+         vwriteSTD3(:,n)=vlevSTD(:,k)
+         wwriteSTD3(:,n)=wlevSTD(:,k)
+        endif !rlevSTD3(n).EQ.rlevSTD(k)
+       ENDDO 
+      ENDDO 
+c
+      DO n=1, nlevSTD8
+       DO k=1, nlevSTD
+        if(rlevSTD8(n).EQ.rlevSTD(k)) THEN
+         tnondefSTD8(:,n)=tnondef(:,k,2)
+         twriteSTD8(:,n)=tsumSTD(:,k,2)
+         qwriteSTD8(:,n)=qsumSTD(:,k,2)
+         rhwriteSTD8(:,n)=rhsumSTD(:,k,2)
+         phiwriteSTD8(:,n)=phisumSTD(:,k,2)
+         uwriteSTD8(:,n)=usumSTD(:,k,2)
+         vwriteSTD8(:,n)=vsumSTD(:,k,2)
+         wwriteSTD8(:,n)=wsumSTD(:,k,2)
+        endif !rlevSTD8(n).EQ.rlevSTD(k)
+       ENDDO 
+      ENDDO 
 c
 c slp sea level pressure
@@ -3521,5 +3593,7 @@
 #endif
 
-#ifdef histmthNMC
+#ifdef histNMC
+#include "write_histhfNMC.h"
+#include "write_histdayNMC.h"
 #include "write_histmthNMC.h"
 #endif
