CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: [RESOLVED] Fortran to VB6

  1. #1
    Join Date
    Apr 2020
    Posts
    7

    [RESOLVED] Fortran to VB6

    Hi Everyone,

    I have a small amount of Fortran 77 code to convert to VB6 and I'd like suggestions/ code from anyone with experience at this:

    Code:
         implicit real*8(a-h,o-z)
          real*4 data(100000)
          real*8 glamn,glomn,dla,dlo
          integer*4 nla,nlo,ikind
          character*88 fname
    
          open(2,file=fname,form='formatted')
          
          read(2,*)glamn,glomn,dla,dlo,nla,nlo,ikind
          
          do 10 i=1,nla
                read(2,*)(data(j),j=1,nlo)
                xlat=glamn+(i-1)*dla
           do 11 j=1,nlo
                 xlon=glomn+(j-1)*dlo   
                 write(6,*) xlat,xlon,data(J)   
    c latitude (N) longitude (E) in degree, data(j) geoid heights in meters
     10 continue
          end
    Thanks for any help
    Last edited by 2kaud; April 2nd, 2020 at 11:24 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    I can't convert to VB6 but I could convert to C++ if that's any help.

    Couple of points:
    1) label 11 for the inner do loop isn't specified
    2) file 6 isn't specified
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,732

    Re: Fortran to VB6

    Quote Originally Posted by 2kaud View Post
    I can't convert to VB6 but I could convert to C++ if that's any help.

    Couple of points:
    1) label 11 for the inner do loop isn't specified
    2) file 6 isn't specified
    If I recall it correctly "file 6" means the standard output (standard printer).
    Victor Nijegorodov

  4. #4
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    Quote Originally Posted by 2kaud View Post
    I can't convert to VB6 but I could convert to C++ if that's any help.

    Couple of points:
    1) label 11 for the inner do loop isn't specified
    2) file 6 isn't specified
    Thanks. I did get clarity, file 6 is just any output file that I would want to use like 'myOutPut.txt'. '11 continue' is supposed to be the line right before '10 continue'.

    If you could write this in VB6 it would be a huge help.
    Thank You

  5. #5
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    C++ would be great, C++ was the language I learned on back in college so that would be a big help. I'm a little rusty but it should come back to me.

    Thank you

  6. #6
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    Hi VictorN,

    I have some additional info: 'file 6' is any file that I want to use for output so it could be myOutPut.txt or something like that. Label 11 should be the line above '10 continue'. I'm just learning Fortran 77 but I'm afraid I might mess up this conversion, I'd greatly appreciate any help that you could provide.

    Thanks and I'm sorry if I didn't respond to the correct person, I'm new to codeguru

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    Quote Originally Posted by geoscotty View Post
    C++ would be great, C++ was the language I learned on back in college so that would be a big help. I'm a little rusty but it should come back to me.

    Thank you
    OK. Would you please attach a small sample file for testing.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    Assuming I've read the Fortran code correctly (I'm a bit rusty!), the below is my first attempt at a C++ translation. Note that without sample data, I have not tested this. Let me know of any issues. I don't think you actually need data to be an array - so I haven't used one. What C++ compiler are you using?

    Note also that the input/output file names are hard coded into the program. If they are not always the same, it's possible to specify these names when the program is executed. If this facility is required, let me know and I'll modify the C++ code.

    Code:
    #include <fstream>
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    const string inpfilnam = "...";		// Name of input file goes here
    const string outfilnam = "...";		// Name of output file goes here
    
    int main()
    {
    	ifstream ifs(inpfilnam);
    	ofstream ofs(outfilnam);
    
    	if (!ifs.is_open())
    		return (cout << "Cannot open input file " << inpfilnam << endl), 1;
    
    	if (!ofs.is_open())
    		return (cout << "Cannot open output file " << outfilnam << endl), 2;
    
    	double glamn, glomn, dla, dlo;
    	int nla, nlo, ikind;
    
    	ifs >> glamn >> glomn >> dla >> dlo >> nla >> nlo >> ikind;
    
    	if (!ifs.good())
    		return (cout << "Error reading parameters from file\n"), 3;
    
    	for (int i = 0; i < nla; ++i) {
    		const double xlat = glamn + i * dla;
    		double data;
    
    		for (int j = 0; (j < nlo) && ifs.good(); ++j) {
    			ifs >> data;
    			ofs << xlat << " " << glomn + j * dlo << " " << data << '\n';
    		}
    	}
    }
    PS Assuming this C++ code is OK and a VB6 version (why not VB.Net?) is still required by the OP, would some kind VB6 guru be able to provide the conversion from C++ to VB6?
    Last edited by 2kaud; April 3rd, 2020 at 10:13 AM. Reason: Changed ofs << line
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  9. #9
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    This is awesome, thank you 2kaud, this is a huge help. This is for a new part of an old VB6 program that I've added functionality to over the years. I do plan to convert the program to another language but I haven't decided the best language to use. I've attached a sample of a source data file as well. If the attachment doesn't come through because it's too big, the files are available for download here:

    https://www.ngs.noaa.gov/GEOID/GEOID...2B_CONUS.shtml

    Any of the binary compressed ASC should work as the source

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    OK. Tried it with g2012bu0.asc. One small correction to the program needed. The ofs << line has been changed in my code in post #8.

    What processing are using for the generated output file?
    Last edited by 2kaud; April 3rd, 2020 at 10:36 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    It seems likely that you'll need to use this program with different input/output files. This version allows these names to be specified when the program is used. eg

    Code:
    test12 v:\g2012bu0.asc v:\g2012bu0.txt
    where test12 is the name of the program, v:\g2012bu0.asc is the input file name and v:\g2012bu0.txt is the output file (which shouldn't be the same name as the input file!).

    Code:
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    	if (argc != 3)
    		return (cout << "Format is <progname> inputfile outputfile\n"), 4;
    
    	ifstream ifs(argv[1]);
    	ofstream ofs(argv[2]);
    
    	if (!ifs.is_open())
    		return (cout << "Cannot open input file " << argv[1] << endl), 1;
    
    	if (!ofs.is_open())
    		return (cout << "Cannot open output file " << argv[2] << endl), 2;
    
    	double glamn, glomn, dla, dlo;
    	int nla, nlo, ikind;
    
    	ifs >> glamn >> glomn >> dla >> dlo >> nla >> nlo >> ikind;
    
    	if (!ifs.good())
    		return (cout << "Error reading parameters from file\n"), 3;
    
    	for (int i = 0; i < nla; ++i) {
    		const double xlat = glamn + i * dla;
    		double data;
    
    		for (int j = 0; (j < nlo) && ifs.good(); ++j) {
    			ifs >> data;
    			ofs << xlat << " " << glomn + j * dlo << " " << data << '\n';
    		}
    	}
    }
    Last edited by 2kaud; April 3rd, 2020 at 10:32 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  12. #12
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    Thanks 2kaud,

    One of my specialties is a high-precision form of GPS that is accurate to about 1 cm. GPS satellites actually provide information in the form of latitude, longitude, and something called ellipsoid height; but people typically need north, east, and elevation. The program that I'm adding this code to already converts lat/ long into north/east for most recognized geodetic grids, but it currently doesn't project ellipsoid height into an elevation, this code will change that. This code extracts the information needed to calculate elevation from ellipsoid height based on a particular geoid model in an ascii format. Elevation above or below sea level isn't typically based on tidal gauges anymore, it's usually based on a particular geoid model; the one that you just tested was a geoid model called 12B, and it's the most common model used in North America today.

    I'm going to get this added to my program and I'll let you know how I make out, thanks again, this is a huge help.

  13. #13
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,142

    Re: Fortran to VB6

    The reason i asked, is because that program converts one file into another - which is presumably then going to be used by another program? I was wondering about the program that uses this intermediate output file and whether this 'intermediate' output created file by this program was needed - or whether the program that uses it could be altered to use the original file direct ?? Just a thought - as it would reduce the amount of file processing involved.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  14. #14
    Join Date
    Apr 2020
    Posts
    7

    Re: Fortran to VB6

    OK thanks. I most likely will have the program read the data directly without the intermediate file, but I'm kicking around the idea of using a variation of the code that you helped me with to make an optimized file. The ASCII file for North America actually has a lot more data than I need. Either way you've been a big help. Thanks again, I hope I can return the favor sometime but I doubt that you have much need for VB6 code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)