dustem_set_up_fortran.pro
2.97 KB
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
FUNCTION dustem_set_up_fortran,random_name=random_name,user_number=user_number
;du=dustem_set_up_fortran(/random_name,user_number=user_number)
;The idea is to modify the dustem fortran to make it run independently between users
;Method is:
;1/ modify input file that needs to be
;2/ compile fortran to a executable with a given name
;3/ modify the dustem system variables accordingly
;Please do:
;cp DM_constants.f90 DM_constants_saved.f90
;cp dustem dustem_saved
;before first use of this routine (!!)
dustem_user='dustem_user' ;default name
user_number=''
IF keyword_set(random_name) THEN BEGIN
user_number=strtrim(long(abs(randomn(seed))*1.e5),2)
dustem_user='dustem_user'+user_number
ENDIF
dustem_dat='/tmp/'+dustem_user
dustem_res='/tmp/'+dustem_user
;1/
;read DM_constants.f90
fortran_file_name=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants.f90'
fortran_file_name_modified=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants_modified.f90'
openr,unit,fortran_file_name,/get_lun
line=' '
lines=[' ']
WHILE NOT eof(unit) DO BEGIN
readf,unit,line
lines=[lines,line]
ENDWHILE
lines=lines[1:*]
close,unit
free_lun,unit
original_lines=lines ;This is to be able to recompile the original dustem when over
Nlines=n_elements(lines)
search_what="data_path='"
search_length=strlen(search_what)
FOR i=0L,Nlines-1 DO BEGIN
pos=strposmulti(lines[i],search_what,count)
IF count NE 0 THEN BEGIN
new_line=strmid(lines[i],0,pos[0]+search_length)
new_line=new_line+dustem_dat
new_line=new_line+"'"
print,new_line
lines[i]=new_line
;stop
ENDIF
ENDFOR
search_what="dir_PDR='"
search_length=strlen(search_what)
FOR i=0L,Nlines-1 DO BEGIN
pos=strposmulti(lines[i],search_what,count)
IF count NE 0 THEN BEGIN
new_line=strmid(lines[i],0,pos[0]+search_length)
new_line=new_line+dustem_dat
new_line=new_line+"'"
print,new_line
lines[i]=new_line
;stop
ENDIF
ENDFOR
;stop
;modify DM_constants.f90
openw,unit,fortran_file_name_modified,/get_lun
FOR i=0L,Nlines-1 DO BEGIN
printf,unit,lines[i]
ENDFOR
close,unit
free_lun,unit
stop
;move modified file into used file
str='mv '+fortran_file_name_modified+' '+fortran_file_name
message,'Issuing '+str,/cont
spawn,str
;2/ compile dustem
str='rm '+!DUSTEM_SOFT_DIR+'/src/*.o'
message,'Issuing '+str,/cont
spawn,str
str='rm '+!DUSTEM_SOFT_DIR+'/src/*.mod'
message,'Issuing '+str,/cont
spawn,str
str='rm '+!DUSTEM_SOFT_DIR+'/src/dustem*'
message,'Issuing '+str,/cont
spawn,str
;3/ compile
;str='make -f '+!DUSTEM_SOFT_DIR+'/src/Makefile'
;message,'Issuing '+str,/cont
;str='cd '+!DUSTEM_SOFT_DIR+'/src'+' & make'
str='make -C'+!DUSTEM_SOFT_DIR+'/src/'+' -f '+'Makefile'
message,'Issuing '+str,/cont
spawn,str
;rename executable
str='mv '+!DUSTEM_SOFT_DIR+'/src/dustem '+!DUSTEM_SOFT_DIR+'/src/'+dustem_user
message,'Issuing '+str,/cont
;stop
;change dustemwrap system variables
dustem_f90_name=!DUSTEM_SOFT_DIR+'/src/'+dustem_user
defsysv,'!dustem_f90_exec',dustem_f90_name
defsysv,'!DUSTEM_DAT',dustem_dat+'/'
defsysv,'!DUSTEM_RES',dustem_res+'/'
;stop
RETURN,dustem_user
END