1 | #!/bin/ksh |
---|
2 | |
---|
3 | #************************************************************** |
---|
4 | # Author: Martial Mancip |
---|
5 | # Contact: Martial.Mancip__at__ipsl.jussieu.fr |
---|
6 | # $Revision:: $ Revision of last commit |
---|
7 | # $Author:: $ Author of last commit |
---|
8 | # $Date:: $ Date of last commit |
---|
9 | # IPSL (2006) |
---|
10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
11 | # |
---|
12 | #************************************************************** |
---|
13 | |
---|
14 | #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
15 | # We keep only first time axis as time_counter !!!! |
---|
16 | #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
17 | |
---|
18 | function IGCM_Patch_20091030_histcom_time_axis { |
---|
19 | IGCM_debug_PushStack "IGCM_Patch_histcom_time_axis" $@ |
---|
20 | |
---|
21 | typeset file AXISt AXISt_i VARName var ATTN ATTNV VAR_AXISt VAR_AXISt_i |
---|
22 | |
---|
23 | ncdump -h ${1} > ${1}_ncdump-h |
---|
24 | set +A AXISt $(cat ${1}_ncdump-h | grep 't_ave_.*(time_counter)' | sed -e 's/[[:space:]][fd][lo][ou][ab][tl][ e] *t_ave_\([0-9a-zA-Z]*\).*/\1/') |
---|
25 | # liste => tous les axes de temps vont s'appeler time_counter !! |
---|
26 | if [ $? -eq 0 ] ; then |
---|
27 | if [ ${#AXISt[*]} -ge 1 ] ; then |
---|
28 | |
---|
29 | file=t_$1 |
---|
30 | IGCM_sys_Mv ${1} ${file} |
---|
31 | IGCM_sys_Chmod 644 ${file} |
---|
32 | |
---|
33 | if [ ${#AXISt[*]} -gt 1 ] ; then |
---|
34 | echo "WARNING : for file ${1} we have more than one time axis !" |
---|
35 | echo "We choose first one ! = t_ave_${AXISt[0]}." |
---|
36 | fi |
---|
37 | #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
38 | # We keep only first time axis as time_counter !!!! |
---|
39 | #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
40 | |
---|
41 | AXISt_i=${AXISt[0]} |
---|
42 | # Rename time_counter variable |
---|
43 | IGCM_sys_ncrename -O --hst -v t_ave_${AXISt_i},time_counter ${file} |
---|
44 | ncdump -h ${file} > ${file}_ncdump-h |
---|
45 | |
---|
46 | # We have also to rename variables indexed by this time value |
---|
47 | # liste => pb avec deux variables indéxées par deux valeurs de temps différentes => même nom au final! |
---|
48 | set +A VAR_AXISt $( cat ${file}_ncdump-h | grep "[[:space:]]*[a-z]* [a-zA-Z_]*${AXISt_i}(.*) ;" | sed -e "s/[[:space:]]*[a-z]* \([a-zA-Z_]*\)_${AXISt_i}(.*) ;/\1/" ) |
---|
49 | for VAR_AXISt_i in ${VAR_AXISt[*]} ; do |
---|
50 | IGCM_sys_ncrename -O --hst -v ${VAR_AXISt_i}_${AXISt_i},${VAR_AXISt_i} ${file} |
---|
51 | done |
---|
52 | |
---|
53 | # A-t-on besoin de renommer les attributs des autres variables ?? |
---|
54 | # Rename relative associate string in other variables |
---|
55 | |
---|
56 | set +A VARName $( cat ${file}_ncdump-h | grep "[0-9a-zA-Z_]*.*:associate.*" | grep "t_ave_${AXISt_i}" | sed -e "s/[[:space:]]*\(.*\):associate.*/\1/" ) |
---|
57 | for var in ${VARName[*]} ; do |
---|
58 | # Old attribute value |
---|
59 | ATTN=$( cat ${file}_ncdump-h | grep "${var}:associate.*" | grep "t_ave_${AXISt_i}" | sed -e "s/.*:associate = \"\(.*\)\" ;/\1/" ) |
---|
60 | # New attribute value |
---|
61 | ATTNV=$( echo ${ATTN} | sed -e "s/t_ave_${AXISt_i}/time_counter/" ) #| sed -e 's/[[:space:]]/\\ /g') |
---|
62 | # change it ! |
---|
63 | IGCM_sys_ncatted -O --hst -a associate,${var},m,c,"${ATTNV}" ${file} |
---|
64 | done |
---|
65 | |
---|
66 | # Rename coordinates attribut from t_ave_xxxx to time_counter |
---|
67 | |
---|
68 | set +A VARName $( cat ${file}_ncdump-h | grep "[0-9a-zA-Z_]*.*:coordinates.*" | grep "t_ave_${AXISt_i}" | sed -e "s/[[:space:]]*\(.*\):coordinates.*/\1/" ) |
---|
69 | for var in ${VARName[*]} ; do |
---|
70 | # Old attribute value |
---|
71 | ATTN=$( cat ${file}_ncdump-h | grep "${var}:coordinates.*" | grep "t_ave_${AXISt_i}" | sed -e "s/.*:coordinates = \"\(.*\)\" ;/\1/" ) |
---|
72 | # New attribute value |
---|
73 | ATTNV=$( echo ${ATTN} | sed -e "s/t_ave_${AXISt_i}/time_counter/" ) #| sed -e 's/[[:space:]]/\\ /g') |
---|
74 | # change it ! |
---|
75 | IGCM_sys_ncatted -O --hst -a coordinates,${var},m,c,"${ATTNV}" ${file} |
---|
76 | done |
---|
77 | |
---|
78 | |
---|
79 | IGCM_debug_Verif_Exit_Post |
---|
80 | IGCM_sys_Mv ${file} ${1} |
---|
81 | IGCM_sys_Rm ${file}_ncdump-h |
---|
82 | fi |
---|
83 | fi |
---|
84 | IGCM_sys_Rm ${1}_ncdump-h |
---|
85 | |
---|
86 | IGCM_debug_PopStack "IGCM_Patch_histcom_time_axis" |
---|
87 | } |
---|