Visual Basic source code (R.Charter & J.Wilkinson) for calculating CalCOFI Line & Sta from latitude & longitude or latitude & longitude from Line & Sta.
Fortran source code was migrated from VMS by Dave Newton 1992; extracted from starep.for (CalCOFI station report generator).
Refer to Microsoft Help for additional information on the following built-in Visual Basic mathmatical functions:
- Log = Returns a Double value containing the logarithm of a specified number.
- Tan = Returns a Double value containing the tangent of an angle.
- Sin = Returns a Double value specifying the sine of an angle.
- Cos = Returns a Double value containing the cosine of the specified angle.
- Atn = Returns a Double value containing the angle whose tangent is the specified number.
'Function used by conversion algorithm
Private Function cRad(Deg As Double) As Double
cRad = Deg * 1.74532925199433E-02
End Function
'Function used by conversion algorithm
Private Function fnz(T1 As Double) As Double
fnz = Log(Tan(cRad(45 + T1 / 2))) * 180 / 3.14159265 - 0.387815 * Sin(cRad(T1))
End Function
'**********'VB Source to Convert LAT-LON TO CALCOFI STN NO. (Line & Sta)**********
Private Static Sub lattosta()
'variables
Dim B As Double, T1 As Double, T2 As Double
Dim F1 As Double, D2 As Double, D1 As Double
Dim M1 As Double, M2 As Double, L2 As Double
Dim L1 As Double, R1 As Double, R2 As Double
Dim X7 As Double, Y7 As Double, L5 As Double
Dim L6 As Double, L4 As Double
Dim Y9 As Double, X9 As Double, Y5 As Double
Dim X5 As Double, J9 As Double, I9 As Double
Dim Longitude As Double, Latitude As Double
Dim S As Double, L As Double, PI As Double
PI = 4 * Atn(1)
'longitude
X = Val(txtLongd.Text) + (Val(txtLongm.Text) / 60)
'latitude
Y = Val(txtLatd.Text) + (Val(txtLatm.Text) / 60)
'constants
X9 = 121.15
Y9 = 34.15
I9 = 60
J9 = 80
X5 = 1 / 15
Y5 = -0.2
If Y = 0 Then GoTo 760 'if latitude = 0 then exit
L1 = (fnz(Y) - fnz(Y9)) * Tan(cRad(30))
L2 = X - X9 - L1
D1 = L1 / Sin(cRad(30))
D2 = L2 * Sin(cRad(30))
F1 = (D1 + D2) * Cos(cRad(30)) + fnz(Y9)
'INVERSE MERCATOR TRANSFORM
'THIS IS AN ITERATIVE PROCEDURE IN WHICH FNZ(T1) IS TAKEN AS THE FIRST APPROXIMATION TO T1.
'IT CONVERGES TO WITHIN .0001 DEG (.006 MIN) OF T1 AFTER ONE ITERATION. GREATER ACCURACY
'CAN BE OBTAINED BY APPROPRIATE MODIFICATION OF THE PROCEDURE TO PERFORM MORE ITERATIONS.
T2 = F1 * PI / 180
T1 = F1
For B = 1 To 5
T1 = 2 * (Atn(Exp(T2 + 0.0067686 * Sin(cRad(T1)))) * 180 / PI - 45)
Next B
R1 = T1
L = J9 + (R1 - Y9) / Cos(cRad(30)) / Y5
S = I9 + (R1 - Y) / Sin(cRad(30)) / X5
'output
txtLine.Text = Format$(L, "##0.0")
txtStation.Text = Format$(S, "##0.0")
txtLatdec.Text = Format$(Y, "#0.000")
txtLongdec.Text = Format$(X, "##0.000")
End Sub
'**********VB Source to Convert Line & Sta to Lat & Lon**********
Private Static Sub statolat()
Dim B As Double, T1 As Double, T2 As Double
Dim F1 As Double, D2 As Double, D1 As Double
Dim M1 As Double, M2 As Double, L2 As Double
Dim L1 As Double, R1 As Double, R2 As Double
Dim X7 As Double, Y7 As Double, L5 As Double
Dim L6 As Double, L4 As Double
Dim Y9 As Double, X9 As Double, Y5 As Double
Dim X5 As Double, J9 As Double, I9 As Double
Dim X As Double, Y As Double, S As Double, L As Double
L = Val(txtLine.Text)
S = Val(txtStation.Text)
I9 = 60
J9 = 80
X5 = 1 / 15
Y5 = -0.2
X9 = 121.15
Y9 = 34.15
If L = 0 Then GoTo 470
'Rem LINES ENDING WITH 3 WILL HAVE .333 ADDED TO LINE
'Rem LINES ENDING WITH 7 WILL HAVE .333 SUBTRACTED
L4 = L / 10
'Int returns the integer portion of a real number
L5 = Int(L4) * 10
L6 = L - L5
If L6 = 3 Then GoTo 310
If L6 = 7 Then GoTo 330
300 GoTo 340
310 L = L + 0.3
GoTo 340
330 L = L - 0.3
340 Y7 = Y5 * (L - J9)
X7 = X5 * (S - I9)
R1 = Y9 + Y7 * Cos(cRad(30))
R2 = X9 + (fnz(R1) - fnz(Y9)) * Tan(cRad(30))
Y = R1 - X7 * Sin(cRad(30))
X = R2 + (fnz(R1) - fnz(Y)) / Tan(cRad(30))
'output
txtLatd.Text = Str$(Int(Y))
txtLatm.Text = Format$((Y - Int(Y)) * 60, "#0.0")
txtLongd.Text = Str$(Int(X))
txtLongm.Text = Format$((X - Int(X)) * 60, "#0.0")
txtLatdec.Text = Format$(Y, "#0.000")
txtLongdec.Text = Format$(X, "##0.000")
470 End Sub
**********End Visual Basic Code**********
**********Fortran Source Code**********
C----------CALCC
C
SUBROUTINE CALCC (LAT, LON, LINE, STA)
C
C CALCULATE CALCOFI LINE AND STATION NUMBER FROM STACST LAT AND LON
C NOTE: BECAUSE THIS ROUTINE IS USED ONLY FOR THE CALCOFI AREA
C WEST LONGITUDE IS POSITIVE.
C
REAL MPLA,DEG,SIN30,COS30
REAL PI,MRCTR, LAT, LON, LINE, STA, L1, L2, MRLA, RLA, RAD
PARAMETER (PI=3.141592654,RAD=PI/180.)
C
INTRINSIC LOG,TAN,SIN,COS
EXTERNAL NVMCT
C
MRCTR(DEG) = LOG(TAN(45.* RAD+DEG/2.))*180./PI - 0.387815*SIN(DEG)
C
MPLA = MRCTR (LAT * RAD)
SIN30 = SIN (30. * RAD)
COS30 = COS (30. * RAD)
L1 = (MPLA - MRCTR (34.15 * RAD)) * TAN (30. * RAD)
L2 = LON - L1 - 121.15
MRLA = L2 * COS30 * SIN30 + MPLA
CALL NVMCT (MRLA, RLA)
LINE = 80. - (RLA - 34.15) * 5. / COS30
STA = 60. + (RLA - LAT ) * 15. / SIN30
RETURN
END
C
C----------NVMCT
C
SUBROUTINE NVMCT( MLAT, LAT)
REAL MLAT, LAT, PI, RAD
INTEGER I
PARAMETER (PI=3.141592654,RAD=PI/180.)
INTRINSIC ATAN,EXP,SIN
C
LAT = MLAT
DO 10 I = 1, 4
LAT = 2.* (ATAN(EXP(MLAT*RAD+ 0.0067686* SIN(LAT* RAD)))
* * 180./PI - 45.)
10 CONTINUE
RETURN
**********End Fortran Source Code**********
| < Prev | Next > |
|---|




