$KCODE="e"
path = "./txt/"

map = %w(cylindrical orthographic orthographic-polar)
#map = %w(cylindrical mollweide azimuthal-eq-area)
omega = [0,25,50,100,200,400,1000,4000]
g = [5,10,100,1000,10000,"inf"]
u0 = %w(1 sqrt2)

def test(o,g,u)
  if o==1000 && g==5 && u=="1"
    return false
  elsif o==0 && g==5 && u=="sqrt2"
    return false
  elsif o==25 && g==5 && u=="sqrt2"
    return false
  elsif o==50 && g==5 && u=="sqrt2"
    return false
  elsif o==200 && g==5 && u=="sqrt2"
    return false
  elsif o==400 && g==5 && u=="sqrt2"
    return false
  elsif o==1000 && g==5 && u=="sqrt2"
    return false
  elsif g=="inf" && u=="1"
    return false
  end
  return true
end

u0.each do |u|
  %w(u-xm ucos-xm uhcos-xm).each do |v|
    File.open("#{path}index_#{v}_U#{u}.txt","w") do |file|
      file.print <<"EOF"
label::<hr>凜棉-啕蘸 蠅昍<hr>
label::<hr>
label::<hr>
label::<hr>
label::<hr>
EOF
      omega.each do |i|
        g.each do |j|
          if test(i,j,u) && !(v=~/h/ && j=="inf")
            file.print <<"EOF"
#{v}_time-lat_Omega#{i}_G#{j}_U#{u}.png::次=#{i}, g=#{j}, U=#{u}
EOF
          else
            file.print <<"EOF"
label::次=#{i}, g=#{j}, U=#{u}
EOF
          end
       end
      end
    end
  end

  %w(xm).each do |v|
    File.open("#{path}index_#{v}_U#{u}.txt","w") do |file|
      file.print <<"EOF"
label::<hr><hr>
label::<hr>
label::<hr>
label::<hr>
label::<hr>
EOF
      omega.each do |i|
        g.each do |j|
          if test(i,j,u)
            file.print <<"EOF"
#{v}_Omega#{i}_G#{j}_U#{u}.png::次=#{i}, g=#{j}, U=#{u}
EOF
          else
            file.print <<"EOF"
label::次=#{i}, g=#{j}, U=#{u}
EOF
          end
       end
      end
    end
  end

  %w(energy enstrophy).each do |v|
    File.open("#{path}index_#{v}_U#{u}.txt","w") do |file|
      file.print <<"EOF"
label::<hr><hr>
label::<hr>
label::<hr>
label::<hr>
label::<hr>
EOF
      omega.each do |i|
        g.each do |j|
          if test(i,j,u)
            file.print <<"EOF"
#{v}_time_Omega#{i}_G#{j}_U#{u}.png::次=#{i}, g=#{j}, U=#{u}
EOF
          else
            file.print <<"EOF"
label::次=#{i}, g=#{j}, U=#{u}
EOF
          end
       end
      end
    end
  end

  %w(vor potvor div hsfc strfunc velpot).each do |v|
    map.each do |m|
      File.open("#{path}index_#{v}_#{m}_U#{u}.txt","w") do |file|
        file.print <<"EOF"
label::<hr>煩蘸-啕蘸 蠅昍<hr>
label::<hr>t=10.0sec<hr>
label::<hr>
label::<hr>
label::<hr>
EOF
        omega.each do |i|
          g.each do |j|
            if test(i,j,u) && !(j=="inf" && (v=="potvor"||v=="div"||v=="hsfc"||v=="velpot"))
              file.print <<"EOF"
#{v}_lon-lat_#{m}_Omega#{i}_G#{j}_U#{u}.png::次=#{i}, g=#{j}, U=#{u} <a href="gallery/#{v}_lon-lat_Omega#{i}_G#{j}_U#{u}.gif">失瓦丟□扑亦件</a>
EOF
            else
              file.print <<"EOF"
label::次=#{i}, g=#{j}, U=#{u}
EOF
            end
          end
        end
      end
    end
  end
end
