I am trying to compile a code that hasn't been developed with the newest standards in mind. I am using the gfortran compiler and get a few errors that I can't correct.
A partner of mine uses the Intel Visual Fortran compiler in MS Visual Studio and doesn't get any errors. Below are the relevant sections of code and their errors. Insight into any of these would be greatly appreciated.
Error 1:
flow.for:63.63:
3 *gjmh_old(j)*abs(gjmh_old(j))/2.0d0/dens_fjmh(j) )
1
Error: Expected a right parenthesis in expression at (1)
Corresponding code:
sum_dpjmh_old= 1.0/2.0*(dens_jmh(j)+dens_old(j))*grav*(dzc(j)/2.0d0) !!!!
1 + ( gavg_old(j)*gavg_old(j)/dens_mom(j)
1 -gjmh_old(j)*gjmh_old(j)/dmom_jmh(j) )
3 + 1.0/2.0*
3 ( fric(j)*dzc(j)/2.0/dhyd(j)
3 *gavg_old(j)*abs(gavg_old(j))/2.0d0/dens_fric(j)
3 +fjmh(j)*dzc(j)/2.0/dhyd(j)
3 *gjmh_old(j)*abs(gjmh_old(j))/2.0d0/dens_fjmh(j) )
Error 2:
flow.for:78.13:
1 + ( gavg(j)*gavg(j)/dens_momn(j)
1
Error: Missing exponent in real number at (1)
Corresponding Code:
sum_dpjmh = 1.0/2.0*(dens_jmhn(j)+dens_ch(j))*grav*(dzc(j)/2.0d0) !!!!
1 + ( gavg(j)*gavg(j)/dens_momn(j)
1 -gjmh(j)*gjmh(j)/dmom_jmhn(j) )
3 + 1.0/2.0*
3 ( fric(j)*(dzc(j)/2.0)/dhyd(j)
3 *gavg(j)*abs(gavg(j))/2.0d0/dens_ch(j)
3 + fjmh(j)*(dzc(j)/2.0)/dhyd(j)
3 *gjmh(j)*abs(gjmh(j))/2.0d0/dens_jmhn(j) )
Error 3:
flow.for:684.72:
3 /dens_fjmh(j) )
1
Error: Syntax error in argument list at (1)
Corresponding code:
gjmh(j) = gjmh_old(j) + dt/dzc(j)*(
1 phi*2.0d0*(pjmh(j)-p(j))
1 + (1.0-phi)*2.0d0*(pjmh_old(j)-p_old(j))
1 - 2.0d0*( gavg_old(j)*gavg_old(j)/dens_mom(j)
1 -gjmh_old(j)*gjmh_old(j)/dmom_jmh(j) )
4 - dens_jmh(j)*grav*dzc(j)
3 - fjmh(j)*dzc(j)/2.0d0/dhyd(j)*gjmh_old(j)*abs(gjmh_old(j))
3 /dens_fjmh(j) )
It seems your code is not well formatted. If you are trying to use fixed format, you should follow the request of fixed format, as http://nf.nci.org.au/training/FortranBasic/slides/slides.005.html.
Or following instructions in http://en.wikipedia.org/wiki/Fortran#Fixed_layout_and_punched_cards:
Column 1 contains *, ! or C for comments.
Column 6 for continuation.
Another way is to convert fixed format to free format, but since your code is not well formatted, most converter may be not working well.
Related
I'm trying to run a for loop to make a balance table in Stata (comparing the demographics of my dataset with national-level statistics)
For this, I'm prepping my dataset and attempting to calculate the percentages/averages for some key demographics.
preserve
rename unearnedinc_wins95 unearninc_wins95
foreach var of varlist fem age nonwhite hhsize parent employed savings_wins95 debt_wins95 earnedinc_wins95 unearninc_wins95 underfpl2019 { //continuous or binary; to put categorical vars use kwallis test
dis "for variable `var':"
tabstat `var'
summ `var'
local `var'_samplemean=r(mean)
}
clear
set obs 11
gen var=""
gen sample=.
gen F=.
gen pvalue=.
replace var="% Female" if _n==1
replace var="Age" if _n==2
replace var="% Non-white" if _n==3
replace var="HH size" if _n==4
replace var="% Parent" if _n==5
replace var="% Employed" if _n==6
replace var="Savings stock ($)" if _n==7
replace var="Debt stock ($)" if _n==8
replace var="Earned income last mo. ($)" if _n==9
replace var="Unearned income last mo. ($)" if _n==10
replace var="% Under FPL 2019" if _n==11
foreach col of varlist sample {
replace `col'=100*round(`fem_`col'mean', 0.01) if _n==1
replace `col'=round(`age_`col'mean') if _n==2
replace `col'=100*round(`nonwhite_`col'mean', 0.01) if _n==3
replace `col'=round(`hhsize_`col'mean', 0.1) if _n==4
replace `col'=100*round(`parent_`col'mean', 0.01) if _n==5
replace `col'=100*round(`employed_`col'mean', 0.01) if _n==6
replace `col'=round(`savings_wins95_`col'mean') if _n==7
replace `col'=round(`debt_wins95_`col'mean') if _n==8
replace `col'=round(`earnedinc_wins95_`col'mean') if _n==9
replace `col'=round(`unearninc_wins95_`col'mean') if _n==10
replace `col'=100*round(`underfpl2019_`col'mean', 0.01) if _n==11
}
I'm trying to run the following loop, but in the second half of the loop, I keep getting an 'invalid syntax' error. For context, in the first half of the loop (before clearing the dataset), the code stores the average values of the variables as a macro (`var'_samplemean). Can someone help me out and mend this loop?
My sample data:
clear
input byte fem float(age nonwhite) byte(hhsize parent) float employed double(savings_wins95 debt_wins95 earnedinc_wins95 unearninc_wins95) float underfpl2019
1 35 1 6 1 1 0 2500 0 0 0
0 40 0 4 1 1 0 10000 1043 0 0
0 40 0 4 1 1 0 20000 2400 0 0
0 40 0 4 1 1 .24 20000 2000 0 0
0 40 0 4 1 1 10 . 2600 0 0
Thanks!
Thanks for sharing the snippet of data. Apart from the fact the variable unearninc_wins95 has already been renamed in your sample data, the code runs fine for me without returning an error.
That being said, the columns for your F-statistics and p-values are empty once the loop at the bottom of your code completes. As far as I can see there is no local/varlist called sample which you're attempting to call with the line foreach col of varlist sample{. This could be because you haven't included it in your code, in which case please do, or it could be because you haven't created the local/varlist sample, in which case this could well be the source of your error message.
Taking a step back, there are more efficient ways of achieving what I think you're after. For example, you can get (part of) what you want using the package stat2data (if you don't have it installed already, run ssc install stat2data from the command prompt). You can then run the following code:
stat2data fem age nonwhite hhsize parent employed savings_wins95 debt_wins95 earnedinc_wins95 unearninc_wins95 underfpl2019, saving("~/yourstats.dta") stat(count mean)
*which returns:
preserve
use "~/yourstats.dta", clear
. list, sep(11)
+----------------------------+
| _name sN smean |
|----------------------------|
1. | fem 5 .2 |
2. | age 5 39 |
3. | nonwhite 5 .2 |
4. | hhsize 5 4.4 |
5. | parent 5 1 |
6. | employed 5 1 |
7. | savings_wins 5 2.048 |
8. | debt_wins95 4 13125 |
9. | earnedinc_wi 5 1608.6 |
10. | unearninc_wi 5 0 |
11. | underfpl2019 5 0 |
+----------------------------+
restore
This is missing the empty F-statistic and p-value variables you created in your code above, but you can always add them in the same way you have with gen F=. and gen pvalue=.. The presence of these variables though indicates you want to run some tests at some point and then fill the cells with values from them. I'd offer advice on how to do this but it's not obvious to me from your code what you want to test. If you can clarify this I will try and edit this answer to include that.
This doesn't answer your question directly; as others gently point out the question is hard to answer without a reproducible example. But I have several small comments on your code which are better presented in this form.
Assuming that all the variables needed are indeed present in the dataset, I would recommend something more like this:
local myvarlist fem age nonwhite hhsize parent employed savings_wins95 debt_wins95 earnedinc_wins95 unearninc_wins95 underfpl2019
local desc `" "% Female" "Age" "% Non-white" "HH size" "% Parent" "% Employed" "Savings stock ($)" "Debt stock ($)" "Earned income last mo. ($)" "Unearned income last mo. ($)" "% Under FPL 2019" "'
local i = 1
gen variable = ""
gen mean = ""
local i = 1
foreach var of local myvars {
summ `var', meanonly
local this : word `i' of `desc'
replace variable = "`this'" in `i'
if inlist(`i', 1, 3, 5, 6, 11) {
replace mean = strofreal(100 * r(mean), "%2.0f") in `i'
}
else if `i' == 4 {
replace mean = strofreal(r(mean), "%2.1f") in `i'
}
else replace mean = strofreal(r(mean), "%2.0f") in `i'
local ++i
}
This has not been tested.
Points arising include:
Using in is preferable for what you want over testing the observation number with if.
round() is treacherous for rounding to so many decimal places. Most of the time you will get what you want, but occasionally you will get bizarre results arising from the fact that Stata works in binary, like any equivalent program. It is safer to treat rounding as a problem in string manipulation and use display formats as offering precisely what you want.
If the text you want to show is just the variable label for each variable, this code could be simplified further.
The code hints at intent to show other stuff, which is easily done compatibly with this design.
Hope you all are doing good ,
I am working on fine tuning GPT 2 model to generate Title based on the content ,While working on it ,I have created a simple CSV files containing only the title to train the model , But while inputting this model to GPT 2 for fine tuning I am getting the following ERROR ,
JSONDecodeError Traceback (most recent call last)
in ()
10 steps=1000,
11 save_every=200,
---> 12 sample_every=25) # steps is max number of training steps
13
14 # gpt2.generate(sess)
3 frames
/usr/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
336 if s.startswith('\ufeff'):
337 s = s.encode('utf8')[3:].decode('utf8')
--> 338 # raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
339 # s, 0)
340 else:
JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
Below is my code for the above :
import gpt_2_simple as gpt2
model_name = "120M" # "355M" for larger model (it's 1.4 GB)
gpt2.download_gpt2(model_name=model_name) # model is saved into current directory under /models/117M/
sess = gpt2.start_tf_sess()
gpt2.finetune(sess,
'titles.csv',
model_name=model_name,
steps=1000,
save_every=200,
sample_every=25) # steps is max number of training steps
I have tried all the basic mechanism of handing UTF -8 BOM but did not find any luck ,Hence requesting your help .It would be a great help from you all .
Try changing the model name because i see you input 120M and the gpt2 model is called 124M
I removed the header in my data but I am having troubles removing the first row. Basically I want to turn
1
2
3
4
5
into
2
3
4
5
I keep getting this error. I am using a number because it is the title of my gage.
"11481000" = "11481000"[-1,]
Error in "11481000"[-1, ] : incorrect number of dimensions
"11481000"[-1,]
Error in "11481000"[-1, ] : incorrect number of dimensions
View(11481000)
"11481000" <- "11481000" [-c(1), ]
Error in "11481000"[-c(1), ] : incorrect number of dimensions
TIA
My dataset consists of a number of variables:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(v1 v2) str11 Date float(v4 v5 v6 v7 v8)
1 2 "15-aug-2016" 1 1 1 1 1
1 2 "07-may-2015" 1 1 1 1 50
1 2 "07-may-2015" 1 1 1 1 88
1 2 "15-aug-2016" 1 1 1 1 29
end
The variable date is a date and time and is formatted as a datetime
generate double date = date(Date,"DMY")
My duplicates are the same for v1-v2-v4-v5-v6-v7 (as in the example), while v8 is different.
I need to delete duplicates based on v1-v2-v4-v5-v6-v7 and keep the one with the smallest date (here 07-may-2015).
I have tried without success:
1.
gsort -date
bysort v1 v2 v4 v5 v6 v7: generate dublet=_n
order dublet date
keep if dublet==1
drop dublet
--> Works for the first 25 rows or so, then keeps the wrong one a couple of times and then the right one again. (Seems to me, that the bysort command removes the sort done by gsort? Any knowing if that's correct?)
bysort v1 v2 v4 v5 v6 v7 (date) : keep if _n == _N
--> Obviously keeps the wrong one, since Date is not -Date.
However, -Date is not an option - Stata writes: - invalid name
You could change your second answer to bysort v1 v2 v4 v5 v6 v7 (date) : keep if _n == 1 and that should give you what you're looking for.
Since in your data example there are duplicate dates (2 observations are May 7th 2015) you will get a random one of the observations with the minimum date.
I have to implement a scenario where I have 2 groups. Group 1 contains only process 0 and 1. Group 2 contains all the processes. Now the processes in Group 2 read some data and send it to Group 1(process 0 or 1, equal division). It should look like this:
Grp1 Grp2
Rank
(grp)
0 0 0
1 1 1
2 2
3 3
4 4 and so on..
Now to implement this, I have used the following code (All the variables and other things are taken care)
program mpi
use mpi
integer ierr,new_rank1,new_grp1,new_rank2,new_grp2,new_comm1,new_comm2
integer numtasks,rank,orig_grp,tag,sendbuf,recvbuf
integer ranks1(2),ranks2(8),stat(MPI_STATUS_SIZE)
data ranks1 /0,1/,ranks2 /0,1,2,3,4,5,6,7/
call mpi_init(ierr)
call mpi_comm_rank(mpi_comm_world,rank,ierr)
call mpi_comm_size(mpi_comm_world,numtasks,ierr)
call MPI_COMM_GROUP(MPI_COMM_WORLD,orig_grp,ierr)
tag = 342
call MPI_GROUP_INCL(orig_grp,8,ranks2,new_grp2,ierr)
call mpi_comm_create_group(mpi_comm_world,new_grp2,112,new_comm2,ierr)
call mpi_comm_rank(new_comm2,new_rank2,ierr)
if(new_rank2 == 4) then
call mpi_send(123,1,MPI_INT,0,tag,new_comm2,ierr) !send a msg from rank 4 of group 2 to rank 0 of group 1
end if
if(rank <2) then
call MPI_GROUP_INCL(orig_grp,2,ranks1,new_grp1,ierr)
call mpi_comm_create_group(mpi_comm_world,new_grp1,111,new_comm1,ierr)
call mpi_comm_rank(new_comm1,new_rank1,ierr)
if(new_rank1 == 0) then
call mpi_recv(recvbuf,1,MPI_INT,4,tag,new_comm2,stat,ierr)
print*,recvbuf
end if
end if
call mpi_finalize(ierr)
end
Facing errors in sending and receiving data. The other things work fine. And also if the whole concept is wrong, I am open to suggestions.