photos_montage_aladin_osx.sh 43 KB
Newer Older
1
2
3
4
#!/bin/sh

. ./.env

5
6
7
export LC_CTYPE=C
export LANG=C

8
9
10
#---------------------------#
#-------- functions --------#
#---------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
11
function_message()
12
{
PENGUEN Julien's avatar
PENGUEN Julien committed
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  # function_message: display message with input argument
  # input error_message to display

  type_message=$1
  message=$2

  if [ "$type_message" == "TYPE_VAL_ERROR" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
    echo -e "\033[31m========================================================="
    echo -e "WARNING => ${message}"
    echo -e "=========================================================\033[0m"

  elif [ "$type_message" == "TYPE_HELP" ]; then

    echo ""
    echo "------------------------------------"
    echo ""
    echo -e "\033[32m========"
    echo -e "= HELP ="
    echo -e "========\033[0m"

  elif [ "$type_message" == "TYPE_UNKNOWN" ]; then
    echo ""
    echo -e "\033[31m==============================="
    echo -e " error: unrecognized arguments "
    echo -e "===============================\033[0m"

  elif [ "$type_message" == "TYPE_EXIST_VERSION" ]; then

    echo ''
    echo -e "\033[31m===================================="
    echo -e "             WARNING"
    echo -e "====================================\033[0m"
    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 ''


  elif [ "$type_message" == "TYPE_FORCE_WARNING" ]; then

    echo ''
    echo -e "\033[31m===================================="
    echo -e "             WARNING"
    echo -e "====================================\033[0m"
    echo ''
    echo '------------------------------------'
    echo ''
    echo "With option --force you must select an existing area"
    echo ''
    echo 'Please see the available area(s) on:'
    echo ''
    echo "${message}"
    echo ''
    echo '------------------------------------'
    echo ''

  elif [ "$type_message" == "TYPE_DELETE_EXIST_VERSION" ]; then

    echo ''
    echo -e "\033[31m===================================="
    echo -e "             WARNING"
    echo -e "====================================\033[0m"
    echo ''
    echo '------------------------------------'
    echo ''
    echo "You must delete an existing version"
    echo "    available on the localhost     "
    echo ''
    echo 'To see the available version(s):'
    echo ''
    echo "Please make ./photos_montage_aladin.sh -i OR --infos"
    echo ''
    echo '------------------------------------'
    echo ''

  elif [ "$type_message" == "TYPE_UPDATE" ]; then

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

  else

    echo "BLA BLA"

  fi

  if [[ "$type_message" == "TYPE_VAL_ERROR" || "$type_message" == "TYPE_HELP" || "$type_message" == "TYPE_UNKNOWN" ]]; then

    echo ""
    echo "------------------------------------"
    echo ""
    echo "use : ./photos_montage_aladin.sh [options] [others]"
    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 ""
    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'"
    echo "--area file                        run photos_montage_aladin with this survey file instead of "
    echo "the default file define on .env file. the area file must be on format '.csv'"
    echo ""
    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"
    echo "--resolution_col                   run photos_montage_aladin with this number of pixel by columns for the Image Magick montages"
    echo "--resolution_line                  run photos_montage_aladin with this number of pixel by lines for the Image Magick montages"
    echo ""
  fi

}


function_build_tab_hach()
{
  # 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
  # - message: in case of error, error message

  # ---------------------- #
  # 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

  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";
  ARRAY["--angular"]="NUMBER";
  ARRAY["--resolution_line"]="NUMBER";
  ARRAY["--resolution_col"]="NUMBER";

  # ---------------------- #
  # 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;
  ARGS_WEIGHT["--angular"]=2;
  ARGS_WEIGHT["--resolution_line"]=2;
  ARGS_WEIGHT["--resolution_col"]=2;

  # -------- #

  indice=0;

  for params in "$@"
  do
    tab_params[$indice]=$params
    ((indice++));
  done

  # -------- #
  val_error="FALSE"
  elements_ok=0

  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

        elements_ok=$(($elements_ok + 1))
        tab_keys[$indice]=$elem
        tab_values[$indice]="None"
        tab_weight[$indice]=${ARGS_WEIGHT[${elem}]}

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

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

          if [[ ${tab_params[$indice +1]} != "" && $FOUND == "" && ${tab_params[$indice +1]} != -* ]]; then
            #case argument needed for the option is present on input argument
            tab_values[$indice]=${tab_params[$indice +1]}
            elements_ok=$(($elements_ok + 1))
          else
            #case argument needed for the option is missing on input argument
            message="Missing argument for the option "${elem}
            val_error="TRUE"
          fi

        fi

      fi

      ((indice++));

    done

  done
# echo "elements_ok="$elements_ok
# echo "total ${#@}"

  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"

}

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[@]}"

}

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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

}

function_jar_updated_search()
{
  # function_jar_updated_search: get the last jar version
  # returns:
  #    return number_version

  curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" > .temp
  sed -i '' '/Official version/!d' .temp
  version=$(cut -d">" -f3 .temp)
  rm .temp

  number_version=$(echo ${version:1})
  echo "$number_version"

}

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 ..."

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

  echo "=> Deleting the image_photos_montage_aladin-$1 docker image successfully"

}

function_build_image()
{
  # function_build_image: build the photos_montage_aladin image

      version=$1

      #----------------------------------------#
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" > .tempo
      sed -i '' '/Official version/!d' .tempo
      awk -F">" '{print $3}' .tempo > .tempo5
      sed -i '' 's/v//' .tempo5
      curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" > .tempo2
      sed -i '' '/<!--/d' .tempo2
      sed -i '' '/last/!d' .tempo2
      awk -F">" '{print $3}' .tempo2 > .tempo3
      awk -F"<" '{print $1}' .tempo3 > .tempo4
      sed -i '' 's/\.jar//' .tempo4
      sed -i '' 's/Aladin//' .tempo4
      cat .tempo4 >> .tempo5
      list_jar=$(sort -r .tempo5 | awk '{print $1}')
      rm .tempo*

PENGUEN Julien's avatar
PENGUEN Julien committed
452
      present=$(echo $list_jar| grep "${version}")
453
454
455

      if [ $? -eq 1 ]; then

PENGUEN Julien's avatar
PENGUEN Julien committed
456
        function_message "TYPE_EXIST_VERSION"
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
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
522
523
524
525
526
527
        exit 0


      else

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

        id_image=$(docker inspect --format="{{.Id}}" image_photos_montage_aladin-${version})

        if [ ${id_image} ]; then

          echo "=> The image_photos_montage_aladin-${version} docker image already exist"
          echo ''

        else

          #----------------------------------------#
          curl -s ${ALADIN_URL}"/nph-aladin.pl?frame=downloading" > .temp
          sed -i '' '/Official version/!d' .temp
          tempo=$(cut -d">" -f3 .temp)
          rm .temp

          aladin_last_number_version=$(echo ${tempo:1})
          #----------------------------------------#

          if [ ${aladin_last_number_version} == ${version} ]; then
            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin.jar --no-check-certificate
            mv conf-montage/Aladin.jar conf-montage/Aladin-${version}.jar
          else
            wget -o .logfile -P conf-montage ${ALADIN_URL}/Aladin${version}.jar --no-check-certificate
            mv conf-montage/Aladin${version}.jar conf-montage/Aladin-${version}.jar

          fi

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

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

          echo "=> creating the photos_montage_aladin-${version} docker image successfully"
          echo '------------------------------------------------------------------'
          echo ''
          #-----------------#

          rm conf-montage/Aladin-${version}.jar
          rm .logfile

        fi
      fi

}



function_create_ajs_file()
{
  # function_create_ajs_file : create ajs surveys file

inputfile=$1
outputfile=$2
area=$3
ra_area=$4
dec_area=$5
outputfolder=$6


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

528
echo "reset" > ${outputfile}
529
530
531
532
533
534
535
536

number=0;

for survey in ${list_survey}
do
    i=0;
    ((number++));

537
538
    echo "#" >> ${outputfile}
    echo "rm @1" >> ${outputfile}
PENGUEN Julien's avatar
PENGUEN Julien committed
539
    echo "get HiPS("$survey")" ${ra_area} ${dec_area} ${ANGULAR}"'" >> ${outputfile}
540
    echo "cm BB localcut" >> ${outputfile}
541
542
543
544
545
546
547
548
549
550
551
552
553


    for val in `echo $survey | tr "/" " "`;
    do
     ((i++));
     tab[$i]=${val}
    done

    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
554
    echo "save 200x200 ${outputfolder}/$chaine" >> ${outputfile}
555
556
557
558
559
560
561
562
563
564
565


done



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

PENGUEN Julien's avatar
PENGUEN Julien committed
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
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
823
824
825
#---------------------#
# management arguments
# call function_sort_tab

RESULTAT=`function_build_tab_hach $@`

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

#------------------------------------#
#check if val_error is TRUE

if [ $val_error == "TRUE" ]; then
  error_message=`echo $RESULTAT | cut --delimiter=, -f 5`

  function_message "TYPE_VAL_ERROR" "${error_message}"
  exit 0
fi

#------------------------------------#
#check options presents
#to manage '--select' and '--no_select'
#options

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' || "${tempo_arg_keys[0]}" == '--force' ]]; then
        #case '--force_all', '--force'

        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


    elif [ "${tempo_arg_weight[0]}" -eq 2 ]; then
        #case '--survey', '--area' ,'--angular'

        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

      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


    fi

    if [ "$tempo_weight_2" == 'TRUE' ]; then
      #case '--survey', '--area' ,'--angular'

        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[@]// / } )



    fi

    ;;
esac


#--------------------------#
# 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// / } )

#------------------------------#
#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

#-------------------------------------#
#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

#-------------------------------------#
#check resolution line input args

if [[ "${sort_arg_keys[@]}" =~ "--resolution_line" ]]; then

  RESULT_INDICE_RESOLUTION_LINE=`function_return_indice_arg "${sort_arg_keys[*]}" "--resolution_line"`
  RESOLUTION_BY_LINE=${sort_arg_values[$RESULT_INDICE_RESOLUTION_LINE]}

fi

#-------------------------------------#
#check resolution col input args

if [[ "${sort_arg_keys[@]}" =~ "--resolution_col" ]]; then

  RESULT_INDICE_RESOLUTION_COL=`function_return_indice_arg "${sort_arg_keys[*]}" "--resolution_col"`
  RESOLUTION_BY_COL=${sort_arg_values[$RESULT_INDICE_RESOLUTION_COL]}

fi

#---------------------#
# --no_select management

if [ "${sort_arg_keys[0]}" == "--no_select" ]; then
  sort_arg_keys[0]=""
  sort_arg_values[0]=""
  sort_arg_weight[0]=0
fi

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


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


#=============================================================#
#=============================================================#
#=============================================================#



case ${sort_arg_keys[0]} in
    ""|"--select")
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
      ###################################
      # use: ./photos_montage_aladin.sh #
      ###################################
      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`
        #----------------------------------------#
        sed -i '' "s/ALADIN_VERSION=?/ALADIN_VERSION=${aladin_last_number_version}/" .env

      else

        init='FALSE'

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

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

        version=${aladin_last_number_version}

      else
PENGUEN Julien's avatar
PENGUEN Julien committed
856
        if [ "${sort_arg_keys[0]}" == "--select" ]; then
857
858
859
860
861
862

          # --------------- #
          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
PENGUEN Julien's avatar
PENGUEN Julien committed
863
          present=$(echo $list_jar| grep "${sort_arg_values[0]}")
864
865
866

          if [ $? -eq 1 ]; then

PENGUEN Julien's avatar
PENGUEN Julien committed
867
            function_message "TYPE_EXIST_VERSION"
868
869
870
871
            exit 0

          else

PENGUEN Julien's avatar
PENGUEN Julien committed
872
            version=${sort_arg_values[0]}
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899

          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

PENGUEN Julien's avatar
PENGUEN Julien committed
900
        function_message "TYPE_UPDATE" "${aladin_last_number_version}"
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
        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

      #------------------------#
      #creation of main_folder

      main_folder=$HOME"/.photos_montage_aladin"

      if [ -d ${main_folder} ]; then
        echo "=> ${main_folder} exist"
        echo " "
      else
        mkdir ${main_folder}
        echo "=> creation of " ${main_folder}
        echo " "

      fi

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

      indice=0

      while read enreg
      do
        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
      done < ${INPUT_FILE_AREAS}

      #------------------------#
951
952
953
954
955
956
957
958
      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))



959
960
961
962
963
964
965
966
967
968
969
      #------------------------#
      #loop on areas

      for k in ${!list_zone[*]}
      do

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

      #------------------------#
PENGUEN Julien's avatar
PENGUEN Julien committed
970
        if [ "${sort_arg_keys[1]}" == "--force-all" ]; then
971
972
          force='TRUE'
          force_all='TRUE'
PENGUEN Julien's avatar
PENGUEN Julien committed
973
974
          force_warning='FALSE'
        elif [[ "${sort_arg_keys[1]}" == "--force" && "${sort_arg_values[1]}" == ${list_zone[$k]} ]]; then
975
976
          force='TRUE'
          force_all='FALSE'
PENGUEN Julien's avatar
PENGUEN Julien committed
977
978
979
980
981
          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'
982
983
984
985
986
987
988
989
990
991
        else
          force='FALSE'
        fi

        #------------------------#
        area_folder[$k]=${main_folder}"/"${list_zone[$k]}
        tempo_folder[$k]=${area_folder[$k]}
        images_folder[$k]=${area_folder[$k]}"/images"
        montages_folder[$k]=${area_folder[$k]}"/montages"
        area_ajs[$k]=${tempo_folder[$k]}"/area_"${list_zone[$k]}".ajs"
PENGUEN Julien's avatar
PENGUEN Julien committed
992
993
        log_aladin_file[$k]=${area_folder[$k]}"/"${list_zone[$k]}".log"
        infos_file[$k]=${area_folder[$k]}"/infos_"${list_zone[$k]}".txt"
994
995
996
997
998
999
1000

        #------------------------#
        if [ -d ${area_folder[$k]} ]; then
          if [ $force == 'TRUE' ]; then
            rm -rf ${area_folder[$k]} #case --force

            if [ $force_all == 'TRUE' ]; then
For faster browsing, not all history is shown. View entire blame