Index: modipsl/trunk/util/ins_job
===================================================================
--- modipsl/trunk/util/ins_job	(revision 1908)
+++ modipsl/trunk/util/ins_job	(revision 2036)
@@ -14,10 +14,11 @@
 
 Usage :
-  ${b_n} [-h] [-v] [-e]
+  ${b_n} [-h] [-v] [-e] [-p project]
 
 Options :
-  -h   : help
-  -v   : verbose mode
-  -e   : turn on hindcast/forecast ensemble mode
+  -h          : help
+  -v          : verbose mode
+  -e          : turn on hindcast/forecast ensemble mode
+  -p project  : add default project on curie
 "
 }
@@ -37,13 +38,16 @@
 x_v='silencious';
 x_e=false;
-while getopts :hve V ; do
+x_p=false;
+while getopts :hvep: V ; do
   case $V in
   (h)  ins_job_Usage; exit 0;;
   (v)  x_v='verbose';;
   (e)  x_e=true;;
+  (p)  x_p=true
+       ProjectID=${OPTARG} ;;
   (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
-  exit 2;;
+       exit 2;;
   (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
-  exit 2;;
+       exit 2;;
   esac
 done
@@ -105,4 +109,26 @@
   . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
 fi
+
+#-
+# Define Project ID to set up jobs header for Curie (TGCC)
+#-
+if ( ! ${x_p} ) ; then
+  if [ "X${x_t}" == "Xcurie" ] ; then
+    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )
+    ProjectID=${ProjectID:="gen2211"}
+    answer=""
+    print - "Hit Enter or give project ID (default is ${ProjectID}):"
+    read answer
+
+    if [ "X${answer}" != "X" ] ; then
+      ProjectID=${answer}
+    fi
+  fi
+else
+  if ( "X${x_t}" != "Xcurie" ) ; then
+    print - "\nOption -p invalid with this host (${x_t}): it will be ignored" 1>&2;
+  fi
+fi
+
 #-
 # Define the pattern string to substitute
@@ -116,101 +142,102 @@
 for i in $(find ${d_n}/.. -name ${F_CFG} -print)
 do
- j=$(cd ${i%/*};/bin/pwd;)
- n_f=${F_RCI##*/};
-
- if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
- # Do not treat config.card if it is in sub-directory of EXPERIMENTS
- # Continue to next config.card
-     continue
- else
-     [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
- fi
-
- # Find out if new structure and set .resol filename
- if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
-     # New Structure
-     [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
-     new_struct=yes
-     resolfile=$j/.resol
- else
-     # Old Structure
-     new_struct=no
-     resolfile=$j/../.resol
- fi
- 
- # Get all variables declared in section UserChoices in config.card
- IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
- # Set default values
- config_UserChoices_JobClass=mono
- config_UserChoices_JobNumProcTot=1
- config_UserChoices_ExpType=""
- RESOL_ATM_3D=this_is_a_test_string
- RESOL=this_is_another_test_string
- typeset option
- for option in ${config_UserChoices[*]} ; do
-     IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
- done
-
-# Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
- if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
+  j=$(cd ${i%/*};/bin/pwd;)
+  n_f=${F_RCI##*/};
+
+  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
+    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
+    # Continue to next config.card
+    continue
+  else
+    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
+  fi
+
+  # Find out if new structure and set .resol filename
+  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
+    # New Structure
+    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
+    new_struct=yes
+    resolfile=$j/.resol
+  else
+    # Old Structure
+    new_struct=no
+    resolfile=$j/../.resol
+  fi
+
+  # Get all variables declared in section UserChoices in config.card
+  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
+  # Set default values
+  config_UserChoices_JobClass=mono
+  config_UserChoices_JobNumProcTot=1
+  config_UserChoices_ExpType=""
+  RESOL_ATM_3D=this_is_a_test_string
+  RESOL=this_is_another_test_string
+  typeset option
+  for option in ${config_UserChoices[*]} ; do
+    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
+  done
+
+  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
+  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
     TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
     echo TRUERESOL = $TRUERESOL
     JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
     IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
- elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
-     TRUERESOL=$( head -1 $resolfile  )
-     JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
-     IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
- else
-     JobName=${config_UserChoices_JobName}
- fi
- [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
-
-# Add specific treatment for new type of directory structure 
+  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
+    TRUERESOL=$( head -1 $resolfile  )
+    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
+    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
+  else
+    JobName=${config_UserChoices_JobName}
+  fi
+  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
+
+  # Add specific treatment for new type of directory structure 
   if [ ${new_struct} == yes ] ; then
 
-      if [ "X${config_UserChoices_ExpType}" = X ] ; then
-	echo "\nERROR in ${j}/config.card"
-	echo "ins_job stops here"
-	echo "=> The variable ExpType must be added in config.card in section UserChoices"
-	echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
-        exit 4
-      else
-	[[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
-      fi
-
-      if [ -d ${j}/${JobName} ] ; then
-	  echo "Directory ${j}/${JobName} exist already, continue next config.card"
-	  continue
-      fi
-      echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
-      cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
-      cp -r ${j}/GENERAL/* ${j}/${JobName}/.
-      cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
-      rm -f ${j}/${F_CFG}
-      rm -f ${j}/${F_CFG}.bak
-      j=${j}/${JobName}
-      [[ ${x_v} = 'verbose' ]] && echo new j=$j
-  fi
-# end specific treatment for new type directory structure 
-
- [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
-  {
-   [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
-   \cp ${F_RCI} ${j};
-  }
-
- # File name for Job
- n_f='Job_'${JobName};
- [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
- [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
- sed -e "/^${W_W} */ s///" \
-     -e "/^${W_P}/d"       \
-     -e "s%::modipsl::%${F_MOD}%" \
-     -e "s/::Jobname::/${JobName}/" \
-     -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
-     -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
-     ${F_JOB} > ${j}'/'${n_f}
- chmod u+x ${j}'/'${n_f}
+    if [ "X${config_UserChoices_ExpType}" = X ] ; then
+      echo "\nERROR in ${j}/config.card"
+      echo "ins_job stops here"
+      echo "=> The variable ExpType must be added in config.card in section UserChoices"
+      echo "=> ExpType gives the directory for the .card configurtaion files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
+      exit 4
+    else
+      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
+    fi
+
+    if [ -d ${j}/${JobName} ] ; then
+      echo "Directory ${j}/${JobName} exist already, continue next config.card"
+      continue
+    fi
+    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
+    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
+    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
+    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
+    rm -f ${j}/${F_CFG}
+    rm -f ${j}/${F_CFG}.bak
+    j=${j}/${JobName}
+    [[ ${x_v} = 'verbose' ]] && echo new j=$j
+  fi
+  # end specific treatment for new type directory structure 
+
+  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
+   {
+    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
+    \cp ${F_RCI} ${j};
+   }
+
+  # File name for Job
+  n_f='Job_'${JobName};
+  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
+  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
+  sed -e "/^${W_W} */ s///" \
+      -e "/^${W_P}/d"       \
+      -e "s%::modipsl::%${F_MOD}%" \
+      -e "s/::Jobname::/${JobName}/" \
+      -e "s/::JobClass::/${config_UserChoices_JobClass}/" \
+      -e "s/::JobNumProcTot::/${config_UserChoices_JobNumProcTot}/" \
+      -e "s/::default_project::/${ProjectID}/" \
+      ${F_JOB} > ${j}'/'${n_f}
+  chmod u+x ${j}'/'${n_f}
 done
 #-
@@ -220,14 +247,15 @@
 for i in $(find ${libIGCM} -name "AA_*" -print | grep -v .svn )
 do
- i_f=${i##*/};
- [[ ${i_f} = 'AA_job' ]] && { continue; }
- j=${i%/*}; n_f=${i_f#AA_}'.job';
- [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
- [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
- sed -e "/^${W_W} */ s///" \
-     -e "s%::modipsl::%${F_MOD}%" \
-     -e "/^${W_P}/d"       \
-     ${i} > ${j}'/'${n_f}
- chmod u+x ${j}'/'${n_f}
+  i_f=${i##*/};
+  [[ ${i_f} = 'AA_job' ]] && { continue; }
+  j=${i%/*}; n_f=${i_f#AA_}'.job';
+  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
+  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
+  sed -e "/^${W_W} */ s///" \
+      -e "s%::modipsl::%${F_MOD}%" \
+      -e "/^${W_P}/d"       \
+      -e "s/::default_project::/${ProjectID}/" \
+      ${i} > ${j}'/'${n_f}
+  chmod u+x ${j}'/'${n_f}
 done
 #-
