source: trunk/libIGCM/libIGCM_post/IGCM_Patch_20091030_histcom_time_axis.ksh @ 195

Last change on this file since 195 was 195, checked in by mafoipsl, 15 years ago

Bad dot.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Martial Mancip
5# Contact: Martial.Mancip_ipsl.jussieu.fr
6# $Date: $
7# $Author: mmaipsl $
8# $Revision: $
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
18function 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            ${ncatted} -O --hst -a associate,${var},m,c,"${ATTNV}" ${file}
64            # This is not an IGCM function because of a
65            # Problem with ksh and string passed in this IGCM_sys_ncatted function to ncatted !
66        done
67
68        # Rename coordinates attribut from t_ave_xxxx to time_counter
69
70        set +A VARName $( cat ${file}_ncdump-h | grep "[0-9a-zA-Z_]*.*:coordinates.*" | grep "t_ave_${AXISt_i}" | sed -e "s/[[:space:]]*\(.*\):coordinates.*/\1/" )
71        for var in ${VARName[*]} ; do
72            # Old attribute value
73            ATTN=$( cat ${file}_ncdump-h | grep "${var}:coordinates.*" | grep "t_ave_${AXISt_i}" | sed -e "s/.*:coordinates = \"\(.*\)\" ;/\1/" )
74            # New attribute value
75            ATTNV=$( echo ${ATTN} | sed -e "s/t_ave_${AXISt_i}/time_counter/" ) #| sed -e 's/[[:space:]]/\\ /g')
76            # change it !
77            ${ncatted} -O --hst -a coordinates,${var},m,c,"${ATTNV}" ${file}
78            # This is not an IGCM function because of a
79            # Problem with ksh and string passed in this IGCM_sys_ncatted function to ncatted !
80        done
81
82
83        IGCM_debug_Verif_Exit_Post
84        IGCM_sys_Mv ${file} ${1}
85        IGCM_sys_Rm ${file}_ncdump-h
86      fi
87    fi
88    IGCM_sys_Rm ${1}_ncdump-h
89   
90    IGCM_debug_PopStack "IGCM_Patch_histcom_time_axis"
91}
Note: See TracBrowser for help on using the repository browser.