Announcement

Collapse
No announcement yet.

calling all Perl experts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calling all Perl experts

    Hey guys, so I'm brand new to perl. So i'm in quite a pickle, I have the code I need in FORTRAN, but I am trying to translate it into Perl.

    Originally posted by Fortran
    parameter(ntm=10000,nspc=1000,particles=201,specie s=4)
    integer cfg,nt,nxspc(nspc)
    double precision tm,ran2
    integer nconfg,nbin(ntm),nhist,ndev,ntspc1(ntm,nspc),flag1 ,flag2,flag3,flag4,flag5
    integer ntspc2(ntm,nspc),ntspc3(ntm,nspc),ntspc4(ntm,nspc)
    integer ntspc5(ntm,nspc),knt1,knt2,knt3,knt4,knt5
    double precision histp,histm,avspc(nspc),sumspc(nspc)
    double precision hist1(particles,species),TT1,chist1(nspc,nspc)
    double precision hist2(particles,species),TT2,chist2(nspc,nspc)
    double precision hist3(particles,species),TT3,chist3(nspc,nspc)
    double precision hist4(particles,species),TT4,chist4(nspc,nspc)
    double precision hist5(particles,species),TT5,chist5(nspc,nspc)


    nconfg=4


    do j=1,1000
    avspc(j)=0.d0
    enddo

    do i=1,10000
    do j=1,1000
    ntspc1(i,j)=0
    ntspc2(i,j)=0
    ntspc3(i,j)=0
    ntspc4(i,j)=0
    ntspc5(i,j)=0
    enddo
    enddo


    do i=1,1000
    nxspc(i)=0
    sumspc(i)=0.d0
    do j=1,1000
    chist1(i,j)=0.d0
    chist2(i,j)=0.d0
    chist3(i,j)=0.d0
    chist4(i,j)=0.d0
    chist5(i,j)=0.d0
    enddo
    enddo
    do i=1,particles
    do j=1,species
    hist1(i,j)=0.d0
    hist2(i,j)=0.d0
    hist3(i,j)=0.d0
    hist4(i,j)=0.d0
    hist5(i,j)=0.d0
    enddo
    enddo

    do cfg=1,nconfg
    flag1=0
    flag2=0
    flag3=0
    flag4=0
    flag5=0


    call system("$home\abdurehman1\BioNetGen\Perl2\BNG2.pl rxn1.txt
    & > test.txt")

    c call system("tac test>>test1")

    cc # gives number of lines in the file test
    call system("cat test | wc -l > inpl")
    cc # gives number of columns in the file test
    call system("cat test | tail -3 | head -1|awk '{print NF}'>inpc")


    open(unit=10,file='inpl',status='old')
    read(10,*)nt
    close(10)

    open(unit=11,file='inpc',status='old')
    read(11,*)ncol
    close(11)


    c TT1=60.d0
    c TT2=160.d0
    c TT3=260.d0
    c TT4=460.d0
    c TT5=760.d0

    TT1=60.d0
    TT2=100.d0
    TT3=200.d0
    TT4=660.d0
    TT5=2000.d0

    open(unit=2,file='test',status='old')


    do i=1,nt-1
    read(2,*)tm,(nxspc(j),j=1,ncol-1)



    if(flag1.eq.0) then
    if(tm.ge.TT1)then
    flag1=1

    do j=1,ncol-1
    hist1(nxspc(j)+1,j)= hist1(nxspc(j)+1,j)+1

    enddo
    endif
    endif
    if(flag2.eq.0) then
    if(tm-TT2.ge.0)then
    flag2=1

    do j=1,ncol-1
    hist2(nxspc(j)+1,j)= hist2(nxspc(j)+1,j)+1

    enddo
    endif
    endif

    if(flag3.eq.0) then
    if(tm-TT3.ge.0)then
    flag3=1

    do j=1,ncol-1
    hist3(nxspc(j)+1,j)=hist3(nxspc(j)+1,j)+1

    enddo

    endif
    endif

    if(flag4.eq.0) then
    if(tm-TT4.ge.0)then
    flag4=1

    do j=1,ncol-1
    hist4(nxspc(j)+1,j)=hist4(nxspc(j)+1,j)+1

    enddo
    endif
    endif
    if(flag5.eq.0) then
    if(tm-TT5.ge.0)then
    flag5=1

    do j=1,ncol-1
    hist5(nxspc(j)+1,j)=hist5(nxspc(j)+1,j)+1

    enddo
    endif
    endif


    enddo
    close(2)
    enddo


    open(unit=31,status='unknown')
    write(96,*)"# histogram at",TT1,"secs"
    do i=1,201

    write(96,'(1X,I4,28F15.5)')i-1,(hist1(i,j), j=1,ncol-1)

    enddo
    4:BigKing> xD
    4:Best> i'm leaving chat
    4:BigKing> what did i do???
    4:Best> told you repeatedly you cannot use that emoji anymore
    4:BigKing> ???? why though
    4:Best> you're 6'4 and black...you can't use emojis like that
    4:BigKing> xD

  • #2
    I know in Perl I can skip like all of this defining and most of the initiliazing


    #!/usr/bin/perl


    #$runs=<>;
    $runs=20; #comment


    for($i=1;$i< $runs+1; $i++)
    {


    `BioNetGen\Perl2\BGN2.pl $me/rxn1.txt`;

    `mv rxn_ssa.cdat test`;



    @avspc ("j")

    @ntspc1 ("i", "j")

    @ntspc2 ("i", "j")

    @ntspc3 ("i", "j")

    @ntspc4 ("i", "j")

    @ntspc5 ("i", "j")

    @chist1 ("i","j")

    @chist2 ("i","j")

    @chist3 ("i","j")

    @chist4 ("i","j")

    @chist5 ("i","j")

    @hist1 ("i", "j")

    @hist2 ("i", "j")

    @hist3 ("i", "j")

    @hist4 ("i", "j")

    @hist5 ("i", "j")


    $flag1=0

    $flag2=0

    $flag3=0

    $flag4=0

    $flag5=0



    `cat test | wc -l > inpl` #open test, read # of rows, print to inpl


    `cat test | tail -3 | head -1|awk '{print NF}'>inpc` # read columns, print to inpc



    open FILE, "inpl.txt"
    $nt=<FILE>
    4:BigKing> xD
    4:Best> i'm leaving chat
    4:BigKing> what did i do???
    4:Best> told you repeatedly you cannot use that emoji anymore
    4:BigKing> ???? why though
    4:Best> you're 6'4 and black...you can't use emojis like that
    4:BigKing> xD

    Comment


    • #3
      I'll do it but you'll have to paypal me $100 first for my time.

      Comment


      • #4
        Originally posted by Nockm View Post
        I'll do it but you'll have to paypal me $100 first for my time.
        not asking you to do it,

        anyways, been googling past 2 hours, how do i read a text file, and only store the first column into an array.

        i have:

        open (filehandle, 'inpc')
        while (<Filehandle> {
        $ _=@array

        should i just do a split? but i've seen splits done only on data inputted by the user, where there are like clearly different sets of values (ints and strings for instance)

        in fortran i would do a do loop and just do read(unit, *)@array, @array2, but this is just implied syntax to make it read only the first value of the first row, and continue from there.
        but asfkjasf i CANT GET IT.

        edit: the whole thing must be done in Perl, all those saying call Fortran can just forget it!!!
        4:BigKing> xD
        4:Best> i'm leaving chat
        4:BigKing> what did i do???
        4:Best> told you repeatedly you cannot use that emoji anymore
        4:BigKing> ???? why though
        4:Best> you're 6'4 and black...you can't use emojis like that
        4:BigKing> xD

        Comment


        • #5
          you serious?


          this shit is way too easy, not going to tell you


          good luck with your search

          Comment


          • #6
            disclaimer: i am all sorts of rusty. haven't done a lick of coding in a good long while. never messed with perl very much.


            do you know the width of each column? (width in terms of the number of characters) if so, you should be able to pull a substring out of the text file and push that into your array.

            http://www.trilug.org/~chilcote/Perl/flatfiles.html - start reading under the "Flat File Sorting" heading.
            jasonofabitch loves!!!!

            Comment


            • #7
              i actually figured it out, after some excruciating visual parsing of hundreds of google pages

              push @columnTime,(split(/\s+/,$_))[0]

              so this basically does the job haha, i read more about the split function and the column syntax and it worked out well.

              and for the rest of the columns, just did a for loop and stored every i=1, i++ column into $columnRest, split(akfmklaf)[$i]

              haven't really compiled in a while since i don't want my hopes and dreams to get murderized, but i will be doing it tonight, thanks for the help though jason, the push was it
              4:BigKing> xD
              4:Best> i'm leaving chat
              4:BigKing> what did i do???
              4:Best> told you repeatedly you cannot use that emoji anymore
              4:BigKing> ???? why though
              4:Best> you're 6'4 and black...you can't use emojis like that
              4:BigKing> xD

              Comment


              • #8
                Oh well, got here too late.

                Comment

                Working...
                X