Current Page: NeXtMidas Training Working with Files Lab 1 Solution
- - | Lab 1 (solution): Here is what you should have done: Use the `WAVEFORM` or `HEADER/CREATE` command to force a file called `myfile.tmp` to be created in your home directory.
        nM> waveform myfile.tmp{AUX=HOME}
    or
        nM> header/create myfile.tmp{AUX=HOME}
  - If it is not already on your read AUX list, put HOME on it. Now run the command:
        nM> waveform myfile.tmp ELEM=8k
  Where was the file created?
      In the HOME AUX. Midas writes over existing files
      before creating new ones!
  - Use the `FILES` command to find the name of the shape (`.shp`) file that is located in the `dat` area of SYS.
        nM> files ext=shp aux=dat
        Auxiliary [DAT] = /home/student/nxmlatest/nxm/sys/dat/   (1 files)
          world.shp
  - Use the `STATUS` command to find out the size (number of bytes) of the shape file in the `dat` area of SYS. (Data displayed is from NeXtMidas 3.8+)
        nM> status /home/student/nxmlatest/nxm/sys/dat/world.shp
        ShapeFile   :  file:/home/student/nxmlatest/nxm/sys/dat/world.shp
        Code        :  9994
        Version     :  1000
        Length      :  224094
        Size        :  448188.0 bytes
        Type        :  Polygon
        X1,X2       :  (-180.0,180.00000190734863)
        Y1,Y2       :  (-90.0,83.57026863098145)
        DB File     :  /home/student/nxmlatest/nxm/sys/dat/world.dbf, exists=true
        Comment     :  null
  - Use `DATALIST` to list the data in `airports.csv`.
        nM> datalist airports.csv
          0: {COL_1="AIRPORT NAME",COL_2="CODE",COL_3="LATITUDE",COL_4="LONGITUDE"}
          1: {COL_1="Abu Dhabi",COL_2="AUH",COL_3="024.43333",COL_4="054.65000"}
          2: {COL_1="Adelaide",COL_2="ADL",COL_3="-034.94639",COL_4="138.52944"}
          3: {COL_1="Agnew",COL_2="AGW",COL_3="-028.01667",COL_4="120.53333"}
          4: {COL_1="Albany",COL_2="ALH",COL_3="-034.94472",COL_4="117.80750"}
          5: {COL_1="Albury",COL_2="ABX",COL_3="-036.06889",COL_4="146.95639"}
          6: {COL_1="Alcoota",COL_2="ALC",COL_3="-022.83333",COL_4="134.45000"}
        Note that the first line is a header.
  - Now use `STATUS` with the `/d` switch to list the header and data in `airports.csv`. But, this time, give it the `HEADERROWS=1` qualifier, and see what happens.
        nM> status airports.csv{headerrows=1} /d
        CsvFile   : file:/home/student/nxmlatest/nxm/sys/dat/airports.csv
        Rows      : 726
        Columns   : 4
        Header    : First Row
        Column Name=AIRPORT_NAME    Format=??
        Column Name=CODE            Format=??
        Column Name=LATITUDE        Format=??
        Column Name=LONGITUDE       Format=??
          0: {AIRPORT_NAME="Abu Dhabi",CODE="AUH",LATITUDE="024.43333",LONGITUDE="054.65000"}
          1: {AIRPORT_NAME="Adelaide",CODE="ADL",LATITUDE="-034.94639",LONGITUDE="138.52944"}
          2: {AIRPORT_NAME="Agnew",CODE="AGW",LATITUDE="-028.01667",LONGITUDE="120.53333"}
          3: {AIRPORT_NAME="Albany",CODE="ALH",LATITUDE="-034.94472",LONGITUDE="117.80750"}
          4: {AIRPORT_NAME="Albury",CODE="ABX",LATITUDE="-036.06889",LONGITUDE="146.95639"}
          5: {AIRPORT_NAME="Alcoota",CODE="ALC",LATITUDE="-022.83333",LONGITUDE="134.45000"}
  - Set up an AUX called WEB and point it to original: `http://nextmidas.com/nm/nxm/sys/dat/` (currently unavailable) alternate: `file:///opt/midas/nxmlatest/nxm/sys/dat/` (where /opt/midas/nxmlatest is a softlink to your local nxm installation) Now list the header of the world.prm in this AUX.
        original: nM> set AUX.WEB "http://nextmidas.com/nm/nxm/sys/dat/"
        alternate: nM> set AUX.WEB "/opt/midas/nxmlatest/nm/nxm/sys/dat/"

        nM> status world.prm{AUX=WEB}
  - Use the `HEADER` command to create the similarly named files called `temp_xxx_file.tmp`, `temp_yyy_file.tmp`, `temp_xyx_file.tmp`, and `temp_zzy_file.tmp`. Then use the `FILES` command to find all files starting with temp_, with a y somewhere after the temp_ and ending with _file. Use the `FILES/E` command to erase all of the files you created.
        nM> header/create temp_xxx_file.tmp
        nM> header/create temp_yyy_file.tmp
        nM> header/create temp_xyx_file.tmp
        nM> header/create temp_zzy_file.tmp
        nM> files name=temp_*y*_file
        Auxiliary [1] = /midas/data1/student/   (3 files)
          temp_yyy_file.tmp   temp_xyx_file.tmp   temp_zzy_file.tmp
        nM> files/e name=temp_*_file
  - NOTE: Erase does not take in wild cards, so `erase temp_*_file` will not work. Use `FNAME` to form the path for the DAT area of the SYS option tree.
        nM> FNAME datDir AREA=DAT NAME="" EXT="" OPT=SYS
        nM> res datDir
        31S: DATDIR          = /home/midas/nxmxxx/nxm/sys/dat/
    or
        nM> FNAME datDir AREA=DAT
        nM> res datDir
        31S: DATDIR          = /home/midas/nxmxxx/nxm/sys/dat/
  - using the defaults for `NAME`, `EXT` and `OPT` Use `FILE` to open the `airports.csv` file, convert it into a table with a row prefix of `R_` excluding the header, then close the file.
        nM> file open filetag airports.csv{HEADERROWS=1}
        nM> res t:tbl filetag.toTable(R_)
        nM> file close filetag
        nM> res/all tbl
          T: TBL             = Table of 726 entries
          T:  R_1            = Table of 4 entries
         9S:   AIRPORT_NAME  = Abu Dhabi
         3S:   CODE          = AUH
         9S:   LATITUDE      = 024.43333
         9S:   LONGITUDE     = 054.65000
          T:  R_2            = Table of 4 entries
         8S:   AIRPORT_NAME  = Adelaide
         3S:   CODE          = ADL
        10S:   LATITUDE      = -034.94639
         9S:   LONGITUDE     = 138.52944
               ...