forked from solarmonitor/solarmonitoridl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm_batch
executable file
·187 lines (164 loc) · 5.62 KB
/
sm_batch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# SolarMonitor batch script.
# It generates all the file structure and runs
# the IDL and perl scripts for solarmonitor.
#
#
sm_dirtree()
{ #sm_paths generates all the directory structure
# after an input directory ($1)
# Check whether the base directory has been set.
if [ -z $1 ]; then
# ${0/\/*\//} changes variable $0 (script currently running path)
# to just the file name.
echo ${0/\/*\//}':sm_dirtree: You need to define the base directory'
exit 1;
fi
# List of instruments for which fits and pngs are created
instruments=('bbso' 'gong' 'gsxi' 'seit' 'hxrt' 'smdi' /
'trce' 'stra' 'strb' 'slis' 'swap' 'saia' /
'shmi' 'iono' 'chmi')
# List of instruments for which movies (mpgs) are created
inst_mpgs=('lsco' 'smdi' 'seit' 'stra' 'strb' 'iono' )
# List of directories for each day of SM archives
dirs=('fits' 'pngs' 'mpgs' 'meta')
# Run over all the type of data and instruments for each.
for dir in "${dirs[@]}"; do
mkdir -p $1/$dir
if [[ $dir =~ ('fits'|'pngs') ]]; then
for inst in "${instruments[@]}"; do
mkdir -p $1/$dir/$inst
done
elif [[ $dir = 'mpgs' ]]; then
for inst in "${inst_mpgs[@]}"; do
mkdir -p $1/$dir/$inst
done
fi
done
# pngs also contain a directory with thumbnails for frontpage.
mkdir -p $1/pngs/thmb $1/pngs/ace $1/pngs/goes $1/pngs/eve
echo ${0/\/*\//}':sm_dirtree: Directories created'
}
sm_dirtree5()
{
# Create 5 days in advance for forecast
for day in {1..5}; do
if [[ `uname -s` =~ 'Linux' ]]; then
# Linux
FUTURE_DAY=`date --date="+$day day" -u +%Y/%m/%d`
elif [[ `uname -s` =~ 'Darwin' ]]; then
# Mac
FUTURE_DAY=`date -v+${day}d -u +%Y/%m/%d`
fi
mkdir -p $1/$FUTURE_DAY/meta
done
echo ${0/\/*\//}':sm_dirtree5: Future (5 days) directories created'
}
sm_var()
{
WORKING_PATH=${0/sm_batch/} # Where all the code resides
if [ ! -f $WORKING_PATH/sm_batch.cfg ]; then
echo "Configuration file $WORKING_PATH/sm_batch.cfg does not exist!"
echo ""
echo "You can find an example sm_batch.cfg in $WORKING_PATH/doc/examples."
echo "Copy this example and modify it to suit your environment."
exit 2;
fi
. $WORKING_PATH/sm_batch.cfg # Load the config file variables
TIME_START=`date -u`
TODAYS_DATE=`date -u +%Y%m%d`
TODAYS_DATE_DIR=`date -u +%Y/%m/%d`
}
sm_outlog()
{
echo "#################################################"
echo "########### SM batch running ###############"
echo "Now is "$TIME_START
echo "SM runing with variables defined in:"
echo $WORKING_PATH"/sm_batch.cfg"
echo " ------------------ sm_batch.cfg ----------------"
cat $WORKING_PATH/sm_batch.cfg | grep -v '^#' | sed -e 's/#.*//'
echo " ------------------------------------------------"
echo ''
}
sm_sswscript()
{
# It generates the cshell script to run the IDL code
SSWCSH_FILE=$TEMP_PATH/run_sm.csh
SMIDL_FILE=$TEMP_PATH/sm_batch.tmp
SMIDLLOG_FILE=$TEMP_PATH/sm_batch.log
echo $SSWCSH_FILE
echo $SMIDL_FILE
echo $SMIDLLOG_FILE
if [ ! -d $TEMP_PATH ]; then
mkdir -p $TEMP_PATH
fi
# Write idl script
echo "arm_batch, '$TEMP_PATH', '$OUTPUT_PATH'" > $SMIDL_FILE
echo "exit" >> $SMIDL_FILE
# Write cshell config/runing file
echo "#!/bin/csh" > $SSWCSH_FILE
if [[ -n $PROXY ]]; then
proxy_list="http_proxy https_proxy ftp_proxy"
for proxyset in $proxy_list; do
echo "setenv" $proxyset $PROXY >> $SSWCSH_FILE
echo "setenv" ${proxyset^^} $PROXY >> $SSWCSH_FILE
done
fi
echo "setenv SSW "$SSW_PATH >> $SSWCSH_FILE
echo "setenv SSW_INSTR \"gen eit hessi secchi stereo vobs ontology swap\"" >> $SSWCSH_FILE
echo "source \$SSW/gen/setup/setup.ssw /quiet" >> $SSWCSH_FILE
echo "setenv IDL_DIR $IDL_DIR" >> $SSWCSH_FILE
echo "setenv IDL_PATH $WORKING_PATH/idl:+$COYOTE" >> $SSWCSH_FILE
echo "setenv WORKING_PATH "$WORKING_PATH >> $SSWCSH_FILE
echo "sswidl $SMIDL_FILE >& $SMIDLLOG_FILE" >> $SSWCSH_FILE
# In the original file was calling sswidl -32; It does not work in linux
chmod 700 $SSWCSH_FILE
$SSWCSH_FILE
}
sm_processimages()
{
# It runs the perl scripts for the date
echo ${0/\/*\//}':sm_processimages:Doing Full-disk thumbs'
perl $WORKING_PATH/perl/process_thumbs.pl $1
}
sm_package()
{
tar -cvz -C $OUTPUT_PATH --exclude '*sm_files*.tar.gz' -f $OUTPUT_PATH/sm_files.tar.gz .
}
sm_upload()
{
if [ -z "$1" ]
then
SM_HOST=$REMOTE_HOST
else
SM_HOST=$1
fi
scp $OUTPUT_PATH/sm_files.tar.gz $SM_HOST:$REMOTE_PATH
ssh $SM_HOST "cd $REMOTE_PATH && tar -xvz -f sm_files.tar.gz"
}
sm_cleanup()
{
if [ -d $OUTPUT_PATH ]; then
rm -rf $OUTPUT_PATH/sm_files.tar.gz
rm -rf $OUTPUT_PATH/20*
rm -rf $OUTPUT_PATH/latest_images/
fi
}
# Load variables (local for the run, and global for SM)
sm_var
# Write out the info of this run
sm_outlog
# Create directories for SM
mkdir -p $OUTPUT_PATH/latest_images
sm_dirtree $OUTPUT_PATH/$TODAYS_DATE_DIR # Directories for today data
sm_dirtree5 $OUTPUT_PATH # Future directories for forecasting data
# Create the scripts for running IDL SM batch and Run SM batch
sm_sswscript
# Resize and stamps the images with the perl scripts
sm_processimages $OUTPUT_PATH/$TODAYS_DATE_DIR
sm_package
sm_upload
sm_upload "[email protected]"
sm_cleanup
echo "everything sounds good!"