Blame view

src/idl/dustem_set_up_fortran.pro 3.84 KB
5112f161   Jean-Philippe Bernard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

ae5b5906   Jean-Philippe Bernard   fixed
23
;==== this is where everything will happen
f27e8037   Jean-Philippe Bernard   fixed
24
25
26
27
tmp_dir='/tmp/'+getenv('USER')+'/'

dustem_dat=tmp_dir+dustem_user+'/'
dustem_res=tmp_dir+dustem_user+'/'
5112f161   Jean-Philippe Bernard   First commit
28

ae5b5906   Jean-Philippe Bernard   fixed
29
30
31
32
33
34
35
36
37
38

;0/ save current  DM_constants.f90 and dustem executable
str='cp '+!DUSTEM_SOFT_DIR+'/src/'+'DM_constants.f90'+' '+!DUSTEM_SOFT_DIR+'/src/'+'DM_constants_saved_by_idl.f90'
message,'Issuing '+str,/cont
spawn,str
str='cp '+!DUSTEM_SOFT_DIR+'/src/'+'dustem'+' '+!DUSTEM_SOFT_DIR+'/src/'+'dustem_saved_by_idl'
message,'Issuing '+str,/cont
spawn,str


5112f161   Jean-Philippe Bernard   First commit
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
;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

0873e733   Jean-Philippe Bernard   fixed
96
;stop
5112f161   Jean-Philippe Bernard   First commit
97
98

;move modified file into used file
79682ce9   Jean-Philippe Bernard   fixed a bug
99
str='mv '+fortran_file_name_modified+' '+fortran_file_name
5112f161   Jean-Philippe Bernard   First commit
100
101
102
103
104
105
106
107
108
109
110
111
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

59d02e52   Jean-Philippe Bernard   fixed
112
str='rm '+!DUSTEM_SOFT_DIR+'/src/dustem'
5112f161   Jean-Philippe Bernard   First commit
113
114
115
116
117
118
119
120
message,'Issuing '+str,/cont
spawn,str

;3/ compile

;str='make -f '+!DUSTEM_SOFT_DIR+'/src/Makefile'
;message,'Issuing '+str,/cont

4136ccf8   Jean-Philippe Bernard   fixed
121
;str='cd '+!DUSTEM_SOFT_DIR+'/src'+' & make'
0873e733   Jean-Philippe Bernard   fixed
122
str='make -C '+!DUSTEM_SOFT_DIR+'/src/'+' -f '+'Makefile'
5112f161   Jean-Philippe Bernard   First commit
123
124
125
126
message,'Issuing '+str,/cont
spawn,str

;rename executable
59d02e52   Jean-Philippe Bernard   fixed
127
;dustem_f90_name=!DUSTEM_SOFT_DIR+'/src/'+dustem_user
f27e8037   Jean-Philippe Bernard   fixed
128
129
;dustem_f90_name='/tmp/'+dustem_user+'_exec'
dustem_f90_name=tmp_dir+dustem_user+'_exec'
59d02e52   Jean-Philippe Bernard   fixed
130
str='mv '+!DUSTEM_SOFT_DIR+'/src/dustem '+dustem_f90_name
5112f161   Jean-Philippe Bernard   First commit
131
message,'Issuing '+str,/cont
0873e733   Jean-Philippe Bernard   fixed
132
spawn,str
5112f161   Jean-Philippe Bernard   First commit
133
134
135
136

;stop

;change dustemwrap system variables
f2356fbf   Jean-Philippe Bernard   fixed
137
defsysv,'!dustem_f90_exec',dustem_f90_name
75c2fa4b   Jean-Philippe Bernard   fixed
138
139
defsysv,'!DUSTEM_DAT',dustem_dat
defsysv,'!DUSTEM_RES',dustem_res
5112f161   Jean-Philippe Bernard   First commit
140

ae5b5906   Jean-Philippe Bernard   fixed
141
142
143
144
145
146
147
148
149
150
;restore original files in the fortran
;0/ save current  DM_constants.f90 and dustem executable
str='cp '+!DUSTEM_SOFT_DIR+'/src/'+'DM_constants_saved_by_idl.f90'+' '+!DUSTEM_SOFT_DIR+'/src/'+'DM_constants.f90'
message,'Issuing '+str,/cont
spawn,str
str='cp '+!DUSTEM_SOFT_DIR+'/src/'+'dustem_saved_by_idl'+' '+!DUSTEM_SOFT_DIR+'/src/'+'dustem'
message,'Issuing '+str,/cont
spawn,str


5112f161   Jean-Philippe Bernard   First commit
151
152
153
154
155
;stop

RETURN,dustem_user

END