source: tags/ORCHIDEE_1_9_5/ORCHIDEE_OL/FLUXNET/post_FLUXNET @ 8

Last change on this file since 8 was 8, checked in by orchidee, 14 years ago

import first tag equivalent to CVS orchidee_1_9_5 + OOL_1_9_5

File size: 6.6 KB
Line 
1#!/bin/ksh
2
3########################################################################
4
5#D- Flag to determine if this job in a standalone mode
6#D- Default : value from AA_job if any
7StandAlone=${StandAlone:=true}
8
9#D- Increased verbosity (1, 2, 3)
10#D- Default : value from AA_job if any
11Verbosity=${Verbosity:=3}
12
13#D- Low level debug : to bypass lib test checks and stack construction
14#D- Default : value from AA_job if any
15DEBUG_debug=${DEBUG_debug:=false}
16
17#RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$}
18
19########################################################################
20
21MODIPSL=$1
22libIGCM=${libIGCM:=${MODIPSL}/libIGCM}
23
24. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
25. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
26. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
27. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
28
29########################################################################
30#set -vx
31########################################################################
32# Script input parameters
33
34# Site name
35SiteArg=$2
36Site=${SiteArg:=Gu}
37# Time in years in file for this site :
38DureeArg=$3
39export DUREE=${DureeArg:=1}
40
41# First year in file for this site :
42FirstArg=$4
43export FYEAR=${FirstArg:=1}
44
45
46# Atlas Name :
47AtlasCfgArg=$5
48AtlasCfg=${AtlasCfgArg:=atlas_FLUXNET.cfg}
49
50# observation_file
51observation_file_pathArg=$6
52observation_file_path=${observation_file_pathArg:='${R_IN}/BC/OOL/${config_UserChoices_TagName}/FLUXNET/OLD/${Site}.nc'}
53#/home/mancip/IGCM/BC/OOL/OL2/FLUXNET/OBS/${Site}_obs_gapfilled.nc
54
55# old history file
56reference_file_pathArg=$7
57reference_file_path=${reference_file_pathArg:='/home/mancip/PROG/IPSL/VALID_OL/SECHIBA/${Site}_sechiba_hist.nc'}
58
59# Modulo for SpinUp years
60ModuloArg=$8
61
62#if [ ${DEBUG_debug} = true ] ; then
63IGCM_sys_MkdirWork ${RUN_DIR_PATH}
64echo "RUN_DIR_PATH ${RUN_DIR_PATH} ok."
65#fi
66IGCM_sys_Cd ${RUN_DIR_PATH}
67
68if [ ${StandAlone} = true ] ; then
69    CARD_DIR=${SUBMIT_DIR}
70else
71    CARD_DIR=${RUN_DIR_PATH}/$( basename ${SUBMIT_DIR} )
72    IGCM_sys_Get_Master ${SUBMIT_DIR} ${RUN_DIR_PATH}
73fi
74
75#
76# First of all
77#
78IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card UserChoices
79typeset option
80for option in ${config_UserChoices[*]} ; do
81    IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
82done
83#
84echo
85IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
86IGCM_debug_PrintVariables 3 config_UserChoices_JobName
87if [ 3 -le ${Verbosity} ] ; then
88    echo "--------------Debug3-->" "config_UserChoices_LongName="
89    echo "--------------Debug3-->" \"${config_UserChoices_LongName}\"
90fi
91IGCM_debug_PrintVariables 3 config_UserChoices_TagName
92IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
93IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
94IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
95IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
96echo
97
98
99# FLAG = SECHIBA, OK_STOMATE
100IGCM_card_DefineVariableFromOption ${CARD_DIR}/fluxnet.card UserChoices ok_stomate
101if [ X${fluxnet_UserChoices_ok_stomate} = Xn ] ; then
102    export FLAG=SECHIBA
103else
104    export FLAG=OK_STOMATE
105fi
106
107#==================================
108
109SpinUpJob=${Site}${config_UserChoices_JobName}
110
111R_BC=${R_IN}/BC
112R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${SpinUpJob}/SPIN
113
114# look at files
115IGCM_card_DefineVariableFromOption ${CARD_DIR}/fluxnet.card UserChoices DEBUG_SPIN
116if [ X${fluxnet_UserChoices_DEBUG_SPIN} = Xn ] ; then
117    set -A liste_fichiers_with_path -- $( \ls -rt ${R_SAVE}/Output/${SpinUpJob}*/SRF/Output/MO/*_sechiba_history.nc ${R_OUT}/${config_UserChoices_TagName}/${SpinUpJob}HIST/SRF/Output/MO/*_sechiba_history.nc )
118else
119    set -A liste_fichiers_with_path -- $( \ls -rt ${R_OUT}/${config_UserChoices_TagName}/${SpinUpJob}*/SRF/Output/MO/*_sechiba_history.nc )
120fi
121
122ii=0
123for file in ${liste_fichiers_with_path[@]} ; do
124    liste_fichiers[$ii]=$( echo ${file} | xargs basename )
125    (( ii = ii + 1 ))
126done
127echo ${liste_fichiers[*]}
128
129# Get and sed atlas
130IGCM_sys_Cp ${CARD_DIR}/${AtlasCfg} ./atlas.cfg
131
132# Set default Modulo parameter to the last file
133eval NbFiles=${#liste_fichiers[@]}
134echo "NbFiles=" $NbFiles
135Modulo=${ModuloArg:=$(( NbFiles - 1 ))}
136
137# Get last time_axis patch
138Last_Patch_File=$( ls -t ${libIGCM}/libIGCM_post/IGCM_Patch_*_histcom_time_axis.ksh | tail -1 )
139#echo "source patch file : ${Last_Patch_File}"
140# . ${Last_Patch_File}
141# Last_Patch=$( echo ${Last_Patch_File} | sed -e "s&${libIGCM}/libIGCM_post/\(.*\)\.ksh&\1&" )
142#echo "We will apply the patch on all sechiba files : "  ${Last_Patch}
143
144# Apply atlas
145ii=0
146for file in ${liste_fichiers[*]} ; do
147
148    DirFile=$( dirname ${liste_fichiers_with_path[$ii]} )
149    echo ${DirFile}
150
151    # First apply the last time_axis patch
152#     IGCM_sys_Cd ${DirFile}
153#     ${Last_Patch} ${file}
154#     # clean dir
155#     rm out_rsync
156#     # Then return to RUN_DIR_PATH
157#     IGCM_sys_Cd ${RUN_DIR_PATH}
158   
159    if [ $ii -eq 0 ]  ; then
160        file_=${file}
161        # copy files we need for ATLAS
162        IGCM_sys_Cp -p ${liste_fichiers_with_path[$ii]} .
163    fi
164    echo "!!!!!!!!!!!!!!!!!"
165    echo ${file}
166    export F_FILE=${Site}
167    echo $ii "Modulo : " $( expr $ii \% $Modulo )
168    if [ $ii -gt 0 ] && [ X$( expr $ii \% $Modulo ) = X0 ] ; then
169
170        # copy files we need for ATLAS
171        IGCM_sys_Cp -Rp ${liste_fichiers_with_path[$ii]} .
172
173        reference_file=${file_}
174        eval observation_file=${observation_file_path}
175        echo "ATLAS DIFF for files : " ${file} ${reference_file} ${observation_file}
176
177        #cat atlas.cfg
178        sed -e "s,RRRRRRR,${reference_file},g" -e "s,VVVVVVV,${observation_file},g" atlas.cfg > atlas_.cfg
179        #cat atlas_.cfg
180        AtlasPath=$( echo ${file} | sed -e 's/_1M_sechiba_history.nc//' )
181        atlas -o ATLAS_DIFF_${AtlasPath} atlas_.cfg ${file}
182
183        # Save files
184        IGCM_sys_Put_Dir ATLAS_DIFF_${AtlasPath} ${R_SAVE}
185#       IGCM_sys_Rm -Rf ATLAS_DIFF_${AtlasPath}
186        echo "&&&&&&&&&&&&&&&&!"
187
188        file_=${file}
189    fi
190    (( ii=ii+1 ))
191done
192eval reference_file=${reference_file_path}
193sed -e "s,RRRRRRR,${reference_file},g" -e "s,VVVVVVV,${observation_file},g" atlas.cfg > atlas_.cfg
194
195echo "REFERENCE ATLAS for file : " ${file} ${reference_file} ${observation_file}
196atlas -o ATLAS_FIN_${AtlasPath}_ref atlas_.cfg ${file}
197
198# Save files
199IGCM_sys_Put_Dir ATLAS_FIN_${AtlasPath}_ref ${R_SAVE}
200
201IGCM_sys_Rm -Rf ATLAS_FIN_${AtlasPath}_ref
202
203
204
205# # Get and Apply Patch
206# . ${MODIPSL}/libIGCM/libIGCM_post/IGCM_Patch_20070220_histcom_time_axis.ksh
207# for file in ${liste_fichiers[*]} ; do
208#     IGCM_Patch_20070220_histcom_time_axis ${file}
209# done
210
211# # look at files
212# echo "after Patch" IGCM_Patch_20070220_histcom_time_axis
213# \ls -lrt  *_sechiba_history.nc
214
215# Concat files
216#IGCM_sys_ncrcat -o ${SpinUpJob}_1M_sechiba_history.nc ${liste_fichiers[*]}
217
218IGCM_sys_Rm -Rf  ${liste_fichiers[*]}
219
220IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
Note: See TracBrowser for help on using the repository browser.