photos_montage_aladin.sh 45.4 KB
Newer Older
PENGUEN Julien's avatar
PENGUEN Julien committed
1
2
3
4
5
6
7
#!/bin/sh

. ./.env

#---------------------------#
#-------- functions --------#
#---------------------------#
8
9

function_build_tab_hach()
PENGUEN Julien's avatar
PENGUEN Julien committed
10
{
11
12
13
14
15
16
17
  # function_build_tab_hach: retrieve and organize $@
  # on differents arrays
  # return:
  # - tab_keys: array of options present on $@
  # - tab_values: array of argument need for each option present on $@
  # - tab_weight: array of weight need for each option present on $@
  # - val_error: TRUE or FALSE depending on error
18
  # - message: in case of error, error message
19
20
21
22
23
24
25
26
27
28

  # ---------------------- #
  # ARRAY[key]=value
  #declaration of the ARRAY
  #containing the options
  #allowed by the program
  #and if there is an argument With
  #the option
  # => key : option
  # => value : None or argument
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

  declare -A ARRAY

  ARRAY["-i"]="None";
  ARRAY["--infos"]="None";
  ARRAY["-b"]="VERSION";
  ARRAY["--build"]="VERSION";
  ARRAY["--select"]="VERSION";
  ARRAY["--force-all"]="None";
  ARRAY["--force"]="AREA";
  ARRAY["-u"]="None";
  ARRAY["--update"]="None";
  ARRAY["-rm"]="VERSION";
  ARRAY["--remove"]="VERSION";
  ARRAY["-h"]="None";
  ARRAY["--help"]="None";
  ARRAY["-v"]="None";
  ARRAY["--version"]="None";
  ARRAY["--survey"]="PATH FILE SURVEYS";
  ARRAY["--area"]="PATH FILE AREAS";
49
  ARRAY["--angular"]="NUMBER";
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
  # ---------------------- #
  # ARRAY_WEIGHT[key]=value
  #declaration of the ARRAY_WEIGHT
  #containing the options
  #allowed by the program
  #and the weight of each option
  # => key : option
  # => value : weight

  declare -A ARGS_WEIGHT

  ARGS_WEIGHT["--select"]=0;
  ARGS_WEIGHT["--no_select"]=0;
  ARGS_WEIGHT["--force-all"]=1;
  ARGS_WEIGHT["--force"]=1;
  ARGS_WEIGHT["--update"]=1;
  ARGS_WEIGHT["-u"]=1;
  ARGS_WEIGHT["-i"]=1;
  ARGS_WEIGHT["--infos"]=1;
  ARGS_WEIGHT["-b"]=1;
  ARGS_WEIGHT["--build"]=1;
  ARGS_WEIGHT["-rm"]=1;
  ARGS_WEIGHT["--remove"]=1;
  ARGS_WEIGHT["-h"]=1;
  ARGS_WEIGHT["--help"]=1;
  ARGS_WEIGHT["-v"]=1;
  ARGS_WEIGHT["--version"]=1;
  ARGS_WEIGHT["--survey"]=2;
  ARGS_WEIGHT["--area"]=2;
80
  ARGS_WEIGHT["--angular"]=2;
81

82
83
84
85
86
87
  # -------- #

  indice=0;

  for params in "$@"
  do
88
89
    tab_params[$indice]=$params
    ((indice++));
90
91
92
93
  done

  # -------- #
  val_error="FALSE"
94
  elements_ok=0
95
96
97
98
99
100
101
102
103
104

  for elem in ${!ARRAY[*]} ; do

    indice=0;

    for param in "$@" #loop on input args
    do
      if [ "${elem}" == $param ]; then
        #if option of ARRAY is find among input argument

105
        elements_ok=$(($elements_ok + 1))
106
107
        tab_keys[$indice]=$elem
        tab_values[$indice]="None"
108
        tab_weight[$indice]=${ARGS_WEIGHT[${elem}]}
109
110
111
112
113
114

        if [ "${ARRAY[${elem}]}" != "None" ]; then
          #case argument needed for the option

          FOUND=$(echo ${!ARRAY[*]} | grep -- "${tab_params[$indice +1]}")

115
          if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then
116
          #if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" ]]; then
117
            #case argument needed for the option is present on input argument
118
            tab_values[$indice]=${tab_params[$indice +1]}
119
            elements_ok=$(($elements_ok + 1))
120
          else
121
            #case argument needed for the option is missing on input argument
122
123
            #val_element=${elem}
            message="Missing argument for the option "${elem}
124
125
126
127
128
129
130
131
132
133
134
135
            val_error="TRUE"
          fi

        fi

      fi

      ((indice++));

    done

  done
136
137
# echo "elements_ok="$elements_ok
# echo "total ${#@}"
138

139
140
141
142
143
144
145
146
147
148
149
150
151
  if [ "$val_error" == "FALSE" ]; then
    # echo "val_error false"
    if [ "$elements_ok" -ne "${#@}" ]; then
      # echo "val_error true"

      val_error="TRUE"
      message="Option not found"
    else
      val_error="FALSE"
    fi
  fi

  echo "${tab_keys[@]},${tab_values[@]},${tab_weight[@]},$val_error,$message"
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

}

function_sort_tab()
{
  # function_sort_tab: sort input arrays depending on weight
  # inputs:
  # - tab_keys: array of options present on $@
  # - tab_values: array of argument need for each option present on $@
  # - tab_weight: array of weight need for each option present on $@
  # return:
  # - sort_arg_keys: array 'tab_keys' sorted by weight
  # - sort_arg_values: array 'tab_values' sorted by weight
  # - sort_arg_weight: array 'tab_weight' sorted by weight

  #--------------------------#
  # retrieving input arrays
  tab_arg_keys=$1
  tab_arg_values=$2
  tab_arg_weight=$3

  arg_keys=( ${tab_arg_keys// / } )
  arg_values=( ${tab_arg_values// / } )
  arg_weight=( ${tab_arg_weight// / } )

  #--------------------------#
  indice=0
  indice_weight=0
  l=0

  #--------------------------#
  # sorts input arrays

  while [ $indice -ne ${#arg_weight[@]} ];
   do
    if [ ${arg_weight[$l]} -eq $indice_weight ]; then
      sort_arg_keys[$indice]=${arg_keys[$l]}
      sort_arg_values[$indice]=${arg_values[$l]}
      sort_arg_weight[$indice]=${arg_weight[$l]}
      indice=$(($indice + 1))
      l=$(($l + 1))
    else
      l=$(($l + 1))
    fi

    if [ $l -eq ${#arg_weight[@]} ]; then
      l=0
      indice_weight=$(($indice_weight + 1))
    fi

   done

  #--------------------------#
  #return arrays sorted

  echo "${sort_arg_keys[@]},${sort_arg_values[@]},${sort_arg_weight[@]}"
PENGUEN Julien's avatar
PENGUEN Julien committed
208
209
210

}

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
function_return_indice_arg()
{
  # function_return_indice_arg: get the indice in input array of the element we want
  # input:
  # -tab: array of options present on $@
  # -find_arg: option we want find
  # return:
  # -indice of the option we want find

  #---------------#
  #input arguments
  tab=$1
  find_arg=$2
  #---------------#

  tempo_tab=( ${tab// / } )
  val="None"

  #------------------------------------#
  #loop to find indice of option we want
  for k in ${!tempo_tab[*]}
  do
    if [ "${tempo_tab[$k]}" == "$find_arg" ]; then
      val=$k
    fi
  done
  #------------------------------------#

  echo $val

}

PENGUEN Julien's avatar
PENGUEN Julien committed
243
244
245
246
247
248
function_jar_updated_search()
{
  # function_jar_updated_search: get the last jar version
  # returns:
  #    return number_version

249
  version=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
PENGUEN Julien's avatar
PENGUEN Julien committed
250
251
252
253
254
  number_version=$(echo ${version:1})
  echo "$number_version"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
255
256
257
258
259
260
261
function_delete_image()
{
  # function_delete_image: delete the image
  # params:
  #    $1 - photos_montage_aladin version image to delete

  echo "- Deleting the photos_montage_aladin-$1 docker image ..."
262

263
264
  old_id=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-$1)
  sudo docker rmi ${old_id} #remove old photos_montage_aladin image
265

PENGUEN Julien's avatar
PENGUEN Julien committed
266
267
268
269
  echo "=> Deleting the image_photos_montage_aladin-$1 docker image successfully"

}

PENGUEN Julien's avatar
PENGUEN Julien committed
270
271
272
273
274
275
function_build_image()
{
  # function_build_image: build the photos_montage_aladin image

      version=$1

PENGUEN Julien's avatar
PENGUEN Julien committed
276
      #----------------------------------------#
277
278
279
280
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3 | sed 's/v//' > .temp
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
      list_jar=$(sort -r .temp | awk '{print $1}')
      rm .temp
281

282
      present=$(echo $list_jar| grep "${version}")
PENGUEN Julien's avatar
PENGUEN Julien committed
283
284
285

      if [ $? -eq 1 ]; then

286
287
288
289
        echo ''
        echo -e "\033[31m===================================="
        echo -e "             WARNING"
        echo -e "====================================\033[0m"
PENGUEN Julien's avatar
PENGUEN Julien committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
        echo ''
        echo '------------------------------------'
        echo ''
        echo "You must select an existing version"
        echo "            available on   "
        echo "   https://aladin.u-strasbg.fr   "

        echo ''
        echo 'To see the available version(s):'
        echo ''
        echo "Please make ./photos_montage_aladin.sh -i OR --infos"
        echo ''
        echo '------------------------------------'
        echo ''
        exit 0


      else

        echo ''
        echo "- Searching for the current photos_montage_aladin-${version} docker image ..."
311

312
        id_image=$(sudo docker inspect --format="{{.Id}}" image_photos_montage_aladin-${version})
PENGUEN Julien's avatar
PENGUEN Julien committed
313
314
315

        if [ ${id_image} ]; then

PENGUEN Julien's avatar
PENGUEN Julien committed
316
          echo "=> The image_photos_montage_aladin-${version} docker image already exist"
PENGUEN Julien's avatar
PENGUEN Julien committed
317
318
319
          echo ''

        else
PENGUEN Julien's avatar
PENGUEN Julien committed
320
321

          #----------------------------------------#
322
          tempo=$(curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3)
Julien Penguen's avatar
Julien Penguen committed
323

PENGUEN Julien's avatar
PENGUEN Julien committed
324
          aladin_last_number_version=$(echo ${tempo:1})
Julien Penguen's avatar
Julien Penguen committed
325
326
          echo "${aladin_last_number_version}"
          echo "${version}"
PENGUEN Julien's avatar
PENGUEN Julien committed
327
          #----------------------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
328

PENGUEN Julien's avatar
PENGUEN Julien committed
329
          if [ ${aladin_last_number_version} == ${version} ]; then
Julien Penguen's avatar
Julien Penguen committed
330
            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin.jar --no-check-certificate
331
            mv conf-montage/Aladin.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
332
          else
Julien Penguen's avatar
Julien Penguen committed
333
334

            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin${version}.jar --no-check-certificate
PENGUEN Julien's avatar
PENGUEN Julien committed
335
            mv conf-montage/Aladin${version}.jar conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
336
337
338
339
340
341
342

          fi

          #-----------------#
          #build
          echo "- Creating the photos_montage_aladin-${version} docker image in progress ..."
          echo '------------------------------------------------------------------'
343
344
345

          sudo docker build --build-arg username=$USER --build-arg uidval=$UID --build-arg home=$HOME --build-arg aladin_version=${version} -t image_photos_montage_aladin-${version} conf-montage

PENGUEN Julien's avatar
PENGUEN Julien committed
346
347
348
349
350
          echo "=> creating the photos_montage_aladin-${version} docker image successfully"
          echo '------------------------------------------------------------------'
          echo ''
          #-----------------#

351
          rm conf-montage/Aladin-${version}.jar
PENGUEN Julien's avatar
PENGUEN Julien committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
          rm .logfile

        fi
      fi

}



function_create_ajs_file()
{
  # function_create_ajs_file : create ajs surveys file

inputfile=$1
outputfile=$2
367
368
area=$3
ra_area=$4
PENGUEN Julien's avatar
PENGUEN Julien committed
369
370
dec_area=$5
outputfolder=$6
PENGUEN Julien's avatar
PENGUEN Julien committed
371
372
373
374
375
376
377
378
379
380
381
382


list_survey=$(awk '{print $1}' $inputfile)

echo -e "reset" > ${outputfile}

number=0;

for survey in ${list_survey}
do
    i=0;
    ((number++));
PENGUEN Julien's avatar
PENGUEN Julien committed
383
    #echo -e "$survey"
PENGUEN Julien's avatar
PENGUEN Julien committed
384
385
386

    echo -e "#" >> ${outputfile}
    echo -e "rm @1" >> ${outputfile}
387
    echo -e "get HiPS("$survey")" ${ra_area} ${dec_area} ${ANGULAR}"'" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
388
389
390
391
    echo -e "cm BB localcut" >> ${outputfile}


    for val in `echo $survey | tr "/" " "`;
392
    do
PENGUEN Julien's avatar
PENGUEN Julien committed
393
394
395
396
     ((i++));
     tab[$i]=${val}
    done

PENGUEN Julien's avatar
PENGUEN Julien committed
397
398
399
400
401
402
    if [ $number -lt '10' ]; then
      chaine="0${number}_${area}-${tab[$i-1]}_${tab[$i]}.jpg"
    else
      chaine="${number}_${area}-${tab[$i-1]}_${tab[$i]}.jpg"
    fi
    echo -e "save 200x200 ${outputfolder}/$chaine" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
403
404
405
406
407
408
409
410
411
412
413


done



}
#-----------------------------------------#
#----------- main program ----------------#
#-----------------------------------------#

414
415
#---------------------#
# management arguments
416
# call function_sort_tab
417
418
419
420
421

RESULTAT=`function_build_tab_hach $@`

tab_arg_keys=`echo $RESULTAT | cut --delimiter=, -f 1`
tab_arg_values=`echo $RESULTAT | cut --delimiter=, -f 2`
422
423
tab_arg_weight=`echo $RESULTAT | cut --delimiter=, -f 3`
val_error=`echo $RESULTAT | cut --delimiter=, -f 4`
424

425
#------------------------------------#
426
#check if val_error is TRUE
427
428

if [ $val_error == "TRUE" ]; then
429
  error_message=`echo $RESULTAT | cut --delimiter=, -f 5`
430
431
432
433
434

  echo ""
  echo "------------------------------------"
  echo ""
  echo -e "\033[31m========================================================="
435
  echo -e "WARNING => ${error_message}"
436
437
438
439
  echo -e "=========================================================\033[0m"
  echo ""
  echo "------------------------------------"
  echo ""
440
  echo "use : ./photos_montage_aladin.sh [options] [others]"
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
  echo ""
  echo ""
  echo "OPTIONS:"
  echo ""
  echo "-i, --infos                        give informations about versions available on aladin server"
  echo "                                   and about photos_montage_aladin image present on localhost"
  echo "-b version, --build version        build photos_montage_aladin image with selected version"
  echo "--select version                   run photos_montage_aladin with selected version number"
  echo "--force-all                        re-run all areas in input csv"
  echo "--force area                       re-run for the area, the area must be in input csv"
  echo "-u, --update                       update photos_montage_aladin image version"
  echo "-rm version, --remove version      remove photos_montage_aladin image with selected version"
  echo "-h, --help                         show this help message and exit"
  echo "-v, --version                      give photos_montage_aladin.sh current version number"
  echo ""
456
457
458
459
460
  echo ""
  echo "OTHERS:"
  echo ""
  echo "--survey file                      run photos_montage_aladin with this survey file instead of "
  echo "the default file define on .env file. the survey file must be on format '.dat'"
461
  echo "--area file                        run photos_montage_aladin with this survey file instead of "
462
  echo "the default file define on .env file. the area file must be on format '.csv'"
463
464
  echo "--angular                          run photos_montage_aladin with this angular dimension value instead of "
  echo "the default angular value define on .env file. the angular value must be on second of arc"
465
  echo ""
466
467
468
469
470
471
  echo "------------------------------------"
  echo ""
  exit 0

fi

472
#------------------------------------#
473
#check options presents
474
475
#to manage '--select' and '--no_select'
#options
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521

tempo_arg_weight=( ${tab_arg_weight// / } )
tempo_arg_keys=( ${tab_arg_keys// / } )

taille=${#tempo_arg_weight[@]}

case $taille in
  "0")
    #---------------------#
    #case 0 input argument
    #---------------------#
    tab_arg_keys[0]="--no_select"
    tab_arg_values[0]="$ALADIN_VERSION"
    tab_arg_weight[0]=0
    arg_keys=( ${tab_arg_keys[@]// / } )
    arg_values=( ${tab_arg_values[@]// / } )
    arg_weight=( ${tab_arg_weight[@]// / } )

    ;;
  "1")
    #---------------------#
    #case 1 input argument
    #---------------------#
    if [ "${tempo_arg_weight[0]}" -eq 0 ]; then
      # case option with weight=0 ('--select')

      arg_keys=( ${tab_arg_keys// / } )
      arg_values=( ${tab_arg_values// / } )
      arg_weight=( ${tab_arg_weight// / } )


    elif [ "${tempo_arg_weight[0]}" -eq 1 ]; then
      #case option with weight=1

      if [ "${tempo_arg_keys[0]}" == '--force-all' ]; then
        #case '--force_all'

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )
522

523
524
      else
        #case '-i','--infos','-u','--update','-h','-v','--version'
525

526
527
528
529
530
531
532
        arg_keys=( ${tab_arg_keys// / } )
        arg_values=( ${tab_arg_values// / } )
        arg_weight=( ${tab_arg_weight// / } )

      fi


533
    elif [ "${tempo_arg_weight[0]}" -eq 2 ]; then
534
        #case '--survey', '--area' ,'--angular'
535
536
537
538
539
540
541
542
543
544
545
546

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )


547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
    else

      echo '=> No case possible for the moment'

    fi

    ;;
  *)
    #-----------------------------#
    #case 2 or more input arguments
    #-----------------------------#
    for p in ${!tempo_arg_keys[*]}
    do
      echo "${tempo_arg_keys[$p]}"

      if [ ${tempo_arg_weight[$p]} -eq 0 ]; then
        tempo_weight_0="TRUE"
      elif [ ${tempo_arg_weight[$p]} -eq 1 ]; then
        tempo_weight_1="TRUE"
        indice_tempo_weight_1=$p
      elif [ ${tempo_arg_weight[$p]} -eq 2 ]; then
        tempo_weight_2="TRUE"
      fi

    done

    if [[ "$tempo_weight_0" == 'TRUE' && "$tempo_weight_2" == 'FALSE' ]]; then
      #case '--select'
      arg_keys=( ${tab_arg_keys// / } )
      arg_values=( ${tab_arg_values// / } )
      arg_weight=( ${tab_arg_weight// / } )
    fi

    if [ "$tempo_weight_1" == 'TRUE' ]; then

      if [ "${tempo_arg_keys[$indice_tempo_weight_1]}" == '--force-all' ]; then
        #case '--force_all'

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )

      else
        #case '-i','--infos','-u','--update','-h','-v','--version'

        arg_keys=( ${tab_arg_keys// / } )
        arg_values=( ${tab_arg_values// / } )
        arg_weight=( ${tab_arg_weight// / } )

      fi


605
606
607
    fi

    if [ "$tempo_weight_2" == 'TRUE' ]; then
608
      #case '--survey', '--area' ,'--angular'
609
610
611
612
613
614
615
616
617
618
619
620
621

        tab2_arg_keys[0]="--no_select"
        tab2_arg_values[0]="$ALADIN_VERSION"
        tab2_arg_weight[0]=0
        tab2_arg_keys[1]=${tab_arg_keys}
        tab2_arg_values[1]=${tab_arg_values}
        tab2_arg_weight[1]=${tab_arg_weight}
        arg_keys=( ${tab2_arg_keys[@]// / } )
        arg_values=( ${tab2_arg_values[@]// / } )
        arg_weight=( ${tab2_arg_weight[@]// / } )



622
623
624
625
    fi

    ;;
esac
626

627

628
#--------------------------#
629
630
631
632
633
634
635
636
637
638
639
640
641
# sort the arrays arguments
# call function_sort_tab

RESULT_SORT=`function_sort_tab "${arg_keys[*]}" "${arg_values[*]}" "${arg_weight[*]}"`

tab_sort_arg_keys=`echo $RESULT_SORT | cut --delimiter=, -f 1`
tab_sort_arg_values=`echo $RESULT_SORT | cut --delimiter=, -f 2`
tab_sort_arg_weight=`echo $RESULT_SORT | cut --delimiter=, -f 3`

sort_arg_keys=( ${tab_sort_arg_keys// / } )
sort_arg_values=( ${tab_sort_arg_values// / } )
sort_arg_weight=( ${tab_sort_arg_weight// / } )

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
#------------------------------#
#check survey or area input args

if [[ "${sort_arg_keys[@]}" =~ "--survey" ]]; then
  RESULT_INDICE_SURVEY=`function_return_indice_arg "${sort_arg_keys[*]}" "--survey"`
  INPUT_FILE_SURVEYS=${sort_arg_values[$RESULT_INDICE_SURVEY]}
fi

if [[ "${sort_arg_keys[@]}" =~ "--area" ]]; then
  RESULT_INDICE_AREA=`function_return_indice_arg "${sort_arg_keys[*]}" "--area"`
  INPUT_FILE_AREAS=${sort_arg_values[$RESULT_INDICE_AREA]}
fi

echo "=> use ${INPUT_FILE_SURVEYS}"
echo "=> use ${INPUT_FILE_AREAS}"

658
659
660
661
662
663
664
665
666
667
#-------------------------------------#
#check angular input arg

if [[ "${sort_arg_keys[@]}" =~ "--angular" ]]; then
  RESULT_INDICE_ANGULAR=`function_return_indice_arg "${sort_arg_keys[*]}" "--angular"`
  ANGULAR=${sort_arg_values[$RESULT_INDICE_ANGULAR]}
fi

echo "=> use ${ANGULAR}"

668

669
670
 #---------------------#
 # --no_select management
671

672
 if [ "${sort_arg_keys[0]}" == "--no_select" ]; then
673
674
675
676
677
   sort_arg_keys[0]=""
   sort_arg_values[0]=""
   sort_arg_weight[0]=0
 fi

678
679
#---------------------#

680
681
682
683
684
685
686
687
688
689

for k in ${!sort_arg_weight[*]}
do
  echo "sort_arg_keys[$k]=${sort_arg_keys[$k]}"
	echo "sort_arg_values[$k]=${sort_arg_values[$k]}"
	echo "sort_arg_weight[$k]=${sort_arg_weight[$k]}"
done



690
691
case ${sort_arg_keys[0]} in
    ""|"--select")
692
693
694
695
696
      ####################################################
      #      use: ./photos_montage_aladin.sh             #
      #                      or                          #
      # use: ./photos_montage_aladin.sh --select version #
      ####################################################
697

PENGUEN Julien's avatar
PENGUEN Julien committed
698
699
700
701
702
703
704
705
706
707
708
709
710
711
      version_init=$(cat .env | grep ALADIN_VERSION)

      if [ ${version_init} == "ALADIN_VERSION=?" ]; then

        init='TRUE'

        echo "INITIALISATION VERSION"

        #------------------------------------------#
        #call function function_jar_updated_search

        aladin_last_number_version=`function_jar_updated_search`
        echo "aladin_last_number_version=$aladin_last_number_version"
        #----------------------------------------#
712
        sed -i "s/ALADIN_VERSION=?/ALADIN_VERSION=${aladin_last_number_version}/" .env
PENGUEN Julien's avatar
PENGUEN Julien committed
713
714
715
716
717
718
719
720
721
722
723
724
725

      else

        init='FALSE'

      fi
      # ---------------------------------------- #

      if [ ${init} == TRUE ]; then

        version=${aladin_last_number_version}

      else
726
        if [ "${sort_arg_keys[0]}" == "--select" ]; then
PENGUEN Julien's avatar
PENGUEN Julien committed
727
728
729
730
731
732

          # --------------- #
          curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/Official version/!d' | cut -d">" -f3 | sed 's/v//' > .temp
          curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" | sed '/<!--/d'| sed '/last/!d' | cut -d">" -f3 | cut -d"<" -f1 | sed 's/\.jar//' | sed 's/Aladin//' >> .temp
          list_jar=$(sort -r .temp | awk '{print $1}')
          rm .temp
733
          present=$(echo $list_jar| grep "${sort_arg_values[0]}")
PENGUEN Julien's avatar
PENGUEN Julien committed
734
735
736

          if [ $? -eq 1 ]; then

737
738
739
740
            echo ''
            echo -e "\033[31m===================================="
            echo -e "             WARNING"
            echo -e "====================================\033[0m"
PENGUEN Julien's avatar
PENGUEN Julien committed
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
            echo ''
            echo '------------------------------------'
            echo ''
            echo "You must select an existing version"
            echo "            available on   "
            echo "   https://aladin.u-strasbg.fr   "

            echo ''
            echo 'To see the available version(s):'
            echo ''
            echo "Please make ./photos_montage_aladin.sh -i OR --infos"
            echo ''
            echo '------------------------------------'
            echo ''
            exit 0

          else

759
            version=${sort_arg_values[0]}
PENGUEN Julien's avatar
PENGUEN Julien committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822

          fi
          # --------------- #

        else

          version=${ALADIN_VERSION}

        fi

      fi

      echo ''
      echo '------------------------------------'
      echo '        Photos Montage Aladin       '
      echo ''
      echo '- aladin version: ' ${version}

      #----------------------------------------#
      #call function function_jar_updated_search

      aladin_last_number_version=`function_jar_updated_search`

      #----------------------------------------#

      if [ ${aladin_last_number_version} != ${version} ]; then

        echo ''
        echo '========================================'
        echo '     YOU ARE NOT USING THE LAST         '
        echo '            ALADIN VERSION              '
        echo '========================================'
        echo ''
        echo '=> A new ALADIN version is available:' ${aladin_last_number_version}
        echo ''
        echo 'COMMAND TO UPDATE ALADIN VERSION:'
        echo ''
        echo '=> ./photos_montage_aladin.sh -u OR --update'
        echo '------------------------------------'
        echo ''
        echo ''

        sleep 5

      else
        #case no update

        echo ''
        echo '------------------------------------'
        echo ''

      fi

      #----------------------------------------#
      #call function function_build_image

      if [ ${version} == ${ALADIN_VERSION} ]; then
        function_build_image ${ALADIN_VERSION}
      else
        function_build_image $version
      fi

      #------------------------#
823
      #creation of main_folder
PENGUEN Julien's avatar
PENGUEN Julien committed
824

825
      main_folder=$HOME"/.photos_montage_aladin"
826

PENGUEN Julien's avatar
PENGUEN Julien committed
827
      if [ -d ${main_folder} ]; then
828
829
        echo "=> ${main_folder} exist"
        echo " "
PENGUEN Julien's avatar
PENGUEN Julien committed
830
831
      else
        mkdir ${main_folder}
832
833
        echo "=> creation of " ${main_folder}
        echo " "
834

PENGUEN Julien's avatar
PENGUEN Julien committed
835
      fi
836

837
      #------------------------#
838
839
      #------------------------#

840
      indice=0
841

842
      while read enreg
843
      do
844
845
846
847
848
849
        if [ $enreg != "id,name,la,ld,ra,dec" ]; then
          list_zone[$indice]=`echo $enreg | awk -F"," '{print $2}'`
          list_ra[$indice]=`echo $enreg | awk -F"," '{print $5}'`
          list_dec[$indice]=`echo $enreg | awk -F"," '{print $6}'`
          ((indice++));
        fi
850
      done < ${INPUT_FILE_AREAS}
851

852
      #------------------------#
853
854
      #------------------------#
      #loop on areas
855

856
857
      for k in ${!list_zone[*]}
      do
858
859
860
861
862
863

      echo "============================="
      echo "${list_zone[$k]}"
      echo "============================="

      #------------------------#
864
        if [ "${sort_arg_keys[1]}" == "--force-all" ]; then
865
          force='TRUE'
866
          force_all='TRUE'
867
868
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" == ${list_zone[$k]} ]]; then
869
          force='TRUE'
870
          force_all='FALSE'
871
872
873
874
875
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" != ${list_zone[$k]} ]]; then
          force='FALSE'
          force_all='FALSE'
          force_warning='TRUE'
876
877
878
879
880
        else
          force='FALSE'
        fi

        #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
881
        area_folder[$k]=${main_folder}"/"${list_zone[$k]}
882
883
        tempo_folder[$k]=${area_folder[$k]}
        images_folder[$k]=${area_folder[$k]}"/images"
884
        montages_folder[$k]=${area_folder[$k]}"/montages"
885
        area_ajs[$k]=${tempo_folder[$k]}"/area_"${list_zone[$k]}".ajs"
886
887
        log_aladin_file[$k]=${area_folder[$k]}"/"${list_zone[$k]}".log"
        infos_file[$k]=${area_folder[$k]}"/infos_"${list_zone[$k]}".txt"
PENGUEN Julien's avatar
PENGUEN Julien committed
888

889
        #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
890
        if [ -d ${area_folder[$k]} ]; then
891
892
          if [ $force == 'TRUE' ]; then
            rm -rf ${area_folder[$k]} #case --force
893
894
895
896
897
898
899
900
901
902
903

            if [ $force_all == 'TRUE' ]; then
              echo ""
              echo "* USE OF --force-all"
              echo ""
            else
              echo ""
              echo "* USE OF --force ${list_zone[$k]}"
              echo ""
            fi

904
905
906
907
908
909
            echo "=> remove of " ${area_folder[$k]}
            mkdir ${area_folder[$k]}
            echo "=> creation of " ${area_folder[$k]}
          else
            echo "=> ${area_folder[$k]} exist"
          fi
PENGUEN Julien's avatar
PENGUEN Julien committed
910
911
        else
          mkdir ${area_folder[$k]}
912
          echo "=> creation of " ${area_folder[$k]}
PENGUEN Julien's avatar
PENGUEN Julien committed
913
        fi
914
915
        #-----------------------------#
        #call function_create_ajs_file
916

917
918
        if [ -f ${area_ajs[$k]} ]; then
          echo "=> ${area_ajs[$k]} exist"
919
        else
920
          echo -e "=> \033[31mWARNING\033[0m : ${area_ajs[$k]} not found"
921
          echo "=> construction of ${area_ajs[$k]} in progress ..."
922
          function_create_ajs_file ${INPUT_FILE_SURVEYS} ${area_ajs[$k]} ${list_zone[$k]} ${list_ra[k]} ${list_dec[k]} ${images_folder[$k]}
923
924
925
          echo "=> construction of ${area_ajs[$k]} OK"
          rm -rf ${images_folder[$k]}
          rm -rf ${montages_folder[$k]}
926
927
928
          rm ${infos_file[$k]}
          rm ${log_aladin_file[$k]}

929
930
        fi

931
        #---------------------------#
932
        #tests on images and montages
933
934
935
        #folders

        #--------#
936
        if [ -d ${images_folder[$k]} ]; then
937
          echo "=> ${images_folder[$k]} exist"
938
939
        else
          mkdir ${images_folder[$k]}
940
941
942
          echo "=> creation of " ${images_folder[$k]}
        fi
        #--------#
943
944
        if [ -d ${montages_folder[$k]} ]; then
          echo "=> ${montages_folder[$k]} exist"
945
        else
946
947
          mkdir ${montages_folder[$k]}
          echo "=> creation of " ${montages_folder[$k]}
948
        fi
949
        #--------#
950

951
        test_images_folder=$([ "$(ls -A ${images_folder[$k]})" ] && echo "Non vide" || echo "Vide")
952
        test_montages_folder=$([ "$(ls -A ${montages_folder[$k]})" ] && echo "Non vide" || echo "Vide")
953

954
        if [[ ${test_images_folder} == "Non vide" && ${test_montages_folder} == "Non vide" ]]; then
955
          nb_images[$k]=$(find ${images_folder[$k]} -type f | wc -l)
956
          nb_montages[$k]=$(find ${montages_folder[$k]} -type f | wc -l)
957
958
959
960
961
962
          nb_lines_survey=`wc -l $INPUT_FILE_SURVEYS | awk '{print $1}'`

          tempo_tile=`expr $NB_TILE_BY_LINE \* $NB_TILE_BY_COL `
          tempo2_tile=`expr ${nb_lines_survey}/${tempo_tile}`
          nb_tile=$((${tempo2_tile%.*}+1))

963
          if [[ ${nb_images[$k]} == $nb_lines_survey && ${nb_montages[$k]} == $nb_tile ]]; then
964
965
966
967
968
            state="FINISH"
            echo "=> All image(s) and montage(s) present(s) for " ${list_zone[$k]}

          else
            rm -rf ${images_folder[$k]}
969
            rm -rf ${montages_folder[$k]}
970
971

            mkdir ${images_folder[$k]}
972
            mkdir ${montages_folder[$k]}
973
974
975
976
977
978
979
980
981
982

            rm ${area_ajs[$k]}
            rm ${infos_file[$k]}
            rm ${log_aladin_file[$k]}

            echo "=> construction of ${area_ajs[$k]} in progress ..."
            function_create_ajs_file ${INPUT_FILE_SURVEYS} ${area_ajs[$k]} ${list_zone[$k]} ${list_ra[k]} ${list_dec[k]} ${images_folder[$k]}
            echo "=> construction of ${area_ajs[$k]} OK"


983
            state="RUN"
984
985
986
987

            if [ $force == 'FALSE' ]; then
              echo -e "=> \033[31mWARNING\033[0m : Missing one or more images or montages"
            fi
988
          fi
989
990

        else
991
          rm -rf ${images_folder[$k]}
992
          rm -rf ${montages_folder[$k]}
993
994

          mkdir ${images_folder[$k]}
995
          mkdir ${montages_folder[$k]}
996

997
          state="RUN"
998
999
        fi

1000
        #------------------------#
For faster browsing, not all history is shown. View entire blame