0

I want to create an input file for one code. It looks like this

SITE   FREQ   DATA TYPE      DATUM              ERROR
     1     1     1    2.01562    0.217000E-01
     1     1     2    44.8114     2.86600    
     1     1     5    2.02486    0.217000E-01
     1     1     6    44.0423     2.86600    
     1     2     1    2.03421    0.217000E-01
     1     2     2    53.5181     2.86600    
     1     2     5    2.01103    0.217000E-01
     1     2     6    43.6452     2.86600    
     1     3     1    1.88711    0.217000E-01
     1     3     2    51.5582     2.86600    
     1     3     5    2.00536    0.217000E-01
     1     3     6    43.4296     2.86600    
     1     4     1    1.85939    0.217000E-01
     1     4     2    49.8675     2.86600    
     1     4     5    2.04246    0.217000E-01
     1     4     6    41.5948     2.86600    
     1     5     1    1.86721    0.217000E-01
     1     5     2    42.6603     2.86600    
     1     5     5    2.02059    0.217000E-01
     1     5     6    44.6032     2.86600    
     1     6     1    1.90233    0.217000E-01
     1     6     2    34.9367     2.86600    
     1     6     5    2.02904    0.217000E-01
     1     6     6    45.5312     2.86600    
     2     1     1    2.02998    0.217000E-01
     2     1     2    46.3565     2.86600    
     2     1     5    2.07089    0.217000E-01
     2     1     6    47.8481     2.86600    
     2     2     1    1.94406    0.217000E-01
     2     2     2    52.9107     2.86600    
     2     2     5    1.94073    0.217000E-01
     2     2     6    47.7353     2.86600    
     2     3     1    1.77228    0.217000E-01
     2     3     2    53.3664     2.86600    
     2     3     5    1.93717    0.217000E-01

I have thought of something like this

do i=1,74
  do j=1,4
    write(50,)num1,s1(i),dt(j),v1(i),er1
  end do
end do

But the data type takes value 1,2,5,6 not 1 to 4. How to solve this?

5
  • INTEGER ITRANS(4) / DATA ITRANS /1,2,5,6/ / write(50,)num1,s1(i),ITRANS(j),v1(i),er1? But then I'm not sure I understand the question :) Commented Mar 8, 2016 at 19:14
  • I don't quite understand the two loops and what they would produce. Are you saying that 'DATA TYPE` is in a 4-long vector with values 1,2,5,6 ? Is this your dt? Commented Mar 8, 2016 at 19:20
  • @JoachimIsaksson Yes,that is what I need. Commented Mar 8, 2016 at 19:21
  • @zdim Yes,that is my vector. Commented Mar 8, 2016 at 19:22
  • I've replaced mod(i,4) with Fortran's ternary operator merge, to account for the case when it returns zero. [ dt(mod(4,4)) would have been dt(0), etc ]. Now it returns dt(size(dt)) when i is evenly divisble by dt size. Commented Mar 8, 2016 at 19:43

2 Answers 2

1

Use one loop as you normally would (drop the loop over j) and print corresponding dt values (1,2,5,6) as

merge( dt(mod(i,4)), dt(size(dt)), mod(i,4)/=0 )

This is Fortran's ternary, producing either dt(mod(i,4)) if mod(i,4)/=0 or dt(size(dt)) when mod returns zero. The merge is F95. This does run mod every time through. Alternatively you can make a 74-long vector with repeating 1,2,5,6 in which case you have an extra vector.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure that I fully understand the question but unless I'm wide of the mark I'd frame a solution along these lines:

integer, dimension(4) :: aux = [1,2,5,6]
...
do i=1,74
  do j=1,4
    write(50,)num1,s1(i),dt(aux(j)),v1(i),er1
  end do
end do

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.