Commit 5112f1610ec21ecde872365c2fd86c2b302b1799

Authored by Jean-Philippe Bernard
1 parent 14c90b64
Exists in master

First commit

Showing 1 changed file with 130 additions and 0 deletions   Show diff stats
src/idl/dustem_set_up_fortran.pro 0 → 100644
... ... @@ -0,0 +1,130 @@
  1 +FUNCTION dustem_set_up_fortran,random_name=random_name,user_number=user_number
  2 +
  3 +;du=dustem_set_up_fortran(/random_name,user_number=user_number)
  4 +
  5 +;The idea is to modify the dustem fortran to make it run independently between users
  6 +;Method is:
  7 +;1/ modify input file that needs to be
  8 +;2/ compile fortran to a executable with a given name
  9 +;3/ modify the dustem system variables accordingly
  10 +
  11 +;Please do:
  12 +;cp DM_constants.f90 DM_constants_saved.f90
  13 +;cp dustem dustem_saved
  14 +;before first use of this routine (!!)
  15 +
  16 +dustem_user='dustem_user' ;default name
  17 +user_number=''
  18 +IF keyword_set(random_name) THEN BEGIN
  19 + user_number=strtrim(long(abs(randomn(seed))*1.e5),2)
  20 + dustem_user='dustem_user'+user_number
  21 +ENDIF
  22 +
  23 +dustem_dat='/tmp/'+dustem_user
  24 +dustem_res='/tmp/'+dustem_user
  25 +
  26 +;1/
  27 +;read DM_constants.f90
  28 +fortran_file_name=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants.f90'
  29 +fortran_file_name_modified=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants_modified.f90'
  30 +
  31 +openr,unit,fortran_file_name,/get_lun
  32 +line=' '
  33 +lines=[' ']
  34 +WHILE NOT eof(unit) DO BEGIN
  35 + readf,unit,line
  36 + lines=[lines,line]
  37 +ENDWHILE
  38 +lines=lines[1:*]
  39 +close,unit
  40 +free_lun,unit
  41 +
  42 +original_lines=lines ;This is to be able to recompile the original dustem when over
  43 +
  44 +Nlines=n_elements(lines)
  45 +search_what="data_path='"
  46 +search_length=strlen(search_what)
  47 +FOR i=0L,Nlines-1 DO BEGIN
  48 + pos=strposmulti(lines[i],search_what,count)
  49 + IF count NE 0 THEN BEGIN
  50 + new_line=strmid(lines[i],0,pos[0]+search_length)
  51 + new_line=new_line+dustem_dat
  52 + new_line=new_line+"'"
  53 + print,new_line
  54 + lines[i]=new_line
  55 + ;stop
  56 + ENDIF
  57 +ENDFOR
  58 +
  59 +search_what="dir_PDR='"
  60 +search_length=strlen(search_what)
  61 +FOR i=0L,Nlines-1 DO BEGIN
  62 + pos=strposmulti(lines[i],search_what,count)
  63 + IF count NE 0 THEN BEGIN
  64 + new_line=strmid(lines[i],0,pos[0]+search_length)
  65 + new_line=new_line+dustem_dat
  66 + new_line=new_line+"'"
  67 + print,new_line
  68 + lines[i]=new_line
  69 + ;stop
  70 + ENDIF
  71 +ENDFOR
  72 +
  73 +;stop
  74 +
  75 +;modify DM_constants.f90
  76 +openw,unit,fortran_file_name_modified,/get_lun
  77 +FOR i=0L,Nlines-1 DO BEGIN
  78 + printf,unit,lines[i]
  79 +ENDFOR
  80 +close,unit
  81 +free_lun,unit
  82 +
  83 +;stop
  84 +
  85 +;move modified file into used file
  86 +str='mv '+!DUSTEM_SOFT_DIR+'/src/'+fortran_file_name_modified+' '+!DUSTEM_SOFT_DIR+'/src/'+fortran_file_name
  87 +message,'Issuing '+str,/cont
  88 +spawn,str
  89 +
  90 +;2/ compile dustem
  91 +str='rm '+!DUSTEM_SOFT_DIR+'/src/*.o'
  92 +message,'Issuing '+str,/cont
  93 +spawn,str
  94 +
  95 +str='rm '+!DUSTEM_SOFT_DIR+'/src/*.mod'
  96 +message,'Issuing '+str,/cont
  97 +spawn,str
  98 +
  99 +str='rm '+!DUSTEM_SOFT_DIR+'/src/dustem*'
  100 +message,'Issuing '+str,/cont
  101 +spawn,str
  102 +
  103 +;3/ compile
  104 +
  105 +;str='make -f '+!DUSTEM_SOFT_DIR+'/src/Makefile'
  106 +;message,'Issuing '+str,/cont
  107 +
  108 +str='cd '+!DUSTEM_SOFT_DIR+'/src'+' & make'
  109 +message,'Issuing '+str,/cont
  110 +spawn,str
  111 +
  112 +;rename executable
  113 +
  114 +str='mv '+!DUSTEM_SOFT_DIR+'/src/dustem '+!DUSTEM_SOFT_DIR+'/src/'+dustem_user
  115 +message,'Issuing '+str,/cont
  116 +
  117 +;stop
  118 +
  119 +;change dustemwrap system variables
  120 +dustem_name=!DUSTEM_SOFT_DIR+dustem_user
  121 +
  122 +defsysv,'!dustem_f90_exec',dustem_name
  123 +defsysv,'!DUSTEM_DAT',dustem_dat
  124 +defsysv,'!DUSTEM_RES',dustem_res
  125 +
  126 +;stop
  127 +
  128 +RETURN,dustem_user
  129 +
  130 +END
0 131 \ No newline at end of file
... ...