C This is a sample FORTRAN program for Compaq Digital Fortran compiler. C The generated DLL is to be linked to PSIM. C C To compile the program into DLL, you can open the workspace file C "fortran_dll.dsw" as provided. Or you can create a new project by C following the procedure below: C C - Create a directory called "C:\digital_fortran_dll", and copy the file C "fortran_dll.f" that comes with the PSIM software into the directory C C:\fortran_dll. C C - Start Microsoft Developer Studio. From the "File" menu, choose "New". C In the "Projects" page, select "Win32 Dynamic-Link Library", and set C "Project name" as "digital_fortran_dll", and "Location" as C "C:\fortran_dll". Make sure that "Create new workspace" is selected, C and under "Platform", "Win32" is selected. C C - From the "Project" menu, go to "Add to Project"/"Files...", and select C "fortran_dll.f". C C - Go to "Project"/"Settings..."/"Fortran", select "External Procedures", C and make sure that the option "Argument Passing Conventions" is set to C "C, By Reference". C C - Add your own code as needed. C C - From the "Build" menu, go to "Set Active Configurations...", and select C "Win32 Release". From the "Build" menu, choose "Rebuild All" to C generate the DLL file "fortran_dll.dll". The DLL file will be stored C under the directory "C:\fortran_dll\release". C C - Give a unique name to the DLL file. For example, if your schematic C file is called "test fortran_dll.sch", you can call it "test_fortran_dll.dll". C C - Copy the renamed DLL file into the same directory as the schematic file. C In the circuit, specify the external DLL block file name as the one C you specified (for example, "test_fortran_dll.dll" in this case). C You are then ready to run PSIM with your own DLL. C C C This sample program calculates the rms of a 60-Hz input in[0], and C stores the output in out[0]. C C You may change the variable names (say from "t" to "Time"). C But DO NOT change the function name, number of variables, variable type, and sequence. C C Variables: C t: Time, passed from PSIM C delt: Time step, passed from PSIM C in: input array, passed from PSIM C out: output array, sent back to PSIM (Note: the values of out[*] can C be modified in PSIM) C C The maximum length of the input and output array "in" and "out" is 30. subroutine SIMUSER (t, delt, in, out) !DEC$ ATTRIBUTES DLLEXPORT::SIMUSER !DEC$ATTRIBUTES VALUE :: t !DEC$ATTRIBUTES VALUE :: delt !DEC$ATTRIBUTES REFERENCE :: in !DEC$ATTRIBUTES REFERENCE :: out C Note: This line should not be changed. real*8 t, delt, in(50), out(50) C Place your code here............begin C Define local variables real*8 nsum, sum, rms, Tperiod; Tperiod=1./60. if (t .ge. nsum*Tperiod) then nsum=nsum+1. rms = sqrt(sum*delt/Tperiod) sum=0. end if out(1) = rms sum=sum+in(1)*in(1) C Place your code here............end return end subroutine