How can I fix the Error of MSC Bootloader with ATxmega32a4? - avr

I'm trying to upload a .hex file via Uart into an ATxmega32a4. I'm using BASCOM IDE and Programmed my MCU with the sample code which is available in sample folder of Bascom (I have attached my code). So I'm using MSC Bootloader Wizard in Bascom to upload my code but unfortunately it has error 6006. I increased timeout but the problem is not fixed.
I monitored serial port as you can find it in attachments.
Could anyone help?
'----------------------------------------------------------------
' (c) 1995-2020, MCS
' BootloaderXmega32A4.bas
' This sample demonstrates how you can write your own bootloader
' in BASCOM BASIC for the XMEGA
'-----------------------------------------------------------------
'The loader is supported from the IDE
$crystal = 29491200 ' xmega128 is running on 32 MHz
$regfile = "xm32a4def.dat"
$hwstack = 40
$swstack = 40
$framesize = 40
'first enabled the osc of your choice
''Config Osc = Disabled , 32mhzosc = Enabled 'internal 2 MHz and 32 MHz enabled
Config Osc = Enabled , 32mhzosc = Enabled , Extosc = Enabled
'configure the systemclock
''Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 ' we will use 32 MHz and divide by 1 to end up with 32 MHz
Config Sysclock = External , Prescalea = 1 , Prescalebc = 1_1
$loader = &H4000 ' bootloader starts after the application
'this sample uses 38400 baud. To be able to use the Xplain which has a bootloader working at 9600 baud you need to use 9600 baud
''Config Com1 = 38400 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8 ' use USART C0
'COM0-USARTC0, COM1-USARTC2, COM2-USARTD0. etc.
''Config Portc.3 = Output 'define TX as output
''Config Pinc.2 = Input
Config Com3 = 115200 , Mode = Asynchroneous , Parity = EVEN , Stopbits = 1 , Databits = 8
Open "COM3:" For Binary As #1
Config PortD.3 = Output 'define TX as output
Config PinD.2 = Input
Const Maxwordbit = 7 ' Z7 is maximum bit '
Const Maxword =(2 ^ Maxwordbit) * 2 '128
Const Maxwordshift = Maxwordbit + 1
Const Cdebug = 0 ' leave this to 0
'Dim the used variables
Dim Bstatus As Byte , Bretries As Byte , Bmincount As Byte , Bblock As Byte , Bblocklocal As Byte
Dim Bcsum1 As Byte , Bcsum2 As Byte , Buf(128) As Byte , Csum As Byte
Dim J As Byte , Spmcrval As Byte ' self program command byte value
Dim Z As Long 'this is the Z pointer word
Dim Vl As Byte , Vh As Byte ' these bytes are used for the data values
Dim Wrd As Word , Page As Word 'these vars contain the page and word address
Disable Interrupts 'we do not use ints
'We start with receiving a file. The PC must send this binary file
'some constants used in serial com
Const Nak = &H15
Const Ack = &H06
Const Can = &H18
$timeout = 300000 'we use a timeout
'When you get LOADER errors during the upload, increase the timeout value
'for example at 16 Mhz, use 200000
Bretries = 5 : Bmincount = 3 'we try 10 times and want to get 123 at least 3 times
Do
Bstatus = Waitkey(#1) 'wait for the loader to send a byte
If Bstatus = 123 Then 'did we received value 123 ?
If Bmincount > 0 Then
Decr Bmincount
Else
Print #1, Chr(bstatus);
Goto Loader ' yes so run bootloader
End If
Else 'we received some other data
If Bretries > 0 Then 'retries left?
Bmincount = 3
Decr Bretries
Else
Rampz = 0
Goto Proces_reset 'goto the normal reset vector at address 0
End If
End If
Loop
'this is the loader routine. It is a Xmodem-checksum reception routine
Loader:
Do
Bstatus = Waitkey(#1)
Loop Until Bstatus = 0
Spmcrval = &H20 : Gosub Do_spm ' erase all app pages
Bretries = 10 'number of retries
Do
Csum = 0 'checksum is 0 when we start
Bblocklocal = 1
Print #1, Chr(bstatus); ' firt time send a nack
Do
Bstatus = Waitkey(#1) 'wait for statuse byte
Select Case Bstatus
Case 1: ' start of heading, PC is ready to send
Csum = 1 'checksum is 1
Bblock = Waitkey(#1) : Csum = Csum + Bblock 'get block
Bcsum1 = Waitkey(#1) : Csum = Csum + Bcsum1 'get checksum first byte
For J = 1 To 128 'get 128 bytes
Buf(j) = Waitkey(#1) : Csum = Csum + Buf(j)
Next
Bcsum2 = Waitkey(#1) 'get second checksum byte
If Bblocklocal = Bblock Then 'are the blocks the same?
If Bcsum2 = Csum Then 'is the checksum the same?
Gosub Writepage 'yes go write the page
Print #1, Chr(bstatus); 'acknowledge
Incr Bblocklocal 'increase local block count
Else 'no match so send nak
Print #1, Chr(bstatus);
End If
Else
Print #1, Chr(bstatus); 'blocks do not match
End If
Case 4: ' end of transmission , file is transmitted
If Wrd > 0 Then 'if there was something left in the page
Wrd = 0 'Z pointer needs wrd to be 0
Spmcrval = &H24 : Gosub Do_spm 'write page
End If
Print #1, Chr(bstatus); ' send ack and ready
Waitms 20
Goto Proces_reset
Case &H18: ' PC aborts transmission
Goto Proces_reset ' ready
Case 123 : Exit Do 'was probably still in the buffer
Case 124 : Exit Do
Case Else
Exit Do ' no valid data
End Select
Loop
If Bretries > 0 Then 'attempte left?
Waitms 1000
Decr Bretries 'decrease attempts
Else
Goto Proces_reset 'reset chip
End If
Loop
'write one or more pages
Writepage:
For J = 1 To 128 Step 2 'we write 2 bytes into a page
Vl = Buf(j) : Vh = Buf(j + 1) 'get Low and High bytes
!lds r0, {vl} 'store them into r0 and r1 registers
!lds r1, {vh}
Spmcrval = &H23 : Gosub Do_spm 'write value into page at word address
Wrd = Wrd + 2 ' word address increases with 2 because LS bit of Z is not used
If Wrd = Maxword Then ' page is full
Wrd = 0 'Z pointer needs wrd to be 0
Spmcrval = &H24 : Gosub Do_spm 'write page
Page = Page + 1 'next page
End If
Next
Return
Do_spm:
Z = Page 'make equal to page
Shift Z , Left , Maxwordshift 'shift to proper place
Z = Z + Wrd 'add word
!lds r30,{Z}
!lds r31,{Z+1}
#if _romsize > 65536
!lds r24,{Z+2}
!sts rampz,r24 ' we need to set rampz also for the M128
#endif
Nvm_cmd = Spmcrval
Cpu_ccp = &H9D
!spm 'this is an asm instruction
Do_spm_busy:
!lds r23, NVM_STATUS
!sbrc r23,7 ;if busy bit is cleared skip next instruc tion
!rjmp do_spm_busy
Return
Proces_reset:
Rampz = 0
Goto _reset 'start at address 0

Related

PrintPreviewControl & Form Design working differently on another OS. VB.NET

im writing an app for accountings of small hotel, i'm working with Visual Studio 2013, on OS: windows 10 (Laptop). After finishing the app just published it using publish wizard, then everything was going great till i copied the published files to another computer contains OS: Windows 7 SP1, the app worked successfully but with a little changes in form design and while preview reports printing.
Here's two pictures to explain what is exactly the problem...
If anyone could explain what's going on and what to do to solve this issue would be respected.
Here's my class which contains printpreviewcontrol code:
Private mRow As Integer = 0
Private newpage As Boolean = True
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
Dim font36 = New Font("Playball", 36, FontStyle.Regular)
Dim font8 = New Font("Lora", 8, FontStyle.Regular)
Dim font20 = New Font("Lora", 20, FontStyle.Underline)
Dim font16 = New Font("Lora", 16, FontStyle.Regular)
e.Graphics.DrawString("Riviera Beach Chalets", font36, Brushes.Black, New Rectangle(150, 25, 800, 100))
e.Graphics.DrawString("Accounting Reports", font20, Brushes.Black, New Rectangle(650, 45, 300, 50))
e.Graphics.FillRectangle(Brushes.MistyRose, New Rectangle(101, 741, 19, 19))
e.Graphics.DrawString("Accommondation Revenue or Beach Revenue or CoffeeShop Revenue is 0", font8, Brushes.Black, New Rectangle(125, 745, 500, 30))
e.Graphics.DrawString("Amount Received Total :", font16, Brushes.Black, New Rectangle(570, 735, 500, 50))
e.Graphics.DrawString(Report_Database.reporttot, font16, Brushes.Black, New Rectangle(850, 735, 500, 50))
' sets it to show '...' for long text
Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
fmt.LineAlignment = StringAlignment.Center
fmt.Trimming = StringTrimming.EllipsisCharacter
Dim y As Int32 = e.MarginBounds.Top
Dim rc As Rectangle
Dim x As Int32
Dim h As Int32 = 0
Dim row As DataGridViewRow
' print the header text for a new page
' use a grey bg just like the control
If newpage Then
row = Report_Database.DataGridView1.Rows(mRow)
x = 50
For Each cell As DataGridViewCell In row.Cells
' since we are printing the control's view,
' skip invidible columns
If cell.Visible Then
rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)
e.Graphics.FillRectangle(Brushes.LightGray, rc)
e.Graphics.DrawRectangle(Pens.Black, rc)
' reused in the data pront - should be a function
Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
Case DataGridViewContentAlignment.BottomRight,
DataGridViewContentAlignment.MiddleRight
fmt.Alignment = StringAlignment.Far
rc.Offset(-1, 0)
Case DataGridViewContentAlignment.BottomCenter,
DataGridViewContentAlignment.MiddleCenter
fmt.Alignment = StringAlignment.Center
Case Else
fmt.Alignment = StringAlignment.Near
rc.Offset(2, 0)
End Select
e.Graphics.DrawString(Report_Database.DataGridView1.Columns(cell.ColumnIndex).HeaderText,
Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)
x += rc.Width
h = Math.Max(h, rc.Height)
End If
Next
y += h
End If
newpage = False
' now print the data for each row
Dim thisNDX As Int32
For thisNDX = mRow To Report_Database.DataGridView1.RowCount - 1
' no need to try to print the new row
If Report_Database.DataGridView1.Rows(thisNDX).IsNewRow Then Exit For
row = Report_Database.DataGridView1.Rows(thisNDX)
h = 0
' reset X for data
x = 50
' print the data
For Each cell As DataGridViewCell In row.Cells
If cell.Visible Then
rc = New Rectangle(x, y, cell.Size.Width, cell.Size.Height)
' SAMPLE CODE: How To
' up a RowPrePaint rule
If Val(row.Cells(2).Value) = 0 Or Val(row.Cells(3).Value) = 0 Or Val(row.Cells(4).Value) = 0 Then
Using br As New SolidBrush(Color.MistyRose)
e.Graphics.FillRectangle(br, rc)
End Using
End If
e.Graphics.DrawRectangle(Pens.Black, rc)
Select Case Report_Database.DataGridView1.Columns(cell.ColumnIndex).DefaultCellStyle.Alignment
Case DataGridViewContentAlignment.BottomRight,
DataGridViewContentAlignment.MiddleRight
fmt.Alignment = StringAlignment.Far
rc.Offset(-1, 0)
Case DataGridViewContentAlignment.BottomCenter,
DataGridViewContentAlignment.MiddleCenter
fmt.Alignment = StringAlignment.Center
Case Else
fmt.Alignment = StringAlignment.Near
rc.Offset(2, 0)
End Select
e.Graphics.DrawString(cell.FormattedValue.ToString(),
Report_Database.DataGridView1.Font, Brushes.Black, rc, fmt)
x += rc.Width
h = Math.Max(h, rc.Height)
End If
Next
y += h
' next row to print
mRow = thisNDX + 1
If y + h > e.MarginBounds.Bottom Then
e.HasMorePages = True
' mRow -= 1 causes last row to rePrint on next page
newpage = True
Button1.Enabled = True
Button4.Enabled = True
If mRow = Report_Database.DataGridView1.RowCount Then
e.HasMorePages = False
Exit Sub
End If
Return
End If
Next
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical)
End Try

typecasting error in 64 bit. type mismatch

I am having problem in deploying VB6 apps into 64 bit windows. When I run the EXE, It gives out error "type mismatch"
The code is below :
Private Sub writedate (loc as string)
Dim dout(0 To 15) As Byte
Dim strdate_day as string
Dim strdate_mon as string
:
:
dout(0) = strdate_day 'This is the problem in 64 bit
dout(1) = strdate_mon
End sub
Public Function **Hex_Dec2**(ByVal val As String, ByVal start As Byte) As Byte
Dim MSB As Byte
Dim LSB As Byte
Dim Fbyte As Byte
Fbyte = 0
MSB = 0
LSB = 0
MSB = StrHEX_Dec(Mid(val, start, 1))
LSB = StrHEX_Dec(Mid(val, start + 1, 1))
Fbyte = (MSB * 16) + LSB
Hex_Dec2 = Fbyte
Debug.Print "val : " & val & " Fbyte : " & Fbyte
End Function
If I run the EXE file on 32 bit machine, it works fine. Absolutely no error.
The code HEX_DEC2 is a special function that converts string into byte. I have to use this function otherwise the value written will be incorrect. When I do : dout(0) = HEX_DEC2(strdate_day), it does not give "type mismatch" error on 64bit. For technical reason, i don't want to run this function
Strangely, the laptop that I am using to develop the app is 64 bit as well and doesn't give out any error when i run it from both the source code and the EXE file.
How do i overcome this problem ?

How to get physical page in Solaris 11

I am using mdb on Solaris 11. I have opened a file by using " tail -f file_name" command in another ssh session. I got the pid of tail command and Vnode of the file opened by tail command. After getting the Vnode, I fired "walk page" on this file. Unfortunately, I am not getting any pages in walk. How to get Virtual Pages and Physical pages?
I have done following.
1) Opened the file with 'tail -f'.
2) Get the pid in mdb. Get the Vnode of the opened file.
3) Get the page_t from Vnode_t of the opened file.
4) Left shift to the page number with 0xD, it will give pp2pa effect.
Here are the dcmds in mdb.
> ::pgrep tail
S PID PPID PGID SID UID FLAGS ADDR NAME
R 2889 2882 2889 2850 0 0x4a004000 0000060013f29890 tail
> 0000060013f29890::pfiles
FD TYPE VNODE INFO
0 REG 00000600162f6740 /export/home/chaitanya/OpenSolaris/README.opensolaris
1 CHR 000006001a290400 /devices/pseudo/pts#0:2
2 CHR 000006001a290400 /devices/pseudo/pts#0:2
> 00000600162f6740::walk page
70004781480
700040b0400
> 70004781480::print -at page_t
{
70004781480 u_offset_t p_offset = 0x2000
70004781488 struct vnode *p_vnode = 0x600162f6740
70004781490 selock_t p_selock = 0
70004781494 uint_t p_vpmref = 0x11d9d
70004781498 struct page *p_hash = 0x70002f79b00
700047814a0 struct page *p_vpnext = 0x700040b0400
700047814a8 struct page *p_vpprev = 0x700040b0400
700047814b0 struct page *p_next = 0x70004781480
700047814b8 struct page *p_prev = 0x70004781480
700047814c0 ushort_t p_lckcnt = 0
700047814c2 ushort_t p_cowcnt = 0
700047814c4 kcondvar_t p_cv = {
700047814c4 ushort_t _opaque = 0
}
700047814c6 kcondvar_t p_io_cv = {
700047814c6 ushort_t _opaque = 0
}
700047814c8 uchar_t p_iolock_state = 0
700047814c9 volatile uchar_t p_szc = 0
700047814ca uchar_t p_fsdata = 0
700047814cb uchar_t p_state = 0x40
700047814cc uchar_t p_nrm = 0x2
700047814cd uchar_t p_vcolor = 0x2
700047814ce uchar_t p_index = 0
700047814cf uchar_t p_toxic = 0
700047814d0 void *p_mapping = 0
700047814d8 pfn_t p_pagenum = 0x80f029
700047814e0 uint_t p_share = 0
700047814e4 uint_t p_sharepad = 0
700047814e8 uint_t p_slckcnt = 0
700047814ec uint_t p_kpmref = 0
700047814f0 struct kpme *p_kpmelist = 0
700047814f8 kmutex_t p_ilock = {
700047814f8 void *[1] _opaque = [ 0 ]
}
}
Left shift to the page number 0x80f029 with 0xD, it will give pp2pa
> 101E052000,100::dump -p
\/ 1 2 3 4 5 6 7 8 9 a b c d e f v123456789abcdef
101e052000: 75742069 742e2020 4e6f7220 646f2079 ut it. Nor do y
101e052010: 6f752068 61766520 746f206b 65657020 ou have to keep
101e052020: 7468650a 20202020 206e616d 65206f70 the. name op
101e052030: 656e736f 6c617269 732e7368 2c206275 ensolaris.sh, bu
101e052040: 74207468 61742773 20746865 206e616d t that's the nam
101e052050: 65207765 276c6c20 75736520 696e2074 e we'll use in t
101e052060: 68657365 206e6f74 65732e0a 0a202020 hese notes...
101e052070: 20205468 656e206d 616b6520 74686520 Then make the
101e052080: 666f6c6c 6f77696e 67206368 616e6765 following change
101e052090: 7320696e 20796f75 72206f70 656e736f s in your openso
101e0520a0: 6c617269 732e7368 3a0a0a20 20202d20 laris.sh:.. -
101e0520b0: 6368616e 67652047 41544520 746f2074 change GATE to t
101e0520c0: 6865206e 616d6520 6f662074 68652074 he name of the t
101e0520d0: 6f702d6c 6576656c 20646972 6563746f op-level directo
101e0520e0: 72792028 652e672e 2c0a2020 20202022 ry (e.g.,. "
101e0520f0: 74657374 77732229 2e0a0a20 20202d20 testws")... -

End-of-file error reading text file

I have got a problem in running the blew program for reading a text file as input file. This input file is like a matrix with 3 columns -- 3 numbers with format of (3(F3.6,1x)) -- and 4368 rows.
The input file is:
602340.440000 129706.190000 28.892939
602340.880000 129706.390000 28.955128
602884.500000 128780.700000 29.876873
602884.380000 128781.190000 29.875114
602884.250000 128781.660000 29.885448
602884.130000 128782.150000 29.895996
602883.940000 128782.630000 29.899380
602883.810000 128783.120000 29.903221
602883.690000 128783.590000 29.907070
PROGRAM is:
USE BIEF
USE DECLARATIONS_TELEMAC2D
IMPLICIT NONE
INTEGER LNG,LU, ITRAC,I, NSOM,J, K, NDOWN
INTEGER, PARAMETER :: NLINE =4368
DOUBLE PRECISION, PARAMETER:: BATHY_RADIER_up= 29.84D0
DOUBLE PRECISION, PARAMETER:: DEPTH_up = 2.15D0
REAL :: A(5000),B(5000),C(5000)
DOUBLE PRECISION :: XPOLYD(14), YPOLYD(14), INPOLYD(14)
COMMON/INFO/LNG,LU
DOUBLE PRECISION XPOLY(6), YPOLY(6),COTE_RADIER_up
NSOM = 6
XPOLY(1) = 602883.13
XPOLY(2) = 602886.15
XPOLY(3) = 602887.15
XPOLY(4) = 602905.46
XPOLY(5) = 602902.52
XPOLY(6) = 602884.13
YPOLY(1) = 128779.99
YPOLY(2) = 128780.80
YPOLY(3) = 128777.12
YPOLY(4) = 128741.21
YPOLY(5) = 128739.75
YPOLY(6) = 128775.96
AT = 0.D0
CALL OS( 'X=0 ' , X=U )
CALL OS( 'X=0 ' , X=V )
IF(CDTINI(1:10).EQ.'COTE NULLE'.OR.
* CDTINI(1:14).EQ.'ZERO ELEVATION') THEN
CALL OS( 'X=C ' , H , H , H , 0.D0 )
CALL OS( 'X=X-Y ' , H , ZF , H , 0.D0 )
ELSEIF(CDTINI(1:14).EQ.'COTE CONSTANTE'.OR.
* CDTINI(1:18).EQ.'CONSTANT ELEVATION') THEN
CALL OS( 'X=C ' , H , H , H , COTINI )
CALL OS( 'X=X-Y ' , H , ZF , H , 0.D0 )
ELSEIF(CDTINI(1:13).EQ.'HAUTEUR NULLE'.OR.
* CDTINI(1:10).EQ.'ZERO DEPTH') THEN
CALL OS( 'X=C ' , H , H , H , 0.D0 )
ELSEIF(CDTINI(1:17).EQ.'HAUTEUR CONSTANTE'.OR.
* CDTINI(1:14).EQ.'CONSTANT DEPTH') THEN
CALL OS( 'X=C ' , H , H , H , HAUTIN )
ELSEIF(CDTINI(1:13).EQ.'PARTICULIERES'.OR.
* CDTINI(1:10).EQ.'PARTICULAR'.OR.
* CDTINI(1:07).EQ.'SPECIAL') THEN
NDOWN = 14
XPOLYD(1) = 602883.13
XPOLYD(2) = 602886.15
XPOLYD(3) = 602864.47
XPOLYD(4) = 602837.90
XPOLYD(5) = 602821.91
XPOLYD(6) = 602649.77
XPOLYD(7) = 602634.35
XPOLYD(8) = 602345.08
XPOLYD(9) = 602326.07
XPOLYD(10) = 602619.31
XPOLYD(11) = 602638.33
XPOLYD(12) = 602811.64
XPOLYD(13) = 602831.52
XPOLYD(14) = 602857.16
YPOLYD(1) = 128779.99
YPOLYD(2) = 128780.80
YPOLYD(3) = 128867.74
YPOLYD(4) = 128936.74
YPOLYD(5) = 128953.95
YPOLYD(6) = 129105.43
YPOLYD(7) = 129143.43
YPOLYD(8) = 129713.38
YPOLYD(9) = 129708.26
YPOLYD(10) = 129136.41
YPOLYD(11) = 129094.72
YPOLYD(12) = 128941.16
YPOLYD(13) = 128931.09
YPOLYD(14) = 128865.81
PRINT *, 'opening file'
DO 10 J=1,NPOIN
IF(INPOLY(X(J),Y(J),XPOLY,YPOLY,NSOM)) THEN
PRINT *, 'upstream area'
H%R(J)=MAX(0.D0,COTE_RADIER_up-ZF%R(J))
U%R(J)=0.0D0
PRINT *, 'upstream area'
write(lu,*) 'upstream ....',J,H%r(J)
ELSE
IF(INPOLY(X(J),Y(J),XPOLYD,YPOLYD,NDOWN)) THEN
OPEN(unit =90, FILE = 'cunnette_xyz.txt', FORM='FORMATTED')
PRINT *, 'downstream area'
READ(90,*) A(K),B(K),C(K)
PRINT *, 'already read'
DO K=1,NLINE
PRINT *, "number of lines read:", NLINE
IF(A(K).EQ.X(J).AND.B(K).EQ.Y(J)) then
PRINT *, 'Nodes are inside'
H%R(K)=0.45D0
U%R(K)=0.D0
ELSE
H%R(K)=0.0D0
U%R(K)=0.0D0
ENDIF
ENDDO
CLOSE(90)
ENDIF
ENDIF
10 CONTINUE
ELSE
IF(LNG.EQ.1) THEN
WRITE(LU,*) 'CONDIN : CONDITION INITIALE NON PREVUE : ',CDTINI
ENDIF
IF(LNG.EQ.2) THEN
WRITE(LU,*) 'CONDIN: INITIAL CONDITION UNKNOWN: ',CDTINI
ENDIF
STOP
ENDIF
IF(NTRAC.GT.0) THEN
DO ITRAC=1,NTRAC
CALL OS( 'X=C ' , X=T%ADR(ITRAC)%P , C=TRAC0(ITRAC) )
ENDDO
ENDIF
CALL OS( 'X=C ' , VISC , VISC , VISC , PROPNU )
RETURN
END
The error message when running is:
at line read file: Fortran runtime error: End of file.
My last output is 'downstream area' aftre open Command. Could anybody help me please?
First of all, you are opening the file repeatedly for every value of J. This seems wrong.
Secondly, you have not given the variable NPOIN a value (greater than 1), so your outer loop on J will not stop running (I guess), and this will eventually lead to you trying to read beyond the end of file.
You have nested loops, one on J and one on K, which seems not logical. You should have one only.
Open the file outside of the J loop, and then read line per line until you reach the end of the file:
INTEGER :: Reason
INTEGER :: NPOIN
OPEN(unit =90, IOSTAT=Reason, FILE = 'cunnette_xyz.txt', FORM='FORMATTED')
IF (Reason > 0) THEN
* ... something wrong ...
PRINT *, 'Error opening file'
STOP
END IF
NPOIN = 0
DO
NPOIN = NPOIN + 1
READ(*,*, IOSTAT=Reason) A(NPOIN), B(NPOIN), C(NPOIN)
IF (Reason > 0) THEN
PRINT *, 'Error reading input from file. Aborted'
STOP
ELSE IF (Reason < 0) THEN
* ... end of file reached ...
NPOIN = NPOIN - 1
PRINT *, 'All data read from file'
EXIT
END IF
END DO
* All input should be in A, B, C arrays now, with NPOIN entries
DO K=1, NPOIN
* Your processing comes here. No more file I/O.
END DO

Sub line gives compile error: variable not defined

Upon trying to run my code I get the error "compile error: variable not defined" and it highlights my Sub line. Here is the code for reference.
Sub RI_Processing()
Dim i As Single
Dim Output() As Single 'Define this dynamic array for the solver output
Process the DMSO data
For i = 1 To 45 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet1.Columns("i").Values
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 1) = Sheet1.Range("B4").Values
Next i
i = 0
' Process the NaCl Data
For i = 1 To 102 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet2.Columns("i").Values
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 2) = Sheet1.Range("B4").Values
Next i
i = 0
' Process the Sucrose data
For i = 1 To 72 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet3.Columns("i").Values 'Copies the data of all 'i' columns to raw data for solver
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve 'Run solver
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 3) = Sheet1.Range("B4").Values 'Put solver output to the matrix 'output' in the appropriate columns
Next i
End Sub

Resources