[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Please help parsing file [sed, awk, fortran, bash]



Le vendredi 31 août 2012 à 08:21 -0700, daniel jimenez a écrit :

> as before, the file is from an experimenter who chose the format
> arbitrarily (maybe the photon counter outputs that, no clue [dont
> really care]) and Im doing this as a favor.
Maybe this experimenter should ask for a program alteration that would
output the right things straight away. You don't seem to be concerned,
but you might stress the point that someone crafted the output to be
like that. His reasons might have been valid or not but there is
definitely something to do there (not by you, I've understood but your
coworker might not have realized that).  

> I will be looking into sed as it seems like a really useful tool.
I have not used sed enough to be fully proficient with it but while I
think replacing missing values might be quite easy, I can't come up with
something to expand the missing indexes. 

> p.s. doing this from fortran would be a chore...
Well, I find it's a shame that someone coded something he thought was
smart in the first place to finally undo completely what he has done.

      PROGRAM converter
          IMPLICIT NONE
          INTEGER :: DAT(1024)
          DATA DAT / 1024 * 0 /
          INTEGER :: IDX, VAL
          INTEGER  :: MAXLINES
          PARAMETER(MAXLINES=1026)
          CHARACTER(LEN=80) :: LINE
          INTEGER :: i
          OPEN(1, FILE="your_file", STATUS="OLD", ACTION="READ")
          OPEN(2, FILE="your_new_file", STATUS="NEW", ACTION="WRITE")
          READ(1,*)
          READ(1,*)
          DO i=1,MAXLINES
              VAL=1
              READ(1,'(A)', END=20) LINE
              READ(LINE, *, END=10) IDX, VAL
   10         DAT(IDX)=VAL
          END DO
   20     PRINT *, "REACHED END OF FILE"  
          DO i=1,1024
              WRITE(2,*), i, DAT(i)
          END DO
          CLOSE(1)
          CLOSE(2)
      END PROGRAM

Ok, now, I must stress that I am no masochist, that some people do love
me and that I have no neurosis. The problem is I have to learn fortran.
I just thought this was a great opportunity to start that :)



Reply to: