gsub for loop x rows at a time - r

I am not sure if this has been asked before and feel free to edit the title of this question if it can be phrased better. I have a list of files that need to be moved. They are stored on a server and are quite large so they take a bit of time to move. I can only really move 10 files at a time but I can submit multiple jobs. So what I want to do is use gsub and a for loop to edit a script with the first 10 files then a new script with the next 10 files to move and then a new script with the next 10 files to move and so on. Here is an example of the files I want to move. The list has 26 files... I know I mentioned I wanted to move in groups of 10 but I am curious what would happen if there were 6 samples instead of 10. The output files can be named whatever, that doesn't really matter. They obviously need to be unique. I will also attach the for loop that I tried to run but what I struggled with was looping through the list and also making a unique name
mcli <- structure(list(`mcli[c(1:25), ]` = structure(1:26, .Label = c("mcli mv --recursive /path/to/directory/D00063/alignment/ /path/to/directory/D00063/new.folder/alignment/",
"mcli mv --recursive /path/to/directory/D00063/bam/ /path/to/directory/D00063/new.folder/bam/",
"mcli mv --recursive /path/to/directory/D00063/fastqc/ /path/to/directory/D00063/new.folder/fastqc/",
"mcli mv --recursive /path/to/directory/D00063/gvcf/ /path/to/directory/D00063/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00063/trim/ /path/to/directory/D00063/new.folder/trim/",
"mcli mv --recursive /path/to/directory/D00064/alignment/ /path/to/directory/D00064/new.folder/alignment/",
"mcli mv --recursive /path/to/directory/D00064/bam/ /path/to/directory/D00064/new.folder/bam/",
"mcli mv --recursive /path/to/directory/D00064/fastqc/ /path/to/directory/D00064/new.folder/fastqc/",
"mcli mv --recursive /path/to/directory/D00064/gvcf/ /path/to/directory/D00064/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00064/trim/ /path/to/directory/D00064/new.folder/trim/",
"mcli mv --recursive /path/to/directory/D00105/gvcf/ /path/to/directory/D00105/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00151/gvcf/ /path/to/directory/D00151/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00188/gvcf/ /path/to/directory/D00188/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D002053/D02053/ /path/to/directory/D002053/new.folder/D02053/",
"mcli mv --recursive /path/to/directory/D00220/gvcf/ /path/to/directory/D00220/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00257/gvcf/ /path/to/directory/D00257/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00258/gvcf/ /path/to/directory/D00258/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00264/gvcf/ /path/to/directory/D00264/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00268/alignment/ /path/to/directory/D00268/new.folder/alignment/",
"mcli mv --recursive /path/to/directory/D00268/bam/ /path/to/directory/D00268/new.folder/bam/",
"mcli mv --recursive /path/to/directory/D00268/fastqc/ /path/to/directory/D00268/new.folder/fastqc/",
"mcli mv --recursive /path/to/directory/D00268/gvcf/ /path/to/directory/D00268/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00268/logs/ /path/to/directory/D00268/new.folder/logs/",
"mcli mv --recursive /path/to/directory/D00268/trim/ /path/to/directory/D00268/new.folder/trim/",
"mcli mv --recursive /path/to/directory/D00269/gvcf/ /path/to/directory/D00269/new.folder/gvcf/",
"mcli mv --recursive /path/to/directory/D00270/gvcf/ /path/to/directory/D00270/new.folder/gvcf/"), class = "factor")), .Names = "mcli[c(1:25), ]", row.names = c(NA,
-25L), class = "data.frame")
Here is an example of the script I want to edit
slurm <- structure(list(V1 = c("#!/bin/bash -l", "#SBATCH --nodes=1",
"#SBATCH --ntasks-per-node=10 ", "#SBATCH --mem-per-cpu=5gb",
"#SBATCH -t 20:00:00", "#SBATCH --mail-type=ALL",
"#SBATCH --mail-user=email ", "#SBATCH -o %j.out",
"#SBATCH -e %j.err", "", "", "cd $SLURM_SUBMIT_DIR",
"", "srun --exclusive --ntasks 1 abc123 &", "srun --exclusive --ntasks 1 def456 &",
"srun --exclusive --ntasks 1 ghi789 &", "srun --exclusive --ntasks 1 jkl101112 &",
"srun --exclusive --ntasks 1 mno131415 &", "srun --exclusive --ntasks 1 pqr161718 &",
"srun --exclusive --ntasks 1 stu192021 &", "srun --exclusive --ntasks 1 vwx222324 &",
"srun --exclusive --ntasks 1 yza252627 &", "srun --exclusive --ntasks 1 abc282930 &",
"", "wait")), row.names = c(NA,
-25L), class = c("data.table", "data.frame"))
example code that doesn't work
for(i in 1:length(mcli[[1]])){
df2 <- as.data.frame(slurm)
df2[,'V1'] <- gsub("abc123", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("def456", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("ghi789", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("jkl101112", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("mno131415", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("pqr161718", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("stu192021", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("vwx222324", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("yza252627", mcli[['V1']][i], df2[,'V1'])
df2[,'V1'] <- gsub("abc282930", mcli[['V1']][i], df2[,'V1'])
write.table(df2, paste(file = "/path/to/random/folder/",mcli[['V1']][i], ".csh", sep = ""), row.names = FALSE, col.names =FALSE, quote = FALSE)
}
expected output script1
#!/bin/bash -l
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=10
#SBATCH --mem-per-cpu=5gb
#SBATCH -t 20:00:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=bgwillia#umn.edu
#SBATCH -o %j.out
#SBATCH -e %j.err
cd $SLURM_SUBMIT_DIR
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00063/alignment/ /path/to/directory/D00063/new.folder/alignment/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00063/bam/ /path/to/directory/D00063/new.folder/bam/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00063/fastqc/ /path/to/directory/D00063/new.folder/fastqc/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00063/gvcf/ /path/to/directory/D00063/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00063/trim/ /path/to/directory/D00063/new.folder/trim/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00064/alignment/ /path/to/directory/D00064/new.folder/alignment/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00064/bam/ /path/to/directory/D00064/new.folder/bam/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00064/fastqc/ /path/to/directory/D00064/new.folder/fastqc/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00064/gvcf/ /path/to/directory/D00064/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00064/trim/ /path/to/directory/D00064/new.folder/trim/ &
wait
expected output script2
#!/bin/bash -l
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=10
#SBATCH --mem-per-cpu=5gb
#SBATCH -t 20:00:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=bgwillia#umn.edu
#SBATCH -o %j.out
#SBATCH -e %j.err
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00105/gvcf/ /path/to/directory/D00105/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00151/gvcf/ /path/to/directory/D00151/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00188/gvcf/ /path/to/directory/D00188/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D002053/D02053/ /path/to/directory/D002053/new.folder/D02053/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00220/gvcf/ /path/to/directory/D00220/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00257/gvcf/ /path/to/directory/D00257/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00258/gvcf/ /path/to/directory/D00258/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00264/gvcf/ /path/to/directory/D00264/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/alignment/ /path/to/directory/D00268/new.folder/alignment/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/bam/ /path/to/directory/D00268/new.folder/bam/ &
wait
expected output script3
#!/bin/bash -l
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=10
#SBATCH --mem-per-cpu=5gb
#SBATCH -t 20:00:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=bgwillia#umn.edu
#SBATCH -o %j.out
#SBATCH -e %j.err
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/fastqc/ /path/to/directory/D00268/new.folder/fastqc/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/gvcf/ /path/to/directory/D00268/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/logs/ /path/to/directory/D00268/new.folder/logs/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/trim/ /path/to/directory/D00268/new.folder/trim/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00269/gvcf/ /path/to/directory/D00269/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00270/gvcf/ /path/to/directory/D00270/new.folder/gvcf/ &
wait

Instead of a frame, I'm going to operate on a vector of commands to run:
mcli <- c("mcli mv --recursive /path/to/directory/D00063/alignment/ /path/to/directory/D00063/new.folder/alignment/", "mcli mv --recursive /path/to/directory/D00063/bam/ /path/to/directory/D00063/new.folder/bam/", "mcli mv --recursive /path/to/directory/D00063/fastqc/ /path/to/directory/D00063/new.folder/fastqc/", "mcli mv --recursive /path/to/directory/D00063/gvcf/ /path/to/directory/D00063/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00063/trim/ /path/to/directory/D00063/new.folder/trim/", "mcli mv --recursive /path/to/directory/D00064/alignment/ /path/to/directory/D00064/new.folder/alignment/", "mcli mv --recursive /path/to/directory/D00064/bam/ /path/to/directory/D00064/new.folder/bam/", "mcli mv --recursive /path/to/directory/D00064/fastqc/ /path/to/directory/D00064/new.folder/fastqc/", "mcli mv --recursive /path/to/directory/D00064/gvcf/ /path/to/directory/D00064/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00064/trim/ /path/to/directory/D00064/new.folder/trim/", "mcli mv --recursive /path/to/directory/D00105/gvcf/ /path/to/directory/D00105/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00151/gvcf/ /path/to/directory/D00151/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00188/gvcf/ /path/to/directory/D00188/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D002053/D02053/ /path/to/directory/D002053/new.folder/D02053/", "mcli mv --recursive /path/to/directory/D00220/gvcf/ /path/to/directory/D00220/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00257/gvcf/ /path/to/directory/D00257/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00258/gvcf/ /path/to/directory/D00258/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00264/gvcf/ /path/to/directory/D00264/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00268/alignment/ /path/to/directory/D00268/new.folder/alignment/", "mcli mv --recursive /path/to/directory/D00268/bam/ /path/to/directory/D00268/new.folder/bam/", "mcli mv --recursive /path/to/directory/D00268/fastqc/ /path/to/directory/D00268/new.folder/fastqc/", "mcli mv --recursive /path/to/directory/D00268/gvcf/ /path/to/directory/D00268/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00268/logs/ /path/to/directory/D00268/new.folder/logs/", "mcli mv --recursive /path/to/directory/D00268/trim/ /path/to/directory/D00268/new.folder/trim/", "mcli mv --recursive /path/to/directory/D00269/gvcf/ /path/to/directory/D00269/new.folder/gvcf/", "mcli mv --recursive /path/to/directory/D00270/gvcf/ /path/to/directory/D00270/new.folder/gvcf/")
I do this for three reasons: (1) I get warnings about corrupt data frame: columns will be truncated or padded with NAs; (2) those are factors, when we really just need character (easily fixed, I know); and (3) I want this to be generalizable to any other column/vector.
I'll modify your slurm template a little, as
slurm <- list(
bef = "#!/bin/bash -l\n#SBATCH --nodes=1\n#SBATCH --ntasks-per-node=10 \n#SBATCH --mem-per-cpu=5gb\n#SBATCH -t 20:00:00\n#SBATCH --mail-type=ALL\n#SBATCH --mail-user=email \n#SBATCH -o %j.out\n#SBATCH -e %j.err\n\n\ncd $SLURM_SUBMIT_DIR",
job = "srun --exclusive --ntasks 1 %s &",
aft = "\n\nwait\n"
)
From here:
scripts <- by(mcli, (seq_along(mcli)-1) %/% 10,
FUN = function(z) {
paste(slurm$bef, paste(sprintf(slurm$job, z), collapse = "\n"),
slurm$aft, sep = "\n")
})
Each of the elements of scripts is a full 10-job batch file. For instance, the last is
> cat(scripts[[3]], "\n")
#!/bin/bash -l
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=10
#SBATCH --mem-per-cpu=5gb
#SBATCH -t 20:00:00
#SBATCH --mail-type=ALL
#SBATCH --mail-user=email
#SBATCH -o %j.out
#SBATCH -e %j.err
cd $SLURM_SUBMIT_DIR
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/fastqc/ /path/to/directory/D00268/new.folder/fastqc/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/gvcf/ /path/to/directory/D00268/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/logs/ /path/to/directory/D00268/new.folder/logs/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00268/trim/ /path/to/directory/D00268/new.folder/trim/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00269/gvcf/ /path/to/directory/D00269/new.folder/gvcf/ &
srun --exclusive --ntasks 1 mcli mv --recursive /path/to/directory/D00270/gvcf/ /path/to/directory/D00270/new.folder/gvcf/ &
wait
If you need those as individual files, you can do something like:
for (i in seq_along(scripts)) {
writeLines(scripts[[i]], paste0("script", i))
}

Related

Fortran Error:Bad continuation line at (1)

I am trying to use fortran to write a Unix script into a file. Nonetheless, it keeps reminding me that my format is incorrect. I have been doing this for many times and they are all succeed to be compiled. For this time, I do not know what goes wrong. I have attached my codes and the information on errors and I will be very grateful if someone can point out my mistakes. Thanks!!!
subroutine get_gmt(max1,min1,max2,min2,max3,min3,max4,min4)
real*4 max1,min1,max2,min2,max3,min3,max4,min4
real*4 dt1,dt2,dt3,dt4
real*4 dtt1,dtt2,dtt3,dtt4
dt1 = (max1-min1)/2000
dt2 = (max1-min1)/8
open(23,file='plot.gmt')
write(23,100) dt1,dt2,min1,max1,min2
& ,max2,min3,max3,min4,max4
100 format('#!/bin/bash', /
& 'rm tmp?.ps tmp?.cpt',//
& 'set dt1= ',f11.5,/
& 'set dt2= ',f11.5,/
& 'set T1= ',f11.5,/
& 'set T2= ',f11.5,/
& 'set T3= ',f11.5,/
& 'set T4= ',f11.5,/
& 'set T5= ',f11.5,/
& 'set T6= ',f11.5,/
& 'set T7= ',f11.5,/
& 'set T8= ',f11.5,/
& 'psbasemap -R0/360/0/90 -JPa3/0
& -P -Ba40/a10 -V -X6.5 -Y24 -K > tmp.ps',/
& 'surface data.dat -Gtmp.grd -I0.05/0.05
& -R -C100 -T0.35 -N10 -V',//
& 'makecpt -Crainbow -T$T1/$T2/$dt1 -Z -V > tmp.cpt',/
& 'makecpt -Crainbow -T$T1/$T2/$dt2 -Z -V > tmp1.cpt',//
& 'psscale -D-1.25/1.5/3/0.4 -Ctmp1.cpt -L -O -K -A >> tmp.ps',//
& 'grdimage tmp.grd -R -JP -O -Ctmp.cpt -V -K >> tmp.ps',//
& 'gawk ''{print $2,$5,0.5*$3}'' result4.dat | psxy
& -R -JP -K -O -B -V -Sc -N -W0.5,red >> tmp.ps',//
& 'psxyz -R0/2/0/2/0/2 -JX2/2 -JZ2 -E135/30 -Sc0.1
& -W4,red -P -Gred -Bx1 -By1 -Bz1 -BWSneZ
& -N -X-6.0 -K -O <<END>> tmp.ps',/
& '0 0 1',/
& '0 0 0',/
& 'END',//
& 'pstext -R -JX -O -K -JZ -E -W4,red -P -B -N <<END>> tmp.ps',/
& '-0.2 0 0 9 0 15 subevent1',/
& '0 0 1.2 9 0 15 subevent2',/
& 'END',//
& 'gawk ''{print $1,$2}'' time.dat |psxy -R0/360/$T1/$T2 -JX3/3 -P -Ba60/a$dt2
& -V -K -O -Sc0.05 -N -X10.5 -P >> tmp.ps',//
& 'gawk ''{print $2,$5}'' result4.dat |psxy -R
& -JX -K -O -B -V -Sa0.15 -N -W0.5,red
& >> tmp.ps',//
& 'gmtset BASEMAP_AXES = WeSN',/
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $1,$2}'' time1.dat |psxy
& -R0/90/$T1/$T2 -JX3/3 -P -Ba15/a$dt2 -V -K -O
& -Sc0.05 -N -X4.5 >> tmp.ps',//
& 'psbasemap -R0/360/0/90 -JPa3/0 -P
& -Ba40/a10 -V -X-9 -Y-5 -K -O >> tmp.ps',/
& 'surface data1.dat -Gtmp1.grd -I0.1/0.1 -R -C100 -T0 -N10 -V',//
& 'makecpt -Crainbow -T$T3/$T4/$dt1 -Z -V > tmp3.cpt',//
& 'makecpt -Crainbow -T$T3/$T4/$dt2 -Z -V > tmp4.cpt',//
& 'psscale -D-1.25/1.5/3/0.4
& -Ctmp4.cpt -L -O -K -A >> tmp.ps',//
& 'grdimage tmp1.grd -R -JP -O -Ctmp3.cpt -V -K >> tmp.ps',//
& 'gawk ''{print $2,$5,0.5*$3}'' result4.dat |
& psxy -R -JP -K -O -B -V
& -Sc -N -W0.5,red >> tmp.ps',//
& 'psxyz -R0/2/0/2/0/2 -JX2/2 -JZ2 -E135/30
& -Sc0.1 -W4,red -P -Gred -BWSneZ -Bx1 -By1
& -Bz1 -N -X-6.0 -K -O <<END>> tmp.ps',/
& '1 0 0',/
& '0 0 0',/
& 'END',//
& 'gmtset BASEMAP_AXES = WeSN',/
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $1,$2}'' time4.dat |psxy
& -R0/360/$T3/$T4 -JX3/3 -P -Ba60/a$dt2 -V -K -P
& -Sc0.05 -N -X10.5 >> tmp.ps',//
& ‘gmtset BASEMAP_AXES = WeSN',/
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $1,$2}'' time3.dat |psxy
& -R0/90/$T3/$T4 -JX3/3 -P -K -Ba15/a$dt2 -V
& -X4.5 -O -Sc0.05 -N >> tmp.ps',//
& 'psbasemap -R0/360/0/90 -JPa3/0 -P
& -Ba40/a10 -V -X6.5 -Y24 -K > tmp1.ps',/
& 'surface data2.dat -Gtmp2.grd
& -I0.1/0.1 -R -C100 -T0 -N10 -V',//
& 'makecpt -Crainbow -T$T5/$T6/$dt1 -Z -V > tmp5.cpt',/
& 'makecpt -Crainbow -T$T5/$T6/$dt2 -Z -V > tmp6.cpt',//
& 'psscale -D-1.25/1.5/3/0.4
& -Ctmp6.cpt -V -K -O -A -L >> tmp1.ps',//
& 'grdimage tmp2.grd -R -JP -O
& -Ctmp5.cpt -V -K >> tmp1.ps',//
& 'gawk ''{print $2,$5,0.5*$3}'' result4.dat |psxy -R
& -JP -K -O -B -V -Sc -N -W0.5,red
& >> tmp1.ps',/
& 'psxyz -R0/2/0/2/0/2 -JX2/2 -JZ2 -E135/30
& -Sc0.1 -W4,red -P -Gred -Bx1 -By1 -Bz1
& -BWSneZ -N -X-6.0 -K -O <<END>>tmp1.ps',/
& '0 1 0',/
& '0 0 0',/
& 'END',//
& 'gmtset BASEMAP_AXES = WeSN',/
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $1,$2}'' time6.dat |psxy -R0/360/$T5/$T6
& -JX3/3 -P -Ba60/a$dt2 -V
& -X10.5 -K -O -Sc0.05 -N >> tmp1.ps',//
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $1,$2}'' time5.dat |psxy -R0/90/$T5/$T6
& -JX3/3 -P -Ba15/a$dt2 -V
& -X4.5 -O -Sc0.05 -N -K >> tmp1.ps',//
& 'psbasemap -R0/360/0/90 -JPa3/0 -P
& -Ba40/a10 -V -X-9 -Y-5 -K -O >> tmp1.ps',/
& 'surface data3.dat -Gtmp3.grd -I0.1/0.1 -R -C100 -T0 -N10 -V',//
& 'makecpt -Crainbow -T$T7/$T8/$dt1 -Z -V > tmp9.cpt',//
& 'makecpt -Crainbow -T$T7/$T8/$dt2 -Z -V > tmp10.cpt',//
& 'psscale -D-1.25/1.5/3/0.4
& -Ctmp10.cpt -L -O -K -A >> tmp2.ps',//
& 'gawk ''{print $2,$5,$3}'' result4.dat |psxy
& -R -JP -K -O -B -V -Sc0.1 -Ctmp9.cpt -N
& -Gblack >> tmp2.ps',//
& 'BASEMAP_AXES = WeSN',/
& 'FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $2,$3}'' result4.dat |psxy
& -R0/360/$T7/$T8 -JX3/3 -P -Ba60/a$dt2 -V
& -X4.5 -K -O -Sc0.05 -N >> tmp2.ps',//
& 'gmtset BASEMAP_AXES = WeSN',/
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
& 'gawk ''{print $5,$3}'' result4.dat |psxy -R0/90/$T7/$T8
& -JX3/3 -P -Ba15/a$dt2 -V
& -X4.5 -O -Sc0.05 -N >> tmp2.ps')
close(23)
end
And it reports numerous errors, but the typical errors are as follows:
& 'grdimage tmp.grd -R -JP -O -Ctmp.cpt -V -K >> tmp.ps',//
Error: Positive width required in format specifier G at (1)
forward_modeling.f:407:6:
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
1
Error: Bad continuation line at (1)
forward_modeling.f:407:15:
& 'gmtset FONT_ANNOT_PRIMARY 7p',//
1
Error: Invalid character in name at (1)
forward_modeling.f:410:6:
& -JX3/3 -P -Ba15/a$dt2 -V
1
Error: Bad continuation line at (1)
Error: Unclassifiable statement at (1)
forward_modeling.f:285:72:
& ,max2,min3,max3,min4,max4
1
Error: FORMAT label 100 at (1) not defined

How can I write a GNU Makefile that has multiple target/prerequisites to execute the same recipe?

As an example:
a:b
cp $< $#
c:d
cp $< $#
e:f
cp $< $#
One solution would be to use a function:
define my_cp
cp $(1) $(2)
endef
a:b
$(call my_cp, $<, $#)
...
But I was wondering if people could suggest an alternative ...
The call thing seems more complex than necessary. You could just use:
CP = cp $< $#
a:b
$(CP)
...
You could also do this:
a c e:
cp $< $#
a: b
c: d
e: f
That's about it though.

Gmake errors but only on certain Windows machines

I get the following error when I run my makefile in windows using gmake.
It happens on only 1 PC of 5 in the group - the other 4 run perfectly, and the file that's "not found" is definitely in the file system - I can run an assemble from the command line with the same path and it works fine.
C:\Eclipse\tools\gmake\gmake.exe BUILD_TYPE=RAM all
07:43:14 **** Build of configuration Debug for project U500 ****
"C:\\Eclipse\\tools\\gmake\\gmake.exe" BUILD_TYPE=RAM all
mkdir -p "object_flash"
mkdir -p "object"
mkdir -p "../TSP for iNav/Builds/iNav RAM/output"
mkdir -p "../TSP for iNav/Builds/Flash Release/output"
AS object/CpuCore.o
here is the curdir C:/work/Insulet/PhoenixII/robert_test_workspace/U500/Debug
C:/Eclipse/tools/codesourcery_arm_3.4.2/bin/arm-none-eabi-as -o object/CpuCore.o -gdwarf2 -meabi=4 -I"../../source/CPU" ../../source/CPU/CpuCore.s
Assembler messages:
**Can't open ../../source/CPU/CpuCore.s
for reading: Invalid argument**
The makefile is (look for #### for the rule causing an issue)
====
ifeq ($(BUILD_TYPE),RAM)
BUILDDIR = ../TSP for iNav/Builds/iNav RAM
MAPFILE = iNav_RAM.map
LDFILE = iNav_RAM.ld
IMGNAME = iNav_RAM.elf
DEBUGFLAGS = -DDEBUG_DEVELOPMENT_MODE
OBJDIR = ./object
DRIVERDIR =objects/ ``
#UT_OBJECTS = UnitTest.o
else
ifeq ($(BUILD_TYPE),FLASH)
BUILDDIR = ../TSP for iNav/Builds/FLASH Release
MAPFILE = FLASH_Release.map
LDFILE = FLASH_Release.ld
IMGNAME = FLASH_Release.elf
#POSTPROCESSING = sh -c 'pushd ../TSP\ for\ iNav/Batch\ Files/;\
cmd.exe /c "ProcessFlashReleaseImage.bat";\
popd'
#POSTPROCESSING = sh -c '$(OBJCOPY) -R .lcdmem -O binary -S $(IMG) $(APP_FLASH_IMG)'
#
# copy /b $(APP_FLASH_IMG) + $(UPGRADER_IMG) $(COMBINED_FLASH_IMG);\
# ../TSP\ for\ iNav/Build\ Tools/ProcessImage_iNavMainApp $(COMBINED_FLASH_IMG)'
APP_FLASH_IMG = "$(BUILDDIR)/Output/Pre_FLASH_Release.bin"
UPGRADER_IMG = "../TSP for iNav/UpgraderBin/Upgrader.bin"
COMBINED_FLASH_IMG = "$(BUILDDIR)/Output/FLASH_Release.bin"
OBJDIR = ./object_flash
OBJDIR1 = .\objects
#DEBUGFLAGS = -D__CSURF__
else
#This is to build the boot ROM
ifeq ($(BUILD_TYPE),FLASH_BOOT)
#### mods for boot flash needed
BUILDDIR = ../TSP for iNav/Builds/iNav Flash Boot
MAPFILE = BOOT_FLASH_Release.map
LDFILE = BOOT_FLASH_Release.ld
IMGNAME = BOOT_FLASH_Release.elf
#POSTPROCESSING = sh -c 'pushd ../TSP\ for\ iNav/Batch\ Files/;\
cmd.exe /c "ProcessFlashReleaseImage.bat";\
popd'
#POSTPROCESSING = sh -c '$(OBJCOPY) -R .lcdmem -O binary -S $(IMG) $(APP_FLASH_IMG)'
#
# copy /b $(APP_FLASH_IMG) + $(UPGRADER_IMG) $(COMBINED_FLASH_IMG);\
# ../TSP\ for\ iNav/Build\ Tools/ProcessImage_iNavMainApp $(COMBINED_FLASH_IMG)'
APP_FLASH_IMG = "$(BUILDDIR)/Output/Pre_FLASH_Release.bin"
UPGRADER_IMG = "../TSP for iNav/UpgraderBin/Upgrader.bin"
COMBINED_FLASH_IMG = "$(BUILDDIR)/Output/FLASH_Release.bin"
OBJDIR = ./object_flash
OBJDIR1 = .\objects
else
error:
#echo 'invalid build type: $(BUILD_TYPE)'
endif
endif
endif
IMG = "$(BUILDDIR)/Output/$(IMGNAME)"
#export C_COLON = /c
export C_COLON = /cygdrive/c
#export TOOL_LOCATION = $(C_COLON)/mgc/embedded/tools/codesourcery_arm_3.4.2/bin
export TOOL_LOCATION = C:/Eclipse/tools/codesourcery_arm_3.4.2/bin
export CC = $(TOOL_LOCATION)/arm-none-eabi-gcc
export AS = $(TOOL_LOCATION)/arm-none-eabi-as
export LD = $(TOOL_LOCATION)/arm-none-eabi-ld
export AR = $(TOOL_LOCATION)/arm-none-eabi-ar
export OBJCOPY = $(TOOL_LOCATION)/arm-none-eabi-objcopy
export RM = rm -f
export CP = cp
INCLUDDIRS = -I"../../source" -I"../../source/Drivers" -I"../../source/CPU" -I"../../source/smx/XFD" -I"../../source/smx/XFS" -I"../../source/smx/xusbd" -I"../../source/smx/xusbd/Core" -I"../../source/smx/xusbd/DCD" -I"../../source/smx/xusbd/Function" -I"."
CFLAGS = $(DEBUGFLAGS) -gdwarf-2 -mcpu=arm9 -fno-short-enums -fno-zero-initialized-in-bss -fsigned-char $(INCLUDDIRS) -Wall -Wno-missing-braces $(EXTRA_CFLAGS)
LDLIBS = --start-group "./TSP_for_iNav/CSL-ARM-GNU-Debug/Output/TSP_for_iNav.lib" "../TSP for iNav/GNU Libraries/libgcc.a" "../TSP for iNav/GNU Libraries/libc.a" --end-group
MAP = "$(BUILDDIR)/Output/$(MAPFILE)"
LINKSCRIPT = "./TSP_for_iNav/src/csgnu_arm/$(LDFILE)"
LDFLAGS = -Map $(MAP) -T$(LINKSCRIPT)
_APP_OBJECTS = alarm.o SdDiag.o alarm_repair.o beep.o cgmLog.o comm.o cond_state.o confirm.o confirm_calc.o confirm_pump.o conversion.o critical.o cursor_list.o diag.o display.o eeprom.o entry.o entry_bg.o font.o fooddb.o graph.o h_main.o handlers.o history.o history_page.o icons.o language.o language_Compiler_verify.o lcd.o list.o log.o logs.o mainloop.o menu.o pending.o prog_view.o pump.o pump_alert.o pump_cmd.o pumpmfg.o pumpverify.o queue.o ram.o rtc.o sched.o screen.o serial.o state.o state_alert.o state_bg_setup.o state_bgmeter.o state_bkgd_ck.o state_cgm.o state_comm.o state_fooddb.o state_presets.o state_sw.o suggbol.o suggbol_hist.o swtimer.o usb.o view.o view_bg.o
#APP_OBJECTS = $(patsubst %,$(OBJDIR)/%,$(_APP_OBJECTS))
APP_OBJECTS = $(addprefix $(OBJDIR)/,$(_APP_OBJECTS))
_DRIVER_OBJECTS = BGBoard.o BGMeter.o Flash.o init_lcd.o Interrupt.o MX21Config.o MX21_RTC.o MicroManager.o crc16-123.o eNavCGM.o gpio.o h_diag.o h_eeprom.o h_icons.o h_lcd.o h_rtc.o h_sys.o h_usb.o h_usbevt.o h_usbints.o h_usbos.o h_usbotg.o h_usbphy.o h_usbregs.o h_usbtrace.o hwTimer.o i2c.o key.o pwm.o rf.o secui.o spi.o super.o trans.o uart.o wdog.o
DRIVER_OBJECTS =$(addprefix $(OBJDIR)/,$(_DRIVER_OBJECTS))
_CPU_OBJECTS = AITC.o RunTimeInit.o
CPU_OBJECTS =$(addprefix $(OBJDIR)/,$(_CPU_OBJECTS))
_USB_OBJECTS = norfd.o norio_insulet.o fapi.o fcache.o fdnor.o fdram.o fdwin.o ffind.o fmount.o fpath.o fport.o funicode.o udhdw.o udinit.o uddcd.o uddevice.o udep0.o udfunc.o udutil.o udmx21.o udcompos.o udftempl.o udmouse.o udmstor.o udserial.o
USB_OBJECTS =$(addprefix $(OBJDIR)/,$(_USB_OBJECTS))
_ASM_OBJECTS = CpuCore.o CpuException.o
ASM_OBJECTS =$(addprefix $(OBJDIR)/,$(_ASM_OBJECTS))
OBJECTS = $(APP_OBJECTS) $(DRIVER_OBJECTS) $(CPU_OBJECTS) $(USB_OBJECTS) $(ASM_OBJECTS)
ARCHIVES = app.a Drivers.a CPU.a smx.a
.PHONY: all clean img TSP_lib
all: img
-include $(OBJECTS:.o=.d)
img: $(ASM_OBJECTS) $(ARCHIVES) TSP_lib
#echo LD $#
$(LD) -o $(IMG) $(ASM_OBJECTS) $(ARCHIVES) $(LDLIBS) $(LDFLAGS)
# $(POSTPROCESSING)
# #../TSP\ for\ iNav/Batch\ Files/ProcessFlashReleaseImage.bat
TSP_lib:
$(MAKE) -C "./TSP_for_iNav"
app.a: $(APP_OBJECTS)
#echo AR $#
$(AR) rc $# $(APP_OBJECTS)
Drivers.a: $(DRIVER_OBJECTS)
#echo AR $#
$(AR) rc $# $(DRIVER_OBJECTS)
CPU.a: $(CPU_OBJECTS)
#echo AR $#
$(AR) rc $# $(CPU_OBJECTS)
smx.a: $(USB_OBJECTS)
#echo AR $#
$(AR) rc $# $(USB_OBJECTS)
########### rule causing problems ###########
$(OBJDIR)/CpuCore.o: ../../source/CPU/CpuCore.s
-mkdir -p "object_flash"
-mkdir -p "object"
-mkdir -p "../TSP for iNav/Builds/iNav RAM/output"
-mkdir -p "../TSP for iNav/Builds/Flash Release/output"
#echo AS $#
#echo here is the curdir ${CURDIR}
$(AS) -o $# -gdwarf2 -meabi=4 -I"../../source/CPU" $<
$(OBJDIR)/CpuException.o: ../../source/CPU/CpuException.s
#echo AS $#
$(AS) -o $# -gdwarf2 -meabi=4 -I"../../source/CPU" $<
lcd.o: lcd.c
#echo CC $#
$(CC) $(CFLAGS) -O3 -c -o $# $<
#$(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/drivers/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/drivers/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/CPU/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/XFD/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/XFS/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/xusbd/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/xusbd/core/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/xusbd/DCD/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
$(OBJDIR)/%.o: ../../source/SMX/xusbd/Function/%.c
#echo CC $#
$(CC) $(CFLAGS) -c -o $# $<
# $(CC) -MM -MT '$(#:.o=.d) $#' $(CFLAGS) $< > $(<:.c=.d)
clean:
#echo CLEAN
rm -f $(OBJECTS)
rm -f ../../TSP\ for\ iNav/Builds/Flash\ Release/output/BOOT_FLASH_Release.elf
rm -f ../../TSP\ for\ iNav/Builds/Flash\ Release/output/BOOT_FLASH_Release.map
rm -f ../../TSP\ for\ iNav/Builds/Flash\ Release/output/FLASH_Release.elf
rm -f ../../TSP\ for\ iNav/Builds/Flash\ Release/output/FLASH_Release.map
rm -f ../../TSP\ for\ iNav/Builds/iNAV\ RAM/output/iNAV_RAM.map
rm -f ../../TSP\ for\ iNav/Builds/iNAV\ RAM/output/iNAV_RAM.elf
# del $(OBJECTS) $(OBJECTS:.o=.d) $(ARCHIVES) $(IMG)
# $(MAKE) clean -C "../../TSP for iNav"
cleanobj:
#echo CLEANOBJ
$(RM) $(OBJECTS)
Turns out there was something fishy on the guys path, so all is well now.

start-stop-daemon and javaFX program

this is driving me crazy, please could you help with the start-stop-daemon to start a javafx jar file, where I need to issue the following command to start it
sudo /opt/jdk1.8.0/bin/java -Djavafx.platform=eglfb -cp /opt/jdk1.8.0/jre/lib/jfxrt.jar:/home/pi/prayertime/JavaFXApplication4.jar javafxapplication4.JavaFXApplication4 &
and the start_stop_daemon script is as follows
#!/bin/sh
#
# init script for ship-it
#
### BEGIN INIT INFO
# Provides: ship-it
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: init script for the ship-it box
# Description: We'll have to fill this out later...
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NAME=prayertime
DAEMON=/home/pi/prayertime/JavaFXApplication4.jar
DAEMONARGS="javafxapplication4.JavaFXApplication4"
PIDFILE=/var/run/$NAME.pid
LOGFILE=/var/log/$NAME.log
. /lib/lsb/init-functions
test -f $DAEMON || exit 0
case "$1" in
start)
start-stop-daemon --start --background \
--pidfile $PIDFILE --make-pidfile --startas /bin/bash \
-- -c "exec sudo /opt/jdk1.8.0/bin/java -Djavafx.platform=eglfb -cp /opt/jdk1.8.0/jre/lib/jfxrt.jar: $DAEMON $DAEMONARGS > $LOGFILE 2>&1"
log_end_msg $?
;;

Setting up Rcpp GSL for windows

I am trying to set up Rcpp GSL for windows.. I read lot of post on the subject, but I have been unable to find a solution for a while now.. Sorry in advance..
So I am running R 3.1 on windows 8.1. Both Rcpp and Rcpp Armadillo are working fine..
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RcppGSL_0.2.0 RcppArmadillo_0.4.300.0 Rcpp_0.11.1 foreign_0.8-61
loaded via a namespace (and not attached):
[1] tools_3.1.0
1) I made sure that there is no space in the R directory
2) I installed gnuwin32
3) I changed my Makevars.win
PKG_CPPFLAGS=-I$(LIB_GSL=C:/GnuWin32)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL=C:/GnuWin32)/lib -lgsl -lgslcblas $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
4) Here is my Makeconf, but let's be honest here.. I have no idea what this is saying
#-*- Makefile -*-
# $(R_HOME}/etc$(R_ARCH)/Makeconf
# Hand-edited version for gnuwin32.
ifdef DEBUG
DLLFLAGS=
DEBUGFLAG=-gdwarf-2
else
DLLFLAGS=-s
DEBUGFLAG=
endif
DLLFLAGS+= -static-libgcc
LINKFLAGS+= -static-libgcc
## Things which are substituted by fixed/Makefile (and also -O2 -> -O2)
WIN = 64
BINPREF =
# SYMPAT = 's/^.* [BCDRT] _/ /p' for 32-bit
# SYMPAT = 's/^.* [BCDRT] / /p' for 64-bit
SYMPAT = 's/^.* [BCDRT] / /p'
IMPDIR = bin/x64
# flags for multilib builds, for compilers, dlltool and windres
M_ARCH = -m64
DT_ARCH = -m i386:x86-64 --as-flags --64
RC_ARCH = -F pe-x86-64
# Used by packages tcltk and tkrplot
TCL_HOME = $(R_HOME)/Tcl
LOCAL_SOFT = d:/RCompile/CRANpkg/extralibs64/local
ifneq ($(strip $(LOCAL_SOFT)),)
LOCAL_CPPFLAGS = -I"$(LOCAL_SOFT)/include"
LOCAL_LIBS = -L"$(LOCAL_SOFT)/lib$(R_ARCH)" -L"$(LOCAL_SOFT)/lib"
endif
DLLTOOL = $(BINPREF)dlltool --as $(BINPREF)as $(DT_ARCH)
DLLTOOLFLAGS = -k
NM = $(BINPREF)nm
RESCOMP = $(BINPREF)windres $(RC_ARCH)
## MAIN_LD needs to be set by the package
LINKER = $(MAIN_LD)
## as a default
DLL = $(CC)
## Things defined in Renviron on Unix
SED = sed
TAR = tar
## Things defined in MkRules
CAT = cat
CP = cp
MKDIR = mkdir
RM = rm -f
SORT = sort
## For use in packages
GRAPHAPP_LIB = -lRgraphapp
TCL_VERSION = 85
ZLIB_LIBS = -lRzlib
AR = $(BINPREF)ar
## Used by packages 'maps' and 'mapdata'
AWK = gawk
BLAS_LIBS = -L"$(R_HOME)/$(IMPDIR)" -lRblas
C_VISIBILITY =
CC = $(BINPREF)gcc $(M_ARCH)
CFLAGS = -O2 -Wall $(DEBUGFLAG) -std=gnu99 -mtune=core2
CPICFLAGS =
CPPFLAGS =
CXX = $(BINPREF)g++ $(M_ARCH)
CXXCPP = $(CXX) -E
CXXFLAGS = -O2 -Wall $(DEBUGFLAG) -mtune=core2
CXXPICFLAGS =
CXX1X = $(BINPREF)g++ $(M_ARCH)
CXX1XFLAGS = -O2 -Wall $(DEBUGFLAG) -mtune=core2
CXX1XPICFLAGS =
CXX1XSTD = -std=c++0x
DYLIB_EXT = .dll
DYLIB_LD = $(DLL)
DYLIB_LDFLAGS = -shared
DYLIB_LINK = $(DYLIB_LD) $(DYLIB_LDFLAGS) $(LDFLAGS)
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
FC = $(BINPREF)gfortran $(M_ARCH)
FCFLAGS = -O2 $(DEBUGFLAG) -mtune=core2
# additional libs needed when linking with $(FC), e.g. on Solaris
FCLIBS =
F77 = $(BINPREF)gfortran $(M_ARCH)
F77_VISIBILITY =
FFLAGS = -O2 $(DEBUGFLAG) -mtune=core2
FLIBS = -lgfortran
FCPICFLAGS =
FPICFLAGS =
FOUNDATION_CPPFLAGS =
FOUNDATION_LIBS =
JAR =
JAVA =
JAVAC =
JAVAH =
# JAVA_HOME =
# JAVA_LD_LIBRARY_PATH =
JAVA_LIBS = -L"$(JAVA_HOME)/bin/client" -ljvm -ljvm-w32
JAVA_CPPFLAGS = -I"$(JAVA_HOME)/../include" -I"$(JAVA_HOME)/../include/win32"
LAPACK_LIBS = -L"$(R_HOME)/$(IMPDIR)" -lRlapack
## we only need this is if it is external, as otherwise link to R
LIBINTL=
LIBM = -lm
LIBR = -L"$(R_HOME)/$(IMPDIR)" -lR
LIBS = -lm
## needed by R CMD config
LIBnn = lib
LIBTOOL =
LDFLAGS =
## needed to build applications linking to static libR
# MAIN_LD =
# MAIN_LDFLAGS =
# MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
# don't have this: would 'mkdir -p' do?
# MKINSTALLDIRS = $(R_HOME)/bin/mkinstalldirs
## There is no ObjC support in the recommended toolchain,
## but if a toolchain had support, this it what it would be.
OBJC = $(CC)
OBJCFLAGS = -O2
OBJC_LIBS = -lobjc
OBJCXX =
R_ARCH = /x64
RANLIB = $(BINPREF)ranlib
SAFE_FFLAGS = -O2 -ffloat-store
SED = sed
## it seems some makes (but not ours) get upset if SHELL is set.
# SHELL = /bin/sh
SHLIB_CFLAGS =
SHLIB_CXXFLAGS =
SHLIB_CXXLD = $(CXX)
## ideally -shared -static-libstdc++, but not for gcc 4.2.1
SHLIB_CXXLDFLAGS = -shared
SHLIB_CXX1XLD = $(CXX1X)
SHLIB_CXX1XLDFLAGS = -shared
SHLIB_EXT = .dll
SHLIB_FCLD = $(FC)
## ideally -shared -static-libgfortran, but not for gcc 4.2.1
SHLIB_FCLDFLAGS = -shared
SHLIB_FFLAGS =
SHLIB_LD = $(CC)
SHLIB_LDFLAGS = -shared
SHLIB_LIBADD =
SHLIB_LINK = $(SHLIB_LD) -Wl,--export-all-symbols $(SHLIB_LDFLAGS) $(LDFLAGS)
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
SHLIB_PTHREAD_FLAGS = -pthread
STRIP_LIBS = $(BINPREF)strip --strip-unneeded
STRIP_STATIC_LIBS = $(BINPREF)strip --strip-debug
TCLTK_CPPFLAGS = -I "$(TCL_HOME)/include" -DWin32
TCLTK_LIBS = -L"$(TCL_HOME)/bin64" -ltcl$(TCL_VERSION) -ltk$(TCL_VERSION)
STATIC_LIBR =
R_XTRA_CFLAGS =
R_XTRA_CPPFLAGS = -I"$(R_HOME)/include" -DNDEBUG
R_XTRA_CXXFLAGS =
R_XTRA_FFLAGS =
ALL_CFLAGS = $(R_XTRA_CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) $($*-CPPFLAGS) $(CLINK_CPPFLAGS) $(LOCAL_CPPFLAGS)
ALL_CXXFLAGS = $(R_XTRA_CXXFLAGS) $(PKG_CXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(CXXFLAGS)
ALL_OBJCFLAGS = $(PKG_OBJCFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(OBJCFLAGS)
ALL_OBJCXXFLAGS = $(PKG_OBJCXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(OBJCXXFLAGS)
ALL_FFLAGS = $(R_XTRA_FFLAGS) $(PKG_FFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) $(FFLAGS)
ALL_LIBS = $(PKG_LIBS) $(LOCAL_LIBS) $(SHLIB_LIBADD) $(LIBR) $(LIBINTL)
.SUFFIXES:
.SUFFIXES: .c .cc .cpp .d .f .f90 .f95 .m .mm .M .o .a .def .dll .exe .rc
.c.o:
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $#
.c.d:
#echo "making $# from $<"
#$(CC) -std=gnu99 -MM $(ALL_CPPFLAGS) $< > $#
.cc.o:
$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $#
.cpp.o:
$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $#
.cc.d:
#echo "making $# from $<"
#$(CXX) -M $(ALL_CPPFLAGS) $< > $#
.cpp.d:
#echo "making $# from $<"
#$(CXX) -M $(ALL_CPPFLAGS) $< > $#
.m.o:
$(OBJC) $(ALL_CPPFLAGS) $(ALL_OBJCFLAGS) -c $< -o $#
.m.d:
#echo "making $# from $<"
#$(OBJC) -MM $(ALL_CPPFLAGS) $< > $#
.mm.o:
$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $#
.M.o:
$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $#
.f.o:
$(F77) $(ALL_FFLAGS) -c $< -o $#
.f95.o:
$(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c $< -o $#
.f90.o:
$(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c $< -o $#
%.exe:
$(LINKER) $(LINKFLAGS) $($*-LINKFLAGS) -o $# $^ $($*-LIBS) $(LOCAL_LIBS) $(LIBS)
%.dll:
#echo EXPORTS > $*.def
#$(NM) $^ | $(SED) -n $(SYMPAT) >> $*.def
$(SHLIB_LD) -shared $(DLLFLAGS) -o $# $*.def $^ $(ALL_LIBS)
#$(RM) $*.def
lib%.dll.a: %.def
$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $*.dll --input-def $*.def --output-lib $#
%.a:
#$(RM) $#
$(AR) crs $# $^
%.o: %.rc
$(RESCOMP) $(RESFLAGS) -i $< -o $#
5) I am just trying to reproduce the example in the GSL vignette
#include <RcppGSL.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
extern "C" SEXP colNorm(SEXP sM) {
try {
RcppGSL::matrix<double> M = sM; // create gsl data structures from SEXP
int k = M.ncol();
Rcpp::NumericVector n(k); // to store results
for (int j = 0; j < k; j++) {
RcppGSL::vector_view<double> colview = gsl_matrix_column (M, j);
n[j] = gsl_blas_dnrm2(colview);
}
M.free() ;
return n; // return vector
} catch( std::exception &ex ) {
forward_exception_to_r( ex );
} catch(...) {
::Rf_error( "c++ exception (unknown reason)" );
}
return R_NilValue; // -Wall
}
and I get this error
sourceCpp("gsltest.cpp")
g++ -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG -I"C:/R/R-3.1.0/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c gsltest.cpp -o gsltest.o gsltest.cpp:1:21: fatal error: RcppGSL.h: No such file or directory compilation terminated. make: *** [gsltest.o] Error 1 Warning message: running command 'make -f "C:/R/R-31~1.0/etc/x64/Makeconf" -f "C:/R/R-31~1.0/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_15178.dll" WIN=64 TCLBIN=64 OBJECTS="gsltest.o"' had status 2
Error in sourceCpp("gsltest.cpp") :
Error 1 occurred building shared library.
Thanks a lot..
For Windows users with the same problem, you need to follow these steps:
Install R, making sure there are no spaces in the path;
Install Rtools;
Download file local300.zip as suggested by Dirk. And unzip it in the R directory;
Edit the path (e.g. following general instructions shown here http://www.computerhope.com/issues/ch000549.htm) to add the link the directory of local300 as LIB_GSL
Edit your Makevars.win, and you are ready to go
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib/x64 -lgsl -lgslcblas
When you use sourceCpp, if the RcppGSL package does a good job of defining its inline plugin, you need to add to pull in headers, etc ...
// [[Rcpp::depends(RcppGSL)]]
The clue is in what sourceCpp gives you, this below is an extract of what you posted:
g++ -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG
-I"C:/R/R-3.1.0/library/Rcpp/include"
-I"d:/RCompile/CRANpkg/extralibs64/local/include"
-O2 -Wall -mtune=core2 -c gsltest.cpp -o gsltest.o
gsltest.cpp:1:21: fatal error: RcppGSL.h: No such file or directory
If it is too hard to locally build GSL, note that you can also download the actual prebuilt GSL library which CRAN itself uses from this page -- you want the (large-ish) file local300.zip.
It should then should be a matter of adjusting the ennvironment variable LIB_GSL used here:
edd#max:~$ cat svn/rcpp/pkg/RcppGSL/src/Makevars.win
## This assumes that the LIB_GSL variable points to working GSL libraries
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas
edd#max:~$
where I have removed the now-redundant invocation of Rscript for the Rcpp library we no longer need.

Resources