Index: codes/icosagcm/trunk/arch/arch-X64_CURIE.env
===================================================================
--- codes/icosagcm/trunk/arch/arch-X64_CURIE.env	(revision 346)
+++ codes/icosagcm/trunk/arch/arch-X64_CURIE.env	(revision 347)
@@ -1,6 +1,5 @@
 module unload netcdf
 module unload hdf5
-module load netcdf/4.2_hdf5_parallel
-module load  hdf5/1.8.9_parallel
+module load  netcdf/4.3.3.1_hdf5_parallel 
 module load vampir
 module load vampirtrace
Index: codes/icosagcm/trunk/arch/arch-X64_CURIE.path
===================================================================
--- codes/icosagcm/trunk/arch/arch-X64_CURIE.path	(revision 346)
+++ codes/icosagcm/trunk/arch/arch-X64_CURIE.path	(revision 347)
@@ -11,5 +11,9 @@
 HDF5_LIB="-lhdf5_hl -lhdf5 -lhdf5 -lz -lcurl"
 
-XIOS_INCDIR="-I$WORKDIR/XIOS_COMMIT_V1.7/inc"
-XIOS_LIBDIR="-L$WORKDIR/XIOS_COMMIT_V1.7/lib"
+XIOS_INCDIR="-I $PWD/../XIOS/inc"
+XIOS_LIBDIR="-L $PWD/../XIOS/lib"
 XIOS_LIB="-lxios -lstdc++"
+
+IOIPSL_INCDIR="-I $PWD/../IOIPSL/src"
+IOIPSL_LIBDIR="-L $PWD/../IOIPSL/src"
+IOIPSL_LIB="-lioipsl"
Index: codes/icosagcm/trunk/bld.cfg
===================================================================
--- codes/icosagcm/trunk/bld.cfg	(revision 346)
+++ codes/icosagcm/trunk/bld.cfg	(revision 347)
@@ -13,12 +13,14 @@
 %FFLAGS           %BASE_FFLAGS %COMPIL_FFLAGS
 
-#dest   $PWD
 dir::root            $PWD
 
 src::src	src
-src::ioipsl	tools/ioipsl
+src::ioipsl	%IOIPSL_PATH
 search_src           false
-bld::lib::ioipsl ioipsl
-bld::target libioipsl.a
+#bld::lib::ioipsl ioipsl
+#bld::target libioipsl.a
+
+bld::lib    icosa
+bld::target libicosa.a
 bld::target icosa_gcm.exe
 
@@ -38,4 +40,5 @@
 bld::excl_dep        inc::mpif.h
 bld::excl_dep        use::xios
+bld::excl_dep        %USE_IOIPSL
 
 bld::tool::SHELL   /bin/bash
Index: codes/icosagcm/trunk/clean
===================================================================
--- codes/icosagcm/trunk/clean	(revision 346)
+++ codes/icosagcm/trunk/clean	(revision 347)
@@ -1,6 +1,12 @@
-rm -rf ./obj/*
-rm -rf ./done/*
-rm -rf ./inc/*
-rm -rf ./flags/*
-rm -rf ./ppsrc/*
+rm -rf ./obj
+rm -rf ./done
+rm -rf ./inc
+rm -rf ./flags
+rm -rf ./ppsrc
+rm -rf ./bld
+rm -rf ./lib
+rm -rf ./etc
+rm -rf ./tmp
+rm -rf ./bin
 
+
Index: codes/icosagcm/trunk/compile
===================================================================
--- codes/icosagcm/trunk/compile	(revision 346)
+++ codes/icosagcm/trunk/compile	(revision 347)
@@ -1,2 +1,1 @@
-./make_icosa -prod -arch x86_skd 
-#./make_icosa -prod -arch x86_skdmpi -parallel mpi
+./make_icosa -debug -parallel mpi_omp -arch X64_CURIE 
Index: codes/icosagcm/trunk/make_icosa
===================================================================
--- codes/icosagcm/trunk/make_icosa	(revision 346)
+++ codes/icosagcm/trunk/make_icosa	(revision 347)
@@ -1,4 +1,3 @@
 #!/bin/bash
-set -x
 export PATH=$PWD/tools/FCM/bin:$PATH
 
@@ -17,4 +16,7 @@
 parallel="none"
 physics="none"
+external_ioipsl="FALSE"
+external_physics="FALSE"
+
 CPP_KEY="CPP_NONE" 
 ICOSA_LIB=""
@@ -61,4 +63,10 @@
       "-with_xios")
 	  with_xios_defined="TRUE" ; shift ;;
+
+      "-external_ioipsl")
+	  external_ioipsl="TRUE" ; shift ;;
+
+      "-external_physics")
+	  external_physics="TRUE" ; shift ;;
 
       *)
@@ -140,4 +148,20 @@
 fi  
 
+if [[ "$external_ioipsl" == "TRUE" ]]
+then
+  ioipsl_path=".void_dir"
+  use_ioipsl="use::ioipsl"
+  COMPIL_FFLAGS="$COMPIL_FFLAGS $IOIPSL_INCDIR"
+  ICOSA_LIB="$ICOSA_LIB $IOIPSL_LIBDIR $IOIPSL_LIB"
+else 
+  ioipsl_path="tools/ioipsl"
+  use_ioipsl=""
+fi  
+
+if [[ "$external_physics" == "TRUE" ]]
+then
+  CPP_KEY="$CPP_KEY CPP_USING_EXTERNAL_PHYSICS"
+fi
+
 ICOSA_LIB="$ICOSA_LIB $NETCDF_LIBDIR $NETCDF_LIB $HDF5_LIBDIR $HDF5_LIB"
 
@@ -149,4 +173,6 @@
 echo "%CPP_KEY $CPP_KEY" >> config.fcm
 echo "%LIB $ICOSA_LIB">> config.fcm
+echo "%IOIPSL_PATH $ioipsl_path">> config.fcm
+echo "%USE_IOIPSL $use_ioipsl">> config.fcm
 
 if [[ "$full_defined" == "TRUE" ]]
Index: codes/icosagcm/trunk/src/advect_tracer.f90
===================================================================
--- codes/icosagcm/trunk/src/advect_tracer.f90	(revision 346)
+++ codes/icosagcm/trunk/src/advect_tracer.f90	(revision 347)
@@ -58,5 +58,5 @@
     USE mpipara
     USE trace
-    USE write_field
+    USE write_field_mod
     IMPLICIT NONE
     
Index: codes/icosagcm/trunk/src/caldyn_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 346)
+++ codes/icosagcm/trunk/src/caldyn_gcm.f90	(revision 347)
@@ -223,4 +223,6 @@
           CALL compute_pvort(ps,u,theta_rhodz, mass,theta,qu,qv)
        ENDDO
+!       CALL checksum(f_mass)
+!       CALL checksum(f_theta)
 
        CALL send_message(f_qu,req_qu)
@@ -252,4 +254,9 @@
           END IF
        ENDDO       
+   
+!       CALL checksum(f_geopot)
+!       CALL checksum(f_dmass)
+!       CALL checksum(f_pk)
+!       CALL checksum(f_pk)
        
     CASE(enstrophy) ! enstrophy-conserving
@@ -294,17 +301,17 @@
 !       CALL write_output_fields(f_ps, f_phis, f_dps, f_u, f_theta_rhodz, f_q, &
 !            f_buf_i, f_buf_v, f_buf_u3d, f_buf_ulon, f_buf_ulat, f_buf_s, f_buf_p)
-       CALL un2ulonlat(f_u, f_buf_ulon, f_buf_ulat)
-       CALL output_field("ulon",f_buf_ulon)
-       CALL output_field("ulat",f_buf_ulat)
-
-       CALL output_field("ps",f_ps)
-       CALL output_field("dps",f_dps)
-       CALL output_field("mass",f_mass)
-       CALL output_field("dmass",f_dmass)
-       CALL output_field("vort",f_qv)
-       CALL output_field("theta",f_theta)
-       CALL output_field("exner",f_pk)
-       CALL output_field("pv",f_qv)
- 
+!       CALL un2ulonlat(f_u, f_buf_ulon, f_buf_ulat)
+!       CALL output_field("ulon",f_buf_ulon)
+!       CALL output_field("ulat",f_buf_ulat)
+
+!       CALL output_field("ps",f_ps)
+!       CALL output_field("dps",f_dps)
+!       CALL output_field("mass",f_mass)
+!       CALL output_field("dmass",f_dmass)
+!       CALL output_field("vort",f_qv)
+!       CALL output_field("theta",f_theta)
+!       CALL output_field("exner",f_pk)
+!       CALL output_field("pv",f_qv)
+! 
     END IF
     
@@ -439,18 +446,12 @@
     INTEGER :: i,j,ij,l
     REAL(rstd) :: p_ik, exner_ik
-    INTEGER,SAVE ::ij_omp_begin_ext, ij_omp_end_ext
-!$OMP THREADPRIVATE(ij_omp_begin_ext, ij_omp_end_ext)
-    LOGICAL,SAVE :: first=.TRUE.
-!$OMP THREADPRIVATE(first)
+    INTEGER    :: ij_omp_begin_ext, ij_omp_end_ext
 
 
     CALL trace_start("compute_geopot")
     
-    IF (first) THEN
-      first=.FALSE.
-      CALL distrib_level(ij_end_ext-ij_begin_ext+1,ij_omp_begin_ext,ij_omp_end_ext)
-      ij_omp_begin_ext=ij_omp_begin_ext+ij_begin_ext-1
-      ij_omp_end_ext=ij_omp_end_ext+ij_begin_ext-1
-    ENDIF
+    CALL distrib_level(ij_end_ext-ij_begin_ext+1,ij_omp_begin_ext,ij_omp_end_ext)
+    ij_omp_begin_ext=ij_omp_begin_ext+ij_begin_ext-1
+    ij_omp_end_ext=ij_omp_end_ext+ij_begin_ext-1
 
     IF(caldyn_eta==eta_mass) THEN
@@ -798,18 +799,12 @@
     INTEGER :: i,j,ij,l
     REAL(rstd) :: p_ik, exner_ik
-    INTEGER,SAVE ::ij_omp_begin, ij_omp_end
-!$OMP THREADPRIVATE(ij_omp_begin, ij_omp_end)
-    LOGICAL,SAVE :: first=.TRUE.
-!$OMP THREADPRIVATE(first)
+    INTEGER    :: ij_omp_begin, ij_omp_end
 
 
     CALL trace_start("compute_geopot")
-    
-    IF (first) THEN
-      first=.FALSE.
-      CALL distrib_level(ij_end-ij_begin+1,ij_omp_begin,ij_omp_end)
-      ij_omp_begin=ij_omp_begin+ij_begin-1
-      ij_omp_end=ij_omp_end+ij_begin-1
-    ENDIF
+
+    CALL distrib_level(ij_end-ij_begin+1,ij_omp_begin,ij_omp_end)
+    ij_omp_begin=ij_omp_begin+ij_begin-1
+    ij_omp_end=ij_omp_end+ij_begin-1
 
 !    REAL(rstd) :: wwuu(iim*3*jjm,llm+1) ! tmp var, don't know why but gain 30% on the whole code in opemp
@@ -959,5 +954,5 @@
     USE pression_mod
     USE omega_mod
-    USE write_field
+    USE write_field_mod
     USE vertical_interp_mod
     USE wind_mod
Index: codes/icosagcm/trunk/src/etat0_heldsz.f90
===================================================================
--- codes/icosagcm/trunk/src/etat0_heldsz.f90	(revision 346)
+++ codes/icosagcm/trunk/src/etat0_heldsz.f90	(revision 347)
@@ -76,5 +76,5 @@
 
        theta_eq=f_theta_eq(ind) 
-       CALL compute_Teq(lat_i,theta_eq) ! FIXME : already done by Init_Teq
+       CALL compute_Teq(lat_i,theta_eq) ! FIXME : already done by Init_Teq 
 
        ps=f_ps(ind)
@@ -90,5 +90,7 @@
        CALL compute_theta2theta_rhodz(ps,theta,theta_rhodz,1)
        q=f_q(ind)
-       q(:,:,:)=1e2
+       q(:,:,1)=1e-2
+       q(:,:,2)=0
+       q(:,:,3:)=1e-2
     ENDDO
   END SUBROUTINE etat0
Index: codes/icosagcm/trunk/src/etat0_start_file.f90
===================================================================
--- codes/icosagcm/trunk/src/etat0_start_file.f90	(revision 346)
+++ codes/icosagcm/trunk/src/etat0_start_file.f90	(revision 347)
@@ -11,5 +11,5 @@
   USE restart_mod
   USE wind_mod
-  USE write_field
+  USE write_field_mod
   USE time_mod
   USE transfert_mod
Index: codes/icosagcm/trunk/src/icosa_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 346)
+++ codes/icosagcm/trunk/src/icosa_gcm.f90	(revision 347)
@@ -1,99 +1,13 @@
-PROGRAM ICOSA_GCM
-  USE icosa
-  USE timeloop_gcm_mod
-  USE disvert_mod
-  USE etat0_mod
-  USE wind_mod
-  USE mpipara
-  USE omp_para
-  USE vertical_interp_mod
-  USE trace
-  USE output_field_mod
-  USE xios_mod
-  USE write_field
-  USE physics_mod
+PROGRAM icosa_gcm
+  USE icosa_init_mod, ONLY : icosa_init
 
-!  USE getin_mod
-  IMPLICIT NONE
-  
-  CALL init_mpipara
-  CALL trace_off
-  CALL xios_init
-  CALL init_earth_const 
-  CALL init_grid_param(is_mpi_master)
-  CALL init_omp_para(is_mpi_master)
-  CALL compute_metric
-  CALL compute_domain
-  CALL init_transfert
-  CALL init_writefield
-  CALL init_trace
+  CALL icosa_init
 
-!$OMP PARALLEL  
-  CALL switch_omp_no_distrib_level
-  CALL compute_geometry
-  CALL check_total_area
-  
-  CALL init_disvert 
-  CALL init_vertical_interp
 
-  CALL WriteField("Ai",geom%Ai)
-  
-  IF (is_mpi_root) CALL write_apbp
-  CALL init_time
+END PROGRAM icosa_gcm
 
-  CALL output_field_init
-  CALL init_timeloop
-!$OMP END PARALLEL
- 
-  CALL init_physics
-   
-!$OMP PARALLEL  
-  CALL timeloop
-  CALL switch_omp_no_distrib_level
-!$OMP END PARALLEL
+SUBROUTINE initialize_external_physics
+END SUBROUTINE initialize_external_physics
 
-  CALL output_field_finalize
-  CALL close_files
-  CALL close_time_counter
-  CALL finalize_mpipara
-
-CONTAINS
-  
-  SUBROUTINE check_total_area
-    IMPLICIT NONE
-    TYPE(t_field),POINTER,SAVE :: sum_ne(:)
-    TYPE(t_field),POINTER,SAVE :: sum_ne_glo(:)
-    REAL(rstd),POINTER :: pt_sum_ne(:)
-    
-    INTEGER :: ind,i,j,k,n
-    REAL(rstd) :: vect(3,6)
-    REAL(rstd) :: centr(3),dist    
-    REAL(rstd) :: tot_sum=0
-    CALL allocate_field(sum_ne,field_T,type_real)
-    
-    !$OMP BARRIER
-    !$OMP MASTER
-    DO ind=1,ndomain
-       
-       pt_sum_ne=sum_ne(ind)
-       
-       CALL swap_dimensions(ind)
-       CALL swap_geometry(ind)
-       
-       DO j=jj_begin,jj_end
-          DO i=ii_begin,ii_end
-             n=(j-1)*iim+i
-             pt_sum_ne(n)=0
-             DO k=1,6
-                pt_sum_ne(n)=pt_sum_ne(n)+ne(n,k)
-             ENDDO
-             IF (domain(ind)%own(i,j)) tot_sum=tot_sum+Ai(n)
-          ENDDO
-       ENDDO
-    ENDDO
-    
-    IF (is_mpi_root) PRINT *," Diff surf",1-tot_sum/(4*Pi*radius*radius)
-    !$OMP END MASTER
-    
-  END SUBROUTINE check_total_area
-END PROGRAM ICOSA_gcm
+SUBROUTINE external_physics
+END SUBROUTINE external_physics
Index: codes/icosagcm/trunk/src/icosa_mod.f90
===================================================================
--- codes/icosagcm/trunk/src/icosa_mod.f90	(revision 346)
+++ codes/icosagcm/trunk/src/icosa_mod.f90	(revision 347)
@@ -13,5 +13,5 @@
   USE vector
   USE field_mod
-  USE write_field
+  USE write_field_mod
   USE transfert_mod
   USE time_mod
Index: codes/icosagcm/trunk/src/output_field.f90
===================================================================
--- codes/icosagcm/trunk/src/output_field.f90	(revision 346)
+++ codes/icosagcm/trunk/src/output_field.f90	(revision 347)
@@ -14,5 +14,5 @@
   USE getin_mod
   USE xios_mod
-  USE write_field
+  USE write_field_mod
   IMPLICIT NONE
 
@@ -37,5 +37,5 @@
     USE field_mod
     USE xios_mod
-    USE write_field
+    USE write_field_mod
     IMPLICIT NONE  
      CHARACTER(LEN=*),INTENT(IN) :: name_in
Index: codes/icosagcm/trunk/src/physics.f90
===================================================================
--- codes/icosagcm/trunk/src/physics.f90	(revision 346)
+++ codes/icosagcm/trunk/src/physics.f90	(revision 347)
@@ -5,5 +5,5 @@
   PRIVATE
 
-  INTEGER, PARAMETER :: phys_none=0, phys_HS94=1, phys_DCMIP=2, phys_lmdz_generic=3, phys_LB2012=4 
+  INTEGER, PARAMETER :: phys_none=0, phys_HS94=1, phys_DCMIP=2, phys_lmdz_generic=3, phys_LB2012=4, phys_external=5
 
   INTEGER :: phys_type
@@ -27,4 +27,5 @@
     USE etat0_venus_mod, ONLY : init_phys_venus=>init_physics
     USE physics_lmdz_generic_mod, ONLY : init_physics_lmdz_generic=>init_physics
+    USE physics_external_mod, ONLY : init_physics_external=>init_physics
     IMPLICIT NONE
 
@@ -45,4 +46,7 @@
        CALL init_physics_lmdz_generic
        phys_type=phys_lmdz_generic
+    CASE ('phys_external')
+       CALL init_physics_external
+       phys_type=phys_external
     CASE ('dcmip')
        CALL allocate_field(f_dulon,field_t,type_real,llm, name='dulon')
@@ -55,5 +59,6 @@
     CASE DEFAULT
        IF(is_mpi_root) PRINT*, 'init_physics : Bad selector for variable physics <',&
-            TRIM(physics_type), '> options are <none>, <held_suarez>, <Lebonnois2012>, <dcmip>, <phys_lmdz_generic>'
+            TRIM(physics_type), '> options are <none>, <held_suarez>, <Lebonnois2012>, <dcmip>', &
+                                '<phys_lmdz_generic>, <phys_external>'
        STOP
     END SELECT
@@ -66,4 +71,5 @@
     USE physics_interface_mod
     USE physics_lmdz_generic_mod, ONLY : physics_lmdz_generic => physics
+    USE physics_external_mod, ONLY : physics_external => physics
     USE physics_dcmip_mod, ONLY : write_physics_dcmip => write_physics
     USE etat0_heldsz_mod
@@ -96,4 +102,6 @@
        CASE (phys_lmdz_generic)
          CALL physics_lmdz_generic(it ,f_phis, f_ps, f_theta_rhodz, f_ue, f_wflux, f_q)
+       CASE (phys_external)
+         CALL physics_external(it ,f_phis, f_ps, f_theta_rhodz, f_ue, f_wflux, f_q)
        CASE(phys_LB2012)
           CALL phys_venus(f_ps,f_theta_rhodz,f_ue) 
Index: codes/icosagcm/trunk/src/time.f90
===================================================================
--- codes/icosagcm/trunk/src/time.f90	(revision 346)
+++ codes/icosagcm/trunk/src/time.f90	(revision 347)
@@ -25,24 +25,12 @@
   INTEGER,SAVE :: day_step,ndays
 !$OMP THREADPRIVATE(day_step,ndays)  
-  REAL(rstd),SAVE :: jD_ref,jH_ref
-!$OMP THREADPRIVATE(jD_ref,jH_ref)  
-  INTEGER,SAVE :: day_ini,day_end,annee_ref,day_ref
-!$OMP THREADPRIVATE(day_ini,day_end,annee_ref,day_ref)  
-  REAL(rstd),SAVE::start_time
-!$OMP THREADPRIVATE(start_time)  
+
   CHARACTER(LEN=255) :: time_style
 !$OMP THREADPRIVATE(time_style)  
-  INTEGER,SAVE:: an, mois, jour
-!$OMP THREADPRIVATE(an, mois, jour)  
-  REAL(rstd),SAVE:: heure
-!$OMP THREADPRIVATE(heure)  
-  CHARACTER (LEN=10):: calend
-!$OMP THREADPRIVATE(calend)  
 
   PUBLIC create_time_counter_header, update_time_counter, close_time_counter, init_time,  &
          dt, write_period, itau_out, itau_adv, itau_dissip, itau_physics, itaumax,  &
          itau_check_conserv,  & 
-         day_step,ndays,jD_ref,jH_ref,day_ini,day_end,annee_ref,day_ref, &
-         an, mois, jour,heure, calend,time_style,itau0
+         day_step,ndays,time_style,itau0
 
 
Index: codes/icosagcm/trunk/src/timeloop_gcm.f90
===================================================================
--- codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 346)
+++ codes/icosagcm/trunk/src/timeloop_gcm.f90	(revision 347)
@@ -40,5 +40,5 @@
   USE check_conserve_mod
   USE output_field_mod
-  USE write_field
+  USE write_field_mod
   USE theta2theta_rhodz_mod
   USE sponge_mod
@@ -246,7 +246,13 @@
 
     DO stage=1,nb_stage
+!       CALL checksum(f_ps)
+!       CALL checksum(f_theta_rhodz)
+!       CALL checksum(f_mass)
        CALL caldyn((stage==1) .AND. (MOD(it,itau_out)==0), &
             f_phis,f_ps,f_mass,f_theta_rhodz,f_u, f_q, &
             f_hflux, f_wflux, f_dps, f_dmass, f_dtheta_rhodz, f_du)
+!       CALL checksum(f_dps)
+!       CALL checksum(f_dtheta_rhodz)
+!       CALL checksum(f_dmass)
        SELECT CASE (scheme)
        CASE(euler)
Index: codes/icosagcm/trunk/src/write_etat0.f90
===================================================================
--- codes/icosagcm/trunk/src/write_etat0.f90	(revision 346)
+++ codes/icosagcm/trunk/src/write_etat0.f90	(revision 347)
@@ -9,5 +9,5 @@
   USE restart_mod
   USE wind_mod
-  USE write_field
+  USE write_field_mod
   IMPLICIT NONE
     INTEGER,INTENT(IN)    :: it
Index: codes/icosagcm/trunk/src/write_field.f90
===================================================================
--- codes/icosagcm/trunk/src/write_field.f90	(revision 346)
+++ codes/icosagcm/trunk/src/write_field.f90	(revision 347)
@@ -1,3 +1,3 @@
-module write_field
+module write_field_mod
 USE genmod
 implicit none
@@ -1799,4 +1799,4 @@
   end function int2str
 
-end module write_field
+end module write_field_mod
   
