Subversion Repositories lagranto.um

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
#!/bin/csh
2
 
15 michaesp 3
# Set Lagranto 
4
set LAGRANTO = ${LAGRANTOBASE}.${MODEL}/
5
 
3 michaesp 6
# -----------------------------------------------------------------------------
7
# Set some parameters
8
# -----------------------------------------------------------------------------
9
 
10
# Get arguments
11
if ( ${#argv} == 0 ) then
12
    set poleprint = 1
13
    set inpfile   = ""
14
    set outfile   = ""
15
else
16
    set poleprint = 0
17
    set inpfile   = $1
18
    set outfile   = $2
19
endif
20
 
21
# Get the pole position
22
if ( -f geo2rot.pole ) then
23
   set pole = `cat geo2rot.pole` 
24
else if ( -f rot2geo.pole ) then 
25
   set pole = `cat rot2geo.pole` 
26
else
27
   set pole = "0. 90."
28
endif
29
 
30
# Handle optional arguments
31
set polefile = 0
32
 
33
while ( $#argv > 0 )
34
 
35
  switch ( $argv[1] )
36
 
37
   case -lonlat
38
     set pole = "$argv[2] $argv[3]"
39
     shift; shift;
40
   breaksw
41
 
42
   case -file
43
     set polefile = 1
44
     set filename = $argv[2] 
45
     shift;
46
   breaksw
47
 
48
  endsw
49
 
50
  shift;
51
 
52
end
53
 
54
# Get the pole position from file  if requested
55
if ( "${polefile}" == "1" ) then
56
 
57
    # Check whether file is available
58
    if ( ! -f ${filename} ) then
59
       echo "file ${filename} not found... stop"
60
       exit 1
61
    endif
62
 
63
    # Get pole directly from cst or from P,S file
64
    set pollon = ""
65
    set ok     = `ncdump -h ${filename} | grep pollon`
66
    if ( "${ok}" != "" ) then
67
       set pollon = `ncdump ${filename} | grep 'pollon =' | awk '{print $3}'`
68
    else 
69
       set ok       = `ncdump -h ${filename} | grep constants_file_name`
70
       set filename = `ncdump -h ${filename} | grep 'constants_file_name' | awk '{print $3}'`
71
       set filename = `echo ${filename} | sed -e 's/\"//g'`
72
       set ok       = `ncdump -h ${filename} | grep pollon`
73
       set pollon   = `ncdump ${filename}    | grep 'pollon =' | awk '{print $3}'`
74
    endif
75
 
76
    set pollat = ""
77
    set ok     = `ncdump -h ${filename} | grep pollat`
78
    if ( "${ok}" != "" ) then
79
       set pollat = `ncdump ${filename} | grep 'pollat =' | awk '{print $3}'`
80
    else 
81
       set ok       = `ncdump -h ${filename} | grep constants_file_name`
82
       set filename = `ncdump -h ${filename} | grep 'constants_file_name' | awk '{print $3}'`
83
       set filename = `echo ${filename} | sed -e 's/\"//g'`
84
       set ok       = `ncdump -h ${filename} | grep pollat`
85
       set pollat   = `ncdump ${filename}    | grep 'pollat =' | awk '{print $3}'`
86
    endif
87
 
88
    if ( ( "${pollon}" == "" ) | ( "${pollat}" == "" ) ) then
89
       echo "cannot find pollon/pollat on ${filename}... Stop"
90
       exit 1
91
    endif
92
 
93
    set pole = "${pollon} ${pollat}"
94
 
95
endif
96
 
97
# Write the pole position to the pole file  
98
\rm -f geo2rot.pole
99
echo ${pole} > geo2rot.pole
100
 
101
# Decide whether to exit from the script
102
if ( "${inpfile}" == "-lonlat" ) set poleprint = 1
103
if ( "${inpfile}" == "-file"   ) set poleprint = 1
104
 
105
# On request, print the pole position and exit
106
if ( ${poleprint} == 1 ) then
107
    cat geo2rot.pole
108
    exit 0
109
endif
110
 
111
# Decide whether a position or a trajectory is to be rotated
112
set ok1 = `echo ${inpfile} | sed -e 's/[0123456789.-]//g' | wc -w`
113
set ok2 = `echo ${outfile} | sed -e 's/[0123456789.-]//g' | wc -w`
114
 
115
if ( ( ${ok1} == 0 ) && ( ${ok2} == 0 ) ) then
116
    set mode = 'position'
117
    set lon  = ${inpfile}
118
    set lat  = ${outfile}
119
else if ( ( ${ok1} != 0 ) && ( ${ok2} != 0 ) ) then
120
    set mode = 'trajectory'
121
    if ( ! -f ${inpfile} ) then
122
       echo "${inpfile} is missing... Stop"
123
       exit 1
124
    endif
125
else
126
    set mode = 'nil'
127
endif
128
 
129
# Decide whether the Fortran programe needs to be launched
130
if ( "${mode}" == "nil" ) then
131
    exit 0
132
endif
133
 
134
# Prepare the parameter file and run Fortran program
135
\rm -f geo2rot.param
136
echo \"${mode}\"                             >! geo2rot.param
137
if ( "${mode}" == "position" ) then
138
   echo ${lon}                               >> geo2rot.param
139
   echo ${lat}                               >> geo2rot.param
140
else if ( "${mode}" == "trajectory" ) then
141
   echo \"${inpfile}\"                       >> geo2rot.param
142
   echo \"${outfile}\"                       >> geo2rot.param
143
   ${LAGRANTO}/bin/trainfo.sh ${inpfile} dim >> geo2rot.param
144
endif
145
echo ${pole} >> geo2rot.param
146
 
147
${LAGRANTO}/goodies/geo2rot
148
 
149
# Make clean
150
#\rm -f geo2rot.param
151
 
152
exit 0
153